1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.dbcp2.datasources;
19
20 import static org.junit.jupiter.api.Assertions.assertNotNull;
21
22 import java.util.Hashtable;
23
24 import javax.naming.CompositeName;
25 import javax.naming.Context;
26 import javax.naming.InitialContext;
27 import javax.naming.Name;
28 import javax.naming.Reference;
29 import javax.naming.StringRefAddr;
30 import javax.naming.spi.ObjectFactory;
31
32 import org.junit.jupiter.api.Test;
33
34
35
36 public class TestFactory {
37
38
39
40
41
42 @Test
43 public void testJNDI2Pools() throws Exception {
44 final Reference refObj = new Reference(SharedPoolDataSource.class.getName());
45 refObj.add(new StringRefAddr("dataSourceName","java:comp/env/jdbc/bookstoreCPDS"));
46 final Context context = new InitialContext();
47 final Hashtable<?, ?> env = new Hashtable<>();
48
49 final ObjectFactory factory = new SharedPoolDataSourceFactory();
50
51 final Name name = new CompositeName("myDB");
52 final Object obj = factory.getObjectInstance(refObj, name, context, env);
53 assertNotNull(obj);
54
55 final Name name2 = new CompositeName("myDB2");
56 final Object obj2 = factory.getObjectInstance(refObj, name2, context, env);
57 assertNotNull(obj2);
58 }
59 }