summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--a1-policy-management/config/application.yaml4
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java22
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java3
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java2
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java2
5 files changed, 20 insertions, 13 deletions
diff --git a/a1-policy-management/config/application.yaml b/a1-policy-management/config/application.yaml
index e1a778c3..d02c0a87 100644
--- a/a1-policy-management/config/application.yaml
+++ b/a1-policy-management/config/application.yaml
@@ -74,5 +74,7 @@ app:
http.proxy-type: HTTP
# path where the service can store data
vardata-directory: /var/policy-management-service
- config-file-schema-path:
+ # the config-file-schema-path referres to a location in the jar file. If this property is empty or missing,
+ # no schema validation will be executed.
+ config-file-schema-path: /application_configuration_schema.json
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java
index 3cab8aa0..726d67fc 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java
@@ -20,14 +20,15 @@
package org.onap.ccsdk.oran.a1policymanagementservice.configuration;
+import com.google.common.io.CharStreams;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import java.io.File;
import java.io.IOException;
-import java.net.URL;
-import java.nio.file.Files;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -46,6 +47,7 @@ import org.json.JSONObject;
import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
/**
* Parser for the Json representing of the component configuration.
@@ -129,13 +131,15 @@ public class ApplicationConfigParser {
}
}
- private String readSchemaFile() throws IOException {
- ClassLoader classLoader = getClass().getClassLoader();
+ private String readSchemaFile() throws IOException, ServiceException {
String filePath = applicationConfig.getConfigurationFileSchemaPath();
- URL url = classLoader.getResource(filePath);
- File file = new File(url.getFile());
- return new String(Files.readAllBytes(file.toPath()));
-
+ InputStream in = getClass().getResourceAsStream(filePath);
+ logger.debug("Reading application schema file from: {} with: {}", filePath, in);
+ if (in == null) {
+ throw new ServiceException("Could not read application configuration schema file: " + filePath,
+ HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ return CharStreams.toString(new InputStreamReader(in, StandardCharsets.UTF_8));
}
private void checkConfigurationConsistency(List<RicConfig> ricConfigs,
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java
index b0076405..3cb1d91d 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java
@@ -58,7 +58,8 @@ import org.springframework.util.StringUtils;
@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"})
@SuppressWarnings("java:S3577") // Class name should start or end with Test. This is not a test class per se,
// but a mock
// of the server.
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 d12fd6bc..4a4e8a33 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
@@ -55,7 +55,7 @@ class ApplicationConfigParserTest {
JsonObject jsonRootObject = getJsonRootObject();
when(applicationConfigMock.getConfigurationFileSchemaPath())
- .thenReturn("application_configuration_schema.json");
+ .thenReturn("/application_configuration_schema.json");
ApplicationConfigParser.ConfigParserResult result = parserUnderTest.parse(jsonRootObject);
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 d2805556..b4ff6962 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
@@ -61,7 +61,7 @@ import reactor.test.StepVerifier;
"server.ssl.key-store=./config/keystore.jks", //
"app.webclient.trust-store=./config/truststore.jks", //
"app.vardata-directory=./target", //
- "app.config-file-schema-path=application_configuration_schema.json" //
+ "app.config-file-schema-path=/application_configuration_schema.json" //
})
class ConfigurationControllerTest {
@Autowired