use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class JsonPropertyConverterTest method fromReturnsADatablePropertyWithADecodedStringValue.
// Datable tests
@Test
public void fromReturnsADatablePropertyWithADecodedStringValue() throws Exception {
Collection collection = mock(Collection.class);
ReadableProperty readableProperty = mock(ReadableProperty.class);
when(readableProperty.getUniqueTypeId()).thenReturn("datable");
when(collection.getProperty("prop")).thenReturn(Optional.of(readableProperty));
JsonPropertyConverter instance = new JsonPropertyConverter(collection);
TimProperty<?> from = instance.from("prop", jsn("1800"));
assertThat(from.getValue(), is("1800"));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection 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")))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class JsonToEntityMapperTest method newUpdateEntityThrowsAnIoExceptionWhenThePropertyIsUnknown.
@Test(expected = IOException.class)
public void newUpdateEntityThrowsAnIoExceptionWhenThePropertyIsUnknown() 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("unknownProperty", jsn("value"), "age", jsn("12"), "^rev", jsn(2));
JsonToEntityMapper instance = new JsonToEntityMapper();
instance.newUpdateEntity(collection, UUID.randomUUID(), input);
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class JsonToEntityMapperTest method newCreateEntityThrowsAnIoExceptionWhenThePropertyCannotBeConverted.
@Test(expected = IOException.class)
public void newCreateEntityThrowsAnIoExceptionWhenThePropertyCannotBeConverted() 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();
instance.getDataProperties(collection, input);
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class JsonToEntityMapperTest method newUpdateEntityMapsTheJsonObjectToAnUpdateEntity.
@Test
public void newUpdateEntityMapsTheJsonObjectToAnUpdateEntity() 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();
int rev = 2;
ObjectNode input = JsonBuilder.jsnO("name", jsn("Hans"), "age", jsn("12"), "^rev", jsn(rev));
JsonToEntityMapper instance = new JsonToEntityMapper();
UUID id = UUID.randomUUID();
UpdateEntity updateEntity = instance.newUpdateEntity(collection, id, input);
assertThat(updateEntity.getProperties(), containsInAnyOrder(allOf(hasProperty("name", equalTo("name")), hasProperty("value", equalTo("Hans"))), allOf(hasProperty("name", equalTo("age")), hasProperty("value", equalTo("12")))));
assertThat(updateEntity.getId(), is(id));
assertThat(updateEntity.getRev(), is(rev));
}
Aggregations