Search in sources :

Example 6 with SummaryProp

use of nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp in project timbuctoo by HuygensING.

the class SummaryPropDataRetrieverTest method createSummaryPropertyStopsWhenTheFirstPartOfThePathCannotBeFound.

@Test
public void createSummaryPropertyStopsWhenTheFirstPartOfThePathCannotBeFound() {
    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);
    given(quadStore.getQuads("http://example.org/source", "http://example.org/path", Direction.OUT, "")).willReturn(Stream.empty());
    instance.createSummaryProperty(subjectWithUri("http://example.org/source"), dataSetWithQuadStore(quadStore));
    verify(quadStore).getQuads("http://example.org/source", "http://example.org/path", Direction.OUT, "");
    verify(quadStore, never()).getQuads(anyString(), eq("http://example.org/path2"), eq(Direction.OUT), eq(""));
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) SummaryProp(nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp) Test(org.junit.Test)

Example 7 with SummaryProp

use of nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp 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, "");
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) SummaryProp(nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp) TypedValue(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue) Test(org.junit.Test)

Example 8 with SummaryProp

use of nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp 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(""));
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) SummaryProp(nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp) TypedValue(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue) Test(org.junit.Test)

Aggregations

QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)8 SummaryProp (nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp)8 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)7 Test (org.junit.Test)7 TypedValue (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue)4 InOrder (org.mockito.InOrder)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 IOException (java.io.IOException)1 List (java.util.List)1 Optional (java.util.Optional)1 Stream (java.util.stream.Stream)1 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)1 Direction (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)1 SubjectReference (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference)1 RdfConstants (nl.knaw.huygens.timbuctoo.v5.util.RdfConstants)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1