01: package org.geotools.data.jdbc.ds;
02:
03: import java.io.IOException;
04: import java.util.HashMap;
05: import java.util.Map;
06:
07: import javax.sql.DataSource;
08:
09: import junit.framework.TestCase;
10:
11: import org.apache.commons.dbcp.BasicDataSource;
12: import org.geotools.data.jdbc.datasource.DBCPDataSourceFactory;
13: import org.geotools.data.jdbc.datasource.DataSourceFinder;
14:
15: public class DataSourceFinderTest extends TestCase {
16: public void testDbcpFactory() throws IOException {
17: assertTrue(new DBCPDataSourceFactory().isAvailable());
18: DataSourceFinder.scanForPlugins();
19:
20: Map map = new HashMap();
21: map.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
22: map.put(DBCPDataSourceFactory.DRIVERCLASS.key, "org.h2.Driver");
23: map.put(DBCPDataSourceFactory.JDBC_URL.key,
24: "jdbc:h2:mem:test_mem");
25: map.put(DBCPDataSourceFactory.USERNAME.key, "admin");
26: map.put(DBCPDataSourceFactory.PASSWORD.key, "");
27: map.put(DBCPDataSourceFactory.MAXACTIVE.key, new Integer(10));
28: map.put(DBCPDataSourceFactory.MAXIDLE.key, new Integer(0));
29:
30: DataSource source = DataSourceFinder.getDataSource(map);
31: assertNotNull(source);
32: assertTrue(source instanceof BasicDataSource);
33: }
34:
35: // public void testJNDIFactory() throws Exception {
36: // can't make this work... there are dependencies from EJBMock to stuff
37: // that's not in the maven repos
38:
39: // EJBMockObjectFactory ejbMock = new EJBMockObjectFactory();
40: // ejbMock.initMockContextFactory();
41: // Context mockContext = new MockContext();
42: // InitialContext context = new InitialContext();
43: // DataSource mockDataSource = new MockDataSource();
44: // context.rebind("jdbc/pool", mockDataSource);
45: // JNDI.init(context);
46: //
47: // assertTrue(new JNDIDataSourceFactory().isAvailable());
48: // DataSourceFinder.scanForPlugins();
49: //
50: //
51: //
52: // Map map = new HashMap();
53: // map.put(JNDIDataSourceFactory.JNDI_REFNAME.key, "jdbc/pool");
54: //
55: // DataSource source = DataSourceFinder.getDataSource(map);
56: // assertNotNull(source);
57: // assertEquals(mockDataSource, source);
58: // }
59: }
|