use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method assertEntitySetsTheRdfUriProperty.
@Test
public void assertEntitySetsTheRdfUriProperty() {
TinkerPopGraphManager graphManager = newGraph().wrap();
TinkerPopOperations instance = forGraphWrapper(graphManager);
Vre vre = minimalCorrectVre(instance, "vre");
instance.assertEntity(vre, "http://example.org/1");
assertThat(graphManager.getGraph().traversal().V().values(RDF_SYNONYM_PROP).next(), is(new String[] { "http://example.org/1" }));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager 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.server.TinkerPopGraphManager 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.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method assertEntityDoesNotReCreateEntitiesThatAlreadyExist.
@Test
public void assertEntityDoesNotReCreateEntitiesThatAlreadyExist() {
TinkerPopGraphManager graphManager = newGraph().wrap();
TinkerPopOperations instance = forGraphWrapper(graphManager);
Vre vre = minimalCorrectVre(instance, "vre");
long administrativeVertices = graphManager.getGraph().traversal().V().count().next();
instance.assertEntity(vre, "http://example.org/1");
instance.assertEntity(vre, "http://example.org/1");
assertThat(graphManager.getGraph().traversal().V().count().next(), is(administrativeVertices + 1));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager 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);
}
Aggregations