KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.rmi.AccessException JavaDoc;
26 import java.security.GeneralSecurityException JavaDoc;
27 import java.security.InvalidKeyException JavaDoc;
28 import javax.ejb.EJBException JavaDoc;
29 import javax.ejb.TransactionRolledbackLocalException JavaDoc;
30 import javax.ejb.AccessLocalException JavaDoc;
31 import javax.ejb.CreateException JavaDoc;
32 import javax.naming.InitialContext JavaDoc;
33 import javax.transaction.TransactionRolledbackException JavaDoc;
34
35 import junit.framework.Test;
36 import org.jboss.logging.Logger;
37 import org.jboss.test.JBossTestCase;
38 import org.jboss.test.util.ejb.EJBTestCase;
39
40 /**
41  * Test ejb exception propagation
42  *
43  * @author Scott.Stark@jboss.org
44  * @version $Revision: 41274 $
45  */

46 public class ExceptionUnitTestCase extends EJBTestCase
47 {
48    static Logger log = Logger.getLogger(ExceptionUnitTestCase.class);
49
50    public static Test suite() throws Exception JavaDoc
51    {
52       return JBossTestCase.getDeploySetup(ExceptionUnitTestCase.class,
53          "exception.jar");
54    }
55
56    public ExceptionUnitTestCase(String JavaDoc name)
57    {
58       super(name);
59    }
60
61    private ExceptionTesterHome exceptionTesterHome;
62    private ExceptionTesterLocalHome exceptionTesterLocalHome;
63
64    /**
65     * Looks up all of the home interfaces and creates the initial data. Looking
66     * up objects in JNDI is expensive, so it should be done once and cached.
67     * @throws Exception if a problem occures while finding the home interfaces,
68     * or if an problem occures while createing the initial data
69     */

70    public void setUp() throws Exception JavaDoc
71    {
72       InitialContext JavaDoc jndi = new InitialContext JavaDoc();
73       exceptionTesterHome = (ExceptionTesterHome)
74          jndi.lookup("exception/ExceptionTester");
75       exceptionTesterLocalHome = (ExceptionTesterLocalHome)
76          jndi.lookup("exception/ExceptionTesterLocal");
77    }
78
79    public void testSessionEjbCreateException() throws Exception JavaDoc
80    {
81       log.info("+++ testSessionEjbCreateException");
82       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
83       ExceptionTesterHome home = (ExceptionTesterHome)
84          ctx.lookup("exception/CreateExceptionTesterEJB");
85       try
86       {
87          ExceptionTester bean = home.create();
88          fail("Expected CreateException on ExceptionTesterHome.create(), bean="+bean);
89       }
90       catch(CreateException JavaDoc e)
91       {
92          log.info("Saw CreateException via remote as expected", e);
93       }
94
95       ExceptionTesterLocalHome lhome = (ExceptionTesterLocalHome)
96          ctx.lookup("exception/CreateExceptionTesterLocalEJB");
97       try
98       {
99          ExceptionTesterLocal bean = lhome.create();
100          fail("Expected CreateException on ExceptionTesterLocalHome.create(), bean="+bean);
101       }
102       catch(CreateException JavaDoc e)
103       {
104          log.info("Saw CreateException via local as expected", e);
105       }
106    }
107
108    public void testApplicationExceptionInTx_remote() throws Exception JavaDoc
109    {
110       ExceptionTester exceptionTester = null;
111       try
112       {
113          exceptionTester = exceptionTesterHome.create();
114
115          exceptionTester.applicationExceptionInTx();
116
117          fail("Expected application exception to be thrown");
118
119       }
120       catch (ApplicationException e)
121       {
122          // good this was expected
123
}
124       catch (Exception JavaDoc e)
125       {
126          fail("Expected ApplicationException but got " + e);
127       }
128       finally
129       {
130          if (exceptionTester != null)
131          {
132             exceptionTester.remove();
133          }
134       }
135    }
136
137    public void testApplicationErrorInTx_remote() throws Exception JavaDoc
138    {
139       ExceptionTester exceptionTester = null;
140       try
141       {
142          exceptionTester = exceptionTesterHome.create();
143
144          exceptionTester.applicationErrorInTx();
145
146          fail("Expected transaction rolled back exception to be thrown");
147
148       }
149       catch (TransactionRolledbackException JavaDoc e)
150       {
151          // good this was expected
152
assertNotNull("TransactionRolledbackException.detail should not be null",
153             e.detail);
154
155          assertEquals("TransactionRolledbackException.detail should " +
156             "be a ApplicationError",
157             ApplicationError.class,
158             e.detail.getClass());
159
160       }
161       catch (Exception JavaDoc e)
162       {
163          fail("Expected TransactionRolledbackException but got " + e);
164       }
165       finally
166       {
167          if (exceptionTester != null)
168          {
169             exceptionTester.remove();
170          }
171       }
172    }
173
174    public void testEJBExceptionInTx_remote() throws Exception JavaDoc
175    {
176       ExceptionTester exceptionTester = null;
177       try
178       {
179          exceptionTester = exceptionTesterHome.create();
180
181          exceptionTester.ejbExceptionInTx();
182
183          fail("Expected transaction rolled back exception to be thrown");
184
185       }
186       catch (TransactionRolledbackException JavaDoc e)
187       {
188          // good this was expected
189
assertNotNull("TransactionRolledbackException.detail should not be null",
190             e.detail);
191          assertEquals("TransactionRolledbackException.detail should " +
192             "be an EJBException",
193             EJBException JavaDoc.class,
194             e.detail.getClass());
195
196       }
197       catch (Exception JavaDoc e)
198       {
199          fail("Expected TransactionRolledbackException but got " + e);
200       }
201       finally
202       {
203          if (exceptionTester != null)
204          {
205             exceptionTester.remove();
206          }
207       }
208    }
209
210
211    public void testRuntimeExceptionInTx_remote() throws Exception JavaDoc
212    {
213       ExceptionTester exceptionTester = null;
214       try
215       {
216          exceptionTester = exceptionTesterHome.create();
217
218          exceptionTester.runtimeExceptionInTx();
219
220          fail("Expected transaction rolled back exception to be thrown");
221
222       }
223       catch (TransactionRolledbackException JavaDoc e)
224       {
225          // good this was expected
226
assertNotNull("TransactionRolledbackException.detail should not be null",
227             e.detail);
228
229          assertEquals("TransactionRolledbackException.detail should " +
230             "be a RuntimeException",
231             RuntimeException JavaDoc.class,
232             e.detail.getClass());
233
234       }
235       catch (Exception JavaDoc e)
236       {
237          fail("Expected TransactionRolledbackException but got " + e);
238       }
239       finally
240       {
241          if (exceptionTester != null)
242          {
243             exceptionTester.remove();
244          }
245       }
246    }
247
248
249    public void testRemoteExceptionInTx_remote() throws Exception JavaDoc
250    {
251       ExceptionTester exceptionTester = null;
252       try
253       {
254          exceptionTester = exceptionTesterHome.create();
255
256          exceptionTester.remoteExceptionInTx();
257
258          fail("Expected transaction rolled back exception to be thrown");
259
260       }
261       catch (TransactionRolledbackException JavaDoc e)
262       {
263          // good this was expected
264
assertNotNull("TransactionRolledbackException.detail should not be null",
265             e.detail);
266          assertEquals("TransactionRolledbackException.detail should " +
267             "be a RemoteException",
268             RemoteException JavaDoc.class,
269             e.detail.getClass());
270
271       }
272       catch (Exception JavaDoc e)
273       {
274          fail("Expected TransactionRolledbackException but got " + e);
275       }
276       finally
277       {
278          if (exceptionTester != null)
279          {
280             exceptionTester.remove();
281          }
282       }
283    }
284
285    public void testApplicationExceptionNewTx_remote() throws Exception JavaDoc
286    {
287       ExceptionTester exceptionTester = null;
288       try
289       {
290          exceptionTester = exceptionTesterHome.create();
291
292          exceptionTester.applicationExceptionNewTx();
293
294          fail("Expected application exception to be thrown");
295
296       }
297       catch (ApplicationException e)
298       {
299          // good this was expected
300
}
301       catch (Exception JavaDoc e)
302       {
303          fail("Expected ApplicationException but got " + e);
304       }
305       finally
306       {
307          if (exceptionTester != null)
308          {
309             exceptionTester.remove();
310          }
311       }
312    }
313
314    public void testApplicationErrorNewTx_remote() throws Exception JavaDoc
315    {
316       ExceptionTester exceptionTester = null;
317       try
318       {
319          exceptionTester = exceptionTesterHome.create();
320
321          exceptionTester.applicationErrorNewTx();
322
323          fail("Expected RemoteException to be thrown");
324
325       }
326       catch (RemoteException JavaDoc e)
327       {
328          // good this was expected
329
assertNotNull("RemoteException.detail should not be null",
330             e.detail);
331
332          assertEquals("RemoteException.detail should be a ApplicationError",
333             ApplicationError.class,
334             e.detail.getClass());
335       }
336       catch (Exception JavaDoc e)
337       {
338          fail("Expected RemoteException but got " + e);
339       }
340       finally
341       {
342          if (exceptionTester != null)
343          {
344             exceptionTester.remove();
345          }
346       }
347    }
348
349    public void testEJBExceptionNewTx_remote() throws Exception JavaDoc
350    {
351       ExceptionTester exceptionTester = null;
352       try
353       {
354          exceptionTester = exceptionTesterHome.create();
355
356          exceptionTester.ejbExceptionNewTx();
357
358          fail("Expected RemoteException to be thrown");
359
360       }
361       catch (RemoteException JavaDoc e)
362       {
363          // good this was expected
364
assertNotNull("RemoteException.detail should not be null",
365             e.detail);
366
367          assertEquals("RemoteException.detail should be a EJBException",
368             EJBException JavaDoc.class,
369             e.detail.getClass());
370       }
371       catch (Exception JavaDoc e)
372       {
373          fail("Expected RemoteException but got " + e);
374       }
375       finally
376       {
377          if (exceptionTester != null)
378          {
379             exceptionTester.remove();
380          }
381       }
382    }
383
384
385    public void testRuntimeExceptionNewTx_remote() throws Exception JavaDoc
386    {
387       ExceptionTester exceptionTester = null;
388       try
389       {
390          exceptionTester = exceptionTesterHome.create();
391
392          exceptionTester.runtimeExceptionNewTx();
393
394          fail("Expected RemoteException to be thrown");
395
396       }
397       catch (RemoteException JavaDoc e)
398       {
399          // good this was expected
400
assertNotNull("RemoteException.detail should not be null",
401             e.detail);
402
403          assertEquals("RemoteException.detail should be a RuntimeException",
404             RuntimeException JavaDoc.class,
405             e.detail.getClass());
406
407       }
408       catch (Exception JavaDoc e)
409       {
410          fail("Expected RemoteException but got " + e);
411       }
412       finally
413       {
414          if (exceptionTester != null)
415          {
416             exceptionTester.remove();
417          }
418       }
419    }
420
421
422    public void testRemoteExceptionNewTx_remote() throws Exception JavaDoc
423    {
424       ExceptionTester exceptionTester = null;
425       try
426       {
427          exceptionTester = exceptionTesterHome.create();
428
429          exceptionTester.remoteExceptionNewTx();
430
431          fail("Expected RemoteException to be thrown");
432
433       }
434       catch (RemoteException JavaDoc e)
435       {
436          // good this was expected
437
}
438       catch (Exception JavaDoc e)
439       {
440          fail("Expected RemoteException but got " + e);
441       }
442       finally
443       {
444          if (exceptionTester != null)
445          {
446             exceptionTester.remove();
447          }
448       }
449    }
450
451    public void testApplicationExceptionNoTx_remote() throws Exception JavaDoc
452    {
453       ExceptionTester exceptionTester = null;
454       try
455       {
456          exceptionTester = exceptionTesterHome.create();
457
458          exceptionTester.applicationExceptionNoTx();
459
460          fail("Expected application exception to be thrown");
461
462       }
463       catch (ApplicationException e)
464       {
465          // good this was expected
466
}
467       catch (Exception JavaDoc e)
468       {
469          fail("Expected ApplicationException but got " + e);
470       }
471       finally
472       {
473          if (exceptionTester != null)
474          {
475             exceptionTester.remove();
476          }
477       }
478    }
479
480    public void testApplicationErrorNoTx_remote() throws Exception JavaDoc
481    {
482       ExceptionTester exceptionTester = null;
483       try
484       {
485          exceptionTester = exceptionTesterHome.create();
486
487          exceptionTester.applicationErrorNoTx();
488
489          fail("Expected RemoteException to be thrown");
490
491       }
492       catch (RemoteException JavaDoc e)
493       {
494          // good this was expected
495
assertNotNull("RemoteException.detail should not be null",
496             e.detail);
497
498          assertEquals("RemoteException.detail should be a ApplicationError",
499             ApplicationError.class,
500             e.detail.getClass());
501       }
502       catch (Exception JavaDoc e)
503       {
504          fail("Expected RemoteException but got " + e);
505       }
506       finally
507       {
508          if (exceptionTester != null)
509          {
510             exceptionTester.remove();
511          }
512       }
513    }
514
515    public void testEJBExceptionNoTx_remote() throws Exception JavaDoc
516    {
517       ExceptionTester exceptionTester = null;
518       try
519       {
520          exceptionTester = exceptionTesterHome.create();
521
522          exceptionTester.ejbExceptionNoTx();
523
524          fail("Expected RemoteException to be thrown");
525
526       }
527       catch (RemoteException JavaDoc e)
528       {
529          // good this was expected
530
assertNotNull("RemoteException.detail should not be null",
531             e.detail);
532
533          assertEquals("RemoteException.detail should be a EJBException",
534             EJBException JavaDoc.class,
535             e.detail.getClass());
536       }
537       catch (Exception JavaDoc e)
538       {
539          fail("Expected RemoteException but got " + e);
540       }
541       finally
542       {
543          if (exceptionTester != null)
544          {
545             exceptionTester.remove();
546          }
547       }
548    }
549
550
551    public void testRuntimeExceptionNoTx_remote() throws Exception JavaDoc
552    {
553       ExceptionTester exceptionTester = null;
554       try
555       {
556          exceptionTester = exceptionTesterHome.create();
557
558          exceptionTester.runtimeExceptionNoTx();
559
560          fail("Expected RemoteException to be thrown");
561
562       }
563       catch (RemoteException JavaDoc e)
564       {
565          // good this was expected
566
assertNotNull("RemoteException.detail should not be null",
567             e.detail);
568
569          assertEquals("RemoteException.detail should be a RuntimeException",
570             RuntimeException JavaDoc.class,
571             e.detail.getClass());
572
573       }
574       catch (Exception JavaDoc e)
575       {
576          fail("Expected RemoteException but got " + e);
577       }
578       finally
579       {
580          if (exceptionTester != null)
581          {
582             exceptionTester.remove();
583          }
584       }
585    }
586
587
588    public void testRemoteExceptionNoTx_remote() throws Exception JavaDoc
589    {
590       ExceptionTester exceptionTester = null;
591       try
592       {
593          exceptionTester = exceptionTesterHome.create();
594
595          exceptionTester.remoteExceptionNoTx();
596
597          fail("Expected RemoteException to be thrown");
598
599       }
600       catch (RemoteException JavaDoc e)
601       {
602          // good this was expected
603
}
604       catch (Exception JavaDoc e)
605       {
606          fail("Expected RemoteException but got " + e);
607       }
608       finally
609       {
610          if (exceptionTester != null)
611          {
612             exceptionTester.remove();
613          }
614       }
615    }
616
617    public void testSecurityException_remote() throws Exception JavaDoc
618    {
619       ExceptionTester exceptionTester = null;
620       try
621       {
622          InitialContext JavaDoc jndi = new InitialContext JavaDoc();
623          ExceptionTesterHome exTesterHome =
624             (ExceptionTesterHome) jndi.lookup("exception/SecuredExceptionTester");
625          exceptionTester = exTesterHome.create();
626          exceptionTester.securityExceptionNoTx();
627
628          fail("Expected AccessException to be thrown");
629
630       }
631       catch (AccessException JavaDoc e)
632       {
633          // good this was expected
634
}
635       catch (Exception JavaDoc e)
636       {
637          fail("Expected AccessException but got " + e);
638       }
639       finally
640       {
641          if (exceptionTester != null)
642          {
643             exceptionTester.remove();
644          }
645       }
646    }
647
648    public void testSecurityExceptionByAppNoTx_remote() throws Exception JavaDoc
649    {
650       ExceptionTester exceptionTester = null;
651       try
652       {
653          InitialContext JavaDoc jndi = new InitialContext JavaDoc();
654          ExceptionTesterHome exTesterHome =
655             (ExceptionTesterHome) jndi.lookup("exception/ExceptionTester");
656          exceptionTester = exTesterHome.create();
657          exceptionTester.securityExceptionByAppNoTx();
658
659          fail("Expected InvalidKeyException to be thrown");
660
661       }
662       catch (InvalidKeyException JavaDoc e)
663       {
664          // good this was expected
665
}
666       catch (Exception JavaDoc e)
667       {
668          fail("Expected InvalidKeyException but got " + e);
669       }
670       finally
671       {
672          if (exceptionTester != null)
673          {
674             exceptionTester.remove();
675          }
676       }
677    }
678
679    public void testApplicationExceptionInTx_local() throws Exception JavaDoc
680    {
681       ExceptionTesterLocal exceptionTester = null;
682       try
683       {
684          exceptionTester = exceptionTesterLocalHome.create();
685
686          exceptionTester.applicationExceptionInTx();
687
688          fail("Expected ApplicationException to be thrown");
689
690       }
691       catch (ApplicationException e)
692       {
693          // good this was expected
694
}
695       catch (Exception JavaDoc e)
696       {
697          fail("Expected ApplicationException but got " + e);
698       }
699       finally
700       {
701          if (exceptionTester != null)
702          {
703             exceptionTester.remove();
704          }
705       }
706    }
707
708    public void testApplicationErrorInTx_local() throws Exception JavaDoc
709    {
710       ExceptionTesterLocal exceptionTester = null;
711       try
712       {
713          exceptionTester = exceptionTesterLocalHome.create();
714
715          exceptionTester.applicationErrorInTx();
716
717          fail("Expected TransactionRolledbackLocalException to be thrown");
718
719       }
720       catch (TransactionRolledbackLocalException JavaDoc e)
721       {
722          // good this was expected
723
assertNotNull("TransactionRolledbackLocalException.getCausedByException() " +
724             "should not be null",
725             e.getCausedByException());
726
727          assertEquals("TransactionRolledbackLocalException.getCausedByExcption() " +
728             "should be an EJBException",
729             EJBException JavaDoc.class,
730             e.getCausedByException().getClass());
731       }
732       catch (Exception JavaDoc e)
733       {
734          fail("Expected TransactionRolledbackLocalException but got " + e);
735       }
736       finally
737       {
738          if (exceptionTester != null)
739          {
740             exceptionTester.remove();
741          }
742       }
743    }
744
745
746    public void testEJBExceptionInTx_local() throws Exception JavaDoc
747    {
748       ExceptionTesterLocal exceptionTester = null;
749       try
750       {
751          exceptionTester = exceptionTesterLocalHome.create();
752
753          exceptionTester.ejbExceptionInTx();
754
755          fail("Expected TransactionRolledbackLocalException to be thrown");
756
757       }
758       catch (TransactionRolledbackLocalException JavaDoc e)
759       {
760          // good this was expected
761
assertNotNull("TransactionRolledbackLocalException.getCausedByException() " +
762             "should not be null",
763             e.getCausedByException());
764
765          assertEquals("TransactionRolledbackLocalException.getCausedByException() " +
766             "should be an EJBException",
767             EJBException JavaDoc.class,
768             e.getCausedByException().getClass());
769
770       }
771       catch (Exception JavaDoc e)
772       {
773          fail("Expected TransactionRolledbackLocalException but got " + e);
774       }
775       finally
776       {
777          if (exceptionTester != null)
778          {
779             exceptionTester.remove();
780          }
781       }
782    }
783
784
785    public void testRuntimeExceptionInTx_local() throws Exception JavaDoc
786    {
787       ExceptionTesterLocal exceptionTester = null;
788       try
789       {
790          exceptionTester = exceptionTesterLocalHome.create();
791
792          exceptionTester.runtimeExceptionInTx();
793
794          fail("Expected TransactionRolledbackLocalException to be thrown");
795
796       }
797       catch (TransactionRolledbackLocalException JavaDoc e)
798       {
799          // good this was expected
800
assertNotNull("TransactionRolledbackLocalException.getCausedByException() " +
801             "should not be null",
802             e.getCausedByException());
803
804          assertEquals("TransactionRolledbackLocalException.getCausedByException() " +
805             "should be a RuntimeException",
806             RuntimeException JavaDoc.class,
807             e.getCausedByException().getClass());
808
809       }
810       catch (Exception JavaDoc e)
811       {
812          fail("Expected TransactionRolledbackLocalException but got " + e);
813       }
814       finally
815       {
816          if (exceptionTester != null)
817          {
818             exceptionTester.remove();
819          }
820       }
821    }
822
823    public void testApplicationExceptionNewTx_local() throws Exception JavaDoc
824    {
825       ExceptionTesterLocal exceptionTester = null;
826       try
827       {
828          exceptionTester = exceptionTesterLocalHome.create();
829
830          exceptionTester.applicationExceptionNewTx();
831
832          fail("Expected ApplicationException to be thrown");
833
834       }
835       catch (ApplicationException e)
836       {
837          // good this was expected
838
}
839       catch (Exception JavaDoc e)
840       {
841          fail("Expected ApplicationException but got " + e);
842       }
843       finally
844       {
845          if (exceptionTester != null)
846          {
847             exceptionTester.remove();
848          }
849       }
850    }
851
852    public void testApplicationErrorNewTx_local() throws Exception JavaDoc
853    {
854       ExceptionTesterLocal exceptionTester = null;
855       try
856       {
857          exceptionTester = exceptionTesterLocalHome.create();
858
859          exceptionTester.applicationErrorNewTx();
860
861          fail("Expected EJBException to be thrown");
862
863       }
864       catch (EJBException JavaDoc e)
865       {
866          // good this was expected
867
assertNull("EJBException.getCausedByException() should be null",
868             e.getCausedByException());
869       }
870       catch (Exception JavaDoc e)
871       {
872          fail("Expected EJBException but got " + e);
873       }
874       finally
875       {
876          if (exceptionTester != null)
877          {
878             exceptionTester.remove();
879          }
880       }
881    }
882
883    public void testEJBExceptionNewTx_local() throws Exception JavaDoc
884    {
885       ExceptionTesterLocal exceptionTester = null;
886       try
887       {
888          exceptionTester = exceptionTesterLocalHome.create();
889
890          exceptionTester.ejbExceptionNewTx();
891
892          fail("Expected EJBException to be thrown");
893
894       }
895       catch (EJBException JavaDoc e)
896       {
897          // good this was expected
898
assertNull("EJBException.getCausedByException() should be null",
899             e.getCausedByException());
900       }
901       catch (Exception JavaDoc e)
902       {
903          fail("Expected EJBException but got " + e);
904       }
905       finally
906       {
907          if (exceptionTester != null)
908          {
909             exceptionTester.remove();
910          }
911       }
912    }
913
914
915    public void testRuntimeExceptionNewTx_local() throws Exception JavaDoc
916    {
917       ExceptionTesterLocal exceptionTester = null;
918       try
919       {
920          exceptionTester = exceptionTesterLocalHome.create();
921
922          exceptionTester.runtimeExceptionNewTx();
923
924          fail("Expected EJBException to be thrown");
925
926       }
927       catch (EJBException JavaDoc e)
928       {
929          // good this was expected
930
assertNotNull("EJBException.getCausedByException() should not be null",
931             e.getCausedByException());
932
933          assertEquals("EJBException.getCausedByException() should be " +
934             "a RuntimeException",
935             RuntimeException JavaDoc.class,
936             e.getCausedByException().getClass());
937
938       }
939       catch (Exception JavaDoc e)
940       {
941          fail("Expected EJBException but got " + e);
942       }
943       finally
944       {
945          if (exceptionTester != null)
946          {
947             exceptionTester.remove();
948          }
949       }
950    }
951
952    public void testApplicationExceptionNoTx_local() throws Exception JavaDoc
953    {
954       ExceptionTesterLocal exceptionTester = null;
955       try
956       {
957          exceptionTester = exceptionTesterLocalHome.create();
958
959          exceptionTester.applicationExceptionNoTx();
960
961          fail("Expected application exception to be thrown");
962
963       }
964       catch (ApplicationException e)
965       {
966          // good this was expected
967
}
968       catch (Exception JavaDoc e)
969       {
970          fail("Expected ApplicationException but got " + e);
971       }
972       finally
973       {
974          if (exceptionTester != null)
975          {
976             exceptionTester.remove();
977          }
978       }
979    }
980
981    public void testApplicationErrorNoTx_local() throws Exception JavaDoc
982    {
983       ExceptionTesterLocal exceptionTester = null;
984       try
985       {
986          exceptionTester = exceptionTesterLocalHome.create();
987
988          exceptionTester.applicationErrorNoTx();
989
990          fail("Expected EJBException to be thrown");
991
992       }
993       catch (EJBException JavaDoc e)
994       {
995          // good this was expected
996
assertNull("EJBException.getCausedByException() should be null",
997             e.getCausedByException());
998       }
999       catch (Exception JavaDoc e)
1000      {
1001         fail("Expected EJBException but got " + e);
1002      }
1003      finally
1004      {
1005         if (exceptionTester != null)
1006         {
1007            exceptionTester.remove();
1008         }
1009      }
1010   }
1011
1012   public void testEJBExceptionNoTx_local() throws Exception JavaDoc
1013   {
1014      ExceptionTesterLocal exceptionTester = null;
1015      try
1016      {
1017         exceptionTester = exceptionTesterLocalHome.create();
1018
1019         exceptionTester.ejbExceptionNoTx();
1020
1021         fail("Expected EJBException to be thrown");
1022
1023      }
1024      catch (EJBException JavaDoc e)
1025      {
1026         // good this was expected
1027
assertNull("EJBException.getCausedByException() should be null",
1028            e.getCausedByException());
1029      }
1030      catch (Exception JavaDoc e)
1031      {
1032         fail("Expected EJBException but got " + e);
1033      }
1034      finally
1035      {
1036         if (exceptionTester != null)
1037         {
1038            exceptionTester.remove();
1039         }
1040      }
1041   }
1042
1043
1044   public void testRuntimeExceptionNoTx_local() throws Exception JavaDoc
1045   {
1046      ExceptionTesterLocal exceptionTester = null;
1047      try
1048      {
1049         exceptionTester = exceptionTesterLocalHome.create();
1050
1051         exceptionTester.runtimeExceptionNoTx();
1052
1053         fail("Expected EJBException to be thrown");
1054
1055      }
1056      catch (EJBException JavaDoc e)
1057      {
1058         // good this was expected
1059
assertNotNull("EJBException.getCausedByException() should not be null",
1060            e.getCausedByException());
1061
1062         assertEquals("EJBException.getCausedByException() should be " +
1063            "a RuntimeException",
1064            RuntimeException JavaDoc.class,
1065            e.getCausedByException().getClass());
1066
1067      }
1068      catch (Exception JavaDoc e)
1069      {
1070         fail("Expected EJBException but got " + e);
1071      }
1072      finally
1073      {
1074         if (exceptionTester != null)
1075         {
1076            exceptionTester.remove();
1077         }
1078      }
1079   }
1080
1081   public void testSecurityException_local() throws Exception JavaDoc
1082   {
1083      ExceptionTesterLocal exceptionTester = null;
1084      try
1085      {
1086         InitialContext JavaDoc jndi = new InitialContext JavaDoc();
1087         ExceptionTesterLocalHome exTesterLocalHome =
1088            (ExceptionTesterLocalHome) jndi.lookup("exception/SecuredExceptionTesterLocal");
1089         exceptionTester = exTesterLocalHome.create();
1090
1091         exceptionTester.securityExceptionNoTx();
1092
1093         fail("Expected AccessLocalException to be thrown");
1094
1095      }
1096      catch (AccessLocalException JavaDoc e)
1097      {
1098         // good this was expected
1099
assertNotNull("AccessLocalException.getCausedByException() should not be null",
1100            e.getCausedByException());
1101
1102         Exception JavaDoc ex = e.getCausedByException();
1103         boolean isSecurityException = ex instanceof SecurityException JavaDoc
1104            || ex instanceof GeneralSecurityException JavaDoc;
1105         assertTrue("AccessLocalException.getCausedByException() should be " +
1106            "a security exception", isSecurityException);
1107      }
1108      catch (Exception JavaDoc e)
1109      {
1110         fail("Expected EJBException but got " + e);
1111      }
1112      finally
1113      {
1114         if (exceptionTester != null)
1115         {
1116            exceptionTester.remove();
1117         }
1118      }
1119   }
1120
1121   public void testSecurityExceptionByAppNoTx_local() throws Exception JavaDoc
1122   {
1123      ExceptionTesterLocal exceptionTester = null;
1124      try
1125      {
1126         InitialContext JavaDoc jndi = new InitialContext JavaDoc();
1127         ExceptionTesterLocalHome exTesterLocalHome =
1128            (ExceptionTesterLocalHome) jndi.lookup("exception/ExceptionTesterLocal");
1129         exceptionTester = exTesterLocalHome.create();
1130
1131         exceptionTester.securityExceptionByAppNoTx();
1132
1133         fail("Expected InvalidKeyException to be thrown");
1134
1135      }
1136      catch (InvalidKeyException JavaDoc e)
1137      {
1138         // good this was expected
1139
}
1140      catch (Exception JavaDoc e)
1141      {
1142         fail("Expected InvalidKeyException but got " + e);
1143      }
1144      finally
1145      {
1146         if (exceptionTester != null)
1147         {
1148            exceptionTester.remove();
1149         }
1150      }
1151   }
1152}
1153
Popular Tags