Search in sources :

Example 16 with QuadStore

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, "");
}
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 17 with QuadStore

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(""));
}
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 18 with QuadStore

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));
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) DocumentLoader(com.github.jsonldjava.core.DocumentLoader) Test(org.junit.Test)

Example 19 with QuadStore

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"));
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) DocumentLoader(com.github.jsonldjava.core.DocumentLoader) Test(org.junit.Test)

Aggregations

QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)16 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)11 Test (org.junit.Test)11 SummaryProp (nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp)8 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)5 TypedValue (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue)5 IOException (java.io.IOException)4 List (java.util.List)4 Direction (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 DocumentLoader (com.github.jsonldjava.core.DocumentLoader)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Stream (java.util.stream.Stream)3 SubjectReference (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2