| 1 17 18 package org.sape.carbon.services.sql.connection.test; 19 20 import java.sql.Connection ; 21 import java.sql.SQLException ; 22 23 import org.sape.carbon.core.component.Lookup; 24 import org.sape.carbon.services.sql.connection.ConnectionFactory; 25 26 import junit.extensions.ActiveTestSuite; 27 import junit.framework.Test; 28 import junit.framework.TestCase; 29 import junit.framework.TestSuite; 30 31 public class StandaloneConnectionFactoryTest extends TestCase { 32 public StandaloneConnectionFactoryTest(String name){ 33 super(name); 34 } 35 36 39 public void testObtainConnection() throws Exception { 40 Connection conn = null; 41 try { 42 ConnectionFactory connFac = 43 (ConnectionFactory) Lookup.getInstance().fetchComponent( 44 STANDALONE_CONNECTION_FACTORY); 45 conn = connFac.getConnection(); 46 super.assertNotNull("Null connection returned from config at: "+ 47 "["+STANDALONE_CONNECTION_FACTORY+"]", conn); 48 } 49 finally{ 50 if(null != conn){ 51 conn.close(); 52 } 53 } 54 } 55 56 62 public void testObtainConnectionWithAdditionalProperties() throws Exception { 63 Connection conn = null; 64 try { 65 ConnectionFactory factory = 66 (ConnectionFactory)Lookup.getInstance().fetchComponent(STANDALONE_CONNECTION_FACTORY_WITH_PROPERTIES); 67 factory.getConnection(); 68 fail("Retrieve connection should have failed, as the connection factory has been "+ 69 " configured with invalid additional properties "); 70 } catch(SQLException se) { 71 } finally { 73 if ( conn != null ) { 74 conn.close(); 75 } 76 } 77 } 78 79 80 public static final String STANDALONE_CONNECTION_FACTORY = 81 "/sql/connection/test/StandaloneConnectionFactory"; 82 83 public static final String STANDALONE_CONNECTION_FACTORY_WITH_PROPERTIES = 84 "/sql/connection/test/StandaloneConnectionFactoryWithProperties"; 85 86 90 public static Test suite() { 91 TestSuite masterSuite = new TestSuite(); 92 Test singleThreadedTests = getSingleThreadedTests(); 94 if (singleThreadedTests != null) { 95 masterSuite.addTest(singleThreadedTests); 96 } 97 Test multiThreadedTests = getMultiThreadedTests(); 99 if (multiThreadedTests != null) { 100 masterSuite.addTest(multiThreadedTests); 101 } 102 return masterSuite; 103 } 104 105 111 private static Test getSingleThreadedTests() { 112 TestSuite suite = new TestSuite(); 113 114 suite.addTest(new StandaloneConnectionFactoryTest("testObtainConnection")); 115 suite.addTest(new StandaloneConnectionFactoryTest("testObtainConnectionWithAdditionalProperties")); 116 117 return suite; 118 } 119 120 125 private static Test getMultiThreadedTests() { 126 TestSuite suite = new ActiveTestSuite(); 127 128 134 135 return suite; 136 } 137 138 139 } 140 | Popular Tags |