Search in sources :

Example 6 with EditMutationChangeLog

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

the class EditMutationChangeLogTest method getReplacementsThrowsAnExceptionWhenTheReplacementHasAnUnsupportedValue.

@Test(expected = IllegalArgumentException.class)
public void getReplacementsThrowsAnExceptionWhenTheReplacementHasAnUnsupportedValue() throws Exception {
    String addedValue1 = "newValue1";
    String oldValue = "oldValue";
    Map<Object, Object> replacements = Maps.newHashMap();
    replacements.put(NAMES_FIELD, addedValue1);
    Map<Object, Object> entity = Maps.newHashMap();
    entity.put("replacements", replacements);
    EditMutationChangeLog instance = new EditMutationChangeLog(new Graph(GRAPH), SUBJECT, entity);
    valuesInQuadStore(NAMES_PRED, oldValue);
    // collect to trigger right exception
    instance.getReplacements(dataSet).collect(Collectors.toList());
}
Also used : Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) EditMutationChangeLog(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog) Test(org.junit.Test)

Example 7 with EditMutationChangeLog

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog 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 8 with EditMutationChangeLog

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog 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)

Example 9 with EditMutationChangeLog

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

the class EditMutationChangeLogTest method getAdditionsDoesNotIgnoreAdditionsForSameValue.

// The addition is captured, even though it already exists.
// But this 'addition' is filtered out when the data will be persisted
@Test
public void getAdditionsDoesNotIgnoreAdditionsForSameValue() throws Exception {
    String existingValue = "value";
    Map<Object, Object> additions = Maps.newHashMap();
    additions.put(NAMES_FIELD, newArrayList(createPropertyInput(existingValue)));
    Map<Object, Object> entity = Maps.newHashMap();
    entity.put("additions", additions);
    EditMutationChangeLog instance = new EditMutationChangeLog(new Graph(GRAPH), SUBJECT, entity);
    valuesInQuadStore(NAMES_PRED, existingValue);
    List<Change> adds = instance.getAdditions(dataSet).collect(toList());
    assertThat(adds.size(), is(1));
    assertThat(adds, contains(likeChange().withValues(new Value(existingValue, 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 10 with EditMutationChangeLog

use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog 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)

Aggregations

EditMutationChangeLog (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog)22 Graph (nl.knaw.huygens.timbuctoo.v5.util.Graph)22 Test (org.junit.Test)21 ChangeMatcher.likeChange (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange)20 Value (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)1 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)1 LogStorageFailedException (nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException)1 ImmutableContextData (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ImmutableContextData)1 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)1