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 DatabaseMetaDataTest extends TestCase {
027:
028: /*
029: * Public statics test
030: */
031: public void testPublicStatics() {
032:
033: HashMap<String, Number> thePublicStatics = new HashMap<String, Number>();
034: thePublicStatics.put("sqlStateSQL99", new Integer(2));
035: thePublicStatics.put("sqlStateXOpen", new Integer(1));
036: thePublicStatics.put("attributeNullableUnknown", new Short(
037: (short) 2));
038: thePublicStatics.put("attributeNullable", new Short((short) 1));
039: thePublicStatics.put("attributeNoNulls", new Short((short) 0));
040: thePublicStatics.put("tableIndexOther", new Short((short) 3));
041: thePublicStatics.put("tableIndexHashed", new Short((short) 2));
042: thePublicStatics.put("tableIndexClustered",
043: new Short((short) 1));
044: thePublicStatics.put("tableIndexStatistic",
045: new Short((short) 0));
046: thePublicStatics.put("typeSearchable", new Integer(3));
047: thePublicStatics.put("typePredBasic", new Integer(2));
048: thePublicStatics.put("typePredChar", new Integer(1));
049: thePublicStatics.put("typePredNone", new Integer(0));
050: thePublicStatics.put("typeNullableUnknown", new Integer(2));
051: thePublicStatics.put("typeNullable", new Integer(1));
052: thePublicStatics.put("typeNoNulls", new Integer(0));
053: thePublicStatics
054: .put("importedKeyNotDeferrable", new Integer(7));
055: thePublicStatics.put("importedKeyInitiallyImmediate",
056: new Integer(6));
057: thePublicStatics.put("importedKeyInitiallyDeferred",
058: new Integer(5));
059: thePublicStatics.put("importedKeySetDefault", new Integer(4));
060: thePublicStatics.put("importedKeyNoAction", new Integer(3));
061: thePublicStatics.put("importedKeySetNull", new Integer(2));
062: thePublicStatics.put("importedKeyRestrict", new Integer(1));
063: thePublicStatics.put("importedKeyCascade", new Integer(0));
064: thePublicStatics.put("versionColumnPseudo", new Integer(2));
065: thePublicStatics.put("versionColumnNotPseudo", new Integer(1));
066: thePublicStatics.put("versionColumnUnknown", new Integer(0));
067: thePublicStatics.put("bestRowPseudo", new Integer(2));
068: thePublicStatics.put("bestRowNotPseudo", new Integer(1));
069: thePublicStatics.put("bestRowUnknown", new Integer(0));
070: thePublicStatics.put("bestRowSession", new Integer(2));
071: thePublicStatics.put("bestRowTransaction", new Integer(1));
072: thePublicStatics.put("bestRowTemporary", new Integer(0));
073: thePublicStatics.put("columnNullableUnknown", new Integer(2));
074: thePublicStatics.put("columnNullable", new Integer(1));
075: thePublicStatics.put("columnNoNulls", new Integer(0));
076: thePublicStatics
077: .put("procedureNullableUnknown", new Integer(2));
078: thePublicStatics.put("procedureNullable", new Integer(1));
079: thePublicStatics.put("procedureNoNulls", new Integer(0));
080: thePublicStatics.put("procedureColumnResult", new Integer(3));
081: thePublicStatics.put("procedureColumnReturn", new Integer(5));
082: thePublicStatics.put("procedureColumnOut", new Integer(4));
083: thePublicStatics.put("procedureColumnInOut", new Integer(2));
084: thePublicStatics.put("procedureColumnIn", new Integer(1));
085: thePublicStatics.put("procedureColumnUnknown", new Integer(0));
086: thePublicStatics.put("procedureReturnsResult", new Integer(2));
087: thePublicStatics.put("procedureNoResult", new Integer(1));
088: thePublicStatics.put("procedureResultUnknown", new Integer(0));
089:
090: Class<?> databaseMetaDataClass;
091: try {
092: databaseMetaDataClass = Class
093: .forName("java.sql.DatabaseMetaData");
094: } catch (ClassNotFoundException e) {
095: fail("java.sql.DatabaseMetaData class not found!");
096: return;
097: } // end try
098:
099: Field[] theFields = databaseMetaDataClass.getDeclaredFields();
100: int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
101: + Modifier.FINAL;
102:
103: int countPublicStatics = 0;
104: for (Field element : theFields) {
105: String fieldName = element.getName();
106: int theMods = element.getModifiers();
107: if (Modifier.isPublic(theMods)
108: && Modifier.isStatic(theMods)) {
109: try {
110: Object fieldValue = element.get(null);
111: Object expectedValue = thePublicStatics
112: .get(fieldName);
113: if (expectedValue == null) {
114: fail("Field " + fieldName + " missing!");
115: } // end
116: assertEquals("Field " + fieldName
117: + " value mismatch: ", expectedValue,
118: fieldValue);
119: assertEquals("Field " + fieldName
120: + " modifier mismatch: ", requiredModifier,
121: theMods);
122: countPublicStatics++;
123: } catch (IllegalAccessException e) {
124: fail("Illegal access to Field " + fieldName);
125: } // end try
126: } // end if
127: } // end for
128:
129: } // end method testPublicStatics
130:
131: } // end class DatabaseMetaDataTest
|