KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > exception > EntityExceptionUnitTestCase


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.exception;
23
24 import java.rmi.RemoteException JavaDoc;
25
26 import javax.ejb.EJBException JavaDoc;
27 import javax.ejb.FinderException JavaDoc;
28 import javax.ejb.TransactionRolledbackLocalException JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30 import javax.transaction.TransactionRolledbackException JavaDoc;
31
32 import junit.framework.Test;
33 import junit.framework.TestSuite;
34
35 import org.jboss.test.JBossTestCase;
36 import org.jboss.test.util.ejb.EJBTestCase;
37
38 public class EntityExceptionUnitTestCase extends EJBTestCase
39 {
40    public static Test suite() throws Exception JavaDoc
41    {
42       // JBAS-3492, the execution order of tests in this test case is important
43
// so it must be defined explicitly when running under some JVMs
44
TestSuite suite = new TestSuite();
45       suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionInTx_remote"));
46       suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionInTx_remote"));
47       suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionInTxMarkRollback_remote"));
48       suite.addTest(new EntityExceptionUnitTestCase("testApplicationErrorInTx_remote"));
49       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedApplicationErrorInTx_remote"));
50       suite.addTest(new EntityExceptionUnitTestCase("testEJBExceptionInTx_remote"));
51       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedEJBExceptionInTx_remote"));
52       suite.addTest(new EntityExceptionUnitTestCase("testRuntimeExceptionInTx_remote"));
53       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRuntimeExceptionInTx_remote"));
54       suite.addTest(new EntityExceptionUnitTestCase("testRemoteExceptionInTx_remote"));
55       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRemoteExceptionInTx_remote"));
56       suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionNewTx_remote"));
57       suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionNewTx_remote"));
58       suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionNewTxMarkRollback_remote"));
59       //suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionNewTxMarkRollback_remote"));
60
suite.addTest(new EntityExceptionUnitTestCase("testApplicationErrorNewTx_remote"));
61       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedApplicationErrorNewTx_remote"));
62       suite.addTest(new EntityExceptionUnitTestCase("testEJBExceptionNewTx_remote"));
63       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedEJBExceptionNewTx_remote"));
64       suite.addTest(new EntityExceptionUnitTestCase("testRuntimeExceptionNewTx_remote"));
65       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRuntimeExceptionNewTx_remote"));
66       suite.addTest(new EntityExceptionUnitTestCase("testRemoteExceptionNewTx_remote"));
67       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRemoteExceptionNewTx_remote"));
68       suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionNoTx_remote"));
69       suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionNoTx_remote"));
70       suite.addTest(new EntityExceptionUnitTestCase("testApplicationErrorNoTx_remote"));
71       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedApplicationErrorNoTx_remote"));
72       suite.addTest(new EntityExceptionUnitTestCase("testEJBExceptionNoTx_remote"));
73       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedEJBExceptionNoTx_remote"));
74       suite.addTest(new EntityExceptionUnitTestCase("testRuntimeExceptionNoTx_remote"));
75       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRuntimeExceptionNoTx_remote"));
76       suite.addTest(new EntityExceptionUnitTestCase("testRemoteExceptionNoTx_remote"));
77       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRemoteExceptionNoTx_remote"));
78       suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionInTx_local"));
79       suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionInTx_local"));
80       suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionInTxMarkRollback_local"));
81       //suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionInTxMarkRollback_local"));
82
suite.addTest(new EntityExceptionUnitTestCase("testApplicationErrorInTx_local"));
83       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedApplicationErrorInTx_local"));
84       suite.addTest(new EntityExceptionUnitTestCase("testEJBExceptionInTx_local"));
85       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedEJBExceptionInTx_local"));
86       suite.addTest(new EntityExceptionUnitTestCase("testRuntimeExceptionInTx_local"));
87       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRuntimeExceptionInTx_local"));
88       suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionNewTx_local"));
89       suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionNewTx_local"));
90       suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionNewTxMarkRollback_local"));
91       //suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionNewTxMarkRollback_local"));
92
suite.addTest(new EntityExceptionUnitTestCase("testApplicationErrorNewTx_local"));
93       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedApplicationErrorNewTx_local"));
94       suite.addTest(new EntityExceptionUnitTestCase("testEJBExceptionNewTx_local"));
95       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedEJBExceptionNewTx_local"));
96       suite.addTest(new EntityExceptionUnitTestCase("testRuntimeExceptionNewTx_local"));
97       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRuntimeExceptionNewTx_local"));
98       suite.addTest(new EntityExceptionUnitTestCase("testApplicationExceptionNoTx_local"));
99       suite.addTest(new EntityExceptionUnitTestCase("testNotDiscardedApplicationExceptionNoTx_local"));
100       suite.addTest(new EntityExceptionUnitTestCase("testApplicationErrorNoTx_local"));
101       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedApplicationErrorNoTx_local"));
102       suite.addTest(new EntityExceptionUnitTestCase("testEJBExceptionNoTx_local"));
103       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedEJBExceptionNoTx_local"));
104       suite.addTest(new EntityExceptionUnitTestCase("testRuntimeExceptionNoTx_local"));
105       suite.addTest(new EntityExceptionUnitTestCase("testDiscardedRuntimeExceptionNoTx_local"));
106
107       return JBossTestCase.getDeploySetup(suite, "exception.jar");
108    }
109
110    public EntityExceptionUnitTestCase(String JavaDoc name)
111    {
112       super(name);
113    }
114
115    private EntityExceptionTesterHome exceptionTesterHome;
116
117    private EntityExceptionTesterLocalHome exceptionTesterLocalHome;
118
119    /**
120     * Looks up all of the home interfaces and creates the initial data.
121     * Looking up objects in JNDI is expensive, so it should be done once
122     * and cached.
123     * @throws Exception if a problem occures while finding the home interfaces,
124     * or if an problem occures while createing the initial data
125     */

126    public void setUp() throws Exception JavaDoc
127    {
128       InitialContext JavaDoc jndi = new InitialContext JavaDoc();
129       exceptionTesterHome = (EntityExceptionTesterHome) jndi.lookup("exception/EntityExceptionTester");
130       exceptionTesterLocalHome = (EntityExceptionTesterLocalHome) jndi.lookup("exception/EntityExceptionTesterLocal");
131    }
132
133    public void testApplicationExceptionInTx_remote() throws Exception JavaDoc
134    {
135       EntityExceptionTester exceptionTester = null;
136       try
137       {
138          exceptionTester = exceptionTesterHome.create(getName());
139          exceptionTester.applicationExceptionInTx();
140          fail("Expected application exception to be thrown");
141       }
142       catch (ApplicationException e)
143       {
144          // good this was expected
145
}
146       catch (Exception JavaDoc e)
147       {
148          fail("Expected ApplicationException but got " + e);
149       }
150    }
151
152    public void testNotDiscardedApplicationExceptionInTx_remote() throws Exception JavaDoc
153    {
154       exceptionTesterHome.findByPrimaryKey("testApplicationExceptionInTx_remote");
155    }
156
157    public void testApplicationExceptionInTxMarkRollback_remote() throws Exception JavaDoc
158    {
159       EntityExceptionTester exceptionTester = null;
160       try
161       {
162          exceptionTester = exceptionTesterHome.create(getName());
163          exceptionTester.applicationExceptionInTxMarkRollback();
164          fail("Expected application exception to be thrown");
165       }
166       catch (ApplicationException e)
167       {
168          // good this was expected
169
}
170       catch (Exception JavaDoc e)
171       {
172          fail("Expected ApplicationException but got " + e);
173       }
174    }
175
176    /*
177     * It is not clear what the behaviour should be from the spec
178     *
179     void testNotDiscardedApplicationExceptionInTxMarkRollback_remote() throws Exception
180     {
181     exceptionTesterHome.findByPrimaryKey("testApplicationExceptionInTxMarkRollback_remote");
182     }
183     */

184    public void testApplicationErrorInTx_remote() throws Exception JavaDoc
185    {
186       EntityExceptionTester exceptionTester = null;
187       try
188       {
189          exceptionTester = exceptionTesterHome.create(getName());
190          exceptionTester.applicationErrorInTx();
191          fail("Expected transaction rolled back exception to be thrown");
192       }
193       catch (TransactionRolledbackException JavaDoc e)
194       {
195          // good this was expected
196
assertNotNull("TransactionRolledbackException.detail should not be null", e.detail);
197          assertEquals("TransactionRolledbackException.detail should " + "be a ApplicationError",
198                ApplicationError.class, e.detail.getClass());
199       }
200       catch (Exception JavaDoc e)
201       {
202          fail("Expected TransactionRolledbackException but got " + e);
203       }
204    }
205
206    public void testDiscardedApplicationErrorInTx_remote() throws Exception JavaDoc
207    {
208       boolean caught = false;
209       try
210       {
211          exceptionTesterHome.findByPrimaryKey("testApplicationErrorInTx_remote");
212       }
213       catch (FinderException JavaDoc expected)
214       {
215          caught = true;
216       }
217       assertTrue("Instance not discarded " + getName(), caught);
218    }
219
220    public void testEJBExceptionInTx_remote() throws Exception JavaDoc
221    {
222       EntityExceptionTester exceptionTester = null;
223       try
224       {
225          exceptionTester = exceptionTesterHome.create(getName());
226          exceptionTester.ejbExceptionInTx();
227          fail("Expected transaction rolled back exception to be thrown");
228       }
229       catch (TransactionRolledbackException JavaDoc e)
230       {
231          // good this was expected
232
assertNotNull("TransactionRolledbackException.detail should not be null", e.detail);
233          assertEquals("TransactionRolledbackException.detail should " + "be an EJBException", EJBException JavaDoc.class,
234                e.detail.getClass());
235       }
236       catch (Exception JavaDoc e)
237       {
238          fail("Expected TransactionRolledbackException but got " + e);
239       }
240    }
241
242    public void testDiscardedEJBExceptionInTx_remote() throws Exception JavaDoc
243    {
244       boolean caught = false;
245       try
246       {
247          exceptionTesterHome.findByPrimaryKey("testEJBExceptionInTx_remote");
248       }
249       catch (FinderException JavaDoc expected)
250       {
251          caught = true;
252       }
253       assertTrue("Instance not discarded " + getName(), caught);
254    }
255
256    public void testRuntimeExceptionInTx_remote() throws Exception JavaDoc
257    {
258       EntityExceptionTester exceptionTester = null;
259       try
260       {
261          exceptionTester = exceptionTesterHome.create(getName());
262          exceptionTester.runtimeExceptionInTx();
263          fail("Expected transaction rolled back exception to be thrown");
264       }
265       catch (TransactionRolledbackException JavaDoc e)
266       {
267          // good this was expected
268
assertNotNull("TransactionRolledbackException.detail should not be null", e.detail);
269          assertEquals("TransactionRolledbackException.detail should " + "be a RuntimeException",
270                RuntimeException JavaDoc.class, e.detail.getClass());
271       }
272       catch (Exception JavaDoc e)
273       {
274          fail("Expected TransactionRolledbackException but got " + e);
275       }
276    }
277
278    public void testDiscardedRuntimeExceptionInTx_remote() throws Exception JavaDoc
279    {
280       boolean caught = false;
281       try
282       {
283          exceptionTesterHome.findByPrimaryKey("testRuntimeExceptionInTx_remote");
284       }
285       catch (FinderException JavaDoc expected)
286       {
287          caught = true;
288       }
289       assertTrue("Instance not discarded " + getName(), caught);
290    }
291
292    public void testRemoteExceptionInTx_remote() throws Exception JavaDoc
293    {
294       EntityExceptionTester exceptionTester = null;
295       try
296       {
297          exceptionTester = exceptionTesterHome.create(getName());
298          exceptionTester.remoteExceptionInTx();
299          fail("Expected transaction rolled back exception to be thrown");
300       }
301       catch (TransactionRolledbackException JavaDoc e)
302       {
303          // good this was expected
304
assertNotNull("TransactionRolledbackException.detail should not be null", e.detail);
305          assertEquals("TransactionRolledbackException.detail should " + "be a RemoteException", RemoteException JavaDoc.class,
306                e.detail.getClass());
307       }
308       catch (Exception JavaDoc e)
309       {
310          fail("Expected TransactionRolledbackException but got " + e);
311       }
312    }
313
314    public void testDiscardedRemoteExceptionInTx_remote() throws Exception JavaDoc
315    {
316       boolean caught = false;
317       try
318       {
319          exceptionTesterHome.findByPrimaryKey("testRemoteExceptionInTx_remote");
320       }
321       catch (FinderException JavaDoc expected)
322       {
323          caught = true;
324       }
325       assertTrue("Instance not discarded " + getName(), caught);
326    }
327
328    public void testApplicationExceptionNewTx_remote() throws Exception JavaDoc
329    {
330       EntityExceptionTester exceptionTester = null;
331       try
332       {
333          exceptionTester = exceptionTesterHome.create(getName());
334          exceptionTester.applicationExceptionNewTx();
335          fail("Expected application exception to be thrown");
336       }
337       catch (ApplicationException e)
338       {
339          // good this was expected
340
}
341       catch (Exception JavaDoc e)
342       {
343          fail("Expected ApplicationException but got " + e);
344       }
345    }
346
347    public void testNotDiscardedApplicationExceptionNewTx_remote() throws Exception JavaDoc
348    {
349       exceptionTesterHome.findByPrimaryKey("testApplicationExceptionNewTx_remote");
350    }
351
352    public void testApplicationExceptionNewTxMarkRollback_remote() throws Exception JavaDoc
353    {
354       EntityExceptionTester exceptionTester = null;
355       try
356       {
357          exceptionTester = exceptionTesterHome.create(getName());
358          exceptionTester.applicationExceptionNewTxMarkRollback();
359          fail("Expected application exception to be thrown");
360       }
361       catch (ApplicationException e)
362       {
363          // good this was expected
364
}
365       catch (Exception JavaDoc e)
366       {
367          fail("Expected ApplicationException but got " + e);
368       }
369    }
370
371    /*
372     * It is not clear what the behaviour should be from the spec
373     *
374     public void testNotDiscardedApplicationExceptionNewTxMarkRollback_remote() throws Exception
375     {
376     exceptionTesterHome.findByPrimaryKey("testApplicationExceptionNewTxMarkRollback_remote");
377     }
378     */

379    public void testApplicationErrorNewTx_remote() throws Exception JavaDoc
380    {
381       EntityExceptionTester exceptionTester = null;
382       try
383       {
384          exceptionTester = exceptionTesterHome.create(getName());
385          exceptionTester.applicationErrorNewTx();
386          fail("Expected RemoteException to be thrown");
387       }
388       catch (RemoteException JavaDoc e)
389       {
390          // good this was expected
391
assertNotNull("RemoteException.detail should not be null", e.detail);
392          assertEquals("RemoteException.detail should be a ApplicationError", ApplicationError.class, e.detail
393                .getClass());
394       }
395       catch (Exception JavaDoc e)
396       {
397          fail("Expected RemoteException but got " + e);
398       }
399    }
400
401    public void testDiscardedApplicationErrorNewTx_remote() throws Exception JavaDoc
402    {
403       boolean caught = false;
404       try
405       {
406          exceptionTesterHome.findByPrimaryKey("testApplicationErrorNewTx_remote");
407       }
408       catch (FinderException JavaDoc expected)
409       {
410          caught = true;
411       }
412       assertTrue("Instance not discarded " + getName(), caught);
413    }
414
415    public void testEJBExceptionNewTx_remote() throws Exception JavaDoc
416    {
417       EntityExceptionTester exceptionTester = null;
418       try
419       {
420          exceptionTester = exceptionTesterHome.create(getName());
421          exceptionTester.ejbExceptionNewTx();
422          fail("Expected RemoteException to be thrown");
423       }
424       catch (RemoteException JavaDoc e)
425       {
426          // good this was expected
427
assertNotNull("RemoteException.detail should not be null", e.detail);
428          assertEquals("RemoteException.detail should be a EJBException", EJBException JavaDoc.class, e.detail.getClass());
429       }
430       catch (Exception JavaDoc e)
431       {
432          fail("Expected RemoteException but got " + e);
433       }
434    }
435
436    public void testDiscardedEJBExceptionNewTx_remote() throws Exception JavaDoc
437    {
438       boolean caught = false;
439       try
440       {
441          exceptionTesterHome.findByPrimaryKey("testEJBExceptionNewTx_remote");
442       }
443       catch (FinderException JavaDoc expected)
444       {
445          caught = true;
446       }
447       assertTrue("Instance not discarded " + getName(), caught);
448    }
449
450    public void testRuntimeExceptionNewTx_remote() throws Exception JavaDoc
451    {
452       EntityExceptionTester exceptionTester = null;
453       try
454       {
455          exceptionTester = exceptionTesterHome.create(getName());
456          exceptionTester.runtimeExceptionNewTx();
457          fail("Expected RemoteException to be thrown");
458       }
459       catch (RemoteException JavaDoc e)
460       {
461          // good this was expected
462
assertNotNull("RemoteException.detail should not be null", e.detail);
463          assertEquals("RemoteException.detail should be a RuntimeException", RuntimeException JavaDoc.class, e.detail
464                .getClass());
465       }
466       catch (Exception JavaDoc e)
467       {
468          fail("Expected RemoteException but got " + e);
469       }
470    }
471
472    public void testDiscardedRuntimeExceptionNewTx_remote() throws Exception JavaDoc
473    {
474       boolean caught = false;
475       try
476       {
477          exceptionTesterHome.findByPrimaryKey("testRuntimeExceptionNewTx_remote");
478       }
479       catch (FinderException JavaDoc expected)
480       {
481          caught = true;
482       }
483       assertTrue("Instance not discarded " + getName(), caught);
484    }
485
486    public void testRemoteExceptionNewTx_remote() throws Exception JavaDoc
487    {
488       EntityExceptionTester exceptionTester = null;
489       try
490       {
491          exceptionTester = exceptionTesterHome.create(getName());
492          exceptionTester.remoteExceptionNewTx();
493          fail("Expected RemoteException to be thrown");
494       }
495       catch (RemoteException JavaDoc e)
496       {
497          // good this was expected
498
}
499       catch (Exception JavaDoc e)
500       {
501          fail("Expected RemoteException but got " + e);
502       }
503    }
504
505    public void testDiscardedRemoteExceptionNewTx_remote() throws Exception JavaDoc
506    {
507       boolean caught = false;
508       try
509       {
510          exceptionTesterHome.findByPrimaryKey("testRemoteExceptionNewTx_remote");
511       }
512       catch (FinderException JavaDoc expected)
513       {
514          caught = true;
515       }
516       assertTrue("Instance not discarded " + getName(), caught);
517    }
518
519    public void testApplicationExceptionNoTx_remote() throws Exception JavaDoc
520    {
521       EntityExceptionTester exceptionTester = null;
522       try
523       {
524          exceptionTester = exceptionTesterHome.create(getName());
525          exceptionTester.applicationExceptionNoTx();
526          fail("Expected application exception to be thrown");
527       }
528       catch (ApplicationException e)
529       {
530          // good this was expected
531
}
532       catch (Exception JavaDoc e)
533       {
534          fail("Expected ApplicationException but got " + e);
535       }
536    }
537
538    public void testNotDiscardedApplicationExceptionNoTx_remote() throws Exception JavaDoc
539    {
540       exceptionTesterHome.findByPrimaryKey("testApplicationExceptionNoTx_remote");
541    }
542
543    public void testApplicationErrorNoTx_remote() throws Exception JavaDoc
544    {
545       EntityExceptionTester exceptionTester = null;
546       try
547       {
548          exceptionTester = exceptionTesterHome.create(getName());
549          exceptionTester.applicationErrorNoTx();
550          fail("Expected RemoteException to be thrown");
551       }
552       catch (RemoteException JavaDoc e)
553       {
554          // good this was expected
555
assertNotNull("RemoteException.detail should not be null", e.detail);
556          assertEquals("RemoteException.detail should be a ApplicationError", ApplicationError.class, e.detail
557                .getClass());
558       }
559       catch (Exception JavaDoc e)
560       {
561          fail("Expected RemoteException but got " + e);
562       }
563    }
564
565    public void testDiscardedApplicationErrorNoTx_remote() throws Exception JavaDoc
566    {
567       boolean caught = false;
568       try
569       {
570          exceptionTesterHome.findByPrimaryKey("testApplicationErrorNoTx_remote");
571       }
572       catch (FinderException JavaDoc expected)
573       {
574          caught = true;
575       }
576       assertTrue("Instance not discarded " + getName(), caught);
577    }
578
579    public void testEJBExceptionNoTx_remote() throws Exception JavaDoc
580    {
581       EntityExceptionTester exceptionTester = null;
582       try
583       {
584          exceptionTester = exceptionTesterHome.create(getName());
585          exceptionTester.ejbExceptionNoTx();
586          fail("Expected RemoteException to be thrown");
587       }
588       catch (RemoteException JavaDoc e)
589       {
590          // good this was expected
591
assertNotNull("RemoteException.detail should not be null", e.detail);
592          assertEquals("RemoteException.detail should be a EJBException", EJBException JavaDoc.class, e.detail.getClass());
593       }
594       catch (Exception JavaDoc e)
595       {
596          fail("Expected RemoteException but got " + e);
597       }
598    }
599
600    public void testDiscardedEJBExceptionNoTx_remote() throws Exception JavaDoc
601    {
602       boolean caught = false;
603       try
604       {
605          exceptionTesterHome.findByPrimaryKey("testEJBExceptionNoTx_remote");
606       }
607       catch (FinderException JavaDoc expected)
608       {
609          caught = true;
610       }
611       assertTrue("Instance not discarded " + getName(), caught);
612    }
613
614    public void testRuntimeExceptionNoTx_remote() throws Exception JavaDoc
615    {
616       EntityExceptionTester exceptionTester = null;
617       try
618       {
619          exceptionTester = exceptionTesterHome.create(getName());
620          exceptionTester.runtimeExceptionNoTx();
621          fail("Expected RemoteException to be thrown");
622       }
623       catch (RemoteException JavaDoc e)
624       {
625          // good this was expected
626
assertNotNull("RemoteException.detail should not be null", e.detail);
627          assertEquals("RemoteException.detail should be a RuntimeException", RuntimeException JavaDoc.class, e.detail
628                .getClass());
629       }
630       catch (Exception JavaDoc e)
631       {
632          fail("Expected RemoteException but got " + e);
633       }
634    }
635
636    public void testDiscardedRuntimeExceptionNoTx_remote() throws Exception JavaDoc
637    {
638       boolean caught = false;
639       try
640       {
641          exceptionTesterHome.findByPrimaryKey("testRuntimeExceptionNoTx_remote");
642       }
643       catch (FinderException JavaDoc expected)
644       {
645          caught = true;
646       }
647       assertTrue("Instance not discarded " + getName(), caught);
648    }
649
650    public void testRemoteExceptionNoTx_remote() throws Exception JavaDoc
651    {
652       EntityExceptionTester exceptionTester = null;
653       try
654       {
655          exceptionTester = exceptionTesterHome.create(getName());
656          exceptionTester.remoteExceptionNoTx();
657          fail("Expected RemoteException to be thrown");
658       }
659       catch (RemoteException JavaDoc e)
660       {
661          // good this was expected
662
}
663       catch (Exception JavaDoc e)
664       {
665          fail("Expected RemoteException but got " + e);
666       }
667    }
668
669    public void testDiscardedRemoteExceptionNoTx_remote() throws Exception JavaDoc
670    {
671       boolean caught = false;
672       try
673       {
674          exceptionTesterHome.findByPrimaryKey("testRemoteExceptionNoTx_remote");
675       }
676       catch (FinderException JavaDoc expected)
677       {
678          caught = true;
679       }
680       assertTrue("Instance not discarded " + getName(), caught);
681    }
682
683    public void testApplicationExceptionInTx_local() throws Exception JavaDoc
684    {
685       EntityExceptionTesterLocal exceptionTester = null;
686       try
687       {
688          exceptionTester = exceptionTesterLocalHome.create(getName());
689          exceptionTester.applicationExceptionInTx();
690          fail("Expected ApplicationException to be thrown");
691       }
692       catch (ApplicationException e)
693       {
694          // good this was expected
695
}
696       catch (Exception JavaDoc e)
697       {
698          fail("Expected ApplicationException but got " + e);
699       }
700    }
701
702    public void testNotDiscardedApplicationExceptionInTx_local() throws Exception JavaDoc
703    {
704       exceptionTesterHome.findByPrimaryKey("testApplicationExceptionInTx_local");
705    }
706
707    public void testApplicationExceptionInTxMarkRollback_local() throws Exception JavaDoc
708    {
709       EntityExceptionTesterLocal exceptionTester = null;
710       try
711       {
712          exceptionTester = exceptionTesterLocalHome.create(getName());
713          exceptionTester.applicationExceptionInTxMarkRollback();
714          fail("Expected ApplicationException to be thrown");
715       }
716       catch (ApplicationException e)
717       {
718          // good this was expected
719
}
720       catch (Exception JavaDoc e)
721       {
722          fail("Expected ApplicationException but got " + e);
723       }
724    }
725
726    /*
727     * It is not clear what the behaviour should be from the spec
728     *
729     public void testNotDiscardedApplicationExceptionInTxMarkRollback_local() throws Exception
730     {
731     exceptionTesterHome.findByPrimaryKey("testApplicationExceptionInTxMarkRollback_local");
732     }
733     */

734    public void testApplicationErrorInTx_local() throws Exception JavaDoc
735    {
736       EntityExceptionTesterLocal exceptionTester = null;
737       try
738       {
739          exceptionTester = exceptionTesterLocalHome.create(getName());
740          exceptionTester.applicationErrorInTx();
741          fail("Expected TransactionRolledbackLocalException to be thrown");
742       }
743       catch (TransactionRolledbackLocalException JavaDoc e)
744       {
745          // good this was expected
746
assertNotNull("TransactionRolledbackLocalException.getCausedByException() " + "should not be null", e
747                .getCausedByException());
748          assertEquals("TransactionRolledbackLocalException.getCausedByExcption() " + "should be an EJBException",
749                EJBException JavaDoc.class, e.getCausedByException().getClass());
750       }
751       catch (Exception JavaDoc e)
752       {
753          fail("Expected TransactionRolledbackLocalException but got " + e);
754       }
755    }
756
757    public void testDiscardedApplicationErrorInTx_local() throws Exception JavaDoc
758    {
759       boolean caught = false;
760       try
761       {
762          exceptionTesterHome.findByPrimaryKey("testApplicationErrorInTx_local");
763       }
764       catch (FinderException JavaDoc expected)
765       {
766          caught = true;
767       }
768       assertTrue("Instance not discarded " + getName(), caught);
769    }
770
771    public void testEJBExceptionInTx_local() throws Exception JavaDoc
772    {
773       EntityExceptionTesterLocal exceptionTester = null;
774       try
775       {
776          exceptionTester = exceptionTesterLocalHome.create(getName());
777          exceptionTester.ejbExceptionInTx();
778          fail("Expected TransactionRolledbackLocalException to be thrown");
779       }
780       catch (TransactionRolledbackLocalException JavaDoc e)
781       {
782          // good this was expected
783
assertNotNull("TransactionRolledbackLocalException.getCausedByException() " + "should not be null", e
784                .getCausedByException());
785          assertEquals("TransactionRolledbackLocalException.getCausedByException() " + "should be an EJBException",
786                EJBException JavaDoc.class, e.getCausedByException().getClass());
787       }
788       catch (Exception JavaDoc e)
789       {
790          fail("Expected TransactionRolledbackLocalException but got " + e);
791       }
792    }
793
794    public void testDiscardedEJBExceptionInTx_local() throws Exception JavaDoc
795    {
796       boolean caught = false;
797       try
798       {
799          exceptionTesterHome.findByPrimaryKey("testEJBExceptionInTx_local");
800       }
801       catch (FinderException JavaDoc expected)
802       {
803          caught = true;
804       }
805       assertTrue("Instance not discarded " + getName(), caught);
806    }
807
808    public void testRuntimeExceptionInTx_local() throws Exception JavaDoc
809    {
810       EntityExceptionTesterLocal exceptionTester = null;
811       try
812       {
813          exceptionTester = exceptionTesterLocalHome.create(getName());
814          exceptionTester.runtimeExceptionInTx();
815          fail("Expected TransactionRolledbackLocalException to be thrown");
816       }
817       catch (TransactionRolledbackLocalException JavaDoc e)
818       {
819          // good this was expected
820
assertNotNull("TransactionRolledbackLocalException.getCausedByException() " + "should not be null", e
821                .getCausedByException());
822          assertEquals("TransactionRolledbackLocalException.getCausedByException() " + "should be a RuntimeException",
823                RuntimeException JavaDoc.class, e.getCausedByException().getClass());
824       }
825       catch (Exception JavaDoc e)
826       {
827          fail("Expected TransactionRolledbackLocalException but got " + e);
828       }
829    }
830
831    public void testDiscardedRuntimeExceptionInTx_local() throws Exception JavaDoc
832    {
833       boolean caught = false;
834       try
835       {
836          exceptionTesterHome.findByPrimaryKey("testRuntimeExceptionInTx_local");
837       }
838       catch (FinderException JavaDoc expected)
839       {
840          caught = true;
841       }
842       assertTrue("Instance not discarded " + getName(), caught);
843    }
844
845    public void testApplicationExceptionNewTx_local() throws Exception JavaDoc
846    {
847       EntityExceptionTesterLocal exceptionTester = null;
848       try
849       {
850          exceptionTester = exceptionTesterLocalHome.create(getName());
851          exceptionTester.applicationExceptionNewTx();
852          fail("Expected ApplicationException to be thrown");
853       }
854       catch (ApplicationException e)
855       {
856          // good this was expected
857
}
858       catch (Exception JavaDoc e)
859       {
860          fail("Expected ApplicationException but got " + e);
861       }
862    }
863
864    public void testNotDiscardedApplicationExceptionNewTx_local() throws Exception JavaDoc
865    {
866       exceptionTesterHome.findByPrimaryKey("testApplicationExceptionNewTx_local");
867    }
868
869    public void testApplicationExceptionNewTxMarkRollback_local() throws Exception JavaDoc
870    {
871       EntityExceptionTesterLocal exceptionTester = null;
872       try
873       {
874          exceptionTester = exceptionTesterLocalHome.create(getName());
875          exceptionTester.applicationExceptionNewTxMarkRollback();
876          fail("Expected ApplicationException to be thrown");
877       }
878       catch (ApplicationException e)
879       {
880          // good this was expected
881
}
882       catch (Exception JavaDoc e)
883       {
884          fail("Expected ApplicationException but got " + e);
885       }
886    }
887
888    /*
889     * It is not clear what the behaviour should be from the spec
890     *
891     public void testNotDiscardedApplicationExceptionNewTxMarkRollback_local() throws Exception
892     {
893     exceptionTesterHome.findByPrimaryKey("testApplicationExceptionNewTxMarkRollback_local");
894     }
895     */

896    public void testApplicationErrorNewTx_local() throws Exception JavaDoc
897    {
898       EntityExceptionTesterLocal exceptionTester = null;
899       try
900       {
901          exceptionTester = exceptionTesterLocalHome.create(getName());
902          exceptionTester.applicationErrorNewTx();
903          fail("Expected EJBException to be thrown");
904       }
905       catch (EJBException JavaDoc e)
906       {
907          // good this was expected
908
assertNull("EJBException.getCausedByException() should be null", e.getCausedByException());
909       }
910       catch (Exception JavaDoc e)
911       {
912          fail("Expected EJBException but got " + e);
913       }
914    }
915
916    public void testDiscardedApplicationErrorNewTx_local() throws Exception JavaDoc
917    {
918       boolean caught = false;
919       try
920       {
921          exceptionTesterHome.findByPrimaryKey("testApplicationErrorNewTx_local");
922       }
923       catch (FinderException JavaDoc expected)
924       {
925          caught = true;
926       }
927       assertTrue("Instance not discarded " + getName(), caught);
928    }
929
930    public void testEJBExceptionNewTx_local() throws Exception JavaDoc
931    {
932       EntityExceptionTesterLocal exceptionTester = null;
933       try
934       {
935          exceptionTester = exceptionTesterLocalHome.create(getName());
936          exceptionTester.ejbExceptionNewTx();
937          fail("Expected EJBException to be thrown");
938       }
939       catch (EJBException JavaDoc e)
940       {
941          // good this was expected
942
assertNull("EJBException.getCausedByException() should be null", e.getCausedByException());
943       }
944       catch (Exception JavaDoc e)
945       {
946          fail("Expected EJBException but got " + e);
947       }
948    }
949
950    public void testDiscardedEJBExceptionNewTx_local() throws Exception JavaDoc
951    {
952       boolean caught = false;
953       try
954       {
955          exceptionTesterHome.findByPrimaryKey("testEJBExceptionNewTx_local");
956       }
957       catch (FinderException JavaDoc expected)
958       {
959          caught = true;
960       }
961       assertTrue("Instance not discarded " + getName(), caught);
962    }
963
964    public void testRuntimeExceptionNewTx_local() throws Exception JavaDoc
965    {
966       EntityExceptionTesterLocal exceptionTester = null;
967       try
968       {
969          exceptionTester = exceptionTesterLocalHome.create(getName());
970          exceptionTester.runtimeExceptionNewTx();
971          fail("Expected EJBException to be thrown");
972       }
973       catch (EJBException JavaDoc e)
974       {
975          // good this was expected
976
assertNotNull("EJBException.getCausedByException() should not be null", e.getCausedByException());
977          assertEquals("EJBException.getCausedByException() should be " + "a RuntimeException", RuntimeException JavaDoc.class,
978                e.getCausedByException().getClass());
979       }
980       catch (Exception JavaDoc e)
981       {
982          fail("Expected EJBException but got " + e);
983       }
984    }
985
986    public void testDiscardedRuntimeExceptionNewTx_local() throws Exception JavaDoc
987    {
988       boolean caught = false;
989       try
990       {
991          exceptionTesterHome.findByPrimaryKey("testRuntimeExceptionNewTx_local");
992       }
993       catch (FinderException JavaDoc expected)
994       {
995          caught = true;
996       }
997       assertTrue("Instance not discarded " + getName(), caught);
998    }
999
1000   public void testApplicationExceptionNoTx_local() throws Exception JavaDoc
1001   {
1002      EntityExceptionTesterLocal exceptionTester = null;
1003      try
1004      {
1005         exceptionTester = exceptionTesterLocalHome.create(getName());
1006         exceptionTester.applicationExceptionNoTx();
1007         fail("Expected application exception to be thrown");
1008      }
1009      catch (ApplicationException e)
1010      {
1011         // good this was expected
1012
}
1013      catch (Exception JavaDoc e)
1014      {
1015         fail("Expected ApplicationException but got " + e);
1016      }
1017   }
1018
1019   public void testNotDiscardedApplicationExceptionNoTx_local() throws Exception JavaDoc
1020   {
1021      exceptionTesterHome.findByPrimaryKey("testApplicationExceptionNoTx_local");
1022   }
1023
1024   public void testApplicationErrorNoTx_local() throws Exception JavaDoc
1025   {
1026      EntityExceptionTesterLocal exceptionTester = null;
1027      try
1028      {
1029         exceptionTester = exceptionTesterLocalHome.create(getName());
1030         exceptionTester.applicationErrorNoTx();
1031         fail("Expected EJBException to be thrown");
1032      }
1033      catch (EJBException JavaDoc e)
1034      {
1035         // good this was expected
1036
assertNull("EJBException.getCausedByException() should be null", e.getCausedByException());
1037      }
1038      catch (Exception JavaDoc e)
1039      {
1040         fail("Expected EJBException but got " + e);
1041      }
1042   }
1043
1044   public void testDiscardedApplicationErrorNoTx_local() throws Exception JavaDoc
1045   {
1046      boolean caught = false;
1047      try
1048      {
1049         exceptionTesterHome.findByPrimaryKey("testApplicationErrorNoTx_local");
1050      }
1051      catch (FinderException JavaDoc expected)
1052      {
1053         caught = true;
1054      }
1055      assertTrue("Instance not discarded " + getName(), caught);
1056   }
1057
1058   public void testEJBExceptionNoTx_local() throws Exception JavaDoc
1059   {
1060      EntityExceptionTesterLocal exceptionTester = null;
1061      try
1062      {
1063         exceptionTester = exceptionTesterLocalHome.create(getName());
1064         exceptionTester.ejbExceptionNoTx();
1065         fail("Expected EJBException to be thrown");
1066      }
1067      catch (EJBException JavaDoc e)
1068      {
1069         // good this was expected
1070
assertNull("EJBException.getCausedByException() should be null", e.getCausedByException());
1071      }
1072      catch (Exception JavaDoc e)
1073      {
1074         fail("Expected EJBException but got " + e);
1075      }
1076   }
1077
1078   public void testDiscardedEJBExceptionNoTx_local() throws Exception JavaDoc
1079   {
1080      boolean caught = false;
1081      try
1082      {
1083         exceptionTesterHome.findByPrimaryKey("testEJBExceptionNoTx_local");
1084      }
1085      catch (FinderException JavaDoc expected)
1086      {
1087         caught = true;
1088      }
1089      assertTrue("Instance not discarded " + getName(), caught);
1090   }
1091
1092   public void testRuntimeExceptionNoTx_local() throws Exception JavaDoc
1093   {
1094      EntityExceptionTesterLocal exceptionTester = null;
1095      try
1096      {
1097         exceptionTester = exceptionTesterLocalHome.create(getName());
1098         exceptionTester.runtimeExceptionNoTx();
1099         fail("Expected EJBException to be thrown");
1100      }
1101      catch (EJBException JavaDoc e)
1102      {
1103         // good this was expected
1104
assertNotNull("EJBException.getCausedByException() should not be null", e.getCausedByException());
1105         assertEquals("EJBException.getCausedByException() should be " + "a RuntimeException", RuntimeException JavaDoc.class,
1106               e.getCausedByException().getClass());
1107      }
1108      catch (Exception JavaDoc e)
1109      {
1110         fail("Expected EJBException but got " + e);
1111      }
1112   }
1113
1114   public void testDiscardedRuntimeExceptionNoTx_local() throws Exception JavaDoc
1115   {
1116      boolean caught = false;
1117      try
1118      {
1119         exceptionTesterHome.findByPrimaryKey("testRuntimeExceptionNoTx_local");
1120      }
1121      catch (FinderException JavaDoc expected)
1122      {
1123         caught = true;
1124      }
1125      assertTrue("Instance not discarded " + getName(), caught);
1126   }
1127}
Popular Tags