Closed loop operation guarantee for ccvpn
[policy/models.git] / models-interactions / model-actors / actor.so / src / test / java / org / onap / policy / controlloop / actor / so / ModifyCllTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2022 CTC, Inc. and others. 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
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.assertj.core.api.Assertions.assertThatIllegalStateException;
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 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.resources.ResourceUtils;
37 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
38 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
39 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig;
40 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams;
41 import org.onap.policy.so.SoResponse;
42
43 public class ModifyCllTest extends BasicSoOperation {
44
45     private ModifyCll oper;
46
47
48     public ModifyCllTest() {
49         super(DEFAULT_ACTOR, ModifyCll.NAME);
50     }
51
52     @BeforeClass
53     public static void setUpBeforeClass() throws Exception {
54         initBeforeClass();
55     }
56
57     @AfterClass
58     public static void tearDownAfterClass() {
59         destroyAfterClass();
60     }
61
62     @Override
63     @Before
64     public void setUp() throws Exception {
65         super.setUp();
66         oper = new ModifyCll(params, config);
67     }
68
69     @Test
70     public void testSuccess() throws Exception {
71         HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT)
72                 .path("infra/serviceIntent/v1/modify")
73                 .pollPath("orchestrationRequests/v5/").maxPolls(2).build();
74         config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
75         params = params.toBuilder().retry(0).timeoutSec(50).executor(blockingExecutor).build();
76
77         oper = new ModifyCll(params, config);
78         oper.setProperty(OperationProperties.EVENT_PAYLOAD, getPayload());
79         outcome = oper.start().get();
80
81         assertEquals(OperationResult.SUCCESS, outcome.getResult());
82         assertTrue(outcome.getResponse() instanceof SoResponse);
83     }
84
85     @Test
86     public void testConstructor() {
87         assertEquals(DEFAULT_ACTOR, oper.getActorName());
88         assertEquals(ModifyCll.NAME, oper.getName());
89         assertFalse(oper.isUsePolling());
90
91         params = params.toBuilder().targetType(null).build();
92         assertThatIllegalArgumentException().isThrownBy(() -> new ModifyCll(params, config))
93                 .withMessageContaining("Target information");
94     }
95
96     @Test
97     public void testGetPropertyNames() {
98         assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.EVENT_PAYLOAD));
99     }
100
101     private String getPayload() {
102         return ResourceUtils.getResourceAsString("src/test/resources/ModifyCll.json");
103     }
104
105     /**
106      * Tests makeRequest() when a property is missing.
107      */
108     @Test
109     public void testMakeRequestMissingProperty() throws Exception {
110         oper = new ModifyCll(params, config);
111
112         assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest())
113                         .withMessageContaining("missing event payload");
114     }
115
116 }