Search in sources :

Example 16 with Value

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.

the class GraphQlToRdfPatchTest method removesAllOldValuesOfReplacements.

@Test
public void removesAllOldValuesOfReplacements() throws Exception {
    String oldValue = "oldValue";
    String oldValue2 = "oldValue2";
    String addedValue = "newValue";
    String addedValue2 = "newValue2";
    addReplacementsToChangeLog(new Replacement(PRED1, newArrayList(new Value(addedValue, STRING), new Value(addedValue2, STRING)), newArrayList(new Value(oldValue, STRING), new Value(oldValue2, STRING))));
    GraphQlToRdfPatch instance = new GraphQlToRdfPatch(GRAPH, SUBJECT, USER_URI, changeLog);
    instance.sendQuads(serializer, s -> {
    }, dataSet);
    InOrder inOrder = inOrder(serializer);
    inOrder.verify(serializer).addDelQuad(false, SUBJECT, PRED1, oldValue, STRING, null, GRAPH);
    inOrder.verify(serializer).addDelQuad(false, SUBJECT, PRED1, oldValue2, STRING, null, GRAPH);
    inOrder.verify(serializer).addDelQuad(true, SUBJECT, PRED1, addedValue, STRING, null, GRAPH);
    inOrder.verify(serializer).addDelQuad(true, SUBJECT, PRED1, addedValue2, STRING, null, GRAPH);
}
Also used : InOrder(org.mockito.InOrder) Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) Test(org.junit.Test)

Example 17 with Value

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.

the class GraphQlToRdfPatchTest method addsDeletionsToPlan.

@Test
public void addsDeletionsToPlan() throws Exception {
    String oldValue = "oldValue";
    String oldValue2 = "oldValue2";
    addDeletionsToChangeLog(new Deletion(PRED1, newArrayList(new Value(oldValue, STRING), new Value(oldValue2, STRING))));
    GraphQlToRdfPatch instance = new GraphQlToRdfPatch(GRAPH, SUBJECT, USER_URI, changeLog);
    instance.sendQuads(serializer, s -> {
    }, dataSet);
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/plan"), eq(timPredicate("deletions")), startsWith(DATA_SET_URI + "/deletions"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/deletions"), eq(RDF_TYPE), eq(TIM_VOCAB + "Deletions"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/deletions"), eq(timPredicate("hasDeletion")), startsWith(DATA_SET_URI + "/deletion"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/deletion"), eq(RDF_TYPE), eq(TIM_VOCAB + "Deletion"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/deletion"), eq(timPredicate("hasKey")), eq(PRED1), isNull(), isNull(), eq(GRAPH));
    // one for each value
    verify(serializer, times(2)).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/deletion"), eq(timPredicate("hasValue")), startsWith(DATA_SET_URI + "/value"), isNull(), isNull(), eq(GRAPH));
    // one for each value
    verify(serializer, times(2)).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/value"), eq(RDF_TYPE), eq(timType("Value")), isNull(), isNull(), eq(GRAPH));
    // one for each value
    verify(serializer, times(2)).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/value"), eq(timPredicate("type")), eq(STRING), eq(STRING), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/value"), eq(timPredicate("rawValue")), eq(oldValue), eq(STRING), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/value"), eq(timPredicate("rawValue")), eq(oldValue2), eq(STRING), isNull(), eq(GRAPH));
    // TODO find a better way to test
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/value"), eq(timPredicate("nextValue")), startsWith(DATA_SET_URI + "/value"), isNull(), isNull(), eq(GRAPH));
}
Also used : Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) Test(org.junit.Test)

Example 18 with Value

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.

the class GraphQlToRdfPatchTest method addsCustomProvenanceToPlan.

