KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > reference21_30 > unit > ReferenceTestCase


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.reference21_30.unit;
23
24 import javax.ejb.EJBException JavaDoc;
25 import javax.ejb.EJBHome JavaDoc;
26 import javax.ejb.EJBMetaData JavaDoc;
27 import javax.ejb.EJBObject JavaDoc;
28 import javax.ejb.Handle JavaDoc;
29 import javax.ejb.HomeHandle JavaDoc;
30 import javax.naming.InitialContext JavaDoc;
31 import org.jboss.ejb3.test.reference21_30.Session21;
32 import org.jboss.ejb3.test.reference21_30.Session30;
33 import org.jboss.ejb3.test.reference21_30.Session30Home;
34 import org.jboss.ejb3.test.reference21_30.StatefulSession30;
35 import org.jboss.ejb3.test.reference21_30.StatefulSession30Home;
36 import org.jboss.logging.Logger;
37 import org.jboss.test.JBossTestCase;
38 import junit.framework.Test;
39
40 /**
41  * Test for EJB3.0/EJB2.1 references
42  *
43  * @version <tt>$Revision: 39814 $</tt>
44  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
45  */

46 public class ReferenceTestCase
47     extends JBossTestCase {
48
49    private static final Logger log = Logger
50          .getLogger(ReferenceTestCase.class);
51
52    public ReferenceTestCase(String JavaDoc name)
53    {
54       super(name);
55    }
56
57    public void testSession21() throws Exception JavaDoc
58    {
59       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
60       
61       Session21 session = (Session21)jndiContext.lookup("Session21");
62       String JavaDoc access = session.access();
63       assertEquals("Session21", access);
64       access = session.access30();
65       assertEquals("Session30", access);
66    }
67    
68    public void testSession30() throws Exception JavaDoc
69    {
70       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
71  
72       Session30 session = (Session30) jndiContext.lookup("Session30");
73       String JavaDoc access = session.access();
74       assertEquals("Session30", access);
75       access = session.access21();
76       assertEquals("Session21", access);
77    }
78    
79    public void testSessionHome30() throws Exception JavaDoc
80    {
81       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
82       
83       Session30 session = (Session30) jndiContext.lookup("Session30");
84       assertNotNull(session);
85       String JavaDoc access = session.access();
86       assertEquals("Session30", access);
87       
88       Session30Home home = (Session30Home) jndiContext.lookup("Session30Home");
89       assertNotNull(home);
90       session = (Session30)home.create();
91       assertNotNull(session);
92       access = session.access();
93       assertEquals("Session30", access);
94    }
95
96    public void testStatefulRemove() throws Exception JavaDoc
97    {
98       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
99       
100       StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("StatefulSession30Home");
101       assertNotNull(home);
102       StatefulSession30 session = (StatefulSession30)home.create();
103       assertNotNull(session);
104       session.setValue("123");
105       String JavaDoc value = session.getValue();
106       assertEquals("123", value);
107       
108       EJBObject JavaDoc ejbObject = (EJBObject JavaDoc)session;
109       
110       Handle JavaDoc handle = session.getHandle();
111       assertNotNull(handle);
112       
113       home.remove(handle);
114       
115       try {
116          session.getValue();
117          assertTrue(false);
118       } catch (EJBException JavaDoc e)
119       {
120          assertTrue(e instanceof EJBException JavaDoc);
121       }
122       
123       session = (StatefulSession30)home.create();
124       assertNotNull(session);
125       session.setValue("123");
126       value = session.getValue();
127       assertEquals("123", value);
128       
129       session.remove();
130       
131       try {
132          session.getValue();
133          assertTrue(false);
134       } catch (EJBException JavaDoc e)
135       {
136          assertTrue(e instanceof EJBException JavaDoc);
137       }
138    }
139  
140    public void testStatefulSessionHome30() throws Exception JavaDoc
141    {
142       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
143       
144       StatefulSession30 session = (StatefulSession30) jndiContext.lookup("StatefulSession30");
145       assertNotNull(session);
146       session.setValue("testing");
147       String JavaDoc value = session.getValue();
148       assertEquals("testing", value);
149       
150       StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("StatefulSession30Home");
151       assertNotNull(home);
152       session = (StatefulSession30)home.create();
153       assertNotNull(session);
154       session.setValue("123");
155       value = session.getValue();
156       assertEquals("123", value);
157       
158       session = (StatefulSession30)home.create("456");
159       assertNotNull(session);
160       value = session.getValue();
161       assertEquals("456", value);
162       
163       session = (StatefulSession30)home.create("combined", new Integer JavaDoc("789"));
164       assertNotNull(session);
165       value = session.getValue();
166       assertEquals("combined789", value);
167    }
168    
169    public void testRemoteHomeAnnotation() throws Exception JavaDoc
170    {
171       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
172       
173       StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("HomedStatefulSession30Home");
174       assertNotNull(home);
175       StatefulSession30 session = (StatefulSession30)home.create();
176       assertNotNull(session);
177       session.setValue("123");
178       String JavaDoc value = session.getValue();
179       assertEquals("123", value);
180       
181       session = (StatefulSession30)home.create("456");
182       assertNotNull(session);
183       value = session.getValue();
184       assertEquals("456", value);
185       
186       session = (StatefulSession30)home.create("combined", new Integer JavaDoc("789"));
187       assertNotNull(session);
188       value = session.getValue();
189       assertEquals("combined789", value);
190    }
191    
192    public void testLocalHomeAnnotation() throws Exception JavaDoc
193    {
194       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
195       
196       StatefulSession30 session = (StatefulSession30) jndiContext.lookup("StatefulSession30");
197       
198       String JavaDoc access = session.accessLocalHome();
199       assertEquals("LocalHome", access);
200    }
201    
202    public void testLocalHome() throws Exception JavaDoc
203    {
204       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
205       
206       StatefulSession30 statefulSession = (StatefulSession30) jndiContext.lookup("StatefulSession30");
207       assertNotNull(statefulSession);
208       String JavaDoc access = statefulSession.accessLocalStateless();
209       assertEquals("Session30", access);
210       
211       Session30 session = (Session30) jndiContext.lookup("Session30");
212       assertNotNull(session);
213       access = session.accessLocalStateful();
214       assertEquals("default", access);
215       
216       access = session.accessLocalStateful("testing");
217       assertEquals("testing", access);
218       
219       access = session.accessLocalStateful("testing", new Integer JavaDoc(123));
220       assertEquals("testing123", access);
221    }
222  
223    public void testStatefulState() throws Exception JavaDoc
224    {
225       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
226            
227       StatefulSession30 session1 = (StatefulSession30) jndiContext.lookup("StatefulSession30");
228       assertNotNull(session1);
229       session1.setValue("testing");
230       assertEquals("testing", session1.getValue());
231       
232       StatefulSession30 session2 = (StatefulSession30) jndiContext.lookup("StatefulSession30");
233       assertNotNull(session2);
234       assertEquals("default", session2.getValue());
235      
236       StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("StatefulSession30Home");
237       assertNotNull(home);
238       StatefulSession30 session3 = (StatefulSession30)home.create();
239       assertNotNull(session3);
240       session3.setValue("123");
241       assertEquals("123", session3.getValue());
242       
243       StatefulSession30 session4 = (StatefulSession30)home.create();
244       assertNotNull(session4);
245       assertEquals("default", session4.getValue());
246       assertEquals("default", session4.getValue());
247       
248       StatefulSession30 session5 = (StatefulSession30)home.create("init");
249       assertNotNull(session5);
250       assertEquals("init", session5.getValue());
251       
252       StatefulSession30 session6 = (StatefulSession30)home.create("init", new Integer JavaDoc(123));
253       assertNotNull(session6);
254       assertEquals("init123", session6.getValue());
255       
256       StatefulSession30 session7 = (StatefulSession30)home.create("secondinit");
257       assertNotNull(session7);
258       assertEquals("secondinit", session7.getValue());
259       
260       StatefulSession30 session8 = (StatefulSession30) jndiContext.lookup("StatefulSession30");
261       assertNotNull(session8);
262       assertEquals("default", session8.getValue());
263       
264       assertEquals("testing", session1.getValue());
265       assertEquals("default", session2.getValue());
266       assertEquals("123", session3.getValue());
267       assertEquals("default", session4.getValue());
268       assertEquals("init", session5.getValue());
269       assertEquals("init123", session6.getValue());
270       assertEquals("secondinit", session7.getValue());
271    }
272    
273    public void testStateful21Interfaces() throws Exception JavaDoc
274    {
275       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
276       
277       StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("StatefulSession30Home");
278       assertNotNull(home);
279       
280       EJBMetaData JavaDoc metadata = home.getEJBMetaData();
281       assertNotNull(metadata);
282       assertEquals("org.jboss.ejb3.test.reference21_30.StatefulSession30",metadata.getRemoteInterfaceClass().getName());
283       
284       HomeHandle JavaDoc homeHandle = home.getHomeHandle();
285       assertNotNull(homeHandle);
286       
287       EJBHome JavaDoc ejbHome = homeHandle.getEJBHome();
288       assertNotNull(ejbHome);
289       metadata = ejbHome.getEJBMetaData();
290       assertNotNull(metadata);
291       assertEquals("org.jboss.ejb3.test.reference21_30.StatefulSession30",metadata.getRemoteInterfaceClass().getName());
292       
293       StatefulSession30 session = (StatefulSession30)home.create();
294       assertNotNull(session);
295       ejbHome = session.getEJBHome();
296       assertNotNull(ejbHome);
297       Object JavaDoc primaryKey = session.getPrimaryKey();
298       assertNotNull(primaryKey);
299       
300       Handle JavaDoc handle = session.getHandle();
301       assertNotNull(handle);
302       
303       EJBObject JavaDoc ejbObject = handle.getEJBObject();
304       assertNotNull(ejbObject);
305       
306       ejbHome = ejbObject.getEJBHome();
307       assertNotNull(ejbHome);
308     
309       Handle JavaDoc handle1 = ejbObject.getHandle();
310       assertNotNull(handle1);
311       
312       StatefulSession30 session1 = (StatefulSession30)home.create();
313       assertFalse(session.isIdentical(session1));
314       assertTrue(session.isIdentical(session));
315    }
316  
317    public void testStateless21Interfaces() throws Exception JavaDoc
318    {
319       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
320       
321       Session30Home home = (Session30Home) jndiContext.lookup("Session30Home");
322       assertNotNull(home);
323       
324       EJBMetaData JavaDoc metadata = home.getEJBMetaData();
325       assertNotNull(metadata);
326       assertEquals("org.jboss.ejb3.test.reference21_30.Session30",metadata.getRemoteInterfaceClass().getName());
327       
328       HomeHandle JavaDoc homeHandle = home.getHomeHandle();
329       assertNotNull(homeHandle);
330       
331       EJBHome JavaDoc ejbHome = homeHandle.getEJBHome();
332       assertNotNull(ejbHome);
333       metadata = ejbHome.getEJBMetaData();
334       assertNotNull(metadata);
335       assertEquals("org.jboss.ejb3.test.reference21_30.Session30",metadata.getRemoteInterfaceClass().getName());
336       
337       Session30 session = (Session30)home.create();
338       assertNotNull(session);
339       ejbHome = session.getEJBHome();
340       assertNotNull(ejbHome);
341       Object JavaDoc primaryKey = session.getPrimaryKey();
342       assertNull(primaryKey);
343       
344       Handle JavaDoc handle = session.getHandle();
345       assertNotNull(handle);
346       
347       EJBObject JavaDoc ejbObject = handle.getEJBObject();
348       assertNotNull(ejbObject);
349       
350       ejbHome = ejbObject.getEJBHome();
351       assertNotNull(ejbHome);
352     
353       Handle JavaDoc handle1 = ejbObject.getHandle();
354       assertNotNull(handle1);
355       
356       Session30 session1 = (Session30)home.create();
357       assertFalse(session.isIdentical(session1));
358    }
359
360    protected void setUp() throws Exception JavaDoc
361    {
362    }
363
364    public static Test suite() throws Exception JavaDoc
365    {
366       return getDeploySetup(ReferenceTestCase.class, "reference.jar");
367    }
368 }
369
Popular Tags