Search in sources :

Example 6 with Change

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change 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());
}
Also used : Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) EditMutationChangeLog(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog) ChangeMatcher.likeChange(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange) Test(org.junit.Test)

Example 7 with Change

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change 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());
}
Also used : Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) EditMutationChangeLog(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog) ChangeMatcher.likeChange(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange) Test(org.junit.Test)

Example 8 with Change

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change 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))));
}
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 9 with Change

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

the class EditMutationChangeLogTest method getAdditionsForListIgnoresReplacementsWithOldValue.

@Test
public void getAdditionsForListIgnoresReplacementsWithOldValue() throws Exception {
    String addedValue1 = "newValue1";
    String addedValue2 = "newValue2";
    String oldValue = "oldValue";
    Map<Object, Object> replacements = Maps.newHashMap();
    replacements.put(NAMES_FIELD, newArrayList(createPropertyInput(addedValue1), createPropertyInput(addedValue2)));
    Map<Object, Object> entity = Maps.newHashMap();
    entity.put("replacements", replacements);
    EditMutationChangeLog instance = new EditMutationChangeLog(new Graph(GRAPH), SUBJECT, entity);
    valuesInQuadStore(NAMES_PRED, oldValue);
    Stream<Change> adds = instance.getAdditions(dataSet);
    assertThat(adds, StreamMatchers.empty());
}
Also used : Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) EditMutationChangeLog(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog) ChangeMatcher.likeChange(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange) Test(org.junit.Test)

Example 10 with Change

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

the class EditMutationChangeLogTest method getDeletionsForListReturnsReplacements.

@Test
public void getDeletionsForListReturnsReplacements() throws Exception {
    String existingValue1 = "existingValue1";
    String existingValue2 = "existingValue2";
    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);
    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(existingValue1, STRING), new Value(existingValue2, 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)

Aggregations

Test (org.junit.Test)36 Graph (nl.knaw.huygens.timbuctoo.v5.util.Graph)33 ChangeMatcher.likeChange (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange)32 Value (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value)24 EditMutationChangeLog (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog)20 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 TypeNameStore (nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore)5 Change (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change)5 CustomProvenance (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance)5 ProvenanceChangeLog (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.ProvenanceChangeLog)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 Map (java.util.Map)4 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)4 Stream (java.util.stream.Stream)3 CreateMutationChangeLog (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CreateMutationChangeLog)3 DeleteMutationChangeLog (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.DeleteMutationChangeLog)3 JsonSubTypes (com.fasterxml.jackson.annotation.JsonSubTypes)2 JsonTypeInfo (com.fasterxml.jackson.annotation.JsonTypeInfo)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2