diff options
author | Lusheng Ji <lji@research.att.com> | 2018-08-14 22:47:58 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-08-14 22:47:58 +0000 |
commit | d161143571eec74f877e5be6b85e479c44aae881 (patch) | |
tree | 70fcb0c9f617a637a3d52ed4882bff9ade7bfbb1 /src/test/java/org/onap/dcae/ApplicationSettingsTest.java | |
parent | 83db58c6c3b93ecee2352572260f31382bff7629 (diff) | |
parent | e1ccd83e39090f16a446b23e154b8e28530e2fdd (diff) |
Merge "Refactor the code base a bit"
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 |