KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > longlived > unit > EntityUnitTestCase


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.longlived.unit;
23
24 import org.jboss.ejb3.test.longlived.Customer;
25 import org.jboss.ejb3.test.longlived.ShoppingCart;
26 import org.jboss.ejb3.test.longlived.StatelessRemote;
27 import org.jboss.test.JBossTestCase;
28 import junit.framework.Test;
29
30 /**
31  * Sample client for the jboss container.
32  *
33  * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
34  * @version $Id: EntityUnitTestCase.java 58110 2006-11-04 08:34:21Z scott.stark@jboss.org $
35  */

36
37 public class EntityUnitTestCase
38 extends JBossTestCase
39 {
40    org.jboss.logging.Logger log = getLog();
41
42    static boolean deployed = false;
43    static int test = 0;
44
45    public EntityUnitTestCase(String JavaDoc name)
46    {
47
48       super(name);
49
50    }
51
52    public void testWithFlushMode() throws Exception JavaDoc
53    {
54       ShoppingCart test = (ShoppingCart) this.getInitialContext().lookup("ShoppingCartBean/remote");
55       StatelessRemote remote = (StatelessRemote) this.getInitialContext().lookup("StatelessSessionBean/remote");
56       Customer c;
57       long id;
58
59
60       id = test.createCustomer();
61       c = remote.find(id);
62       assertEquals("William", c.getName());
63       c = test.find(id);
64       assertEquals("William", c.getName());
65       test.never();
66       c = remote.find(id);
67       assertEquals("William", c.getName());
68
69       test.checkout();
70       c = remote.find(id);
71       assertEquals("Bob", c.getName());
72
73       // make sure FlushMode
74

75       test = (ShoppingCart) this.getInitialContext().lookup("ShoppingCartBean/remote");
76
77
78       id = test.createCustomer();
79       c = remote.find(id);
80       assertEquals("William", c.getName());
81       c = test.find(id);
82       assertEquals("William", c.getName());
83       test.update();
84       c = remote.find(id);
85       assertEquals("Bill", c.getName());
86       c = test.find(id);
87       assertEquals("Bill", c.getName());
88       test.update2();
89       c = remote.find(id);
90       assertEquals("Billy", c.getName());
91       c = test.find(id);
92       assertEquals("Billy", c.getName());
93       test.update3();
94       c = remote.find(id);
95       assertEquals("Bill Jr.", c.getName());
96       c = test.find(id);
97       assertEquals("Bill Jr.", c.getName());
98       test.checkout();
99    }
100
101    public void testLongLivedSession() throws Exception JavaDoc
102    {
103       ShoppingCart test = (ShoppingCart) this.getInitialContext().lookup("ShoppingCartBean/remote");
104       StatelessRemote remote = (StatelessRemote) this.getInitialContext().lookup("StatelessSessionBean/remote");
105       Customer c;
106
107       long id = test.createCustomer();
108       c = remote.find(id);
109       assertEquals("William", c.getName());
110       c = test.find(id);
111       assertEquals("William", c.getName());
112       test.update();
113       c = remote.find(id);
114       assertEquals("Bill", c.getName());
115       c = test.find(id);
116       assertEquals("Bill", c.getName());
117       test.update2();
118       c = remote.find(id);
119       assertEquals("Billy", c.getName());
120       c = test.find(id);
121       assertEquals("Billy", c.getName());
122       test.update3();
123       c = remote.find(id);
124       assertEquals("Bill Jr.", c.getName());
125       c = test.find(id);
126       assertEquals("Bill Jr.", c.getName());
127       test.setContainedCustomer();
128       Thread.sleep(6000); // passivation
129
assertTrue(remote.isPassivated());
130       test.checkContainedCustomer();
131       test.findAndUpdateStateless();
132       test.updateContained();
133       remote.clearDestroyed();
134       assertTrue(test.isContainedActivated());
135       test.checkout();
136       assertTrue(remote.isDestroyed());
137    }
138
139    public void testHibernateLongLivedSession() throws Exception JavaDoc
140    {
141       ShoppingCart test = (ShoppingCart) this.getInitialContext().lookup("HibernateShoppingCart");
142       StatelessRemote remote = (StatelessRemote) this.getInitialContext().lookup("StatelessSessionBean/remote");
143       Customer c;
144
145       long id = test.createCustomer();
146       c = remote.find(id);
147       assertEquals("William", c.getName());
148       c = test.find(id);
149       assertEquals("William", c.getName());
150       test.update();
151       c = remote.find(id);
152       assertEquals("Bill", c.getName());
153       c = test.find(id);
154       assertEquals("Bill", c.getName());
155       test.update2();
156       c = remote.find(id);
157       assertEquals("Billy", c.getName());
158       c = test.find(id);
159       assertEquals("Billy", c.getName());
160       test.update3();
161       c = remote.find(id);
162       assertEquals("Bill Jr.", c.getName());
163       c = test.find(id);
164       assertEquals("Bill Jr.", c.getName());
165       test.checkout();
166    }
167
168    public void testHibernateWithFlushMode() throws Exception JavaDoc
169    {
170       ShoppingCart test = (ShoppingCart) this.getInitialContext().lookup("HibernateShoppingCart");
171       StatelessRemote remote = (StatelessRemote) this.getInitialContext().lookup("StatelessSessionBean/remote");
172       Customer c;
173       long id;
174
175
176       id = test.createCustomer();
177       c = remote.find(id);
178       assertEquals("William", c.getName());
179       c = test.find(id);
180       assertEquals("William", c.getName());
181       test.never();
182       c = remote.find(id);
183       assertEquals("William", c.getName());
184
185       test.checkout();
186       c = remote.find(id);
187       assertEquals("Bob", c.getName());
188
189       // make sure FlushMode
190

191       test = (ShoppingCart) this.getInitialContext().lookup("HibernateShoppingCart");
192
193
194       id = test.createCustomer();
195       c = remote.find(id);
196       assertEquals("William", c.getName());
197       c = test.find(id);
198       assertEquals("William", c.getName());
199       test.update();
200       c = remote.find(id);
201       assertEquals("Bill", c.getName());
202       c = test.find(id);
203       assertEquals("Bill", c.getName());
204       test.update2();
205       c = remote.find(id);
206       assertEquals("Billy", c.getName());
207       c = test.find(id);
208       assertEquals("Billy", c.getName());
209       test.update3();
210       c = remote.find(id);
211       assertEquals("Bill Jr.", c.getName());
212       c = test.find(id);
213       assertEquals("Bill Jr.", c.getName());
214       test.checkout();
215    }
216
217    public static Test suite() throws Exception JavaDoc
218    {
219       return getDeploySetup(EntityUnitTestCase.class, "longlived-test.jar");
220    }
221
222 }
223
Popular Tags