aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/dcae/restapi/EventValidatorTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap/dcae/restapi/EventValidatorTest.java')
-rw-r--r--src/test/java/org/onap/dcae/restapi/EventValidatorTest.java29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/test/java/org/onap/dcae/restapi/EventValidatorTest.java b/src/test/java/org/onap/dcae/restapi/EventValidatorTest.java
index 4ac3c487..53595100 100644
--- a/src/test/java/org/onap/dcae/restapi/EventValidatorTest.java
+++ b/src/test/java/org/onap/dcae/restapi/EventValidatorTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* org.onap.dcaegen2.collectors.ves
* ================================================================================
- * Copyright (C) 2019 Nokia. All rights reserved.
+ * Copyright (C) 2020 Nokia. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,8 +20,13 @@
package org.onap.dcae.restapi;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
+import java.util.Optional;
import org.json.JSONObject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -32,13 +37,6 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.dcae.ApplicationSettings;
import org.springframework.http.ResponseEntity;
-import java.io.IOException;
-import java.util.Optional;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
-
@ExtendWith(MockitoExtension.class)
public class EventValidatorTest {
private static final String DUMMY_SCHEMA_VERSION = "v5";
@@ -60,7 +58,7 @@ public class EventValidatorTest {
@Test
public void shouldReturnEmptyOptionalOnJsonSchemaValidationDisabled() {
//given
- when(settings.jsonSchemaValidationEnabled()).thenReturn(false);
+ when(settings.eventSchemaValidationEnabled()).thenReturn(false);
//when
Optional<ResponseEntity<String>> result = sut.validate(jsonObject, DUMMY_TYPE, DUMMY_SCHEMA_VERSION);
@@ -73,7 +71,7 @@ public class EventValidatorTest {
@Test
public void shouldReturnInvalidJsonErrorOnWrongType() {
//given
- when(settings.jsonSchemaValidationEnabled()).thenReturn(true);
+ when(settings.eventSchemaValidationEnabled()).thenReturn(true);
//when
Optional<ResponseEntity<String>> result = sut.validate(jsonObject, "wrongType", DUMMY_SCHEMA_VERSION);
@@ -83,11 +81,11 @@ public class EventValidatorTest {
}
@Test
- public void shouldReturnSchemaValidationFailedErrorOnInvalidJsonObjectSchema() throws IOException {
+ public void shouldReturnSchemaValidationFailedErrorOnInvalidJsonObjectSchema() {
//given
String schemaRejectingEverything = "{\"not\":{}}";
mockJsonSchema(schemaRejectingEverything);
- when(settings.jsonSchemaValidationEnabled()).thenReturn(true);
+ when(settings.eventSchemaValidationEnabled()).thenReturn(true);
//when
Optional<ResponseEntity<String>> result = sut.validate(jsonObject, DUMMY_TYPE, DUMMY_SCHEMA_VERSION);
@@ -97,11 +95,11 @@ public class EventValidatorTest {
}
@Test
- public void shouldReturnEmptyOptionalOnValidJsonObjectSchema() throws IOException {
+ public void shouldReturnEmptyOptionalOnValidJsonObjectSchema() {
//given
String schemaAcceptingEverything = "{}";
mockJsonSchema(schemaAcceptingEverything);
- when(settings.jsonSchemaValidationEnabled()).thenReturn(true);
+ when(settings.eventSchemaValidationEnabled()).thenReturn(true);
//when
Optional<ResponseEntity<String>> result = sut.validate(jsonObject, DUMMY_TYPE, DUMMY_SCHEMA_VERSION);
@@ -110,6 +108,7 @@ public class EventValidatorTest {
assertEquals(Optional.empty(), result);
}
+
private void mockJsonSchema(String jsonSchemaContent) {
JsonSchemaFactory factory = JsonSchemaFactory.getInstance();
@@ -121,4 +120,4 @@ public class EventValidatorTest {
return Optional.of(ResponseEntity.status(schemaValidationFailed.httpStatusCode)
.body(schemaValidationFailed.toJSON().toString()));
}
-} \ No newline at end of file
+}