2 * ========================LICENSE_START=================================
4 * ======================================================================
5 * Copyright (C) 2024 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.controllers.v3;
23 import org.junit.jupiter.api.*;
24 import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
25 import org.onap.ccsdk.oran.a1policymanagementservice.config.TestConfig;
26 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
27 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.OpenPolicyAgentSimulatorController;
28 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.RappSimulatorController;
29 import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
30 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
31 import org.onap.ccsdk.oran.a1policymanagementservice.utils.MockA1ClientFactory;
32 import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelper;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.boot.test.context.SpringBootTest;
37 import org.springframework.boot.test.web.server.LocalServerPort;
38 import org.springframework.http.HttpStatus;
39 import org.springframework.http.ResponseEntity;
40 import org.springframework.test.context.ContextConfiguration;
41 import org.springframework.test.context.TestPropertySource;
42 import reactor.core.publisher.Mono;
44 import java.io.IOException;
45 import java.lang.invoke.MethodHandles;
47 @TestMethodOrder(MethodOrderer.MethodName.class)
48 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
49 @ContextConfiguration(classes = TestConfig.class)
50 @TestPropertySource(properties = { //
51 "server.ssl.key-store=./config/keystore.jks", //
52 "app.webclient.trust-store=./config/truststore.jks", //
53 "app.webclient.trust-store-used=true", //
54 "app.vardata-directory=/tmp/pmstestv3", //a
55 "app.s3.bucket=" // If this is set, S3 will be used to store data.
57 class RicRepositoryControllerV3Test {
59 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
62 private TestHelper testHelper;
65 private ApplicationConfig applicationConfig;
68 private MockA1ClientFactory a1ClientFactory;
71 private RappSimulatorController rAppSimulator;
74 private SecurityContext securityContext;
77 private OpenPolicyAgentSimulatorController openPolicyAgentSimulatorController;
80 private PolicyTypes policyTypes;
90 testHelper.port = port;
92 this.applicationConfig.setAuthProviderUrl(testHelper.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
98 a1ClientFactory.reset();
99 this.rAppSimulator.getTestResults().clear();
100 this.a1ClientFactory.setPolicyTypes(policyTypes); // Default same types in RIC and in this app
101 this.securityContext.setAuthTokenFilePath(null);
102 this.openPolicyAgentSimulatorController.getTestResults().reset();
106 void testGetRic() throws IOException {
107 testHelper.addPolicyType("1", "ricAdded");
108 Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().getForEntity("/rics/ric?ricId=ricAdded");
109 testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody
110 .contains("{\"ricId\":\"ricAdded\",\"managedElementIds\":[],\"state\":\"AVAILABLE\",\"policyTypeIds\":[\"1\"]}"));
114 void testGetRics() throws IOException {
115 testHelper.addPolicyType("1", "ricAddedOne");
116 testHelper.addPolicyType("2", "ricAddedTwo");
117 Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().getForEntity("/rics");
118 testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody
119 .contains("{\"ricId\":\"ricAddedTwo\",\"managedElementIds\":[],\"state\":\"AVAILABLE\"," +
120 "\"policyTypeIds\":[\"2\"]},{\"ricId\":\"ricAddedOne\",\"managedElementIds\":[]," +
121 "\"state\":\"AVAILABLE\",\"policyTypeIds\":[\"1\"]"));