KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cts > test > BmpUnitTestCase


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.cts.test;
23
24
25 import java.io.ByteArrayInputStream JavaDoc;
26 import java.io.ObjectInputStream JavaDoc;
27 import java.io.ByteArrayOutputStream JavaDoc;
28 import java.io.ObjectOutputStream JavaDoc;
29
30 import java.util.Collection JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Properties JavaDoc;
33
34 import javax.ejb.Handle JavaDoc;
35 import javax.ejb.HomeHandle JavaDoc;
36 import javax.ejb.EJBMetaData JavaDoc;
37
38 import javax.naming.InitialContext JavaDoc;
39
40 import javax.rmi.PortableRemoteObject JavaDoc;
41
42 import javax.transaction.UserTransaction JavaDoc;
43
44 import org.jboss.test.cts.jms.ContainerMBox;
45 import org.jboss.test.cts.interfaces.CtsBmpHome;
46 import org.jboss.test.cts.interfaces.CtsBmp;
47 import org.jboss.test.cts.interfaces.UserTransactionTester;
48 import org.jboss.test.cts.interfaces.StatelessSession;
49 import org.jboss.test.cts.keys.AccountPK;
50
51 import junit.framework.Test;
52
53 import org.jboss.test.JBossTestCase;
54
55
56 /**
57  * Class BmpTest
58  *
59  * @author Author: kimptoc
60  * @version $Revision: 58364 $
61  */

