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.harmony.sql.tests.java.sql;
19:
20: import java.lang.reflect.Field;
21: import java.lang.reflect.Modifier;
22: import java.util.HashMap;
23:
24: import junit.framework.TestCase;
25:
26: public class ConnectionTest extends TestCase {
27:
28: /*
29: * Public statics test
30: */
31: public void testPublicStatics() {
32:
33: HashMap<String, Integer> thePublicStatics = new HashMap<String, Integer>();
34: thePublicStatics
35: .put("TRANSACTION_SERIALIZABLE", new Integer(8));
36: thePublicStatics.put("TRANSACTION_REPEATABLE_READ",
37: new Integer(4));
38: thePublicStatics.put("TRANSACTION_READ_COMMITTED", new Integer(
39: 2));
40: thePublicStatics.put("TRANSACTION_READ_UNCOMMITTED",
41: new Integer(1));
42: thePublicStatics.put("TRANSACTION_NONE", new Integer(0));
43:
44: /*
45: * System.out.println( "TRANSACTION_SERIALIZABLE: " +
46: * Connection.TRANSACTION_SERIALIZABLE ); System.out.println(
47: * "TRANSACTION_REPEATABLE_READ: " +
48: * Connection.TRANSACTION_REPEATABLE_READ ); System.out.println(
49: * "TRANSACTION_READ_COMMITTED: " +
50: * Connection.TRANSACTION_READ_COMMITTED ); System.out.println(
51: * "TRANSACTION_READ_UNCOMMITTED: " +
52: * Connection.TRANSACTION_READ_UNCOMMITTED ); System.out.println(
53: * "TRANSACTION_NONE: " + Connection.TRANSACTION_NONE );
54: */
55:
56: Class<?> connectionClass;
57: try {
58: connectionClass = Class.forName("java.sql.Connection");
59: } catch (ClassNotFoundException e) {
60: fail("java.sql.Connection class not found!");
61: return;
62: } // end try
63:
64: Field[] theFields = connectionClass.getDeclaredFields();
65: int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
66: + Modifier.FINAL;
67:
68: int countPublicStatics = 0;
69: for (Field element : theFields) {
70: String fieldName = element.getName();
71: int theMods = element.getModifiers();
72: if (Modifier.isPublic(theMods)
73: && Modifier.isStatic(theMods)) {
74: try {
75: Object fieldValue = element.get(null);
76: Object expectedValue = thePublicStatics
77: .get(fieldName);
78: if (expectedValue == null) {
79: fail("Field " + fieldName + " missing!");
80: } // end
81: assertEquals("Field " + fieldName
82: + " value mismatch: ", expectedValue,
83: fieldValue);
84: assertEquals("Field " + fieldName
85: + " modifier mismatch: ", requiredModifier,
86: theMods);
87: countPublicStatics++;
88: } catch (IllegalAccessException e) {
89: fail("Illegal access to Field " + fieldName);
90: } // end try
91: } // end if
92: } // end for
93:
94: } // end method testPublicStatics
95:
96: } // end class ConnectionTest
|