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