Add Modify NSSI operation in SO actor
[policy/models.git] / models-interactions / model-actors / actor.so / src / test / java / org / onap / policy / controlloop / actor / so / ModifyNssiTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 Wipro Limited.
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.policy.controlloop.actor.so;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertTrue;
28
29 import java.util.List;
30 import java.util.Map;
31 import org.junit.AfterClass;
32 import org.junit.Before;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
36 import org.onap.policy.common.utils.coder.CoderException;
37 import org.onap.policy.common.utils.coder.StandardCoder;
38 import org.onap.policy.common.utils.resources.ResourceUtils;
39 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
40 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
41 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig;
42 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams;
43 import org.onap.policy.so.SoResponse;
44
45 public class ModifyNssiTest extends BasicSoOperation {
46
47     private ModifyNssi oper;
48
49     private static StandardCoder coder = new StandardCoder();
50
51     public ModifyNssiTest() {
52         super(DEFAULT_ACTOR, ModifyNssi.NAME);
53     }
54
55     @BeforeClass
56     public static void setUpBeforeClass() throws Exception {
57         initBeforeClass();
58     }
59
60     @AfterClass
61     public static void tearDownAfterClass() {
62         destroyAfterClass();
63     }
64
65     @Before
66     public void setUp() throws Exception {
67         super.setUp();
68         oper = new ModifyNssi(params, config);
69     }
70
71     @Test
72     public void testSuccess() throws Exception {
73         HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT)
74                 .path("3gppservices/v7/modify").pollPath("orchestrationRequests/v5/")
75                 .maxPolls(2).build();
76         config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
77         params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
78
79         oper = new ModifyNssi(params, config);
80
81         outcome = oper.start().get();
82
83         assertEquals(OperationResult.SUCCESS, outcome.getResult());
84         assertTrue(outcome.getResponse() instanceof SoResponse);
85     }
86
87     @Test
88     public void testConstructor() {
89         assertEquals(DEFAULT_ACTOR, oper.getActorName());
90         assertEquals(ModifyNssi.NAME, oper.getName());
91         assertFalse(oper.isUsePolling());
92
93         params = params.toBuilder().targetType(null).build();
94         assertThatIllegalArgumentException().isThrownBy(() -> new ModifyNssi(params, config))
95                 .withMessageContaining("Target information");
96     }
97
98     @Test
99     public void testGetPropertyNames() {
100         assertThat(oper.getPropertyNames()).isEqualTo(
101                 List.of(
102                         OperationProperties.AAI_SERVICE,
103                         OperationProperties.EVENT_PAYLOAD));
104     }
105
106     @Override
107     protected Map<String, Object> makePayload() {
108         String payloadString = ResourceUtils
109                 .getResourceAsString("src/test/resources/ModifyNSSI.json");
110
111         try {
112             return coder.decode(payloadString, Map.class);
113         } catch (CoderException e) {
114             throw new IllegalArgumentException("invalid payload value: " + payloadString, e);
115         }
116     }
117 }