use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty 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());
}
use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty in project timbuctoo by HuygensING.
the class EntityToJsonMapperTest method doesNotAddNonConvertableProperties.
@Test
public void doesNotAddNonConvertableProperties() {
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 HyperLinksProperty("nonParsableProp", "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(Lists.newArrayList(resutlJson.fieldNames()), not(hasItem("nonParsableProp")));
}
use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty in project timbuctoo by HuygensING.
the class JsonToEntityMapperTest method newCreateEntityIgnoresThePrefixedFields.
@Test
public void newCreateEntityIgnoresThePrefixedFields() throws Exception {
Collection collection = new VresBuilder().withVre("WomenWriters", "ww", vre -> vre.withCollection("wwpersons")).build().getCollection("wwpersons").get();
ObjectNode input = JsonBuilder.jsnO("_id", jsn("id"), "^rev", jsn(1), "@type", jsn("wwperson"));
JsonToEntityMapper instance = new JsonToEntityMapper();
List<TimProperty<?>> properties = instance.getDataProperties(collection, input);
assertThat(properties, not(containsInAnyOrder(hasProperty("name", equalTo("_id")), hasProperty("name", equalTo("^rev")), hasProperty("name", equalTo("@type")))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty in project timbuctoo by HuygensING.
the class JsonToEntityMapperTest method newCreateEntityMapsTheJsonObjectToACreateEntity.
@Test
public void newCreateEntityMapsTheJsonObjectToACreateEntity() 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("12"));
JsonToEntityMapper instance = new JsonToEntityMapper();
List<TimProperty<?>> properties = instance.getDataProperties(collection, input);
assertThat(properties, containsInAnyOrder(allOf(hasProperty("name", equalTo("name")), hasProperty("value", equalTo("Hans"))), allOf(hasProperty("name", equalTo("age")), hasProperty("value", equalTo("12")))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty in project timbuctoo by HuygensING.
the class TinkerPopPropertyConverterTest method fromCreatesAStringPropertyWhenUsesTheUniqueTypeIdOfThePropertyToDetermineTheTimPropertyType.
@Test
public void fromCreatesAStringPropertyWhenUsesTheUniqueTypeIdOfThePropertyToDetermineTheTimPropertyType() throws UnknownPropertyException, IOException {
Collection collection = mock(Collection.class);
ReadableProperty readableProperty = mock(ReadableProperty.class);
when(readableProperty.getUniqueTypeId()).thenReturn("string");
when(collection.getProperty(PROPERTY_NAME)).thenReturn(Optional.of(readableProperty));
TinkerPopPropertyConverter instance = new TinkerPopPropertyConverter(collection);
TimProperty property = instance.from(PROPERTY_NAME, STRING_VALUE);
assertThat(property, is(instanceOf(StringProperty.class)));
}
Aggregations