2d290d68ae9056075bf68398b405dbd46dc33775
[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  * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.controlloop.actor.so;
23
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertTrue;
29
30 import java.util.List;
31 import java.util.Map;
32 import org.junit.AfterClass;
33 import org.junit.Before;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
37 import org.onap.policy.common.utils.coder.CoderException;
38 import org.onap.policy.common.utils.coder.StandardCoder;
39 import org.onap.policy.common.utils.resources.ResourceUtils;
40 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
41 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
42 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig;
43 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams;
44 import org.onap.policy.so.SoResponse;
45
46 public class ModifyNssiTest extends BasicSoOperation {
47
48     private ModifyNssi oper;
49
50     private static StandardCoder coder = new StandardCoder();
51
52     public ModifyNssiTest() {
53         super(DEFAULT_ACTOR, ModifyNssi.NAME);
54     }
55
56     @BeforeClass
57     public static void setUpBeforeClass() throws Exception {
58         initBeforeClass();
59     }
60
61     @AfterClass
62     public static void tearDownAfterClass() {
63         destroyAfterClass();
64     }
65
66     @Before
67     public void setUp() throws Exception {
68         super.setUp();
69         oper = new ModifyNssi(params, config);
70     }
71
72     @Test
73     public void testSuccess() throws Exception {
74         HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT)
75                 .path("3gppservices/v7/modify").pollPath("orchestrationRequests/v5/")
76                 .maxPolls(2).build();
77         config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
78         params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
79
80         oper = new ModifyNssi(params, config);
81         oper.setProperty(OperationProperties.EVENT_PAYLOAD, getPayload());
82         outcome = oper.start().get();
83
84         assertEquals(OperationResult.SUCCESS, outcome.getResult());
85         assertTrue(outcome.getResponse() instanceof SoResponse);
86     }
87
88     @Test
89     public void testConstructor() {
90         assertEquals(DEFAULT_ACTOR, oper.getActorName());
91         assertEquals(ModifyNssi.NAME, oper.getName());
92         assertFalse(oper.isUsePolling());
93
94         params = params.toBuilder().targetType(null).build();
95         assertThatIllegalArgumentException().isThrownBy(() -> new ModifyNssi(params, config))
96                 .withMessageContaining("Target information");
97     }
98
99     @Test
100     public void testGetPropertyNames() {
101         assertThat(oper.getPropertyNames()).isEqualTo(
102                 List.of(
103                         OperationProperties.EVENT_PAYLOAD));
104     }
105
106     private String getPayload() {
107         return ResourceUtils
108                 .getResourceAsString("src/test/resources/ModifyNSSI.json");
109     }
110
111
112 }