use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method assertPropertyWillKeepTrackOfThePredicate.
@Test
public void assertPropertyWillKeepTrackOfThePredicate() {
TinkerPopOperations instance = TinkerPopOperationsStubs.newInstance();
Vre vre = instance.ensureVreExists("vre");
instance.addCollectionToVre(vre, CreateCollection.defaultCollection("vre"));
instance.addPredicateValueTypeVertexToVre(vre);
vre = instance.loadVres().getVre("vre");
Collection defaultCollection = vre.getCollectionForTypeName(defaultEntityTypeName(vre));
instance.assertProperty(vre, "http://example.org/1", new RdfProperty("http://example.org/propName", "value", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"));
instance.assertProperty(vre, "http://example.org/2", new RdfProperty("http://example.org/propName", "value", "http://www.w3.org/2001/XMLSchema#float"));
List<PredicateInUse> predicates = instance.getPredicatesFor(defaultCollection);
assertThat(predicates, contains(hasProperty("predicateUri", equalTo("http://example.org/propName"))));
List<ValueTypeInUse> valueTypes = predicates.get(0).getValueTypes();
assertThat(valueTypes, containsInAnyOrder(allOf(hasProperty("typeUri", equalTo("http://www.w3.org/2001/XMLSchema#float")), hasProperty("entitiesConnected", contains("http://example.org/2"))), allOf(hasProperty("typeUri", equalTo("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString")), hasProperty("entitiesConnected", contains("http://example.org/1")))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method acceptRelationsThrowsARelationNotPossibleExceptionIfTheTypeOfTheTargetIsInvalid.
@Test(expected = RelationNotPossibleException.class)
public void acceptRelationsThrowsARelationNotPossibleExceptionIfTheTypeOfTheTargetIsInvalid() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testrelations").get();
UUID typeId = UUID.randomUUID();
UUID sourceId = UUID.randomUUID();
UUID targetId = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(typeId.toString()).withType("relationtype").withProperty("relationtype_regularName", "isRelatedTo").withProperty("relationtype_sourceTypeName", "testthing").withProperty("relationtype_targeTypeName", "teststuff").withProperty("rev", 1).withProperty("isLatest", true)).withVertex(v -> v.withTimId(sourceId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).withVertex(v -> v.withTimId(targetId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
CreateRelation createRelation = new CreateRelation(sourceId, typeId, targetId);
createRelation.setCreated(new Change(Instant.now().toEpochMilli(), "userId", null));
instance.acceptRelation(collection, createRelation);
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getCollectionReturnsAllTheLatestEntitiesOfACollection.
@Test
public void getCollectionReturnsAllTheLatestEntitiesOfACollection() {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
UUID id3 = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withLabel("testthing").withType("thing").withVre("test").isLatest(true).withTimId(id1.toString())).withVertex(v -> v.withLabel("testthing").withType("thing").withVre("test").isLatest(true).withTimId(id2.toString())).withVertex(v -> v.withLabel("testthing").withType("thing").withVre("test").isLatest(false).withTimId(id2.toString())).withVertex(v -> v.withLabel("testthing").withType("thing").withVre("test").isLatest(true).withTimId(id3.toString())).withVertex(v -> v.withLabel("teststuff").withType("stuff").withVre("test").isLatest(true).withTimId(UUID.randomUUID().toString())).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
DataStream<ReadEntity> entities = instance.getCollection(collection, 0, 3, false, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
List<UUID> ids = entities.map(ReadEntity::getId);
assertThat(ids, hasSize(3));
assertThat(ids, containsInAnyOrder(id1, id2, id3));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityThrowsNotFoundIfTheEntityDoesNotContainTheRequestType.
@Test(expected = NotFoundException.class)
public void getEntityThrowsNotFoundIfTheEntityDoesNotContainTheRequestType() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id.toString()).withType("thing").withVre("other").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceRelationUpdatesTheRevisionByOne.
@Test
public void replaceRelationUpdatesTheRevisionByOne() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testrelations").get();
UUID typeId = UUID.randomUUID();
UUID sourceId = UUID.randomUUID();
UUID targetId = UUID.randomUUID();
UUID relId = UUID.randomUUID();
int relationRev = 1;
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(typeId.toString()).withType("relationtype").withProperty("relationtype_regularName", "regularName").withProperty("rev", 1).withProperty("isLatest", true)).withVertex(v -> v.withTimId(sourceId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true).withOutgoingRelation("regularName", "otherVertex", r -> r.withTim_id(relId).withAccepted("testrelation", true).withTypeId(typeId).withRev(relationRev).addType("testrelation"))).withVertex("otherVertex", v -> v.withTimId(targetId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).wrap();
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.findEdgeById(relId)).thenReturn(Optional.of(graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).next()));
TinkerPopOperations instance = forGraphMappingsAndIndex(graphManager, vres, indexHandler);
UpdateRelation updateRelation = new UpdateRelation(relId, 1, false);
updateRelation.setModified(new Change(Instant.now().toEpochMilli(), "userId", null));
instance.replaceRelation(collection, updateRelation);
assertThat(graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).has("isLatest", true).next(), is(likeEdge().withProperty("rev", relationRev + 1)));
}
Aggregations