use of org.apache.stanbol.enhancer.servicesapi.ContentSource in project stanbol by apache.
the class ContentReferenceTest method testUrlReference.
@Test
public void testUrlReference() throws IOException {
ContentReference ref = new UrlReference(testURL);
assertNotNull(ref);
assertEquals(ref.getReference(), testURL.toString());
ContentSource source = ref.dereference();
assertNotNull(source);
String content = IOUtils.toString(source.getStream(), "UTF-8");
assertNotNull(content);
assertEquals(TEST_RESOURCE_CONTENT, content);
//same as above, but by using ContentSource.getData() instead of
//ContentSource.getStream()
ref = new UrlReference(testURL);
assertNotNull(ref);
assertEquals(ref.getReference(), testURL.toString());
source = ref.dereference();
assertNotNull(source);
content = new String(source.getData(), "UTF-8");
assertNotNull(content);
assertEquals(TEST_RESOURCE_CONTENT, content);
//test the constructor that takes a String
ref = new UrlReference(testURL.toString());
assertNotNull(ref);
assertEquals(ref.getReference(), testURL.toString());
source = ref.dereference();
assertNotNull(source);
content = IOUtils.toString(source.getStream(), "UTF-8");
assertNotNull(content);
assertEquals(TEST_RESOURCE_CONTENT, content);
}
use of org.apache.stanbol.enhancer.servicesapi.ContentSource in project stanbol by apache.
the class ContentSourceTest method checkMediaTypeForByteArraySource.
@Test
public void checkMediaTypeForByteArraySource() throws IOException {
ContentSource source = new ByteArraySource(DATA);
assertEquals(DEFAULT_MT, source.getMediaType());
source = new ByteArraySource(DATA, null);
assertEquals(DEFAULT_MT, source.getMediaType());
source = new ByteArraySource(DATA, null, FILE_NAME, HEADERS);
assertEquals(DEFAULT_MT, source.getMediaType());
source = new ByteArraySource(DATA, MT);
assertEquals(MT, source.getMediaType());
source = new ByteArraySource(DATA, MT, FILE_NAME, HEADERS);
assertEquals(MT, source.getMediaType());
//Parameters MUST BE preserved!
source = new ByteArraySource(DATA, MT_WITH_PARAM);
assertEquals(MT_WITH_PARAM, source.getMediaType());
source = new ByteArraySource(DATA, MT_WITH_PARAM, FILE_NAME);
assertEquals(MT_WITH_PARAM, source.getMediaType());
source = new ByteArraySource(DATA, MT_WITH_PARAM, FILE_NAME, HEADERS);
assertEquals(MT_WITH_PARAM, source.getMediaType());
}
use of org.apache.stanbol.enhancer.servicesapi.ContentSource in project stanbol by apache.
the class ContentSourceTest method checkHeaders.
@Test
public void checkHeaders() throws IOException {
ContentSource source = new StreamSource(new ByteArrayInputStream(DATA), null, null, null);
assertNotNull(source.getHeaders());
assertTrue(source.getHeaders().isEmpty());
source = new StreamSource(new ByteArrayInputStream(DATA), null, null, HEADERS);
assertEquals(HEADERS, source.getHeaders());
source = new ByteArraySource(DATA, null, null, null);
assertNotNull(source.getHeaders());
assertTrue(source.getHeaders().isEmpty());
source = new ByteArraySource(DATA, null, null, HEADERS);
assertEquals(HEADERS, source.getHeaders());
}
use of org.apache.stanbol.enhancer.servicesapi.ContentSource in project stanbol by apache.
the class ContentSourceTest method checkDataFromByteArraySource.
@Test
public void checkDataFromByteArraySource() throws IOException {
ContentSource source = new ByteArraySource(DATA);
assertTrue(Arrays.equals(DATA, source.getData()));
//also check that the array is not copied
//Also checks multiple calls to getData MUST work
assertSame(DATA, source.getData());
}
use of org.apache.stanbol.enhancer.servicesapi.ContentSource in project stanbol by apache.
the class ContentSourceTest method checkMediaTypeForStreamSource.
/*
* Tests checking correct handling of parameters and default values
*/
@Test
public void checkMediaTypeForStreamSource() throws IOException {
ContentSource source = new StreamSource(new ByteArrayInputStream(DATA));
assertEquals(DEFAULT_MT, source.getMediaType());
source = new StreamSource(new ByteArrayInputStream(DATA), null);
assertEquals(DEFAULT_MT, source.getMediaType());
source = new StreamSource(new ByteArrayInputStream(DATA), null, HEADERS);
assertEquals(DEFAULT_MT, source.getMediaType());
source = new StreamSource(new ByteArrayInputStream(DATA), null, FILE_NAME, HEADERS);
assertEquals(DEFAULT_MT, source.getMediaType());
source = new StreamSource(new ByteArrayInputStream(DATA), MT);
assertEquals(MT, source.getMediaType());
source = new StreamSource(new ByteArrayInputStream(DATA), MT, HEADERS);
assertEquals(MT, source.getMediaType());
source = new StreamSource(new ByteArrayInputStream(DATA), MT, FILE_NAME, HEADERS);
assertEquals(MT, source.getMediaType());
//Parameters MUST BE preserved!
source = new StreamSource(new ByteArrayInputStream(DATA), MT_WITH_PARAM);
assertEquals(MT_WITH_PARAM, source.getMediaType());
source = new StreamSource(new ByteArrayInputStream(DATA), MT_WITH_PARAM, HEADERS);
assertEquals(MT_WITH_PARAM, source.getMediaType());
source = new StreamSource(new ByteArrayInputStream(DATA), MT_WITH_PARAM, FILE_NAME, HEADERS);
assertEquals(MT_WITH_PARAM, source.getMediaType());
}
Aggregations