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 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) && Modifier.isStatic(theMods)) {
64                try {
65                    Object fieldValue = element.get(null);
66                    Object expectedValue = thePublicStatics.get(fieldName);
67                    if (expectedValue == null) {
68                        fail("Field " + fieldName + " missing!");
69                    } // end
70                    assertEquals("Field " + fieldName + " value mismatch: ",
71                            expectedValue, fieldValue);
72                    assertEquals("Field " + fieldName + " modifier mismatch: ",
73                            requiredModifier, theMods);
74                    countPublicStatics++;
75                } catch (IllegalAccessException e) {
76                    fail("Illegal access to Field " + fieldName);
77                } // end try
78            } // end if
79        } // end for
80
81    } // end method testPublicStatics
82
83} // end class ResultSetMetaDataTest
84
85