diff options
author | awudzins <adam.wudzinski@nokia.com> | 2020-01-13 11:43:08 +0100 |
---|---|---|
committer | awudzins <adam.wudzinski@nokia.com> | 2020-01-17 14:39:20 +0100 |
commit | ab6421bcf7b480f9955b6b4376554ec9677e71ed (patch) | |
tree | 347d29e9629a04888daf1fd216284f15b72a7149 /src/test/java/org/onap/dcae/restapi/EventValidatorTest.java | |
parent | 7e5a7d1d8cd74e42c8549e02724ec2df589e4117 (diff) |
Changed EventTransformation schema to be loaded only once
Issue-ID: DCAEGEN2-1774
Signed-off-by: adamwudzinski <adam.wudzinski@nokia.com>
Change-Id: I50f3da2c11201a40be948ab199aaca89bbbb38db
Diffstat (limited to 'src/test/java/org/onap/dcae/restapi/EventValidatorTest.java')
-rw-r--r-- | src/test/java/org/onap/dcae/restapi/EventValidatorTest.java | 29 |
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 +} |