aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/dcae/ApplicationSettingsTest.java42
-rw-r--r--src/test/java/org/onap/dcae/restapi/EventValidatorTest.java18
2 files changed, 38 insertions, 22 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
diff --git a/src/test/java/org/onap/dcae/restapi/EventValidatorTest.java b/src/test/java/org/onap/dcae/restapi/EventValidatorTest.java
index 5bacd31c..4ac3c487 100644
--- a/src/test/java/org/onap/dcae/restapi/EventValidatorTest.java
+++ b/src/test/java/org/onap/dcae/restapi/EventValidatorTest.java
@@ -20,9 +20,8 @@
package org.onap.dcae.restapi;
-import com.github.fge.jackson.JsonLoader;
-import com.github.fge.jsonschema.core.exceptions.ProcessingException;
-import com.github.fge.jsonschema.main.JsonSchemaFactory;
+import com.networknt.schema.JsonSchema;
+import com.networknt.schema.JsonSchemaFactory;
import org.json.JSONObject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -84,7 +83,7 @@ public class EventValidatorTest {
}
@Test
- public void shouldReturnSchemaValidationFailedErrorOnInvalidJsonObjectSchema() throws ProcessingException, IOException {
+ public void shouldReturnSchemaValidationFailedErrorOnInvalidJsonObjectSchema() throws IOException {
//given
String schemaRejectingEverything = "{\"not\":{}}";
mockJsonSchema(schemaRejectingEverything);
@@ -98,7 +97,7 @@ public class EventValidatorTest {
}
@Test
- public void shouldReturnEmptyOptionalOnValidJsonObjectSchema() throws ProcessingException, IOException {
+ public void shouldReturnEmptyOptionalOnValidJsonObjectSchema() throws IOException {
//given
String schemaAcceptingEverything = "{}";
mockJsonSchema(schemaAcceptingEverything);
@@ -111,10 +110,11 @@ public class EventValidatorTest {
assertEquals(Optional.empty(), result);
}
- private void mockJsonSchema(String jsonSchema) throws IOException, ProcessingException {
- when(settings.jsonSchema(any())).thenReturn(
- JsonSchemaFactory.byDefault()
- .getJsonSchema(JsonLoader.fromString(jsonSchema)));
+ private void mockJsonSchema(String jsonSchemaContent) {
+ JsonSchemaFactory factory = JsonSchemaFactory.getInstance();
+
+ JsonSchema schema = factory.getSchema(jsonSchemaContent);
+ when(settings.jsonSchema(any())).thenReturn(schema);
}
private Optional<ResponseEntity<String>> generateResponseOptional(ApiException schemaValidationFailed) {