Search in sources :

Example 1 with JsonPropertyConverter

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"));
}
Also used : ReadableProperty(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) JsonPropertyConverter(nl.knaw.huygens.timbuctoo.crud.conversion.JsonPropertyConverter) Test(org.junit.Test)

Example 2 with JsonPropertyConverter

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")));
}
Also used : DatableProperty(nl.knaw.huygens.timbuctoo.core.dto.property.DatableProperty) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonPropertyConverter(nl.knaw.huygens.timbuctoo.crud.conversion.JsonPropertyConverter) Test(org.junit.Test)

Example 3 with JsonPropertyConverter

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"))));
}
Also used : AltNamesProperty(nl.knaw.huygens.timbuctoo.core.dto.property.AltNamesProperty) AltNames(nl.knaw.huygens.timbuctoo.model.AltNames) JsonNode(com.fasterxml.jackson.databind.JsonNode) AltName(nl.knaw.huygens.timbuctoo.model.AltName) JsonPropertyConverter(nl.knaw.huygens.timbuctoo.crud.conversion.JsonPropertyConverter) Test(org.junit.Test)

Example 4 with JsonPropertyConverter

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")));
}
Also used : DatableProperty(nl.knaw.huygens.timbuctoo.core.dto.property.DatableProperty) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonPropertyConverter(nl.knaw.huygens.timbuctoo.crud.conversion.JsonPropertyConverter) Test(org.junit.Test)

Aggregations

JsonPropertyConverter (nl.knaw.huygens.timbuctoo.crud.conversion.JsonPropertyConverter)4 Test (org.junit.Test)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 DatableProperty (nl.knaw.huygens.timbuctoo.core.dto.property.DatableProperty)2 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)1 AltNamesProperty (nl.knaw.huygens.timbuctoo.core.dto.property.AltNamesProperty)1 AltName (nl.knaw.huygens.timbuctoo.model.AltName)1 AltNames (nl.knaw.huygens.timbuctoo.model.AltNames)1 ReadableProperty (nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty)1