Example #1
0
  @Test
  public void testIsJDBC3() {
    Overrider overrider = new Overrider();

    Assert.assertEquals(false, TypeHandlerUtils.isJDBC3(overrider));

    overrider.override(MjdbcConstants.OVERRIDE_INT_JDBC3, true);
    Assert.assertEquals(true, TypeHandlerUtils.isJDBC3(overrider));

    overrider.override(MjdbcConstants.OVERRIDE_INT_JDBC3, false);
    Assert.assertEquals(false, TypeHandlerUtils.isJDBC3(overrider));
  }
Example #2
0
  private void testReadClob(boolean close) throws Exception {
    byte[] result = null;
    String data = "ZIP";

    when(clob.getAsciiStream()).thenReturn(new ByteArrayInputStream(data.getBytes()));

    if (close == true) {
      result = TypeHandlerUtils.readClob(clob);
    } else {
      result = TypeHandlerUtils.readClob(clob, false);
    }

    Assert.assertEquals(data, new String(result));
  }
Example #3
0
  private void testReadSqlXml(boolean close) throws Exception {
    byte[] result = null;
    String data = "tar.gz";

    // when(sqlXml.getBinaryStream()).thenReturn(new ByteArrayInputStream(data.getBytes()));
    when(MappingUtils.invokeFunction(sqlXml, "getBinaryStream", new Class[] {}, new Object[] {}))
        .thenReturn(new ByteArrayInputStream(data.getBytes()));

    if (close == true) {
      result = TypeHandlerUtils.readSqlXml(sqlXml);
    } else {
      result = TypeHandlerUtils.readSqlXml(sqlXml, false);
    }

    Assert.assertEquals(data, new String(result));
  }
Example #4
0
  @Test
  public void testConvertClobByte() throws Exception {
    testConvertClobPrepare();

    TypeHandlerUtils.convertClob(clob, "JPEG".getBytes());

    testConvertClobCheck();
  }
Example #5
0
  @Test
  public void testConvertSqlXmlString() throws Exception {
    testConvertSqlXmlPrepare();

    TypeHandlerUtils.convertSqlXml(sqlXml, "TIFF");

    testConvertSqlXmlCheck();
  }
Example #6
0
  @Test
  public void testConvertSqlXmlInputStream() throws Exception {
    testConvertSqlXmlPrepare();

    TypeHandlerUtils.convertSqlXml(sqlXml, new ByteArrayInputStream("PNG".getBytes()));

    testConvertSqlXmlCheck();
  }
Example #7
0
  @Test
  public void testConvertSqlXmlByte() throws Exception {
    testConvertSqlXmlPrepare();

    TypeHandlerUtils.convertSqlXml(sqlXml, "JPEG".getBytes());

    testConvertSqlXmlCheck();
  }
Example #8
0
  @Test
  public void testConvertClobString() throws Exception {
    testConvertClobPrepare();

    TypeHandlerUtils.convertClob(clob, "TIFF");

    testConvertClobCheck();
  }
Example #9
0
  @Test
  public void testConvertClobInputStream() throws Exception {
    testConvertClobPrepare();

    TypeHandlerUtils.convertClob(clob, new ByteArrayInputStream("PNG".getBytes()));

    testConvertClobCheck();
  }
Example #10
0
  @Test
  public void testToString() throws Exception {
    String data = "tar.gz";
    String result = "";

    result = TypeHandlerUtils.toString(new StringReader(data));

    Assert.assertEquals(data, result);
  }
Example #11
0
  @Test
  public void testToByteArray() throws Exception {
    String data = "ace";
    byte[] result = null;

    result = TypeHandlerUtils.toByteArray(new ByteArrayInputStream(data.getBytes()));

    Assert.assertEquals(data, new String(result));
  }
Example #12
0
  @Test
  public void testCloseQuietlyOutput() throws Exception {
    Mockito.doThrow(new IOException()).when(output).close();

    try {
      TypeHandlerUtils.closeQuietly(output);
    } catch (Exception ex) {
      fail();
    }
  }
Example #13
0
  @Test
  public void testCopy() throws Exception {
    String data = "rar";
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    InputStream inputStream = new ByteArrayInputStream(data.getBytes());

    TypeHandlerUtils.copy(inputStream, outputStream);

    Assert.assertEquals(data, new String(outputStream.toByteArray()));
  }
Example #14
0
  @Test
  public void testConvertSqlXmlConnString() throws Exception {
    testConvertSqlXmlPrepare();

    TypeHandlerUtils.convertSqlXml(conn, "PCX");

    // verify(conn, times(1)).createSQLXML();
    MappingUtils.invokeFunction(
        verify(conn, times(1)), "createSQLXML", new Class[] {}, new Object[] {});
    testConvertSqlXmlCheck();
  }
Example #15
0
  @Test
  public void testConvertBlobConnInputStream() throws Exception {
    testConvertBlobPrepare();

    TypeHandlerUtils.convertBlob(conn, new ByteArrayInputStream("BMP".getBytes()));

    // verify(conn, times(1)).createBlob();
    MappingUtils.invokeFunction(
        verify(conn, times(1)), "createBlob", new Class[] {}, new Object[] {});
    testConvertBlobCheck();
  }
Example #16
0
  @Test
  public void testConvertClobConnByte() throws Exception {
    testConvertClobPrepare();

    TypeHandlerUtils.convertClob(conn, "GIF".getBytes());

    // verify(conn, times(1)).createClob();
    MappingUtils.invokeFunction(
        verify(conn, times(1)), "createClob", new Class[] {}, new Object[] {});
    testConvertClobCheck();
  }
Example #17
0
  @Test
  public void testConvertArrayCollection() throws Exception {
    Object[] array = new String[] {"Venus"};

    TypeHandlerUtils.convertArray(conn, Arrays.asList(array));

    // verify(conn, times(1)).createArrayOf("VARCHAR", array);
    MappingUtils.invokeFunction(
        verify(conn, times(1)),
        "createArrayOf",
        new Class[] {String.class, Object[].class},
        new Object[] {"VARCHAR", array});
  }
Example #18
0
 @Test
 public void testConvertJavaClassToSqlType() throws Exception {
   Assert.assertEquals("VARCHAR", TypeHandlerUtils.convertJavaClassToSqlType("String"));
 }