Search in sources :

Example 66 with Value

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

the class EditMutationChangeLogTest method getAdditionsReturnsAdditions.

@Test
public void getAdditionsReturnsAdditions() throws Exception {
    String addedValue = "newValue";
    Map<Object, Object> additions = Maps.newHashMap();
    additions.put(NAMES_FIELD, newArrayList(createPropertyInput(addedValue)));
    Map<Object, Object> entity = Maps.newHashMap();
    entity.put("additions", additions);
    EditMutationChangeLog instance = new EditMutationChangeLog(new Graph(GRAPH), SUBJECT, entity);
    List<Change> adds = instance.getAdditions(dataSet).collect(toList());
    assertThat(adds.size(), is(1));
    assertThat(adds, contains(likeChange().withValues(new Value(addedValue, STRING)).oldValuesIsEmpty()));
}
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 67 with Value

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

the class EditMutationChangeLogTest method getAdditionsReturnsReplacements.

@Test
public void getAdditionsReturnsReplacements() throws Exception {
    String addedValue = "newValue";
    Map<Object, Object> replacements = Maps.newHashMap();
    replacements.put(NAMES_FIELD, createPropertyInput(addedValue));
    Map<Object, Object> entity = Maps.newHashMap();
    entity.put("replacements", replacements);
    EditMutationChangeLog instance = new EditMutationChangeLog(new Graph(GRAPH), SUBJECT, entity);
    List<Change> adds = instance.getAdditions(dataSet).collect(toList());
    assertThat(adds.size(), is(1));
    assertThat(adds, contains(likeChange().withValues(new Value(addedValue, STRING)).oldValuesIsEmpty()));
}
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 68 with Value

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

the class EditMutationChangeLogTest method getReplacementsForSingleValueReturnsReplacementsWithOldValues.

@Test
public void getReplacementsForSingleValueReturnsReplacementsWithOldValues() throws Exception {
    String addedValue1 = "newValue1";
    String oldValue = "oldValue";
    Map<Object, Object> replacements = Maps.newHashMap();
    replacements.put(NAMES_FIELD, createPropertyInput(addedValue1));
    Map<Object, Object> entity = Maps.newHashMap();
    entity.put("replacements", replacements);
    EditMutationChangeLog instance = new EditMutationChangeLog(new Graph(GRAPH), SUBJECT, entity);
    valuesInQuadStore(NAMES_PRED, oldValue);
    List<Change> reps = instance.getReplacements(dataSet).collect(toList());
    assertThat(reps.size(), is(1));
    assertThat(reps, contains(likeChange().withValues(new Value(addedValue1, STRING)).withOldValues(new Value(oldValue, 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 69 with Value

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

the class GraphQlToRdfPatchTest method addsAdditionsToPlan.

@Test
public void addsAdditionsToPlan() throws Exception {
    String addedValue = "newValue";
    String addedValue2 = "newValue2";
    addAdditionsToChangeLog(new Change(new Graph(GRAPH), SUBJECT, PRED1, newArrayList(new Value(addedValue, STRING), new Value(addedValue2, STRING)), null));
    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("additions")), startsWith(DATA_SET_URI + "/additions"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/additions"), eq(RDF_TYPE), eq(TIM_VOCAB + "Additions"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/additions"), eq(timPredicate("hasAddition")), startsWith(DATA_SET_URI + "/addition"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/addition"), eq(RDF_TYPE), eq(TIM_VOCAB + "Addition"), isNull(), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/addition"), eq(timPredicate("hasKey")), eq(PRED1), isNull(), isNull(), eq(GRAPH));
    // one for each value
    verify(serializer, times(2)).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/addition"), 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(addedValue), eq(STRING), isNull(), eq(GRAPH));
    verify(serializer).addDelQuad(eq(true), startsWith(DATA_SET_URI + "/value"), eq(timPredicate("rawValue")), eq(addedValue2), 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 : Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) Test(org.junit.Test)

Example 70 with Value

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

the class GraphQlToRdfPatchTest method addsTheNewValuesForReplacement.

@Test
public void addsTheNewValuesForReplacement() throws Exception {
    String addedValue = "newValue";
    String addedValue2 = "newValue2";
    String oldValue = "oldValue";
    addReplacementsToChangeLog(new Replacement(PRED1, newArrayList(new Value(addedValue, STRING), new Value(addedValue2, STRING)), 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);
    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)

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