Search in sources :

Example 66 with Representation

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

the class RepresentationTest method testEmptyFieldRemoveAllNaturalText.

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

Example 67 with Representation

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

the class RepresentationTest method testURIToReferenceConversion.

/**
     * Tests if {@link Reference} instances are correctly generated for {@link URI}. This test also depends on
     * the correct implementation of the {@link Reference#equals(Object)} method
     * 
     * @throws URISyntaxException
     */
@Test
public void testURIToReferenceConversion() throws URISyntaxException {
    String field = "urn:the.field:used.for.this.Test";
    URI uri = new URI("http://www.test.org/uriTest");
    ValueFactory vf = getValueFactory();
    Representation rep = createRepresentation(null);
    // test conversion
    rep.add(field, uri);
    Iterator<Reference> refs = rep.getReferences(field);
    assertTrue(refs.hasNext());
    assertEquals(refs.next().getReference(), uri.toString());
    assertFalse(refs.hasNext());
    // test multiple adds do not generate duplicate References
    rep.add(field, uri);
    assertTrue(asCollection(rep.get(field)).size() == 1);
    // test adding a equivalent reference
    rep.add(field, vf.createReference(uri.toString()));
    assertTrue(asCollection(rep.get(field)).size() == 1);
    // test removing
    rep.remove(field, uri);
    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) URI(java.net.URI) Test(org.junit.Test)

Example 68 with Representation

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

the class RepresentationTest method testRemoveAllNaturalLanguageValuesByParsingNullAsLanguageArray.

@Test
public void testRemoveAllNaturalLanguageValuesByParsingNullAsLanguageArray() {
    String field = "urn:the.field:used.for.this.Test";
    Representation rep = initNaturalLanguageTest(field);
    // add a reference to ensure that only texts (and strings) are removed
    String testReference = "http://www.test.org/test";
    rep.addReference(field, testReference);
    // test removal of all natural language values by parsing only a single argument
    rep.removeAllNaturalText(field);
    Iterator<Text> texts = rep.get(field, (String[]) null);
    assertFalse(texts.hasNext());
    // text of the added reference is still present
    assertTrue(rep.get(field).hasNext());
}
Also used : Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Text(org.apache.stanbol.entityhub.servicesapi.model.Text) Test(org.junit.Test)

Example 69 with Representation

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

the class RepresentationTest method testRemoveNaturalTextWithCorrectAndWrongLanguage.

@Test
public void testRemoveNaturalTextWithCorrectAndWrongLanguage() {
    String field = "urn:the.field:used.for.this.Test";
    Representation rep = initNaturalLanguageTest(field);
    // remove a specific text, parse one correct and one wrong lang
    rep.removeNaturalText(field, NL_TEST_en2, "de", "en");
    Set<String> textSet = new HashSet<String>(NL_TEST_all);
    // remove all remaining values
    for (Iterator<Text> texts = rep.getText(field); texts.hasNext(); textSet.remove(texts.next().getText())) ;
    // and check that the value we expect to be removed is still in the set
    assertTrue(textSet.size() == 1);
    assertTrue(textSet.contains(NL_TEST_en2));
}
Also used : Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Text(org.apache.stanbol.entityhub.servicesapi.model.Text) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 70 with Representation

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

the class RepresentationTest method testNullFieldRemoveAll.

@Test(expected = IllegalArgumentException.class)
public void testNullFieldRemoveAll() {
    Representation rep = createRepresentation(null);
    rep.removeAll(null);
}
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