001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.sql.tests.java.sql;
019:
020: import java.lang.reflect.Field;
021: import java.lang.reflect.Modifier;
022: import java.util.HashMap;
023:
024: import junit.framework.TestCase;
025:
026: public class ResultSetTest extends TestCase {
027:
028: /*
029: * Public statics test
030: */
031: public void testPublicStatics() {
032:
033: HashMap<String, Integer> thePublicStatics = new HashMap<String, Integer>();
034: thePublicStatics.put("CLOSE_CURSORS_AT_COMMIT",
035: new java.lang.Integer(2));
036: thePublicStatics.put("HOLD_CURSORS_OVER_COMMIT",
037: new java.lang.Integer(1));
038: thePublicStatics.put("CONCUR_UPDATABLE", new java.lang.Integer(
039: 1008));
040: thePublicStatics.put("CONCUR_READ_ONLY", new java.lang.Integer(
041: 1007));
042: thePublicStatics.put("TYPE_SCROLL_SENSITIVE",
043: new java.lang.Integer(1005));
044: thePublicStatics.put("TYPE_SCROLL_INSENSITIVE",
045: new java.lang.Integer(1004));
046: thePublicStatics.put("TYPE_FORWARD_ONLY",
047: new java.lang.Integer(1003));
048: thePublicStatics.put("FETCH_UNKNOWN", new java.lang.Integer(
049: 1002));
050: thePublicStatics.put("FETCH_REVERSE", new java.lang.Integer(
051: 1001));
052: thePublicStatics.put("FETCH_FORWARD", new java.lang.Integer(
053: 1000));
054:
055: /*
056: * System.out.println( "CLOSE_CURSORS_AT_COMMIT: " +
057: * ResultSet.CLOSE_CURSORS_AT_COMMIT ); System.out.println(
058: * "HOLD_CURSORS_OVER_COMMIT: " + ResultSet.HOLD_CURSORS_OVER_COMMIT );
059: * System.out.println( "CONCUR_UPDATABLE: " + ResultSet.CONCUR_UPDATABLE );
060: * System.out.println( "CONCUR_READ_ONLY: " + ResultSet.CONCUR_READ_ONLY );
061: * System.out.println( "TYPE_SCROLL_SENSITIVE: " +
062: * ResultSet.TYPE_SCROLL_SENSITIVE ); System.out.println(
063: * "TYPE_SCROLL_INSENSITIVE: " + ResultSet.TYPE_SCROLL_INSENSITIVE );
064: * System.out.println( "TYPE_FORWARD_ONLY: " +
065: * ResultSet.TYPE_FORWARD_ONLY ); System.out.println( "FETCH_UNKNOWN: " +
066: * ResultSet.FETCH_UNKNOWN ); System.out.println( "FETCH_REVERSE: " +
067: * ResultSet.FETCH_REVERSE ); System.out.println( "FETCH_FORWARD: " +
068: * ResultSet.FETCH_FORWARD );
069: */
070:
071: Class<?> resultSetClass;
072: try {
073: resultSetClass = Class.forName("java.sql.ResultSet");
074: } catch (ClassNotFoundException e) {
075: fail("java.sql.ResultSet class not found!");
076: return;
077: } // end try
078:
079: Field[] theFields = resultSetClass.getDeclaredFields();
080: int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
081: + Modifier.FINAL;
082:
083: int countPublicStatics = 0;
084: for (Field element : theFields) {
085: String fieldName = element.getName();
086: int theMods = element.getModifiers();
087: if (Modifier.isPublic(theMods)
088: && Modifier.isStatic(theMods)) {
089: try {
090: Object fieldValue = element.get(null);
091: Object expectedValue = thePublicStatics
092: .get(fieldName);
093: if (expectedValue == null) {
094: fail("Field " + fieldName + " missing!");
095: } // end
096: assertEquals("Field " + fieldName
097: + " value mismatch: ", expectedValue,
098: fieldValue);
099: assertEquals("Field " + fieldName
100: + " modifier mismatch: ", requiredModifier,
101: theMods);
102: countPublicStatics++;
103: } catch (IllegalAccessException e) {
104: fail("Illegal access to Field " + fieldName);
105: } // end try
106: } // end if
107: } // end for
108:
109: } // end method testPublicStatics
110:
111: } // end class ResultSetTest
|