KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mchange > v2 > c3p0 > test > junit > ConnectionPropertiesResetJUnitTestCase


1 /*
2  * Distributed as part of c3p0 v.0.9.1
3  *
4  * Copyright (C) 2005 Machinery For Change, Inc.
5  *
6  * Author: Steve Waldman <swaldman@mchange.com>
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License version 2.1, as
10  * published by the Free Software Foundation.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this software; see the file LICENSE. If not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */

22
23
24 package com.mchange.v2.c3p0.test.junit;
25
26 import java.sql.*;
27 import java.util.*;
28 import junit.framework.*;
29
30 public final class ConnectionPropertiesResetJUnitTestCase extends C3P0JUnitTestCaseBase
31 {
32     final static Map TM;
33
34     static
35     {
36     Map tmp = new HashMap();
37     tmp.put("FAKE", SQLData.class);
38     TM = Collections.unmodifiableMap( tmp );
39     }
40
41     public void testAllConnectionDefaultsReset()
42     {
43 // System.err.println("XOXO err");
44
// System.out.println("XOXO out");
45

46     cpds.setInitialPoolSize(5);
47     cpds.setMinPoolSize(5);
48     cpds.setMaxPoolSize(5);
49     cpds.setMaxIdleTime(0);
50     cpds.setTestConnectionOnCheckout(false);
51     cpds.setTestConnectionOnCheckin(false);
52     cpds.setIdleConnectionTestPeriod(0);
53
54     String JavaDoc dfltCat;
55     int dflt_txn_isolation;
56
57     try
58         {
59         Connection con = null;
60         try
61             {
62             con = cpds.getConnection();
63             
64
65             dfltCat = con.getCatalog();
66             dflt_txn_isolation = con.getTransactionIsolation();
67
68             try { con.setReadOnly(true); } catch (Exception JavaDoc e) { /* setReadOnly() not supported */ }
69             try { con.setTypeMap(TM); } catch (Exception JavaDoc e) { /* setTypeMap() not supported */ }
70             try { con.setCatalog("C3P0TestCatalogXXX"); } catch (Exception JavaDoc e) { /* setCatalog() not supported */ }
71             try
72                 {
73                 con.setTransactionIsolation( dflt_txn_isolation == Connection.TRANSACTION_SERIALIZABLE ?
74                                  Connection.TRANSACTION_READ_COMMITTED :
75                                  Connection.TRANSACTION_SERIALIZABLE );
76                 }
77             catch (Exception JavaDoc e) { /* setTransactionIsolation() not fully supported */ }
78             }
79         finally
80             {
81             try { if (con != null) con.close(); }
82             catch (Exception JavaDoc e) {}
83             }
84
85         Connection[] cons = new Connection[5];
86         for (int i = 0; i < 5; ++i)
87             {
88             cons[i] = cpds.getConnection();
89             assertFalse( "Connection from pool should not be readOnly!", cons[i].isReadOnly() );
90
91             // some drivers return null rather than an empty type map
92
Map typeMap = cons[i].getTypeMap();
93             assertTrue( "Connection from pool should have an empty type map!", (typeMap == null ? true : typeMap.isEmpty() ) );
94
95             assertEquals( "Connection from pool should have default catalog set!", dfltCat, cons[i].getCatalog() );
96             assertEquals( "Connection from pool should have default txn isolation set!", dflt_txn_isolation, cons[i].getTransactionIsolation() );
97             cons[i].close();
98             }
99         }
100     catch (Exception JavaDoc e)
101         {
102         e.printStackTrace();
103         fail( e.getMessage() );
104         }
105     }
106 }
Popular Tags