use of nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty 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.property.StringProperty in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityUpdatesTheKnownProperties.
@Test
public void replaceEntityUpdatesTheKnownProperties() 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("testthing_prop1", "oldValue").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ArrayList<TimProperty<?>> properties = Lists.newArrayList(new StringProperty("prop1", "newValue"), new StringProperty("prop2", "prop2Value"));
UpdateEntity updateEntity = new UpdateEntity(id, properties, 1);
long timeStamp = Instant.now().toEpochMilli();
updateEntity.setModified(new Change(timeStamp, "userId", null));
instance.replaceEntity(collection, updateEntity);
Vertex vertex = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
assertThat(vertex, is(likeVertex().withProperty("testthing_prop1", "newValue").withProperty("testthing_prop2", "prop2Value")));
}
use of nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityRemovesThePropertiesThatAreNotProvided.
@Test
public void replaceEntityRemovesThePropertiesThatAreNotProvided() 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("testthing_prop1", "oldValue1").withProperty("testthing_prop2", "oldValue2").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ArrayList<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));
instance.replaceEntity(collection, updateEntity);
Vertex vertex = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
assertThat(vertex, is(likeVertex().withoutProperty("testthing_prop2")));
}
use of nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty in project timbuctoo by HuygensING.
the class EntityToJsonMapperTest method mapEntityMapsTheProperties.
@Test
public void mapEntityMapsTheProperties() throws Exception {
ReadEntityImpl readEntity = new ReadEntityImpl();
readEntity.setId(UUID.randomUUID());
String userId = "userId";
Change change = new Change(Instant.now().toEpochMilli(), userId, null);
readEntity.setCreated(change);
readEntity.setModified(change);
String type = "otherType";
readEntity.setTypes(Lists.newArrayList("type", type));
readEntity.setDeleted(false);
readEntity.setRev(1);
readEntity.setPid("pid");
ArrayList<TimProperty<?>> properties = Lists.newArrayList();
properties.add(new StringProperty("name", "Name"));
readEntity.setProperties(properties);
EntityToJsonMapper instance = new EntityToJsonMapper(userValidator, (collection, id1, rev) -> URI.create("www.example.com"));
Collection collection = mock(Collection.class);
when(collection.getEntityTypeName()).thenReturn(type);
ObjectNode resutlJson = instance.mapEntity(collection, readEntity, false, (readEntity1, resultJson) -> {
}, (relationRef, resultJson) -> {
});
assertThat(resutlJson.toString(), sameJSONAs(jsnO("name", jsn("Name")).toString()).allowingExtraUnexpectedFields());
}
Aggregations