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());
}
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);
}
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());
}
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));
}
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());
}
Aggregations