c51d27b4e03d77b2f5d532f9a9d1d54983bf0529
[ccsdk/oran.git] /
1 /*-
2  * ========================LICENSE_START=================================
3  * ONAP : ccsdk oran
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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===================================
19  */
20
21 package org.onap.ccsdk.oran.a1policymanagementservice.utils.v3;
22
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;
42
43 import java.lang.invoke.MethodHandles;
44 import java.nio.file.Path;
45
46 import static org.junit.jupiter.api.Assertions.assertTrue;
47
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"
57 })
58 class ReactiveEntryExitFilterTest {
59
60     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
61
62     @Autowired
63     private ApplicationConfig applicationConfig;
64
65     @Autowired
66     private TestHelperTest testHelperTest;
67
68     @LocalServerPort
69     private int port;
70
71     @BeforeEach
72     void init() {
73         testHelperTest.port = port;
74         this.applicationConfig.setAuthProviderUrl(testHelperTest.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
75     }
76
77     @AfterAll
78     static void clearTestDir() {
79         try {
80             FileSystemUtils.deleteRecursively(Path.of("/tmp/pmstestv3"));
81         } catch (Exception e) {
82             logger.warn("Could test directory : {}", e.getMessage());
83         }
84     }
85
86     @Test
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:"));
101     }
102
103     @Test
104     @DisplayName("test verify entry exit log for health actuator is present")
105     void testHealthActuatorFilterIncluded(CapturedOutput capturedOutput) throws Exception {
106         String url = "/actuator/health";
107         Mono<ResponseEntity<String>> responseGetHealthMono =
108                 testHelperTest.restClient(testHelperTest.baseUrl(), false).getForEntity(url);
109         testHelperTest.testSuccessResponse(responseGetHealthMono, HttpStatus.OK, responseBody -> responseBody.contains("UP"));
110         assertTrue(capturedOutput.getOut().contains("Request received with path: /actuator/health"));
111         assertTrue(capturedOutput.getOut().contains("the response is:"));
112     }
113 }