Search in sources :

Example 36 with Collection

use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.

the class JsonToEntityMapperTest method newCreateEntityThrowsAnIoExceptionWhenThePropertyIsUnknown.

@Test(expected = IOException.class)
public void newCreateEntityThrowsAnIoExceptionWhenThePropertyIsUnknown() throws Exception {
    Collection collection = new VresBuilder().withVre("WomenWriters", "ww", vre -> vre.withCollection("wwpersons", c -> c.withProperty("name", localProperty("wwname")).withProperty("age", localProperty("wwage")))).build().getCollection("wwpersons").get();
    ObjectNode input = JsonBuilder.jsnO("unknownProperty", jsn("value"), "age", jsn("12"));
    JsonToEntityMapper instance = new JsonToEntityMapper();
    instance.getDataProperties(collection, input);
}
Also used : TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) JsonBuilder(nl.knaw.huygens.timbuctoo.util.JsonBuilder) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) Matchers.allOf(org.hamcrest.Matchers.allOf) Matchers.not(org.hamcrest.Matchers.not) Test(org.junit.Test) IOException(java.io.IOException) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) UUID(java.util.UUID) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) JsonToEntityMapper(nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonToEntityMapper(nl.knaw.huygens.timbuctoo.crud.conversion.JsonToEntityMapper) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Test(org.junit.Test)

Example 37 with Collection

use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.

the class LoadSaveCollectionTest method loadLoadsTheDisplayName.

@Test
public void loadLoadsTheDisplayName() {
    final Vertex collectionVertex = graph.addVertex(Collection.DATABASE_LABEL);
    final Vertex displayNameVertex = graph.addVertex(ReadableProperty.DATABASE_LABEL);
    final String collectionName = "persons";
    final String entityTypeName = "person";
    final String propertyType = new StringToStringConverter().getUniqueTypeIdentifier();
    collectionVertex.property(COLLECTION_NAME_PROPERTY_NAME, collectionName);
    collectionVertex.property(ENTITY_TYPE_NAME_PROPERTY_NAME, entityTypeName);
    collectionVertex.property(IS_RELATION_COLLECTION_PROPERTY_NAME, false);
    displayNameVertex.property(LocalProperty.CLIENT_PROPERTY_NAME, "@displayName");
    displayNameVertex.property(LocalProperty.DATABASE_PROPERTY_NAME, "person_prop1");
    displayNameVertex.property(LocalProperty.PROPERTY_TYPE_NAME, propertyType);
    collectionVertex.addEdge(HAS_DISPLAY_NAME_RELATION_NAME, displayNameVertex);
    final Collection instance = load(collectionVertex);
    assertThat(instance.getDisplayName(), instanceOf(ReadableProperty.class));
}
Also used : StringToStringConverter(nl.knaw.huygens.timbuctoo.model.properties.converters.StringToStringConverter) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ReadableProperty(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) CollectionBuilder.timbuctooCollection(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder.timbuctooCollection) Test(org.junit.Test)

Example 38 with Collection

use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.

the class LoadSaveCollectionTest method loadLoadsACollectionFromAVertex.

@Test
public void loadLoadsACollectionFromAVertex() {
    final Vertex collectionVertex = graph.addVertex(Collection.DATABASE_LABEL);
    final String collectionName = "persons";
    final String entityTypeName = "person";
    collectionVertex.property(COLLECTION_NAME_PROPERTY_NAME, collectionName);
    collectionVertex.property(ENTITY_TYPE_NAME_PROPERTY_NAME, entityTypeName);
    collectionVertex.property(IS_RELATION_COLLECTION_PROPERTY_NAME, false);
    final Collection instance = load(collectionVertex);
    assertThat(instance.getEntityTypeName(), equalTo(entityTypeName));
    assertThat(instance.getCollectionName(), equalTo(collectionName));
    assertThat(instance.getAbstractType(), equalTo(entityTypeName));
    assertThat(instance.isRelationCollection(), equalTo(false));
}
Also used : VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) CollectionBuilder.timbuctooCollection(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder.timbuctooCollection) Test(org.junit.Test)

Example 39 with Collection

use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.

the class LoadSaveCollectionTest method loadLoadsAnInheritingCollectionFromAVertexWithHasArchetypeRelation.

