Пример #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"));
 }