Search in sources :

Example 1 with UrlReference

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

Aggregations

ContentReference (org.apache.stanbol.enhancer.servicesapi.ContentReference)1 ContentSource (org.apache.stanbol.enhancer.servicesapi.ContentSource)1 UrlReference (org.apache.stanbol.enhancer.servicesapi.impl.UrlReference)1 Test (org.junit.Test)1