@Test
public void loadLoadsAnInheritingCollectionFromAVertexWithHasArchetypeRelation() {
    final Vertex collectionVertex = graph.addVertex(Collection.DATABASE_LABEL);
    final Vertex abstractCollectionVertex = graph.addVertex(Collection.DATABASE_LABEL);
    final String collectionName = "wwpersons";
    final String entityTypeName = "wwperson";
    final String abstractCollectionName = "persons";
    final String abstractEntityTypeName = "person";
    collectionVertex.property(COLLECTION_NAME_PROPERTY_NAME, collectionName);
    collectionVertex.property(ENTITY_TYPE_NAME_PROPERTY_NAME, entityTypeName);
    collectionVertex.property(IS_RELATION_COLLECTION_PROPERTY_NAME, false);
    abstractCollectionVertex.property(COLLECTION_NAME_PROPERTY_NAME, abstractCollectionName);
    abstractCollectionVertex.property(ENTITY_TYPE_NAME_PROPERTY_NAME, abstractEntityTypeName);
    collectionVertex.addEdge(HAS_ARCHETYPE_RELATION_NAME, abstractCollectionVertex);
    final Collection instance = load(collectionVertex);
    assertThat(instance.getAbstractType(), equalTo(abstractEntityTypeName));
}
Also used : VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) CollectionBuilder.timbuctooCollection(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder.timbuctooCollection) Test(org.junit.Test)

Example 40 with Collection

use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.

the class LoadSaveVreTest method loadLoadsRelationCollections.

@Test
public void loadLoadsRelationCollections() {
    final String entityTypeName = "relation";
    final String collectionName = "relations";
    final Vre instance = load(initGraph(g -> g.withVertex("vre", v -> v.withLabel(Vre.DATABASE_LABEL).withProperty(VRE_NAME_PROPERTY_NAME, "VreName")).withVertex("collection", v -> v.withLabel(entityTypeName).withProperty(Collection.COLLECTION_NAME_PROPERTY_NAME, collectionName).withProperty(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, entityTypeName).withProperty(Collection.IS_RELATION_COLLECTION_PROPERTY_NAME, true).withIncomingRelation(HAS_COLLECTION_RELATION_NAME, "vre"))));
    final Collection collectionByName = instance.getCollectionForCollectionName(collectionName).get();
    assertThat(instance.getRelationCollection().get(), equalTo(collectionByName));
}
Also used : TestGraphBuilder(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder) HAS_ARCHETYPE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ARCHETYPE_RELATION_NAME) Graph(org.apache.tinkerpop.gremlin.structure.Graph) Tuple(nl.knaw.huygens.timbuctoo.util.Tuple) HashMap(java.util.HashMap) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) VRE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.VRE_NAME_PROPERTY_NAME) Lists(com.google.common.collect.Lists) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DataStoreOperations(nl.knaw.huygens.timbuctoo.core.DataStoreOperations) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Neo4jVertex(org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jVertex) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Maps(com.google.common.collect.Maps) KEYWORD_TYPES_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.KEYWORD_TYPES_PROPERTY_NAME) Consumer(java.util.function.Consumer) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Direction(org.apache.tinkerpop.gremlin.structure.Direction) List(java.util.List) HAS_COLLECTION_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.HAS_COLLECTION_RELATION_NAME) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Optional(java.util.Optional) VreBuilder.vre(nl.knaw.huygens.timbuctoo.model.vre.VreBuilder.vre) Tuple.tuple(nl.knaw.huygens.timbuctoo.util.Tuple.tuple) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Test(org.junit.Test)

Aggregations

Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)147 Test (org.junit.Test)122 UUID (java.util.UUID)91 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)85 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)81 TinkerPopGraphManager (nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager)80 Optional (java.util.Optional)77 List (java.util.List)76 CreateCollection (nl.knaw.huygens.timbuctoo.core.dto.CreateCollection)74 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)74 Vres (nl.knaw.huygens.timbuctoo.model.vre.Vres)73 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)72 IOException (java.io.IOException)71 Vre (nl.knaw.huygens.timbuctoo.model.vre.Vre)71 JsonBuilder.jsn (nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn)71 Matchers.is (org.hamcrest.Matchers.is)71 Change (nl.knaw.huygens.timbuctoo.model.Change)70 Matchers.not (org.hamcrest.Matchers.not)70 UpdateEntity (nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity)69 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)69