Search in sources :

Example 26 with Reference

use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.

the class RepresentationTest method testNonExistingFields.

/**
     * Tests if value iterators for non existing fields return an Iterator with no elements (Here it is
     * important, that in such cases methods do not return <code>null</code>).
     */
@Test
public void testNonExistingFields() {
    String field = "urn:this.field:does.not:exist";
    // Iterators MUST NOT be NULL but MUST NOT contain any element
    Representation rep = createRepresentation(null);
    Iterator<String> fieldIt = rep.getFieldNames();
    assertNotNull(fieldIt);
    assertFalse(fieldIt.hasNext());
    Iterator<Object> valueIt = rep.get(field);
    assertNotNull(valueIt);
    assertFalse(valueIt.hasNext());
    Iterator<Reference> refIt = rep.getReferences(field);
    assertNotNull(refIt);
    assertFalse(refIt.hasNext());
    Iterator<Text> textIt = rep.get(field, (String[]) null);
    assertNotNull(textIt);
    assertFalse(textIt.hasNext());
}
Also used : Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Text(org.apache.stanbol.entityhub.servicesapi.model.Text) Test(org.junit.Test)

Example 27 with Reference

use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.

the class RepresentationTest method testReferences.

@Test
public void testReferences() {
    String field = "urn:the.field:used.for.this.Test";
    Set<String> refs = new HashSet<String>(Arrays.asList("http://www.test.org/test1", "urn:test.org:test.1"));
    Representation rep = createRepresentation(null);
    for (String ref : refs) {
        rep.addReference(field, ref);
    }
    Iterator<Reference> refIterator = rep.getReferences(field);
    assertNotNull(refIterator);
    while (refIterator.hasNext()) {
        Reference ref = refIterator.next();
        assertTrue(refs.remove(ref.getReference()));
    }
    assertTrue(refs.isEmpty());
}
Also used : Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 28 with Reference

use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.

the class RepresentationTest method testURLToReferenceConversion.

/**
     * Tests if {@link Reference} instances are correctly generated for {@link URL}. This test also depends on
     * the correct implementation of the {@link Reference#equals(Object)} method
     * 
     * @throws MalformedURLException
     */
@Test
public void testURLToReferenceConversion() throws MalformedURLException {
    String field = "urn:the.field:used.for.this.Test";
    URL url = new URL("http://www.test.org/urlTest");
    ValueFactory vf = getValueFactory();
    Representation rep = createRepresentation(null);
    // test empty reference
    Iterator<Reference> refs = rep.getReferences(field);
    assertFalse(refs.hasNext());
    // test conversion
    rep.add(field, url);
    refs = rep.getReferences(field);
    assertTrue(refs.hasNext());
    assertEquals(refs.next().getReference(), url.toString());
    assertFalse(refs.hasNext());
    // test multiple adds do not generate duplicate References
    rep.add(field, url);
    assertTrue(asCollection(rep.get(field)).size() == 1);
    // test adding a equivalent reference
    rep.add(field, vf.createReference(url.toString()));
    assertTrue(asCollection(rep.get(field)).size() == 1);
    // test removing
    rep.remove(field, url);
    assertFalse(rep.get(field).hasNext());
}
Also used : Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) ValueFactory(org.apache.stanbol.entityhub.servicesapi.model.ValueFactory) URL(java.net.URL) Test(org.junit.Test)

Example 29 with Reference

use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.

the class ClerezzaYardTest method testRemovalOfTypeRepresentationStatement.

/**
     * The Clerezza Yard uses the Statement<br>
     * <code>representationId -> rdf:type -> Representation</code><br>
     * to identify that an IRI in the RDF graph (Graph) represents a
     * Representation. This Triple is added when a Representation is stored and
     * removed if retrieved from the Yard.<p>
     * This tests if this functions as expected
     * @throws YardException
     */
@Test
public void testRemovalOfTypeRepresentationStatement() throws YardException {
    Yard yard = getYard();
    ValueFactory vf = yard.getValueFactory();
    Reference representationType = vf.createReference(RdfResourceEnum.Representation.getUri());
    Representation test = create();
    //the rdf:type Representation MUST NOT be within the Representation
    Assert.assertFalse(test.get(RDF.type.getUnicodeString()).hasNext());
    //now add the statement and see if an IllegalStateException is thrown
    /*
         * The triple within this Statement is internally used to "mark" the
         * URI of the Representation as 
         */
    test.add(RDF.type.getUnicodeString(), representationType);
}
Also used : Yard(org.apache.stanbol.entityhub.servicesapi.yard.Yard) Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) ValueFactory(org.apache.stanbol.entityhub.servicesapi.model.ValueFactory) Test(org.junit.Test) YardTest(org.apache.stanbol.entityhub.test.yard.YardTest)

Example 30 with Reference

use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.

the class SesameYardTest method testRemovalOfTypeRepresentationStatement.

/**
     * The Clerezza Yard uses the Statement<br>
     * <code>representationId -> rdf:type -> Representation</code><br>
     * to identify that an UriRef in the RDF graph (MGraph) represents a
     * Representation. This Triple is added when a Representation is stored and
     * removed if retrieved from the Yard.<p>
     * This tests if this functions as expected
     * @throws YardException
     */
@Test
public void testRemovalOfTypeRepresentationStatement() throws YardException {
    Yard yard = getYard();
    ValueFactory vf = yard.getValueFactory();
    Reference representationType = vf.createReference(RdfResourceEnum.Representation.getUri());
    Representation test = create();
    //the rdf:type Representation MUST NOT be within the Representation
    Assert.assertFalse(test.get(NamespaceEnum.rdf + "type").hasNext());
    //now add the statement and see if an IllegalStateException is thrown
    /*
         * The triple within this Statement is internally used to "mark" the
         * URI of the Representation as 
         */
    test.add(NamespaceEnum.rdf + "type", representationType);
}
Also used : SesameYard(org.apache.stanbol.entityhub.yard.sesame.SesameYard) Yard(org.apache.stanbol.entityhub.servicesapi.yard.Yard) Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) RdfRepresentation(org.apache.stanbol.entityhub.model.sesame.RdfRepresentation) ValueFactory(org.apache.stanbol.entityhub.servicesapi.model.ValueFactory) Test(org.junit.Test) YardTest(org.apache.stanbol.entityhub.test.yard.YardTest)

Aggregations

Reference (org.apache.stanbol.entityhub.servicesapi.model.Reference)30 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)12 Text (org.apache.stanbol.entityhub.servicesapi.model.Text)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)7 ValueFactory (org.apache.stanbol.entityhub.servicesapi.model.ValueFactory)7 IRI (org.apache.clerezza.commons.rdf.IRI)5 URI (java.net.URI)4 URL (java.net.URL)3 URI (org.openrdf.model.URI)3 HashSet (java.util.HashSet)2 Language (org.apache.clerezza.commons.rdf.Language)2 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)2 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)2 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)2 Yard (org.apache.stanbol.entityhub.servicesapi.yard.Yard)2 YardTest (org.apache.stanbol.entityhub.test.yard.YardTest)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 Value (org.openrdf.model.Value)2 Date (java.util.Date)1