use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.DATABASE_LABEL 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.DATABASE_LABEL in project timbuctoo by HuygensING.
the class CollectionTest method addPropertyAddsHasNextEdgeBetweenTheProperties.
@Test
public void addPropertyAddsHasNextEdgeBetweenTheProperties() {
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);
instance.addProperty(mock(Vertex.class), "prop1", "val1", type);
instance.addProperty(mock(Vertex.class), "prop2", "val2", type);
instance.addProperty(mock(Vertex.class), "prop3", "val3", type);
assertThat(graphWrapper.getGraph().traversal().V(collectionVertex.id()).out(HAS_INITIAL_PROPERTY_RELATION_NAME).out(HAS_NEXT_PROPERTY_RELATION_NAME).out(HAS_NEXT_PROPERTY_RELATION_NAME).count().next(), is(1L));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.DATABASE_LABEL in project timbuctoo by HuygensING.
the class CollectionTest method addPropertyDoesNotAddAPropConfigWhenTheCollectionIsAnArchetype.
@Test
public void addPropertyDoesNotAddAPropConfigWhenTheCollectionIsAnArchetype() {
GraphWrapper graphWrapper = newGraph().withVertex(v -> v.withLabel(DATABASE_LABEL).withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "concept").withProperty(COLLECTION_NAME_PROPERTY_NAME, "concepts")).wrap();
Vertex collectionVertex = graphWrapper.getGraph().traversal().V().next();
CollectionDescription collectionDescription = CollectionDescription.createForAdmin("concept");
Collection instance = new Collection("Admin", collectionVertex, graphWrapper, collectionDescription);
Vertex entityVertex = mock(Vertex.class);
instance.addProperty(entityVertex, "prop1", "val1", type);
assertThat(graphWrapper.getGraph().traversal().V(collectionVertex.id()).out(HAS_PROPERTY_RELATION_NAME).count().next(), is(0L));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.DATABASE_LABEL in project timbuctoo by HuygensING.
the class CollectionTest method setArchetypeSetsTheUriOfTheOriginalArchetypeToEdgeToTheArchetype.
@Test
public void setArchetypeSetsTheUriOfTheOriginalArchetypeToEdgeToTheArchetype() {
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);
String originalArchetypeUri = "http://example.com/originalArchetype";
instance.setArchetype(archetype, originalArchetypeUri);
assertThat(graphWrapper.getGraph().traversal().V(collectionVertex.id()).outE(HAS_ARCHETYPE_RELATION_NAME).toList(), hasItem(likeEdge().withProperty(RDF_URI_PROP, originalArchetypeUri)));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.DATABASE_LABEL in project timbuctoo by HuygensING.
the class CollectionTest method removeDoesNothingWhenTheEntityIsNotPartOfTheCollection.
@Test
public void removeDoesNothingWhenTheEntityIsNotPartOfTheCollection() {
GraphWrapper graphWrapper = newGraph().withVertex("collection", v -> v.withLabel(DATABASE_LABEL).withOutgoingRelation(HAS_ENTITY_NODE_RELATION_NAME, "entityNode").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, ENTITY_NAME).withProperty(COLLECTION_NAME_PROPERTY_NAME, COLLECTION_NAME)).withVertex("entityNode", v -> {
}).withVertex("entity", v -> v.withLabel("entity")).wrap();
Vertex collectionVertex = graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of(DATABASE_LABEL)).next();
Vertex entityVertex = graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of("entity")).next();
Collection instance = new Collection(VRE_NAME, collectionVertex, graphWrapper);
try {
instance.remove(entityVertex);
} catch (FastNoSuchElementException e) {
fail("Should not throw an exception.");
}
}
Aggregations