Search in sources :

Example 1 with AltName

use of nl.knaw.huygens.timbuctoo.model.AltName 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 2 with AltName

use of nl.knaw.huygens.timbuctoo.model.AltName in project timbuctoo by HuygensING.

the class AltNamesConverterTest method tinkerpopToJsonReadsTheListOfTheAltNamesValues.

@Test
public void tinkerpopToJsonReadsTheListOfTheAltNamesValues() throws Exception {
    AltNames altNames = new AltNames();
    altNames.list = Lists.newArrayList(ALT_NAME_1, ALT_NAME_2);
    String dbValue = objectMapper.writeValueAsString(altNames);
    JsonNode jsonNode = instance.tinkerpopToJson(dbValue);
    List<AltName> altNameList = objectMapper.readValue(jsonNode.toString(), new TypeReference<List<AltName>>() {
    });
    assertThat(altNameList, containsInAnyOrder(ALT_NAME_1, ALT_NAME_2));
}
Also used : AltNames(nl.knaw.huygens.timbuctoo.model.AltNames) JsonNode(com.fasterxml.jackson.databind.JsonNode) List(java.util.List) AltName(nl.knaw.huygens.timbuctoo.model.AltName) Test(org.junit.Test)

Example 3 with AltName

use of nl.knaw.huygens.timbuctoo.model.AltName in project timbuctoo by HuygensING.

the class AltNameFacetDescriptionTest method getValuesReturnsTheDisplayNamesOfAllTheAltNames.

@Test
public void getValuesReturnsTheDisplayNamesOfAllTheAltNames() throws Exception {
    String displayName1 = "displayName1";
    String displayName2 = "displayName2";
    AltNames altNames = new AltNames();
    altNames.list = Lists.newArrayList(new AltName("nameType", displayName1), new AltName("nameType", displayName2));
    String altNamesPropValue = new ObjectMapper().writeValueAsString(altNames);
    Vertex vertex = vertex().withProperty(PROPERTY_NAME, altNamesPropValue).build();
    AltNameFacetDescription instance = new AltNameFacetDescription("facetName", PROPERTY_NAME);
    List<String> values = instance.getValues(vertex);
    assertThat(values, containsInAnyOrder(displayName1, displayName2));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) AltNames(nl.knaw.huygens.timbuctoo.model.AltNames) AltName(nl.knaw.huygens.timbuctoo.model.AltName) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

AltName (nl.knaw.huygens.timbuctoo.model.AltName)3 AltNames (nl.knaw.huygens.timbuctoo.model.AltNames)3 Test (org.junit.Test)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 List (java.util.List)1 AltNamesProperty (nl.knaw.huygens.timbuctoo.core.dto.property.AltNamesProperty)1 JsonPropertyConverter (nl.knaw.huygens.timbuctoo.crud.conversion.JsonPropertyConverter)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1