use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection 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.dataset.Collection 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.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method retractPropertyRemovesTheValueTypeFromThePredicateIfItDoesNotApplyToAnyEntity.
@Test
public void retractPropertyRemovesTheValueTypeFromThePredicateIfItDoesNotApplyToAnyEntity() {
TinkerPopGraphManager graphManager = newGraph().wrap();
TinkerPopOperations instance = forGraphWrapper(graphManager);
Vre vre = minimalCorrectVre(instance, "vre");
Collection defaultCollection = vre.getCollectionForTypeName(defaultEntityTypeName(vre));
RdfProperty stringProperty = new RdfProperty("http://example.org/propName", "value", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
RdfProperty floatProperty = new RdfProperty("http://example.org/propName", "1.5", "http://www.w3.org/2001/XMLSchema#float");
instance.assertProperty(vre, "http://example.org/1", stringProperty);
instance.assertProperty(vre, "http://example.org/2", floatProperty);
instance.assertProperty(vre, "http://example.org/3", floatProperty);
instance.retractProperty(vre, "http://example.org/1", stringProperty);
instance.retractProperty(vre, "http://example.org/2", floatProperty);
List<PredicateInUse> predicates = instance.getPredicatesFor(defaultCollection);
assertThat(predicates, hasSize(1));
assertThat(predicates.get(0).getValueTypes(), contains(hasProperty("typeUri", equalTo("http://www.w3.org/2001/XMLSchema#float"))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityOnlyMapsTheKnownProperties.
@Test
public void getEntityOnlyMapsTheKnownProperties() 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).withType("thing").withVre("test").withProperty("testthing_prop1", "val1").withProperty("testthing_prop2", "val2").withProperty("testthing_unknownProp", "val")).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ReadEntity entity = instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getProperties(), containsInAnyOrder(allOf(hasProperty("name", equalTo("prop1")), hasProperty("value", equalTo("val1"))), allOf(hasProperty("name", equalTo("prop2")), hasProperty("value", equalTo("val2")))));
assertThat(entity.getProperties(), not(contains(allOf(hasProperty("name", equalTo("unknownProp")), hasProperty("value", equalTo("val"))))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method createEntityMarksOneVertexAsLatest.
@Test
public void createEntityMarksOneVertexAsLatest() 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()).has("isLatest", true).count().next(), is(1L));
}
Aggregations