/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverPropertyInfoTest.java

https://github.com/mkedwards/platform__libcore · Java · 160 lines · 94 code · 36 blank · 30 comment · 0 complexity · 4ae2214b8e88266a1520a882563a7532 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 SQLite.JDBCDriver;
  19. import dalvik.annotation.BrokenTest;
  20. import dalvik.annotation.TestTargetClass;
  21. import dalvik.annotation.TestTargets;
  22. import dalvik.annotation.TestLevel;
  23. import dalvik.annotation.TestTargetNew;
  24. import java.sql.Driver;
  25. import java.sql.DriverManager;
  26. import java.sql.DriverPropertyInfo;
  27. import java.sql.SQLException;
  28. import java.util.Arrays;
  29. import java.util.Properties;
  30. import junit.framework.TestCase;
  31. @TestTargetClass(DriverPropertyInfo.class)
  32. /**
  33. * JUnit Testcase for the java.sql.DriverPropertyInfo class
  34. *
  35. */
  36. public class DriverPropertyInfoTest extends TestCase {
  37. /*
  38. * Constructor test
  39. */
  40. @TestTargetNew(
  41. level = TestLevel.COMPLETE,
  42. notes = "Verification with invalid parameters missed: no feasible behaviour not specified (black box approach).",
  43. method = "DriverPropertyInfo",
  44. args = {java.lang.String.class, java.lang.String.class}
  45. )
  46. public void testDriverPropertyInfoStringString() {
  47. DriverPropertyInfo aDriverPropertyInfo = new DriverPropertyInfo(
  48. validName, validValue);
  49. assertNotNull(aDriverPropertyInfo);
  50. assertEquals(aDriverPropertyInfo.name,validName);
  51. assertEquals(aDriverPropertyInfo.value,validValue);
  52. aDriverPropertyInfo = new DriverPropertyInfo(null, null);
  53. assertNotNull(aDriverPropertyInfo);
  54. assertNull(aDriverPropertyInfo.name);
  55. assertNull(aDriverPropertyInfo.value);
  56. } // end method testDriverPropertyInfoStringString
  57. /*
  58. * Public fields test
  59. */
  60. static String validName = "testname";
  61. static String validValue = "testvalue";
  62. static String[] updateChoices = { "Choice1", "Choice2", "Choice3" };
  63. static String updateValue = "updateValue";
  64. static boolean updateRequired = true;
  65. static String updateDescription = "update description";
  66. static String updateName = "updateName";
  67. String connectionURL = "jdbc:sqlite:/" + "Test.db";
  68. String classname = "SQLite.JDBCDriver";
  69. @TestTargetNew(
  70. level = TestLevel.COMPLETE,
  71. notes = "Field testing",
  72. method = "!Constants",
  73. args = {}
  74. )
  75. public void testPublicFields() {
  76. // Constructor here...
  77. DriverPropertyInfo aDriverPropertyInfo = new DriverPropertyInfo(
  78. validName, validValue);
  79. assertTrue(Arrays.equals(testChoices, aDriverPropertyInfo.choices));
  80. assertEquals(testValue, aDriverPropertyInfo.value);
  81. assertEquals(testRequired, aDriverPropertyInfo.required);
  82. assertEquals(testDescription, aDriverPropertyInfo.description);
  83. assertEquals(testName, aDriverPropertyInfo.name);
  84. aDriverPropertyInfo.choices = updateChoices;
  85. aDriverPropertyInfo.value = updateValue;
  86. aDriverPropertyInfo.required = updateRequired;
  87. aDriverPropertyInfo.description = updateDescription;
  88. aDriverPropertyInfo.name = updateName;
  89. assertTrue(Arrays.equals(updateChoices, aDriverPropertyInfo.choices));
  90. assertEquals(updateValue, aDriverPropertyInfo.value);
  91. assertEquals(updateRequired, aDriverPropertyInfo.required);
  92. assertEquals(updateDescription, aDriverPropertyInfo.description);
  93. assertEquals(updateName, aDriverPropertyInfo.name);
  94. //functional test
  95. try {
  96. Class.forName(classname).newInstance();
  97. Properties props = new Properties();
  98. Driver d = DriverManager.getDriver(connectionURL);
  99. DriverPropertyInfo[] info = d.getPropertyInfo(connectionURL,
  100. props);
  101. // get the property metadata
  102. String name = info[0].name;
  103. assertNotNull(name);
  104. assertEquals(name, "encoding");
  105. String[] choices = info[0].choices;
  106. assertNull(choices);
  107. boolean required = info[0].required;
  108. assertFalse(required);
  109. String description = info[0].description;
  110. assertNull(description);
  111. } catch (SQLException e) {
  112. System.out.println("Error in test setup: " + e.getMessage());
  113. e.printStackTrace();
  114. } catch (Exception ex) {
  115. System.err.println("Unexpected exception " + ex.toString());
  116. }
  117. } // end method testPublicFields
  118. // Default values...
  119. static String[] testChoices = null;
  120. static java.lang.String testValue = validValue;
  121. static boolean testRequired = false;
  122. static java.lang.String testDescription = null;
  123. static java.lang.String testName = validName;
  124. } // end class DriverPropertyInfoTest