001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.cts.test;
023:
024: import java.io.ByteArrayInputStream;
025: import java.io.ObjectInputStream;
026: import java.io.ByteArrayOutputStream;
027: import java.io.ObjectOutputStream;
028:
029: import java.util.Collection;
030: import java.util.Iterator;
031: import java.util.Properties;
032:
033: import javax.ejb.Handle;
034: import javax.ejb.HomeHandle;
035: import javax.ejb.EJBMetaData;
036:
037: import javax.naming.InitialContext;
038:
039: import javax.rmi.PortableRemoteObject;
040:
041: import javax.transaction.UserTransaction;
042:
043: import org.jboss.test.cts.jms.ContainerMBox;
044: import org.jboss.test.cts.interfaces.CtsBmpHome;
045: import org.jboss.test.cts.interfaces.CtsBmp;
046: import org.jboss.test.cts.interfaces.UserTransactionTester;
047: import org.jboss.test.cts.interfaces.StatelessSession;
048: import org.jboss.test.cts.keys.AccountPK;
049:
050: import junit.framework.Test;
051:
052: import org.jboss.test.JBossTestCase;
053:
054: /**
055: * Class BmpTest
056: *
057: * @author Author: kimptoc
058: * @version $Revision: 57211 $
059: */
060:
061: public class BmpUnitTestCase extends JBossTestCase {
062: private ContainerMBox mbx = null;
063: public static final String BEAN_NAME = "GuysName";
064: public static final String BEAN_OTHER_NAME = "OtherGuysName";
065: public static final String BEAN_PK_007 = "007";
066:
067: /**
068: * Constructor BmpTest
069: *
070: * @param name
071: *
072: */
073: public BmpUnitTestCase(String name) {
074: super (name);
075: }
076:
077: /**
078: * Return the bean home interface.
079: */
080: private CtsBmpHome getHome() throws Exception {
081: return (CtsBmpHome) getInitialContext()
082: .lookup("ejbcts/BMPBean");
083: }
084:
085: /**
086: * Create a bean instance.
087: */
088: private CtsBmp doEjbCreate(AccountPK pk, String name)
089: throws Exception {
090: return getHome().create(pk, name);
091: }
092:
093: /**
094: * Method testEjbCreate
095: * EJB 1.1 [8.3.1] p. 89
096: * An entity bean's home interface can define zero or more create(...)
097: * methods.
098: *
099: * @throws Exception
100: *
101: */
102: public void testEjbCreate() throws Exception {
103: getLog()
104: .debug(
105: "**************************************************************");
106: getLog().debug(" testEjbCreate()");
107:
108: CtsBmp bean = null;
109:
110: try {
111: getLog().debug("create bean, name=" + BEAN_NAME);
112:
113: bean = doEjbCreate(new AccountPK(BEAN_PK_007), BEAN_NAME);
114: } catch (Exception ex) {
115: getLog().error("Error in bmptest", ex);
116: fail("testEjbCreate has failed!");
117: }
118:
119: assertEquals(BEAN_NAME, bean.getPersonsName());
120:
121: getLog()
122: .debug(
123: "**************************************************************");
124: }
125:
126: /**
127: * Method testEjbFinder
128: * EJB 1.1 [8.3.2] p. 90
129: * An entity bean's home interface defines one or more finder methods,
130: * one for each way to find and entity object or collection of entity objects
131: * within the home.
132: *
133: * Test stategy: Create a bean. Use the bean that has been previously
134: * created, and call the finder method. Make sure that
135: * a result set is returned and that the bean returned
136: * has the same name associated with it as the bean that
137: * was previously created.
138: *
139: * @throws Exception
140: *
141: */
142: public void testEjbFinder() throws Exception {
143: getLog()
144: .debug(
145: "**************************************************************");
146: getLog().debug(" testEjbFinder()");
147:
148: CtsBmp bean = null;
149:
150: try {
151: CtsBmpHome home = getHome();
152:
153: // First create a bean instance to find
154: getLog().debug("Create bean, name=" + BEAN_NAME);
155: doEjbCreate(new AccountPK(BEAN_PK_007), BEAN_NAME);
156:
157: getLog().debug("Find bean, name=" + BEAN_NAME);
158:
159: Collection clct = home.findByPersonsName(BEAN_NAME);
160: getLog().debug("Verify result set not empty");
161: assertTrue(!clct.isEmpty());
162: getLog().debug("OK");
163: getLog().debug("Bean result set:");
164: for (Iterator itr = clct.iterator(); itr.hasNext();) {
165: bean = (CtsBmp) itr.next();
166: getLog().debug(
167: "Name from Bean=" + bean.getPersonsName());
168: getLog().debug("Verify bean name equals: " + BEAN_NAME);
169: assertTrue(bean.getPersonsName().trim().equals(
170: BEAN_NAME));
171: getLog().debug("OK");
172: }
173: } catch (Exception ex) {
174: getLog().error("Error in bmptest", ex);
175: fail("testEjbFinder has failed!");
176: }
177:
178: getLog()
179: .debug(
180: "**************************************************************");
181: }
182:
183: /**
184: * Method testEjbRemove
185: * EJB 1.1 [8.3.3] p. 90
186: *
187: * Test Strategy:
188: * 1) Create a bean to remove.
189: * 2) Attempt a simple remove using the remote interface.
190: * 3) Create a bean to remove.
191: * 4) Attempt a simple remove using the home interface and primary key.
192: * 5) Create a bean to remove.
193: * 6) Try to remove the instance using its handle.
194: * 7) Try to access the instance. This should result in a
195: * java.rmi.NoSuchObjectException
196: *
197: * @throws Exception
198: */
199: public void testEjbRemove() throws Exception {
200: getLog()
201: .debug(
202: "**************************************************************");
203: getLog().debug(" testEjbRemove()");
204:
205: CtsBmp bean = null;
206:
207: try {
208: CtsBmpHome home = getHome();
209: AccountPK pk = new AccountPK(BEAN_PK_007);
210:
211: getLog().debug("Create a bean...");
212: bean = doEjbCreate(pk, BEAN_NAME);
213: getLog().debug("OK");
214:
215: getLog().debug("Delete with bean.remove()...");
216: bean.remove();
217: getLog().debug("OK");
218:
219: getLog().debug("Recreate the bean...");
220: bean = doEjbCreate(pk, BEAN_NAME);
221: getLog().debug("OK");
222:
223: getLog().debug("Remove the bean using primary key...");
224: home.remove(pk);
225: getLog().debug("OK");
226:
227: getLog().debug("Reconstitute the bean...");
228: bean = doEjbCreate(pk, BEAN_NAME);
229: getLog().debug("OK");
230:
231: getLog().debug("Get Handle object...");
232: Handle hn = bean.getHandle();
233: getLog().debug("OK");
234:
235: getLog().debug("Remove the bean using the handle...");
236: home.remove(hn);
237: getLog().debug("OK");
238:
239: getLog()
240: .debug(
241: "Bean remove, try to use.. "
242: + "Should get 'java.rmi.NoSuchObjectException'...");
243: try {
244: bean.getPersonsName();
245: } catch (java.rmi.NoSuchObjectException nsoex) {
246: getLog().debug("OK");
247: } catch (Exception ex) {
248: fail("Got Exception: expecting NoSuchObjectException"
249: + ex.toString());
250: }
251: } catch (Exception ex) {
252: getLog().error("Error in bmptest", ex);
253: fail("testEjbRemove has failed!");
254: }
255:
256: getLog()
257: .debug(
258: "**************************************************************");
259: }
260:
261: /**
262: * Method testEjbLifeCycle
263: * EJB 1.1 [8.4] p. 92
264: *
265: * A client can get a reference to an existing entity objects
266: * remote interface in any of the following ways:
267: * - Receive the reference as a parameter in a method call.
268: * - Find the entity object using a finder method defined in the EB home i/f.
269: * - Obtain the reference from the entity objects' handle.
270: *
271: * @throws Exception
272: *
273: */
274: public void testEjbLifeCycle() {
275: getLog()
276: .debug(
277: "**************************************************************");
278: getLog().debug(" testEjbLifeCycle()");
279:
280: CtsBmp bean = null;
281:
282: try {
283: CtsBmpHome home = getHome();
284: AccountPK pk = new AccountPK(BEAN_PK_007);
285:
286: getLog().debug("Create a bean...");
287: doEjbCreate(pk, BEAN_NAME);
288: getLog().debug("OK");
289:
290: getLog().debug(
291: "Use a finder method to retrieve the bean...");
292: bean = home.findByPrimaryKey(pk);
293: getLog().debug("OK");
294:
295: getLog()
296: .debug(
297: "Assert it is the same bean as passed to a method...");
298: // Send to a method as a reference, make sure it is usable by the method
299: assertTrue(this .gotRefOkay(bean, BEAN_NAME));
300: getLog().debug("OK");
301:
302: // Execute a business method
303: getLog().debug("Calling setter as a business method...");
304: bean.setPersonsName(BEAN_OTHER_NAME);
305: getLog().debug("OK");
306:
307: // Get the home interface
308: getLog().debug("Get the HOME interface...");
309: home = (CtsBmpHome) bean.getEJBHome();
310: getLog().debug("OK");
311:
312: // Get the primary key
313: getLog().debug("Get the bean's Primary Key...");
314: pk = (AccountPK) bean.getPrimaryKey();
315: getLog().debug("OK");
316:
317: getLog().debug("Get the bean's handle...");
318: Handle hn = bean.getHandle();
319: getLog().debug("OK");
320:
321: // Remove
322: getLog().debug("Remove the bean...");
323: bean.remove();
324: getLog().debug("OK");
325: } catch (Exception ex) {
326: getLog().error("Error in bmptest", ex);
327: fail("testEjbCreate has failed!");
328: }
329:
330: getLog()
331: .debug(
332: "**************************************************************");
333: }
334:
335: /**
336: * Method testPrimaryKeyObjectIdentity
337: * EJB 1.1 [8.5] p. 92-93
338: *
339: * Every entity object has a unique identity within its home. If
340: * two entity objects have the same home and the same primary key
341: * they are considered identitcal.
342: *
343: * getPrimaryKey() always returns the same value when called one the
344: * same entity object.
345: *
346: * A client can test whether two entity object references refer to the
347: * same entity object by using the isIdentical(EBJObject) method.
348: * Alternatively, if a client obtains two entity object references from
349: * the same home, it can determin if they refer to the same entity by comparing
350: * their primary keys using the 'equals' method.
351: *
352: * @throws Exception
353: *
354: */
355: public void testPrimaryKeyObjectIdentity() {
356: getLog()
357: .debug(
358: "**************************************************************");
359: getLog().debug(" testPrimaryKeyObjectIdentity()");
360:
361: CtsBmp bean = null;
362: CtsBmp anotherBean = null;
363: CtsBmp differentBean = null;
364:
365: try {
366: CtsBmpHome home = getHome();
367: AccountPK pk = new AccountPK(BEAN_PK_007);
368:
369: getLog().debug("Create a bean...");
370: bean = doEjbCreate(pk, BEAN_NAME);
371: getLog().debug("OK");
372:
373: getLog().debug(
374: "Now query based on the 'PersonsName': "
375: + BEAN_NAME + "...");
376: Collection clct = home.findByPersonsName(BEAN_NAME);
377: getLog().debug("OK");
378:
379: getLog().debug("Verify result set not empty...");
380: assertTrue(!clct.isEmpty());
381: getLog().debug("OK");
382:
383: getLog().debug("Bean result set:");
384: for (Iterator itr = clct.iterator(); itr.hasNext();) {
385: anotherBean = (CtsBmp) itr.next();
386: getLog().debug("Use 'isIdentical()' to compare beans");
387: assertTrue(anotherBean.isIdentical(bean));
388: getLog().debug("beans match..OK");
389: }
390:
391: getLog().debug("Make a bean that doesn't match..");
392: AccountPK anotherPK = new AccountPK("123");
393: differentBean = doEjbCreate(anotherPK, "SomeOtherGuy");
394: getLog().debug("OK");
395:
396: getLog().debug(
397: "Use 'isIdentical()' to verify different beans...");
398: assertTrue(!differentBean.isIdentical(bean));
399: getLog().debug("OK...beans are different!");
400:
401: getLog().debug("Test the Primary Keys...");
402: AccountPK beansPK = (AccountPK) bean.getPrimaryKey();
403: AccountPK anotherBeansPK = (AccountPK) anotherBean
404: .getPrimaryKey();
405: assertTrue(beansPK.equals(anotherBeansPK));
406: getLog().debug("OK...they're the same");
407:
408: getLog().debug("Compare different keys...");
409: assertTrue(!beansPK.equals(anotherPK));
410: getLog().debug("OK...they're different");
411:
412: getLog()
413: .debug(
414: "**************************************************************");
415:
416: } catch (Exception ex) {
417: getLog().error("Error in bmptest", ex);
418: fail("Caught an unknown exception: " + ex.toString());
419: }
420: }
421:
422: /**
423: * Method testEjbRemoteIF
424: * EJB 1.1 [8.6] p. 93-94
425: *
426: * The javax.ejb.EJBObject I/F defines the methods that allow the client
427: * to perform the following:
428: * - Obtain the home interface for the entity object
429: * - Remove the entity object
430: * - Obtain the entity object's handle
431: * - Obtain the entity object's primary key
432: *
433: * @throws Exception
434: *
435: */
436: public void testEjbRemoteIF() {
437: getLog()
438: .debug(
439: "**************************************************************");
440: getLog().debug(" testEjbRemoteIF ()");
441:
442: CtsBmp bean = null;
443:
444: try {
445: CtsBmpHome home = getHome();
446: AccountPK pk = new AccountPK(BEAN_PK_007);
447:
448: getLog().debug("Create a bean...");
449: bean = doEjbCreate(pk, BEAN_NAME);
450: getLog().debug("OK");
451:
452: getLog().debug("Obtain the HOME interface...");
453: home = (CtsBmpHome) bean.getEJBHome();
454: assertTrue(home != null);
455: getLog().debug("OK");
456:
457: getLog().debug("Obtain the HANDLE...");
458: Handle han = bean.getHandle();
459: assertTrue(han != null);
460: getLog().debug("OK");
461:
462: getLog().debug("Obtain the primary key...");
463: pk = (AccountPK) bean.getPrimaryKey();
464: assertTrue(pk != null);
465: getLog().debug("OK");
466:
467: getLog().debug("Remove the entity bean");
468: bean.remove();
469: getLog().debug("OK");
470: } catch (Exception ex) {
471: getLog().error("Error in bmptest", ex);
472: fail("Caught an unknown exception" + ex.toString());
473: }
474:
475: getLog()
476: .debug(
477: "**************************************************************");
478: }
479:
480: /**
481: * Method testEntityHandle
482: * EJB 1.1 [8.7] p. 93-94
483: *
484: * - Client can get handle to remote interface
485: * - Use javax.rmi.PortableRemoteObject.narrow(...) to convert the
486: * result of the getEJBObject().
487: * - An entity handle is typically implemented to be usable over a
488: * long period of time it must be usable at least across a server
489: * restart.
490: *
491: * @throws Exception
492: *
493: */
494: public void testEntityHandle() {
495: getLog()
496: .debug(
497: "**************************************************************");
498: getLog().debug(" testEntityHandle()");
499:
500: CtsBmp bean = null;
501:
502: try {
503: CtsBmpHome home = getHome();
504: AccountPK pk = new AccountPK(BEAN_PK_007);
505:
506: getLog().debug("Create a bean...");
507: bean = doEjbCreate(pk, BEAN_NAME);
508: getLog().debug("OK");
509:
510: getLog()
511: .debug("Get a Handle reference and serialize it...");
512: Handle beanHandle = bean.getHandle();
513: ByteArrayOutputStream out = new ByteArrayOutputStream();
514: ObjectOutputStream sOut = new ObjectOutputStream(out);
515: sOut.writeObject(beanHandle);
516: sOut.flush();
517: byte[] bytes = out.toByteArray();
518: getLog().debug("OK");
519:
520: getLog().debug("Unserialize bean handle...");
521: ByteArrayInputStream in = new ByteArrayInputStream(bytes);
522: ObjectInputStream sIn = new ObjectInputStream(in);
523: beanHandle = (Handle) sIn.readObject();
524: getLog().debug("OK");
525:
526: getLog().debug(
527: "Use PortableRemoteObject to narrow result...");
528: bean = (CtsBmp) PortableRemoteObject.narrow(beanHandle
529: .getEJBObject(), CtsBmp.class);
530: getLog().debug("OK");
531:
532: getLog().debug("Check that new reference works...");
533: assertTrue(bean.getPersonsName().trim().equals(BEAN_NAME));
534: getLog().debug("OK");
535: } catch (Exception ex) {
536: getLog().error("Error in bmptest", ex);
537: fail("Caught an unknown exeption: " + ex.toString());
538: }
539:
540: getLog()
541: .debug(
542: "**************************************************************");
543:
544: }
545:
546: /** Test of handle that is unmarshalled in a environment where
547: * new InitialContext() will not work. This must use the
548: * @throws Exception
549: */
550: public void testSessionHandleNoDefaultJNDI() throws Exception {
551: getLog().debug("+++ testSessionHandleNoDefaultJNDI()");
552:
553: /* We have to establish the JNDI env by creating a InitialContext with
554: the org.jboss.naming.NamingContextFactory. Normally this would be done
555: during the home lookup and session creation.
556: */
557: Properties homeProps = new Properties();
558: homeProps.setProperty("java.naming.factory.initial",
559: "org.jboss.naming.NamingContextFactory");
560: InitialContext ic = new InitialContext(homeProps);
561: CtsBmpHome home = (CtsBmpHome) ic.lookup("ejbcts/BMPBean");
562: AccountPK pk = new AccountPK(BEAN_PK_007);
563: CtsBmp bean = doEjbCreate(pk, BEAN_NAME);
564: Handle beanHandle = bean.getHandle();
565: ByteArrayOutputStream out = new ByteArrayOutputStream();
566: ObjectOutputStream oos = new ObjectOutputStream(out);
567: oos.writeObject(beanHandle);
568: oos.flush();
569: byte[] bytes = out.toByteArray();
570:
571: Properties sysProps = System.getProperties();
572: Properties newProps = new Properties(sysProps);
573: newProps.setProperty("java.naming.factory.initial",
574: "badFactory");
575: newProps.setProperty("java.naming.provider.url",
576: "jnp://badhost:12345");
577: System.setProperties(newProps);
578: try {
579: getLog().debug("Unserialize bean handle...");
580: ByteArrayInputStream in = new ByteArrayInputStream(bytes);
581: ObjectInputStream ois = new ObjectInputStream(in);
582: beanHandle = (Handle) ois.readObject();
583: bean = (CtsBmp) beanHandle.getEJBObject();
584: String name = bean.getPersonsName();
585: getLog().debug("getPersonsName: " + name);
586: } finally {
587: System.setProperties(sysProps);
588: }
589: }
590:
591: /**
592: * Method testProbeContainerCallbacks
593: */
594: public void testProbeContainerCallbacks() {
595: getLog()
596: .debug(
597: "**************************************************************");
598: getLog().debug(" testProbeContainerCallbacks()");
599:
600: CtsBmp bean = null;
601:
602: try {
603: CtsBmpHome home = getHome();
604: AccountPK pk = new AccountPK(BEAN_PK_007);
605:
606: mbx.clearMessages();
607:
608: getLog().debug("Create a bean...");
609: bean = doEjbCreate(pk, BEAN_NAME);
610: getLog().debug("OK");
611:
612: getLog().debug(
613: "Check for set entity context, create "
614: + "and post create messages...");
615: Thread.sleep(2500);
616: // OSH: We cannot be sure that the context will be set:
617: // If the container elects a pooled instance to use for the
618: // new object, setEntityContext() may have been called before
619: // we cleared the message box.
620: //assertTrue(mbx.messageReceived(ContainerMBox.SET_ENTITY_CONTEXT_MSG));
621: assertTrue(
622: "Expected to receive notification of EJB_CREATE_MSG",
623: mbx.messageReceived(ContainerMBox.EJB_CREATE_MSG));
624: assertTrue(
625: "Expected to receive notification of EJB_POST_CREATE_MSG",
626: mbx
627: .messageReceived(ContainerMBox.EJB_POST_CREATE_MSG));
628: getLog().debug("OK");
629:
630: // Execute a business method
631: getLog().debug("Calling setter as a business method...");
632: bean.setPersonsName(BEAN_OTHER_NAME);
633: getLog().debug("OK");
634:
635: // Remove
636: getLog().debug("Remove the bean...");
637: bean.remove();
638: Thread.sleep(3000);
639: assertTrue(
640: "Expected to receive notification of EJB_STORE_MSG",
641: mbx.messageReceived(ContainerMBox.EJB_STORE_MSG));
642: assertTrue(
643: "Expected to receive notification of EJB_REMOVE_MSG",
644: mbx.messageReceived(ContainerMBox.EJB_REMOVE_MSG));
645: getLog().debug("OK");
646: } catch (Exception ex) {
647: getLog().error("Error in bmptest", ex);
648: fail("testEjbCreate has failed!");
649: }
650:
651: getLog()
652: .debug(
653: "**************************************************************");
654: }
655:
656: /**
657: * Method testContainerObjects
658: * EJB 1.1 [9.3] p. 127-129
659: * Container must implement:
660: * - Entity EJBHome class
661: * - Entity EJBObject class
662: * - Handle class
663: * - HomeHandle class
664: * - Meta-data class
665: */
666: public void testContainerObjects() {
667: getLog()
668: .debug(
669: "**************************************************************");
670: getLog().debug(" testContainerObjects()");
671:
672: CtsBmp bean = null;
673:
674: try {
675: CtsBmpHome home = getHome();
676: AccountPK pk = new AccountPK(BEAN_PK_007);
677:
678: mbx.clearMessages();
679:
680: getLog().debug("Create a bean...");
681: bean = doEjbCreate(pk, BEAN_NAME);
682: getLog().debug("OK");
683:
684: getLog().debug("Get HomeHandle...");
685: HomeHandle homeHan = home.getHomeHandle();
686: assertTrue(homeHan != null);
687: getLog().debug("OK");
688:
689: getLog().debug("Get another home from the HomeHandle...");
690: CtsBmpHome anotherHome = (CtsBmpHome) homeHan.getEJBHome();
691: assertTrue(anotherHome != null);
692: getLog().debug("OK");
693:
694: getLog().debug("Get the Meta-data object...");
695: EJBMetaData md = anotherHome.getEJBMetaData();
696: assertTrue(md != null);
697: getLog().debug("OK");
698:
699: getLog().debug("Probe the Meta-data object:");
700: String homeInterface = md.getHomeInterfaceClass().getName();
701: String primaryKey = md.getPrimaryKeyClass().getName();
702: String remoteInterface = md.getRemoteInterfaceClass()
703: .getName();
704: getLog().debug(" Home Interface : " + homeInterface);
705: getLog().debug(" PrimaryKey : " + primaryKey);
706: getLog().debug(" Remote Interface: " + remoteInterface);
707: assertTrue(homeInterface
708: .equals("org.jboss.test.cts.interfaces.CtsBmpHome"));
709: assertTrue(primaryKey
710: .equals("org.jboss.test.cts.keys.AccountPK"));
711: assertTrue(remoteInterface
712: .equals("org.jboss.test.cts.interfaces.CtsBmp"));
713: getLog().debug("Meta-data OK");
714:
715: getLog().debug("Check isSession()==false ...");
716: assertTrue(!md.isSession());
717: getLog().debug("OK");
718:
719: getLog().debug("Check isStatelessSession()==false ...");
720: assertTrue(!md.isStatelessSession());
721: getLog().debug("OK");
722:
723: getLog().debug("Test EJBHome.remove(PrimaryKey)");
724: anotherHome.remove(pk);
725: getLog().debug("OK");
726:
727: } catch (Exception ex) {
728: getLog().error("Error in bmptest", ex);
729: fail("testEjbCreate has failed!");
730: }
731:
732: getLog()
733: .debug(
734: "**************************************************************");
735: }
736:
737: /**
738: * Do the UserTransaction tests.
739: */
740: public void testUserTransaction() throws Exception {
741: getLog()
742: .debug(
743: "**************************************************************");
744: getLog().debug(" testUserTransaction()");
745:
746: CtsBmpHome home = getHome();
747: UserTransaction ut;
748:
749: getLog().debug("Obtain UserTransaction...");
750: Object o = new InitialContext().lookup("UserTransaction");
751: ut = (UserTransaction) PortableRemoteObject.narrow(o,
752: UserTransaction.class);
753: assertTrue(ut != null);
754: getLog().debug("OK");
755:
756: getLog().debug("Do UserTransaction tests...");
757: UserTransactionTester utt = new UserTransactionTester(home, ut);
758: assertTrue(ut != null);
759: assertTrue(utt.runAllTests());
760: getLog().debug("Ok");
761:
762: getLog()
763: .debug(
764: "**************************************************************");
765: }
766:
767: // Used to test passing a Entity bean as a parameter.
768: // OSH: ??? This just calls a method on the bean ???
769: private boolean gotRefOkay(CtsBmp bean, String expectedName) {
770: boolean retVal = false;
771:
772: try {
773: getLog().debug(
774: expectedName + "==" + bean.getPersonsName() + "?");
775: retVal = (bean.getPersonsName().equals(expectedName));
776: } catch (Exception ex) {
777: getLog().debug("Unknown Exception : " + ex.toString());
778: }
779:
780: return retVal;
781: }
782:
783: //do the mbox setup/teardown for each test separately
784: protected void setUp() throws Exception {
785: getLog().debug("Build Container MBX for BMP");
786: mbx = new ContainerMBox();
787:
788: getLog().debug("Initialize to empty BMP table.");
789: CtsBmpHome home = getHome();
790: Collection clct = home.findAll();
791: if (clct.size() != 0) {
792: getLog().debug("Removing " + clct.size() + " old beans.");
793: for (Iterator itr = clct.iterator(); itr.hasNext();) {
794: CtsBmp bean = (CtsBmp) itr.next();
795: bean.remove();
796: }
797: getLog().debug("Removal done.");
798: }
799: }
800:
801: protected void tearDown() throws Exception {
802: try {
803: mbx.close();
804: } catch (Exception ignoredBecauseProblemsWillBeHighlightedAsTestFailures) {
805: }
806: }
807:
808: //deploy the cts.jar once for the suite.
809: public static Test suite() throws Exception {
810: return getDeploySetup(BmpUnitTestCase.class, "cts.jar");
811: }
812:
813: }
|