Search in sources :

Example 81 with Representation

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

the class RepresentationTest method testEmptyFieldAdd.

/*--------------------------------------------------------------------------
     * Set of Tests that check if all Methods correctly throw a IllegalArgumentExceptions
     * when parsing an empty string as field
     *  - important to prevent "" fields within the Entityhub
     *--------------------------------------------------------------------------
     */
@Test(expected = IllegalArgumentException.class)
public void testEmptyFieldAdd() {
    Representation rep = createRepresentation(null);
    rep.add("", "test");
}
Also used : Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Example 82 with Representation

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

the class RepresentationTest method testNullFieldAddReference.

@Test(expected = IllegalArgumentException.class)
public void testNullFieldAddReference() {
    Representation rep = createRepresentation(null);
    rep.addReference(null, "urn:test");
}
Also used : Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Example 83 with Representation

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

the class RepresentationTest method testEmptyFieldGetFirstReference.

@Test(expected = IllegalArgumentException.class)
public void testEmptyFieldGetFirstReference() {
    Representation rep = createRepresentation(null);
    rep.getFirstReference("");
}
Also used : Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Example 84 with Representation

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

the class RepresentationTest method testMultipleAddAndRemove.

@Test
public void testMultipleAddAndRemove() throws MalformedURLException, URISyntaxException {
    String field = "urn:the.field:used.for.this.Test";
    ValueFactory vf = getValueFactory();
    Representation rep = createRepresentation(null);
    Reference ref = vf.createReference("http://www.test.org/test");
    Text text = vf.createText("test", "en");
    Integer i = 42;
    Double d = Math.PI;
    URI uri = new URI("http://www.test.org/uriTest");
    URL url = new URL("http://www.test.org/urlTest");
    String[] textAsArray = new String[] { "Test text as Array", "en" };
    Collection<Object> values = Arrays.asList(ref, text, i, d);
    Collection<Object> convertedValues = Arrays.asList((Object) url, uri, textAsArray);
    Collection<Object> allValues = Arrays.asList(ref, text, i, d, uri, url, textAsArray);
    // test adding of collections
    rep.add(field, values);
    assertTrue(asCollection(rep.get(field)).size() == 4);
    rep.remove(field, values);
    assertFalse(rep.get(field).hasNext());
    // test adding of Iterators
    rep.add(field, values.iterator());
    assertTrue(asCollection(rep.get(field)).size() == 4);
    rep.remove(field, values.iterator());
    assertFalse(rep.get(field).hasNext());
    // test adding of Enumerations
    Vector<Object> v = new Vector<Object>(values);
    rep.add(field, v.elements());
    assertTrue(asCollection(rep.get(field)).size() == 4);
    rep.remove(field, v.elements());
    assertFalse(rep.get(field).hasNext());
    // test adding and removing elements that need to be converted
    // only for collections this time -> want to test only converting is
    // applied for both add and remove
    rep.add(field, convertedValues);
    assertTrue(asCollection(rep.get(field)).size() == 3);
    rep.remove(field, convertedValues);
    assertFalse(rep.get(field).hasNext());
    // a final test to ensure, that remove does not only delete all values
    rep.add(field, allValues);
    assertTrue(asCollection(rep.get(field)).size() == 7);
    rep.remove(field, convertedValues);
    assertTrue(asCollection(rep.get(field)).size() == 4);
}
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) ValueFactory(org.apache.stanbol.entityhub.servicesapi.model.ValueFactory) URI(java.net.URI) URL(java.net.URL) Vector(java.util.Vector) Test(org.junit.Test)

Example 85 with Representation

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

the class RepresentationTest method testRemoveNaturalTextWithWrongNullLanguage.

@Test
public void testRemoveNaturalTextWithWrongNullLanguage() {
    String field = "urn:the.field:used.for.this.Test";
    Representation rep = initNaturalLanguageTest(field);
    // remove a specific text, but with wrong null language -> also no effect
    rep.removeNaturalText(field, NL_TEST_de, (String) null);
    assertTrue(asCollection(rep.get(field)).size() == NL_TEST_all.size());
}
Also used : Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Aggregations

Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)198 Test (org.junit.Test)117 Text (org.apache.stanbol.entityhub.servicesapi.model.Text)32 HashSet (java.util.HashSet)31 Yard (org.apache.stanbol.entityhub.servicesapi.yard.Yard)25 Entity (org.apache.stanbol.entityhub.servicesapi.model.Entity)16 YardException (org.apache.stanbol.entityhub.servicesapi.yard.YardException)15 ValueFactory (org.apache.stanbol.entityhub.servicesapi.model.ValueFactory)14 Reference (org.apache.stanbol.entityhub.servicesapi.model.Reference)12 FieldQuery (org.apache.stanbol.entityhub.servicesapi.query.FieldQuery)12 ArrayList (java.util.ArrayList)11 RdfRepresentation (org.apache.stanbol.entityhub.model.sesame.RdfRepresentation)10 IOException (java.io.IOException)9 IRI (org.apache.clerezza.commons.rdf.IRI)9 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)8 Graph (org.apache.clerezza.commons.rdf.Graph)8 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)8 RdfRepresentation (org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation)8 RdfValueFactory (org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory)8 EntityhubException (org.apache.stanbol.entityhub.servicesapi.EntityhubException)8