OracleSerialClobNormaliser implements TypeTransformer { @Override public Object transform(Object o) throws SQLException { if (o == null) return null; if (!(o instanceof oracle.jdbc.rowset.OracleSerialClob)) { throw new UnsupportedOperationException( "OracleSerialClobNormaliser cannot work with " + o.getClass()); } oracle.jdbc.rowset.OracleSerialClob clob = (oracle.jdbc.rowset.OracleSerialClob) o; if (clob.length() > MAX_CLOB_LENGTH) throw new UnsupportedOperationException("Clobs larger than " + MAX_CLOB_LENGTH + " bytes are not supported by DBFIT"); return clob.getSubString(1, (int)clob.length()); }  @Override Object transform(Object o);  }
@Test public void shouldReturnNullIfGivenNull() throws SQLException { assertNull(new OracleSerialClobNormaliser().transform(null)); }
@Test public void shouldThrowCorrectExceptionIfNotGivenAnOracleSerialClob() throws SQLException { expectedEx.expect(UnsupportedOperationException.class); expectedEx.expectMessage("OracleSerialClobNormaliser cannot work with class java.lang.String"); new OracleSerialClobNormaliser().transform("Any Old Object"); }
@Test public void shouldThrowCorrectExceptionIfClobIsLargerThanMaximum() throws SQLException { OracleSerialClob clob = mock(OracleSerialClob.class); when(clob.length()).thenReturn(10001l); expectedEx.expect(UnsupportedOperationException.class); expectedEx.expectMessage("Clobs larger than 10000 bytes are not supported by DBFIT"); new OracleSerialClobNormaliser().transform(clob); }
@Test public void shouldReturnContentsOfClobIFAllOkay() throws SQLException { OracleSerialClob clob = mock(OracleSerialClob.class); when(clob.length()).thenReturn(Long.valueOf("CLOB contents".length())); when(clob.getSubString(1l, "CLOB contents".length())).thenReturn("CLOB contents"); assertEquals("CLOB contents", new OracleSerialClobNormaliser().transform(clob)); }