KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > exception > F_CatcherBMT


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: F_CatcherBMT.java,v 1.3 2003/01/20 14:04:48 coqp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.exception;
27
28 import java.rmi.RemoteException JavaDoc;
29 import javax.naming.NamingException JavaDoc;
30 import javax.rmi.PortableRemoteObject JavaDoc;
31 import junit.framework.Test;
32 import junit.framework.TestSuite;
33 import org.objectweb.jonas.jtests.beans.beanexc.AccountS;
34 import org.objectweb.jonas.jtests.beans.beanexc.AccountSHome;
35 import org.objectweb.jonas.jtests.beans.beanexc.AppException;
36 import org.objectweb.jonas.jtests.util.JTestCase;
37
38 /**
39  * Exception test cases specific for session with bean-managed transaction
40  * @see Spec 2.0 table 16 page377
41  *
42  * @author Ph.Coq
43  */

44 public class F_CatcherBMT extends JTestCase {
45
46     // Note: the <ejb-name> is taken as <jndi-name> when not present
47
// in jonas specific deployment descriptor
48
private static String JavaDoc BEAN_HOME = "BTAccountSLHome";
49     protected static AccountSHome home = null;
50
51     public F_CatcherBMT(String JavaDoc name) {
52     super(name);
53     }
54
55     protected void setUp() {
56     super.setUp();
57     useBeans("beanexc", true);
58     }
59
60     public AccountSHome getHome() {
61         if (home == null) {
62         try {
63         home = (AccountSHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME), AccountSHome.class);
64         } catch (NamingException JavaDoc e) {
65         fail("Cannot get bean home");
66         }
67     }
68     return home;
69     }
70
71     /**
72      * return an AccountS
73      */

74     public AccountS getAccountS(int i) {
75         AccountS acs = null;
76         try {
77             acs = getHome().create();
78         } catch (Exception JavaDoc e) {
79             // should never occurs if the test is well written
80
fail("Exception in getAccountS should never occur:"+e);
81         }
82         return acs;
83     }
84
85     /**
86      * Test business method throwing an Application exception.
87      * It must be caught by the client.
88      *
89      * Spec 2.0 page 377 (table16)
90      */

91     public void testApplicationBMT() throws Exception JavaDoc {
92     AccountS acs = getAccountS(83);
93     try {
94         acs.doAppException_3();
95         fail("No AppException");
96     } catch (AppException e) {
97     }
98     }
99
100     /**
101      * Test business method throwing an unchecked exception.
102      * The client must receive RemoteException
103      *
104      * See EJB2.0 specs page 377 (table 16)
105      */

106     public void testUncheckedBMT() throws Exception JavaDoc {
107     AccountS acs = getAccountS(84);
108     try {
109         acs.doUncheckedException_3();
110         fail("No RemoteException");
111     } catch (RemoteException JavaDoc e) {
112     }
113
114     }
115
116     public static Test suite() {
117     return new TestSuite(F_CatcherBMT.class);
118     }
119
120     public static void main (String JavaDoc args[]) {
121     String JavaDoc testtorun = null;
122     // Get args
123
for (int argn = 0; argn < args.length; argn++) {
124         String JavaDoc s_arg = args[argn];
125         Integer JavaDoc i_arg;
126         if (s_arg.equals("-n")) {
127         testtorun = args[++argn];
128         }
129     }
130     if (testtorun == null) {
131         junit.textui.TestRunner.run(suite());
132     } else {
133         junit.textui.TestRunner.run(new F_CatcherBMT(testtorun));
134     }
135     }
136
137 }
138
Popular Tags