KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > dbcp > datasources > TestFactory


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.dbcp.datasources;
18
19 import java.util.Hashtable JavaDoc;
20
21 import javax.naming.CompositeName JavaDoc;
22 import javax.naming.Context JavaDoc;
23 import javax.naming.InitialContext JavaDoc;
24 import javax.naming.Name JavaDoc;
25 import javax.naming.Reference JavaDoc;
26 import javax.naming.StringRefAddr JavaDoc;
27 import javax.naming.spi.ObjectFactory JavaDoc;
28
29 import junit.framework.Test;
30 import junit.framework.TestCase;
31 import junit.framework.TestSuite;
32
33 /**
34  * @author Dirk Verbeeck
35  * @version $Revision: 1.2 $ $Date: 2004/02/28 11:47:52 $
36  */

37 public class TestFactory extends TestCase {
38     public TestFactory(String JavaDoc testName) {
39         super(testName);
40     }
41
42     public static Test suite() {
43         return new TestSuite(TestFactory.class);
44     }
45
46     // Bugzilla Bug 24082: bug in InstanceKeyDataSourceFactory
47
// There's a fatal bug in InstanceKeyDataSourceFactory that means you can't
48
// instantiate more than one factory.
49
// http://issues.apache.org/bugzilla/show_bug.cgi?id=24082
50
public void testJNDI2Pools() throws Exception JavaDoc {
51         Reference JavaDoc refObj = new Reference JavaDoc(SharedPoolDataSource.class.getName());
52         refObj.add(new StringRefAddr JavaDoc("dataSourceName","java:comp/env/jdbc/bookstoreCPDS"));
53         Context JavaDoc context = new InitialContext JavaDoc();
54         Hashtable JavaDoc env = new Hashtable JavaDoc();
55         
56         ObjectFactory JavaDoc factory = new SharedPoolDataSourceFactory();
57         
58         Name JavaDoc name = new CompositeName JavaDoc("myDB");
59         Object JavaDoc obj = factory.getObjectInstance(refObj, name, context, env);
60         assertNotNull(obj);
61         
62         Name JavaDoc name2 = new CompositeName JavaDoc("myDB2");
63         Object JavaDoc obj2 = factory.getObjectInstance(refObj, name2, context, env);
64         assertNotNull(obj2);
65     }
66 }
67
Popular Tags