summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'a1-policy-management/src/test/java')
-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
2 files changed, 25 insertions, 4 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) {