2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Wipro Limited.
6 * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
7 * Modifications Copyright (C) 2020,2023,2024 Nordix Foundation.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.controlloop.actor.so;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
27 import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
28 import static org.junit.jupiter.api.Assertions.assertEquals;
29 import static org.junit.jupiter.api.Assertions.assertFalse;
30 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
32 import java.util.List;
33 import org.junit.jupiter.api.AfterAll;
34 import org.junit.jupiter.api.BeforeAll;
35 import org.junit.jupiter.api.BeforeEach;
36 import org.junit.jupiter.api.Test;
37 import org.junit.jupiter.api.extension.ExtendWith;
38 import org.mockito.junit.jupiter.MockitoExtension;
39 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
40 import org.onap.policy.common.utils.resources.ResourceUtils;
41 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
42 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
43 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig;
44 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams;
45 import org.onap.policy.so.SoResponse;
47 @ExtendWith(MockitoExtension.class)
48 class ModifyNssiTest extends BasicSoOperation {
50 private ModifyNssi oper;
54 super(DEFAULT_ACTOR, ModifyNssi.NAME);
58 static void setUpBeforeClass() throws Exception {
63 static void tearDownAfterClass() {
69 void setUp() throws Exception {
71 oper = new ModifyNssi(params, config);
75 void testSuccess() throws Exception {
76 HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT).path("3gppservices/v7/modify")
77 .pollPath("orchestrationRequests/v5/").maxPolls(2).build();
78 config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
79 params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
81 oper = new ModifyNssi(params, config);
82 oper.setProperty(OperationProperties.EVENT_PAYLOAD, getPayload());
83 outcome = oper.start().get();
85 assertEquals(OperationResult.SUCCESS, outcome.getResult());
86 assertInstanceOf(SoResponse.class, outcome.getResponse());
90 void testConstructor() {
91 assertEquals(DEFAULT_ACTOR, oper.getActorName());
92 assertEquals(ModifyNssi.NAME, oper.getName());
93 assertFalse(oper.isUsePolling());
95 params = params.toBuilder().targetType(null).build();
96 assertThatIllegalArgumentException().isThrownBy(() -> new ModifyNssi(params, config))
97 .withMessageContaining("Target information");
101 void testGetPropertyNames() {
102 assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.EVENT_PAYLOAD));
105 private String getPayload() {
106 return ResourceUtils.getResourceAsString("src/test/resources/ModifyNSSI.json");
110 * Tests makeRequest() when a property is missing.
113 void testMakeRequestMissingProperty() throws Exception {
114 oper = new ModifyNssi(params, config);
116 assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest())
117 .withMessageContaining("missing event payload");