use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME in project timbuctoo by HuygensING.
the class DatabaseTest method isKnowArchetypeChecksIfTheCollectionWithTheNameIsAKnowArchetype.
@Test
public void isKnowArchetypeChecksIfTheCollectionWithTheNameIsAKnowArchetype() {
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();
Database instance = new Database(graphWrapper);
assertThat(instance.isKnownArchetype("knownArchetype"), is(true));
assertThat(instance.isKnownArchetype("unknownArchetype"), is(false));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME in project timbuctoo by HuygensING.
the class DatabaseTest method findOrCreateCollectionReturnsTheNewlyAddedCollectionWithRdfUri.
@Test
public void findOrCreateCollectionReturnsTheNewlyAddedCollectionWithRdfUri() {
String vreName = "vreName";
String rdfUri = "http://www.example.com/entity";
String localName = "entity";
TinkerPopGraphManager graphWrapper = newGraph().withVertex(v -> v.withLabel(Vre.DATABASE_LABEL).withProperty("name", vreName)).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(vreName, collectionNode.getURI(), collectionNode.getLocalName());
assertThat(collection, hasProperty("vreName", equalTo(vreName)));
assertThat(graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of(Vre.DATABASE_LABEL)).out(Vre.HAS_COLLECTION_RELATION_NAME).has(RDF_URI_PROP, rdfUri).hasNext(), is(true));
assertThat(graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of(Vre.DATABASE_LABEL)).out(Vre.HAS_COLLECTION_RELATION_NAME).has(RDF_URI_PROP, rdfUri).out(HAS_ENTITY_NODE_RELATION_NAME).hasNext(), is(true));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME in project timbuctoo by HuygensING.
the class DatabaseTest method findOrCreateCollectionReturnsTheCollectionForARequestedVre.
@Test
public void findOrCreateCollectionReturnsTheCollectionForARequestedVre() {
String vreName = "vreName";
String rdfUri = "http://www.example.com/entity";
String localName = "entity";
TinkerPopGraphManager graphWrapper = newGraph().withVertex(v -> v.withLabel(Vre.DATABASE_LABEL).withProperty("name", vreName).withOutgoingRelation(Vre.HAS_COLLECTION_RELATION_NAME, "collection")).withVertex("collection", v -> v.withLabel("collection").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, localName)).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.withIncomingRelation(HAS_ARCHETYPE_RELATION_NAME, "collection");
}).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(vreName, collectionNode.getURI(), collectionNode.getLocalName());
assertThat(collection, hasProperty("vreName", equalTo(vreName)));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME in project timbuctoo by HuygensING.
the class DatabaseTest method findOrCreateEntityAddsANewlyCreatedEntityToTheDefaultCollection.
@Test
public void findOrCreateEntityAddsANewlyCreatedEntityToTheDefaultCollection() {
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);
Entity entity = instance.findOrCreateEntity(VRE_NAME, entityNode);
assertThat(entity, is(notNullValue()));
assertThat(graphWrapper.getGraph().traversal().V(entity.vertex.id()).in(HAS_ENTITY_RELATION_NAME).in(HAS_ENTITY_NODE_RELATION_NAME).has(ENTITY_TYPE_NAME_PROPERTY_NAME, DEFAULT_COLLECTION).hasNext(), is(true));
assertThat(graphWrapper.getGraph().traversal().V(entity.vertex.id()).next(), is(likeVertex().withLabel(DEFAULT_COLLECTION).withType(DEFAULT_COLLECTION)));
}
Aggregations