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_connectorTest.java 4406 2004-03-19 11:57:20Z benoitf $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.j2eeca;
027:
028: import javax.naming.Context;
029: import javax.naming.InitialContext;
030: import javax.rmi.PortableRemoteObject;
031: import javax.transaction.UserTransaction;
032:
033: import junit.framework.Test;
034: import junit.framework.TestSuite;
035:
036: import org.objectweb.jonas.jtests.beans.j2eeca.connectorCA;
037: import org.objectweb.jonas.jtests.beans.j2eeca.connectorCAHome;
038: import org.objectweb.jonas.jtests.util.JTestCase;
039:
040: /**
041: * Tests JOnAS Connector Architecture setter methods
042: */
043:
044: public class F_connectorTest extends JTestCase {
045:
046: private static UserTransaction utx = null;
047:
048: static Context ctx = null;
049:
050: // Lookup bean home
051:
052: protected static String BEAN_HOME = "connectorCAHome";
053: static connectorCAHome home = null;
054: static connectorCA bean = null;
055: static connectorCA bean2 = null;
056: private static final String RAR_JNDI_NAME = "FictionalEIS";
057: final private int CLOSE_HANDLE = 0;
058: final private int CLOSE_PHYSICAL = 1;
059: int CloseType = 0;
060:
061: public F_connectorTest(String name) {
062: super (name);
063: }
064:
065: protected void setUp() {
066: super .setUp();
067:
068: // Get InitialContext
069:
070: try {
071:
072: // get JNDI initial context
073:
074: if (ctx == null) {
075: ctx = new InitialContext();
076: }
077:
078: // We want to start transactions from client: get UserTransaction
079:
080: if (utx == null) {
081: utx = (UserTransaction) ctx
082: .lookup("javax.transaction.UserTransaction");
083: }
084:
085: if (home == null) {
086: useBeans("j2eeca", false); // does jonas admin -j connector.jar
087: }
088:
089: // Connecting to connectorCAHome thru JNDI
090:
091: if (home == null) {
092: home = (connectorCAHome) PortableRemoteObject.narrow(
093: ctx.lookup(BEAN_HOME), connectorCAHome.class);
094: bean = home.create();
095: }
096:
097: assertTrue(5 == 5);
098:
099: } catch (Exception e) {
100: fail("Cannot lookup UserTransaction in setUp: " + e);
101: }
102: }
103:
104: /**
105: *
106: * Common tearDown method, used for every test.
107: * Verify some Application Server tests by reviewing the log file.
108: *
109: * The application server also calls ManagedConnection.destroy when it
110: * receives a connection error event notification that signals a fatal error
111: * on the physical connection. When method closeUp(int x) is called by
112: * tearDown with x>0, a connection error event notification is sent to
113: * the application server. Look for <code>ManagedConnection.destroy</code> entry.
114: *
115: */
116: protected void tearDown() throws Exception {
117: bean.closeUp(CloseType);
118: }
119:
120: protected void startUp(String testName) {
121: try {
122: bean.method1(RAR_JNDI_NAME, testName);
123: } catch (Exception ee) {
124: ee.printStackTrace();
125: System.exit(2);
126: }
127: }
128:
129: // test list ****************************************************
130: /**
131: *
132: * The application server calls setter methods on the ManagedConnectionFactory
133: * instance to set various configuration properties on this instance.
134: *
135: */
136: public void testSetterMethods() throws Exception {
137: // the jonas-ra.xml file contains these properties. The Application Server
138: // calls setter methods on the ManagedConnectionFactory instance
139: // ServerName = 111.222.333.444 PortNumber= ak41
140: // protocol = LINE DUserName = defaultUserName
141: // DPassword = defaultPassword
142: CloseType = CLOSE_PHYSICAL;
143: startUp("testSetterMethods");
144: String cp = bean.getServerName();
145: assertEquals("111.222.333.444", cp);
146: cp = bean.getProtocolProperty();
147: assertEquals("LINE", cp);
148: }
149:
150: /**
151: * An application server is required to provide an implementation of the
152: * javax.resource.spi.ConnectionManager interface.
153: *
154: */
155: public void testCreatedCMInstance() throws Exception {
156: CloseType = CLOSE_PHYSICAL;
157: startUp("testCreatedCMInstance");
158: assertTrue(bean.getCMInstance());
159: }
160:
161: /**
162: * Verify connection is useful by accessing ManagedConnectionMetaData instance
163: */
164: public void testConnectionProduct() throws Exception {
165: CloseType = CLOSE_PHYSICAL;
166: startUp("testConnectionProduct");
167: String p = bean.getConnectionProduct();
168: assertEquals("Fictional EIS", p);
169: }
170:
171: /**
172: *
173: * An application server is required to implement the javax.resource.spi.-
174: * ConnectionEventListener interface and to register ConnectionEventListener
175: * with resource adapter to get connection-related event notifications.
176: *
177: * Count (at least) one listener
178: */
179: public void testRegisteredListener() throws Exception {
180: CloseType = CLOSE_PHYSICAL;
181: startUp("testRegisteredListener");
182: int b = bean.cntListeners();
183: assertTrue(b > 0);
184: }
185:
186: /**
187: * Verify connection was made
188: */
189: public void testConnectionBasics() throws Exception {
190: CloseType = CLOSE_PHYSICAL;
191: startUp("testConnectionBasics");
192: assertTrue(bean.isConnectionSpec());
193: assertTrue(bean.isConnection());
194: assertTrue(bean.isInteraction());
195: }
196:
197: /**
198: * Basic error logging and tracing.
199: *
200: * An application server is required to use the following interfaces (supported
201: * by the resource adapter) to provide basic error logging and tracing for its
202: * configured set of resource adapters.
203: * <pre>
204: * • ManagedConnectionFactory.set/getLogWriter
205: * • ManagedConnection.set/getLogWriter
206: * </pre>
207: *
208: * This test includes in <code>jonas-ra.xml</code> file the log-enabled
209: * info as shown below.
210: * The JtestResourceAdapter.rar
211: * is used. This test looks up "FictionalEIS" in the JNDI name space.
212: * The F_connectorTest is
213: * deployed with log-enabled set to true.
214: * <p>
215: * <pre>
216: * <log-enabled>true</log-enabled>
217: * <log-topic>org.objectweb.jtests.resourceAdapter</log-topic>
218: * </pre>
219: */
220: public void testPrintWriter() throws Exception {
221: CloseType = CLOSE_PHYSICAL;
222: int isNull = 0;
223: int isNotNull = 1;
224: int isError = 2;
225: startUp("testPrintWriter");
226: int x = bean.getMCF_Pwriter();
227: assertEquals(isNotNull, x);
228: x = bean.getMC_Pwriter();
229: assertEquals(isNotNull, x);
230: }
231:
232: // end test list ****************************************************
233:
234: public static Test suite() {
235: return new TestSuite(F_connectorTest.class);
236: }
237:
238: public static void main(String args[]) {
239:
240: String testtorun = null;
241:
242: // Get args
243:
244: for (int argn = 0; argn < args.length; argn++) {
245:
246: String s_arg = args[argn];
247: Integer i_arg;
248:
249: if (s_arg.equals("-n")) {
250: testtorun = args[++argn];
251: }
252: }
253:
254: if (testtorun == null) {
255: junit.textui.TestRunner.run(suite());
256: } else {
257: junit.textui.TestRunner.run(new F_connectorTest(testtorun));
258: }
259: }
260: }
|