Search in sources :

Example 91 with Representation

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

the class RepresentationTest method testStringArrayWithNullTextConversion.

/**
     * Parsing a String Array with null as first element MUST NOT add a value (because null values are not
     * supported by {@link Representation}).
     */
@Test
public void testStringArrayWithNullTextConversion() {
    String field = "urn:the.field:used.for.this.Test";
    Representation rep = createRepresentation(null);
    rep.add(field, new String[] { null, "en" });
    assertFalse(rep.get(field).hasNext());
}
Also used : Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Example 92 with Representation

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

the class RepresentationTest method testNullFieldGetFirstReference.

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

Example 93 with Representation

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

the class ValueFactoryTest method testMultipleInstanceForSameID.

@Test
public void testMultipleInstanceForSameID() {
    Representation rep = testRepresentation("urn:testSameId");
    Representation rep1 = testRepresentation("urn:testSameId");
    // check that multiple calls with the same ID create different instances
    // -> this is very important to allow mapping of Representations (e.g.
    // when they are stored within a cache
    assertNotSame(rep, rep1);
    // if an ID is parsed, than the two instance should be equal
    assertTrue(rep.equals(rep1));
    // check the hash code
    assertTrue(rep.hashCode() == rep1.hashCode());
}
Also used : Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Example 94 with Representation

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

the class RepresentationTest method testEmptyFieldGetNaturalLanguateText.

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

Example 95 with Representation

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

the class RepresentationTest method testAddUnsupportedType.

/*--------------------------------------------------------------------------
     * Set of Tests that check if Methods correctly process UnsupportedTypes
     * This means that the toString Method is used to get the lexical
     * representation of such types
     *--------------------------------------------------------------------------
     */
/**
     * Adding an unsupported type should use the {@link Object#toString()} to store the parsed instance
     */
@Test
public void testAddUnsupportedType() {
    String field = "urn:the.field:used.for.this.Test";
    Representation rep = createRepresentation(null);
    Object value = getUnsupportedValueInstance();
    if (value == null) {
        // this test is not needed
        return;
    }
    rep.add(field, value);
    Iterator<Object> valueIterator = rep.get(field);
    assertNotNull(valueIterator);
    assertTrue(valueIterator.hasNext());
    Object repValue = valueIterator.next();
    assertEquals(value.toString(), repValue.toString());
}
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