Search in sources :

Example 1 with Converter

use of nl.knaw.huygens.timbuctoo.model.properties.converters.Converter in project timbuctoo by HuygensING.

the class LocalPropertyTest method saveSetsOptionsPropertyWhenTheConverterHasOptions.

@Test
public void saveSetsOptionsPropertyWhenTheConverterHasOptions() throws JsonProcessingException {
    final String propertyName = "testProp";
    final String clientPropName = "clientPropName";
    final String[] options = { "val1", "val2" };
    Converter converter = new StringArrayToEncodedArrayOfLimitedValues(options);
    LocalProperty property = new LocalProperty(propertyName, converter);
    Vertex result = property.save(graph, clientPropName);
    assertThat(result, likeVertex().withProperty(OPTIONS_PROPERTY_NAME, new ObjectMapper().writeValueAsString(options)).withProperty(PROPERTY_TYPE_NAME, converter.getUniqueTypeIdentifier()));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Converter(nl.knaw.huygens.timbuctoo.model.properties.converters.Converter) StringArrayToEncodedArrayOfLimitedValues(nl.knaw.huygens.timbuctoo.model.properties.converters.StringArrayToEncodedArrayOfLimitedValues) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with Converter

use of nl.knaw.huygens.timbuctoo.model.properties.converters.Converter in project timbuctoo by HuygensING.

the class LocalPropertyTest method saveCreatesANewVertexWithCorrectLabelAndProperties.

@Test
public void saveCreatesANewVertexWithCorrectLabelAndProperties() {
    final String propertyName = "testProp";
    final String propertyType = "type";
    final String clientPropName = "clientPropName";
    Converter converter = mock(Converter.class);
    given(converter.getUniqueTypeIdentifier()).willReturn(propertyType);
    LocalProperty property = new LocalProperty(propertyName, converter);
    Vertex result = property.save(graph, clientPropName);
    assertThat(result, likeVertex().withLabel(DATABASE_LABEL).withProperty(DATABASE_PROPERTY_NAME, propertyName).withProperty(CLIENT_PROPERTY_NAME, clientPropName).withProperty(PROPERTY_TYPE_NAME, propertyType));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Converter(nl.knaw.huygens.timbuctoo.model.properties.converters.Converter) Test(org.junit.Test)

Example 3 with Converter

use of nl.knaw.huygens.timbuctoo.model.properties.converters.Converter in project timbuctoo by HuygensING.

the class PropertyTypesTest method localPropertyReturnsLocalPropertyWithCorrectPropNameAndCorrectConverter.

@Test
public void localPropertyReturnsLocalPropertyWithCorrectPropNameAndCorrectConverter() throws IOException {
    Converter converter = mock(Converter.class);
    JsonNode value = jsn("value");
    given(converter.jsonToTinkerpop(value)).willReturn("converted-value");
    LocalProperty instance = localProperty("propName", converter);
    Vertex vertex = mock(Vertex.class);
    VertexProperty vertexProperty = mock(VertexProperty.class);
    given(vertex.property("propName")).willReturn(vertexProperty);
    instance.setJson(vertex, null);
    instance.setJson(vertex, value);
    verify(vertex, times(1)).property("propName", "converted-value");
    verify(vertexProperty, times(1)).remove();
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Converter(nl.knaw.huygens.timbuctoo.model.properties.converters.Converter) JsonNode(com.fasterxml.jackson.databind.JsonNode) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) Test(org.junit.Test)

Aggregations

Converter (nl.knaw.huygens.timbuctoo.model.properties.converters.Converter)3 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 Test (org.junit.Test)3 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 StringArrayToEncodedArrayOfLimitedValues (nl.knaw.huygens.timbuctoo.model.properties.converters.StringArrayToEncodedArrayOfLimitedValues)1 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)1