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_transactionTest.java 4604 2004-04-15 17:15:45Z bobkruse $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.jca15;
027:
028: import junit.framework.*;
029: import java.io.BufferedReader;
030: import java.io.FileInputStream;
031: import java.io.InputStreamReader;
032: import java.io.IOException;
033: import java.lang.String;
034: import java.rmi.RemoteException;
035: import javax.rmi.PortableRemoteObject;
036: import java.util.Collection;
037: import java.util.Enumeration;
038: import java.util.Hashtable;
039: import java.util.Properties;
040: import javax.ejb.FinderException;
041: import javax.ejb.RemoveException;
042: import javax.naming.Context;
043: import javax.naming.InitialContext;
044: import javax.naming.NamingException;
045:
046: import org.objectweb.jonas.jtests.beans.jca15.TransactedCA;
047: import org.objectweb.jonas.jtests.beans.jca15.TransactedCAHome;
048: import org.objectweb.jonas.jtests.util.JTestCase;
049: import org.objectweb.jonas.jtests.clients.jca15.F_securityTest;
050:
051: /**
052: * Tests Jonas Connector Architecture Local Transaction.
053: * F_transactionTests tests Jonas CA Local Transaction
054: */
055:
056: public class F_transactionTest extends JTestCase {
057:
058: static Context ctx = null;
059:
060: // Lookup bean home
061:
062: protected static String BEAN_HOME = "TransactedCAHome";
063: protected static TransactedCAHome home = null;
064: private static final String RAR_JNDI_NAME = "eis/ErsatzLoTransaction";
065: final public int CLOSE_HANDLE = 0;
066: final public int CLOSE_PHYSICAL = 1;
067: public int CloseType = 0;
068: static TransactedCA bean = null;
069: public String UseBeans = "jca15";
070:
071: public F_transactionTest(String name) {
072: super (name);
073: }
074:
075: protected void setUp() {
076: super .setUp();
077: try {
078: // get JNDI initial context
079:
080: if (ctx == null) {
081: ctx = new InitialContext();
082: }
083:
084: if (home == null) {
085: useBeans(UseBeans, false);
086: }
087: getBean();
088: assertTrue(6 == 6);
089:
090: } catch (Exception e) {
091: fail("Cannot do setUp: " + e);
092: }
093: }
094:
095: private void getBean() throws Exception {
096: // Connecting to TransactedCAHome thru JNDI
097:
098: if (home == null) {
099: home = (TransactedCAHome) PortableRemoteObject.narrow(ctx
100: .lookup(BEAN_HOME), TransactedCAHome.class);
101: bean = home.create();
102: }
103: }
104:
105: protected void tearDown() throws Exception {
106: //bean.closeUp(CloseType);
107: }
108:
109: protected void startUp(String testName) {
110: try {
111: bean.method1(RAR_JNDI_NAME, testName);
112: } catch (Exception ee) {
113: ee.printStackTrace();
114: System.exit(2);
115: }
116: }
117:
118: // test list ****************************************************
119:
120: /**
121: Test Local Transaction with component-managed demarcation.
122:
123: The application component uses a transaction demarcation API specific
124: to an EIS. The resource adapter needs to notify the application server of
125: the events (transaction begin, commit, and rollback) related to the local
126: transaction. An application server uses this part of the contract.
127:
128: */
129: public void testTransaction1() {
130: CloseType = CLOSE_PHYSICAL;
131: startUp("testTransaction1");
132: try {
133: bean.beginLoTransaction();
134: assertTrue(6 == 6);
135: bean.closeUp(CloseType);
136: bean.commitLoTransaction();
137: assertTrue(6 == 6);
138: } catch (Exception e) {
139: assertTrue(6 == 7);
140: }
141: }
142:
143: public void testTransaction2() {
144: CloseType = CLOSE_PHYSICAL;
145: startUp("testTransaction2");
146: try {
147: bean.closeUp(CloseType);
148: bean.commitLoTransaction();
149: assertTrue(6 == 7);
150: } catch (Exception e) {
151: assertTrue(6 == 6); // should get here
152: }
153: }
154:
155: public static Test suite() {
156: return new TestSuite(F_transactionTest.class);
157: }
158:
159: public static void main(String args[]) {
160:
161: String testtorun = null;
162:
163: // Get args
164:
165: for (int argn = 0; argn < args.length; argn++) {
166:
167: String s_arg = args[argn];
168: Integer i_arg;
169:
170: if (s_arg.equals("-n")) {
171: testtorun = args[++argn];
172: }
173: }
174:
175: if (testtorun == null) {
176: junit.textui.TestRunner.run(suite());
177: } else {
178: junit.textui.TestRunner
179: .run(new F_transactionTest(testtorun));
180: }
181: }
182: }
|