From 1096e91fbc6ce62de29111fdb0a86702af554777 Mon Sep 17 00:00:00 2001 From: Sven Hettwer Date: Mon, 11 Mar 2019 10:23:47 +0100 Subject: [PATCH] (citrusframework/citrus-db#28) Added getAsciiStream implementation --- .../consol/citrus/db/driver/data/CitrusClob.java | 13 +++++++------ .../citrus/db/driver/data/CitrusClobTest.java | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/driver/src/main/java/com/consol/citrus/db/driver/data/CitrusClob.java b/driver/src/main/java/com/consol/citrus/db/driver/data/CitrusClob.java index 0c69d07..89b654d 100644 --- a/driver/src/main/java/com/consol/citrus/db/driver/data/CitrusClob.java +++ b/driver/src/main/java/com/consol/citrus/db/driver/data/CitrusClob.java @@ -1,5 +1,6 @@ package com.consol.citrus.db.driver.data; +import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; @@ -37,18 +38,14 @@ public String getSubString(final long pos, final int length) { return null; } - private long applyOffset(long pos) { - return pos - 1; - } - @Override public Reader getCharacterStream() { return new StringReader(stringBuilder.toString()); } @Override - public InputStream getAsciiStream() throws SQLException { - return null; + public InputStream getAsciiStream() { + return new ByteArrayInputStream(stringBuilder.toString().getBytes()); } @Override @@ -126,4 +123,8 @@ public final int hashCode() { private boolean fitsInInt(final long value) { return (int)value == value; } + + private long applyOffset(final long pos) { + return pos - 1; + } } diff --git a/driver/src/test/java/com/consol/citrus/db/driver/data/CitrusClobTest.java b/driver/src/test/java/com/consol/citrus/db/driver/data/CitrusClobTest.java index 5d83976..4d6b8a6 100644 --- a/driver/src/test/java/com/consol/citrus/db/driver/data/CitrusClobTest.java +++ b/driver/src/test/java/com/consol/citrus/db/driver/data/CitrusClobTest.java @@ -6,6 +6,8 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import java.io.InputStream; +import java.nio.charset.Charset; import java.sql.Clob; import java.sql.SQLException; @@ -86,6 +88,20 @@ public void testSubStringWithLongPositionReturnsNull() throws SQLException { assertNull(subString); } + @Test + public void testGetAsciiStream() throws Exception{ + + //GIVEN + citrusClob.setString(1, sampleText); + + //WHEN + final InputStream asciiStream = citrusClob.getAsciiStream(); + + //THEN + final String clob = IOUtils.toString(asciiStream, Charset.forName("UTF8")); + assertEquals(clob, sampleText); + } + @Test public void testEqualsContract(){ final StringBuilder one = new StringBuilder();