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