aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorraviteja.karumuri <raviteja.karumuri@est.tech>2024-11-18 14:54:35 +0000
committerRAVITEJA KARUMURI <raviteja.karumuri@est.tech>2024-11-22 18:20:56 +0000
commitcc0d65f80ddeac1fb99a433cc25eceb0745ce6f9 (patch)
tree99014a4cbc7c12842f9402239fc403fb51068f38
parentad619dbb43bcdc7c0456a633c9ef1f64fca90cdc (diff)
Entry and Exit Logging Tests
Issue-ID: CCSDK-4040 Change-Id: I64672c1b31c7b3e0506eae4bbecdeecd259ddea7 Signed-off-by: Raviteja Karumuri <raviteja.karumuri@est.tech>
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/ReactiveEntryExitFilter.java34
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3Test.java20
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java128
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3Test.java22
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3Test.java24
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyServiceTest.java66
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterDisableTest.java82
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterTest.java82
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelperTest.java (renamed from a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelper.java)2
9 files changed, 308 insertions, 152 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/ReactiveEntryExitFilter.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/ReactiveEntryExitFilter.java
index 34376614..01830ff4 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/ReactiveEntryExitFilter.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/ReactiveEntryExitFilter.java
@@ -28,7 +28,6 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.http.server.reactive.ServerHttpResponseDecorator;
-import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
@@ -50,43 +49,36 @@ public class ReactiveEntryExitFilter implements WebFilter {
ServerHttpRequest httpRequest = exchange.getRequest();
ServerHttpResponse httpResponse = exchange.getResponse();
MultiValueMap<String, String> queryParams = httpRequest.getQueryParams();
- logger.info("Request received with path: {} and the Request Id: {}", httpRequest.getPath(), exchange.getRequest().getId());
+ logger.info("Request received with path: {}, and the Request Id: {}, with HTTP Method: {}", httpRequest.getPath(),
+ exchange.getRequest().getId(), exchange.getRequest().getMethod());
if (!queryParams.isEmpty())
logger.trace("For the request Id: {}, the Query parameters are: {}", exchange.getRequest().getId(), queryParams);
ServerHttpRequestDecorator loggingServerHttpRequestDecorator = new ServerHttpRequestDecorator(exchange.getRequest()) {
- String requestBody = "";
+ String requestBody;
@Override
public Flux<DataBuffer> getBody() {
return super.getBody().doOnNext(dataBuffer -> {
- try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
- Channels.newChannel(byteArrayOutputStream).write(dataBuffer.asByteBuffer().asReadOnlyBuffer());
- requestBody = byteArrayOutputStream.toString(StandardCharsets.UTF_8);
- if (requestBody != null)
- logger.trace("For the request ID: {} the received request body: {}", exchange.getRequest().getId(), requestBody);
- } catch (IOException e) {
- logger.info("For the request ID: {} we got the error during processing: {}", exchange.getRequest().getId(), e.getMessage());
+ requestBody = dataBuffer.toString(StandardCharsets.UTF_8); // Read the bytes from the DataBuffer
+ if (!(requestBody.isEmpty() && requestBody.isBlank()))
logger.trace("For the request ID: {} the received request body: {}", exchange.getRequest().getId(), requestBody);
- }
});
}
};
-
ServerHttpResponseDecorator loggingServerHttpResponseDecorator = new ServerHttpResponseDecorator(exchange.getResponse()) {
- String responseBody = "";
+ String responseBody;
@Override
public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) {
Flux<DataBuffer> buffer = Flux.from(body);
return super.writeWith(buffer.doOnNext(dataBuffer -> {
- try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
- Channels.newChannel(byteArrayOutputStream).write(dataBuffer.toByteBuffer().asReadOnlyBuffer());
- responseBody = byteArrayOutputStream.toString(StandardCharsets.UTF_8);
+// try {
+ dataBuffer.toString(StandardCharsets.UTF_8);
logger.info("For the request ID: {} the Status code of the response: {}", exchange.getRequest().getId(), httpResponse.getStatusCode());
logger.trace("For the request ID: {} the response is: {} ", exchange.getRequest().getId(), responseBody);
- } catch (Exception e) {
- logger.info("For the request ID: {} we got an Error during processing: {}", exchange.getRequest().getId(), e.getMessage());
- logger.trace("For the request ID: {} the response body :: {}", exchange.getRequest().getId(), responseBody);
- }
+// } catch (Exception e) {
+// logger.info("For the request ID: {} we got an Error during processing: {}", exchange.getRequest().getId(), e.getMessage());
+// logger.trace("For the request ID: {} the response body :: {}", exchange.getRequest().getId(), responseBody);
+// }
}));
}
};
@@ -94,4 +86,4 @@ public class ReactiveEntryExitFilter implements WebFilter {
}
-}
+} \ No newline at end of file
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3Test.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3Test.java
index 1f0ea5d0..d9fa63a9 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3Test.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3Test.java
@@ -23,7 +23,7 @@ import org.junit.jupiter.api.io.TempDir;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
import org.onap.ccsdk.oran.a1policymanagementservice.tasks.RefreshConfigTask;
-import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelper;
+import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelperTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
@@ -63,7 +63,7 @@ class ConfigurationControllerV3Test {
private Rics rics;
@Autowired
- private TestHelper testHelper;
+ private TestHelperTest testHelperTest;
@TempDir
public static File temporaryFolder;
@@ -74,7 +74,7 @@ class ConfigurationControllerV3Test {
@BeforeEach
void init() {
- testHelper.port = port;
+ testHelperTest.port = port;
}
@BeforeAll
static void setup() throws Exception {
@@ -109,19 +109,19 @@ class ConfigurationControllerV3Test {
@Test
void testPutConfiguration() throws Exception {
- Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().putForEntity("/configuration",
- testHelper.configAsString());
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, Objects::isNull);
+ Mono<ResponseEntity<String>> responseEntityMono = testHelperTest.restClientV3().putForEntity("/configuration",
+ testHelperTest.configAsString());
+ testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, Objects::isNull);
//put Valid Configuration With New Ric should Update Repository. So, will wait until the ric size is 2
await().until(rics::size, equalTo(2));
//test Get Configuration
- Mono<ResponseEntity<String>> responseGetConfigMono = testHelper.restClientV3().getForEntity("/configuration");
- testHelper.testSuccessResponse(responseGetConfigMono, HttpStatus.OK, responseBody -> responseBody.contains("config"));
+ Mono<ResponseEntity<String>> responseGetConfigMono = testHelperTest.restClientV3().getForEntity("/configuration");
+ testHelperTest.testSuccessResponse(responseGetConfigMono, HttpStatus.OK, responseBody -> responseBody.contains("config"));
}
@Test
void testHealthCheck() {
- Mono<ResponseEntity<String>> responseHealthCheckMono = testHelper.restClientV3().getForEntity("/status");
- testHelper.testSuccessResponse(responseHealthCheckMono, HttpStatus.OK, responseBody -> responseBody.contains("status"));
+ Mono<ResponseEntity<String>> responseHealthCheckMono = testHelperTest.restClientV3().getForEntity("/status");
+ testHelperTest.testSuccessResponse(responseHealthCheckMono, HttpStatus.OK, responseBody -> responseBody.contains("status"));
}
}
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 14604542..6c597856 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
@@ -33,7 +33,7 @@ import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services;
import org.onap.ccsdk.oran.a1policymanagementservice.util.v3.Helper;
import org.onap.ccsdk.oran.a1policymanagementservice.utils.MockA1ClientFactory;
-import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelper;
+import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelperTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -72,7 +72,7 @@ class PolicyControllerV3Test {
private ApplicationConfig applicationConfig;
@Autowired
- private TestHelper testHelper;
+ private TestHelperTest testHelperTest;
@Autowired
private Rics rics;
@@ -109,8 +109,8 @@ class PolicyControllerV3Test {
@BeforeEach
void init() {
- testHelper.port = port;
- this.applicationConfig.setAuthProviderUrl(testHelper.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
+ testHelperTest.port = port;
+ this.applicationConfig.setAuthProviderUrl(testHelperTest.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
}
@AfterEach
@@ -141,12 +141,12 @@ class PolicyControllerV3Test {
String nonRtRicId = "ric.1";
String policyTypeName = "type1_1.2.3";
String url = "/policies";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName, "");
- Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
- testHelper.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody ->
+ 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}}"));
- testHelper.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
+ testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
}
@Test
@@ -155,10 +155,10 @@ class PolicyControllerV3Test {
String nonRtRicId = "ric.1";
String policyTypeName = "type1_1.2.3";
String url = "/policies";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName, "1");
- Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
- testHelper.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/1"));
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBody = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "1");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
+ testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/1"));
}
@Test
@@ -168,11 +168,11 @@ class PolicyControllerV3Test {
String policyTypeName = "type1_1.2.3";
String url = "/policies";
String policyId = "policy_5g";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName, policyId);
- testHelper.restClientV3().postForEntity(url, policyBody).block();
- Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
- testHelper.testErrorCode(responseMono, HttpStatus.CONFLICT, "Policy already created with ID: " +policyId);
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBody = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, policyId);
+ testHelperTest.restClientV3().postForEntity(url, policyBody).block();
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
+ testHelperTest.testErrorCode(responseMono, HttpStatus.CONFLICT, "Policy already created with ID: " +policyId);
}
@Test
@@ -181,14 +181,14 @@ class PolicyControllerV3Test {
String nonRtRicId = "ric.1";
String policyTypeName = "type1_1.2.3";
String url = "/policies";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName, "");
- Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBody = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
String []locationHeader = Objects.requireNonNull(Objects.requireNonNull(responseMono.block()).getHeaders()
.get("location")).get(0).split("/");
String policyID = locationHeader[(locationHeader.length) - 1];
- Mono<ResponseEntity<String>> responseMonoDelete = testHelper.restClientV3().deleteForEntity(url+"/" +policyID);
- testHelper.testSuccessResponse(responseMonoDelete, HttpStatus.NO_CONTENT, responseBody -> true);
+ Mono<ResponseEntity<String>> responseMonoDelete = testHelperTest.restClientV3().deleteForEntity(url+"/" +policyID);
+ testHelperTest.testSuccessResponse(responseMonoDelete, HttpStatus.NO_CONTENT, responseBody -> true);
}
@Test
@@ -197,11 +197,11 @@ class PolicyControllerV3Test {
String nonRtRicId = "ric.1";
String policyTypeName = "type1_1.2.3";
String url = "/policies";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
when(helper.jsonSchemaValidation(any())).thenReturn(Boolean.FALSE);
- String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName, "");
- Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
- testHelper.testErrorCode(responseMono, HttpStatus.BAD_REQUEST, " Schema validation failed");
+ String policyBody = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
+ testHelperTest.testErrorCode(responseMono, HttpStatus.BAD_REQUEST, " Schema validation failed");
}
@Test
@@ -209,11 +209,11 @@ class PolicyControllerV3Test {
void testCreatePolicyNoRic() throws Exception {
String policyTypeName = "type1_1.2.3";
String url = "/policies";
- testHelper.addPolicyType(policyTypeName, " ");
+ testHelperTest.addPolicyType(policyTypeName, " ");
when(helper.jsonSchemaValidation(any())).thenReturn(Boolean.TRUE);
- String policyBody = testHelper.postPolicyBody("noRic", policyTypeName, "");
- Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
- testHelper.testErrorCode(responseMono, HttpStatus.NOT_FOUND, " Could not find ric: noRic");
+ String policyBody = testHelperTest.postPolicyBody("noRic", policyTypeName, "");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
+ testHelperTest.testErrorCode(responseMono, HttpStatus.NOT_FOUND, " Could not find ric: noRic");
}
@Test
@@ -222,20 +222,20 @@ class PolicyControllerV3Test {
String policyTypeName = "type1_1.2.3";
String nonRtRicId = "ricOne";
String url = "/policies";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
when(helper.jsonSchemaValidation(any())).thenReturn(Boolean.TRUE);
- String policyBody = testHelper.postPolicyBody(nonRtRicId, "noPolicyType", "");
- Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
- testHelper.testErrorCode(responseMono, HttpStatus.NOT_FOUND, "Could not find type: noPolicyType");
+ String policyBody = testHelperTest.postPolicyBody(nonRtRicId, "noPolicyType", "");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
+ testHelperTest.testErrorCode(responseMono, HttpStatus.NOT_FOUND, "Could not find type: noPolicyType");
}
@Test
void testGetPolicyTypesNoRicFound() throws Exception{
String policyTypeName = "type1_1.2.3";
String nonRtRicId = "ricOne";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().getForEntity("/policy-types" + "?nearRtRicId=\"noRic\"");
- testHelper.testErrorCode(responseMono, HttpStatus.NOT_FOUND, "Near-RT RIC not Found using ID:");
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().getForEntity("/policy-types" + "?nearRtRicId=\"noRic\"");
+ testHelperTest.testErrorCode(responseMono, HttpStatus.NOT_FOUND, "Near-RT RIC not Found using ID:");
}
@Test
@@ -244,14 +244,14 @@ class PolicyControllerV3Test {
String nonRtRicId = "ric.1";
String policyTypeName = "type1_1.2.3";
String url = "/policies";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName, "");
- Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBody = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "");
+ Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
String []locationHeader = Objects.requireNonNull(Objects.requireNonNull(responseMono.block()).getHeaders()
.get("location")).get(0).split("/");
String policyID = locationHeader[(locationHeader.length) - 1];
- Mono<ResponseEntity<String>> responseMonoGet = testHelper.restClientV3().getForEntity(url+"/" +policyID);
- testHelper.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody ->
+ Mono<ResponseEntity<String>> responseMonoGet = testHelperTest.restClientV3().getForEntity(url+"/" +policyID);
+ testHelperTest.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody ->
responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}"));
}
@@ -262,14 +262,14 @@ class PolicyControllerV3Test {
String nonRtRicIdTwo = "ric.22";
String policyTypeName = "type1_1.2.3";
String url = "/policies";
- testHelper.addPolicyType(policyTypeName, nonRtRicIdOne);
- String policyBodyOne = testHelper.postPolicyBody(nonRtRicIdOne, policyTypeName, "policyOne");
- testHelper.addPolicyType(policyTypeName, nonRtRicIdTwo);
- String policyBodyTwo = testHelper.postPolicyBody(nonRtRicIdTwo, policyTypeName, "policyTwo");
- testHelper.restClientV3().postForEntity(url, policyBodyOne).block();
- testHelper.restClientV3().postForEntity(url, policyBodyTwo).block();
- Mono<ResponseEntity<String>> responseMonoGet = testHelper.restClientV3().getForEntity(url);
- testHelper.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody ->
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicIdOne);
+ String policyBodyOne = testHelperTest.postPolicyBody(nonRtRicIdOne, policyTypeName, "policyOne");
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicIdTwo);
+ String policyBodyTwo = testHelperTest.postPolicyBody(nonRtRicIdTwo, policyTypeName, "policyTwo");
+ testHelperTest.restClientV3().postForEntity(url, policyBodyOne).block();
+ testHelperTest.restClientV3().postForEntity(url, policyBodyTwo).block();
+ Mono<ResponseEntity<String>> responseMonoGet = testHelperTest.restClientV3().getForEntity(url);
+ testHelperTest.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody ->
responseBody.contains("[{\"policyId\":\"policyTwo\",\"nearRtRicId\":\"ric.22\"},{\"policyId\":\"policyOne\",\"nearRtRicId\":\"ric.11\"}]"));
}
@@ -279,9 +279,9 @@ class PolicyControllerV3Test {
String nonRtRicId = "ric.1";
String policyTypeName = "type1_1.2.3";
String url = "/policy-types";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- Mono<ResponseEntity<String>> responseMonoGet = testHelper.restClientV3().getForEntity(url+"/" +policyTypeName);
- testHelper.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody -> !(responseBody.isEmpty()));
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ Mono<ResponseEntity<String>> responseMonoGet = testHelperTest.restClientV3().getForEntity(url+"/" +policyTypeName);
+ testHelperTest.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody -> !(responseBody.isEmpty()));
}
@Test
@@ -290,9 +290,9 @@ class PolicyControllerV3Test {
String nonRtRicId = "ric.1";
String policyTypeName = "type1_1.2.3";
String url = "/policy-types";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- Mono<ResponseEntity<String>> responseMonoGet = testHelper.restClientV3().getForEntity(url);
- testHelper.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody -> responseBody.contains(
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ Mono<ResponseEntity<String>> responseMonoGet = testHelperTest.restClientV3().getForEntity(url);
+ testHelperTest.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody -> responseBody.contains(
"{\"policyTypeId\":\"type1_1.2.3\",\"nearRtRicId\":\"ric.1\"}]"
));
}
@@ -303,14 +303,14 @@ class PolicyControllerV3Test {
String nonRtRicId = "ric.1";
String policyTypeName = "type1_1.2.3";
String url = "/policies";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- String policyBodyForPost = testHelper.postPolicyBody(nonRtRicId, policyTypeName, "policyOne");
- testHelper.restClientV3().postForEntity(url, policyBodyForPost).block();
- String policyBodyForPut = testHelper.putPolicyBody(nonRtRicId, policyTypeName, "policyOne", "ue5200",
+ 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");
- testHelper.restClientV3().putForEntity(url+"/policyOne", policyBodyForPut).block();
- Mono<ResponseEntity<String>> responseMonoGet = testHelper.restClientV3().getForEntity(url+"/policyOne");
- testHelper.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody ->
+ 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}"));
}
} \ No newline at end of file
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3Test.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3Test.java
index 63b61665..455ea0cf 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3Test.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3Test.java
@@ -29,7 +29,7 @@ import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.RappSimulato
import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
import org.onap.ccsdk.oran.a1policymanagementservice.utils.MockA1ClientFactory;
-import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelper;
+import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelperTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -59,7 +59,7 @@ class RicRepositoryControllerV3Test {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@Autowired
- private TestHelper testHelper;
+ private TestHelperTest testHelperTest;
@Autowired
private ApplicationConfig applicationConfig;
@@ -87,9 +87,9 @@ class RicRepositoryControllerV3Test {
@BeforeEach
void init() {
- testHelper.port = port;
+ testHelperTest.port = port;
rics.clear();
- this.applicationConfig.setAuthProviderUrl(testHelper.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
+ this.applicationConfig.setAuthProviderUrl(testHelperTest.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
}
@AfterEach
@@ -104,18 +104,18 @@ class RicRepositoryControllerV3Test {
@Test
void testGetRic() throws IOException {
- testHelper.addPolicyType("1", "ricAdded");
- Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().getForEntity("/rics/ric?ricId=ricAdded");
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody
+ testHelperTest.addPolicyType("1", "ricAdded");
+ Mono<ResponseEntity<String>> responseEntityMono = testHelperTest.restClientV3().getForEntity("/rics/ric?ricId=ricAdded");
+ testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody
.contains("{\"ricId\":\"ricAdded\",\"managedElementIds\":[],\"state\":\"AVAILABLE\",\"policyTypeIds\":[\"1\"]}"));
}
@Test
void testGetRics() throws IOException {
- testHelper.addPolicyType("1", "ricAddedOne");
- testHelper.addPolicyType("2", "ricAddedTwo");
- Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().getForEntity("/rics");
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody
+ testHelperTest.addPolicyType("1", "ricAddedOne");
+ testHelperTest.addPolicyType("2", "ricAddedTwo");
+ Mono<ResponseEntity<String>> responseEntityMono = testHelperTest.restClientV3().getForEntity("/rics");
+ testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody
.contains("{\"ricId\":\"ricAddedTwo\",\"managedElementIds\":[],\"state\":\"AVAILABLE\"," +
"\"policyTypeIds\":[\"2\"]},{\"ricId\":\"ricAddedOne\",\"managedElementIds\":[]," +
"\"state\":\"AVAILABLE\",\"policyTypeIds\":[\"1\"]"));
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3Test.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3Test.java
index 426cf6ed..671a34e5 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3Test.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3Test.java
@@ -32,7 +32,7 @@ import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Service;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services;
import org.onap.ccsdk.oran.a1policymanagementservice.utils.MockA1ClientFactory;
-import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelper;
+import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelperTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -63,7 +63,7 @@ class ServiceControllerV3Test {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@Autowired
- private TestHelper testHelper;
+ private TestHelperTest testHelperTest;
@Autowired
private ApplicationConfig applicationConfig;
@@ -94,8 +94,8 @@ class ServiceControllerV3Test {
@BeforeEach
void init() {
- testHelper.port = port;
- this.applicationConfig.setAuthProviderUrl(testHelper.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
+ testHelperTest.port = port;
+ this.applicationConfig.setAuthProviderUrl(testHelperTest.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
}
@AfterEach
@@ -112,30 +112,30 @@ class ServiceControllerV3Test {
void testPutService() {
ServiceRegistrationInfo serviceRegistrationInfo = new ServiceRegistrationInfo("serviceId");
serviceRegistrationInfo.callbackUrl("http://callback.com/").keepAliveIntervalSeconds(10L);
- Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3()
+ Mono<ResponseEntity<String>> responseEntityMono = testHelperTest.restClientV3()
.putForEntity("/services", gson.toJson(serviceRegistrationInfo));
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.CREATED, responseBody -> services.size() == 1);
+ testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.CREATED, responseBody -> services.size() == 1);
}
@Test
void testGetService() {
services.put(new Service("newServiceId", Duration.ofSeconds(10L), "http://callback.com/"));
- Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().getForEntity("/services");
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBoy -> responseBoy
+ Mono<ResponseEntity<String>> responseEntityMono = testHelperTest.restClientV3().getForEntity("/services");
+ testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBoy -> responseBoy
.contains("http://callback.com/"));
}
@Test
void testDeleteService() {
services.put(new Service("newServiceId", Duration.ofSeconds(10L), "http://callback.com/"));
- Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().deleteForEntity("/services/newServiceId");
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.NO_CONTENT, responseBody -> services.size() == 0);
+ Mono<ResponseEntity<String>> responseEntityMono = testHelperTest.restClientV3().deleteForEntity("/services/newServiceId");
+ testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.NO_CONTENT, responseBody -> services.size() == 0);
}
@Test
void testKeepAliveService() {
services.put(new Service("newServiceId", Duration.ofSeconds(10L), "http://callback.com/"));
- Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().putForEntity("/services/newServiceId/keepalive", "");
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> services.size() == 1);
+ Mono<ResponseEntity<String>> responseEntityMono = testHelperTest.restClientV3().putForEntity("/services/newServiceId/keepalive", "");
+ testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> services.size() == 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 2e483338..95c77a08 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
@@ -38,7 +38,7 @@ import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyType;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
import org.onap.ccsdk.oran.a1policymanagementservice.util.v3.Helper;
import org.onap.ccsdk.oran.a1policymanagementservice.utils.MockA1ClientFactory;
-import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelper;
+import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelperTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -86,7 +86,7 @@ class PolicyServiceTest {
private PolicyService policyService;
@Autowired
- private TestHelper testHelper;
+ private TestHelperTest testHelperTest;
@MockBean
private Helper helper;
@@ -120,15 +120,15 @@ class PolicyServiceTest {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
- Policy policy = testHelper.buidTestPolicy(testHelper.policyObjectInfo(nonRtRicId, policyTypeName), "122344-5674");
+ Policy policy = testHelperTest.buidTestPolicy(testHelperTest.policyObjectInfo(nonRtRicId, policyTypeName), "122344-5674");
when(helper.jsonSchemaValidation(any())).thenReturn(Boolean.TRUE);
when(helper.buildPolicy(any(),any(), any(), any())).thenReturn(policy);
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(testHelper.policyObjectInfo(nonRtRicId, policyTypeName), serverWebExchange);
- testHelper.verifyMockError(responseMono, "Same policy content already created with policy ID: 122344-5674");
+ Mono<ResponseEntity<PolicyObjectInformation>> responseMono = policyService.createPolicyService(testHelperTest.policyObjectInfo(nonRtRicId, policyTypeName), serverWebExchange);
+ testHelperTest.verifyMockError(responseMono, "Same policy content already created with policy ID: 122344-5674");
}
@Test
@@ -136,13 +136,13 @@ class PolicyServiceTest {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
when(helper.jsonSchemaValidation(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(testHelper.policyObjectInfo(nonRtRicId, policyTypeName), serverWebExchange);
- testHelper.verifyMockError(responseMono, "Not authorized");
+ Mono<ResponseEntity<PolicyObjectInformation>> responseMono = policyService.createPolicyService(testHelperTest.policyObjectInfo(nonRtRicId, policyTypeName), serverWebExchange);
+ testHelperTest.verifyMockError(responseMono, "Not authorized");
}
@Test
@@ -150,8 +150,8 @@ class PolicyServiceTest {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- Policy policy = testHelper.buidTestPolicy(testHelper.policyObjectInfo(nonRtRicId, policyTypeName), "122344-5674");
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ Policy policy = testHelperTest.buidTestPolicy(testHelperTest.policyObjectInfo(nonRtRicId, policyTypeName), "122344-5674");
policies.put(policy);
ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
when(helper.checkRicStateIdle(any())).thenReturn(Mono.just(policy.getRic()));
@@ -159,7 +159,7 @@ class PolicyServiceTest {
when(authorizationService.authCheck(any(), any(), any())).thenReturn(Mono.just(policy));
Mono<ResponseEntity<Void>> responseMonoDelete = policyService.deletePolicyService(policy.getId(), serverWebExchange);
assert(policies.size() == 1);
- testHelper.testSuccessResponse(responseMonoDelete, HttpStatus.NO_CONTENT, responseBody -> policies.size() == 0);
+ testHelperTest.testSuccessResponse(responseMonoDelete, HttpStatus.NO_CONTENT, responseBody -> policies.size() == 0);
}
@Test
@@ -174,11 +174,11 @@ class PolicyServiceTest {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- Policy policy = testHelper.buidTestPolicy(testHelper.policyObjectInfo(nonRtRicId, policyTypeName), "122344-5674");
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ Policy policy = testHelperTest.buidTestPolicy(testHelperTest.policyObjectInfo(nonRtRicId, policyTypeName), "122344-5674");
policies.put(policy);
ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
- PolicyObjectInformation updatedPolicyObjectInfo = testHelper.policyObjectInfo(nonRtRicId, policyTypeName);
+ PolicyObjectInformation updatedPolicyObjectInfo = testHelperTest.policyObjectInfo(nonRtRicId, policyTypeName);
updatedPolicyObjectInfo.setPolicyObject(gson.fromJson(JsonParser.parseString("{\n" +
" \"scope\": {\n" +
" \"ueId\": \"ue6100\",\n" +
@@ -188,13 +188,13 @@ class PolicyServiceTest {
" \"priorityLevel\": 6100.0\n" +
" }\n" +
" }").getAsJsonObject().toString(), Map.class));
- Policy updatedPolicy = testHelper.buidTestPolicy(updatedPolicyObjectInfo, "122344-5674");
+ Policy updatedPolicy = testHelperTest.buidTestPolicy(updatedPolicyObjectInfo, "122344-5674");
when(helper.buildPolicy(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(authorizationService.authCheck(any(), any(), any())).thenReturn(Mono.just(updatedPolicy));
Mono<ResponseEntity<Object>> responseMono = policyService.putPolicyService(policy.getId(), updatedPolicyObjectInfo.getPolicyObject(), serverWebExchange);
- testHelper.testSuccessResponse(responseMono, HttpStatus.OK, responseBody -> {
+ testHelperTest.testSuccessResponse(responseMono, HttpStatus.OK, responseBody -> {
if (responseBody instanceof String returnPolicy)
return returnPolicy.contains(updatedPolicy.getJson());
return false;
@@ -212,18 +212,18 @@ class PolicyServiceTest {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod();
Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono =
policyService.getPolicyTypesService(nearRtRicID, typeName, compatibleWithVersion);
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().count() == 1);
+ testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().count() == 1);
}
@Test
void testGetPolicyTypesEmpty() throws Exception {
when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod();
Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService(null, null, null);
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().findAny().isEmpty());
+ testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().findAny().isEmpty());
}
@Test
@@ -235,28 +235,28 @@ class PolicyServiceTest {
void testGetPolicyTypesNoMatchedTypeName() throws Exception {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod();
Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService("", "noTypeName", null);
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().findAny().isEmpty());
+ testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().findAny().isEmpty());
}
@Test
void testGetPolicyTypesNoMatchedTypeNameWithRic() throws Exception {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod();
Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService("Ric_347", "noTypeName", null);
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().findAny().isEmpty());
+ testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().findAny().isEmpty());
}
@Test
void testGetPolicyIds() throws Exception {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- Policy policy = testHelper.buidTestPolicy(testHelper.policyObjectInfo(nonRtRicId, policyTypeName), "122344-5674");
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ Policy policy = testHelperTest.buidTestPolicy(testHelperTest.policyObjectInfo(nonRtRicId, policyTypeName), "122344-5674");
policies.put(policy);
when(authorizationService.authCheck(any(), any(), any())).thenReturn(Mono.just(policy));
ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
@@ -266,12 +266,12 @@ class PolicyServiceTest {
when(helper.toFluxPolicyInformation(any())).thenReturn(Flux.fromIterable(mockPolicyInfoCollection));
Mono<ResponseEntity<Flux<PolicyInformation>>> responseEntityMono = policyService
.getPolicyIdsService(null, null, null, null, serverWebExchange);
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().count() == 1);
+ testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().count() == 1);
}
@Test
void testGetPolicyIdsNoRic() throws Exception {
- testHelper.addPolicyType("uri_type_123", "Ric_347");
+ testHelperTest.addPolicyType("uri_type_123", "Ric_347");
ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
EntityNotFoundException exception = assertThrows(EntityNotFoundException.class, () -> policyService
.getPolicyIdsService("uri_type_123", "noRic", "", "", serverWebExchange));
@@ -290,13 +290,13 @@ class PolicyServiceTest {
void testGetPolicyService() throws Exception {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- Policy policy = testHelper.buidTestPolicy(testHelper.policyObjectInfo(nonRtRicId, policyTypeName), "122344-5674");
+ testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
+ Policy policy = testHelperTest.buidTestPolicy(testHelperTest.policyObjectInfo(nonRtRicId, policyTypeName), "122344-5674");
policies.put(policy);
when(authorizationService.authCheck(any(), any(), any())).thenReturn(Mono.just(policy));
ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
Mono<ResponseEntity<Object>> responseEntityMono = policyService.getPolicyService(policy.getId(), serverWebExchange);
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> {
+ testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> {
if (responseBody instanceof String returnPolicy)
return returnPolicy.contains(policy.getJson());
return false;
@@ -315,9 +315,9 @@ class PolicyServiceTest {
void testGetPolicyTypeService() throws Exception {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
- PolicyType addedPolicyType = testHelper.addPolicyType(policyTypeName, nonRtRicId);
+ PolicyType addedPolicyType = testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
Mono<ResponseEntity<Object>> responseEntityMono = policyService.getPolicyTypeDefinitionService(policyTypeName);
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> {
+ testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> {
if (responseBody instanceof String returnPolicyType)
return returnPolicyType.contains(addedPolicyType.getSchema());
return false;
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterDisableTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterDisableTest.java
new file mode 100644
index 00000000..54b9d295
--- /dev/null
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterDisableTest.java
@@ -0,0 +1,82 @@
+package org.onap.ccsdk.oran.a1policymanagementservice.utils.v3;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.OpenPolicyAgentSimulatorController;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.system.CapturedOutput;
+import org.springframework.boot.test.system.OutputCaptureExtension;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.util.FileSystemUtils;
+import reactor.core.publisher.Mono;
+
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ExtendWith({OutputCaptureExtension.class})
+@TestPropertySource(properties = {
+ "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",
+ "logging.reactive-entry-exit-filter-enabled=false"
+})
+class ReactiveEntryExitFilterDisableTest {
+
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ @Autowired
+ private ApplicationConfig applicationConfig;
+
+ @Autowired
+ private TestHelperTest testHelperTest;
+
+ @LocalServerPort
+ private int port;
+
+ @BeforeEach
+ void init() {
+ testHelperTest.port = port;
+ this.applicationConfig.setAuthProviderUrl(testHelperTest.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
+ }
+
+ @AfterAll
+ static void clearTestDir() {
+ try {
+ FileSystemUtils.deleteRecursively(Path.of("/tmp/pmstestv3"));
+ } catch (Exception e) {
+ logger.warn("Could test directory : {}", e.getMessage());
+ }
+ }
+
+ @Test
+ @DisplayName("test verify entry exit log")
+ void testPostPolicy(CapturedOutput capturedOutput) throws Exception {
+ 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/"));
+ assertFalse(capturedOutput.getOut().contains("Request received with path: /a1-policy-management/v1/policies"));
+ assertFalse(capturedOutput.getOut().contains("the Status code of the response: 201 CREATED"));
+ assertFalse(capturedOutput.getOut().contains("the response is:"));
+ }
+}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterTest.java
new file mode 100644
index 00000000..9e0f60ea
--- /dev/null
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterTest.java
@@ -0,0 +1,82 @@
+package org.onap.ccsdk.oran.a1policymanagementservice.utils.v3;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.OpenPolicyAgentSimulatorController;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.system.CapturedOutput;
+import org.springframework.boot.test.system.OutputCaptureExtension;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.util.FileSystemUtils;
+import reactor.core.publisher.Mono;
+
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ExtendWith({OutputCaptureExtension.class})
+@TestPropertySource(properties = {
+ "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",
+ "logging.reactive-entry-exit-filter-enabled=true",
+ "logging.level.org.onap.ccsdk.oran.a1policymanagementservice=TRACE"
+})
+class ReactiveEntryExitFilterTest {
+
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ @Autowired
+ private ApplicationConfig applicationConfig;
+
+ @Autowired
+ private TestHelperTest testHelperTest;
+
+ @LocalServerPort
+ private int port;
+
+ @BeforeEach
+ void init() {
+ testHelperTest.port = port;
+ this.applicationConfig.setAuthProviderUrl(testHelperTest.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
+ }
+
+ @AfterAll
+ static void clearTestDir() {
+ try {
+ FileSystemUtils.deleteRecursively(Path.of("/tmp/pmstestv3"));
+ } catch (Exception e) {
+ logger.warn("Could test directory : {}", e.getMessage());
+ }
+ }
+
+ @Test
+ @DisplayName("test verify entry exit log")
+ void testPostPolicy(CapturedOutput capturedOutput) throws Exception {
+ 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/"));
+ assertTrue(capturedOutput.getOut().contains("Request received with path: /a1-policy-management/v1/policies"));
+ assertTrue(capturedOutput.getOut().contains("the Status code of the response: 201 CREATED"));
+ assertTrue(capturedOutput.getOut().contains("the response is:"));
+ }
+}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelper.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelperTest.java
index b0b5858a..78ab385c 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelper.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelperTest.java
@@ -61,7 +61,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Component
-public class TestHelper {
+public class TestHelperTest {
@Autowired
ApplicationConfig applicationConfig;