KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > cacheinvalidation > test > CacheInvalidationUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cmp2.cacheinvalidation.test;
23
24 import org.jboss.test.JBossTestCase;
25 import org.jboss.test.cmp2.cacheinvalidation.ejb.Facade;
26 import org.jboss.test.cmp2.cacheinvalidation.ejb.FacadeHome;
27 import junit.framework.Test;
28
29 import javax.naming.InitialContext JavaDoc;
30 import javax.naming.NamingException JavaDoc;
31
32 /**
33  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
34  * @version <tt>$Revision: 37406 $</tt>
35  */

36 public class CacheInvalidationUnitTestCase
37    extends JBossTestCase
38 {
39    public CacheInvalidationUnitTestCase(String JavaDoc name)
40    {
41       super(name);
42    }
43
44    public static Test suite() throws Exception JavaDoc
45    {
46       return getDeploySetup(CacheInvalidationUnitTestCase.class, "cmp2-cacheinvalidation.jar");
47    }
48
49    public void testBasicInvalidation() throws Exception JavaDoc
50    {
51       Facade facade = getFacadeHome().create();
52
53       try
54       {
55          facade.setup();
56
57          Long JavaDoc pk = new Long JavaDoc(1);
58          String JavaDoc cName = facade.readFirstName("CROLocal", pk);
59          assertEquals("Avoka", cName);
60
61          cName = facade.readFirstName("CRWLocal", pk);
62          assertEquals("Avoka", cName);
63
64          facade.writeFirstName("CRWLocal", pk, "Ataka");
65
66          cName = facade.readFirstName("CROLocal", pk);
67          assertEquals("Ataka", cName);
68
69          cName = facade.readFirstName("CRWLocal", pk);
70          assertEquals("Ataka", cName);
71       }
72       finally
73       {
74          facade.tearDown();
75       }
76    }
77
78    public void testCmrInvalidation() throws Exception JavaDoc
79    {
80       Facade facade = getFacadeHome().create();
81
82       try
83       {
84          facade.setup();
85
86          Long JavaDoc pk = new Long JavaDoc(1);
87          String JavaDoc aName = facade.readRelatedAFirstName("CROLocal", pk);
88          assertEquals("Ataka", aName);
89
90          aName = facade.readRelatedAFirstName("CRWLocal", pk);
91          assertEquals("Ataka", aName);
92
93          facade.removeA("ARWLocal", new Long JavaDoc(2));
94
95          aName = facade.readRelatedAFirstName("CROLocal", pk);
96          assertNull(aName);
97
98          aName = facade.readRelatedAFirstName("CRWLocal", pk);
99          assertNull(aName);
100       }
101       finally
102       {
103          facade.tearDown();
104       }
105    }
106
107    private static final FacadeHome getFacadeHome()
108    {
109       InitialContext JavaDoc ctx = null;
110       try
111       {
112          ctx = new InitialContext JavaDoc();
113          return (FacadeHome)ctx.lookup(FacadeHome.JNDI_NAME);
114       }
115       catch(NamingException JavaDoc e)
116       {
117          throw new IllegalStateException JavaDoc("Failed to look up jndi binding " + FacadeHome.JNDI_NAME + ": " + e.getMessage());
118       }
119    }
120 }
121
Popular Tags