use of nl.knaw.huygens.timbuctoo.crud.conversion.JsonPropertyConverter 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.crud.conversion.JsonPropertyConverter in project timbuctoo by HuygensING.
the class JsonPropertyConverterTest method toReturnsAJsonEncodedStringForADatableProperty.
@Test
public void toReturnsAJsonEncodedStringForADatableProperty() throws Exception {
JsonPropertyConverter instance = new JsonPropertyConverter(null);
DatableProperty property = new DatableProperty("prop", "1800");
Tuple<String, JsonNode> value = instance.to(property);
assertThat(value.getRight(), is(jsn("1800")));
}
use of nl.knaw.huygens.timbuctoo.crud.conversion.JsonPropertyConverter in project timbuctoo by HuygensING.
the class JsonPropertyConverterTest method toConvertsTheListOfAltNamesToAnArrayNode.
@Test
public void toConvertsTheListOfAltNamesToAnArrayNode() throws Exception {
JsonPropertyConverter jsonPropertyConverter = new JsonPropertyConverter(null);
AltNames altNames = new AltNames();
altNames.list = Lists.newArrayList(new AltName("type1", "name1"), new AltName("type2", "name2"));
Tuple<String, JsonNode> valueTuple = jsonPropertyConverter.to(new AltNamesProperty("test", altNames));
JsonNode value = valueTuple.getRight();
assertThat(value.isArray(), is(true));
assertThat(Lists.newArrayList(value.iterator()), containsInAnyOrder(jsnO("nametype", jsn("type1"), "displayName", jsn("name1")), jsnO("nametype", jsn("type2"), "displayName", jsn("name2"))));
}
use of nl.knaw.huygens.timbuctoo.crud.conversion.JsonPropertyConverter in project timbuctoo by HuygensING.
the class JsonPropertyConverterTest method toConvertsADatablePropertyToAString.
@Test
public void toConvertsADatablePropertyToAString() throws Exception {
JsonPropertyConverter instance = new JsonPropertyConverter(null);
DatableProperty datableProperty = new DatableProperty("", "2016-01-02");
Tuple<String, JsonNode> value = instance.to(datableProperty);
assertThat(value.getRight(), is(jsn("2016-01-02")));
}
Aggregations