From 7e5a7d1d8cd74e42c8549e02724ec2df589e4117 Mon Sep 17 00:00:00 2001 From: Pawel Date: Fri, 20 Dec 2019 09:56:29 +0100 Subject: updated jackson-databind and changed json schema validator library Issue-ID: DCAEGEN2-1825 Signed-off-by: Pawel Change-Id: Ia4c9c6286adcf84631a58f9d5bfef124fed1cee6 --- .../org/onap/dcae/ApplicationSettingsTest.java | 42 +++++++++++++++------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'src/test/java/org/onap/dcae/ApplicationSettingsTest.java') diff --git a/src/test/java/org/onap/dcae/ApplicationSettingsTest.java b/src/test/java/org/onap/dcae/ApplicationSettingsTest.java index 6b0023f8..c4ba586e 100644 --- a/src/test/java/org/onap/dcae/ApplicationSettingsTest.java +++ b/src/test/java/org/onap/dcae/ApplicationSettingsTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.dcaegen2.collectors.ves * ================================================================================ - * Copyright (C) 2018 Nokia. All rights reserved. + * Copyright (C) 2018 - 2019 Nokia. All rights reserved. * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,8 +32,7 @@ import static org.onap.dcae.TestingUtilities.createTemporaryFile; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.fge.jsonschema.core.exceptions.ProcessingException; -import com.github.fge.jsonschema.main.JsonSchema; +import com.networknt.schema.JsonSchema; import io.vavr.collection.HashMap; import io.vavr.collection.Map; import java.io.File; @@ -47,6 +46,13 @@ import org.junit.Test; public class ApplicationSettingsTest { + private static final String SAMPLE_JSON_SCHEMA = "{" + + " \"type\": \"object\"," + + " \"properties\": {" + + " \"state\": { \"type\": \"string\" }" + + " }" + + "}"; + @Test public void shouldMakeApplicationSettingsOutOfCLIArguments() { // given @@ -254,15 +260,9 @@ public class ApplicationSettingsTest { } @Test - public void shouldReturnJSONSchema() throws IOException, ProcessingException { + public void shouldReportValidateJSONSchemaErrorWhenJsonContainsIntegerValueNotString() throws IOException { // when - String sampleJsonSchema = "{" - + " \"type\": \"object\"," - + " \"properties\": {" - + " \"state\": { \"type\": \"string\" }" - + " }" - + "}"; - Path temporarySchemaFile = createTemporaryFile(sampleJsonSchema); + Path temporarySchemaFile = createTemporaryFile(SAMPLE_JSON_SCHEMA); // when JsonSchema schema = fromTemporaryConfiguration( @@ -271,9 +271,25 @@ public class ApplicationSettingsTest { // then JsonNode incorrectTestObject = new ObjectMapper().readTree("{ \"state\": 1 }"); + + assertFalse(schema.validate(incorrectTestObject).isEmpty()); + + } + + @Test + public void shouldDoNotReportAnyValidateJSONSchemaError() throws IOException { + // when + Path temporarySchemaFile = createTemporaryFile(SAMPLE_JSON_SCHEMA); + + // when + JsonSchema schema = fromTemporaryConfiguration( + String.format("collector.schema.file={\"v1\": \"%s\"}", temporarySchemaFile)) + .jsonSchema("v1"); + + // then JsonNode correctTestObject = new ObjectMapper().readTree("{ \"state\": \"hi\" }"); - assertFalse(schema.validate(incorrectTestObject).isSuccess()); - assertTrue(schema.validate(correctTestObject).isSuccess()); + ; + assertTrue(schema.validate(correctTestObject).isEmpty()); } @Test -- cgit 1.2.3-korg