use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog in project timbuctoo by HuygensING.
the class ChangeLogSerializationTest method editMutationChangeLogIsSerializable.
@Test
public void editMutationChangeLogIsSerializable() throws Exception {
String addedValue = "newValue";
Map<Object, Object> additions = Maps.newHashMap();
additions.put(FIELD, newArrayList(createPropertyInput(addedValue)));
Map<Object, Object> entity = Maps.newHashMap();
entity.put("additions", additions);
EditMutationChangeLog preSerialization = new EditMutationChangeLog(new Graph("http://example.org/graph"), "http://example.org/subj", entity);
String serialized = OBJECT_MAPPER.writeValueAsString(preSerialization);
List<Change> postAdditions = OBJECT_MAPPER.readValue(serialized, ChangeLog.class).getAdditions(dataSet).collect(Collectors.toList());
assertThat(postAdditions, contains(likeChange().withValues(new Change.Value(addedValue, STRING))));
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog in project timbuctoo by HuygensING.
the class EditMutationChangeLogTest method getDeletionsForListReturnsDeletions.
@Test
public void getDeletionsForListReturnsDeletions() throws Exception {
String existingValue1 = "existingValue1";
String existingValue2 = "existingValue2";
Map<Object, Object> deletions = Maps.newHashMap();
deletions.put(NAMES_FIELD, newArrayList(createPropertyInput(existingValue2)));
Map<Object, Object> entity = Maps.newHashMap();
entity.put("deletions", deletions);
EditMutationChangeLog instance = new EditMutationChangeLog(new Graph(GRAPH), SUBJECT, entity);
valuesInQuadStore(NAMES_PRED, existingValue1, existingValue2);
List<Change> deletes = instance.getDeletions(dataSet).collect(toList());
assertThat(deletes.size(), is(1));
assertThat(deletes, contains(likeChange().valuesIsEmpty().withOldValues(new Value(existingValue2, STRING))));
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog in project timbuctoo by HuygensING.
the class EditMutationChangeLogTest method getDeletionsIgnoresReplacementsWithoutValue.
@Test
public void getDeletionsIgnoresReplacementsWithoutValue() throws Exception {
Map<Object, Object> replacements = Maps.newHashMap();
replacements.put(NAMES_FIELD, null);
Map<Object, Object> entity = Maps.newHashMap();
entity.put("replacements", replacements);
EditMutationChangeLog instance = new EditMutationChangeLog(new Graph(GRAPH), SUBJECT, entity);
Stream<Change> deletes = instance.getDeletions(dataSet);
assertThat(deletes, StreamMatchers.empty());
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog in project timbuctoo by HuygensING.
the class EditMutationChangeLogTest method getAdditionsForListIgnoresReplacementsWithNoValue.
@Test
public void getAdditionsForListIgnoresReplacementsWithNoValue() throws Exception {
Map<Object, Object> replacements = Maps.newHashMap();
replacements.put(NAMES_FIELD, newArrayList());
Map<Object, Object> entity = Maps.newHashMap();
entity.put("replacements", replacements);
EditMutationChangeLog instance = new EditMutationChangeLog(new Graph(GRAPH), SUBJECT, entity);
Stream<Change> adds = instance.getAdditions(dataSet);
assertThat(adds, StreamMatchers.empty());
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog in project timbuctoo by HuygensING.
the class EditMutationChangeLogTest method getDeletionsReturnsReplacements.
@Test
public void getDeletionsReturnsReplacements() throws Exception {
String existingValue = "existingValue";
Map<Object, Object> replacements = Maps.newHashMap();
replacements.put(NAMES_FIELD, null);
Map<Object, Object> entity = Maps.newHashMap();
entity.put("replacements", replacements);
EditMutationChangeLog instance = new EditMutationChangeLog(new Graph(GRAPH), SUBJECT, entity);
valuesInQuadStore(NAMES_PRED, existingValue);
List<Change> deletes = instance.getDeletions(dataSet).collect(toList());
assertThat(deletes.size(), is(1));
assertThat(deletes, contains(likeChange().valuesIsEmpty().withOldValues(new Value(existingValue, STRING))));
}
Aggregations