001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: A_ClientView.java 7540 2005-10-20 13:15:22Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.local;
027:
028: import javax.ejb.EJBException;
029: import javax.ejb.NoSuchObjectLocalException;
030: import javax.ejb.RemoveException;
031: import javax.rmi.PortableRemoteObject;
032:
033: import org.objectweb.jonas.jtests.beans.local.TargetLocal;
034: import org.objectweb.jonas.jtests.beans.local.TargetSLHome;
035: import org.objectweb.jonas.jtests.beans.local.TargetSLLocalHome;
036: import org.objectweb.jonas.jtests.util.JTestCase;
037:
038: /**
039: * This Class defines Test cases that can be run either SF or SL bean.
040: * These tests are related to the "Client View of a Session Bean"
041: * A session bean that supports both Local & Remote interface is used
042: * (TargetSL oe TargetSF in beans/local)
043: * Here are testcases taht must be run remotly
044: * @see EJB2.0 specification Chapter 6.
045: * @author Ph Coq, Ph Durieux
046: */
047:
048: public abstract class A_ClientView extends JTestCase {
049:
050: public A_ClientView(String name) {
051: super (name);
052: }
053:
054: /**
055: * @return TargetSLLocalHome
056: */
057: public abstract TargetSLLocalHome getLocalHome() throws Exception;
058:
059: /**
060: * Lookup a LocalHome Object
061: *
062: * This test verify that we can look up a LocalHome Object
063: * via the root context
064: */
065:
066: public void testLocalLookup() throws Exception {
067: TargetSLLocalHome h = null;
068: h = getLocalHome();
069: assertTrue(h != null);
070: }
071:
072: /**
073: * EJB Reference
074: *
075: * This test verify that we can look up a Home Object of a bean in the same ejbjar file
076: * via the java:comp/env subcontext using an ejb-reference contains an ejb-link.
077: */
078: public void testEjbRef() throws Exception {
079:
080: TargetSLHome home = null;
081: String bName = "java:comp/env/ejb/targetremotelink";
082: home = (TargetSLHome) PortableRemoteObject.narrow(ictx
083: .lookup(bName), TargetSLHome.class);
084: assertTrue(home != null);
085: }
086:
087: /**
088: * EJB Reference
089: *
090: * This test verify that we can look up a Home Object of a bean (in the same ejbjar file)
091: * via the java:comp/env subcontext using an ejb-reference with a jonas-ejb-reference.
092: */
093: public void testEjbRefWithJonasEjbRef() throws Exception {
094:
095: TargetSLHome home = null;
096: String bName = "java:comp/env/ejb/targetremotenolink";
097: home = (TargetSLHome) PortableRemoteObject.narrow(ictx
098: .lookup(bName), TargetSLHome.class);
099: assertTrue(home != null);
100: }
101:
102: /**
103: * EJBLocal Reference
104: *
105: * This test verify that we can look up a LocalHome Object
106: * via the java:comp/env subcontext
107: */
108:
109: public void testEjbLocalRef() throws Exception {
110:
111: TargetSLLocalHome home = null;
112: String bName = "java:comp/env/ejb/targetlocal";
113: home = (TargetSLLocalHome) ictx.lookup(bName);
114: assertTrue(home != null);
115: }
116:
117: /**
118: * This test verify we can create a Local session bean and remove it
119: */
120: public void testLocalCreateRemove() throws Exception {
121: TargetLocal tl = getLocalHome().create();
122: tl.remove();
123: }
124:
125: /**
126: * This test verify we can create a Local session , access to the bean
127: * via its local interface and remove it
128: * It verifies we cannot access to the bean after remove
129: */
130: public void testLocalBusinessMethod1() throws Exception {
131: TargetLocal tl = getLocalHome().create();
132: assertEquals(20, tl.getTwenty());
133: tl.remove();
134: try {
135: tl.lmethod2("Bye");
136: fail("NoSuchObjectLocalException must be raised");
137: } catch (NoSuchObjectLocalException e) {
138: }
139: }
140:
141: /**
142: * Same test than testLocalBusinessMethod1 but two calls to businessmethod
143: */
144: public void testLocalBusinessMethod2() throws Exception {
145: TargetLocal tl = getLocalHome().create();
146: assertEquals(20, tl.getTwenty());
147: assertEquals(20, tl.getTwenty());
148: tl.remove();
149: }
150:
151: /**
152: * test 3 Local Business Methods
153: */
154: public void testLocalBusinessMethod3() throws Exception {
155: TargetLocal tl = getLocalHome().create();
156: assertEquals(20, tl.getTwenty());
157: tl.lmethod2("Hello");
158: assertEquals(20, tl.getTwenty());
159: tl.remove();
160: }
161:
162: /**
163: * test EJBLocalObject.isIdentical on the same bean
164: */
165: public void testLocalIsIdenticalOnSameBean() throws Exception {
166: TargetLocal tl = getLocalHome().create();
167: assertTrue(tl.isIdentical(tl));
168: tl.remove();
169: }
170:
171: /**
172: * test EJBLocalObject.getPrimary Key
173: * This test verify that an EJB Exception must be catched
174: */
175: public void testLocalGetPrimaryKey() throws Exception {
176: TargetLocal tl = getLocalHome().create();
177: try {
178: tl.getPrimaryKey();
179: fail("getPrimaryKey should raise EJBException on a session bean");
180: } catch (EJBException e) {
181: } finally {
182: tl.remove();
183: }
184: }
185:
186: /**
187: * test that EJBLocalHome.remove(pk) should raise EJBException (API) or
188: * RemoveException (spec EJB 2.0 6.3.2)
189: */
190: public void testLocalRemoveByPK() throws Exception {
191: Object pk = null;
192: try {
193: getLocalHome().remove(pk);
194: fail("getPrimaryKey should raise Exception on a session bean");
195: } catch (EJBException e) {
196: } catch (RemoveException e) {
197: }
198: }
199:
200: }
|