use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method createEntityDuplicatesTheVertex.
@Test
public void createEntityDuplicatesTheVertex() throws Exception {
TinkerPopGraphManager graphManager = newGraph().wrap();
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
List<TimProperty<?>> properties = Lists.newArrayList();
CreateEntity createEntity = withProperties(properties);
instance.createEntity(collection, Optional.empty(), createEntity);
assertThat(graphManager.getGraph().traversal().V().has("tim_id", createEntity.getId().toString()).count().next(), is(2L));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceRelationCallsTheChangeListener.
@Test
public void replaceRelationCallsTheChangeListener() 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();
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(1).addType("testrelation"))).withVertex("otherVertex", v -> v.withTimId(targetId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).wrap();
ChangeListener changeListener = mock(ChangeListener.class);
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.findEdgeById(relId)).thenReturn(Optional.of(graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).next()));
TinkerPopOperations instance = forGraphMappingsListenerAndIndex(graphManager, vres, changeListener, indexHandler);
UpdateRelation updateRelation = new UpdateRelation(relId, 1, false);
long timeStamp = Instant.now().toEpochMilli();
String userId = "userId";
updateRelation.setModified(new Change(timeStamp, userId, null));
instance.replaceRelation(collection, updateRelation);
String acceptedProp = createPropName(collection.getEntityTypeName(), "accepted");
verify(changeListener).onEdgeUpdate(argThat(is(sameInstance(collection))), argThat(is(likeEdge().withProperty(acceptedProp, true))), argThat(is(likeEdge().withProperty(acceptedProp, false))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method finishEntitiesCallsTheChangeListener.
@Test
public void finishEntitiesCallsTheChangeListener() {
ChangeListener changeListener = mock(ChangeListener.class);
TinkerPopOperations instance = TinkerPopOperationsStubs.forChangeListenerMock(changeListener);
Vre vre = instance.ensureVreExists("vre");
instance.addCollectionToVre(vre, CreateCollection.defaultCollection("vre"));
vre = instance.loadVres().getVre("vre");
Collection defaultCollection = vre.getCollectionForTypeName(defaultEntityTypeName(vre));
Vertex orig = instance.assertEntity(vre, "http://example.org/entity1");
instance.finishEntities(vre, new EntityFinisherHelper());
Vertex duplicate = orig.vertices(Direction.OUT, VERSION_OF).next();
verify(changeListener).onCreate(eq(defaultCollection), eq(duplicate));
verify(changeListener).onAddToCollection(eq(defaultCollection), eq(Optional.empty()), eq(duplicate));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection 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.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityReturnsTheLatestEntityIfTheRefIsNull.
@Test
public void getEntityReturnsTheLatestEntityIfTheRefIsNull() 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("testthing_prop1", "old").withProperty("rev", 1).withProperty("isLatest", false).withOutgoingRelation("VERSION_OF", "replacement")).withVertex("replacement", v -> v.withTimId(id.toString()).withType("thing").withVre("test").withProperty("testthing_prop1", "new").withProperty("rev", 2).withProperty("isLatest", false).withOutgoingRelation("VERSION_OF", "dangling")).withVertex("dangling", v -> v.withTimId(id.toString()).withType("thing").withVre("test").withProperty("testthing_prop1", "new").withProperty("rev", 2).withProperty("isLatest", true)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ReadEntity entity = instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getRev(), is(2));
assertThat(entity.getProperties(), contains(allOf(hasProperty("name", equalTo("prop1")), hasProperty("value", equalTo("new")))));
}
Aggregations