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: F_BeanToBeanTx.java 3508 2003-10-14 07:58:54Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.transaction;
027:
028: import javax.naming.NamingException;
029: import javax.rmi.PortableRemoteObject;
030: import junit.framework.Test;
031: import junit.framework.TestSuite;
032: import org.objectweb.jonas.jtests.beans.transacted.Simple;
033: import org.objectweb.jonas.jtests.beans.transacted.SimpleEHome;
034: import org.objectweb.jonas.jtests.beans.transacted.SimpleSHome;
035: import org.objectweb.jonas.jtests.util.JTestCase;
036:
037: /**
038: * Test for Bean to Bean transactions
039: * @author Ph.Durieux
040: */
041: public class F_BeanToBeanTx extends JTestCase {
042:
043: protected static SimpleSHome syhome = null;
044: protected static SimpleSHome sfhome = null;
045: protected static SimpleSHome slhome = null;
046: protected static SimpleEHome echome = null;
047: protected static SimpleEHome ec2home = null;
048: protected static SimpleEHome ebhome = null;
049:
050: public F_BeanToBeanTx(String name) {
051: super (name);
052: }
053:
054: protected void setUp() {
055: super .setUp();
056: useBeans("transacted", true);
057: if (syhome == null) {
058: String BEAN_HOME = "transactedSimpleSYHome";
059: try {
060: syhome = (SimpleSHome) PortableRemoteObject.narrow(ictx
061: .lookup(BEAN_HOME), SimpleSHome.class);
062: } catch (NamingException e) {
063: fail("Cannot get " + BEAN_HOME + ":" + e);
064: }
065: }
066: if (sfhome == null) {
067: String BEAN_HOME = "transactedSimpleSFHome";
068: try {
069: sfhome = (SimpleSHome) PortableRemoteObject.narrow(ictx
070: .lookup(BEAN_HOME), SimpleSHome.class);
071: } catch (NamingException e) {
072: fail("Cannot get " + BEAN_HOME + ":" + e);
073: }
074: }
075: if (slhome == null) {
076: String BEAN_HOME = "transactedSimpleSLHome";
077: try {
078: slhome = (SimpleSHome) PortableRemoteObject.narrow(ictx
079: .lookup(BEAN_HOME), SimpleSHome.class);
080: } catch (NamingException e) {
081: fail("Cannot get " + BEAN_HOME + ":" + e);
082: }
083: }
084: if (echome == null) {
085: String BEAN_HOME = "transactedSimpleECHome";
086: try {
087: echome = (SimpleEHome) PortableRemoteObject.narrow(ictx
088: .lookup(BEAN_HOME), SimpleEHome.class);
089: } catch (NamingException e) {
090: fail("Cannot get " + BEAN_HOME + ":" + e);
091: }
092: }
093: if (ec2home == null) {
094: String BEAN_HOME = "transactedSimpleEC2Home";
095: try {
096: ec2home = (SimpleEHome) PortableRemoteObject.narrow(
097: ictx.lookup(BEAN_HOME), SimpleEHome.class);
098: } catch (NamingException e) {
099: fail("Cannot get " + BEAN_HOME + ":" + e);
100: }
101: }
102: if (ebhome == null) {
103: String BEAN_HOME = "transactedSimpleEBHome";
104: try {
105: ebhome = (SimpleEHome) PortableRemoteObject.narrow(ictx
106: .lookup(BEAN_HOME), SimpleEHome.class);
107: } catch (NamingException e) {
108: fail("Cannot get " + BEAN_HOME + ":" + e);
109: }
110: }
111: }
112:
113: /**
114: * SL/Required -> EC/RequiresNew
115: */
116: public void testSLToEC() throws Exception {
117: Simple s1 = slhome.create();
118: Simple s2 = echome.create(30);
119: assertEquals(true, s1.call_requires_new_on(s2));
120: s1.remove();
121: s2.remove();
122: }
123:
124: /**
125: * SL/Required -> EC2/RequiresNew
126: */
127: public void testSLToEC2() throws Exception {
128: Simple s1 = slhome.create();
129: Simple s2 = ec2home.create(30);
130: assertEquals(true, s1.call_requires_new_on(s2));
131: s1.remove();
132: s2.remove();
133: }
134:
135: /**
136: * SF/Required -> EC/RequiresNew
137: */
138: public void testSFToEC() throws Exception {
139: Simple s1 = sfhome.create();
140: Simple s2 = echome.create(30);
141: assertEquals(true, s1.call_requires_new_on(s2));
142: s1.remove();
143: s2.remove();
144: }
145:
146: /**
147: * SF/Required -> EC2/RequiresNew
148: */
149: public void testSFToEC2() throws Exception {
150: Simple s1 = sfhome.create();
151: Simple s2 = ec2home.create(30);
152: assertEquals(true, s1.call_requires_new_on(s2));
153: s1.remove();
154: s2.remove();
155: }
156:
157: /**
158: * SY/Required -> EC/RequiresNew
159: */
160: public void testSYToEC() throws Exception {
161: Simple s1 = syhome.create();
162: Simple s2 = echome.create(30);
163: assertEquals(true, s1.call_requires_new_on(s2));
164: s1.remove();
165: s2.remove();
166: }
167:
168: /**
169: * SY/Required -> EC2/RequiresNew
170: */
171: public void testSYToEC2() throws Exception {
172: Simple s1 = syhome.create();
173: Simple s2 = ec2home.create(30);
174: assertEquals(true, s1.call_requires_new_on(s2));
175: s1.remove();
176: s2.remove();
177: }
178:
179: /**
180: * EC/Required -> EC/RequiresNew
181: */
182: public void testECToEC() throws Exception {
183: Simple s1 = echome.create(31);
184: Simple s2 = echome.create(32);
185: assertEquals(true, s1.call_requires_new_on(s2));
186: s1.remove();
187: s2.remove();
188: }
189:
190: /**
191: * EC2/Required -> EC2/RequiresNew
192: */
193: public void testEC2ToEC2() throws Exception {
194: Simple s1 = ec2home.create(31);
195: Simple s2 = ec2home.create(32);
196: assertEquals(true, s1.call_requires_new_on(s2));
197: s1.remove();
198: s2.remove();
199: }
200:
201: /**
202: * EB/Required -> EC/RequiresNew
203: */
204: public void testEBToEC() throws Exception {
205: Simple s1 = ebhome.create(31);
206: Simple s2 = echome.create(32);
207: assertEquals(true, s1.call_requires_new_on(s2));
208: s1.remove();
209: s2.remove();
210: }
211:
212: /**
213: * EB/Required -> EC2/RequiresNew
214: */
215: public void testEBToEC2() throws Exception {
216: Simple s1 = ebhome.create(31);
217: Simple s2 = ec2home.create(32);
218: assertEquals(true, s1.call_requires_new_on(s2));
219: s1.remove();
220: s2.remove();
221: }
222:
223: /**
224: * SL/Required -> SY/RequiresNew
225: */
226: public void testSLToSY() throws Exception {
227: Simple s1 = slhome.create();
228: Simple s2 = syhome.create();
229: assertEquals(true, s1.call_requires_new_on(s2));
230: s1.remove();
231: s2.remove();
232: }
233:
234: /**
235: * SF/Required -> SY/RequiresNew
236: */
237: public void testSFToSY() throws Exception {
238: Simple s1 = sfhome.create();
239: Simple s2 = syhome.create();
240: assertEquals(true, s1.call_requires_new_on(s2));
241: s1.remove();
242: s2.remove();
243: }
244:
245: /**
246: * SY/Required -> SY/RequiresNew
247: */
248: public void testSYToSY() throws Exception {
249: Simple s1 = syhome.create();
250: Simple s2 = syhome.create();
251: assertEquals(true, s1.call_requires_new_on(s2));
252: s1.remove();
253: s2.remove();
254: }
255:
256: /**
257: * EC/Required -> SY/RequiresNew
258: */
259: public void testECToSY() throws Exception {
260: Simple s1 = echome.create(31);
261: Simple s2 = syhome.create();
262: assertEquals(true, s1.call_requires_new_on(s2));
263: s1.remove();
264: s2.remove();
265: }
266:
267: /**
268: * EC2/Required -> SY/RequiresNew
269: */
270: public void testEC2ToSY() throws Exception {
271: Simple s1 = ec2home.create(31);
272: Simple s2 = syhome.create();
273: assertEquals(true, s1.call_requires_new_on(s2));
274: s1.remove();
275: s2.remove();
276: }
277:
278: public void testSupports2Required() throws Exception {
279: Simple s2 = sfhome.create();
280: assertEquals(true, s2.supports_call_required());
281: s2.remove();
282: }
283:
284: /**
285: * EB/Required -> SY/RequiresNew
286: */
287: public void testEBToSY() throws Exception {
288: Simple s1 = ebhome.create(31);
289: Simple s2 = syhome.create();
290: assertEquals(true, s1.call_requires_new_on(s2));
291: s1.remove();
292: s2.remove();
293: }
294:
295: public static Test suite() {
296: return new TestSuite(F_BeanToBeanTx.class);
297: }
298:
299: public static void main(String args[]) {
300: String testtorun = null;
301: // Get args
302: for (int argn = 0; argn < args.length; argn++) {
303: String s_arg = args[argn];
304: Integer i_arg;
305: if (s_arg.equals("-n")) {
306: testtorun = args[++argn];
307: }
308: }
309: if (testtorun == null) {
310: junit.textui.TestRunner.run(suite());
311: } else {
312: junit.textui.TestRunner.run(new F_BeanToBeanTx(testtorun));
313: }
314: }
315: }
|