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