Search in sources :

Example 6 with GraphWrapper

use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.

the class CollectionTest method addPropertyOnlyAddsThePropertyConfigurationForNewProperties.

@Test
public void addPropertyOnlyAddsThePropertyConfigurationForNewProperties() {
    CollectionDescription description = mock(CollectionDescription.class);
    String collectionPropertyName = "propertyName";
    when(description.createPropertyName(anyString())).thenReturn(collectionPropertyName);
    when(description.getVreName()).thenReturn(VRE_NAME);
    String propName = "propName";
    GraphWrapper graphWrapper = newGraph().withVertex(v -> v.withLabel(DATABASE_LABEL).withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, ENTITY_NAME).withProperty(COLLECTION_NAME_PROPERTY_NAME, COLLECTION_NAME)).wrap();
    Vertex collectionVertex = graphWrapper.getGraph().traversal().V().next();
    Collection instance = new Collection(VRE_NAME, collectionVertex, graphWrapper, description);
    Vertex entityVertex = mock(Vertex.class);
    String propValue = "propValue";
    Vertex otherVertex = mock(Vertex.class);
    instance.addProperty(entityVertex, propName, propValue, type);
    instance.addProperty(otherVertex, propName, propValue, type);
    assertThat(graphWrapper.getGraph().traversal().V(collectionVertex.id()).out(HAS_PROPERTY_RELATION_NAME).has("dbName", collectionPropertyName).has("clientName", propName).count().next(), is(1L));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HAS_ARCHETYPE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ARCHETYPE_RELATION_NAME) LocalProperty(nl.knaw.huygens.timbuctoo.model.properties.LocalProperty) PROPERTY_TYPE_NAME(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty.PROPERTY_TYPE_NAME) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) DATABASE_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.model.properties.LocalProperty.DATABASE_PROPERTY_NAME) Matchers.not(org.hamcrest.Matchers.not) CLIENT_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty.CLIENT_PROPERTY_NAME) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) HAS_INITIAL_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_INITIAL_PROPERTY_RELATION_NAME) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) FastNoSuchElementException(org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException) StringToStringConverter(nl.knaw.huygens.timbuctoo.model.properties.converters.StringToStringConverter) HAS_ENTITY_NODE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME) Iterator(java.util.Iterator) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Mockito.when(org.mockito.Mockito.when) T(org.apache.tinkerpop.gremlin.structure.T) HAS_NEXT_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty.HAS_NEXT_PROPERTY_RELATION_NAME) Mockito.verify(org.mockito.Mockito.verify) DATABASE_LABEL(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.DATABASE_LABEL) Mockito.never(org.mockito.Mockito.never) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Matchers.hasItem(org.hamcrest.Matchers.hasItem) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) RDF_URI_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_URI_PROP) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) HAS_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PROPERTY_RELATION_NAME) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 7 with GraphWrapper

use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.

the class CollectionTest method setArchetypeConnectsTheCollectionToTheNewArchetype.

@Test
public void setArchetypeConnectsTheCollectionToTheNewArchetype() {
    String newArchetypeEntity = "newArchetype";
    GraphWrapper graphWrapper = newGraph().withVertex(v -> v.withLabel(DATABASE_LABEL).withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, ENTITY_NAME).withProperty(COLLECTION_NAME_PROPERTY_NAME, COLLECTION_NAME)).withVertex(v -> v.withLabel(DATABASE_LABEL).withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, newArchetypeEntity)).wrap();
    Vertex collectionVertex = graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of(DATABASE_LABEL)).has(ENTITY_TYPE_NAME_PROPERTY_NAME, ENTITY_NAME).next();
    Collection instance = new Collection(VRE_NAME, collectionVertex, graphWrapper);
    Vertex archetypeVertex = graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of(DATABASE_LABEL)).has(ENTITY_TYPE_NAME_PROPERTY_NAME, newArchetypeEntity).next();
    Collection archetype = new Collection("", archetypeVertex, graphWrapper);
    instance.setArchetype(archetype, "");
    assertThat(graphWrapper.getGraph().traversal().V(collectionVertex.id()).out(HAS_ARCHETYPE_RELATION_NAME).toList(), hasItem(likeVertex().withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, newArchetypeEntity)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HAS_ARCHETYPE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ARCHETYPE_RELATION_NAME) LocalProperty(nl.knaw.huygens.timbuctoo.model.properties.LocalProperty) PROPERTY_TYPE_NAME(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty.PROPERTY_TYPE_NAME) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) DATABASE_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.model.properties.LocalProperty.DATABASE_PROPERTY_NAME) Matchers.not(org.hamcrest.Matchers.not) CLIENT_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty.CLIENT_PROPERTY_NAME) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) HAS_INITIAL_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_INITIAL_PROPERTY_RELATION_NAME) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) FastNoSuchElementException(org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException) StringToStringConverter(nl.knaw.huygens.timbuctoo.model.properties.converters.StringToStringConverter) HAS_ENTITY_NODE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME) Iterator(java.util.Iterator) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Mockito.when(org.mockito.Mockito.when) T(org.apache.tinkerpop.gremlin.structure.T) HAS_NEXT_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty.HAS_NEXT_PROPERTY_RELATION_NAME) Mockito.verify(org.mockito.Mockito.verify) DATABASE_LABEL(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.DATABASE_LABEL) Mockito.never(org.mockito.Mockito.never) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Matchers.hasItem(org.hamcrest.Matchers.hasItem) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) RDF_URI_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_URI_PROP) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) HAS_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PROPERTY_RELATION_NAME) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 8 with GraphWrapper

