KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > j2eeca > 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.2 2004/03/19 11:57:19 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.j2eeca;
27
28 import javax.naming.Context JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30 import javax.rmi.PortableRemoteObject JavaDoc;
31 import javax.transaction.UserTransaction JavaDoc;
32
33 import junit.framework.Test;
34 import junit.framework.TestSuite;
35
36 import org.objectweb.jonas.jtests.beans.j2eeca.runtimeCA;
37 import org.objectweb.jonas.jtests.beans.j2eeca.runtimeCAHome;
38 import org.objectweb.jonas.jtests.util.JTestCase;
39
40 /**
41  * Tests Jonas Connector Architecture Basic error logging and tracing and component-managed sign-on.
42  */

43
44 public class F_runtimeTest extends JTestCase {
45
46     private static UserTransaction JavaDoc utx = null;
47
48     static Context JavaDoc ctx = null;
49
50     // Lookup bean home
51

52     protected static String JavaDoc BEAN_HOME = "runtimeCAHome";
53     protected static runtimeCAHome home = null;
54     private static final String JavaDoc RAR_JNDI_NAME = "FictionalNolog";
55     static runtimeCA bean = null;
56     final private int CLOSE_HANDLE = 0;
57     final private int CLOSE_PHYSICAL = 1;
58     int CloseType = 0;
59
60     public F_runtimeTest(String JavaDoc name) {
61         super(name);
62     }
63
64     protected void setUp() {
65         super.setUp();
66
67     // Get InitialContext
68

69         try {
70
71     // get JNDI initial context
72

73         if (ctx == null) {
74         ctx = new InitialContext JavaDoc();
75         }
76
77     // We want to start transactions from client: get UserTransaction
78

79         if (utx == null) {
80             utx = (UserTransaction JavaDoc) ctx.lookup("javax.transaction.UserTransaction");
81         }
82
83         if (home == null) {
84             useBeans("j2eeca", false);
85         }
86
87     // Connecting to runtimeHome thru JNDI
88

89         if (home == null) {
90             home = (runtimeCAHome)PortableRemoteObject.narrow(
91                               ctx.lookup(BEAN_HOME),
92                               runtimeCAHome.class);
93             bean = home.create();
94         }
95
96         assertTrue (5 == 5);
97
98     } catch (Exception JavaDoc e) {
99         fail("Cannot lookup UserTransaction in setUp: " +e);
100         }
101     }
102
103     protected void tearDown() throws Exception JavaDoc {
104         bean.closeUp(CloseType);
105     }
106     protected void startUp(String JavaDoc testName) {
107         try {
108             bean.method1(RAR_JNDI_NAME, testName);
109         } catch (Exception JavaDoc ee) {
110             ee.printStackTrace();
111             System.exit(2);
112         }
113     }
114 // test list ****************************************************
115
/**
116     * Basic error logging and tracing negative test.
117     *
118     * An application server is required to use the following interfaces (supported
119     * by the resource adapter) to provide basic error logging and tracing for its
120     * configured set of resource adapters.
121     * <pre>
122     * • ManagedConnectionFactory.set/getLogWriter
123     * • ManagedConnection.set/getLogWriter
124     * </pre>
125     *
126     * This test
127     * includes in <code>jonas-ra.xml</code> file the log-enabled info as
128     * shown below. The Nolog.rar
129     * is used. This test looks up "FictionalNolog" in the JNDI name space. The F_runtimeTest is
130     * deployed with log-enabled set to false.
131     * <p><pre>
132     * &lt;log-enabled>false&lt;/log-enabled&gt;
133     * &lt;log-topic&gt;&lt;/log-topic&gt;
134     * </pre>
135     */

136     public void testPrintWriterNull() throws Exception JavaDoc {
137         CloseType=CLOSE_PHYSICAL;
138         int isNull = 0;
139         int isNotNull = 1;
140         int isError = 2;
141         startUp("testPrintWriterNull");
142         int x = bean.getMCF_Pwriter();
143         assertEquals(isNull, x);
144         x = bean.getMC_Pwriter();
145         assertEquals(isNull, x);
146     }
147
148     /**
149      * Component managed sign-on.
150      *
151      * The application server relies on the resource adapter to manage EIS
152      * sign-on. Username and password are passed during connection.
153      * When this class is deployed, the <code>runtime.xml</code> file contains:
154      * <p>
155      * <code>&lt;res-auth&gt;Application&lt;/res-auth&gt;</code>
156      */

157     public void testSecurityContextApplication() throws Exception JavaDoc {
158         CloseType=CLOSE_PHYSICAL;
159         bean.setResAuth("Application");
160         startUp("testSecurityContextApplication");
161         //bean.setMatchNull(true);
162
String JavaDoc pw = bean.getSecurityPassword();
163         String JavaDoc u = bean.getSecurityUserName();
164         String JavaDoc realResAuth = bean.getResAuth();
165         if (realResAuth.equals("Application")) {
166             assertEquals("__Jtest_Pass_word__", pw);
167             assertEquals("Fictional_User_Name", u);
168         } else {
169             assertFalse(pw.equals("__Jtest_Pass_word__"));
170         }
171     
172     }
173     public static Test suite() {
174         return new TestSuite(F_runtimeTest.class);
175     }
176
177     public static void main (String JavaDoc args[]) {
178
179         String JavaDoc testtorun = null;
180
181         // Get args
182

183         for (int argn = 0; argn < args.length; argn++) {
184
185             String JavaDoc s_arg = args[argn];
186             Integer JavaDoc i_arg;
187
188             if (s_arg.equals("-n")) {
189                 testtorun = args[++argn];
190             }
191         }
192
193         if (testtorun == null) {
194             junit.textui.TestRunner.run(suite());
195         } else {
196             junit.textui.TestRunner.run(new F_runtimeTest(testtorun));
197         }
198     }
199 }
200
Popular Tags