Search in sources :

Example 61 with Value

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

the class BdbSchemaStoreTest method generatesASchemaForAllAdded.

@Test
public void generatesASchemaForAllAdded() throws Exception {
    final DummyDataStorage dataStore = new DummyDataStorage();
    ChangeFetcher changeFetcher = new DummyChangeFetcher(CursorQuad.create("subj", "pred", Direction.OUT, ChangeType.ASSERTED, "obj", null, null, null, ""), CursorQuad.create("subj", "langPred", Direction.OUT, ChangeType.ASSERTED, "value", RdfConstants.LANGSTRING, "en", null, ""), CursorQuad.create("subj", RdfConstants.RDF_TYPE, Direction.OUT, ChangeType.ASSERTED, "type", null, null, null, ""), CursorQuad.create("obj", "pred", Direction.IN, ChangeType.ASSERTED, "subj", null, null, null, ""));
    BdbSchemaStore schemaStore = new BdbSchemaStore(dataStore, new ImportStatus(new LogList()));
    schemaStore.start();
    schemaStore.onChangedSubject("subj", changeFetcher);
    schemaStore.onChangedSubject("obj", changeFetcher);
    schemaStore.finish();
    assertThat(dataStore.getResult(), is("{\n" + "  \"type\" : {\n" + "    \"name\" : \"type\",\n" + "    \"predicates\" : [ {\n" + "      \"name\" : \"langPred\",\n" + "      \"direction\" : \"OUT\",\n" + "      \"valueTypes\" : {\n" + "        \"http://www.w3.org/1999/02/22-rdf-syntax-ns#langString\" : 1\n" + "      },\n" + "      \"referenceTypes\" : { },\n" + "      \"languages\" : [ \"en\" ],\n" + "      \"subjectsWithThisPredicate\" : 1,\n" + "      \"subjectsWithThisPredicateAsList\" : 0,\n" + "      \"hasBeenList\" : false,\n" + "      \"hasBeenSingular\" : true\n" + "    }, {\n" + "      \"name\" : \"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\",\n" + "      \"direction\" : \"OUT\",\n" + "      \"valueTypes\" : { },\n" + "      \"referenceTypes\" : {\n" + "        \"http://www.w3.org/2000/01/rdf-schema#Resource\" : 1\n" + "      },\n" + "      \"languages\" : [ ],\n" + "      \"subjectsWithThisPredicate\" : 1,\n" + "      \"subjectsWithThisPredicateAsList\" : 0,\n" + "      \"hasBeenList\" : false,\n" + "      \"hasBeenSingular\" : true\n" + "    }, {\n" + "      \"name\" : \"pred\",\n" + "      \"direction\" : \"OUT\",\n" + "      \"valueTypes\" : { },\n" + "      \"referenceTypes\" : {\n" + "        \"http://www.w3.org/2000/01/rdf-schema#Resource\" : 1\n" + "      },\n" + "      \"languages\" : [ ],\n" + "      \"subjectsWithThisPredicate\" : 1,\n" + "      \"subjectsWithThisPredicateAsList\" : 0,\n" + "      \"hasBeenList\" : false,\n" + "      \"hasBeenSingular\" : true\n" + "    } ],\n" + "    \"subjectsWithThisType\" : 1\n" + "  },\n" + "  \"http://www.w3.org/2000/01/rdf-schema#Resource\" : {\n" + "    \"name\" : \"http://www.w3.org/2000/01/rdf-schema#Resource\",\n" + "    \"predicates\" : [ {\n" + "      \"name\" : \"pred\",\n" + "      \"direction\" : \"IN\",\n" + "      \"valueTypes\" : { },\n" + "      \"referenceTypes\" : {\n" + "        \"type\" : 1\n" + "      },\n" + "      \"languages\" : [ ],\n" + "      \"subjectsWithThisPredicate\" : 1,\n" + "      \"subjectsWithThisPredicateAsList\" : 0,\n" + "      \"hasBeenList\" : false,\n" + "      \"hasBeenSingular\" : true\n" + "    }, {\n" + "      \"name\" : \"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\",\n" + "      \"direction\" : \"IN\",\n" + "      \"valueTypes\" : { },\n" + "      \"referenceTypes\" : {\n" + "        \"type\" : 1\n" + "      },\n" + "      \"languages\" : [ ],\n" + "      \"subjectsWithThisPredicate\" : 0,\n" + "      \"subjectsWithThisPredicateAsList\" : 0,\n" + "      \"hasBeenList\" : false,\n" + "      \"hasBeenSingular\" : true\n" + "    } ],\n" + "    \"subjectsWithThisType\" : 1\n" + "  }\n" + "}"));
}
Also used : LogList(nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogList) ImportStatus(nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus) ChangeFetcher(nl.knaw.huygens.timbuctoo.v5.dataset.ChangeFetcher) Test(org.junit.Test)

