コード例 #1
0
  @Test
  public void getUnsignedIntegerAsLongFromResultSet() throws SQLException, IOException {
    String[] expectedNames = {"Integer", "tinyint", "smallint", "Null"};
    String[] realValues = {String.valueOf(Integer.MAX_VALUE + 200), "2", "3", null};
    String[] expectedValues = {String.valueOf(Integer.MAX_VALUE + 200), "2", "3", ""};
    int[] expectedTypes = {Types.BIGINT, Types.TINYINT, Types.SMALLINT, Types.INTEGER};

    ResultSetMetaData metaData =
        MockResultSetMetaDataBuilder.buildMetaData(expectedNames, expectedTypes);
    ResultSet resultSet = MockResultSetBuilder.buildResultSet(metaData, realValues, expectedTypes);

    ResultSetHelperService service = new ResultSetHelperService();

    String[] columnValues = service.getColumnValues(resultSet);
    assertArrayEquals(expectedValues, columnValues);
  }
コード例 #2
0
  @Test
  public void getObjectFromResultSet() throws SQLException, IOException {
    String[] expectedNames = {"object", "Null Object"};
    String[] realValues = {"foo", null};
    String[] expectedValues = {"foo", ""};
    int[] expectedTypes = {Types.JAVA_OBJECT, Types.JAVA_OBJECT};

    ResultSetMetaData metaData =
        MockResultSetMetaDataBuilder.buildMetaData(expectedNames, expectedTypes);
    ResultSet resultSet = MockResultSetBuilder.buildResultSet(metaData, realValues, expectedTypes);

    ResultSetHelperService service = new ResultSetHelperService();

    String[] columnValues = service.getColumnValues(resultSet);
    assertArrayEquals(expectedValues, columnValues);
  }
コード例 #3
0
  @Test
  public void getUnsupportedFromResultSet() throws SQLException, IOException {

    String[] expectedNames = {"Array", "Null"};
    String[] realValues = {"1", null};
    String[] expectedValues = {"", ""};
    int[] expectedTypes = {Types.ARRAY, Types.ARRAY};

    ResultSetMetaData metaData =
        MockResultSetMetaDataBuilder.buildMetaData(expectedNames, expectedTypes);
    ResultSet resultSet = MockResultSetBuilder.buildResultSet(metaData, realValues, expectedTypes);

    ResultSetHelperService service = new ResultSetHelperService();

    String[] columnValues = service.getColumnValues(resultSet);
    assertArrayEquals(expectedValues, columnValues);
  }
コード例 #4
0
  @Test
  public void getCharHandlesNulls() throws SQLException, IOException {

    String[] expectedNames = {"longvarchar", "varchar", "char", "Null"};
    String[] realValues = {"a", "b", "c", null};
    String[] expectedValues = {"a", "b", "c", ""};
    int[] expectedTypes = {Types.LONGVARCHAR, Types.VARCHAR, Types.CHAR, Types.CHAR};

    ResultSetMetaData metaData =
        MockResultSetMetaDataBuilder.buildMetaData(expectedNames, expectedTypes);
    ResultSet resultSet = MockResultSetBuilder.buildResultSet(metaData, realValues, expectedTypes);

    ResultSetHelperService service = new ResultSetHelperService();

    String[] columnValues = service.getColumnValues(resultSet, true);
    assertArrayEquals(expectedValues, columnValues);
  }
コード例 #5
0
  @Test
  public void getBooleanFromResultSet() throws SQLException, IOException {
    String[] expectedNames = {"true", "false", "TRUE", "FALSE", "Null"};
    String[] realValues = {"true", "false", "TRUE", "FALSE", null};
    String[] expectedValues = {"true", "false", "true", "false", "false"};
    int[] expectedTypes = {
      Types.BOOLEAN, Types.BOOLEAN, Types.BOOLEAN, Types.BOOLEAN, Types.BOOLEAN
    };

    ResultSetMetaData metaData =
        MockResultSetMetaDataBuilder.buildMetaData(expectedNames, expectedTypes);
    ResultSet resultSet = MockResultSetBuilder.buildResultSet(metaData, realValues, expectedTypes);

    ResultSetHelperService service = new ResultSetHelperService();

    String[] columnValues = service.getColumnValues(resultSet);
    assertArrayEquals(expectedValues, columnValues);
  }
