1 24 25 package org.objectweb.cjdbc.scenario.standalone.connection; 26 27 import java.sql.Connection ; 28 import java.sql.DriverManager ; 29 import java.sql.SQLException ; 30 31 import junit.framework.Test; 32 import junit.framework.TestSuite; 33 import junit.textui.TestRunner; 34 35 import org.objectweb.cjdbc.common.exceptions.UnreachableBackendException; 36 import org.objectweb.cjdbc.controller.connection.SimpleConnectionManager; 37 import org.objectweb.cjdbc.scenario.templates.NoTemplate; 38 import org.objectweb.cjdbc.scenario.tools.mock.MockDriver; 39 40 import com.mockobjects.sql.MockConnection2; 41 42 48 public class SimpleConnectionManagerTest extends NoTemplate 49 { 50 51 private MockDriver mockDriver; 52 53 54 private MockConnection2 mockConnection; 55 56 57 private SimpleConnectionManager manager; 58 59 64 public static Test suite() 65 { 66 return new TestSuite(SimpleConnectionManagerTest.class); 67 } 68 69 74 public static void main(String [] args) 75 { 76 TestRunner.run(suite()); 77 } 78 79 82 protected void setUp() 83 { 84 try 86 { 87 mockConnection = new MockConnection2(); 88 mockConnection.setExpectedCloseCalls(1); 89 mockConnection.setupIsClosed(true); 90 mockDriver = new MockDriver(); 91 mockDriver.setExpectedConnectCalls(1); 92 mockDriver.setupConnect(mockConnection); 93 94 DriverManager.registerDriver(mockDriver); 95 } 96 catch (SQLException e) 97 { 98 fail("Failed to register driver: " + e); 99 } 100 101 try 103 { 104 manager = new SimpleConnectionManager("", "", "", "", null, null); 105 } 106 catch (Exception e) 107 { 108 fail("Failed to create simple pool connection manager: " + e); 109 } 110 111 try 113 { 114 manager.initializeConnections(); 115 } 116 catch (SQLException e) 117 { 118 fail("Failed to initialize pool connection manager: " + e); 119 } 120 } 121 122 125 protected void tearDown() 126 { 127 try 129 { 130 DriverManager.deregisterDriver(mockDriver); 131 } 132 catch (SQLException e) 133 { 134 fail("Failed to deregister driver: " + e); 135 } 136 } 137 138 144 public void testSimpleConnectionManager() throws UnreachableBackendException 145 { 146 Connection c = manager.getConnection(); 148 if (c == null) 149 fail("Failed to get a connection from simple connection manager"); 150 151 manager.releaseConnection(c); 153 try 154 { 155 assertTrue(c.isClosed()); 156 } 157 catch (SQLException e) 158 { 159 fail("Exception thrown: " + e); 160 } 161 mockConnection.verify(); 162 mockDriver.verify(); 163 } 164 } | Popular Tags |