aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'a1-policy-management/src/test')
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java195
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyServiceTest.java3
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelperTest.java44
3 files changed, 241 insertions, 1 deletions
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java
index 26c10d2a..834b2186 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java
@@ -117,6 +117,7 @@ class PolicyControllerV3Test {
void init() {
testHelperTest.port = port;
this.applicationConfig.setAuthProviderUrl(testHelperTest.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
+ this.applicationConfig.setValidatePolicyInstanceSchema(ApplicationConfig.ValidateSchema.NONE);
}
@AfterEach
@@ -155,6 +156,93 @@ class PolicyControllerV3Test {
testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
}
+
+ @Test
+ @DisplayName("test Create Policy Success when schema validation set to FAIL")
+ void testPolicyTypeSchemaValidationFail() throws Exception {
+ this.applicationConfig.setValidatePolicyInstanceSchema(ApplicationConfig.ValidateSchema.FAIL);
+ String nonRtRicId = "ric.1";
+ String policyTypeName = "type1_1.2.3";
+ String url = "/policies";
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBody = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
+ testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody ->
+ responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}"));
+ testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
+ }
+
+
+ @Test
+ @DisplayName("test Create Policy Success when schema validation set to INFO")
+ void testPolicyTypeSchemaValidationInfo() throws Exception {
+ this.applicationConfig.setValidatePolicyInstanceSchema(ApplicationConfig.ValidateSchema.INFO);
+ String nonRtRicId = "ric.1";
+ String policyTypeName = "type1_1.2.3";
+ String url = "/policies";
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBody = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
+ testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody ->
+ responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}"));
+ testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
+ }
+
+
+ @Test
+ @DisplayName("test Create Policy Success when schema validation set to WARN")
+ void testPolicyTypeSchemaValidationWarn() throws Exception {
+ this.applicationConfig.setValidatePolicyInstanceSchema(ApplicationConfig.ValidateSchema.WARN);
+ String nonRtRicId = "ric.1";
+ String policyTypeName = "type1_1.2.3";
+ String url = "/policies";
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBody = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
+ testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody ->
+ responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}"));
+ testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
+ }
+
+ @Test
+ @DisplayName("test bad Create Policy when schema validation set to FAIL")
+ void testBadPolicyTypeSchemaValidationFail() throws Exception {
+ this.applicationConfig.setValidatePolicyInstanceSchema(ApplicationConfig.ValidateSchema.FAIL);
+ String nonRtRicId = "ric.1";
+ String policyTypeName = "type1_1.2.3";
+ String url = "/policies";
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBody = testHelperTest.postBadPolicyBody(nonRtRicId, policyTypeName, "");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
+ testHelperTest.testErrorCode(responseMono, HttpStatus.BAD_REQUEST, "Policy Type Schema validation failed");
+ }
+
+ @Test
+ @DisplayName("test bad Create Policy when schema validation set to INFO")
+ void testBadPolicyTypeSchemaValidationInfo() throws Exception {
+ this.applicationConfig.setValidatePolicyInstanceSchema(ApplicationConfig.ValidateSchema.INFO);
+ String nonRtRicId = "ric.1";
+ String policyTypeName = "type1_1.2.3";
+ String url = "/policies";
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBody = testHelperTest.postBadPolicyBody(nonRtRicId, policyTypeName, "");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
+ testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
+ }
+
+ @Test
+ @DisplayName("test bad Create Policy when schema validation set to WARN")
+ void testBadPolicyTypeSchemaValidationWarn() throws Exception {
+ this.applicationConfig.setValidatePolicyInstanceSchema(ApplicationConfig.ValidateSchema.WARN);
+ String nonRtRicId = "ric.1";
+ String policyTypeName = "type1_1.2.3";
+ String url = "/policies";
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBody = testHelperTest.postBadPolicyBody(nonRtRicId, policyTypeName, "");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
+ testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
+ }
+
@Test
@DisplayName("test Create Policy with PolicyID sending")
void testPostPolicyWithPolicyID() throws Exception {
@@ -320,6 +408,113 @@ class PolicyControllerV3Test {
responseBody.contains("{\"scope\":{\"ueId\":\"ue5200\",\"qosId\":\"qos5200\"},\"qosObjectives\":{\"priorityLevel\":5200.0}"));
}
+
+ @Test
+ @DisplayName("test Update Policy Success when schema validation set to FAIL")
+ void testUpdatePolicyTypeSchemaValidationFail() throws Exception {
+ this.applicationConfig.setValidatePolicyInstanceSchema(ApplicationConfig.ValidateSchema.FAIL);
+ String nonRtRicId = "ric.1";
+ String policyTypeName = "type1_1.2.3";
+ String url = "/policies";
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBodyForPost = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "policyOne");
+ testHelperTest.restClientV3().postForEntity(url, policyBodyForPost).block();
+ String policyBodyForPut = testHelperTest.putPolicyBody(nonRtRicId, policyTypeName, "policyOne", "ue5200",
+ "qos5200", "5200.0");
+ testHelperTest.restClientV3().putForEntity(url+"/policyOne", policyBodyForPut).block();
+ Mono<ResponseEntity<String>> responseMonoGet = testHelperTest.restClientV3().getForEntity(url+"/policyOne");
+ testHelperTest.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody ->
+ responseBody.contains("{\"scope\":{\"ueId\":\"ue5200\",\"qosId\":\"qos5200\"},\"qosObjectives\":{\"priorityLevel\":5200.0}"));
+ }
+
+
+ @Test
+ @DisplayName("test Update Policy Success when schema validation set to INFO")
+ void testUpdatePolicyTypeSchemaValidationInfo() throws Exception {
+ this.applicationConfig.setValidatePolicyInstanceSchema(ApplicationConfig.ValidateSchema.INFO);
+ String nonRtRicId = "ric.1";
+ String policyTypeName = "type1_1.2.3";
+ String url = "/policies";
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBodyForPost = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "policyOne");
+ testHelperTest.restClientV3().postForEntity(url, policyBodyForPost).block();
+ String policyBodyForPut = testHelperTest.putPolicyBody(nonRtRicId, policyTypeName, "policyOne", "ue5200",
+ "qos5200", "5200.0");
+ testHelperTest.restClientV3().putForEntity(url+"/policyOne", policyBodyForPut).block();
+ Mono<ResponseEntity<String>> responseMonoGet = testHelperTest.restClientV3().getForEntity(url+"/policyOne");
+ testHelperTest.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody ->
+ responseBody.contains("{\"scope\":{\"ueId\":\"ue5200\",\"qosId\":\"qos5200\"},\"qosObjectives\":{\"priorityLevel\":5200.0}"));
+ }
+
+
+ @Test
+ @DisplayName("test Update Policy Success when schema validation set to WARN")
+ void testUpdatePolicyTypeSchemaValidationWarn() throws Exception {
+ this.applicationConfig.setValidatePolicyInstanceSchema(ApplicationConfig.ValidateSchema.WARN);
+ String nonRtRicId = "ric.1";
+ String policyTypeName = "type1_1.2.3";
+ String url = "/policies";
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBodyForPost = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "policyOne");
+ testHelperTest.restClientV3().postForEntity(url, policyBodyForPost).block();
+ String policyBodyForPut = testHelperTest.putPolicyBody(nonRtRicId, policyTypeName, "policyOne", "ue5200",
+ "qos5200", "5200.0");
+ testHelperTest.restClientV3().putForEntity(url+"/policyOne", policyBodyForPut).block();
+ Mono<ResponseEntity<String>> responseMonoGet = testHelperTest.restClientV3().getForEntity(url+"/policyOne");
+ testHelperTest.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody ->
+ responseBody.contains("{\"scope\":{\"ueId\":\"ue5200\",\"qosId\":\"qos5200\"},\"qosObjectives\":{\"priorityLevel\":5200.0}"));
+ }
+
+ @Test
+ @DisplayName("test bad Update Policy when schema validation set to FAIL")
+ void testUpdateBadPolicyTypeSchemaValidationFail() throws Exception {
+ this.applicationConfig.setValidatePolicyInstanceSchema(ApplicationConfig.ValidateSchema.FAIL);
+ String nonRtRicId = "ric.1";
+ String policyTypeName = "type1_1.2.3";
+ String url = "/policies";
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBodyForPost = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "policyOne");
+ testHelperTest.restClientV3().postForEntity(url, policyBodyForPost).block();
+ String policyBodyForPut = testHelperTest.putBadPolicyBody(nonRtRicId, policyTypeName, "policyOne", "ue5200",
+ "qos5200", "5200.0", "bar");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().putForEntity(url+"/policyOne", policyBodyForPut);
+ testHelperTest.testErrorCode(responseMono, HttpStatus.BAD_REQUEST, "Policy Type Schema validation failed");
+ }
+
+ @Test
+ @DisplayName("test bad Update Policy when schema validation set to WARN")
+ void testUpdateBadPolicyTypeSchemaValidationWarn() throws Exception {
+ this.applicationConfig.setValidatePolicyInstanceSchema(ApplicationConfig.ValidateSchema.WARN);
+ String nonRtRicId = "ric.1";
+ String policyTypeName = "type1_1.2.3";
+ String url = "/policies";
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBodyForPost = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "policyOne");
+ testHelperTest.restClientV3().postForEntity(url, policyBodyForPost).block();
+ String policyBodyForPut = testHelperTest.putBadPolicyBody(nonRtRicId, policyTypeName, "policyOne", "ue5200",
+ "qos5200", "5200.0", "bar");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().putForEntity(url+"/policyOne", policyBodyForPut);
+ testHelperTest.testSuccessResponse(responseMono, HttpStatus.OK, responseBody ->
+ responseBody.contains("{\"scope\":{\"ueId\":\"ue5200\",\"qosId\":\"qos5200\",\"foo\":\"bar\"},\"qosObjectives\":{\"priorityLevel\":5200.0}}"));
+ }
+
+ @Test
+ @DisplayName("test bad Update Policy when schema validation set to INFO")
+ void testUpdateBadPolicyTypeSchemaValidationInfo() throws Exception {
+ this.applicationConfig.setValidatePolicyInstanceSchema(ApplicationConfig.ValidateSchema.INFO);
+ String nonRtRicId = "ric.1";
+ String policyTypeName = "type1_1.2.3";
+ String url = "/policies";
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBodyForPost = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "policyOne");
+ testHelperTest.restClientV3().postForEntity(url, policyBodyForPost).block();
+ String policyBodyForPut = testHelperTest.putBadPolicyBody(nonRtRicId, policyTypeName, "policyOne", "ue5200",
+ "qos5200", "5200.0", "bar");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().putForEntity(url+"/policyOne", policyBodyForPut);
+ testHelperTest.testSuccessResponse(responseMono, HttpStatus.OK, responseBody ->
+ responseBody.contains("{\"scope\":{\"ueId\":\"ue5200\",\"qosId\":\"qos5200\",\"foo\":\"bar\"},\"qosObjectives\":{\"priorityLevel\":5200.0}}"));
+ }
+
private void postPolicyWithTokenAndVerify(String clientId, String serviceId, String result) throws IOException {
testHelperTest.addPolicyType("type1_1.2.3", "ric.1");
String policyBody = testHelperTest.postPolicyBody("ric.1", "type1_1.2.3", "1");
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyServiceTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyServiceTest.java
index f2b74ef3..8e0d3c1c 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyServiceTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyServiceTest.java
@@ -122,6 +122,7 @@ class PolicyServiceTest {
Policy policy = testHelperTest.buidTestPolicy(testHelperTest.policyObjectInfo(nonRtRicId, policyTypeName), "122344-5674");
when(helper.jsonSchemaValidation(any())).thenReturn(Boolean.TRUE);
when(helper.buildPolicy(any(),any(), any(), any(), any())).thenReturn(policy);
+ when(helper.performPolicySchemaValidation(any(), any())).thenReturn(Boolean.TRUE);
when(helper.isPolicyAlreadyCreated(any(), any())).thenReturn(Mono.error(new ServiceException
("Same policy content already created with policy ID: 122344-5674", HttpStatus.BAD_REQUEST)));
Mono<ResponseEntity<PolicyObjectInformation>> responseMono = policyService.createPolicyService(testHelperTest.policyObjectInfo(nonRtRicId, policyTypeName), serverWebExchange);
@@ -136,6 +137,7 @@ class PolicyServiceTest {
testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
when(helper.jsonSchemaValidation(any())).thenReturn(Boolean.TRUE);
+ when(helper.performPolicySchemaValidation(any(), any())).thenReturn(Boolean.TRUE);
when(helper.isPolicyAlreadyCreated(any(), any())).thenReturn(Mono.just(Policy.builder().build()));
when(authorizationService.authCheck(any(), any(), any())).thenReturn(Mono.error(new ServiceException("Not authorized", HttpStatus.UNAUTHORIZED)));
Mono<ResponseEntity<PolicyObjectInformation>> responseMono = policyService.createPolicyService(testHelperTest.policyObjectInfo(nonRtRicId, policyTypeName), serverWebExchange);
@@ -189,6 +191,7 @@ class PolicyServiceTest {
when(helper.buildPolicy(any(),any(), any(), any(), any())).thenReturn(updatedPolicy);
when(helper.checkRicStateIdle(any())).thenReturn(Mono.just(updatedPolicy.getRic()));
when(helper.checkSupportedType(any(), any())).thenReturn(Mono.just(updatedPolicy.getRic()));
+ when(helper.performPolicySchemaValidation(any(), any())).thenReturn(Boolean.TRUE);
when(authorizationService.authCheck(any(), any(), any())).thenReturn(Mono.just(updatedPolicy));
Mono<ResponseEntity<Object>> responseMono = policyService.putPolicyService(policy.getId(), updatedPolicyObjectInfo.getPolicyObject(), serverWebExchange);
testHelperTest.testSuccessResponse(responseMono, HttpStatus.OK, responseBody -> {
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelperTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelperTest.java
index 78ab385c..c36429c6 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelperTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelperTest.java
@@ -2,7 +2,7 @@
* ========================LICENSE_START=================================
* ONAP : ccsdk oran
* ======================================================================
- * Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.
+ * Copyright (C) 2024-2025 OpenInfra Foundation Europe. 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.
@@ -170,6 +170,13 @@ public class TestHelperTest {
return gson.toJson(policyObjectInfo);
}
+ public String postBadPolicyBody(String nearRtRicId, String policyTypeName, String policyId) {
+ PolicyObjectInformation policyObjectInfo = new PolicyObjectInformation(nearRtRicId, dummyBadPolicyObject(), policyTypeName);
+ if (policyId != null && !policyId.isEmpty() && !policyId.isBlank())
+ policyObjectInfo.setPolicyId(policyId);
+ return gson.toJson(policyObjectInfo);
+ }
+
public String putPolicyBody(String nearRtRicId, String policyTypeName, String policyId, String ueId, String qosId,
String priorityLevel) {
PolicyObjectInformation policyObjectInfo = new PolicyObjectInformation(nearRtRicId, dummyPolicyObjectForPut(
@@ -179,6 +186,15 @@ public class TestHelperTest {
return gson.toJson(policyObjectInfo);
}
+ public String putBadPolicyBody(String nearRtRicId, String policyTypeName, String policyId, String ueId, String qosId,
+ String priorityLevel, String foo) {
+ PolicyObjectInformation policyObjectInfo = new PolicyObjectInformation(nearRtRicId, dummyBadPolicyObjectForPut(
+ ueId, qosId, priorityLevel, foo), policyTypeName);
+ if (policyId != null && !policyId.isEmpty() && !policyId.isBlank())
+ policyObjectInfo.setPolicyId(policyId);
+ return gson.toJson(policyObjectInfo);
+ }
+
public PolicyObjectInformation policyObjectInfo(String nearRtRicId, String policyTypeName) {
return gson.fromJson(postPolicyBody(nearRtRicId, policyTypeName, ""), PolicyObjectInformation.class);
}
@@ -195,6 +211,19 @@ public class TestHelperTest {
" }").getAsJsonObject();
}
+ public JsonObject dummyBadPolicyObjectForPut(String... values) {
+ return JsonParser.parseString("{\n" +
+ " \"scope\": {\n" +
+ " \"ueId\": \"" + values[0] + "\",\n" +
+ " \"qosId\": \"" + values[1] + "\",\n" +
+ " \"foo\": \"" + values[3] + "\"\n" +
+ " },\n" +
+ " \"qosObjectives\": {\n" +
+ " \"priorityLevel\": " + values[2] + "\n" +
+ " }\n" +
+ " }").getAsJsonObject();
+ }
+
public JsonObject dummyPolicyObject() {
return JsonParser.parseString("{\n" +
" \"scope\": {\n" +
@@ -207,6 +236,19 @@ public class TestHelperTest {
" }").getAsJsonObject();
}
+ public JsonObject dummyBadPolicyObject() {
+ return JsonParser.parseString("{\n" +
+ " \"scope\": {\n" +
+ " \"ueId\": \"ue5100\",\n" +
+ " \"qosId\": \"qos5100\",\n" +
+ " \"foo\": \"bar\"\n" +
+ " },\n" +
+ " \"qosObjectives\": {\n" +
+ " \"priorityLevel\": 5100.0\n" +
+ " }\n" +
+ " }").getAsJsonObject();
+ }
+
public Policy buidTestPolicy(PolicyObjectInformation policyInfo, String id) throws Exception{
return Policy.builder().ric(rics.getRic(policyInfo.getNearRtRicId()))
.type(policyTypes.getType(policyInfo.getPolicyTypeId()))