1 16 17 package org.apache.commons.dbcp.datasources; 18 19 import java.util.Hashtable ; 20 21 import javax.naming.CompositeName ; 22 import javax.naming.Context ; 23 import javax.naming.InitialContext ; 24 import javax.naming.Name ; 25 import javax.naming.Reference ; 26 import javax.naming.StringRefAddr ; 27 import javax.naming.spi.ObjectFactory ; 28 29 import junit.framework.Test; 30 import junit.framework.TestCase; 31 import junit.framework.TestSuite; 32 33 37 public class TestFactory extends TestCase { 38 public TestFactory(String testName) { 39 super(testName); 40 } 41 42 public static Test suite() { 43 return new TestSuite(TestFactory.class); 44 } 45 46 public void testJNDI2Pools() throws Exception { 51 Reference refObj = new Reference (SharedPoolDataSource.class.getName()); 52 refObj.add(new StringRefAddr ("dataSourceName","java:comp/env/jdbc/bookstoreCPDS")); 53 Context context = new InitialContext (); 54 Hashtable env = new Hashtable (); 55 56 ObjectFactory factory = new SharedPoolDataSourceFactory(); 57 58 Name name = new CompositeName ("myDB"); 59 Object obj = factory.getObjectInstance(refObj, name, context, env); 60 assertNotNull(obj); 61 62 Name name2 = new CompositeName ("myDB2"); 63 Object obj2 = factory.getObjectInstance(refObj, name2, context, env); 64 assertNotNull(obj2); 65 } 66 } 67 | Popular Tags |