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));
}
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)));
}
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);
}
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)));
}
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)));
}
Aggregations