use of nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityUpdatesTheRevisionByOne.
@Test
public void replaceEntityUpdatesTheRevisionByOne() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id.toString()).withProperty("isLatest", true).withProperty("rev", 1).withIncomingRelation("VERSION_OF", "orig")).withVertex("orig", v -> v.withTimId(id.toString()).withProperty("isLatest", false).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
UpdateEntity updateEntity = new UpdateEntity(id, Lists.newArrayList(), 1);
updateEntity.setModified(new Change(Instant.now().toEpochMilli(), "userId", null));
instance.replaceEntity(collection, updateEntity);
int rev = (int) graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).values("rev").next();
assertThat(rev, is(2));
}
use of nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityUpdatesModified.
@Test
public void replaceEntityUpdatesModified() 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);
UpdateEntity updateEntity = new UpdateEntity(id, Lists.newArrayList(), 1);
long timeStamp = Instant.now().toEpochMilli();
updateEntity.setModified(new Change(timeStamp, "userId", null));
instance.replaceEntity(collection, updateEntity);
String modified = (String) graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).properties("modified").value().next();
assertThat(modified, sameJSONAs(String.format("{\"timeStamp\": %s,\"userId\": \"%s\"}", timeStamp, "userId")));
}
use of nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityMovesTheRelationsToTheNewVertex.
@Test
public void replaceEntityMovesTheRelationsToTheNewVertex() 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).withOutgoingRelation("hasWritten", "stuff").withIncomingRelation("isFriendOf", "friend")).withVertex("stuff", v -> v.withVre("test").withType("stuff").isLatest(true).withProperty("rev", 1)).withVertex("friend", v -> v.withVre("test").withType("thing").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 origVertex = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
assertThat(stream(origVertex.edges(Direction.BOTH, "hasWritten", "isFriendOf")).count(), is(2L));
instance.replaceEntity(collection, updateEntity);
Vertex newVertex = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
assertThat(stream(origVertex.edges(Direction.BOTH, "hasWritten", "isFriendOf")).count(), is(0L));
assertThat(stream(newVertex.edges(Direction.BOTH, "hasWritten", "isFriendOf")).count(), is(2L));
}
use of nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityThrowsANotFoundExceptionWhenTheEntityIsNotInTheDatabase.
@Test(expected = NotFoundException.class)
public void replaceEntityThrowsANotFoundExceptionWhenTheEntityIsNotInTheDatabase() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager emptyDatabase = newGraph().wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(emptyDatabase, vres);
UpdateEntity updateEntity = new UpdateEntity(id, Lists.newArrayList(), 1);
long timeStamp = Instant.now().toEpochMilli();
updateEntity.setModified(new Change(timeStamp, "userId", null));
instance.replaceEntity(collection, updateEntity);
}
use of nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityAddsAType.
@Test
public void replaceEntityAddsAType() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id).withVre("other").withType("thing").withProperty("isLatest", true).withProperty("rev", 1).withProperty("otherthing_prop1", "the name").withIncomingRelation("VERSION_OF", "orig")).withVertex("orig", v -> v.withTimId(id).withVre("other").withType("thing").withProperty("isLatest", false).withProperty("rev", 1).withProperty("otherthing_prop1", "the name")).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
UpdateEntity updateEntity = new UpdateEntity(id, Lists.newArrayList(), 1);
updateEntity.setModified(new Change(Instant.now().toEpochMilli(), "userId", null));
instance.replaceEntity(collection, updateEntity);
String types = (String) graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).values("types").next();
assertThat(types, containsString("\"testthing\""));
}
Aggregations