@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) ); }
@Override public Vertex save(Graph graph, String clientPropertyName) { Vertex propertyVertex = super.save(graph, clientPropertyName); propertyVertex.property(DATABASE_PROPERTY_NAME, propName); if (converter instanceof HasOptions) { try { propertyVertex.property(OPTIONS_PROPERTY_NAME, new ObjectMapper().writeValueAsString(((HasOptions) converter).getOptions())); } catch (JsonProcessingException e) { LOG.error("Failed to write options to database for property {}", propName); } } return propertyVertex; }
LocalProperty extends ReadableProperty { @Override public Vertex save(Graph graph, String clientPropertyName) { Vertex propertyVertex = super.save(graph, clientPropertyName); propertyVertex.property(DATABASE_PROPERTY_NAME, propName); if (converter instanceof HasOptions) { try { propertyVertex.property(OPTIONS_PROPERTY_NAME, new ObjectMapper().writeValueAsString(((HasOptions) converter).getOptions())); } catch (JsonProcessingException e) { LOG.error("Failed to write options to database for property {}", propName); } } return propertyVertex; } }
LocalProperty extends ReadableProperty { @Override public Vertex save(Graph graph, String clientPropertyName) { Vertex propertyVertex = super.save(graph, clientPropertyName); propertyVertex.property(DATABASE_PROPERTY_NAME, propName); if (converter instanceof HasOptions) { try { propertyVertex.property(OPTIONS_PROPERTY_NAME, new ObjectMapper().writeValueAsString(((HasOptions) converter).getOptions())); } catch (JsonProcessingException e) { LOG.error("Failed to write options to database for property {}", propName); } } return propertyVertex; } LocalProperty(String propName, Converter converter); }
LocalProperty extends ReadableProperty { @Override public Vertex save(Graph graph, String clientPropertyName) { Vertex propertyVertex = super.save(graph, clientPropertyName); propertyVertex.property(DATABASE_PROPERTY_NAME, propName); if (converter instanceof HasOptions) { try { propertyVertex.property(OPTIONS_PROPERTY_NAME, new ObjectMapper().writeValueAsString(((HasOptions) converter).getOptions())); } catch (JsonProcessingException e) { LOG.error("Failed to write options to database for property {}", propName); } } return propertyVertex; } LocalProperty(String propName, Converter converter); String getDatabasePropertyName(); Optional<Collection<String>> getOptions(); Optional<Collection<String>> getParts(); void setJson(Vertex vertex, JsonNode value); void setValue(Vertex vertex, Object value); @Override String getTypeId(); @Override String getUniqueTypeId(); @Override Vertex save(Graph graph, String clientPropertyName); }
LocalProperty extends ReadableProperty { @Override public Vertex save(Graph graph, String clientPropertyName) { Vertex propertyVertex = super.save(graph, clientPropertyName); propertyVertex.property(DATABASE_PROPERTY_NAME, propName); if (converter instanceof HasOptions) { try { propertyVertex.property(OPTIONS_PROPERTY_NAME, new ObjectMapper().writeValueAsString(((HasOptions) converter).getOptions())); } catch (JsonProcessingException e) { LOG.error("Failed to write options to database for property {}", propName); } } return propertyVertex; } LocalProperty(String propName, Converter converter); String getDatabasePropertyName(); Optional<Collection<String>> getOptions(); Optional<Collection<String>> getParts(); void setJson(Vertex vertex, JsonNode value); void setValue(Vertex vertex, Object value); @Override String getTypeId(); @Override String getUniqueTypeId(); @Override Vertex save(Graph graph, String clientPropertyName); static final String DATABASE_PROPERTY_NAME; static final String OPTIONS_PROPERTY_NAME; }