use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.

the class CollectionTest method addPropertyAddsThePropertyForTheCurrentCollectionToTheEntityVertex.

@Test
public void addPropertyAddsThePropertyForTheCurrentCollectionToTheEntityVertex() {
    CollectionDescription description = mock(CollectionDescription.class);
    String collectionPropertyName = "propertyName";
    when(description.createPropertyName(anyString())).thenReturn(collectionPropertyName);
    when(description.getVreName()).thenReturn(VRE_NAME);
    GraphWrapper graphWrapper = newGraph().withVertex(v -> v.withLabel(DATABASE_LABEL).withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, ENTITY_NAME).withProperty(COLLECTION_NAME_PROPERTY_NAME, COLLECTION_NAME)).wrap();
    Vertex collectionVertex = graphWrapper.getGraph().traversal().V().next();
    Collection instance = new Collection(VRE_NAME, collectionVertex, graphWrapper, description);
    Vertex entityVertex = mock(Vertex.class);
    String propValue = "propValue";
    instance.addProperty(entityVertex, "propName", propValue, type);
    verify(entityVertex).property(collectionPropertyName, propValue);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HAS_ARCHETYPE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ARCHETYPE_RELATION_NAME) LocalProperty(nl.knaw.huygens.timbuctoo.model.properties.LocalProperty) PROPERTY_TYPE_NAME(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty.PROPERTY_TYPE_NAME) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) DATABASE_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.model.properties.LocalProperty.DATABASE_PROPERTY_NAME) Matchers.not(org.hamcrest.Matchers.not) CLIENT_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty.CLIENT_PROPERTY_NAME) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) HAS_INITIAL_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_INITIAL_PROPERTY_RELATION_NAME) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) FastNoSuchElementException(org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException) StringToStringConverter(nl.knaw.huygens.timbuctoo.model.properties.converters.StringToStringConverter) HAS_ENTITY_NODE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME) Iterator(java.util.Iterator) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Mockito.when(org.mockito.Mockito.when) T(org.apache.tinkerpop.gremlin.structure.T) HAS_NEXT_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty.HAS_NEXT_PROPERTY_RELATION_NAME) Mockito.verify(org.mockito.Mockito.verify) DATABASE_LABEL(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.DATABASE_LABEL) Mockito.never(org.mockito.Mockito.never) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Matchers.hasItem(org.hamcrest.Matchers.hasItem) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) RDF_URI_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_URI_PROP) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) HAS_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PROPERTY_RELATION_NAME) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with GraphWrapper

use of nl.knaw.huygens.timbuctoo.server.GraphWrapper 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 10 with GraphWrapper

use of nl.knaw.huygens.timbuctoo.server.GraphWrapper 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

GraphWrapper (nl.knaw.huygens.timbuctoo.server.GraphWrapper)31 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)31 Test (org.junit.Test)31 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)28 Mockito.mock (org.mockito.Mockito.mock)25 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)24 Mockito.verify (org.mockito.Mockito.verify)23 EdgeMatcher.likeEdge (nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge)22 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)20 MockitoHamcrest.argThat (org.mockito.hamcrest.MockitoHamcrest.argThat)18 Iterator (java.util.Iterator)17 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)17 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)15 COLLECTION_NAME_PROPERTY_NAME (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME)13 DATABASE_LABEL (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.DATABASE_LABEL)13 ENTITY_TYPE_NAME_PROPERTY_NAME (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME)13 HAS_ARCHETYPE_RELATION_NAME (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ARCHETYPE_RELATION_NAME)13 HAS_DISPLAY_NAME_RELATION_NAME (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME)13 HAS_ENTITY_NODE_RELATION_NAME (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME)13 HAS_ENTITY_RELATION_NAME (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME)13