KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > jca15 > F_runtimeTest


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: F_runtimeTest.java,v 1.1 2004/04/15 17:09:34 bobkruse Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.jca15;
27
28 import junit.framework.*;
29 import java.io.BufferedReader JavaDoc;
30 import java.io.FileInputStream JavaDoc;
31 import java.io.InputStreamReader JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.lang.String JavaDoc;
34 import java.rmi.RemoteException JavaDoc;
35 import javax.rmi.PortableRemoteObject JavaDoc;
36 import java.util.Collection JavaDoc;
37 import java.util.Enumeration JavaDoc;
38 import java.util.Hashtable JavaDoc;
39 import java.util.Properties JavaDoc;
40 import javax.ejb.FinderException JavaDoc;
41 import javax.ejb.RemoveException JavaDoc;
42 import javax.naming.Context JavaDoc;
43 import javax.naming.InitialContext JavaDoc;
44 import javax.naming.NamingException JavaDoc;
45
46 import org.objectweb.jonas.jtests.beans.jca15.RuntimeCA;
47 import org.objectweb.jonas.jtests.beans.jca15.RuntimeCAHome;
48 import org.objectweb.jonas.jtests.util.JTestCase;
49
50 /**
51  * Tests Jonas Connector Architecture Basic error logging and tracing and component-managed sign-on.
52  */

53
54 public class F_runtimeTest extends JTestCase {
55
56     static Context JavaDoc ctx = null;
57
58     // Lookup bean home
59

60     protected static String JavaDoc BEAN_HOME = "RuntimeCAHome";
61     protected static RuntimeCAHome home = null;
62     private static final String JavaDoc RAR_JNDI_NAME = "eis/ErsatzNolog";
63     static RuntimeCA bean = null;
64     final private int CLOSE_HANDLE = 0;
65     final private int CLOSE_PHYSICAL = 1;
66     int CloseType = 0;
67
68     public F_runtimeTest(String JavaDoc name) {
69         super(name);
70     }
71
72     protected void setUp() {
73         super.setUp();
74
75     // Get InitialContext
76

77         try {
78
79         // get JNDI initial context
80

81             if (ctx == null) {
82             ctx = new InitialContext JavaDoc();
83             }
84
85             if (home == null) {
86                 useBeans("jca15", false); // does "jonas admin -j jca15.jar"
87
}
88
89         // Connecting to runtimeHome thru JNDI
90

91             if (home == null) {
92                 home = (RuntimeCAHome)PortableRemoteObject.narrow(
93                                  ctx.lookup(BEAN_HOME),
94                                  RuntimeCAHome.class);
95                 bean = home.create();
96             }
97
98             assertTrue (5 == 5);
99
100         } catch (Exception JavaDoc e) {
101             fail("Cannot do setUp: " +e);
102         }
103     }
104
105     protected void tearDown() throws Exception JavaDoc {
106         bean.closeUp(CloseType);
107     }
108     protected void startUp(String JavaDoc testName) {
109         try {
110             bean.method1(RAR_JNDI_NAME, testName);
111         } catch (Exception JavaDoc ee) {
112             ee.printStackTrace();
113             System.exit(2);
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 ErsatzNolog.rar
131     * is used. This test looks up "ErsatzNolog" in the JNDI name space. The F_runtimeTest is
132     * deployed with log-enabled set to false.
133     * <p><pre>
134     * &lt;log-enabled>false&lt;/log-enabled&gt;
135     * &lt;log-topic&gt;&lt;/log-topic&gt;
136     * </pre>
137     */

138     public void testPrintWriterNull() throws Exception JavaDoc {
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      *
156      * This test verifies the username and password were passed.
157      */

158     public void testSecurityContextApplication() throws Exception JavaDoc {
159         CloseType=CLOSE_PHYSICAL;
160         bean.setResAuth("Application");
161         startUp("testSecurityContextApplication");
162         //bean.setMatchNull(true);
163
String JavaDoc pw = bean.getSecurityPassword();
164         String JavaDoc u = bean.getSecurityUserName();
165         String JavaDoc realResAuth = bean.getResAuth();
166         if (realResAuth.equals("Application")) {
167             assertEquals("__Jtest_Pass_word__", pw);
168             assertEquals("Ersatz_User_Name", u);
169         } else {
170             assertFalse(pw.equals("__Jtest_Pass_word__"));
171         }
172     
173     }
174 // end test list ****************************************************
175

176     public static Test suite() {
177         return new TestSuite(F_runtimeTest.class);
178     }
179
180     public static void main (String JavaDoc args[]) {
181
182         String JavaDoc testtorun = null;
183
184         // Get args
185

186         for (int argn = 0; argn < args.length; argn++) {
187
188             String JavaDoc s_arg = args[argn];
189             Integer JavaDoc 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 }
203
Popular Tags