use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME 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.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME 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.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME 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.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME in project timbuctoo by HuygensING.
the class DatabaseTest method findEntitiesByCollectionReturnsAllTheEntitiesOfTheCollection.
@Test
public void findEntitiesByCollectionReturnsAllTheEntitiesOfTheCollection() {
CollectionDescription desc = CollectionDescription.createCollectionDescription("collection", VRE_NAME);
TinkerPopGraphManager graphWrapper = newGraph().withVertex("collection", v -> v.withLabel(DATABASE_LABEL).withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, desc.getEntityTypeName()).withProperty(COLLECTION_NAME_PROPERTY_NAME, desc.getCollectionName()).withOutgoingRelation(HAS_ENTITY_NODE_RELATION_NAME, "entityVertex")).withVertex("entityVertex", v -> v.withOutgoingRelation(HAS_ENTITY_RELATION_NAME, "entity1").withOutgoingRelation(HAS_ENTITY_RELATION_NAME, "entity2")).withVertex("entity1", v -> {
}).withVertex("entity2", v -> {
}).withVertex("entityOfOtherCollection", v -> {
}).wrap();
Database instance = new Database(graphWrapper);
Collection collection = mock(Collection.class);
when(collection.getDescription()).thenReturn(desc);
Set<Entity> entitiesByCollection = instance.findEntitiesByCollection(collection);
assertThat(entitiesByCollection, hasSize(2));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME in project timbuctoo by HuygensING.
the class LoadSaveCollectionTest method saveThrowsWhenTheCollectionNameIsNotUniqueToThisVre.
@Test(expected = IllegalArgumentException.class)
public void saveThrowsWhenTheCollectionNameIsNotUniqueToThisVre() {
Graph graph = newGraph().withVertex(v -> {
v.withLabel(Collection.DATABASE_LABEL).withProperty(COLLECTION_NAME_PROPERTY_NAME, "persons").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "person").withIncomingRelation(Vre.HAS_COLLECTION_RELATION_NAME, "vre");
}).withVertex("vre", v -> {
v.withLabel(Vre.DATABASE_LABEL).withProperty(Vre.VRE_NAME_PROPERTY_NAME, "OtherVreName");
}).build();
save(new Collection("person", "person", null, Maps.newLinkedHashMap(), "persons", new Vre(vreName), null, false, false, null), graph);
}
Aggregations