2 * ========================LICENSE_START=================================
4 * ======================================================================
5 * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
6 * ======================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 package org.onap.ccsdk.oran.a1policymanagementservice.utils.v3;
23 import org.junit.jupiter.api.AfterAll;
24 import org.junit.jupiter.api.BeforeEach;
25 import org.junit.jupiter.api.DisplayName;
26 import org.junit.jupiter.api.Test;
27 import org.junit.jupiter.api.extension.ExtendWith;
28 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
29 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.OpenPolicyAgentSimulatorController;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.boot.test.context.SpringBootTest;
34 import org.springframework.boot.test.system.CapturedOutput;
35 import org.springframework.boot.test.system.OutputCaptureExtension;
36 import org.springframework.boot.test.web.server.LocalServerPort;
37 import org.springframework.http.HttpStatus;
38 import org.springframework.http.ResponseEntity;
39 import org.springframework.test.context.TestPropertySource;
40 import org.springframework.util.FileSystemUtils;
41 import reactor.core.publisher.Mono;
43 import java.lang.invoke.MethodHandles;
44 import java.nio.file.Path;
46 import static org.junit.jupiter.api.Assertions.assertTrue;
48 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
49 @ExtendWith({OutputCaptureExtension.class})
50 @TestPropertySource(properties = {
51 "server.ssl.key-store=./config/keystore.jks",
52 "app.webclient.trust-store=./config/truststore.jks",
53 "app.vardata-directory=./target",
54 "app.config-file-schema-path=/application_configuration_schema.json",
55 "logging.reactive-entry-exit-filter-enabled=true",
56 "logging.level.org.onap.ccsdk.oran.a1policymanagementservice=TRACE"
58 class ReactiveEntryExitFilterTest {
60 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
63 private ApplicationConfig applicationConfig;
66 private TestHelperTest testHelperTest;
73 testHelperTest.port = port;
74 this.applicationConfig.setAuthProviderUrl(testHelperTest.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
78 static void clearTestDir() {
80 FileSystemUtils.deleteRecursively(Path.of("/tmp/pmstestv3"));
81 } catch (Exception e) {
82 logger.warn("Could test directory : {}", e.getMessage());
87 @DisplayName("test verify entry exit log")
88 void testPostPolicy(CapturedOutput capturedOutput) throws Exception {
89 String nonRtRicId = "ric.1";
90 String policyTypeName = "type1_1.2.3";
91 String url = "/policies";
92 testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
93 String policyBody = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "");
94 Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
95 testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody ->
96 responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}"));
97 testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/"));
98 assertTrue(capturedOutput.getOut().contains("Request received with path: /a1-policy-management/v1/policies"));
99 assertTrue(capturedOutput.getOut().contains("the Status code of the response: 201 CREATED"));
100 assertTrue(capturedOutput.getOut().contains("the response is:"));