KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > j2eeca > F_connectorTest


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_connectorTest.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.connectorCA;
37 import org.objectweb.jonas.jtests.beans.j2eeca.connectorCAHome;
38 import org.objectweb.jonas.jtests.util.JTestCase;
39
40 /**
41  * Tests JOnAS Connector Architecture setter methods
42  */

43
44 public class F_connectorTest 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 = "connectorCAHome";
53     static connectorCAHome home = null;
54     static connectorCA bean = null;
55     static connectorCA bean2 = null;
56     private static final String JavaDoc RAR_JNDI_NAME = "FictionalEIS";
57     final private int CLOSE_HANDLE = 0;
58     final private int CLOSE_PHYSICAL = 1;
59     int CloseType = 0;
60     
61     public F_connectorTest(String JavaDoc name) {
62         super(name);
63     }
64
65     protected void setUp() {
66         super.setUp();
67
68     // Get InitialContext
69

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

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

80             if (utx == null) {
81                 utx = (UserTransaction JavaDoc) ctx.lookup("javax.transaction.UserTransaction");
82             }
83
84             if (home == null) {
85                 useBeans("j2eeca", false); // does jonas admin -j connector.jar
86
}
87
88             // Connecting to connectorCAHome thru JNDI
89

90             if (home == null) {
91                 home = (connectorCAHome)PortableRemoteObject.narrow(
92                                  ctx.lookup(BEAN_HOME),
93                                  connectorCAHome.class);
94                 bean = home.create();
95             }
96         
97             assertTrue (5 == 5);
98
99         } catch (Exception JavaDoc e) {
100             fail("Cannot lookup UserTransaction in setUp: " +e);
101         }
102     }
103     /**
104      *
105      * Common tearDown method, used for every test.
106      * Verify some Application Server tests by reviewing the log file.
107      *
108      * The application server also calls ManagedConnection.destroy when it
109      * receives a connection error event notification that signals a fatal error
110      * on the physical connection. When method closeUp(int x) is called by
111      * tearDown with x>0, a connection error event notification is sent to
112      * the application server. Look for <code>ManagedConnection.destroy</code> entry.
113      *
114      */

115     protected void tearDown() throws Exception JavaDoc {
116         bean.closeUp(CloseType);
117     }
118     protected void startUp(String JavaDoc testName) {
119         try {
120             bean.method1(RAR_JNDI_NAME, testName);
121         } catch (Exception JavaDoc ee) {
122             ee.printStackTrace();
123             System.exit(2);
124         }
125     }
126 // test list ****************************************************
127
/**
128      *
129      * The application server calls setter methods on the ManagedConnectionFactory
130      * instance to set various configuration properties on this instance.
131      *
132      */

133     public void testSetterMethods() throws Exception JavaDoc {
134         // the jonas-ra.xml file contains these properties. The Application Server
135
// calls setter methods on the ManagedConnectionFactory instance
136
// ServerName = 111.222.333.444 PortNumber= ak41
137
// protocol = LINE DUserName = defaultUserName
138
// DPassword = defaultPassword
139
CloseType=CLOSE_PHYSICAL;
140         startUp("testSetterMethods");
141         String JavaDoc cp = bean.getServerName();
142         assertEquals("111.222.333.444", cp);
143         cp = bean.getProtocolProperty();
144         assertEquals("LINE", cp);
145     }
146     /**
147      * An application server is required to provide an implementation of the
148      * javax.resource.spi.ConnectionManager interface.
149      *
150      */

151     public void testCreatedCMInstance() throws Exception JavaDoc {
152         CloseType=CLOSE_PHYSICAL;
153         startUp("testCreatedCMInstance");
154         assertTrue(bean.getCMInstance());
155     }
156     /**
157      * Verify connection is useful by accessing ManagedConnectionMetaData instance
158      */

159     public void testConnectionProduct() throws Exception JavaDoc {
160         CloseType=CLOSE_PHYSICAL;
161         startUp("testConnectionProduct");
162         String JavaDoc p = bean.getConnectionProduct();
163         assertEquals("Fictional EIS", p);
164     }
165     /**
166      *
167      * An application server is required to implement the javax.resource.spi.-
168      * ConnectionEventListener interface and to register ConnectionEventListener
169      * with resource adapter to get connection-related event notifications.
170      *
171      * Count (at least) one listener
172      */

173     public void testRegisteredListener() throws Exception JavaDoc {
174         CloseType=CLOSE_PHYSICAL;
175         startUp("testRegisteredListener");
176         int b = bean.cntListeners();
177         assertTrue(b>0);
178     }
179     /**
180      * Verify connection was made
181      */

182     public void testConnectionBasics() throws Exception JavaDoc {
183         CloseType=CLOSE_PHYSICAL;
184         startUp("testConnectionBasics");
185         assertTrue(bean.isConnectionSpec());
186         assertTrue(bean.isConnection());
187         assertTrue(bean.isInteraction());
188     }
189    /**
190     * Basic error logging and tracing.
191     *
192     * An application server is required to use the following interfaces (supported
193     * by the resource adapter) to provide basic error logging and tracing for its
194     * configured set of resource adapters.
195     * <pre>
196     * • ManagedConnectionFactory.set/getLogWriter
197     * • ManagedConnection.set/getLogWriter
198     * </pre>
199     *
200     * This test includes in <code>jonas-ra.xml</code> file the log-enabled
201     * info as shown below.
202     * The JtestResourceAdapter.rar
203     * is used. This test looks up "FictionalEIS" in the JNDI name space.
204     * The F_connectorTest is
205     * deployed with log-enabled set to true.
206     * <p>
207     * <pre>
208     * &lt;log-enabled&gt;true&lt;/log-enabled&gt;
209     * &lt;log-topic&gt;org.objectweb.jtests.resourceAdapter&lt;/log-topic&gt;
210     * </pre>
211     */

212     public void testPrintWriter() throws Exception JavaDoc {
213         CloseType=CLOSE_PHYSICAL;
214         int isNull = 0;
215         int isNotNull = 1;
216         int isError = 2;
217         startUp("testPrintWriter");
218         int x = bean.getMCF_Pwriter();
219         assertEquals(isNotNull, x);
220         x = bean.getMC_Pwriter();
221         assertEquals(isNotNull, x);
222     }
223 // end test list ****************************************************
224

225     public static Test suite() {
226         return new TestSuite(F_connectorTest.class);
227     }
228
229     public static void main (String JavaDoc args[]) {
230
231         String JavaDoc testtorun = null;
232
233         // Get args
234

235         for (int argn = 0; argn < args.length; argn++) {
236
237             String JavaDoc s_arg = args[argn];
238             Integer JavaDoc i_arg;
239
240             if (s_arg.equals("-n")) {
241                 testtorun = args[++argn];
242             }
243         }
244
245         if (testtorun == null) {
246             junit.textui.TestRunner.run(suite());
247         } else {
248             junit.textui.TestRunner.run(new F_connectorTest(testtorun));
249         }
250     }
251 }
252
Popular Tags