diff options
author | Pawel <pawel.kasperkiewicz@nokia.com> | 2019-12-20 09:56:29 +0100 |
---|---|---|
committer | Pawel <pawel.kasperkiewicz@nokia.com> | 2020-01-15 09:36:22 +0100 |
commit | 7e5a7d1d8cd74e42c8549e02724ec2df589e4117 (patch) | |
tree | ddb478a9bc8c7d7abbfa8d74a5acc902b6c4045a /src/test/java/org/onap/dcae/ApplicationSettingsTest.java | |
parent | e880d42248d5b6958676b748fdee53eed950ac17 (diff) |
updated jackson-databind and changed json schema validator library
Issue-ID: DCAEGEN2-1825
Signed-off-by: Pawel <pawel.kasperkiewicz@nokia.com>
Change-Id: Ia4c9c6286adcf84631a58f9d5bfef124fed1cee6
Diffstat (limited to 'src/test/java/org/onap/dcae/ApplicationSettingsTest.java')
-rw-r--r-- | src/test/java/org/onap/dcae/ApplicationSettingsTest.java | 42 |
1 files changed, 29 insertions, 13 deletions
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 |