KickJava   Java API By Example, From Geeks To Geeks.

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


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.sql.Connection JavaDoc;
20 import java.sql.PreparedStatement JavaDoc;
21 import java.sql.ResultSet JavaDoc;
22
23 import junit.framework.Test;
24 import junit.framework.TestCase;
25 import junit.framework.TestSuite;
26
27 /**
28  * TestSuite for BasicDataSource
29  *
30  * @author Dirk Verbeeck
31  * @version $Revision: 1.21 $ $Date: 2004/05/20 13:08:32 $
32  */

33 public class TestOracleBasicDataSource extends TestCase {
34     public TestOracleBasicDataSource(String JavaDoc testName) {
35         super(testName);
36     }
37
38     public static Test suite() {
39         return new TestSuite(TestOracleBasicDataSource.class);
40     }
41
42     protected Connection JavaDoc getConnection() throws Exception JavaDoc {
43         return ds.getConnection();
44     }
45
46     protected BasicDataSource ds = null;
47     private static String JavaDoc CATALOG = "test catalog";
48
49     public void setUp() throws Exception JavaDoc {
50         super.setUp();
51         ds = new BasicDataSource();
52         ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
53         ds.setUrl("jdbc:oracle:thin:@localhost:1521:DEMO");
54         ds.setMaxActive(10);
55         ds.setMaxWait(100);
56         ds.setDefaultAutoCommit(true);
57         ds.setDefaultReadOnly(true);
58         ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
59         // ds.setDefaultCatalog(CATALOG);
60
ds.setUsername("SCOTT");
61         ds.setPassword("TIGER");
62         ds.setValidationQuery("SELECT DUMMY FROM DUAL");
63     }
64
65     public void tearDown() throws Exception JavaDoc {
66         super.tearDown();
67         ds = null;
68     }
69  
70     public void testSimple() throws Exception JavaDoc {
71          Connection JavaDoc conn = getConnection();
72          assertTrue(null != conn);
73          PreparedStatement JavaDoc stmt = conn.prepareStatement("select * from dual");
74          assertTrue(null != stmt);
75          ResultSet JavaDoc rset = stmt.executeQuery();
76          assertTrue(null != rset);
77          assertTrue(rset.next());
78          rset.close();
79          stmt.close();
80          conn.close();
81      }
82    
83
84 }
85
Popular Tags