use of org.apache.stanbol.enhancer.servicesapi.impl.ByteArraySource 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.impl.ByteArraySource 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.impl.ByteArraySource 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.impl.ByteArraySource in project stanbol by apache.
the class ContentSourceTest method checkStreamFromByteArraySource.
@Test
public void checkStreamFromByteArraySource() throws IOException {
ContentSource source = new ByteArraySource(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.impl.ByteArraySource in project stanbol by apache.
the class ContentItemBackendTest method testContentWithAdditionalMetadata.
@Test
public void testContentWithAdditionalMetadata() throws IOException, LDPathParseException {
byte[] content = "text content".getBytes();
IRI uri = ContentItemHelper.makeDefaultUrn(content);
ContentItem contentItem = ciFactory.createContentItem(uri, new ByteArraySource(content, "text/plain; charset=UTF-8"));
Graph tc = new SimpleGraph();
Literal literal = LiteralFactory.getInstance().createTypedLiteral("Michael Jackson");
IRI subject = new IRI("dummyUri");
tc.add(new TripleImpl(subject, new IRI("http://xmlns.com/foaf/0.1/givenName"), literal));
contentItem.addPart(new IRI(uri.getUnicodeString() + "_additionalMetadata"), tc);
ContentItemBackend ciBackend = new ContentItemBackend(contentItem, true);
LDPath<RDFTerm> ldPath = new LDPath<RDFTerm>(ciBackend, EnhancerLDPath.getConfig());
Collection<RDFTerm> result = ldPath.pathQuery(subject, "foaf:givenName", null);
assertTrue("Additional metadata cannot be found", result.contains(literal));
}
Aggregations