Example 62 with Value

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

the class CreateMutationChangeLogTest method getAdditionsForListReturnsCreations.

@Test
public void getAdditionsForListReturnsCreations() throws Exception {
    String addedValue1 = "newValue1";
    String addedValue2 = "newValue2";
    Map<Object, Object> creations = Maps.newHashMap();
    creations.put(NAMES_FIELD, newArrayList(createPropertyInput(addedValue1), createPropertyInput(addedValue2)));
    Map<Object, Object> entity = Maps.newHashMap();
    entity.put("creations", creations);
    CreateMutationChangeLog instance = new CreateMutationChangeLog(new Graph(GRAPH), SUBJECT, TYPE_URI, entity);
    List<Change> adds = instance.getAdditions(dataSet).collect(toList());
    assertThat(adds.size(), is(2));
    assertThat(adds.get(0), is(likeChange().withValues(new Value(TYPE_URI, null)).oldValuesIsEmpty()));
    assertThat(adds.get(1), is(likeChange().withValues(new Value(addedValue1, STRING), new Value(addedValue2, STRING)).oldValuesIsEmpty()));
}
Also used : Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) ChangeMatcher.likeChange(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange) CreateMutationChangeLog(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CreateMutationChangeLog) Test(org.junit.Test)

Example 63 with Value

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

the class DeleteMutationChangeLogTest method getDeletionsReturnsDeletions.

@Test
public void getDeletionsReturnsDeletions() throws Exception {
    String existingValue1 = "existingValue1";
    String existingValue2 = "existingValue2";
    DeleteMutationChangeLog instance = new DeleteMutationChangeLog(new Graph(GRAPH), SUBJECT, null);
    valuesInQuadStore(NAMES_PRED, existingValue1, existingValue2);
    List<Change> deletions = instance.getDeletions(dataSet).collect(toList());
    assertThat(deletions.size(), is(1));
    assertThat(deletions, contains(likeChange().valuesIsEmpty().withOldValues(new Value(existingValue1, STRING), new Value(existingValue2, STRING))));
}
Also used : Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value) ChangeMatcher.likeChange(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange) DeleteMutationChangeLog(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.DeleteMutationChangeLog) Test(org.junit.Test)

Example 64 with Value

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

the class EditMutationChangeLogTest method getReplacementsForListReturnsReplacementsWithOldValues.

@Test
public void getReplacementsForListReturnsReplacementsWithOldValues() 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);
    List<Change> reps = instance.getReplacements(dataSet).collect(toList());
    assertThat(reps.size(), is(1));
    assertThat(reps, contains(likeChange().withValues(new Value(addedValue1, STRING), new Value(addedValue2, 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 65 with Value

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

the class EditMutationChangeLogTest method getAdditionsForListReturnsReplacements.

@Test
public void getAdditionsForListReturnsReplacements() throws Exception {
    String addedValue1 = "newValue1";
    String addedValue2 = "newValue2";
    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);
    List<Change> adds = instance.getAdditions(dataSet).collect(toList());
    assertThat(adds.size(), is(1));
    assertThat(adds, contains(likeChange().withValues(new Value(addedValue1, STRING), new Value(addedValue2, 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)

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