diff options
author | PawelSzalapski <pawel.szalapski@nokia.com> | 2018-08-08 11:01:03 +0200 |
---|---|---|
committer | PawelSzalapski <pawel.szalapski@nokia.com> | 2018-08-10 14:21:34 +0200 |
commit | e1ccd83e39090f16a446b23e154b8e28530e2fdd (patch) | |
tree | c38f54e6690f58438cb5e66fed2f6aad177b4bfc /src/test/java/org/onap/dcae/ApplicationSettingsTest.java | |
parent | 5deddeb4892243627ad342a41d4dcef0f7280a29 (diff) |
Refactor the code base a bit
Remove potential race condition coming from
shared 'version' veriable in singleton instance of
RestController.
Move the logic behind reading the json schemas out
of a on-request phase to application startup.
Minor refactoring done that will bump up test coverage.
Change-Id: I2ad1ba91dafafd785ede61591a4dc146abf6a1eb
Signed-off-by: PawelSzalapski <pawel.szalapski@nokia.com>
Issue-ID: DCAEGEN2-526
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 |