KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > dbcp > TestBasicDataSourceFactory


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;
18
19 import java.util.Properties JavaDoc;
20
21 import javax.sql.DataSource JavaDoc;
22
23 import junit.framework.Test;
24 import junit.framework.TestCase;
25 import junit.framework.TestSuite;
26
27 /**
28  * TestSuite for BasicDataSourceFactory
29  *
30  * @author Dirk Verbeeck
31  * @version $Revision: 1.2 $ $Date: 2004/02/28 11:47:51 $
32  */

33 public class TestBasicDataSourceFactory extends TestCase {
34     public TestBasicDataSourceFactory(String JavaDoc testName) {
35         super(testName);
36     }
37
38     public static Test suite() {
39         return new TestSuite(TestBasicDataSourceFactory.class);
40     }
41     
42     public void testNoProperties() throws Exception JavaDoc {
43         Properties JavaDoc properties = new Properties JavaDoc();
44         DataSource JavaDoc ds = BasicDataSourceFactory.createDataSource(properties);
45         
46         assertNotNull(ds);
47         assertTrue(ds instanceof BasicDataSource);
48     }
49
50     public void testProperties() throws Exception JavaDoc {
51         Properties JavaDoc properties = new Properties JavaDoc();
52         properties.setProperty("driverClassName", "org.apache.commons.dbcp.TesterDriver");
53         properties.setProperty("url", "jdbc:apache:commons:testdriver");
54         properties.setProperty("maxActive", "10");
55         properties.setProperty("maxWait", "500");
56         properties.setProperty("defaultAutoCommit", "true");
57         properties.setProperty("defaultReadOnly", "false");
58         properties.setProperty("defaultTransactionIsolation", "READ_COMMITTED");
59         properties.setProperty("defaultCatalog", "test");
60         properties.setProperty("username", "username");
61         properties.setProperty("password", "password");
62         properties.setProperty("validationQuery", "SELECT DUMMY FROM DUAL");
63
64         BasicDataSource ds = (BasicDataSource) BasicDataSourceFactory.createDataSource(properties);
65         
66         assertEquals("jdbc:apache:commons:testdriver", ds.getUrl());
67         assertEquals(10, ds.getMaxActive());
68         assertEquals(true, ds.getDefaultAutoCommit());
69     }
70 }
71
Popular Tags