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