use of org.apache.stanbol.enhancer.servicesapi.ContentSource in project stanbol by apache.
the class ContentSourceTest method checkStreamFromStreamSource.
/*
* Tests checking correct handling of data
*/
@Test
public void checkStreamFromStreamSource() throws IOException {
ContentSource source = new StreamSource(new ByteArrayInputStream(DATA));
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(source.getStream(), out);
Assert.assertTrue(Arrays.equals(DATA, out.toByteArray()));
try {
source.getStream();
//multiple calls are supported -> is OK
} catch (RuntimeException e) {
//multiple calls are not supported -> illegal state
Assert.assertTrue(e instanceof IllegalStateException);
}
}
use of org.apache.stanbol.enhancer.servicesapi.ContentSource in project stanbol by apache.
the class ContentSourceTest method checkDataFromStreamSource.
@Test
public void checkDataFromStreamSource() throws IOException {
ContentSource source = new StreamSource(new ByteArrayInputStream(DATA));
Assert.assertTrue(Arrays.equals(DATA, source.getData()));
//multiple calls must work
source.getData();
}
use of org.apache.stanbol.enhancer.servicesapi.ContentSource in project stanbol by apache.
the class ContentSourceTest method checkFileName.
@Test
public void checkFileName() throws IOException {
ContentSource source = new StreamSource(new ByteArrayInputStream(DATA), null, null, null);
assertNull(source.getFileName());
source = new StreamSource(new ByteArrayInputStream(DATA), null, FILE_NAME, null);
assertEquals(FILE_NAME, source.getFileName());
source = new ByteArraySource(DATA, null, FILE_NAME);
assertEquals(FILE_NAME, source.getFileName());
source = new ByteArraySource(DATA, null, FILE_NAME, null);
assertEquals(FILE_NAME, source.getFileName());
}
use of org.apache.stanbol.enhancer.servicesapi.ContentSource in project stanbol by apache.
the class ContentSourceTest method checkStreamFromStringSource.
@Test
public void checkStreamFromStringSource() throws IOException {
ContentSource source = new StringSource(TEST_STRING);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(source.getStream(), out);
Assert.assertTrue(Arrays.equals(DATA, out.toByteArray()));
try {
source.getStream();
//multiple calls are supported -> is OK
} catch (RuntimeException e) {
//multiple calls are not supported -> illegal state
Assert.assertTrue(e instanceof IllegalStateException);
}
//test different encoding
Charset ISO8859_4 = Charset.forName("ISO-8859-4");
byte[] iso8859_4_data = TEST_STRING.getBytes(ISO8859_4);
source = new StringSource(TEST_STRING, ISO8859_4, null);
out = new ByteArrayOutputStream();
IOUtils.copy(source.getStream(), out);
Assert.assertTrue(Arrays.equals(iso8859_4_data, out.toByteArray()));
}
Aggregations