diff options
Diffstat (limited to 'src/test/java/org/onap/dcae/ApplicationSettingsTest.java')
-rw-r--r-- | src/test/java/org/onap/dcae/ApplicationSettingsTest.java | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/test/java/org/onap/dcae/ApplicationSettingsTest.java b/src/test/java/org/onap/dcae/ApplicationSettingsTest.java index 2ac42080..26b0a68b 100644 --- a/src/test/java/org/onap/dcae/ApplicationSettingsTest.java +++ b/src/test/java/org/onap/dcae/ApplicationSettingsTest.java @@ -20,6 +20,11 @@ package org.onap.dcae; * ============LICENSE_END========================================================= */ +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.core.report.ProcessingReport; +import com.github.fge.jsonschema.main.JsonSchema; import io.vavr.collection.HashMap; import io.vavr.collection.Map; import org.json.JSONObject; @@ -28,6 +33,7 @@ import org.junit.Test; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.Objects; @@ -35,6 +41,7 @@ import java.util.Objects; import static java.util.Collections.singletonList; import static org.junit.Assert.*; import static org.onap.dcae.CLIUtils.processCmdLine; +import static org.onap.dcae.TestingUtilities.createTemporaryFile; public class ApplicationSettingsTest { @@ -281,22 +288,25 @@ public class ApplicationSettingsTest { } @Test - public void shouldReturnJSONSchema() throws IOException { + public void shouldReturnJSONSchema() throws IOException, ProcessingException { // when - JSONObject jsonSchema = fromTemporaryConfiguration("collector.schema.file={\"v1\": {}}") - .jsonSchema(); + String sampleJsonSchema = "{" + + " \"type\": \"object\"," + + " \"properties\": {" + + " \"state\": { \"type\": \"string\" }" + + " }" + + "}"; + Path temporarySchemaFile = createTemporaryFile(sampleJsonSchema); - // then - assertEquals(new JSONObject("{\"v1\": {}}").toMap(), jsonSchema.toMap()); - } - - @Test - public void shouldReturnDefaultJSONSchema() throws IOException { // when - JSONObject jsonSchema = fromTemporaryConfiguration().jsonSchema(); + JsonSchema schema = fromTemporaryConfiguration(String.format("collector.schema.file={\"v1\": \"%s\"}", temporarySchemaFile)) + .jsonSchema("v1"); // then - assertEquals(new JSONObject("{\"v5\":\"./etc/CommonEventFormat_28.3.json\"}").toMap(), jsonSchema.toMap()); + JsonNode incorrectTestObject = new ObjectMapper().readTree("{ \"state\": 1 }"); + JsonNode correctTestObject = new ObjectMapper().readTree("{ \"state\": \"hi\" }"); + assertFalse(schema.validate(incorrectTestObject).isSuccess()); + assertTrue(schema.validate(correctTestObject).isSuccess()); } @Test |