001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: F_Jdbc.java 5427 2004-09-14 15:49:40Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.distribution;
027:
028: import javax.naming.NamingException;
029: import javax.rmi.PortableRemoteObject;
030:
031: import junit.framework.Test;
032: import junit.framework.TestSuite;
033:
034: import org.objectweb.jonas.jtests.beans.jdbc.Manager;
035: import org.objectweb.jonas.jtests.beans.jdbc.ManagerHome;
036: import org.objectweb.jonas.jtests.util.JTestCase;
037:
038: /**
039: * Test Jdbc accesses from a session bean
040: * Beans used: jdbc
041: * @author Philippe Durieux
042: */
043: public class F_Jdbc extends JTestCase {
044:
045: protected static ManagerHome mhome = null;
046: protected Manager manager = null;
047:
048: public F_Jdbc(String name) {
049: super (name);
050: }
051:
052: protected void tearDown() throws Exception {
053: if (manager != null) {
054: manager.remove();
055: }
056: }
057:
058: protected void setUp() {
059: super .setUp();
060: if (mhome == null) {
061: useBeans("jdbc", false);
062: try {
063: mhome = (ManagerHome) PortableRemoteObject
064: .narrow(ictx.lookup("jdbcManagerSYHome"),
065: ManagerHome.class);
066: assertNotNull(mhome);
067: } catch (NamingException e) {
068: fail("Cannot get bean home");
069: }
070: }
071: if (manager == null) {
072: try {
073: manager = mhome.create();
074: assertNotNull(manager);
075: } catch (Exception e) {
076: fail("Cannot create manager session");
077: }
078: }
079: }
080:
081: /**
082: * Test we can open a Connection
083: */
084: public void testOpenConnection() throws Exception {
085: int cnb = manager.openConnection();
086: assertTrue(cnb > 0);
087: }
088:
089: /**
090: * Test we can close a Connection previously opened
091: */
092: public void testCloseConnection() throws Exception {
093: int cnb = manager.openConnection();
094: assertTrue("open connection failed", cnb > 0);
095: assertTrue("isClosed() should return true after close()",
096: manager.closeConnection(cnb));
097: }
098:
099: /**
100: * test we can create and close a Connection in the same method.
101: */
102: public void testOpenCloseConnection() throws Exception {
103: assertTrue(manager.openCloseConnection());
104: }
105:
106: public static Test suite() {
107: return new TestSuite(F_Jdbc.class);
108: }
109:
110: public static void main(String args[]) {
111: String testtorun = null;
112: // Get args
113: for (int argn = 0; argn < args.length; argn++) {
114: String s_arg = args[argn];
115: Integer i_arg;
116: if (s_arg.equals("-n")) {
117: testtorun = args[++argn];
118: }
119: }
120: if (testtorun == null) {
121: junit.textui.TestRunner.run(suite());
122: } else {
123: junit.textui.TestRunner.run(new F_Jdbc(testtorun));
124: }
125: }
126: }
|