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.params.ParameterizedTest;
33 import org.junit.jupiter.params.provider.CsvSource;
34
35
36
37
38 public class TestFactory {
39
40
41
42
43
44
45
46 @ParameterizedTest
47
48 @CsvSource({
49 "dataSourceName, java:comp/env/jdbc/bookstoreCPDS",
50 "description, This is a test.",
51 "jndiEnvironment, X",
52 "loginTimeout, 30000",
53 "blockWhenExhausted, false",
54 "evictionPolicyClassName, org.apache.commons.pool2.impl.DefaultEvictionPolicy",
55 "lifo, true",
56 "maxIdlePerKey, 4",
57 "maxTotalPerKey, 4",
58 "maxWaitMillis, 30001",
59 "minEvictableIdleTimeMillis, 30002",
60 "minIdlePerKey, 4",
61 "numTestsPerEvictionRun, 2",
62 "softMinEvictableIdleTimeMillis, 30003",
63 "testOnCreate, true",
64 "testOnBorrow, true",
65 "testOnReturn, true",
66 "testWhileIdle, true",
67 "timeBetweenEvictionRunsMillis, 30004",
68 "validationQuery, select 1",
69 "validationQueryTimeout, 30005",
70 "rollbackAfterValidation, false",
71 "maxConnLifetimeMillis, 60000",
72 "defaultAutoCommit, true",
73 "defaultTransactionIsolation, X",
74 "defaultReadOnly, true" })
75
76 public void testJNDI2Pools(final String string, final String value) throws Exception {
77 final Reference refObj = new Reference(SharedPoolDataSource.class.getName());
78 refObj.add(new StringRefAddr(string, value));
79 final Context context = new InitialContext();
80 final Hashtable<?, ?> env = new Hashtable<>();
81
82 final ObjectFactory factory = new SharedPoolDataSourceFactory();
83
84 final Name name = new CompositeName("myDB");
85 final Object obj = factory.getObjectInstance(refObj, name, context, env);
86 assertNotNull(obj);
87
88 final Name name2 = new CompositeName("myDB2");
89 final Object obj2 = factory.getObjectInstance(refObj, name2, context, env);
90 assertNotNull(obj2);
91 }
92 }