コード例 #1
0
  /**
   * Tests that the InputStream got from a empty Clob reflects new data in the underlying Clob.
   *
   * @throws Exception
   */
  public void testGetAsciiStreamCreateClob() throws Exception {
    // The String that will be used
    // to do the inserts into the
    // Clob.
    String str = "Hi I am the insert String";

    // Create the InputStream that will
    // be used for comparing the Stream
    // that is obtained from the Blob after
    // the update.
    ByteArrayInputStream str_is = new ByteArrayInputStream(str.getBytes("US-ASCII"));

    // create the empty Clob.
    Clob clob = getConnection().createClob();

    // Get the InputStream from this
    // Clob
    InputStream is = clob.getAsciiStream();

    // set the String into the clob.
    clob.setString(1, str);

    // Ensure that the Stream obtained from
    // the clob contains the expected bytes
    assertEquals(str_is, is);
  }
コード例 #2
0
  /**
   * Tests that the data updated in a Clob is always reflected in the InputStream got. Here the
   * updates into the Clob are done using both an OutputStream obtained from this Clob as well as
   * using Clob.setString.
   *
   * @throws Exception
   */
  public void testGetAsciiStreamClobUpdates() throws Exception {
    // The String that will be used
    // to do the inserts into the
    // Clob.
    String str1 = "Hi I am the insert string";

    // Stores the byte array representation of
    // the insert string.
    byte[] str1_bytes = str1.getBytes();

    // The String that will be used in the
    // second series of updates
    String str2 = "Hi I am the update string";

    // create the empty Clob.
    Clob clob = getConnection().createClob();

    // Get the InputStream from this
    // Clob before any writes happen.
    InputStream is_BeforeWrite = clob.getAsciiStream();

    // Get an OutputStream from this Clob
    // into which the data can be written
    OutputStream os = clob.setAsciiStream(1);
    os.write(str1_bytes);

    // Doing a setString now on the Clob
    // should reflect the same extension
    // in the InputStream also.
    clob.setString((str1_bytes.length) + 1, str2);

    // Get the input stream from the
    // Clob after the update
    InputStream is_AfterWrite = clob.getAsciiStream();

    // Now check if the two InputStreams
    // match
    assertEquals(is_BeforeWrite, is_AfterWrite);
  }
コード例 #3
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));
  }
コード例 #4
0
  /**
   * Tests the implementation for the free() method in the Clob interface.
   *
   * @throws SQLException if an error occurs during releasing the Clob resources
   */
  public void testFreeandMethodsAfterCallingFree()
      throws IllegalAccessException, InvocationTargetException, SQLException {
    clob = BlobClobTestSetup.getSampleClob(getConnection());

    // call the buildHashSetMethod to initialize the
    // HashSet with the method signatures that are exempted
    // from throwing a SQLException after free has been called
    // on the Clob object.
    buildHashSet();

    InputStream asciiStream = clob.getAsciiStream();
    Reader charStream = clob.getCharacterStream();
    clob.free();
    // testing the idempotence of the free() method
    // the method can be called multiple times on

    // the first are treated as no-ops
    clob.free();

    // to the free method so testing calling
    // a method on this invalid object should throw
    // an SQLException
    buildMethodList(clob);
  }