7b2f28d6ba57755fbeafcb32ee1133ac600e35b4
[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.BeforeEach;
24 import org.junit.jupiter.api.DisplayName;
25 import org.junit.jupiter.api.Test;
26 import org.junit.jupiter.api.extension.ExtendWith;
27 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
28 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.OpenPolicyAgentSimulatorController;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.boot.test.context.SpringBootTest;
31 import org.springframework.boot.test.system.CapturedOutput;
32 import org.springframework.boot.test.system.OutputCaptureExtension;
33 import org.springframework.boot.test.web.server.LocalServerPort;
34 import org.springframework.http.HttpStatus;
35 import org.springframework.http.ResponseEntity;
36 import org.springframework.test.context.TestPropertySource;
37 import reactor.core.publisher.Mono;
38
39 import java.io.IOException;
40
41 import static org.junit.jupiter.api.Assertions.assertFalse;
42
43 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
44 @ExtendWith({OutputCaptureExtension.class})
45 @TestPropertySource(properties = {
46         "server.ssl.key-store=./config/keystore.jks",
47         "app.webclient.trust-store=./config/truststore.jks",
48         "app.vardata-directory=./target",
49         "app.config-file-schema-path=/application_configuration_schema.json",
50         "logging.reactive-entry-exit-filter-enabled=true",
51         "logging.level.org.onap.ccsdk.oran.a1policymanagementservice=TRACE",
52         "logging.reactive-entry-exit-filter-exclude-paths=/actuator/**,/a1-policy-management/v1/rics/**"
53 })
54 class ReactiveEntryExitFilterExcludeMultiPathTest {
55
56     @Autowired
57     private ApplicationConfig applicationConfig;
58
59     @Autowired
60     private TestHelperTest testHelperTest;
61
62     @LocalServerPort
63     private int port;
64
65     @BeforeEach
66     void init() {
67         testHelperTest.port = port;
68         this.applicationConfig.setAuthProviderUrl(testHelperTest.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
69     }
70
71     @Test
72     @DisplayName("test verify entry exit log for health actuator is absent")
73     void testHealthActuatorFilterOmitted(CapturedOutput capturedOutput) throws Exception {
74         String url = "/actuator/health";
75         Mono<ResponseEntity<String>> responseGetHealthMono =
76                 testHelperTest.restClient(testHelperTest.baseUrl(), false).getForEntity(url);
77         testHelperTest.testSuccessResponse(responseGetHealthMono, HttpStatus.OK, responseBody -> responseBody.contains("UP"));
78         assertFalse(capturedOutput.getOut().contains("Request received with path: /actuator/health"));
79         assertFalse(capturedOutput.getOut().contains("the response is:"));
80     }
81
82     @Test
83     @DisplayName("test verify entry exit log for the rics endpoint is absent")
84     void testGetRicsFilterOmitted(CapturedOutput capturedOutput) throws Exception {
85         String url = "/rics";
86         Mono<ResponseEntity<String>> responseEntityMono = testHelperTest.restClientV3().getForEntity(url);
87         testHelperTest.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody
88                 .contains("{\"rics\":[]}"));
89         assertFalse(capturedOutput.getOut().contains("Request received with path: /rics"));
90         assertFalse(capturedOutput.getOut().contains("the response is:"));
91     }
92 }