KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > factory > unit > FactoryUnitTestCase


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.factory.unit;
23
24 import org.jboss.ejb3.test.factory.Entity1;
25 import org.jboss.ejb3.test.factory.Entity2;
26 import org.jboss.ejb3.test.factory.MyService;
27 import org.jboss.ejb3.test.factory.Session1;
28 import org.jboss.ejb3.test.factory.Session2;
29 import org.jboss.ejb3.test.factory.Stateful1;
30 import org.jboss.ejb3.test.factory.Util;
31 import org.jboss.test.JBossTestCase;
32 import junit.framework.Test;
33
34 /**
35  * Sample client for the jboss container.
36  *
37  * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
38  * @version $Id: FactoryUnitTestCase.java 58110 2006-11-04 08:34:21Z scott.stark@jboss.org $
39  */

40
41 public class FactoryUnitTestCase
42         extends JBossTestCase
43 {
44    org.jboss.logging.Logger log = getLog();
45
46    static boolean deployed = false;
47    static int test = 0;
48
49    public FactoryUnitTestCase(String JavaDoc name)
50    {
51
52       super(name);
53
54    }
55
56    public void testMe() throws Exception JavaDoc
57    {
58       Session1 session1 = (Session1) this.getInitialContext().lookup("factory-test/Session1Bean/remote");
59       Session2 session2 = (Session2) this.getInitialContext().lookup("factory-test/Session2Bean/remote");
60       MyService service = (MyService) this.getInitialContext().lookup("factory-test/MyServiceBean/remote");
61
62       int oneF = session1.create1FromFactory();
63       int oneM = session1.create1FromManager();
64       int twoF = session1.create2FromFactory();
65       int twoM = session1.create2FromManager();
66       session1.doUtil(new Util());
67
68       session2.find1FromFactory(oneF);
69       assertNotNull(session2.find1FromManager(oneM));
70       session2.find2FromFactory(twoF);
71       assertNotNull(session2.find2FromManager(twoM));
72       assertNotNull(service.find2FromManager(twoM));
73       assertNotNull(session2.findUtil1FromManager(1));
74       assertNotNull(session2.findUtil2FromManager(2));
75
76    }
77
78    public void testExtended() throws Exception JavaDoc
79    {
80       Stateful1 stateful1 = (Stateful1) this.getInitialContext().lookup("factory-test/Stateful1Bean/remote");
81       Session2 session2 = (Session2) this.getInitialContext().lookup("factory-test/Session2Bean/remote");
82
83       int oneId = stateful1.create1();
84       int twoId = stateful1.create2();
85
86       stateful1.update1();
87       stateful1.update2();
88
89       {
90          Entity1 one = session2.find1FromManager(oneId);
91          assertEquals(one.getString(), "changed");
92
93          Entity2 two = session2.find2FromManager(twoId);
94          assertEquals(two.getString(), "changed");
95       }
96
97       stateful1.never();
98
99       {
100          Entity1 one = session2.find1FromManager(oneId);
101          assertEquals(one.getString(), "changed");
102
103          Entity2 two = session2.find2FromManager(twoId);
104          assertEquals(two.getString(), "changed");
105       }
106
107       stateful1.checkout();
108
109       {
110          Entity1 one = session2.find1FromManager(oneId);
111          assertEquals(one.getString(), "never");
112
113          Entity2 two = session2.find2FromManager(twoId);
114          assertEquals(two.getString(), "never");
115       }
116    }
117
118    public void testExtended2() throws Exception JavaDoc
119    {
120       Stateful1 stateful1 = (Stateful1) this.getInitialContext().lookup("factory-test/Stateful1Bean/remote");
121       Session2 session2 = (Session2) this.getInitialContext().lookup("factory-test/Session2Bean/remote");
122
123       int oneId = stateful1.create1();
124       int twoId = stateful1.create2();
125
126       stateful1.update1();
127       stateful1.update2();
128
129       Entity1 one = session2.find1FromManager(oneId);
130       assertEquals(one.getString(), "changed");
131
132       Entity2 two = session2.find2FromManager(twoId);
133       assertEquals(two.getString(), "changed");
134       one.setString("never2");
135       two.setString("never2");
136       stateful1.never2(one, two);
137
138       {
139          Entity1 uno = session2.find1FromManager(oneId);
140          assertEquals(uno.getString(), "changed");
141
142          Entity2 dos = session2.find2FromManager(twoId);
143          assertEquals(dos.getString(), "changed");
144       }
145
146       stateful1.checkout();
147
148       {
149          Entity1 uno = session2.find1FromManager(oneId);
150          assertEquals(uno.getString(), "never2");
151
152          Entity2 dos = session2.find2FromManager(twoId);
153          assertEquals(dos.getString(), "never2");
154       }
155    }
156
157    public static Test suite() throws Exception JavaDoc
158    {
159       return getDeploySetup(FactoryUnitTestCase.class, "factory-test.ear");
160    }
161
162 }
163
Popular Tags