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