コード例 #6
0
  @Test
  public void getLargeClobFromResultSet() throws SQLException, IOException {
    String clobString = buildClobString(ResultSetHelperService.CLOBBUFFERSIZE + 1);

    String[] expectedNames = {"Clob", "Null"};
    String[] realValues = {clobString, null};
    String[] expectedValues = {clobString, ""};
    int[] expectedTypes = {Types.CLOB, Types.CLOB};

    ResultSetMetaData metaData =
        MockResultSetMetaDataBuilder.buildMetaData(expectedNames, expectedTypes);
    ResultSet resultSet = MockResultSetBuilder.buildResultSet(metaData, realValues, expectedTypes);

    ResultSetHelperService service = new ResultSetHelperService();

    String[] columnValues = service.getColumnValues(resultSet);
    assertArrayEquals(expectedValues, columnValues);
  }
コード例 #7
0
  @Test
  public void getBigDecimalFromResultSet() throws SQLException, IOException {

    String[] expectedNames = {"Decimal", "double", "float", "real", "numeric", "Null"};
    String[] realValues = {"1.1", "2.2", "3.3", "4.4", "5.5", null};
    String[] expectedValues = {"1.1", "2.2", "3.3", "4.4", "5.5", ""};
    int[] expectedTypes = {
      Types.DECIMAL, Types.DOUBLE, Types.FLOAT, Types.REAL, Types.NUMERIC, Types.DECIMAL
    };

    ResultSetMetaData metaData =
        MockResultSetMetaDataBuilder.buildMetaData(expectedNames, expectedTypes);
    ResultSet resultSet = MockResultSetBuilder.buildResultSet(metaData, realValues, expectedTypes);

    ResultSetHelperService service = new ResultSetHelperService();

    String[] columnValues = service.getColumnValues(resultSet);
    assertArrayEquals(expectedValues, columnValues);
  }
コード例 #8
0
  @Test
  public void getTimeFromResultSet() throws SQLException, IOException {

    Time time = new Time(12, 0, 0); // noon
    long dateInMilliSeconds = time.getTime();

    String[] expectedNames = {"Time", "Null"};
    String[] realValues = {Long.toString(dateInMilliSeconds), null};
    String[] expectedValues = {time.toString(), ""};
    int[] expectedTypes = {Types.TIME, Types.TIME};

    ResultSetMetaData metaData =
        MockResultSetMetaDataBuilder.buildMetaData(expectedNames, expectedTypes);
    ResultSet resultSet = MockResultSetBuilder.buildResultSet(metaData, realValues, expectedTypes);

    ResultSetHelperService service = new ResultSetHelperService();

    String[] columnValues = service.getColumnValues(resultSet);
    assertArrayEquals(expectedValues, columnValues);
  }
コード例 #9
0
  @Test
  public void getTimestampFromResultSetWithCustomFormat() throws SQLException, IOException {
    Timestamp date = new Timestamp(109, 11, 15, 12, 0, 0, 0); // 12/15/2009 noon
    long dateInMilliSeconds = date.getTime();
    String customFormat = "mm/dd/yy HH:mm:ss";
    SimpleDateFormat timeFormat = new SimpleDateFormat(customFormat);

    String[] expectedNames = {"Timestamp", "Null"};
    String[] realValues = {Long.toString(dateInMilliSeconds), null};
    String[] expectedValues = {timeFormat.format(date), ""};
    int[] expectedTypes = {Types.TIMESTAMP, Types.TIMESTAMP};

    ResultSetMetaData metaData =
        MockResultSetMetaDataBuilder.buildMetaData(expectedNames, expectedTypes);
    ResultSet resultSet = MockResultSetBuilder.buildResultSet(metaData, realValues, expectedTypes);

    ResultSetHelperService service = new ResultSetHelperService();

    String[] columnValues = service.getColumnValues(resultSet, false, null, customFormat);
    assertArrayEquals(expectedValues, columnValues);
  }
コード例 #10
0
  @Test
  public void getDateFromResultSet() throws SQLException, IOException {

    Date date = new Date(109, 11, 15); // 12/15/2009
    long dateInMilliSeconds = date.getTime();
    SimpleDateFormat dateFormat = new SimpleDateFormat(ResultSetHelperService.DEFAULT_DATE_FORMAT);

    String[] expectedNames = {"Date", "Null"};
    String[] realValues = {Long.toString(dateInMilliSeconds), null};
    String[] expectedValues = {dateFormat.format(date), ""};
    int[] expectedTypes = {Types.DATE, Types.DATE};

    ResultSetMetaData metaData =
        MockResultSetMetaDataBuilder.buildMetaData(expectedNames, expectedTypes);
    ResultSet resultSet = MockResultSetBuilder.buildResultSet(metaData, realValues, expectedTypes);

    ResultSetHelperService service = new ResultSetHelperService();

    String[] columnValues = service.getColumnValues(resultSet);
    assertArrayEquals(expectedValues, columnValues);
  }