Search in sources :

Example 56 with Value

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

the class SummaryPropDataRetrieverTest method createSummaryPropertySearchesUntilItFindsAValue.

@Test
public void createSummaryPropertySearchesUntilItFindsAValue() {
    List<SummaryProp> defaultProperties = Lists.newArrayList(summaryPropertyWithPath(DEFAULT_PROP_1), summaryPropertyWithPath(DEFAULT_PROP_2), summaryPropertyWithPath(DEFAULT_PROP_3));
    SummaryPropDataRetriever instance = new SummaryPropDataRetriever(USER_CONFIGURED_PATH, defaultProperties);
    QuadStore quadStore = mock(QuadStore.class);
    CursorQuad foundQuad = quadWithObject(OBJECT_1, Optional.empty());
    given(foundQuad.getObject()).willReturn("http://example.org/value");
    given(quadStore.getQuadsInGraph(SOURCE, DEFAULT_PROP_2, Direction.OUT, "", Optional.of(new Graph(GRAPH)))).willReturn(Stream.of(foundQuad));
    Optional<TypedValue> found = instance.createSummaryProperty(subjectWithUriAndGraph(SOURCE, Optional.of(new Graph(GRAPH))), dataSetWithQuadStore(quadStore), COLLECTION);
    assertThat(found, is(present()));
    assertThat(found.get(), hasProperty("value", is("http://example.org/value")));
    verify(quadStore).getQuadsInGraph(SOURCE, DEFAULT_PROP_1, Direction.OUT, "", Optional.of(new Graph(GRAPH)));
    verify(quadStore).getQuadsInGraph(SOURCE, DEFAULT_PROP_2, Direction.OUT, "", Optional.of(new Graph(GRAPH)));
    verify(quadStore, never()).getQuadsInGraph(anyString(), eq(DEFAULT_PROP_3), eq(Direction.OUT), eq(""), eq(Optional.of(new Graph(GRAPH))));
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) SummaryProp(nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp) TypedValue(nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.TypedValue) Test(org.junit.Test)

Example 57 with Value

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

the class SummaryPropDataRetrieverTest method createSummaryPropertySupportsInverseRelations.

@Test
public void createSummaryPropertySupportsInverseRelations() {
    List<SummaryProp> defaultProperties = Lists.newArrayList(summaryPropertyWithPath(DEFAULT_PROP_1, Direction.IN));
    SummaryPropDataRetriever instance = new SummaryPropDataRetriever(USER_CONFIGURED_PATH, defaultProperties);
    QuadStore quadStore = mock(QuadStore.class);
    CursorQuad foundQuad = quadWithObject(OBJECT_1, Optional.empty());
    given(foundQuad.getObject()).willReturn("http://example.org/value");
    instance.createSummaryProperty(subjectWithUriAndGraph(SOURCE, Optional.of(new Graph(GRAPH))), dataSetWithQuadStore(quadStore), COLLECTION);
    verify(quadStore).getQuadsInGraph(SOURCE, DEFAULT_PROP_1, Direction.IN, "", Optional.of(new Graph(GRAPH)));
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) Graph(nl.knaw.huygens.timbuctoo.v5.util.Graph) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) SummaryProp(nl.knaw.huygens.timbuctoo.v5.graphql.defaultconfiguration.SummaryProp) Test(org.junit.Test)

Example 58 with Value

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

the class DerivedInputTypeSchemaGeneratorTest method returnsAnEmptyStringForReadOnlyTypes.

@Test
public void returnsAnEmptyStringForReadOnlyTypes() {
    DerivedInputTypeSchemaGenerator instance = new DerivedInputTypeSchemaGenerator(READ_ONLY_TYPE, ROOT_TYPE, graphQlNameGenerator, derivedSchemaContainer, readOnlyChecker, new CustomProvenance(Collections.emptyList()));
    Predicate predicate = predicate().withName("http://example.com/value").hasDirection(Direction.OUT).withValueType(RdfConstants.STRING).build();
    instance.valueField(null, predicate, RdfConstants.STRING);
    String schema = instance.getSchema().toString();
    assertThat(schema, isEmptyString());
}
Also used : Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) CustomProvenance(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance) Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate) Test(org.junit.Test)

Example 59 with Value

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

the class DerivedInputTypeSchemaGeneratorTest method addsADeprecatedInputFieldForSingleForAListThatWasASingle.

@Test
public void addsADeprecatedInputFieldForSingleForAListThatWasASingle() {
    Predicate valueList = predicate().withName("http://example.com/wasSingleList").isList().hasBeenSingular().hasDirection(Direction.OUT).build();
    graphQlNameForPredicate("http://example.com/wasSingleList", false, "short_wasSingle");
    graphQlNameForPredicate("http://example.com/wasSingleList", true, "short_wasSingleList");
    instanceNoProv.valueField(null, valueList, RdfConstants.STRING);
    String schema = instanceNoProv.getSchema().toString();
    assertThat(schema, allOf(containsString("input TypeReplacementsInput {\n" + "  short_wasSingleList: [PropertyInput!]\n" + "  short_wasSingle: PropertyInput" + " @deprecated(reason: \"This property only returns the first value of the list. Use the *List version\")\n" + "}\n\n")));
}
Also used : Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate) Test(org.junit.Test)

Example 60 with Value

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

the class SchemaGenerationTest method addAValidIncomingPredicateToTheNewType.

/* When the SUBJECT_C RDF_TYPE TYPE_1 is asserted in a a separate update, while ex:baz did not have a type before.
   * Then I expect the RDF_TYPE to get an inverse of the ex:links predicate that points to TYPE_2
   *
   * But in the current code that does not happen. Instead ex:type gets an ex:links
   *  predicate that has no reference or value types
   */
@Test
public void addAValidIncomingPredicateToTheNewType() throws Exception {
    BdbNonPersistentEnvironmentCreator dataStoreFactory = new BdbNonPersistentEnvironmentCreator();
    final BdbSchemaStore schema = new BdbSchemaStore(new BdbBackedData(dataStoreFactory.getDatabase(USER, DATA_SET, "schema", false, STRING_BINDING, STRING_BINDING, STRING_IS_CLEAN_HANDLER)), mock(ImportStatus.class));
    final StoreUpdater storeUpdater = createInstance(dataStoreFactory, schema);
    storeUpdater.start(0);
    storeUpdater.onQuad(true, SUBJECT_A, PROP_III, SUBJECT_C, null, null, null);
    storeUpdater.onQuad(true, SUBJECT_A, RDF_TYPE, TYPE_2, null, null, null);
    storeUpdater.commit();
    storeUpdater.start(1);
    storeUpdater.onQuad(true, SUBJECT_C, RDF_TYPE, TYPE_1, null, null, null);
    storeUpdater.commit();
    assertThat(schema.getStableTypes(), hasEntry(is(TYPE_1), hasProperty("predicates", hasItem(predicate().withName(PROP_III).withDirection(Direction.IN).withReferenceType(TYPE_2)))));
}
Also used : ImportStatus(nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus) BdbNonPersistentEnvironmentCreator(nl.knaw.huygens.timbuctoo.v5.dropwizard.BdbNonPersistentEnvironmentCreator) 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