use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityReturnsANullPidWhenTheEntityDoesNotContainOne.
@Test
public void getEntityReturnsANullPidWhenTheEntityDoesNotContainOne() 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("test").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ReadEntity entity = instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getPid(), is(nullValue()));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteEntityRemovesTypeWhenOtherTypesExist.
@Test
public void deleteEntityRemovesTypeWhenOtherTypesExist() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
String idString = id.toString();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(idString).withVre("test").withVre("other").withType("thing").withProperty("isLatest", true).withProperty("rev", 1).withLabel("testthing").withLabel("otherthing")).wrap();
GremlinEntityFetcher entityFetcher = new GremlinEntityFetcher();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
String types = (String) graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).properties("types").value().next();
assertThat(types, is("[\"otherthing\"]"));
// Type should also be removed from the Neo4j labels
assertThat(graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).has(T.label, LabelP.of("testthing")).hasNext(), is(false));
// Other type should not be removed from the Neo4j labels
assertThat(graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).has(T.label, LabelP.of("otherthing")).hasNext(), is(true));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteEntitythrowsNotFoundWhenTheIdIsNotInTheDatabase.
@Test(expected = NotFoundException.class)
public void deleteEntitythrowsNotFoundWhenTheIdIsNotInTheDatabase() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
instance.deleteEntity(collection, id, null);
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityMapsTheId.
@Test
public void getEntityMapsTheId() 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("test").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ReadEntity entity = instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getId(), is(id));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityPreparesABackupCopyAfterMakingTheChanges.
@Test
public void replaceEntityPreparesABackupCopyAfterMakingTheChanges() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id).withVre("test").withType("thing").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
List<TimProperty<?>> properties = Lists.newArrayList(new StringProperty("prop1", "newValue"));
UpdateEntity updateEntity = new UpdateEntity(id, properties, 1);
long timeStamp = Instant.now().toEpochMilli();
updateEntity.setModified(new Change(timeStamp, "userId", null));
Vertex beforeUpdate = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
instance.replaceEntity(collection, updateEntity);
Vertex afterUpdate = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
assertThat(afterUpdate.id(), is(not(beforeUpdate.id())));
assertThat(afterUpdate.edges(Direction.IN).next().outVertex().id(), is(beforeUpdate.id()));
}
Aggregations