KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.*;
27 import javax.naming.Reference JavaDoc;
28 import junit.framework.*;
29 import com.mchange.v2.ser.SerializableUtils;
30 import com.mchange.v2.beans.BeansUtils;
31 import com.mchange.v2.naming.ReferenceableUtils;
32 import com.mchange.v2.c3p0.ComboPooledDataSource;
33
34 public final class MarshallUnmarshallDataSourcesJUnitTestCase extends C3P0JUnitTestCaseBase
35 {
36     final static Collection EXCLUDE_PROPS = Arrays.asList( new String JavaDoc[]{
37                                     "allUsers",
38                                     "connection",
39                                     "connectionPoolDataSource",
40                                     "effectivePropertyCycleDefaultUser",
41                                     "lastCheckinFailureDefaultUser",
42                                     "lastCheckoutFailureDefaultUser",
43                                     "lastConnectionTestFailureDefaultUser",
44                                     "lastIdleTestFailureDefaultUser",
45                                     "logWriter",
46                                     "numBusyConnections",
47                                     "numBusyConnectionsAllUsers",
48                                     "numBusyConnectionsDefaultUser",
49                                     "numConnections",
50                                     "numConnectionsAllUsers",
51                                     "numConnectionsDefaultUser",
52                                     "numFailedCheckinsDefaultUser",
53                                     "numFailedCheckoutsDefaultUser",
54                                     "numFailedIdleTestsDefaultUser",
55                                     "numIdleConnections",
56                                     "numIdleConnectionsAllUsers",
57                                     "numIdleConnectionsDefaultUser",
58                                     "numUnclosedOrphanedConnections",
59                                     "numUnclosedOrphanedConnectionsAllUsers",
60                                     "numUnclosedOrphanedConnectionsDefaultUser",
61                                     "numUserPools",
62                                     "startTimeMillisDefaultUser",
63                                     "statementCacheNumCheckedOutDefaultUser",
64                                     "statementCacheNumCheckedOutStatementsAllUsers",
65                                     "statementCacheNumConnectionsWithCachedStatementsAllUsers",
66                                     "statementCacheNumConnectionsWithCachedStatementsDefaultUser",
67                                     "statementCacheNumStatementsAllUsers",
68                                     "statementCacheNumStatementsDefaultUser",
69                                     "threadPoolSize",
70                                     "threadPoolNumActiveThreads",
71                                     "threadPoolNumIdleThreads",
72                                     "threadPoolNumTasksPending",
73                                     "threadPoolStackTraces",
74                                     "threadPoolStatus",
75                                     "upTimeMillisDefaultUser"
76                                     } );
77
78     public void testSerializationRoundTrip()
79     {
80     try
81         {
82         cpds.setIdentityToken("poop"); //simulate a never-before-seen data source, so it's a new registration on deserialization
83
byte[] pickled = SerializableUtils.toByteArray(cpds);
84         ComboPooledDataSource unpickled = (ComboPooledDataSource) SerializableUtils.fromByteArray( pickled );
85         assertTrue( "Marshalled and unmarshalled DataSources should have the same properties!",
86                 BeansUtils.equalsByAccessibleProperties( cpds, unpickled, EXCLUDE_PROPS ) );
87         }
88     catch (Exception JavaDoc e)
89         {
90         e.printStackTrace();
91         fail( e.getMessage() );
92         }
93     }
94
95     public void testRefDerefRoundTrip()
96     {
97     try
98         {
99         cpds.setIdentityToken("scoop"); //simulate a never-before-seen data source, so it's a new registration on deserialization
100
Reference JavaDoc ref = cpds.getReference();
101         ComboPooledDataSource unpickled = (ComboPooledDataSource) ReferenceableUtils.referenceToObject( ref, null, null, null );
102         assertTrue( "Marshalled and unmarshalled DataSources should have the same properties!",
103                 BeansUtils.equalsByAccessibleProperties( cpds, unpickled, EXCLUDE_PROPS ) );
104         }
105     catch (Exception JavaDoc e)
106         {
107         e.printStackTrace();
108         fail( e.getMessage() );
109         }
110     }
111 }
112
Popular Tags