Search in sources :

Example 16 with Yard

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());
}
Also used : YardBackend(org.apache.stanbol.entityhub.ldpath.backend.YardBackend) Yard(org.apache.stanbol.entityhub.servicesapi.yard.Yard) EntityhubLDPath(org.apache.stanbol.entityhub.ldpath.EntityhubLDPath)

Example 17 with Yard

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));
}
Also used : Yard(org.apache.stanbol.entityhub.servicesapi.yard.Yard) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Example 18 with Yard

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));
}
Also used : Yard(org.apache.stanbol.entityhub.servicesapi.yard.Yard) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Example 19 with Yard

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());
}
Also used : Yard(org.apache.stanbol.entityhub.servicesapi.yard.Yard) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Example 20 with Yard

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());
}
Also used : Yard(org.apache.stanbol.entityhub.servicesapi.yard.Yard) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) Test(org.junit.Test)

Aggregations

Yard (org.apache.stanbol.entityhub.servicesapi.yard.Yard)30 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)25 Test (org.junit.Test)23 YardTest (org.apache.stanbol.entityhub.test.yard.YardTest)6 SolrYard (org.apache.stanbol.entityhub.yard.solr.impl.SolrYard)4 Activate (org.apache.felix.scr.annotations.Activate)3 ValueFactory (org.apache.stanbol.entityhub.servicesapi.model.ValueFactory)3 ServiceReference (org.osgi.framework.ServiceReference)3 ConfigurationException (org.osgi.service.cm.ConfigurationException)3 ServiceTracker (org.osgi.util.tracker.ServiceTracker)3 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)3 RdfRepresentation (org.apache.stanbol.entityhub.model.sesame.RdfRepresentation)2 Reference (org.apache.stanbol.entityhub.servicesapi.model.Reference)2 FieldQuery (org.apache.stanbol.entityhub.servicesapi.query.FieldQuery)2 TextConstraint (org.apache.stanbol.entityhub.servicesapi.query.TextConstraint)2 ManagedSiteException (org.apache.stanbol.entityhub.servicesapi.site.ManagedSiteException)2 YardException (org.apache.stanbol.entityhub.servicesapi.yard.YardException)2 SesameYard (org.apache.stanbol.entityhub.yard.sesame.SesameYard)2 Filter (org.osgi.framework.Filter)2 File (java.io.File)1