KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > clusteredsession > unit > ExtendedPersistenceUnitTestCase


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.ejb3.test.clusteredsession.unit;
23
24 import org.jboss.ejb3.test.clusteredsession.Customer;
25 import org.jboss.ejb3.test.clusteredsession.ShoppingCart;
26 import org.jboss.ejb3.test.clusteredsession.StatelessRemote;
27 import org.jboss.test.JBossClusteredTestCase;
28 import junit.framework.Test;
29
30 import javax.naming.InitialContext JavaDoc;
31 import javax.naming.Context JavaDoc;
32 import java.util.Properties JavaDoc;
33
34 /**
35  * Tests for extended persistence under clustering.
36  *
37  * @author Ben Wang
38  * @version $Id: ExtendedPersistenceUnitTestCase.java 58110 2006-11-04 08:34:21Z scott.stark@jboss.org $
39  */

40
41 public class ExtendedPersistenceUnitTestCase extends JBossClusteredTestCase
42 {
43    org.jboss.logging.Logger log = getLog();
44
45    static boolean deployed = false;
46    static int test = 0;
47
48    public ExtendedPersistenceUnitTestCase(String JavaDoc name)
49    {
50
51       super(name);
52
53    }
54
55    protected InitialContext JavaDoc getInitialContext(int node) throws Exception JavaDoc {
56       // Connect to the server0 JNDI
57
String JavaDoc[] urls = getNamingURLs();
58       Properties JavaDoc env1 = new Properties JavaDoc();
59       env1.setProperty(Context.INITIAL_CONTEXT_FACTORY,
60          "org.jnp.interfaces.NamingContextFactory");
61       env1.setProperty(Context.PROVIDER_URL, urls[node]);
62       return new InitialContext JavaDoc(env1);
63    }
64
65    public void testBasic() throws Exception JavaDoc
66    {
67       ShoppingCart cart = (ShoppingCart) getInitialContext(0).lookup("ShoppingCartBean/remote");
68       StatelessRemote stateless = (StatelessRemote) getInitialContext(0).lookup("StatelessSessionBean/remote");
69       Customer customer;
70
71       long id = cart.createCustomer();
72       customer = stateless.find(id);
73       assertEquals("William", customer.getName());
74       customer = cart.find(id);
75       assertEquals("William", customer.getName());
76       cart.update();
77       customer = stateless.find(id);
78       assertEquals("Bill", customer.getName());
79       customer = cart.find(id);
80       assertEquals("Bill", customer.getName());
81       cart.update2();
82       customer = stateless.find(id);
83       assertEquals("Billy", customer.getName());
84       customer = cart.find(id);
85       assertEquals("Billy", customer.getName());
86       cart.update3();
87       customer = stateless.find(id);
88       assertEquals("Bill Jr.", customer.getName());
89       customer = cart.find(id);
90       assertEquals("Bill Jr.", customer.getName());
91       cart.setContainedCustomer();
92       cart.checkout();
93    }
94
95    public void testPassivation() throws Exception JavaDoc
96    {
97       ShoppingCart cart = (ShoppingCart) getInitialContext(0).lookup("ShoppingCartBean/remote");
98       StatelessRemote stateless = (StatelessRemote) getInitialContext(0).lookup("StatelessSessionBean/remote");
99       Customer customer;
100
101       long id = cart.createCustomer();
102       customer = stateless.find(id);
103       assertEquals("William", customer.getName());
104       customer = cart.find(id);
105       assertEquals("William", customer.getName());
106       cart.update();
107       customer = stateless.find(id);
108       assertEquals("Bill", customer.getName());
109       customer = cart.find(id);
110       assertEquals("Bill", customer.getName());
111       cart.update2();
112       customer = stateless.find(id);
113       assertEquals("Billy", customer.getName());
114       customer = cart.find(id);
115       assertEquals("Billy", customer.getName());
116       cart.update3();
117       customer = stateless.find(id);
118       assertEquals("Bill Jr.", customer.getName());
119       customer = cart.find(id);
120       assertEquals("Bill Jr.", customer.getName());
121       cart.setContainedCustomer();
122       Thread.sleep(11000); // passivation
123
assertTrue(stateless.isPassivated());
124       cart.checkContainedCustomer();
125       cart.findAndUpdateStateless();
126       cart.updateContained();
127       stateless.clearDestroyed();
128       assertTrue(cart.isContainedActivated());
129       cart.checkout();
130       assertTrue(stateless.isDestroyed());
131    }
132
133    public static Test suite() throws Exception JavaDoc
134    {
135       final String JavaDoc jarName = "clusteredsession-test.jar";
136       return JBossClusteredTestCase.getDeploySetup(ExtendedPersistenceUnitTestCase.class,
137               jarName);
138    }
139
140 }
141
Popular Tags