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