Search in sources :

Example 1 with ByteArraySource

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());
}
Also used : ContentSource(org.apache.stanbol.enhancer.servicesapi.ContentSource) ByteArraySource(org.apache.stanbol.enhancer.servicesapi.impl.ByteArraySource) Test(org.junit.Test)

Example 2 with ByteArraySource

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());
}
Also used : ContentSource(org.apache.stanbol.enhancer.servicesapi.ContentSource) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamSource(org.apache.stanbol.enhancer.servicesapi.impl.StreamSource) ByteArraySource(org.apache.stanbol.enhancer.servicesapi.impl.ByteArraySource) Test(org.junit.Test)

Example 3 with ByteArraySource

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());
}
Also used : ContentSource(org.apache.stanbol.enhancer.servicesapi.ContentSource) ByteArraySource(org.apache.stanbol.enhancer.servicesapi.impl.ByteArraySource) Test(org.junit.Test)

Example 4 with ByteArraySource

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);
    }
}
Also used : ContentSource(org.apache.stanbol.enhancer.servicesapi.ContentSource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArraySource(org.apache.stanbol.enhancer.servicesapi.impl.ByteArraySource) Test(org.junit.Test)

Example 5 with ByteArraySource

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));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) LDPath(org.apache.marmotta.ldpath.LDPath) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) Literal(org.apache.clerezza.commons.rdf.Literal) ContentItemBackend(org.apache.stanbol.enhancer.ldpath.backend.ContentItemBackend) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) ByteArraySource(org.apache.stanbol.enhancer.servicesapi.impl.ByteArraySource) Test(org.junit.Test)

Aggregations

ByteArraySource (org.apache.stanbol.enhancer.servicesapi.impl.ByteArraySource)11 Test (org.junit.Test)9 ContentSource (org.apache.stanbol.enhancer.servicesapi.ContentSource)7 ByteArrayInputStream (java.io.ByteArrayInputStream)4 StreamSource (org.apache.stanbol.enhancer.servicesapi.impl.StreamSource)4 Graph (org.apache.clerezza.commons.rdf.Graph)3 IRI (org.apache.clerezza.commons.rdf.IRI)3 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)3 InputStream (java.io.InputStream)2 Triple (org.apache.clerezza.commons.rdf.Triple)2 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)2 ParsingProvider (org.apache.clerezza.rdf.core.serializedform.ParsingProvider)2 JenaParserProvider (org.apache.clerezza.rdf.jena.parser.JenaParserProvider)2 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)2 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)2 BeforeClass (org.junit.BeforeClass)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FilterInputStream (java.io.FilterInputStream)1 Charset (java.nio.charset.Charset)1