Search in sources :

Example 1 with TestGraphBuilder

use of nl.knaw.huygens.timbuctoo.util.TestGraphBuilder in project timbuctoo by HuygensING.

the class LoadSaveVreTest method initGraph.

private Tuple<DataStoreOperations, Graph> initGraph(Consumer<TestGraphBuilder> init) {
    TestGraphBuilder testGraphBuilder = newGraph();
    init.accept(testGraphBuilder);
    TinkerPopGraphManager graphManager = testGraphBuilder.wrap();
    return tuple(TinkerPopOperationsStubs.forGraphWrapper(graphManager), graphManager.getGraph());
}
Also used : TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) TestGraphBuilder(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder)

Example 2 with TestGraphBuilder

use of nl.knaw.huygens.timbuctoo.util.TestGraphBuilder in project timbuctoo by HuygensING.

the class CollectionHasEntityRelationChangeListenerTest method onAddToCollectionCreatesARelation.

@Test
public void onAddToCollectionCreatesARelation() throws Exception {
    final String[] types = { "person", "wwperson" };
    final String typesJson = new ObjectMapper().writeValueAsString(types);
    final String linkingNodeWwPersonsName = "linking-node-wwpersons";
    final String linkingNodePersonsName = "linking-node-persons";
    final String createThisVertexName = "create-this-vertex";
    final TestGraphBuilder builder = newGraph().withVertex(linkingNodePersonsName, v -> v.withLabel(Collection.COLLECTION_ENTITIES_LABEL).withProperty("check", linkingNodePersonsName)).withVertex(linkingNodeWwPersonsName, v -> v.withLabel(Collection.COLLECTION_ENTITIES_LABEL).withProperty("check", linkingNodeWwPersonsName)).withVertex("other", v -> v.withLabel(Collection.COLLECTION_ENTITIES_LABEL).withProperty("check", "other")).withVertex(v -> v.withLabel(Collection.DATABASE_LABEL).withProperty(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, "person").withProperty(Collection.COLLECTION_NAME_PROPERTY_NAME, "persons").withOutgoingRelation(Collection.HAS_ENTITY_NODE_RELATION_NAME, linkingNodePersonsName)).withVertex(v -> v.withLabel(Collection.DATABASE_LABEL).withProperty(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, "wwperson").withProperty(Collection.COLLECTION_NAME_PROPERTY_NAME, "wwpersons").withOutgoingRelation(Collection.HAS_ENTITY_NODE_RELATION_NAME, linkingNodeWwPersonsName)).withVertex(v -> v.withProperty("types", typesJson).withTimId(createThisVertexName).withIncomingRelation(Collection.HAS_ENTITY_RELATION_NAME, linkingNodePersonsName));
    final GraphWrapper graphWrapper = builder.wrap();
    Vertex createdVertex = graphWrapper.getGraph().traversal().V().has("tim_id", createThisVertexName).next();
    CollectionHasEntityRelationChangeListener instance = new CollectionHasEntityRelationChangeListener(graphWrapper);
    instance.onAddToCollection(forEntitytypeName("ww", "person"), Optional.empty(), createdVertex);
    final List<Vertex> actualLinkingNodes = Lists.newArrayList(createdVertex.vertices(Direction.IN, Collection.HAS_ENTITY_RELATION_NAME));
    assertThat(actualLinkingNodes, containsInAnyOrder(likeVertex().withProperty("check", linkingNodePersonsName), likeVertex().withProperty("check", linkingNodeWwPersonsName)));
}
Also used : TestGraphBuilder(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder) CollectionStubs.forEntitytypeName(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionStubs.forEntitytypeName) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Direction(org.apache.tinkerpop.gremlin.structure.Direction) List(java.util.List) Lists(com.google.common.collect.Lists) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Optional(java.util.Optional) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) TestGraphBuilder(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with TestGraphBuilder

use of nl.knaw.huygens.timbuctoo.util.TestGraphBuilder in project timbuctoo by HuygensING.

the class CollectionHasEntityRelationChangeListenerTest method onRemoveFromCollectionRemovesTheRelation.

@Test
public void onRemoveFromCollectionRemovesTheRelation() throws Exception {
    final String[] types = { "person" };
    final String typesJson = new ObjectMapper().writeValueAsString(types);
    final String linkingNodeWwPersonsName = "linking-node-wwpersons";
    final String linkingNodePersonsName = "linking-node-persons";
    final String updateThisVertexName = "update-this-vertex";
    final TestGraphBuilder builder = newGraph().withVertex(linkingNodePersonsName, v -> v.withLabel(Collection.COLLECTION_ENTITIES_LABEL).withProperty("check", linkingNodePersonsName)).withVertex(linkingNodeWwPersonsName, v -> v.withLabel(Collection.COLLECTION_ENTITIES_LABEL).withProperty("check", linkingNodeWwPersonsName)).withVertex("other", v -> v.withLabel(Collection.COLLECTION_ENTITIES_LABEL).withProperty("check", "other")).withVertex(v -> v.withLabel(Collection.DATABASE_LABEL).withProperty(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, "person").withProperty(Collection.COLLECTION_NAME_PROPERTY_NAME, "persons").withOutgoingRelation(Collection.HAS_ENTITY_NODE_RELATION_NAME, linkingNodePersonsName)).withVertex(v -> v.withLabel(Collection.DATABASE_LABEL).withProperty(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, "wwperson").withProperty(Collection.COLLECTION_NAME_PROPERTY_NAME, "wwpersons").withOutgoingRelation(Collection.HAS_ENTITY_NODE_RELATION_NAME, linkingNodeWwPersonsName)).withVertex(v -> v.withProperty("types", typesJson).withTimId(updateThisVertexName).withIncomingRelation(Collection.HAS_ENTITY_RELATION_NAME, linkingNodePersonsName).withIncomingRelation(Collection.HAS_ENTITY_RELATION_NAME, linkingNodeWwPersonsName));
    final GraphWrapper graphWrapper = builder.wrap();
    Vertex updatedVertex = graphWrapper.getGraph().traversal().V().has("tim_id", updateThisVertexName).next();
    CollectionHasEntityRelationChangeListener instance = new CollectionHasEntityRelationChangeListener(graphWrapper);
    instance.onRemoveFromCollection(forEntitytypeName("ww", "person"), Optional.empty(), updatedVertex);
    final List<Vertex> actualLinkingNodes = Lists.newArrayList(updatedVertex.vertices(Direction.IN, Collection.HAS_ENTITY_RELATION_NAME));
    assertThat(actualLinkingNodes, contains(likeVertex().withProperty("check", linkingNodePersonsName)));
}
Also used : TestGraphBuilder(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder) CollectionStubs.forEntitytypeName(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionStubs.forEntitytypeName) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Direction(org.apache.tinkerpop.gremlin.structure.Direction) List(java.util.List) Lists(com.google.common.collect.Lists) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Optional(java.util.Optional) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) TestGraphBuilder(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

TestGraphBuilder (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Lists (com.google.common.collect.Lists)2 List (java.util.List)2 Optional (java.util.Optional)2 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)2 CollectionStubs.forEntitytypeName (nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionStubs.forEntitytypeName)2 GraphWrapper (nl.knaw.huygens.timbuctoo.server.GraphWrapper)2 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)2 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)2 Direction (org.apache.tinkerpop.gremlin.structure.Direction)2 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.contains (org.hamcrest.Matchers.contains)2 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)2 Test (org.junit.Test)2 TinkerPopGraphManager (nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager)1