예제 #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));
  }
예제 #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));
  }
예제 #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));
  }
예제 #4
0
  @Test
  public void testConvertClobByte() throws Exception {
    testConvertClobPrepare();

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

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

    TypeHandlerUtils.convertSqlXml(sqlXml, "TIFF");

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

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

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

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

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

    TypeHandlerUtils.convertClob(clob, "TIFF");

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

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

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

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

    Assert.assertEquals(data, result);
  }
예제 #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));
  }
예제 #12
0
  @Test
  public void testCloseQuietlyOutput() throws Exception {
    Mockito.doThrow(new IOException()).when(output).close();

    try {
      TypeHandlerUtils.closeQuietly(output);
    } catch (Exception ex) {
      fail();
    }
  }
예제 #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()));
  }
예제 #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();
  }
예제 #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();
  }
예제 #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();
  }
예제 #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});
  }
예제 #18
0
 @Test
 public void testConvertJavaClassToSqlType() throws Exception {
   Assert.assertEquals("VARCHAR", TypeHandlerUtils.convertJavaClassToSqlType("String"));
 }