use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class DatabaseTest method copyEdgesFromObjectIntoSubjectCopiesTheOutgoingEdgesOfTheObjectIntoTheSubject.
@Test
public void copyEdgesFromObjectIntoSubjectCopiesTheOutgoingEdgesOfTheObjectIntoTheSubject() {
TinkerPopGraphManager graphWrapper = newGraph().withVertex("target1", v -> {
v.withTimId("789");
}).withVertex("target2", v -> {
v.withTimId("abc");
}).withVertex("entity1", v -> {
v.withTimId("123").withOutgoingRelation("relatedTo", "target1", edge -> edge.withRev(9));
}).withVertex("entity2", v -> {
v.withTimId("456").withOutgoingRelation("relatedTo", "target1", edge -> edge.withRev(1337)).withOutgoingRelation("relatedTo", "target2", edge -> edge.withRev(12));
}).wrap();
final String vreName = "vreName";
final Vertex subjectVertex = graphWrapper.getGraph().traversal().V().has("tim_id", "123").next();
final Vertex objectVertex = graphWrapper.getGraph().traversal().V().has("tim_id", "456").next();
final Entity subject = new Entity(subjectVertex, null, null, null);
final Entity object = new Entity(objectVertex, null, null, null);
final Database instance = new Database(graphWrapper);
instance.copyEdgesFromObjectIntoSubject(subject, object);
final List<Edge> edges = graphWrapper.getGraph().traversal().V().has("tim_id", "123").outE("relatedTo").toList();
assertThat(edges.size(), equalTo(2));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class DatabaseTest method findArchetypeCollectionReturnsTheArchetypeCollectionWrappedInAnOptional.
@Test
public void findArchetypeCollectionReturnsTheArchetypeCollectionWrappedInAnOptional() {
TinkerPopGraphManager graphWrapper = newGraph().withVertex(v -> v.withLabel(Vre.DATABASE_LABEL).withProperty(Vre.VRE_NAME_PROPERTY_NAME, "Admin").withOutgoingRelation(Vre.HAS_COLLECTION_RELATION_NAME, "defaultArchetype").withOutgoingRelation(Vre.HAS_COLLECTION_RELATION_NAME, "knownArchetype")).withVertex("defaultArchetype", v -> v.withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "concept").withProperty(COLLECTION_NAME_PROPERTY_NAME, "concepts")).withVertex("knownArchetype", v -> v.withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "knownArchetype").withProperty(COLLECTION_NAME_PROPERTY_NAME, "knownArchetypes")).wrap();
Node node = mock(Node.class);
when(node.getLocalName()).thenReturn("knownArchetype");
Database instance = new Database(graphWrapper);
Optional<Collection> archetypeCollection = instance.findArchetypeCollection(node.getLocalName());
assertThat(archetypeCollection, is(present()));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class DatabaseTest method findOrCreateCollectionAddsTheCollectionToItsArchetype.
@Test
public void findOrCreateCollectionAddsTheCollectionToItsArchetype() {
String rdfUri = "http://www.example.com/entity";
String localName = "entity";
TinkerPopGraphManager graphWrapper = newGraph().withVertex(v -> v.withLabel(Vre.DATABASE_LABEL).withProperty("name", VRE_NAME)).withVertex(v -> {
v.withLabel(Vre.DATABASE_LABEL);
v.withProperty(Vre.VRE_NAME_PROPERTY_NAME, "Admin");
v.withOutgoingRelation(Vre.HAS_COLLECTION_RELATION_NAME, "defaultArchetype");
}).withVertex("defaultArchetype", v -> {
v.withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "concept");
v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "concepts");
}).wrap();
Node collectionNode = mock(Node.class);
when(collectionNode.getLocalName()).thenReturn(localName);
when(collectionNode.getURI()).thenReturn(rdfUri);
Database instance = new Database(graphWrapper);
Collection collection = instance.findOrCreateCollection(VRE_NAME, collectionNode.getURI(), collectionNode.getLocalName());
assertThat(collection, hasProperty("vreName", equalTo(VRE_NAME)));
assertThat(graphWrapper.getGraph().traversal().V().hasLabel(DATABASE_LABEL).has(RDF_URI_PROP, rdfUri).out(HAS_ARCHETYPE_RELATION_NAME).hasNext(), is(true));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class DatabaseTest method findOrCreateEntityGivesABlankNodeADefaultUri.
@Test
public void findOrCreateEntityGivesABlankNodeADefaultUri() {
TinkerPopGraphManager graphWrapper = newGraph().withVertex(v -> v.withLabel(Vre.DATABASE_LABEL).withProperty("name", VRE_NAME)).withVertex(v -> {
v.withLabel(Vre.DATABASE_LABEL);
v.withProperty(Vre.VRE_NAME_PROPERTY_NAME, "Admin");
v.withOutgoingRelation(Vre.HAS_COLLECTION_RELATION_NAME, "defaultArchetype");
}).withVertex("defaultArchetype", v -> {
v.withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "concept");
v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "concepts");
v.withOutgoingRelation(HAS_ENTITY_NODE_RELATION_NAME, "entityCollection");
}).withVertex("entityCollection", v -> {
}).wrap();
final Database instance = new Database(graphWrapper, modifier);
Node blankNode = TripleCreator.createBlankNode();
String expectedUri = VRE_NAME + ":" + blankNode.getBlankNodeLabel();
Entity entity = instance.findOrCreateEntity(VRE_NAME, blankNode);
assertThat(entity, is(notNullValue()));
assertThat(entity.vertex.value(RDF_SYNONYM_PROP), is(new String[] { expectedUri }));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class DatabaseTest method findOrCreateRelationTypeReturnsAnExistingRelationType.
// FIXME: should now be tested using rdf Index
@Ignore
@Test
public void findOrCreateRelationTypeReturnsAnExistingRelationType() {
final String relationtypePrefix = "relationtype_";
String rdfUriVal = "rdfUriVal";
final TinkerPopGraphManager graphWrapper = newGraph().withVertex(v -> v.withLabel("relationtype").withProperty("rdfUri", rdfUriVal).withProperty("types", "[\"relationtype\"]").withProperty(relationtypePrefix + "targetTypeName", "concept").withProperty(relationtypePrefix + "sourceTypeName", "concept").withProperty(relationtypePrefix + "symmetric", false).withProperty(relationtypePrefix + "reflexive", false).withProperty(relationtypePrefix + "derived", false).withProperty(relationtypePrefix + "regularName", RELATION_NAME).withProperty(relationtypePrefix + "inverseName", "inverse:" + RELATION_NAME).withProperty("rev", 1).withProperty("isLatest", true)).wrap();
final Database instance = new Database(graphWrapper);
instance.findOrCreateRelationType(rdfUriVal, RELATION_NAME);
assertThat(graphWrapper.getGraph().traversal().V().hasLabel("relationtype").count().next(), is(1L));
}
Aggregations