@@ -0,0 +1,2654 @@
+package org.flymine.sql;%0A%0Aimport junit.framework.*;%0Aimport java.sql.Connection;%0Aimport javax.sql.DataSource;%0Aimport java.io.IOException;%0Aimport java.util.Properties;%0Aimport org.flymine.sql.ConnectionFactory;%0A%0Apublic class ConnectionFactoryTest extends TestCase%0A%7B%0A    Properties props;%0A%0A    public ConnectionFactoryTest(String arg1) %7B%0A        super(arg1);%0A    %7D%0A%0A    public void testConfigureDataSource() throws Exception %7B%0A        props = new Properties();%0A        props.put(%22db.test.dataSource%22, %22org.postgresql.jdbc2.optional.PoolingDataSource%22);%0A        props.put(%22db.test.serverName%22, %22dbserver.mydomain.org%22);%0A        props.put(%22db.test.databaseName%22, %22test%22);%0A        props.put(%22db.test.maxConnections%22, %2210%22);%0A%0A        DataSource ds = ConnectionFactory.configureDataSource(%22db.test%22, props);%0A        assertTrue(ds instanceof org.postgresql.jdbc2.optional.PoolingDataSource);%0A        assertEquals(%22dbserver.mydomain.org%22, ((org.postgresql.jdbc2.optional.PoolingDataSource) ds).getServerName());%0A        assertEquals(%22test%22, ((org.postgresql.jdbc2.optional.PoolingDataSource) ds).getDatabaseName());%0A        assertEquals(10, ((org.postgresql.jdbc2.optional.PoolingDataSource) ds).getMaxConnections());%0A%0A    %7D%0A%0A    public void testInvalidDataSourceClass() throws Exception %7B%0A        Properties invalidProps = new Properties();%0A        invalidProps.put(%22db.test.dataSource%22, %22org.class.that.cannot.be.Found%22);%0A        try %7B%0A            DataSource ds = ConnectionFactory.configureDataSource(%22db.test%22, invalidProps);%0A            fail(%22Expected: ClassNotFoundException%22);%0A        %7D catch (ClassNotFoundException e) %7B%0A        %7D%0A    %7D%0A%0A    public void testInvalidMethod() throws Exception %7B%0A        Properties invalidProps = new Properties();%0A        invalidProps.put(%22db.test.dataSource%22, %22org.postgresql.jdbc3.Jdbc3PoolingDataSource%22);%0A        invalidProps.put(%22db.test.someRubbish%22, %22blahblahblah%22);%0A        try %7B%0A            DataSource ds = ConnectionFactory.configureDataSource(%22db.test%22, invalidProps);%0A        %7D catch (Exception e) %7B%0A            fail(%22Did not expect an exception to be thrown%22);%0A        %7D%0A    %7D%0A%0A    public void testNullProperties() throws Exception %7B%0A        try %7B%0A            DataSource ds = ConnectionFactory.configureDataSource(%22db.test%22, null);%0A            fail(%22Expected: NullPointerException%22);%0A        %7D catch (NullPointerException e) %7B%0A        %7D%0A    %7D%0A%0A    public void testNullName() throws Exception %7B%0A        try %7B%0A            DataSource ds = ConnectionFactory.configureDataSource(null, new Properties());%0A            fail(%22Expected: NullPointerException%22);%0A        %7D catch (NullPointerException e) %7B%0A        %7D%0A    %7D%0A%0A%7D%0A

Test class for ConnectionFactory