aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/test
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2021-09-21 14:47:59 +0200
committerPatrikBuhr <patrik.buhr@est.tech>2021-09-22 18:06:39 +0200
commitd279ef72d0b634f9fa57b4bce9dffebebf010d83 (patch)
tree5ef174d6ccbfe5d33681e97cf728aaf6afe31808 /a1-policy-management/src/test
parent65cf80bbd2eba0ab60d174c04f981ff6cf929e36 (diff)
Create a json schema for validation of the configuration of the A1 PMS - A1 Jakarta
To create a json schema to be used for validation of the PMS configuration. The schema shall be used by PMS. It can also be used by the end user. The documentation should be updated on how can be done. Issue-ID: CCSDK-3468 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech> Change-Id: I9932fa42ff40681098764c8dc84ac201bb3fabaf
Diffstat (limited to 'a1-policy-management/src/test')
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java22
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java7
-rw-r--r--a1-policy-management/src/test/resources/test_application_configuration.json6
-rw-r--r--a1-policy-management/src/test/resources/test_application_configuration_with_dmaap_config.json1
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",