29a7d082af4b0d2796b485161a28326330fe6f46
[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-2021 AT&T Intellectual Property. All rights reserved.
7  * Modifications Copyright (C) 2020 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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22
23 package org.onap.policy.controlloop.actor.so;
24
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.Assert.assertEquals;
29 import static org.junit.Assert.assertFalse;
30 import static org.junit.Assert.assertTrue;
31
32 import java.util.List;
33 import org.junit.AfterClass;
34 import org.junit.Before;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
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
50     public ModifyNssiTest() {
51         super(DEFAULT_ACTOR, ModifyNssi.NAME);
52     }
53
54     @BeforeClass
55     public static void setUpBeforeClass() throws Exception {
56         initBeforeClass();
57     }
58
59     @AfterClass
60     public static void tearDownAfterClass() {
61         destroyAfterClass();
62     }
63
64     @Override
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).path("3gppservices/v7/modify")
74                 .pollPath("orchestrationRequests/v5/").maxPolls(2).build();
75         config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
76         params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
77
78         oper = new ModifyNssi(params, config);
79         oper.setProperty(OperationProperties.EVENT_PAYLOAD, getPayload());
80         outcome = oper.start().get();
81
82         assertEquals(OperationResult.SUCCESS, outcome.getResult());
83         assertTrue(outcome.getResponse() instanceof SoResponse);
84     }
85
86     @Test
87     public void testConstructor() {
88         assertEquals(DEFAULT_ACTOR, oper.getActorName());
89         assertEquals(ModifyNssi.NAME, oper.getName());
90         assertFalse(oper.isUsePolling());
91
92         params = params.toBuilder().targetType(null).build();
93         assertThatIllegalArgumentException().isThrownBy(() -> new ModifyNssi(params, config))
94                 .withMessageContaining("Target information");
95     }
96
97     @Test
98     public void testGetPropertyNames() {
99         assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.EVENT_PAYLOAD));
100     }
101
102     private String getPayload() {
103         return ResourceUtils.getResourceAsString("src/test/resources/ModifyNSSI.json");
104     }
105
106     /**
107      * Tests makeRequest() when a property is missing.
108      */
109     @Test
110     public void testMakeRequestMissingProperty() throws Exception {
111         oper = new ModifyNssi(params, config);
112
113         assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest())
114                         .withMessageContaining("missing event payload");
115     }
116
117 }