/**
   * Assert that the <code>expected</code> property value is set using a given <code>url</code> and
   * <code>tdsVersion</code> property.
   *
   * @param url The JDBC URL.
   * @param tdsVersion The TDS version.
   * @param key The message key.
   * @param fieldName The field name used in the class.
   * @param expected The expected value of the property.
   */
  private void assertDefaultPropertyByTdsVersion(
      String url, String tdsVersion, String key, String fieldName, String expected) {

    Properties properties = new Properties();
    properties.setProperty(Messages.get("prop.tds"), tdsVersion);
    getTester()
        .assertDefaultProperty(
            "Default property incorrect", url, properties, fieldName, key, expected);
  }
  /**
   * Tests that the {@link DriverPropertyInfo} array returned from {@link
   * Driver#getPropertyInfo(String, Properties)} contains the correct <code>required</code> value on
   * each of the objects.
   */
  public void test_getPropertyInfo_Required() {

    Map requiredTrueMap = new HashMap();
    requiredTrueMap.put(Messages.get(Driver.SERVERNAME), Boolean.TRUE);
    requiredTrueMap.put(Messages.get(Driver.SERVERTYPE), Boolean.TRUE);

    final Map infoMap = new HashMap();
    loadDriverPropertyInfoMap(infoMap);

    final Iterator iterator = infoMap.keySet().iterator();
    while (iterator.hasNext()) {
      String key = (String) iterator.next();
      DriverPropertyInfo info = (DriverPropertyInfo) infoMap.get(key);
      if (requiredTrueMap.containsKey(key)) {
        assertTrue("The 'required' field is not true for key " + key, info.required);
      } else {
        assertFalse("The 'required' field is not false for key " + key, info.required);
      }
    }
  }
  /**
   * Returns a ConnectionProxy.
   *
   * @throws SQLException if an error occurs
   */
  public synchronized Connection getConnection() throws SQLException {
    if (connection == null) {
      fireConnectionEvent(false, new SQLException(Messages.get("error.jdbcx.conclosed"), "08003"));

      return null;
    }

    // Should the SQLException be captured here for safety in the future even though
    // no SQLException is being thrown by the ConnectionProxy at the moment???
    return new ConnectionProxy(this, connection);
  }
  /**
   * Tests that the {@link DriverPropertyInfo} array returned from {@link
   * Driver#getPropertyInfo(String, Properties)} contains the correct <code>choices</code> value on
   * each of the objects.
   */
  public void test_getPropertyInfo_Choices() {

    String[] expectedBooleanChoices =
        new String[] {
          String.valueOf(true), String.valueOf(false),
        };
    String[] expectedPrepareSqlChoices =
        new String[] {
          String.valueOf(TdsCore.UNPREPARED),
          String.valueOf(TdsCore.TEMPORARY_STORED_PROCEDURES),
          String.valueOf(TdsCore.EXECUTE_SQL),
          String.valueOf(TdsCore.PREPARE),
          String.valueOf(TdsCore.PREPEXEC),
        };
    String[] expectedServerTypeChoices =
        new String[] {
          String.valueOf(Driver.SQLSERVER), String.valueOf(Driver.SYBASE),
        };
    String[] expectedTdsChoices =
        new String[] {
          DefaultProperties.TDS_VERSION_42,
          DefaultProperties.TDS_VERSION_50,
          DefaultProperties.TDS_VERSION_70,
          DefaultProperties.TDS_VERSION_80,
        };

    Map expectedChoicesMap = new HashMap();
    expectedChoicesMap.put(Messages.get(Driver.LASTUPDATECOUNT), expectedBooleanChoices);
    expectedChoicesMap.put(Messages.get(Driver.NAMEDPIPE), expectedBooleanChoices);
    expectedChoicesMap.put(Messages.get(Driver.PREPARESQL), expectedPrepareSqlChoices);
    expectedChoicesMap.put(Messages.get(Driver.SERVERTYPE), expectedServerTypeChoices);
    expectedChoicesMap.put(Messages.get(Driver.TDS), expectedTdsChoices);
    expectedChoicesMap.put(
        Messages.get(Driver.SENDSTRINGPARAMETERSASUNICODE), expectedBooleanChoices);

    final Map infoMap = new HashMap();
    loadDriverPropertyInfoMap(infoMap);

    final Iterator iterator = infoMap.keySet().iterator();
    while (iterator.hasNext()) {
      String key = (String) iterator.next();
      DriverPropertyInfo info = (DriverPropertyInfo) infoMap.get(key);
      if (expectedChoicesMap.containsKey(key)) {
        assertEquals(
            "Choices did not match for key " + key,
            ((String[]) expectedChoicesMap.get(key)),
            info.choices);
      } else {
        assertNull("Expected choices to be null for key " + key, expectedChoicesMap.get(key));
      }
    }
  }