01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.commons.dbcp.datasources;
19:
20: import java.util.Hashtable;
21:
22: import javax.naming.CompositeName;
23: import javax.naming.Context;
24: import javax.naming.InitialContext;
25: import javax.naming.Name;
26: import javax.naming.Reference;
27: import javax.naming.StringRefAddr;
28: import javax.naming.spi.ObjectFactory;
29:
30: import junit.framework.Test;
31: import junit.framework.TestCase;
32: import junit.framework.TestSuite;
33:
34: /**
35: * @author Dirk Verbeeck
36: * @version $Revision: 479137 $ $Date: 2006-11-25 08:51:48 -0700 (Sat, 25 Nov 2006) $
37: */
38: public class TestFactory extends TestCase {
39: public TestFactory(String testName) {
40: super (testName);
41: }
42:
43: public static Test suite() {
44: return new TestSuite(TestFactory.class);
45: }
46:
47: // Bugzilla Bug 24082: bug in InstanceKeyDataSourceFactory
48: // There's a fatal bug in InstanceKeyDataSourceFactory that means you can't
49: // instantiate more than one factory.
50: // http://issues.apache.org/bugzilla/show_bug.cgi?id=24082
51: public void testJNDI2Pools() throws Exception {
52: Reference refObj = new Reference(SharedPoolDataSource.class
53: .getName());
54: refObj.add(new StringRefAddr("dataSourceName",
55: "java:comp/env/jdbc/bookstoreCPDS"));
56: Context context = new InitialContext();
57: Hashtable env = new Hashtable();
58:
59: ObjectFactory factory = new SharedPoolDataSourceFactory();
60:
61: Name name = new CompositeName("myDB");
62: Object obj = factory.getObjectInstance(refObj, name, context,
63: env);
64: assertNotNull(obj);
65:
66: Name name2 = new CompositeName("myDB2");
67: Object obj2 = factory.getObjectInstance(refObj, name2, context,
68: env);
69: assertNotNull(obj2);
70: }
71: }
|