Search in sources :

Example 11 with Value

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

the class EditMutationChangeLogTest method getDeletionsReturnsDeletions.

@Test
public void getDeletionsReturnsDeletions() throws Exception {
    String deletedValue = "deletedValue";
    Map<Object, Object> deletions = Maps.newHashMap();
    deletions.put(NAMES_FIELD, newArrayList(createPropertyInput(deletedValue)));
    Map<Object, Object> entity = Maps.newHashMap();
    entity.put("deletions", deletions);
    EditMutationChangeLog instance = new EditMutationChangeLog(new Graph(GRAPH), SUBJECT, entity);
    valuesInQuadStore(NAMES_PRED, deletedValue);
    List<Change> deletes = instance.getDeletions(dataSet).collect(toList());
    assertThat(deletes.size(), is(1));
    assertThat(deletes, contains(likeChange().valuesIsEmpty().withOldValues(new Value(deletedValue, STRING))));
}
Also used : Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) EditMutationChangeLog(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog) Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) ChangeMatcher.likeChange(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange) Test(org.junit.Test)

Example 12 with Value

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

the class GraphQlToRdfPatchTest method deletesAllValuesOfTheDeletions.

@Test
public void deletesAllValuesOfTheDeletions() 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(false, SUBJECT, PRED1, oldValue, STRING, null, GRAPH);
    verify(serializer).addDelQuad(false, SUBJECT, PRED1, oldValue2, STRING, null, GRAPH);
}
Also used : Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) Test(org.junit.Test)

Example 13 with Value

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

the class GraphQlToRdfPatchTest method addsReplacementsToPlan.

@Test
public void addsReplacementsToPlan() throws Exception {
    String newValue = "newValue";
    String newValue2 = "newValue2";
    String oldValue = "oldValue1";
    String oldValue2 = "oldValue2";
    addReplacementsToChangeLog(new Replacement(PRED1, newArrayList(new Value(newValue, STRING), new Value(newValue2, STRING)), 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("replacements")), startsWith(DATA_SET_URI + "/replacements"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/replacements"), eq(RDF_TYPE), eq(TIM_VOCAB + "Replacements"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/replacements"), eq(timPredicate("hasReplacement")), startsWith(DATA_SET_URI + "/replacement"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/replacement"), eq(RDF_TYPE), eq(TIM_VOCAB + "Replacement"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/replacement"), eq(timPredicate("hasKey")), eq(PRED1), isNull(), isNull(), eq(GRAPH));
    // new values
    // one for each value
    verify(serializer, times(2)).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/replacement"), 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(timPredicate("type")), eq(STRING), eq(STRING), isNull(), eq(GRAPH));
    // one for each value
    verify(serializer, times(2)).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/value"), eq(RDF_TYPE), eq(TIM_VOCAB + "Value"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/value"), eq(timPredicate("rawValue")), eq(newValue), eq(STRING), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/value"), eq(timPredicate("rawValue")), eq(newValue2), 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));
    // old values
    // one for each value
    verify(serializer, times(2)).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/replacement"), eq(timPredicate("hadValue")), startsWith(DATA_SET_URI + "/oldValue"), isNull(), isNull(), eq(GRAPH));
    // one for each value
    verify(serializer, times(2)).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/oldValue"), eq(timPredicate("type")), eq(STRING), eq(STRING), isNull(), eq(GRAPH));
    // one for each value
    verify(serializer, times(2)).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/oldValue"), eq(RDF_TYPE), eq(TIM_VOCAB + "OldValue"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/oldValue"), eq(timPredicate("rawValue")), eq(oldValue), eq(STRING), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/oldValue"), 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 + "/oldValue"), eq(timPredicate("nextOldValue")), startsWith(DATA_SET_URI + "/oldValue"), isNull(), isNull(), eq(GRAPH));
}
Also used : Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) Test(org.junit.Test)

Example 14 with Value

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

the class GraphQlToRdfPatchTest method removesOldValuesOfAllDeletions.

@Test
public void removesOldValuesOfAllDeletions() throws Exception {
    String oldValue = "oldValue";
    String oldValue2 = "oldValue2";
    addDeletionsToChangeLog(new Deletion(PRED1, newArrayList(new Value(oldValue, STRING))), new Deletion(PRED2, newArrayList(new Value(oldValue2, STRING))));
    GraphQlToRdfPatch instance = new GraphQlToRdfPatch(GRAPH, SUBJECT, USER_URI, changeLog);
    instance.sendQuads(serializer, s -> {
    }, dataSet);
    verify(serializer).addDelQuad(false, SUBJECT, PRED1, oldValue, STRING, null, GRAPH);
    verify(serializer).addDelQuad(false, SUBJECT, PRED2, oldValue2, STRING, null, GRAPH);
}
Also used : Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) Test(org.junit.Test)

Example 15 with Value

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

the class GraphQlToRdfPatchTest method deletionsAreExecutedBeforeAdditions.

@Test
public void deletionsAreExecutedBeforeAdditions() throws Exception {
    String addedValue = "newValue";
    String oldValue = "oldValue";
    addAdditionsToChangeLog(new Change(new Graph(GRAPH), SUBJECT, PRED1, newArrayList(new Value(addedValue, STRING)), null));
    addDeletionsToChangeLog(new Deletion(PRED1, newArrayList(new Value(oldValue, 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);
}
Also used : Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) InOrder(org.mockito.InOrder) Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) 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