@Test
public void addsCustomProvenanceToPlan() throws Exception {
    String value1 = "value1";
    String value2 = "value2";
    addProvenanceToChangeLog(new Provenance(PRED1, newArrayList(new Value(value1, STRING))), new Provenance(PRED2, newArrayList(new Value(value2, STRING))));
    GraphQlToRdfPatch instance = new GraphQlToRdfPatch(GRAPH, SUBJECT, USER_URI, changeLog);
    instance.sendQuads(serializer, s -> {
    }, dataSet);
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/plan"), eq(timPredicate("hasCustomProv")), startsWith(DATA_SET_URI + "/customProv"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/customProv"), eq(RDF_TYPE), eq(timType("CustomProv")), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(SUBJECT), eq(PRED1), eq(value1), eq(STRING), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(SUBJECT), eq(PRED2), eq(value2), eq(STRING), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/customProv"), eq(PRED1), eq(value1), eq(STRING), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/customProv"), eq(PRED2), eq(value2), eq(STRING), isNull(), eq(GRAPH));
}
Also used : Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) Test(org.junit.Test)

Example 19 with Value

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.

the class GraphQlToRdfPatchTest method addsAndRemovesValuesOfAllReplacements.

@Test
public void addsAndRemovesValuesOfAllReplacements() throws Exception {
    String addedValue = "newValue";
    String addedValue2 = "newValue2";
    String oldValue = "oldValue";
    String oldValue2 = "oldValue2";
    addReplacementsToChangeLog(new Replacement(PRED1, newArrayList(new Value(addedValue, STRING)), newArrayList(new Value(oldValue, STRING))), new Replacement(PRED2, newArrayList(new Value(addedValue2, STRING)), newArrayList(new Value(oldValue2, STRING))));
    GraphQlToRdfPatch instance = new GraphQlToRdfPatch(GRAPH, SUBJECT, USER_URI, changeLog);
    instance.sendQuads(serializer, s -> {
    }, dataSet);
    InOrder inOrder = inOrder(serializer);
    inOrder.verify(serializer).addDelQuad(false, SUBJECT, PRED1, oldValue, STRING, null, GRAPH);
    inOrder.verify(serializer).addDelQuad(true, SUBJECT, PRED1, addedValue, STRING, null, GRAPH);
    inOrder.verify(serializer).addDelQuad(false, SUBJECT, PRED2, oldValue2, STRING, null, GRAPH);
    inOrder.verify(serializer).addDelQuad(true, SUBJECT, PRED2, addedValue2, STRING, null, GRAPH);
}
Also used : InOrder(org.mockito.InOrder) Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) Test(org.junit.Test)

Example 20 with Value

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.

the class ProvenanceChangeLogTest method getProvenanceForListField.

@Test
public void getProvenanceForListField() throws Exception {
    CustomProvenance customProvenance = CustomProvenance.getCustomProvenance(ImmutableMap.of("fields", Lists.newArrayList(ImmutableMap.of("uri", NAME_URI, "isList", true, "valueType", STRING))));
    when(dataSet.getCustomProvenance()).thenReturn(customProvenance);
    String value1 = "value1";
    String value2 = "value2";
    Map<Object, Object> provenance = Maps.newHashMap();
    provenance.put(NAME_FIELD, newArrayList(createPropertyInput(value1), createPropertyInput(value2)));
    Map<Object, Object> entity = Maps.newHashMap();
    entity.put("provenance", provenance);
    ProvenanceChangeLog instance = new ProvenanceChangeLog(entity);
    List<Change> provChanges = instance.getProvenance(dataSet, SUBJECT).collect(toList());
    assertThat(provChanges.size(), is(1));
    assertThat(provChanges.get(0), is(likeChange().withSubject(SUBJECT).withPredicate(NAME_URI).withValues(new Value(value1, STRING), new Value(value2, STRING)).oldValuesIsEmpty()));
}
Also used : Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) ProvenanceChangeLog(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ProvenanceChangeLog) ChangeMatcher.likeChange(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange) CustomProvenance(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)42 Value (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value)32 Graph (nl.knaw.huygens.timbuctoo.v5.util.Graph)22 ChangeMatcher.likeChange (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange)18 Map (java.util.Map)15 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)15 ExecutionException (java.util.concurrent.ExecutionException)12 LogStorageFailedException (nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException)11 PredicateMutation (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.PredicateMutation)11 EditMutationChangeLog (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog)10 QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)9 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)9 List (java.util.List)8 IOException (java.io.IOException)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Direction (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)6 CustomProvenance (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance)6 Optional (java.util.Optional)5