62
63
64 public class BmpUnitTestCase
65    extends JBossTestCase
66 {
67    private ContainerMBox mbx = null;
68    public static final String JavaDoc BEAN_NAME = "GuysName";
69    public static final String JavaDoc BEAN_OTHER_NAME = "OtherGuysName";
70    public static final String JavaDoc BEAN_PK_007 = "007";
71
72    /**
73     * Constructor BmpTest
74     *
75     * @param name
76     *
77     */

78    public BmpUnitTestCase(String JavaDoc name)
79    {
80       super(name);
81    }
82
83    /**
84     * Return the bean home interface.
85     */

86    private CtsBmpHome getHome()
87       throws Exception JavaDoc
88    {
89       return (CtsBmpHome)getInitialContext().lookup("ejbcts/BMPBean");
90    }
91
92    /**
93     * Create a bean instance.
94     */

95    private CtsBmp doEjbCreate(AccountPK pk, String JavaDoc name)
96       throws Exception JavaDoc
97    {
98       return getHome().create(pk, name);
99    }
100
101    /**
102     * Method testEjbCreate
103     * EJB 1.1 [8.3.1] p. 89
104     * An entity bean's home interface can define zero or more create(...)
105     * methods.
106     *
107     * @throws Exception
108     *
109     */

110    public void testEjbCreate()
111       throws Exception JavaDoc
112    {
113       getLog().debug(
114          "**************************************************************");
115       getLog().debug(" testEjbCreate()");
116
117       CtsBmp bean = null;
118
119       try {
120          getLog().debug("create bean, name=" + BEAN_NAME);
121
122          bean = doEjbCreate(new AccountPK(BEAN_PK_007), BEAN_NAME);
123       } catch (Exception JavaDoc ex) {
124          getLog().error("Error in bmptest", ex);
125          fail("testEjbCreate has failed!");
126       }
127
128       assertEquals(BEAN_NAME, bean.getPersonsName());
129
130       getLog().debug(
131          "**************************************************************");
132    }
133
134   /**
135     * Method testEjbFinder
136     * EJB 1.1 [8.3.2] p. 90
137     * An entity bean's home interface defines one or more finder methods,
138     * one for each way to find and entity object or collection of entity objects
139     * within the home.
140     *
141     * Test stategy: Create a bean. Use the bean that has been previously
142     * created, and call the finder method. Make sure that
143     * a result set is returned and that the bean returned
144     * has the same name associated with it as the bean that
145     * was previously created.
146     *
147     * @throws Exception
148     *
149     */

150    public void testEjbFinder()
151       throws Exception JavaDoc
152    {
153       getLog().debug(
154          "**************************************************************");
155       getLog().debug(" testEjbFinder()");
156
157       CtsBmp bean = null;
158
159       try {
160          CtsBmpHome home = getHome();
161
162          // First create a bean instance to find
163
getLog().debug("Create bean, name=" + BEAN_NAME);
164          doEjbCreate(new AccountPK(BEAN_PK_007), BEAN_NAME);
165
166          getLog().debug("Find bean, name=" + BEAN_NAME);
167
168          Collection JavaDoc clct = home.findByPersonsName(BEAN_NAME);
169          getLog().debug("Verify result set not empty");
170          assertTrue(!clct.isEmpty());
171          getLog().debug("OK");
172          getLog().debug("Bean result set:");
173          for(Iterator JavaDoc itr=clct.iterator(); itr.hasNext();)
174      {
175              bean = (CtsBmp)itr.next();
176              getLog().debug("Name from Bean=" + bean.getPersonsName());
177              getLog().debug("Verify bean name equals: " + BEAN_NAME);
178              assertTrue(bean.getPersonsName().trim().equals(BEAN_NAME));
179              getLog().debug("OK");
180      }
181       } catch (Exception JavaDoc ex) {
182          getLog().error("Error in bmptest", ex);
183          fail("testEjbFinder has failed!");
184       }
185
186       getLog().debug(
187          "**************************************************************");
188    }
189
190    /**
191     * Method testEjbRemove
192     * EJB 1.1 [8.3.3] p. 90
193     *
194     * Test Strategy:
195     * 1) Create a bean to remove.
196     * 2) Attempt a simple remove using the remote interface.
197     * 3) Create a bean to remove.
198     * 4) Attempt a simple remove using the home interface and primary key.
199     * 5) Create a bean to remove.
200     * 6) Try to remove the instance using its handle.
201     * 7) Try to access the instance. This should result in a
202     * java.rmi.NoSuchObjectException
203     *
204     * @throws Exception
205     */

206    public void testEjbRemove()
207       throws Exception JavaDoc
208    {
209       getLog().debug(
210          "**************************************************************");
211       getLog().debug(" testEjbRemove()");
212
213       CtsBmp bean = null;
214
215       try {
216          CtsBmpHome home = getHome();
217          AccountPK pk = new AccountPK(BEAN_PK_007);
218
219          getLog().debug("Create a bean...");
220          bean = doEjbCreate(pk, BEAN_NAME);
221          getLog().debug("OK");
222
223          getLog().debug("Delete with bean.remove()...");
224          bean.remove();
225          getLog().debug("OK");
226
227          getLog().debug("Recreate the bean...");
228          bean = doEjbCreate(pk, BEAN_NAME);
229          getLog().debug("OK");
230
231          getLog().debug("Remove the bean using primary key...");
232          home.remove(pk);
233          getLog().debug("OK");
234
235          getLog().debug("Reconstitute the bean...");
236          bean = doEjbCreate(pk, BEAN_NAME);
237          getLog().debug("OK");
238
239          getLog().debug("Get Handle object...");
240          Handle JavaDoc hn = bean.getHandle( );
241          getLog().debug("OK");
242
243          getLog().debug("Remove the bean using the handle...");
244          home.remove(hn);
245          getLog().debug("OK");
246
247          getLog().debug("Bean remove, try to use.. " +
248                           "Should get 'java.rmi.NoSuchObjectException'..." );
249          try {
250          bean.getPersonsName();
251          } catch(java.rmi.NoSuchObjectException JavaDoc nsoex) {
252          getLog().debug("OK");
253          } catch(Exception JavaDoc ex) {
254          fail("Got Exception: expecting NoSuchObjectException" + ex.toString() );
255          }
256       } catch (Exception JavaDoc ex) {
257          getLog().error("Error in bmptest", ex);
258          fail("testEjbRemove has failed!");
259       }
260
261       getLog().debug(
262          "**************************************************************");
263    }
264
265    /**
266     * Method testEjbLifeCycle
267     * EJB 1.1 [8.4] p. 92
268     *
269     * A client can get a reference to an existing entity objects
270     * remote interface in any of the following ways:
271     * - Receive the reference as a parameter in a method call.
272     * - Find the entity object using a finder method defined in the EB home i/f.
273     * - Obtain the reference from the entity objects' handle.
274     *
275     * @throws Exception
276     *
277     */

278    public void testEjbLifeCycle()
279    {
280       getLog().debug(
281          "**************************************************************");
282       getLog().debug(" testEjbLifeCycle()");
283
284       CtsBmp bean = null;
285
286       try {
287          CtsBmpHome home = getHome();
288          AccountPK pk = new AccountPK(BEAN_PK_007);
289
290          getLog().debug("Create a bean...");
291          doEjbCreate(pk, BEAN_NAME);
292          getLog().debug("OK");
293
294          getLog().debug("Use a finder method to retrieve the bean...");
295          bean = home.findByPrimaryKey( pk );
296          getLog().debug("OK");
297
298          getLog().debug("Assert it is the same bean as passed to a method..." );
299          // Send to a method as a reference, make sure it is usable by the method
300
assertTrue( this.gotRefOkay(bean, BEAN_NAME) );
301          getLog().debug("OK");
302
303          // Execute a business method
304
getLog().debug("Calling setter as a business method...");
305          bean.setPersonsName(BEAN_OTHER_NAME);
306          getLog().debug("OK");
307
308          // Get the home interface
309
getLog().debug("Get the HOME interface...");
310          home = (CtsBmpHome)bean.getEJBHome();
311          getLog().debug("OK");
312
313          // Get the primary key
314
getLog().debug("Get the bean's Primary Key...");
315          pk = (AccountPK)bean.getPrimaryKey();
316          getLog().debug("OK");
317
318          getLog().debug("Get the bean's handle...");
319          Handle JavaDoc hn = bean.getHandle();
320          getLog().debug("OK");
321
322          // Remove
323
getLog().debug("Remove the bean...");
324          bean.remove();
325          getLog().debug("OK");
326       } catch (Exception JavaDoc ex) {
327          getLog().error("Error in bmptest", ex);
328          fail("testEjbCreate has failed!");
329       }
330
331       getLog().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    {
357       getLog().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("Now query based on the 'PersonsName': " +
374                           BEAN_NAME + "...");
375          Collection JavaDoc clct = home.findByPersonsName(BEAN_NAME);
376          getLog().debug("OK");
377
378          getLog().debug("Verify result set not empty...");
379          assertTrue(!clct.isEmpty());
380          getLog().debug("OK");
381
382          getLog().debug("Bean result set:");
383          for (Iterator JavaDoc itr=clct.iterator(); itr.hasNext();)
384          {
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("Use 'isIdentical()' to verify different beans...");
397          assertTrue(!differentBean.isIdentical(bean));
398          getLog().debug("OK...beans are different!");
399
400          getLog().debug("Test the Primary Keys...");
401          AccountPK beansPK = (AccountPK)bean.getPrimaryKey();
402          AccountPK anotherBeansPK = (AccountPK)anotherBean.getPrimaryKey();
403          assertTrue(beansPK.equals(anotherBeansPK));
404          getLog().debug("OK...they're the same");
405
406          getLog().debug("Compare different keys...");
407          assertTrue(!beansPK.equals(anotherPK));
408          getLog().debug("OK...they're different");
409
410          getLog().debug(
411            "**************************************************************");
412
413       } catch(Exception JavaDoc ex) {
414          getLog().error("Error in bmptest", ex);
415          fail("Caught an unknown exception: " + ex.toString() );
416       }
417    }
418
419    /**
420     * Method testEjbRemoteIF
421     * EJB 1.1 [8.6] p. 93-94
422     *
423     * The javax.ejb.EJBObject I/F defines the methods that allow the client
424     * to perform the following:
425     * - Obtain the home interface for the entity object
426     * - Remove the entity object
427     * - Obtain the entity object's handle
428     * - Obtain the entity object's primary key
429     *
430     * @throws Exception
431     *
432     */

433    public void testEjbRemoteIF()
434    {
435      getLog().debug(
436          "**************************************************************");
437      getLog().debug(" testEjbRemoteIF ()");
438
439       CtsBmp bean = null;
440
441       try {
442          CtsBmpHome home = getHome();
443          AccountPK pk = new AccountPK(BEAN_PK_007);
444
445          getLog().debug("Create a bean...");
446          bean = doEjbCreate(pk, BEAN_NAME);
447          getLog().debug("OK");
448
449          getLog().debug("Obtain the HOME interface...");
450          home = (CtsBmpHome)bean.getEJBHome();
451          assertTrue(home != null);
452          getLog().debug("OK");
453
454          getLog().debug("Obtain the HANDLE...");
455          Handle JavaDoc han = bean.getHandle();
456          assertTrue(han != null);
457          getLog().debug("OK");
458
459          getLog().debug("Obtain the primary key...");
460          pk = (AccountPK)bean.getPrimaryKey();
461          assertTrue(pk != null);
462          getLog().debug("OK");
463
464          getLog().debug("Remove the entity bean");
465          bean.remove();
466          getLog().debug("OK");
467       } catch(Exception JavaDoc ex) {
468          getLog().error("Error in bmptest", ex);
469          fail("Caught an unknown exception" + ex.toString());
470       }
471
472       getLog().debug(
473          "**************************************************************");
474    }
475
476    /**
477     * Method testEntityHandle
478     * EJB 1.1 [8.7] p. 93-94
479     *
480     * - Client can get handle to remote interface
481     * - Use javax.rmi.PortableRemoteObject.narrow(...) to convert the
482     * result of the getEJBObject().
483     * - An entity handle is typically implemented to be usable over a
484     * long period of time it must be usable at least across a server
485     * restart.
486     *
487     * @throws Exception
488     *
489     */

490    public void testEntityHandle()
491    {
492      getLog().debug(
493          "**************************************************************");
494      getLog().debug(" testEntityHandle()");
495
496       CtsBmp bean = null;
497
498       try {
499          CtsBmpHome home = getHome();
500          AccountPK pk = new AccountPK(BEAN_PK_007);
501
502          getLog().debug("Create a bean...");
503          bean = doEjbCreate(pk, BEAN_NAME);
504          getLog().debug("OK");
505
506          getLog().debug("Get a Handle reference and serialize it...");
507          Handle JavaDoc beanHandle = bean.getHandle();
508          ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
509          ObjectOutputStream JavaDoc sOut = new ObjectOutputStream JavaDoc(out);
510          sOut.writeObject(beanHandle);
511          sOut.flush();
512          byte[] bytes = out.toByteArray();
513          getLog().debug("OK");
514  
515          getLog().debug("Unserialize bean handle...");
516          ByteArrayInputStream JavaDoc in = new ByteArrayInputStream JavaDoc(bytes);
517          ObjectInputStream JavaDoc sIn = new ObjectInputStream JavaDoc(in);
518          beanHandle = (Handle JavaDoc)sIn.readObject();
519          getLog().debug("OK");
520
521          getLog().debug("Use PortableRemoteObject to narrow result...");
522          bean = (CtsBmp)PortableRemoteObject.narrow(beanHandle.getEJBObject(),
523                                                     CtsBmp.class);
524          getLog().debug("OK");
525
526          getLog().debug("Check that new reference works...");
527          assertTrue(bean.getPersonsName().trim().equals(BEAN_NAME));
528          getLog().debug("OK");
529       } catch(Exception JavaDoc ex) {
530          getLog().error("Error in bmptest", ex);
531          fail("Caught an unknown exeption: " + ex.toString());
532       }
533
534      getLog().debug(
535          "**************************************************************");
536
537    }
538
539    /** Test of handle that is unmarshalled in a environment where
540     * new InitialContext() will not work. This must use the
541     * @throws Exception
542     */

543    public void testSessionHandleNoDefaultJNDI()
544          throws Exception JavaDoc
545    {
546       getLog().debug("+++ testSessionHandleNoDefaultJNDI()");
547
548       /* We have to establish the JNDI env by creating a InitialContext with
549       the org.jboss.naming.NamingContextFactory. Normally this would be done
550       during the home lookup and session creation.
551       */

552       Properties JavaDoc homeProps = new Properties JavaDoc();
553       homeProps.setProperty("java.naming.factory.initial", "org.jboss.naming.NamingContextFactory");
554       InitialContext JavaDoc ic = new InitialContext JavaDoc(homeProps);
555       CtsBmpHome home = (CtsBmpHome) ic.lookup("ejbcts/BMPBean");
556       AccountPK pk = new AccountPK(BEAN_PK_007);
557       CtsBmp bean = doEjbCreate(pk, BEAN_NAME);
558       Handle JavaDoc beanHandle = bean.getHandle();
559       ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
560       ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(out);
561       oos.writeObject(beanHandle);
562       oos.flush();
563       byte[] bytes = out.toByteArray();
564
565       Properties JavaDoc sysProps = System.getProperties();
566       Properties JavaDoc newProps = new Properties JavaDoc(sysProps);
567       newProps.setProperty("java.naming.factory.initial", "badFactory");
568       newProps.setProperty("java.naming.provider.url", "jnp://badhost:12345");
569       System.setProperties(newProps);
570       try
571       {
572          getLog().debug("Unserialize bean handle...");
573          ByteArrayInputStream JavaDoc in = new ByteArrayInputStream JavaDoc(bytes);
574          ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(in);
575          beanHandle = (Handle JavaDoc) ois.readObject();
576          bean = (CtsBmp) beanHandle.getEJBObject();
577          String JavaDoc name = bean.getPersonsName();
578          getLog().debug("getPersonsName: "+name);
579       }
580       finally
581       {
582          System.setProperties(sysProps);
583       }
584    }
585
586    /**
587     * Method testProbeContainerCallbacks
588     */

589    public void testProbeContainerCallbacks()
590    {
591       getLog().debug(
592          "**************************************************************");
593       getLog().debug(" testProbeContainerCallbacks()");
594
595       CtsBmp bean = null;
596
597       try {
598          CtsBmpHome home = getHome();
599          AccountPK pk = new AccountPK(BEAN_PK_007);
600
601          mbx.clearMessages();
602
603          getLog().debug("Create a bean...");
604          bean = doEjbCreate(pk, BEAN_NAME);
605          getLog().debug("OK");
606
607          getLog().debug("Check for set entity context, create " +
608                           "and post create messages...");
609          Thread.sleep(2500);
610          // OSH: We cannot be sure that the context will be set:
611
// If the container elects a pooled instance to use for the
612
// new object, setEntityContext() may have been called before
613
// we cleared the message box.
614
//assertTrue(mbx.messageReceived(ContainerMBox.SET_ENTITY_CONTEXT_MSG));
615
assertTrue("Expected to receive notification of EJB_CREATE_MSG",mbx.messageReceived(ContainerMBox.EJB_CREATE_MSG));
616          assertTrue("Expected to receive notification of EJB_POST_CREATE_MSG",mbx.messageReceived(ContainerMBox.EJB_POST_CREATE_MSG));
617          getLog().debug("OK");
618
619          // Execute a business method
620
getLog().debug("Calling setter as a business method...");
621          bean.setPersonsName(BEAN_OTHER_NAME);
622          getLog().debug("OK");
623
624          // Remove
625
getLog().debug("Remove the bean...");
626          bean.remove();
627          Thread.sleep(3000);
628          assertTrue("Expected to receive notification of EJB_STORE_MSG",mbx.messageReceived(ContainerMBox.EJB_STORE_MSG));
629          assertTrue("Expected to receive notification of EJB_REMOVE_MSG",mbx.messageReceived(ContainerMBox.EJB_REMOVE_MSG));
630          getLog().debug("OK");
631       } catch (Exception JavaDoc ex) {
632          getLog().error("Error in bmptest", ex);
633          fail("testEjbCreate has failed!");
634       }
635
636       getLog().debug(
637          "**************************************************************");
638    }
639
640    /**
641     * Method testContainerObjects
642     * EJB 1.1 [9.3] p. 127-129
643     * Container must implement:
644     * - Entity EJBHome class
645     * - Entity EJBObject class
646     * - Handle class
647     * - HomeHandle class
648     * - Meta-data class
649     */

650    public void testContainerObjects()
651    {
652       getLog().debug(
653          "**************************************************************");
654       getLog().debug(" testContainerObjects()");
655
656       CtsBmp bean = null;
657
658       try {
659          CtsBmpHome home = getHome();
660          AccountPK pk = new AccountPK(BEAN_PK_007);
661
662          mbx.clearMessages();
663
664          getLog().debug("Create a bean...");
665          bean = doEjbCreate(pk, BEAN_NAME);
666          getLog().debug("OK");
667
668          getLog().debug("Get HomeHandle..." );
669          HomeHandle JavaDoc homeHan = home.getHomeHandle();
670          assertTrue(homeHan != null);
671          getLog().debug("OK");
672
673          getLog().debug("Get another home from the HomeHandle...");
674          CtsBmpHome anotherHome = (CtsBmpHome)homeHan.getEJBHome();
675          assertTrue(anotherHome != null);
676          getLog().debug("OK");
677
678          getLog().debug("Get the Meta-data object...");
679          EJBMetaData JavaDoc md = anotherHome.getEJBMetaData();
680          assertTrue(md != null);
681          getLog().debug("OK");
682
683          getLog().debug("Probe the Meta-data object:");
684          String JavaDoc homeInterface = md.getHomeInterfaceClass().getName();
685          String JavaDoc primaryKey = md.getPrimaryKeyClass().getName();
686          String JavaDoc remoteInterface = md.getRemoteInterfaceClass().getName();
687          getLog().debug(" Home Interface : " + homeInterface);
688          getLog().debug(" PrimaryKey : " + primaryKey);
689          getLog().debug(" Remote Interface: " + remoteInterface);
690          assertTrue(homeInterface.equals("org.jboss.test.cts.interfaces.CtsBmpHome"));
691          assertTrue(primaryKey.equals("org.jboss.test.cts.keys.AccountPK"));
692          assertTrue(remoteInterface.equals("org.jboss.test.cts.interfaces.CtsBmp"));
693          getLog().debug("Meta-data OK");
694
695          getLog().debug("Check isSession()==false ...");
696          assertTrue(!md.isSession());
697          getLog().debug("OK");
698
699          getLog().debug("Check isStatelessSession()==false ...");
700          assertTrue(!md.isStatelessSession());
701          getLog().debug("OK");
702
703          getLog().debug("Test EJBHome.remove(PrimaryKey)");
704          anotherHome.remove(pk);
705          getLog().debug("OK");
706
707       } catch (Exception JavaDoc ex) {
708          getLog().error("Error in bmptest", ex);
709          fail("testEjbCreate has failed!");
710       }
711
712       getLog().debug(
713          "**************************************************************");
714    }
715
716    /**
717     * Do the UserTransaction tests.
718     */

719    public void testUserTransaction()
720       throws Exception JavaDoc
721    {
722       getLog().debug(
723          "**************************************************************");
724       getLog().debug(" testUserTransaction()");
725  
726       CtsBmpHome home = getHome();
727       UserTransaction JavaDoc ut;
728  
729       getLog().debug("Obtain UserTransaction...");
730       Object JavaDoc o = new InitialContext JavaDoc().lookup("UserTransaction");
731       ut = (UserTransaction JavaDoc)PortableRemoteObject.narrow(o, UserTransaction JavaDoc.class);
732       assertTrue(ut != null);
733       getLog().debug("OK");
734  
735       getLog().debug("Do UserTransaction tests...");
736       UserTransactionTester utt = new UserTransactionTester(home, ut);
737       assertTrue(ut != null);
738       assertTrue(utt.runAllTests());
739       getLog().debug("Ok");
740  
741       getLog().debug(
742          "**************************************************************");
743    }
744   
745    // Used to test passing a Entity bean as a parameter.
746
// OSH: ??? This just calls a method on the bean ???
747
private boolean gotRefOkay(CtsBmp bean, String JavaDoc expectedName)
748    {
749       boolean retVal = false;
750
751       try {
752      getLog().debug(expectedName + "==" + bean.getPersonsName()+"?");
753          retVal = (bean.getPersonsName().equals(expectedName));
754       } catch(Exception JavaDoc ex) {
755          getLog().debug("Unknown Exception : " + ex.toString() );
756       }
757
758       return retVal;
759    }
760     
761     //do the mbox setup/teardown for each test separately
762
protected void setUp()
763       throws Exception JavaDoc
764    {
765       super.setUp();
766       getLog().debug("Build Container MBX for BMP");
767       mbx = new ContainerMBox();
768
769       getLog().debug("Initialize to empty BMP table.");
770       CtsBmpHome home = getHome();
771       Collection JavaDoc clct = home.findAll();
772       if (clct.size() != 0) {
773          getLog().debug("Removing " + clct.size() + " old beans.");
774          for (Iterator JavaDoc itr=clct.iterator(); itr.hasNext();) {
775             CtsBmp bean = (CtsBmp)itr.next();
776             bean.remove();
777      }
778          getLog().debug("Removal done.");
779       }
780    }
781
782    protected void tearDown()
783       throws Exception JavaDoc
784    {
785       try {
786          mbx.close();
787       } catch (Exception JavaDoc ignoredBecauseProblemsWillBeHighlightedAsTestFailures)
788       {}
789    }
790
791     //deploy the cts.jar once for the suite.
792
public static Test suite() throws Exception JavaDoc
793    {
794       return getDeploySetup(BmpUnitTestCase.class, "cts.jar");
795    }
796
797
798 }
799
Popular Tags