001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: F_CatcherBMT.java 1247 2003-01-20 14:04:48Z coqp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.exception;
027:
028: import java.rmi.RemoteException;
029: import javax.naming.NamingException;
030: import javax.rmi.PortableRemoteObject;
031: import junit.framework.Test;
032: import junit.framework.TestSuite;
033: import org.objectweb.jonas.jtests.beans.beanexc.AccountS;
034: import org.objectweb.jonas.jtests.beans.beanexc.AccountSHome;
035: import org.objectweb.jonas.jtests.beans.beanexc.AppException;
036: import org.objectweb.jonas.jtests.util.JTestCase;
037:
038: /**
039: * Exception test cases specific for session with bean-managed transaction
040: * @see Spec 2.0 table 16 page377
041: *
042: * @author Ph.Coq
043: */
044: public class F_CatcherBMT extends JTestCase {
045:
046: // Note: the <ejb-name> is taken as <jndi-name> when not present
047: // in jonas specific deployment descriptor
048: private static String BEAN_HOME = "BTAccountSLHome";
049: protected static AccountSHome home = null;
050:
051: public F_CatcherBMT(String name) {
052: super (name);
053: }
054:
055: protected void setUp() {
056: super .setUp();
057: useBeans("beanexc", true);
058: }
059:
060: public AccountSHome getHome() {
061: if (home == null) {
062: try {
063: home = (AccountSHome) PortableRemoteObject.narrow(ictx
064: .lookup(BEAN_HOME), AccountSHome.class);
065: } catch (NamingException e) {
066: fail("Cannot get bean home");
067: }
068: }
069: return home;
070: }
071:
072: /**
073: * return an AccountS
074: */
075: public AccountS getAccountS(int i) {
076: AccountS acs = null;
077: try {
078: acs = getHome().create();
079: } catch (Exception e) {
080: // should never occurs if the test is well written
081: fail("Exception in getAccountS should never occur:" + e);
082: }
083: return acs;
084: }
085:
086: /**
087: * Test business method throwing an Application exception.
088: * It must be caught by the client.
089: *
090: * Spec 2.0 page 377 (table16)
091: */
092: public void testApplicationBMT() throws Exception {
093: AccountS acs = getAccountS(83);
094: try {
095: acs.doAppException_3();
096: fail("No AppException");
097: } catch (AppException e) {
098: }
099: }
100:
101: /**
102: * Test business method throwing an unchecked exception.
103: * The client must receive RemoteException
104: *
105: * See EJB2.0 specs page 377 (table 16)
106: */
107: public void testUncheckedBMT() throws Exception {
108: AccountS acs = getAccountS(84);
109: try {
110: acs.doUncheckedException_3();
111: fail("No RemoteException");
112: } catch (RemoteException e) {
113: }
114:
115: }
116:
117: public static Test suite() {
118: return new TestSuite(F_CatcherBMT.class);
119: }
120:
121: public static void main(String args[]) {
122: String testtorun = null;
123: // Get args
124: for (int argn = 0; argn < args.length; argn++) {
125: String s_arg = args[argn];
126: Integer i_arg;
127: if (s_arg.equals("-n")) {
128: testtorun = args[++argn];
129: }
130: }
131: if (testtorun == null) {
132: junit.textui.TestRunner.run(suite());
133: } else {
134: junit.textui.TestRunner.run(new F_CatcherBMT(testtorun));
135: }
136: }
137:
138: }
|