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_runtimeTest.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.RuntimeCA;
047: import org.objectweb.jonas.jtests.beans.jca15.RuntimeCAHome;
048: import org.objectweb.jonas.jtests.util.JTestCase;
049:
050: /**
051: * Tests Jonas Connector Architecture Basic error logging and tracing and component-managed sign-on.
052: */
053:
054: public class F_runtimeTest extends JTestCase {
055:
056: static Context ctx = null;
057:
058: // Lookup bean home
059:
060: protected static String BEAN_HOME = "RuntimeCAHome";
061: protected static RuntimeCAHome home = null;
062: private static final String RAR_JNDI_NAME = "eis/ErsatzNolog";
063: static RuntimeCA bean = null;
064: final private int CLOSE_HANDLE = 0;
065: final private int CLOSE_PHYSICAL = 1;
066: int CloseType = 0;
067:
068: public F_runtimeTest(String name) {
069: super (name);
070: }
071:
072: protected void setUp() {
073: super .setUp();
074:
075: // Get InitialContext
076:
077: try {
078:
079: // get JNDI initial context
080:
081: if (ctx == null) {
082: ctx = new InitialContext();
083: }
084:
085: if (home == null) {
086: useBeans("jca15", false); // does "jonas admin -j jca15.jar"
087: }
088:
089: // Connecting to runtimeHome thru JNDI
090:
091: if (home == null) {
092: home = (RuntimeCAHome) PortableRemoteObject.narrow(ctx
093: .lookup(BEAN_HOME), RuntimeCAHome.class);
094: bean = home.create();
095: }
096:
097: assertTrue(5 == 5);
098:
099: } catch (Exception e) {
100: fail("Cannot do setUp: " + e);
101: }
102: }
103:
104: protected void tearDown() throws Exception {
105: bean.closeUp(CloseType);
106: }
107:
108: protected void startUp(String testName) {
109: try {
110: bean.method1(RAR_JNDI_NAME, testName);
111: } catch (Exception ee) {
112: ee.printStackTrace();
113: System.exit(2);
114: }
115: }
116:
117: // test list ****************************************************
118: /**
119: * Basic error logging and tracing negative test.
120: *
121: * An application server is required to use the following interfaces (supported
122: * by the resource adapter) to provide basic error logging and tracing for its
123: * configured set of resource adapters.
124: * <pre>
125: * • ManagedConnectionFactory.set/getLogWriter
126: * • ManagedConnection.set/getLogWriter
127: * </pre>
128: *
129: * This test
130: * includes in <code>jonas-ra.xml</code> file the log-enabled info as
131: * shown below. The ErsatzNolog.rar
132: * is used. This test looks up "ErsatzNolog" in the JNDI name space. The F_runtimeTest is
133: * deployed with log-enabled set to false.
134: * <p><pre>
135: * <log-enabled>false</log-enabled>
136: * <log-topic></log-topic>
137: * </pre>
138: */
139: public void testPrintWriterNull() throws Exception {
140: CloseType = CLOSE_PHYSICAL;
141: int isNull = 0;
142: int isNotNull = 1;
143: int isError = 2;
144: startUp("testPrintWriterNull");
145: int x = bean.getMCF_Pwriter();
146: assertEquals(isNull, x);
147: x = bean.getMC_Pwriter();
148: assertEquals(isNull, x);
149: }
150:
151: /**
152: * Component managed sign-on.
153: *
154: * The application server relies on the resource adapter to manage EIS
155: * sign-on. Username and password are passed during connection.
156: *
157: * This test verifies the username and password were passed.
158: */
159: public void testSecurityContextApplication() throws Exception {
160: CloseType = CLOSE_PHYSICAL;
161: bean.setResAuth("Application");
162: startUp("testSecurityContextApplication");
163: //bean.setMatchNull(true);
164: String pw = bean.getSecurityPassword();
165: String u = bean.getSecurityUserName();
166: String realResAuth = bean.getResAuth();
167: if (realResAuth.equals("Application")) {
168: assertEquals("__Jtest_Pass_word__", pw);
169: assertEquals("Ersatz_User_Name", u);
170: } else {
171: assertFalse(pw.equals("__Jtest_Pass_word__"));
172: }
173:
174: }
175:
176: // end test list ****************************************************
177:
178: public static Test suite() {
179: return new TestSuite(F_runtimeTest.class);
180: }
181:
182: public static void main(String args[]) {
183:
184: String testtorun = null;
185:
186: // Get args
187:
188: for (int argn = 0; argn < args.length; argn++) {
189:
190: String s_arg = args[argn];
191: Integer i_arg;
192:
193: if (s_arg.equals("-n")) {
194: testtorun = args[++argn];
195: }
196: }
197:
198: if (testtorun == null) {
199: junit.textui.TestRunner.run(suite());
200: } else {
201: junit.textui.TestRunner.run(new F_runtimeTest(testtorun));
202: }
203: }
204: }
|