94ab47db05fa125882addd57db9f170f9f66ce3b
[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.assertFalse;
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=false"
56 })
57 class ReactiveEntryExitFilterDisableTest {
58
59     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
60
61     @Autowired
62     private ApplicationConfig applicationConfig;
63
64     @Autowired
65     private TestHelperTest testHelperTest;
66
67     @LocalServerPort
68     private int port;
69
70     @BeforeEach
71     void init() {
72         testHelperTest.port = port;
73         this.applicationConfig.setAuthProviderUrl(testHelperTest.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
74     }
75
76     @AfterAll
77     static void clearTestDir() {
78         try {
79             FileSystemUtils.deleteRecursively(Path.of("/tmp/pmstestv3"));
80         } catch (Exception e) {
81             logger.warn("Could test directory : {}", e.getMessage());
82         }
83     }
84
85     @Test
86     @DisplayName("test verify entry exit log")
87     void testPostPolicy(CapturedOutput capturedOutput) throws Exception {
88         String nonRtRicId = "ric.1";
89         String policyTypeName = "type1_1.2.3";
90         String url = "/policies";
91         testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
92         String policyBody = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "");
93         Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
94         testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody ->
95                 responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}"));
96         testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/"));
97         assertFalse(capturedOutput.getOut().contains("Request received with path: /a1-policy-management/v1/policies"));
98         assertFalse(capturedOutput.getOut().contains("the Status code of the response: 201 CREATED"));
99         assertFalse(capturedOutput.getOut().contains("the response is:"));
100     }
101 }