use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityPreparesABackupCopyAfterMakingTheChanges.
@Test
public void replaceEntityPreparesABackupCopyAfterMakingTheChanges() 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);
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 beforeUpdate = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
instance.replaceEntity(collection, updateEntity);
Vertex afterUpdate = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
assertThat(afterUpdate.id(), is(not(beforeUpdate.id())));
assertThat(afterUpdate.edges(Direction.IN).next().outVertex().id(), is(beforeUpdate.id()));
}
use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method createEntityThrowsAnIoExceptionWhenItEncountersAnUnknownProperty.
@Test(expected = IOException.class)
public void createEntityThrowsAnIoExceptionWhenItEncountersAnUnknownProperty() throws Exception {
TinkerPopGraphManager graphManager = newGraph().wrap();
Vres vres = createConfiguration();
final Collection collection = vres.getCollection("testthings").get();
final TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
List<TimProperty<?>> properties = Lists.newArrayList();
properties.add(new StringProperty("prop1", "val1"));
properties.add(new StringProperty("unknowProp", "val2"));
CreateEntity createEntity = withProperties(properties);
instance.createEntity(collection, Optional.empty(), createEntity);
}
use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method createEntitySetsTheRevToOne.
// TODO move the TimbuctooActions
@Test
public void createEntitySetsTheRevToOne() 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("rev", 1).hasNext(), is(true));
}
use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method createEntityAddsAnEntityWithItsPropertiesToTheDatabase.
@Test
public void createEntityAddsAnEntityWithItsPropertiesToTheDatabase() throws Exception {
TinkerPopGraphManager graphManager = newGraph().wrap();
Vres vres = createConfiguration();
final Collection collection = vres.getCollection("testthings").get();
final TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
List<TimProperty<?>> properties = Lists.newArrayList();
properties.add(new StringProperty("prop1", "val1"));
properties.add(new StringProperty("prop2", "val2"));
CreateEntity createEntity = withProperties(properties);
instance.createEntity(collection, Optional.empty(), createEntity);
assertThat(graphManager.getGraph().traversal().V().has("tim_id", createEntity.getId().toString()).has("testthing_prop1", "val1").has("testthing_prop2", "val2").hasNext(), is(true));
}
use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty in project timbuctoo by HuygensING.
the class JsonToEntityMapperTest method getDataPropertiesIgnoresPropertiesWithValueEmptyString.
@Test
public void getDataPropertiesIgnoresPropertiesWithValueEmptyString() throws Exception {
Collection collection = new VresBuilder().withVre("WomenWriters", "ww", vre -> vre.withCollection("wwpersons", c -> c.withProperty("name", localProperty("wwname")).withProperty("age", localProperty("wwage")))).build().getCollection("wwpersons").get();
ObjectNode input = JsonBuilder.jsnO("name", jsn("Hans"), "age", jsn(""));
JsonToEntityMapper instance = new JsonToEntityMapper();
List<TimProperty<?>> properties = instance.getDataProperties(collection, input);
assertThat(properties, not(hasItem(hasProperty("name", equalTo("age")))));
}
Aggregations