Search in sources :

Example 61 with Representation

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

the class YardTest method testUpdateRepresentations.

@Test
public void testUpdateRepresentations() throws YardException {
    // NOTE: this does not test if the updated view of the representation is
    // stored, but only that the update method works correctly
    Yard yard = getYard();
    String id1 = "urn:yard.test.testUpdateRepresentations:representation.id1";
    String id2 = "urn:yard.test.testUpdateRepresentations:representation.id2";
    String field = "urn:the.field:used.for.this.Test";
    Representation test1 = create(id1, true);
    Representation test2 = create(id2, true);
    // change the representations to be sure to force an update even if the
    // implementation checks for changes before updating a representation
    test1.add(field, "test value 1");
    test2.add(field, "test value 2");
    Iterable<Representation> updatedIterable = yard.update(Arrays.asList(test1, test2));
    assertNotNull(updatedIterable);
    Collection<Representation> updated = asCollection(updatedIterable.iterator());
    // test that both the parsed Representations where stored (updated & created)
    assertTrue(updated.remove(test1));
    assertTrue(updated.remove(test2));
    assertTrue(updated.isEmpty());
}
Also used : Yard(org.apache.stanbol.entityhub.servicesapi.yard.Yard) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Example 62 with Representation

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

the class YardTest method testUpdateRepresentationWithNonPresent.

@Test(expected = IllegalArgumentException.class)
public void testUpdateRepresentationWithNonPresent() throws YardException {
    String id = "urn:yard.test.testUpdateRepresentationWithNonPresent:representation.id";
    Representation test = create(id, false);
    // throws an Exception because test is not part of the yard
    getYard().update(test);
}
Also used : Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Example 63 with Representation

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

the class YardTest method testStoreRepresentationsWithNullElement.

@Test
public void testStoreRepresentationsWithNullElement() throws YardException {
    String testId = "urn:yard.test.testStoreRepresentationsWithNullElement:representation.id";
    Yard yard = getYard();
    Representation test = create(testId, false);
    Iterable<Representation> added = yard.store(Arrays.asList(test, null));
    // now test that only the valid representation was added and the null
    // value was ignored
    assertNotNull(added);
    Iterator<Representation> addedIt = added.iterator();
    assertTrue(addedIt.hasNext());
    assertEquals(test, addedIt.next());
    assertFalse(addedIt.hasNext());
}
Also used : Yard(org.apache.stanbol.entityhub.servicesapi.yard.Yard) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Example 64 with Representation

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

the class YardTest method testRemoveRepresentation.

/**
     * Tests two things:
     * <ol>
     * <li>if representations are removed form the yard
     * <li>if the representation instance is still valid after it is removed
     * </ol>
     * The second is very important, because Representations might still be used by other components after
     * they are remove from the store they where created in
     * 
     * @throws YardException
     */
@Test
public void testRemoveRepresentation() throws YardException {
    // NOTE: This test needs not to use the create(..) method, because we
    // remove the created representation form the store anyway as part of the
    // test
    String id = "urn:yard.test.tesrRemoveRepresentation:representation.id";
    String field = "urn:the.field:used.for.this.Test";
    String testValue = "This is a test";
    Yard yard = getYard();
    Representation test = yard.getValueFactory().createRepresentation(id);
    test.add(field, testValue);
    // store the representation
    yard.store(test);
    // test if stored
    assertTrue(yard.isRepresentation(test.getId()));
    // free the initial
    test = null;
    // create the instance form the store to test (2)
    test = yard.getRepresentation(id);
    // only to be sure ...
    assertEquals(id, test.getId());
    // test (1) - the remove
    yard.remove(test.getId());
    // test if removed
    assertFalse(yard.isRepresentation(test.getId()));
    // test if the test object is not destroyed by removing the representation
    // it represents form the store (2)
    assertEquals(testValue, test.getFirst(field));
}
Also used : Yard(org.apache.stanbol.entityhub.servicesapi.yard.Yard) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Example 65 with Representation

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

the class RepresentationTest method testGetNaturalTextWithAnyLanguageByParsingAnEmptyArray.

@Test
public void testGetNaturalTextWithAnyLanguageByParsingAnEmptyArray() {
    String field = "urn:the.field:used.for.this.Test";
    Representation rep = initNaturalLanguageTest(field);
    // test Iterator for any language (by parsing an empty list)
    Iterator<Text> allTexts = rep.get(field, new String[] {});
    assertNotNull(allTexts);
    assertTrue(asCollection(allTexts).size() == NL_TEST_all.size());
}
Also used : Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Text(org.apache.stanbol.entityhub.servicesapi.model.Text) 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