KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > jca15 > 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/12/17 11:05:11 camillej 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.ConnectorCAHome;
47 import org.objectweb.jonas.jtests.beans.jca15.ConnectorCA;
48 import org.objectweb.jonas.jtests.util.JTestCase;
49
50 /**
51  * Tests JOnAS Connector Architecture setter methods
52  */

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

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

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

82             if (ctx == null) {
83                 ctx = new InitialContext JavaDoc();
84             }
85
86         } catch (Exception JavaDoc e) {
87             fail("Cannot do InitialContext(): " +e);
88         }
89
90         try {
91             if (home == null) {
92                 useBeans("jca15", false); // does "jonas admin -j jca15.jar"
93
}
94         } catch (Exception JavaDoc e) {
95             fail("Cannot do useBeans(jca15, false): " +e);
96         }
97
98             // Connecting to ConnectorCAHome thru JNDI
99

100         try {
101             if (home == null) {
102                 home = (ConnectorCAHome)PortableRemoteObject.narrow(
103                                  ctx.lookup(BEAN_HOME),
104                                  ConnectorCAHome.class);
105             }
106         
107             assertTrue (5 == 5);
108
109         } catch (Exception JavaDoc e) {
110             fail("Cannot do ctx.lookup(BEAN_HOME): " +e);
111         }
112         try {
113                 bean = home.create();
114                 assertTrue (5 == 5);
115
116         } catch (Exception JavaDoc e) {
117             fail("Cannot do home.create(): " +e);
118         }
119     }
120     /**
121      *
122      * Common tearDown method, used for every test.
123      * Verify some Application Server tests by reviewing the log file.
124      *
125      * The application server also calls ManagedConnection.destroy when it
126      * receives a connection error event notification that signals a fatal error
127      * on the physical connection. When method closeUp(int x) is called by
128      * tearDown with x>0, a connection error event notification is sent to
129      * the application server. Look for <code>ManagedConnection.destroy</code> entry.
130      *
131      */

132     protected void tearDown() throws Exception JavaDoc {
133         bean.closeUp(CloseType);
134     }
135     protected void startUp(String JavaDoc testName) {
136         try {
137             bean.method1(RAR_JNDI_NAME, testName);
138         } catch (Exception JavaDoc ee) {
139             ee.printStackTrace();
140             System.exit(2);
141         }
142     }
143 // test list ****************************************************
144
/**
145      *
146      * The application server calls setter methods on the ManagedConnectionFactory
147      * instance to set various configuration properties on this instance.
148      *
149      */

150     public void testSetterMethods() throws Exception JavaDoc {
151         // the jonas-ra.xml file contains these properties. The Application Server
152
// calls setter methods on the ManagedConnectionFactory instance
153
// ServerName = 111.222.333.444 PortNumber= ak41
154
// protocol = LINE DUserName = defaultUserName
155
// DPassword = defaultPassword
156
CloseType=CLOSE_PHYSICAL;
157         startUp("testSetterMethods");
158         String JavaDoc cp = bean.getServerName();
159         assertEquals("111.111.111.111", cp);
160         cp = bean.getProtocolProperty();
161         assertEquals("LINE", cp);
162     }
163     /**
164      * An application server is required to provide an implementation of the
165      * javax.resource.spi.ConnectionManager interface.
166      *
167      */

168     public void testCreatedCMInstance() throws Exception JavaDoc {
169         CloseType=CLOSE_PHYSICAL;
170         startUp("testCreatedCMInstance");
171         assertTrue(bean.getCMInstance());
172     }
173     /**
174      * Verify connection is useful by accessing ManagedConnectionMetaData instance
175      */

176     public void testConnectionProduct() throws Exception JavaDoc {
177         CloseType=CLOSE_PHYSICAL;
178         startUp("testConnectionProduct");
179         String JavaDoc p = bean.getConnectionProduct();
180         assertEquals("Ersatz EIS", p);
181     }
182     /**
183      *
184      * An application server is required to implement the javax.resource.spi.-
185      * ConnectionEventListener interface and to register ConnectionEventListener
186      * with resource adapter to get connection-related event notifications.
187      *
188      * Count (at least) one listener
189      */

190     public void testRegisteredListener() throws Exception JavaDoc {
191         CloseType=CLOSE_PHYSICAL;
192         startUp("testRegisteredListener");
193         int b = bean.cntListeners();
194         assertTrue(b>0);
195     }
196     /**
197      * Verify connection was made
198      */

199     public void testConnectionBasics() throws Exception JavaDoc {
200         CloseType=CLOSE_PHYSICAL;
201         startUp("testConnectionBasics");
202         assertTrue(bean.isConnectionSpec());
203         assertTrue(bean.isConnection());
204         assertTrue(bean.isInteraction());
205     }
206    /**
207     * Basic error logging and tracing.
208     *
209     * An application server is required to use the following interfaces (supported
210     * by the resource adapter) to provide basic error logging and tracing for its
211     * configured set of resource adapters.
212     * <pre>
213     * ? ManagedConnectionFactory.set/getLogWriter
214     * ? ManagedConnection.set/getLogWriter
215     * </pre>
216     *
217     * This test includes in <code>jonas-ra.xml</code> file the log-enabled
218     * info as shown below.
219     * The JSR112ResourceAdapter.rar
220     * is used. This test looks up "ErsatzEIS" in the JNDI name space.
221     * The F_connectorTest is
222     * deployed with log-enabled set to true.
223     * <p>
224     * <pre>
225     * &lt;log-enabled&gt;true&lt;/log-enabled&gt;
226     * &lt;log-topic&gt;org.objectweb.jtests.resourceAdapter&lt;/log-topic&gt;
227     * </pre>
228     */

229     public void testPrintWriter() throws Exception JavaDoc {
230         CloseType=CLOSE_PHYSICAL;
231         int isNull = 0;
232         int isNotNull = 1;
233         int isError = 2;
234         startUp("testPrintWriter");
235         int x = bean.getMCF_Pwriter();
236         assertEquals(isNotNull, x);
237         x = bean.getMC_Pwriter();
238         assertEquals(isNotNull, x);
239     }
240 // end test list ****************************************************
241

242     public static Test suite() {
243         return new TestSuite(F_connectorTest.class);
244     }
245
246     public static void main (String JavaDoc args[]) {
247
248         String JavaDoc testtorun = null;
249
250         // Get args
251

252         for (int argn = 0; argn < args.length; argn++) {
253
254             String JavaDoc s_arg = args[argn];
255             Integer JavaDoc i_arg;
256
257             if (s_arg.equals("-n")) {
258                 testtorun = args[++argn];
259             }
260         }
261
262         if (testtorun == null) {
263             junit.textui.TestRunner.run(suite());
264         } else {
265             junit.textui.TestRunner.run(new F_connectorTest(testtorun));
266         }
267     }
268 }
269
Popular Tags