use of org.apache.stanbol.entityhub.servicesapi.yard.Yard in project stanbol by apache.
the class LdpathPostProcessor method initialise.
@Override
public void initialise() {
//override the ldpath instance used for the initialisation with
//the one using the IndexingDestination
//this is OK, because parsing ldpath programs anyway does only need
//the "value factory" role of the RDFBackend and does not actually
//access any data.
Yard yard = indexingConfig.getIndexingDestination().getYard();
YardBackend backend = new YardBackend(yard);
this.ldPath = new EntityhubLDPath(backend, yard.getValueFactory());
}
use of org.apache.stanbol.entityhub.servicesapi.yard.Yard in project stanbol by apache.
the class YardTest method testRemoveRepresentationsWithNonStoredValue.
/**
* Tests that {@link Representation} IDs that are not stored by the yard are ignored by the multiple
* remove method
*
* @throws YardException
*/
@Test
public void testRemoveRepresentationsWithNonStoredValue() 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.testRemoveRepresentationsWithNullValue:representation.stored";
String id2 = "urn:yard.test.testRemoveRepresentationsWithNullValue:representation.notStored";
Yard yard = getYard();
// create and add
Representation test = yard.create(id);
assertTrue(yard.isRepresentation(test.getId()));
yard.remove(Arrays.asList(test.getId(), id2));
assertFalse(yard.isRepresentation(test.getId()));
assertFalse(yard.isRepresentation(id2));
}
use of org.apache.stanbol.entityhub.servicesapi.yard.Yard in project stanbol by apache.
the class YardTest method testGetRepresentation.
/**
* This tests that {@link Representation} retrieved from the Yard do not influence other
* {@link Representation} instances for the same ID. It is important, that when different
* {@link Representation} instances are returned to different caller, that these do not influence each
* other.
* <p>
* It also tests, that any update to the {@link Representation} as managed by the {@link Yard} does also
* not influence {@link Representation} instances that where created before the change.
*
* @throws YardException
*/
@Test
public void testGetRepresentation() throws YardException {
String id = "urn:yard.test.testGetRepresentation.id";
Yard yard = getYard();
String field = "urn:the.field:used.for.this.Test";
String value1 = "this is a test";
// Representations created via the yard need to be created (as empty
// representation within the yard
Representation test = create(id, true);
// retrieve the representation from the store
Representation retrieved = yard.getRepresentation(id);
assertNotNull(retrieved);
// they MUST NOT be the same, but the MUST be equals
// Note:
// the fact that two representations with the same id are equals is tested
// by the unit tests for the representation interface
assertEquals(test, retrieved);
assertNotSame("getRepresentation MUST return an new instance for each " + "call, so that changes in one return instance do not influence " + "an other returned instance!", test, retrieved);
// now add a property to the original one
test.add(field, value1);
// and check that the retrieved does not have the value
assertFalse(retrieved.get(field).hasNext());
// now store the representation and check that updated are not reflected
// within the retrieved one
yard.store(test);
assertFalse(retrieved.get(field).hasNext());
// now retrieve again an representation
retrieved = null;
retrieved = yard.getRepresentation(id);
// now the Representation MUST HAVE the new field
assertTrue(retrieved.get(field).hasNext());
assertEquals(value1, retrieved.getFirst(field));
// finally retrieve a second and perform the change test again
Representation retrieved2 = yard.getRepresentation(id);
retrieved.removeAll(field);
// check the value is still in retrieved2
assertTrue(retrieved2.get(field).hasNext());
assertEquals(value1, retrieved2.getFirst(field));
}
use of org.apache.stanbol.entityhub.servicesapi.yard.Yard in project stanbol by apache.
the class YardTest method testCreateWithExistingId.
@Test(expected = IllegalArgumentException.class)
public void testCreateWithExistingId() throws YardException {
Yard yard = getYard();
Representation test = create();
assertNotNull(test);
// throws an IllegalArgumentException
yard.create(test.getId());
}
use of org.apache.stanbol.entityhub.servicesapi.yard.Yard in project stanbol by apache.
the class YardTest method testUpdateRepresentationsWithNonPresent.
/**
* When updating multiple non present representations need to be ignored.
*
* @throws YardException
*/
@Test
public void testUpdateRepresentationsWithNonPresent() 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.testUpdateRepresentationsWithNonPresent:representation.id1";
String id2 = "urn:yard.test.testUpdateRepresentationsWithNonPresent:representation.id2";
String field = "urn:the.field:used.for.this.Test";
Representation test1 = create(id1, 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");
// create a 2nd Representation by using the ValueFactory (will not add it
// to the yard!)
Representation test2 = create(id2, false);
// now test1 is present and test2 is not.
Iterable<Representation> updated = yard.update(Arrays.asList(test1, test2));
// We expect that only test1 is updated and test2 is ignored
assertNotNull(updated);
Iterator<Representation> updatedIt = updated.iterator();
assertTrue(updatedIt.hasNext());
assertEquals(test1, updatedIt.next());
assertFalse(updatedIt.hasNext());
}
Aggregations