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 StatementTest 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.put("NO_GENERATED_KEYS", new Integer(2));
35: thePublicStatics.put("RETURN_GENERATED_KEYS", new Integer(1));
36: thePublicStatics.put("EXECUTE_FAILED", new Integer(-3));
37: thePublicStatics.put("SUCCESS_NO_INFO", new Integer(-2));
38: thePublicStatics.put("CLOSE_ALL_RESULTS", new Integer(3));
39: thePublicStatics.put("KEEP_CURRENT_RESULT", new Integer(2));
40: thePublicStatics.put("CLOSE_CURRENT_RESULT", new Integer(1));
41:
42: /*
43: * System.out.println( "NO_GENERATED_KEYS: " +
44: * Statement.NO_GENERATED_KEYS ); System.out.println(
45: * "RETURN_GENERATED_KEYS: " + Statement.RETURN_GENERATED_KEYS );
46: * System.out.println( "EXECUTE_FAILED: " + Statement.EXECUTE_FAILED );
47: * System.out.println( "SUCCESS_NO_INFO: " + Statement.SUCCESS_NO_INFO );
48: * System.out.println( "CLOSE_ALL_RESULTS: " +
49: * Statement.CLOSE_ALL_RESULTS ); System.out.println(
50: * "KEEP_CURRENT_RESULT: " + Statement.KEEP_CURRENT_RESULT );
51: * System.out.println( "CLOSE_CURRENT_RESULT: " +
52: * Statement.CLOSE_CURRENT_RESULT );
53: */
54:
55: Class<?> statementClass;
56: try {
57: statementClass = Class.forName("java.sql.Statement");
58: } catch (ClassNotFoundException e) {
59: fail("java.sql.Statement class not found!");
60: return;
61: } // end try
62:
63: Field[] theFields = statementClass.getDeclaredFields();
64: int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
65: + Modifier.FINAL;
66:
67: int countPublicStatics = 0;
68: for (Field element : theFields) {
69: String fieldName = element.getName();
70: int theMods = element.getModifiers();
71: if (Modifier.isPublic(theMods)
72: && Modifier.isStatic(theMods)) {
73: try {
74: Object fieldValue = element.get(null);
75: Object expectedValue = thePublicStatics
76: .get(fieldName);
77: if (expectedValue == null) {
78: fail("Field " + fieldName + " missing!");
79: } // end
80: assertEquals("Field " + fieldName
81: + " value mismatch: ", expectedValue,
82: fieldValue);
83: assertEquals("Field " + fieldName
84: + " modifier mismatch: ", requiredModifier,
85: theMods);
86: countPublicStatics++;
87: } catch (IllegalAccessException e) {
88: fail("Illegal access to Field " + fieldName);
89: } // end try
90: } // end if
91: } // end for
92:
93: } // end method testPublicStatics
94:
95: } // end class StatementTest
|