2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.apache.harmony.sql.tests.java.sql;
20 import dalvik.annotation.TestTargetClass;
21 import dalvik.annotation.TestTargets;
22 import dalvik.annotation.TestLevel;
23 import dalvik.annotation.TestTargetNew;
25 import java.lang.reflect.Field;
26 import java.lang.reflect.Modifier;
27 import java.util.HashMap;
29 import junit.framework.TestCase;
31 @TestTargetClass(java.sql.ParameterMetaData.class)
32 public class ParameterMetaDataTest extends TestCase {
38 level = TestLevel.COMPLETE,
39 notes = "Field testing",
40 method = "!Constants",
43 public void testPublicStatics() {
45 HashMap<String, Integer> thePublicStatics = new HashMap<String, Integer>();
46 thePublicStatics.put("parameterModeOut", new Integer(4));
47 thePublicStatics.put("parameterModeInOut", new Integer(2));
48 thePublicStatics.put("parameterModeIn", new Integer(1));
49 thePublicStatics.put("parameterModeUnknown", new Integer(0));
50 thePublicStatics.put("parameterNullableUnknown", new Integer(2));
51 thePublicStatics.put("parameterNullable", new Integer(1));
52 thePublicStatics.put("parameterNoNulls", new Integer(0));
55 * System.out.println( "parameterModeOut: " +
56 * ParameterMetaData.parameterModeOut ); System.out.println(
57 * "parameterModeInOut: " + ParameterMetaData.parameterModeInOut );
58 * System.out.println( "parameterModeIn: " +
59 * ParameterMetaData.parameterModeIn ); System.out.println(
60 * "parameterModeUnknown: " + ParameterMetaData.parameterModeUnknown );
61 * System.out.println( "parameterNullableUnknown: " +
62 * ParameterMetaData.parameterNullableUnknown ); System.out.println(
63 * "parameterNullable: " + ParameterMetaData.parameterNullable );
64 * System.out.println( "parameterNoNulls: " +
65 * ParameterMetaData.parameterNoNulls );
68 Class<?> parameterMetaDataClass;
70 parameterMetaDataClass = Class
71 .forName("java.sql.ParameterMetaData");
72 } catch (ClassNotFoundException e) {
73 fail("java.sql.ParameterMetaData class not found!");
77 Field[] theFields = parameterMetaDataClass.getDeclaredFields();
78 int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
81 int countPublicStatics = 0;
82 for (Field element : theFields) {
83 String fieldName = element.getName();
84 int theMods = element.getModifiers();
85 if (Modifier.isPublic(theMods) && Modifier.isStatic(theMods)) {
87 Object fieldValue = element.get(null);
88 Object expectedValue = thePublicStatics.get(fieldName);
89 if (expectedValue == null) {
90 fail("Field " + fieldName + " missing!");
92 assertEquals("Field " + fieldName + " value mismatch: ",
93 expectedValue, fieldValue);
94 assertEquals("Field " + fieldName + " modifier mismatch: ",
95 requiredModifier, theMods);
97 } catch (IllegalAccessException e) {
98 fail("Illegal access to Field " + fieldName);
103 } // end method testPublicStatics
105 } // end class ParameterMetaDataTest