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