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;
19:
20: import java.util.Properties;
21:
22: import javax.sql.DataSource;
23:
24: import junit.framework.Test;
25: import junit.framework.TestCase;
26: import junit.framework.TestSuite;
27:
28: /**
29: * TestSuite for BasicDataSourceFactory
30: *
31: * @author Dirk Verbeeck
32: * @version $Revision: 479137 $ $Date: 2006-11-25 08:51:48 -0700 (Sat, 25 Nov 2006) $
33: */
34: public class TestBasicDataSourceFactory extends TestCase {
35: public TestBasicDataSourceFactory(String testName) {
36: super (testName);
37: }
38:
39: public static Test suite() {
40: return new TestSuite(TestBasicDataSourceFactory.class);
41: }
42:
43: public void testNoProperties() throws Exception {
44: Properties properties = new Properties();
45: DataSource ds = BasicDataSourceFactory
46: .createDataSource(properties);
47:
48: assertNotNull(ds);
49: assertTrue(ds instanceof BasicDataSource);
50: }
51:
52: public void testProperties() throws Exception {
53: Properties properties = new Properties();
54: properties.setProperty("driverClassName",
55: "org.apache.commons.dbcp.TesterDriver");
56: properties.setProperty("url", "jdbc:apache:commons:testdriver");
57: properties.setProperty("maxActive", "10");
58: properties.setProperty("maxWait", "500");
59: properties.setProperty("defaultAutoCommit", "true");
60: properties.setProperty("defaultReadOnly", "false");
61: properties.setProperty("defaultTransactionIsolation",
62: "READ_COMMITTED");
63: properties.setProperty("defaultCatalog", "test");
64: properties.setProperty("username", "username");
65: properties.setProperty("password", "password");
66: properties.setProperty("validationQuery",
67: "SELECT DUMMY FROM DUAL");
68:
69: BasicDataSource ds = (BasicDataSource) BasicDataSourceFactory
70: .createDataSource(properties);
71:
72: assertEquals("jdbc:apache:commons:testdriver", ds.getUrl());
73: assertEquals(10, ds.getMaxActive());
74: assertEquals(true, ds.getDefaultAutoCommit());
75: }
76: }
|