diff options
Diffstat (limited to 'a1-policy-management/src/test')
4 files changed, 29 insertions, 7 deletions
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java index 5e218582..d12fd6bc 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java @@ -20,8 +20,11 @@ package org.onap.ccsdk.oran.a1policymanagementservice.configuration; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; import com.google.common.base.Charsets; import com.google.common.io.Resources; @@ -44,12 +47,16 @@ import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException class ApplicationConfigParserTest { - ApplicationConfigParser parserUnderTest = new ApplicationConfigParser(); + ApplicationConfig applicationConfigMock = spy(new ApplicationConfig()); + ApplicationConfigParser parserUnderTest = new ApplicationConfigParser(applicationConfigMock); @Test void whenCorrectConfig() throws Exception { JsonObject jsonRootObject = getJsonRootObject(); + when(applicationConfigMock.getConfigurationFileSchemaPath()) + .thenReturn("application_configuration_schema.json"); + ApplicationConfigParser.ConfigParserResult result = parserUnderTest.parse(jsonRootObject); String topicUrl = result.dmaapProducerTopicUrl(); @@ -153,6 +160,19 @@ class ApplicationConfigParserTest { assertEquals(message, actualException.getMessage(), "Wrong error message when wrong member name in object"); } + @Test + void schemaValidationError() throws Exception { + when(applicationConfigMock.getConfigurationFileSchemaPath()) + .thenReturn("application_configuration_schema.json"); + JsonObject jsonRootObject = getJsonRootObject(); + JsonObject json = jsonRootObject.getAsJsonObject("config"); + json.remove("ric"); + + Exception actualException = assertThrows(ServiceException.class, () -> parserUnderTest.parse(jsonRootObject)); + + assertThat(actualException.getMessage()).contains("Json schema validation failure"); + } + JsonObject getDmaapInfo(JsonObject jsonRootObject, String streamsPublishesOrSubscribes, String dmaapPublisherOrSubscriber) throws Exception { return jsonRootObject.getAsJsonObject("config").getAsJsonObject(streamsPublishesOrSubscribes) diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java index adb29a70..d2805556 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java @@ -60,7 +60,9 @@ import reactor.test.StepVerifier; @TestPropertySource(properties = { // "server.ssl.key-store=./config/keystore.jks", // "app.webclient.trust-store=./config/truststore.jks", // - "app.vardata-directory=./target"}) + "app.vardata-directory=./target", // + "app.config-file-schema-path=application_configuration_schema.json" // +}) class ConfigurationControllerTest { @Autowired ApplicationContext context; @@ -135,8 +137,7 @@ class ConfigurationControllerTest { String url = "a1-policy/v2/configuration"; // Valid JSON but invalid configuration. - testErrorCode(restClient().put(url, "{\"error\":\"error\"}"), HttpStatus.BAD_REQUEST, - "Missing root configuration"); + testErrorCode(restClient().put(url, "{\"error\":\"error\"}"), HttpStatus.BAD_REQUEST, ""); } private void testErrorCode(Mono<?> request, HttpStatus expStatus, String responseContains) { diff --git a/a1-policy-management/src/test/resources/test_application_configuration.json b/a1-policy-management/src/test/resources/test_application_configuration.json index 3cbc371c..959f53fd 100644 --- a/a1-policy-management/src/test/resources/test_application_configuration.json +++ b/a1-policy-management/src/test/resources/test_application_configuration.json @@ -1,6 +1,6 @@ -{ +{ "config": { - "//description": "Application configuration", + "description": "Application configuration", "ric": [ { "name": "ric1", @@ -36,4 +36,4 @@ } } } -}
\ No newline at end of file +} diff --git a/a1-policy-management/src/test/resources/test_application_configuration_with_dmaap_config.json b/a1-policy-management/src/test/resources/test_application_configuration_with_dmaap_config.json index ed1501dd..b00720c3 100644 --- a/a1-policy-management/src/test/resources/test_application_configuration_with_dmaap_config.json +++ b/a1-policy-management/src/test/resources/test_application_configuration_with_dmaap_config.json @@ -1,5 +1,6 @@ { "config": { + "//description" : "Test", "controller": [ { "name": "controller1", |