KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > naming > test > EjbLinkUnitTestCase


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.test.naming.test;
23
24 import javax.naming.InitialContext JavaDoc;
25 import javax.rmi.PortableRemoteObject JavaDoc;
26
27 import junit.framework.Test;
28 import junit.framework.TestCase;
29 import junit.framework.TestSuite;
30
31 import org.jboss.test.JBossTestCase;
32 import org.jboss.test.naming.interfaces.TestEjbLinkHome;
33 import org.jboss.test.naming.interfaces.TestEjbLink;
34
35 /**
36  * Tests of EjbLink.
37  *
38  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>
39  */

40 public class EjbLinkUnitTestCase extends JBossTestCase
41 {
42    /**
43     * Constructor for the test
44     *
45     * @param name Testcase name
46     */

47    public EjbLinkUnitTestCase(String JavaDoc name)
48    {
49       super(name);
50    }
51
52    /**
53     * Test an ejblink
54     *
55     * @exception Exception Description of Exception
56     */

57    public void testEjbLinkNamed() throws Exception JavaDoc
58    {
59       Object JavaDoc obj = getInitialContext().lookup("naming/SessionB");
60       obj = PortableRemoteObject.narrow(obj, TestEjbLinkHome.class);
61       TestEjbLinkHome home = (TestEjbLinkHome)obj;
62       getLog().debug("Found naming/SessionB");
63
64       TestEjbLink bean = home.create();
65       getLog().debug("Created the bean");
66       assertEquals("Works", bean.testEjbLinkCaller("java:comp/env/ejb/SessionA"));
67       getLog().debug("Test succeeded");
68       bean.remove();
69    }
70
71    /**
72     * Test an ejblink with a relative path
73     *
74     * @exception Exception Description of Exception
75     */

76    public void testEjbLinkRelative() throws Exception JavaDoc
77    {
78       Object JavaDoc obj = getInitialContext().lookup("naming/SessionB");
79       obj = PortableRemoteObject.narrow(obj, TestEjbLinkHome.class);
80       TestEjbLinkHome home = (TestEjbLinkHome)obj;
81       getLog().debug("Found naming/SessionB");
82
83       TestEjbLink bean = home.create();
84       getLog().debug("Created the bean");
85       assertEquals("Works", bean.testEjbLinkCaller("java:comp/env/ejb/RelativeSessionA"));
86       getLog().debug("Test succeeded");
87       bean.remove();
88    }
89
90    /**
91     * Test an ejblink using a local ejb-ref
92     *
93     * @exception Exception Description of Exception
94     */

95    public void testEjbLinkLocalNamed() throws Exception JavaDoc
96    {
97       Object JavaDoc obj = getInitialContext().lookup("naming/SessionB");
98       obj = PortableRemoteObject.narrow(obj, TestEjbLinkHome.class);
99       TestEjbLinkHome home = (TestEjbLinkHome)obj;
100       getLog().debug("Found naming/SessionB");
101
102       TestEjbLink bean = home.create();
103       getLog().debug("Created the bean");
104       assertEquals("Works", bean.testEjbLinkCallerLocal("java:comp/env/ejb/LocalSessionA"));
105       getLog().debug("Test succeeded");
106       bean.remove();
107    }
108
109    /**
110     * Test an ejblink using a local ejb-ref with a relative path
111     *
112     * @exception Exception Description of Exception
113     */

114    public void testEjbLinkLocalRelative() throws Exception JavaDoc
115    {
116       Object JavaDoc obj = getInitialContext().lookup("naming/SessionB");
117       obj = PortableRemoteObject.narrow(obj, TestEjbLinkHome.class);
118       TestEjbLinkHome home = (TestEjbLinkHome)obj;
119       getLog().debug("Found naming/SessionB");
120
121       TestEjbLink bean = home.create();
122       getLog().debug("Created the bean");
123       assertEquals("Works", bean.testEjbLinkCallerLocal("java:comp/env/ejb/LocalRelativeSessionA"));
124       getLog().debug("Test succeeded");
125       bean.remove();
126    }
127
128
129     public void testEjbNoLinkLocal () throws Exception JavaDoc
130     {
131         Object JavaDoc obj = getInitialContext().lookup("naming/SessionB");
132         obj = PortableRemoteObject.narrow(obj, TestEjbLinkHome.class);
133         TestEjbLinkHome home = (TestEjbLinkHome)obj;
134         getLog().debug("Found naming/SessionB");
135
136       TestEjbLink bean = home.create();
137       getLog().debug("Created the bean");
138       assertEquals("Works", bean.testEjbLinkCallerLocal("java:comp/env/ejb/NoLinkLocalSessionA"));
139       getLog().debug("Test succeeded");
140       bean.remove();
141     }
142
143
144     public void testEjbNoLink () throws Exception JavaDoc
145     {
146         Object JavaDoc obj = getInitialContext().lookup("naming/SessionB");
147         obj = PortableRemoteObject.narrow(obj, TestEjbLinkHome.class);
148         TestEjbLinkHome home = (TestEjbLinkHome)obj;
149         getLog().debug("Found naming/SessionB");
150
151         TestEjbLink bean = home.create();
152         getLog().debug("Created the bean");
153         assertEquals("Works", bean.testEjbLinkCaller("java:comp/env/ejb/NoLinkSessionA"));
154         getLog().debug("Test succeeded");
155         bean.remove();
156     }
157
158     public void testEjbNames() throws Exception JavaDoc
159     {
160         Object JavaDoc obj = getInitialContext().lookup("naming/SessionB");
161         obj = PortableRemoteObject.narrow(obj, TestEjbLinkHome.class);
162         TestEjbLinkHome home = (TestEjbLinkHome) obj;
163         getLog().debug("Found naming/SessionB home: "+home);
164
165        obj = getInitialContext().lookup("naming/SessionB1");
166        obj = PortableRemoteObject.narrow(obj, TestEjbLinkHome.class);
167        home = (TestEjbLinkHome) obj;
168        getLog().debug("Found naming/SessionB1 home: "+home);
169     }
170
171    public static Test suite() throws Exception JavaDoc
172    {
173       return getDeploySetup(EjbLinkUnitTestCase.class, "naming.ear");
174    }
175 }
176
Popular Tags