001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.test.stateless;
017:
018: import java.util.Properties;
019:
020: import javax.ejb.EJBMetaData;
021: import javax.ejb.Handle;
022: import javax.ejb.HomeHandle;
023: import javax.naming.Context;
024: import javax.naming.InitialContext;
025:
026: import org.apache.openejb.test.TestManager;
027:
028: /**
029: * [1] Should be run as the first test suite of the StatelessTestClients
030: *
031: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
032: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
033: */
034: public class StatelessContainerTxTests extends
035: org.apache.openejb.test.NamedTestCase {
036:
037: public final static String jndiEJBHomeEntry = "client/tests/stateless/ContainerManagedTransactionTests/EJBHome";
038:
039: protected ContainerTxStatelessHome ejbHome;
040: protected ContainerTxStatelessObject ejbObject;
041:
042: protected EJBMetaData ejbMetaData;
043: protected HomeHandle ejbHomeHandle;
044: protected Handle ejbHandle;
045: protected Integer ejbPrimaryKey;
046:
047: protected InitialContext initialContext;
048:
049: public StatelessContainerTxTests() {
050: super ("Stateless.ContainerManagedTransaction.");
051: }
052:
053: /**
054: * Sets up the fixture, for example, open a network connection.
055: * This method is called before a test is executed.
056: */
057: protected void setUp() throws Exception {
058:
059: Properties properties = TestManager.getServer()
060: .getContextEnvironment();
061: //properties.put(Context.SECURITY_PRINCIPAL, "STATELESS_test00_CLIENT");
062: //properties.put(Context.SECURITY_CREDENTIALS, "STATELESS_test00_CLIENT");
063:
064: initialContext = new InitialContext(properties);
065:
066: /*[1] Get bean */
067: Object obj = initialContext.lookup(jndiEJBHomeEntry);
068: ejbHome = (ContainerTxStatelessHome) javax.rmi.PortableRemoteObject
069: .narrow(obj, ContainerTxStatelessHome.class);
070: ejbObject = ejbHome.create();
071:
072: /*[2] Create database table */
073: TestManager.getDatabase().createAccountTable();
074: }
075:
076: /**
077: * Tears down the fixture, for example, close a network connection.
078: * This method is called after a test is executed.
079: */
080: protected void tearDown() throws Exception {
081: /*[1] Drop database table */
082: TestManager.getDatabase().dropAccountTable();
083: }
084:
085: public void test01_txMandatory_withoutTx() {
086: try {
087: String expected = "ping";
088: String actual = ejbObject.txMandatoryMethod(expected);
089: assertEquals("The method invocation was invalid.",
090: expected, actual);
091: } catch (Exception e) {
092: fail("Received Exception " + e.getClass() + " : "
093: + e.getMessage());
094: }
095: }
096:
097: public void test02_txNever_withoutTx() {
098: try {
099: String expected = "ping";
100: String actual = ejbObject.txNeverMethod(expected);
101: assertEquals("The method invocation was invalid.",
102: expected, actual);
103: } catch (Exception e) {
104: fail("Received Exception " + e.getClass() + " : "
105: + e.getMessage());
106: }
107: }
108:
109: public void test03_txNotSupported_withoutTx() {
110: try {
111: String expected = "ping";
112: String actual = ejbObject.txNotSupportedMethod(expected);
113: assertEquals("The method invocation was invalid.",
114: expected, actual);
115: } catch (Exception e) {
116: fail("Received Exception " + e.getClass() + " : "
117: + e.getMessage());
118: }
119: }
120:
121: public void test04_txRequired_withoutTx() {
122: try {
123: String expected = "ping";
124: String actual = ejbObject.txRequiredMethod(expected);
125: assertEquals("The method invocation was invalid.",
126: expected, actual);
127: } catch (Exception e) {
128: fail("Received Exception " + e.getClass() + " : "
129: + e.getMessage());
130: }
131: }
132:
133: public void test05_txRequiresNew_withoutTx() {
134: try {
135: String expected = "ping";
136: String actual = ejbObject.txRequiresNewMethod(expected);
137: assertEquals("The method invocation was invalid.",
138: expected, actual);
139: } catch (Exception e) {
140: fail("Received Exception " + e.getClass() + " : "
141: + e.getMessage());
142: }
143: }
144:
145: public void test06_txSupports_withoutTx() {
146: try {
147: String expected = "ping";
148: String actual = ejbObject.txSupportsMethod(expected);
149: assertEquals("The method invocation was invalid.",
150: expected, actual);
151: } catch (Exception e) {
152: fail("Received Exception " + e.getClass() + " : "
153: + e.getMessage());
154: }
155: }
156:
157: public void test07_txMandatory_withTx() {
158: try {
159: String expected = "ping";
160: String actual = ejbObject.txMandatoryMethod(expected);
161: assertEquals("The method invocation was invalid.",
162: expected, actual);
163: } catch (Exception e) {
164: fail("Received Exception " + e.getClass() + " : "
165: + e.getMessage());
166: }
167: }
168:
169: public void test08_txNever_withTx() {
170: try {
171: String expected = "ping";
172: String actual = ejbObject.txNeverMethod(expected);
173: assertEquals("The method invocation was invalid.",
174: expected, actual);
175: } catch (Exception e) {
176: fail("Received Exception " + e.getClass() + " : "
177: + e.getMessage());
178: }
179: }
180:
181: public void test09_txNotSupported_withTx() {
182: try {
183: String expected = "ping";
184: String actual = ejbObject.txNotSupportedMethod(expected);
185: assertEquals("The method invocation was invalid.",
186: expected, actual);
187: } catch (Exception e) {
188: fail("Received Exception " + e.getClass() + " : "
189: + e.getMessage());
190: }
191: }
192:
193: public void test10_txRequired_withTx() {
194: try {
195: String expected = "ping";
196: String actual = ejbObject.txRequiredMethod(expected);
197: assertEquals("The method invocation was invalid.",
198: expected, actual);
199: } catch (Exception e) {
200: fail("Received Exception " + e.getClass() + " : "
201: + e.getMessage());
202: }
203: }
204:
205: public void test11_txRequiresNew_withTx() {
206: try {
207: String expected = "ping";
208: String actual = ejbObject.txRequiresNewMethod(expected);
209: assertEquals("The method invocation was invalid.",
210: expected, actual);
211: } catch (Exception e) {
212: fail("Received Exception " + e.getClass() + " : "
213: + e.getMessage());
214: }
215: }
216:
217: public void test12_txSupports_withTx() {
218: try {
219: String expected = "ping";
220: String actual = ejbObject.txSupportsMethod(expected);
221: assertEquals("The method invocation was invalid.",
222: expected, actual);
223: } catch (Exception e) {
224: fail("Received Exception " + e.getClass() + " : "
225: + e.getMessage());
226: }
227: }
228:
229: public void test01_txMandatory_withoutTx_appException() {
230: try {
231: String expected = "ping";
232: String actual = ejbObject.txMandatoryMethod(expected);
233: assertEquals("The method invocation was invalid.",
234: expected, actual);
235: } catch (Exception e) {
236: fail("Received Exception " + e.getClass() + " : "
237: + e.getMessage());
238: }
239: }
240:
241: public void test02_txNever_withoutTx_appException() {
242: try {
243: String expected = "ping";
244: String actual = ejbObject.txNeverMethod(expected);
245: assertEquals("The method invocation was invalid.",
246: expected, actual);
247: } catch (Exception e) {
248: fail("Received Exception " + e.getClass() + " : "
249: + e.getMessage());
250: }
251: }
252:
253: public void test03_txNotSupported_withoutTx_appException() {
254: try {
255: String expected = "ping";
256: String actual = ejbObject.txNotSupportedMethod(expected);
257: assertEquals("The method invocation was invalid.",
258: expected, actual);
259: } catch (Exception e) {
260: fail("Received Exception " + e.getClass() + " : "
261: + e.getMessage());
262: }
263: }
264:
265: public void test04_txRequired_withoutTx_appException() {
266: try {
267: String expected = "ping";
268: String actual = ejbObject.txRequiredMethod(expected);
269: assertEquals("The method invocation was invalid.",
270: expected, actual);
271: } catch (Exception e) {
272: fail("Received Exception " + e.getClass() + " : "
273: + e.getMessage());
274: }
275: }
276:
277: public void test05_txRequiresNew_withoutTx_appException() {
278: try {
279: String expected = "ping";
280: String actual = ejbObject.txRequiresNewMethod(expected);
281: assertEquals("The method invocation was invalid.",
282: expected, actual);
283: } catch (Exception e) {
284: fail("Received Exception " + e.getClass() + " : "
285: + e.getMessage());
286: }
287: }
288:
289: public void test06_txSupports_withoutTx_appException() {
290: try {
291: String expected = "ping";
292: String actual = ejbObject.txSupportsMethod(expected);
293: assertEquals("The method invocation was invalid.",
294: expected, actual);
295: } catch (Exception e) {
296: fail("Received Exception " + e.getClass() + " : "
297: + e.getMessage());
298: }
299: }
300:
301: public void test07_txMandatory_withTx_appException() {
302: try {
303: String expected = "ping";
304: String actual = ejbObject.txMandatoryMethod(expected);
305: assertEquals("The method invocation was invalid.",
306: expected, actual);
307: } catch (Exception e) {
308: fail("Received Exception " + e.getClass() + " : "
309: + e.getMessage());
310: }
311: }
312:
313: public void test08_txNever_withTx_appException() {
314: try {
315: String expected = "ping";
316: String actual = ejbObject.txNeverMethod(expected);
317: assertEquals("The method invocation was invalid.",
318: expected, actual);
319: } catch (Exception e) {
320: fail("Received Exception " + e.getClass() + " : "
321: + e.getMessage());
322: }
323: }
324:
325: public void test09_txNotSupported_withTx_appException() {
326: try {
327: String expected = "ping";
328: String actual = ejbObject.txNotSupportedMethod(expected);
329: assertEquals("The method invocation was invalid.",
330: expected, actual);
331: } catch (Exception e) {
332: fail("Received Exception " + e.getClass() + " : "
333: + e.getMessage());
334: }
335: }
336:
337: public void test10_txRequired_withTx_appException() {
338: try {
339: String expected = "ping";
340: String actual = ejbObject.txRequiredMethod(expected);
341: assertEquals("The method invocation was invalid.",
342: expected, actual);
343: } catch (Exception e) {
344: fail("Received Exception " + e.getClass() + " : "
345: + e.getMessage());
346: }
347: }
348:
349: public void test11_txRequiresNew_withTx_appException() {
350: try {
351: String expected = "ping";
352: String actual = ejbObject.txRequiresNewMethod(expected);
353: assertEquals("The method invocation was invalid.",
354: expected, actual);
355: } catch (Exception e) {
356: fail("Received Exception " + e.getClass() + " : "
357: + e.getMessage());
358: }
359: }
360:
361: public void test12_txSupports_withTx_appException() {
362: try {
363: String expected = "ping";
364: String actual = ejbObject.txSupportsMethod(expected);
365: assertEquals("The method invocation was invalid.",
366: expected, actual);
367: } catch (Exception e) {
368: fail("Received Exception " + e.getClass() + " : "
369: + e.getMessage());
370: }
371: }
372:
373: public void test01_txMandatory_withoutTx_sysException() {
374: try {
375: String expected = "ping";
376: String actual = ejbObject.txMandatoryMethod(expected);
377: assertEquals("The method invocation was invalid.",
378: expected, actual);
379: } catch (Exception e) {
380: fail("Received Exception " + e.getClass() + " : "
381: + e.getMessage());
382: }
383: }
384:
385: public void test02_txNever_withoutTx_sysException() {
386: try {
387: String expected = "ping";
388: String actual = ejbObject.txNeverMethod(expected);
389: assertEquals("The method invocation was invalid.",
390: expected, actual);
391: } catch (Exception e) {
392: fail("Received Exception " + e.getClass() + " : "
393: + e.getMessage());
394: }
395: }
396:
397: public void test03_txNotSupported_withoutTx_sysException() {
398: try {
399: String expected = "ping";
400: String actual = ejbObject.txNotSupportedMethod(expected);
401: assertEquals("The method invocation was invalid.",
402: expected, actual);
403: } catch (Exception e) {
404: fail("Received Exception " + e.getClass() + " : "
405: + e.getMessage());
406: }
407: }
408:
409: public void test04_txRequired_withoutTx_sysException() {
410: try {
411: String expected = "ping";
412: String actual = ejbObject.txRequiredMethod(expected);
413: assertEquals("The method invocation was invalid.",
414: expected, actual);
415: } catch (Exception e) {
416: fail("Received Exception " + e.getClass() + " : "
417: + e.getMessage());
418: }
419: }
420:
421: public void test05_txRequiresNew_withoutTx_sysException() {
422: try {
423: String expected = "ping";
424: String actual = ejbObject.txRequiresNewMethod(expected);
425: assertEquals("The method invocation was invalid.",
426: expected, actual);
427: } catch (Exception e) {
428: fail("Received Exception " + e.getClass() + " : "
429: + e.getMessage());
430: }
431: }
432:
433: public void test06_txSupports_withoutTx_sysException() {
434: try {
435: String expected = "ping";
436: String actual = ejbObject.txSupportsMethod(expected);
437: assertEquals("The method invocation was invalid.",
438: expected, actual);
439: } catch (Exception e) {
440: fail("Received Exception " + e.getClass() + " : "
441: + e.getMessage());
442: }
443: }
444:
445: public void test07_txMandatory_withTx_sysException() {
446: try {
447: String expected = "ping";
448: String actual = ejbObject.txMandatoryMethod(expected);
449: assertEquals("The method invocation was invalid.",
450: expected, actual);
451: } catch (Exception e) {
452: fail("Received Exception " + e.getClass() + " : "
453: + e.getMessage());
454: }
455: }
456:
457: public void test08_txNever_withTx_sysException() {
458: try {
459: String expected = "ping";
460: String actual = ejbObject.txNeverMethod(expected);
461: assertEquals("The method invocation was invalid.",
462: expected, actual);
463: } catch (Exception e) {
464: fail("Received Exception " + e.getClass() + " : "
465: + e.getMessage());
466: }
467: }
468:
469: public void test09_txNotSupported_withTx_sysException() {
470: try {
471: String expected = "ping";
472: String actual = ejbObject.txNotSupportedMethod(expected);
473: assertEquals("The method invocation was invalid.",
474: expected, actual);
475: } catch (Exception e) {
476: fail("Received Exception " + e.getClass() + " : "
477: + e.getMessage());
478: }
479: }
480:
481: public void test10_txRequired_withTx_sysException() {
482: try {
483: String expected = "ping";
484: String actual = ejbObject.txRequiredMethod(expected);
485: assertEquals("The method invocation was invalid.",
486: expected, actual);
487: } catch (Exception e) {
488: fail("Received Exception " + e.getClass() + " : "
489: + e.getMessage());
490: }
491: }
492:
493: public void test11_txRequiresNew_withTx_sysException() {
494: try {
495: String expected = "ping";
496: String actual = ejbObject.txRequiresNewMethod(expected);
497: assertEquals("The method invocation was invalid.",
498: expected, actual);
499: } catch (Exception e) {
500: fail("Received Exception " + e.getClass() + " : "
501: + e.getMessage());
502: }
503: }
504:
505: public void test12_txSupports_withTx_sysException() {
506: try {
507: String expected = "ping";
508: String actual = ejbObject.txSupportsMethod(expected);
509: assertEquals("The method invocation was invalid.",
510: expected, actual);
511: } catch (Exception e) {
512: fail("Received Exception " + e.getClass() + " : "
513: + e.getMessage());
514: }
515: }
516: }
|