use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteEntitySetsDeletedToTrueWhenLastTypeIsRemoved.
@Test
public void deleteEntitySetsDeletedToTrueWhenLastTypeIsRemoved() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
String idString = id.toString();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(idString).withProperty("isLatest", true).withVre("test").withType("thing").withProperty("rev", 1).withIncomingRelation("VERSION_OF", "orig")).withVertex("orig", v -> v.withTimId(idString).withVre("test").withType("thing").withProperty("isLatest", false).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
assertThat(graphManager.getGraph().traversal().V().has("tim_id", idString).has("deleted", true).hasNext(), is(true));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection 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.dataset.Collection in project timbuctoo by HuygensING.
the class EntityToJsonMapperTest method mapEntityAddsADisplayNameWhenItIsKnown.
@Test
public void mapEntityAddsADisplayNameWhenItIsKnown() {
ReadEntityImpl readEntity = new ReadEntityImpl();
UUID id = UUID.randomUUID();
readEntity.setId(id);
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");
readEntity.setProperties(Lists.newArrayList());
readEntity.setRelations(Lists.newArrayList());
String displayName = "displayName";
readEntity.setDisplayName(displayName);
Collection collection = mock(Collection.class);
when(collection.getEntityTypeName()).thenReturn(type);
ObjectNode resutlJson = instance.mapEntity(collection, readEntity, true, (readEntity1, resultJson) -> {
}, (relationRef, resultJson) -> {
});
assertThat(resutlJson.has("@displayName"), is(true));
assertThat(resutlJson.get("@displayName"), is(jsn(displayName)));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class EntityToJsonMapperTest method mapEntityMapsTheTypeAndId.
@Test
public void mapEntityMapsTheTypeAndId() throws Exception {
ReadEntityImpl readEntity = new ReadEntityImpl();
UUID id = UUID.randomUUID();
readEntity.setId(id);
Change change = new Change(Instant.now().toEpochMilli(), USER_ID, 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");
readEntity.setProperties(Lists.newArrayList());
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("_id", jsn(id.toString()), "@type", jsn(type)).toString()).allowingExtraUnexpectedFields());
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class EntityToJsonMapperTest method mapEntityMapsTheRelations.
@Test
public void mapEntityMapsTheRelations() throws Exception {
ReadEntityImpl readEntity = new ReadEntityImpl();
UUID id = UUID.randomUUID();
readEntity.setId(id);
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");
readEntity.setProperties(Lists.newArrayList());
String otherEntity = UUID.randomUUID().toString();
String relType = "relType";
readEntity.setRelations(Lists.newArrayList(new RelationRef(otherEntity, "rdfUri", new String[] { "origUri" }, "otherColl", "otherType", true, "relId", "rdfUri", 1, relType, "displayName")));
Collection collection = mock(Collection.class);
when(collection.getEntityTypeName()).thenReturn(type);
ObjectNode resutlJson = instance.mapEntity(collection, readEntity, true, (readEntity1, resultJson) -> {
}, (relationRef, resultJson) -> {
});
assertThat(resutlJson.toString(), sameJSONAs(jsnO("@relationCount", jsn(1), "@relations", jsnO(relType, jsnA(jsnO("id", jsn(otherEntity))))).toString()).allowingExtraUnexpectedFields());
}
Aggregations