use of nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore in project timbuctoo by HuygensING.
the class SummaryPropDataRetrieverTest method createSummaryPropertyWalksTheSecondPathIfTheFirstGivesNoValue.
@Test
public void createSummaryPropertyWalksTheSecondPathIfTheFirstGivesNoValue() {
List<SummaryProp> defaultProperties = Lists.newArrayList(summaryPropertyWithPath("http://example.org/path", "http://example.org/path2"));
SummaryPropDataRetriever instance = new SummaryPropDataRetriever("http://example.org/userConfigured", defaultProperties);
QuadStore quadStore = mock(QuadStore.class);
CursorQuad foundQuad1 = quadWithObject("http://example.org/objectFound1", Optional.empty());
CursorQuad foundQuad2 = quadWithObject("http://example.org/objectFound2", Optional.empty());
given(quadStore.getQuads("http://example.org/source", "http://example.org/path", Direction.OUT, "")).willReturn(Stream.of(foundQuad1, foundQuad2));
CursorQuad quadWithObjectUriOfPath2 = quadWithObject("http://example.org/objectOfPath2", Optional.empty());
given(quadStore.getQuads("http://example.org/objectFound2", "http://example.org/path2", Direction.OUT, "")).willReturn(Stream.of(quadWithObjectUriOfPath2));
Optional<TypedValue> summaryProperty = instance.createSummaryProperty(subjectWithUri("http://example.org/source"), dataSetWithQuadStore(quadStore));
assertThat(summaryProperty, is(present()));
assertThat(summaryProperty.get(), hasProperty("value", is("http://example.org/objectOfPath2")));
verify(quadStore).getQuads("http://example.org/source", "http://example.org/path", Direction.OUT, "");
verify(quadStore).getQuads("http://example.org/objectFound1", "http://example.org/path2", Direction.OUT, "");
verify(quadStore).getQuads("http://example.org/objectFound2", "http://example.org/path2", Direction.OUT, "");
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore in project timbuctoo by HuygensING.
the class SummaryPropDataRetrieverTest method createSummaryPropertySearchesUntilItFindsAValue.
@Test
public void createSummaryPropertySearchesUntilItFindsAValue() {
List<SummaryProp> defaultProperties = Lists.newArrayList(summaryPropertyWithPath("http://example.org/prop1"), summaryPropertyWithPath("http://example.org/prop2"), summaryPropertyWithPath("http://example.org/prop3"));
SummaryPropDataRetriever instance = new SummaryPropDataRetriever("http://example.org/userConfigured", defaultProperties);
QuadStore quadStore = mock(QuadStore.class);
CursorQuad foundQuad = quadWithObject("http://example.org/objectFound1", Optional.empty());
given(foundQuad.getObject()).willReturn("http://example.org/value");
given(quadStore.getQuads("http://example.org/source", "http://example.org/prop2", Direction.OUT, "")).willReturn(Stream.of(foundQuad));
Optional<TypedValue> found = instance.createSummaryProperty(subjectWithUri("http://example.org/source"), dataSetWithQuadStore(quadStore));
assertThat(found, is(present()));
assertThat(found.get(), hasProperty("value", is("http://example.org/value")));
verify(quadStore).getQuads("http://example.org/source", "http://example.org/prop1", Direction.OUT, "");
verify(quadStore).getQuads("http://example.org/source", "http://example.org/prop2", Direction.OUT, "");
verify(quadStore, never()).getQuads(anyString(), eq("http://example.org/prop3"), eq(Direction.OUT), eq(""));
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore in project timbuctoo by HuygensING.
the class JsonProvenanceToRdfPatchTest method doesOptimisticLocking.
@Test
public void doesOptimisticLocking() throws Exception {
String examplePatch = "{\n" + " \"@type\":\"prov:Activity\",\n" + " \"http://www.w3.org/ns/prov#generates\":[\n" + " {\n" + " \"@type\":\"prov:Entity\",\n" + " \"specializationOf\":{\n" + " \"@id\":\"http://example.com/the/actual/entity1\"\n" + " },\n" + " \"wasRevisionOf\":{\n" + " \"@id\":\"http://example.org/revision1\"\n" + " },\n" + " \"additions\":[\n" + " {\n" + " \"@type\":\"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\",\n" + " \"predicate\":\"http://example.org/pred1\",\n" + " \"value\":\"value1\"\n" + " }\n" + " ]\n" + " }\n" + " ],\n" + context + "}";
QuadStore testQuadStore = new DummyQuadStore().with("http://example.org/entity1", RdfConstants.TIM_LATEST_REVISION, "http://example.org/revision2", null);
boolean exceptionWasThrown = false;
try {
fromCurrentState(new DocumentLoader(), examplePatch, testQuadStore, "http://example.org/users/myUser", UUID.randomUUID().toString(), CLOCK);
} catch (ConcurrentUpdateException e) {
exceptionWasThrown = true;
}
assertThat(exceptionWasThrown, is(true));
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore in project timbuctoo by HuygensING.
the class JsonProvenanceToRdfPatchTest method testReplacement.
@Test
public void testReplacement() throws Exception {
String testReplacement = "{\n" + " \"@type\":\"prov:Activity\",\n" + " \"http://www.w3.org/ns/prov#generates\":[\n" + " {\n" + " \"@type\":\"prov:Entity\",\n" + " \"specializationOf\":{\n" + " \"@id\":\"http://example.com/the/actual/entitys\"\n" + " },\n" + " \"replacements\":[\n" + " {\n" + " \"@type\":\"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\",\n" + " \"predicate\":\"http://example.org/pred1\",\n" + " \"value\":\"value1\"\n" + " }\n" + " ]\n" + " }\n" + " ],\n" + context + "}";
QuadStore testQuadStore = new DummyQuadStore().with("http://example.com/the/actual/entitys", "http://example.org/pred1", "old value", "http://www.w3.org/2001/XMLSchema#string");
JsonProvenanceToRdfPatch creator = fromCurrentState(new DocumentLoader(), testReplacement, testQuadStore, EDITOR_URI, "test", CLOCK);
creator.sendQuads(basicRdfPatchSerializer, s -> {
}, null);
List<String> filteredResult = Lists.newArrayList(Collections2.filter(result, Predicates.containsPattern("http://example.org/pred")));
filteredResult = Lists.newArrayList(Collections2.filter(filteredResult, Predicates.not(Predicates.containsPattern("skolemized"))));
assertThat(filteredResult, containsInAnyOrder("-<http://example.com/the/actual/entitys> <http://example.org/pred1> \"old value\"" + "^^<http://www.w3.org/2001/XMLSchema#string> <" + defaultGraph + "> .\n", "+<http://example.com/the/actual/entitys> <http://example.org/pred1> \"value1\"" + "^^<http://www.w3.org/2001/XMLSchema#string> <" + defaultGraph + "> .\n"));
}
Aggregations