/external/apache-harmony/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/ConnectionTest.java

https://gitlab.com/brian0218/rk3188_r-box_android4.2.2_sdk · Java · 89 lines · 46 code · 13 blank · 30 comment · 5 complexity · bfadac317a67a162dc9e3159e5859d7a MD5 · raw file

  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. package org.apache.harmony.sql.tests.java.sql;
  18. import java.lang.reflect.Field;
  19. import java.lang.reflect.Modifier;
  20. import java.util.HashMap;
  21. import junit.framework.TestCase;
  22. public class ConnectionTest extends TestCase {
  23. /*
  24. * Public statics test
  25. */
  26. public void testPublicStatics() {
  27. HashMap<String, Integer> thePublicStatics = new HashMap<String, Integer>();
  28. thePublicStatics.put("TRANSACTION_SERIALIZABLE", new Integer(8));
  29. thePublicStatics.put("TRANSACTION_REPEATABLE_READ", new Integer(4));
  30. thePublicStatics.put("TRANSACTION_READ_COMMITTED", new Integer(2));
  31. thePublicStatics.put("TRANSACTION_READ_UNCOMMITTED", new Integer(1));
  32. thePublicStatics.put("TRANSACTION_NONE", new Integer(0));
  33. /*
  34. * System.out.println( "TRANSACTION_SERIALIZABLE: " +
  35. * Connection.TRANSACTION_SERIALIZABLE ); System.out.println(
  36. * "TRANSACTION_REPEATABLE_READ: " +
  37. * Connection.TRANSACTION_REPEATABLE_READ ); System.out.println(
  38. * "TRANSACTION_READ_COMMITTED: " +
  39. * Connection.TRANSACTION_READ_COMMITTED ); System.out.println(
  40. * "TRANSACTION_READ_UNCOMMITTED: " +
  41. * Connection.TRANSACTION_READ_UNCOMMITTED ); System.out.println(
  42. * "TRANSACTION_NONE: " + Connection.TRANSACTION_NONE );
  43. */
  44. Class<?> connectionClass;
  45. try {
  46. connectionClass = Class.forName("java.sql.Connection");
  47. } catch (ClassNotFoundException e) {
  48. fail("java.sql.Connection class not found!");
  49. return;
  50. } // end try
  51. Field[] theFields = connectionClass.getDeclaredFields();
  52. int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
  53. + Modifier.FINAL;
  54. int countPublicStatics = 0;
  55. for (Field element : theFields) {
  56. String fieldName = element.getName();
  57. int theMods = element.getModifiers();
  58. if (Modifier.isPublic(theMods) && Modifier.isStatic(theMods)) {
  59. try {
  60. Object fieldValue = element.get(null);
  61. Object expectedValue = thePublicStatics.get(fieldName);
  62. if (expectedValue == null) {
  63. fail("Field " + fieldName + " missing!");
  64. } // end
  65. assertEquals("Field " + fieldName + " value mismatch: ",
  66. expectedValue, fieldValue);
  67. assertEquals("Field " + fieldName + " modifier mismatch: ",
  68. requiredModifier, theMods);
  69. countPublicStatics++;
  70. } catch (IllegalAccessException e) {
  71. fail("Illegal access to Field " + fieldName);
  72. } // end try
  73. } // end if
  74. } // end for
  75. } // end method testPublicStatics
  76. } // end class ConnectionTest