KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > ejbcontext > unit > EjbContextUnitTestCase


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.ejbcontext.unit;
23
24 import org.jboss.ejb3.test.ejbcontext.Stateful;
25 import org.jboss.ejb3.test.ejbcontext.StatefulRemote;
26 import org.jboss.ejb3.test.ejbcontext.Stateless;
27 import org.jboss.logging.Logger;
28 import org.jboss.test.JBossTestCase;
29 import junit.framework.Test;
30
31 /**
32  * Comment
33  *
34  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
35  * @version $Revision: 46279 $
36  */

37 public class EjbContextUnitTestCase
38 extends JBossTestCase
39 {
40    private static final Logger log = Logger.getLogger(EjbContextUnitTestCase.class);
41
42    public EjbContextUnitTestCase(String JavaDoc name)
43    {
44       super(name);
45    }
46    
47    public void testEjbContextJndi() throws Exception JavaDoc
48    {
49      Stateful stateful = (Stateful)getInitialContext().lookup("Stateful");
50      stateful.testEjbContext();
51    }
52    
53    public void testEjbContextLookup() throws Exception JavaDoc
54    {
55      Stateless stateless = (Stateless)getInitialContext().lookup("Stateless");
56      stateless.testEjbContextLookup();
57    }
58    
59    public void testStatelessInvokedBusinessInterface() throws Exception JavaDoc
60    {
61       Stateless stateless1 = (Stateless)getInitialContext().lookup("Stateless");
62       Stateless stateless2 = (Stateless)getInitialContext().lookup("Stateless");
63       
64       Class JavaDoc interfc = stateless1.testInvokedBusinessInterface();
65       assertEquals(interfc, Stateless.class);
66       
67       interfc = stateless2.testInvokedBusinessInterface();
68       assertEquals(interfc, Stateless.class);
69       
70       Stateless stateless = (Stateless)stateless1.testBusinessObject(Stateless.class);
71       stateless.noop();
72
73       assertEquals(interfc, Stateless.class);
74       
75       try{
76          stateless1.testBusinessObject(Stateful.class);
77          fail("IllegalStateException not thrown");
78       }
79       catch (javax.ejb.EJBException JavaDoc e)
80       {
81          if (!(e.getCause() instanceof IllegalStateException JavaDoc)) throw e;
82          assertEquals(IllegalStateException JavaDoc.class, e.getCause().getClass());
83       }
84       
85       stateless1.testEjbObject();
86       
87       stateless1.testEjbLocalObject();
88    }
89    
90    public void testStatefulInvokedBusinessInterface() throws Exception JavaDoc
91    {
92       Stateful stateful1 = (Stateful)getInitialContext().lookup("Stateful");
93       StatefulRemote stateful2 = (StatefulRemote)getInitialContext().lookup("StatefulRemote");
94       
95       Class JavaDoc interfc = stateful1.testInvokedBusinessInterface();
96       assertEquals(interfc, Stateful.class);
97       
98       interfc = stateful2.testInvokedBusinessInterface2();
99       assertEquals(interfc, StatefulRemote.class);
100       
101       interfc = stateful1.testLocalInvokedBusinessInterface();
102       assertEquals(interfc, StatefulRemote.class);
103       
104       stateful1.setState("same");
105       Stateful stateful3 = (Stateful)stateful1.getBusinessObject();
106       assertEquals("same", stateful3.getState());
107
108       
109    }
110
111    public static Test suite() throws Exception JavaDoc
112    {
113       return getDeploySetup(EjbContextUnitTestCase.class, "ejbcontext.jar");
114    }
115
116 }
117
Popular Tags