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()));
}
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()));
}
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))));
}
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));
}
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);
}
Aggregations