use of nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad in project timbuctoo by HuygensING.
the class SummaryPropDataRetrieverTest method createSummaryPropertyWalksTheUserConfiguredPathFirst.
@Test
public void createSummaryPropertyWalksTheUserConfiguredPathFirst() throws JsonProcessingException {
List<SummaryProp> defaultProperties = Lists.newArrayList(summaryPropertyWithPath("http://example.org/path"));
SummaryPropDataRetriever instance = new SummaryPropDataRetriever("http://example.org/userConfigured", defaultProperties);
SummaryProp summaryProp = summaryPropertyWithPath("http://example.org/userPath");
CursorQuad collectionQuad = quadWithObject("http://example.org/collection", Optional.empty());
CursorQuad userConfiguredSummaryProp = quadWithObject(OBJECT_MAPPER.writeValueAsString(summaryProp), Optional.empty());
QuadStore quadStore = mock(QuadStore.class);
given(quadStore.getQuads("http://example.org/source", RdfConstants.RDF_TYPE, Direction.OUT, "")).willReturn(Stream.of(collectionQuad));
given(quadStore.getQuads("http://example.org/collection", "http://example.org/userConfigured", Direction.OUT, "")).willReturn(Stream.of(userConfiguredSummaryProp));
instance.createSummaryProperty(subjectWithUri("http://example.org/source"), dataSetWithQuadStore(quadStore));
InOrder inOrder = inOrder(quadStore);
// walk the path of the user configured SummaryProp
inOrder.verify(quadStore).getQuads("http://example.org/source", "http://example.org/userPath", Direction.OUT, "");
// walk the path of the default SummaryProp
inOrder.verify(quadStore).getQuads("http://example.org/source", "http://example.org/path", Direction.OUT, "");
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad 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.dto.CursorQuad 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.dto.CursorQuad in project timbuctoo by HuygensING.
the class SummaryPropDataRetrieverTest method quadWithObject.
private CursorQuad quadWithObject(String object, Optional<String> valueType) {
CursorQuad foundQuad = mock(CursorQuad.class);
given(foundQuad.getObject()).willReturn(object);
given(foundQuad.getValuetype()).willReturn(valueType);
return foundQuad;
}
use of nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad in project timbuctoo by HuygensING.
the class ChangeFetcherImplTest method showsAdditions.
@Test
public void showsAdditions() throws Exception {
final BdbNonPersistentEnvironmentCreator databaseCreator = new BdbNonPersistentEnvironmentCreator();
final BdbTripleStore bdbTripleStore = new BdbTripleStore(databaseCreator.getDatabase("a", "b", "rdfData", true, TupleBinding.getPrimitiveBinding(String.class), TupleBinding.getPrimitiveBinding(String.class), new StringStringIsCleanHandler()));
final BdbTruePatchStore truePatchStore = new BdbTruePatchStore(databaseCreator.getDatabase("a", "b", "truePatch", true, TupleBinding.getPrimitiveBinding(String.class), TupleBinding.getPrimitiveBinding(String.class), new StringStringIsCleanHandler()));
bdbTripleStore.putQuad("subj", "pred", OUT, "obj", null, null);
truePatchStore.put("subj", 0, "pred", OUT, true, "obj", null, null);
ChangeFetcherImpl changeFetcher = new ChangeFetcherImpl(truePatchStore, bdbTripleStore, 0);
try (Stream<CursorQuad> predicates = changeFetcher.getPredicates("subj", "pred", OUT, false, false, true)) {
assertThat(predicates.count(), is(1L));
}
try (Stream<CursorQuad> predicates = changeFetcher.getPredicates("subj", "pred", OUT, true, true, true)) {
assertThat(predicates.count(), is(1L));
}
try (Stream<CursorQuad> predicates = changeFetcher.getPredicates("subj", "pred", OUT, true, false, true)) {
assertThat(predicates.count(), is(1L));
}
bdbTripleStore.putQuad("subj", "pred", OUT, "obj2", null, null);
truePatchStore.put("subj", 1, "pred", OUT, true, "obj2", null, null);
changeFetcher = new ChangeFetcherImpl(truePatchStore, bdbTripleStore, 1);
try (Stream<CursorQuad> predicates = changeFetcher.getPredicates("subj", "pred", OUT, false, false, true)) {
assertThat(predicates.count(), is(1L));
}
try (Stream<CursorQuad> predicates = changeFetcher.getPredicates("subj", "pred", OUT, true, true, true)) {
assertThat(predicates.count(), is(2L));
}
try (Stream<CursorQuad> predicates = changeFetcher.getPredicates("subj", "pred", OUT, true, false, true)) {
assertThat(predicates.count(), is(1L));
}
}
Aggregations