Skip to content

Commit

Permalink
(#28) Added position implementation for clob needle
Browse files Browse the repository at this point in the history
  • Loading branch information
svettwer committed Mar 11, 2019
1 parent 4ac4d3e commit 2b56b65
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ public long position(final String searchstr, final long start) {

@Override
public long position(final Clob searchstr, final long start) throws SQLException {
return 0;
final long clobLength = searchstr.length();
if(fitsInInt(clobLength)){
final String subString = searchstr.getSubString(1, (int)clobLength);
return position(subString, start);
}
return -1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void testPositionWithStringNeedleWithoutMatch() throws Exception{
}

@Test
public void testPositionWithLongPositionReturnsMinusOne() throws Exception{
public void testPositionWithStringNeedleAndLongPositionReturnsMinusOne() throws Exception{

//GIVEN
citrusClob.setString(1, sampleText);
Expand All @@ -141,6 +141,49 @@ public void testPositionWithLongPositionReturnsMinusOne() throws Exception{
assertEquals(position, -1);
}

@Test
public void testPositionWithClobNeedle() throws Exception{

//GIVEN
final CitrusClob needle = createClobNeedle();
citrusClob.setString(1, sampleText);


//WHEN
final long position = citrusClob.position(needle, 1);

//THEN
assertEquals(position, 10);
}

@Test
public void testPositionWithClobNeedleWithoutMatch() throws Exception{

//GIVEN
final CitrusClob needle = createClobNeedle();
citrusClob.setString(1, sampleText);

//WHEN
final long position = citrusClob.position(needle, 13);

//THEN
assertEquals(position, -1);
}

@Test
public void testPositionWithClobNeedleAndLongPositionReturnsMinusOne() throws Exception{

//GIVEN
final CitrusClob needle = createClobNeedle();
citrusClob.setString(1, sampleText);

//WHEN
final long position = citrusClob.position(needle, Long.MAX_VALUE);

//THEN
assertEquals(position, -1);
}

@Test
public void testEqualsContract(){
final StringBuilder one = new StringBuilder();
Expand All @@ -159,4 +202,10 @@ public void testEqualsContract(){
public void testToString(){
ToStringVerifier.forClass(CitrusClob.class).verify();
}

private CitrusClob createClobNeedle() {
final CitrusClob needle = new CitrusClob();
needle.setString(1, "and");
return needle;
}
}

0 comments on commit 2b56b65

Please sign in to comment.