KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > distribution > F_Jdbc


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_Jdbc.java,v 1.5 2004/09/14 15:49:40 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.distribution;
27
28 import javax.naming.NamingException JavaDoc;
29 import javax.rmi.PortableRemoteObject JavaDoc;
30
31 import junit.framework.Test;
32 import junit.framework.TestSuite;
33
34 import org.objectweb.jonas.jtests.beans.jdbc.Manager;
35 import org.objectweb.jonas.jtests.beans.jdbc.ManagerHome;
36 import org.objectweb.jonas.jtests.util.JTestCase;
37
38 /**
39  * Test Jdbc accesses from a session bean
40  * Beans used: jdbc
41  * @author Philippe Durieux
42  */

43 public class F_Jdbc extends JTestCase {
44
45     protected static ManagerHome mhome = null;
46     protected Manager manager = null;
47
48     public F_Jdbc(String JavaDoc name) {
49         super(name);
50     }
51
52     protected void tearDown() throws Exception JavaDoc {
53         if (manager != null) {
54             manager.remove();
55         }
56     }
57
58     protected void setUp() {
59         super.setUp();
60         if (mhome == null) {
61             useBeans("jdbc", false);
62             try {
63                 mhome = (ManagerHome) PortableRemoteObject.narrow(ictx.lookup("jdbcManagerSYHome"), ManagerHome.class);
64                 assertNotNull(mhome);
65             } catch (NamingException JavaDoc e) {
66                 fail("Cannot get bean home");
67             }
68         }
69         if (manager == null) {
70             try {
71                 manager = mhome.create();
72                 assertNotNull(manager);
73             } catch (Exception JavaDoc e) {
74                 fail("Cannot create manager session");
75             }
76         }
77     }
78
79     /**
80      * Test we can open a Connection
81      */

82     public void testOpenConnection() throws Exception JavaDoc {
83         int cnb = manager.openConnection();
84         assertTrue(cnb > 0);
85     }
86
87     /**
88      * Test we can close a Connection previously opened
89      */

90     public void testCloseConnection() throws Exception JavaDoc {
91         int cnb = manager.openConnection();
92         assertTrue("open connection failed", cnb > 0);
93         assertTrue("isClosed() should return true after close()", manager.closeConnection(cnb));
94     }
95
96     /**
97      * test we can create and close a Connection in the same method.
98      */

99     public void testOpenCloseConnection() throws Exception JavaDoc {
100         assertTrue(manager.openCloseConnection());
101     }
102
103     public static Test suite() {
104         return new TestSuite(F_Jdbc.class);
105     }
106
107     public static void main (String JavaDoc args[]) {
108         String JavaDoc testtorun = null;
109         // Get args
110
for (int argn = 0; argn < args.length; argn++) {
111             String JavaDoc s_arg = args[argn];
112             Integer JavaDoc i_arg;
113             if (s_arg.equals("-n")) {
114                 testtorun = args[++argn];
115             }
116         }
117         if (testtorun == null) {
118             junit.textui.TestRunner.run(suite());
119         } else {
120             junit.textui.TestRunner.run(new F_Jdbc(testtorun));
121         }
122     }
123 }
124
Popular Tags