Search in sources :

Example 76 with Representation

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

the class RepresentationTest method testRemoveStringValuesByRemovingNaturalLanguageTextsWithNullLanguage.

/**
     * String values are treated the same as natural language values with the default (<code>null</code>)
     * language. <br>
     * Removing a natural language value with parsing null as language MUST therefore also remove a string
     * value with the parse same text.
     */
@Test
public void testRemoveStringValuesByRemovingNaturalLanguageTextsWithNullLanguage() {
    String field = "urn:the.field:used.for.this.Test";
    Representation rep = initNaturalLanguageTest(field);
    Set<String> textSet = new HashSet<String>(NL_TEST_all);
    // remove a string value by parsing the text and null as language
    rep.removeNaturalText(field, NL_TEST_string, (String) null);
    for (Iterator<Text> texts = rep.getText(field); texts.hasNext(); textSet.remove(texts.next().getText())) ;
    // only one element should be removed
    assertTrue(textSet.size() == 1);
    // and this should be the stringTest
    assertTrue(textSet.remove(NL_TEST_string));
}
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 77 with Representation

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

the class RepresentationTest method testGetFirstValueWithUnsupportedType.

@Test(expected = UnsupportedTypeException.class)
public void testGetFirstValueWithUnsupportedType() {
    String field = "urn:the.field:used.for.this.Test";
    Representation rep = createRepresentation(null);
    Object value = getUnsupportedValueInstance();
    if (value == null) {
        // this test is not needed therefore return an dummy Exception
        throw new UnsupportedTypeException(Object.class, "dummy exception to successfully complete this unnecessary test");
    } else {
        Class<?> unsupported = value.getClass();
        rep.getFirst(field, unsupported);
    }
}
Also used : UnsupportedTypeException(org.apache.stanbol.entityhub.servicesapi.model.UnsupportedTypeException) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Example 78 with Representation

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

the class RepresentationTest method testNullFieldAddNaturalText.

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

Example 79 with Representation

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

the class RepresentationTest method testRemoveStringValuesByRemovingNaturalLanguageTextsWithEmptyLanguageArray.

/**
     * String values are treated the same as natural language values with the default (<code>null</code>)
     * language. <br>
     * Removing a natural language value with an empty language array MUST be interpreted as default language
     * and therefore remove the String value.
     */
@Test
public void testRemoveStringValuesByRemovingNaturalLanguageTextsWithEmptyLanguageArray() {
    String field = "urn:the.field:used.for.this.Test";
    Representation rep = initNaturalLanguageTest(field);
    Set<String> textSet = new HashSet<String>(NL_TEST_all);
    // remove a string value by parsing an empty list of languages
    rep.removeNaturalText(field, NL_TEST_string);
    textSet.addAll(Arrays.asList(NL_TEST_string, NL_TEST_noLang, NL_TEST_en, NL_TEST_en2, NL_TEST_de, NL_TEST_de_AT));
    for (Iterator<Text> texts = rep.getText(field); texts.hasNext(); textSet.remove(texts.next().getText())) ;
    // only one element should be removed
    assertTrue(textSet.size() == 1);
    // and this should be the stringTest
    assertTrue(textSet.remove(NL_TEST_string));
    // re add the value for further tests
    rep.add(field, NL_TEST_string);
}
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 80 with Representation

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

the class RepresentationTest method testNullFieldRemove.

@Test(expected = IllegalArgumentException.class)
public void testNullFieldRemove() {
    Representation rep = createRepresentation(null);
    rep.remove(null, "test");
}
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