Upgrade and clean up dependencies
[policy/models.git] / models-interactions / model-actors / actor.sdnc / src / test / java / org / onap / policy / controlloop / actor / sdnc / BandwidthOnDemandOperationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2023 Nordix Foundation.
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.sdnc;
23
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertTrue;
28
29 import java.util.List;
30 import org.junit.AfterClass;
31 import org.junit.Before;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.junit.MockitoJUnitRunner;
36 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
37 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
38 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
39 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
40 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
41 import org.onap.policy.sdnc.SdncResponse;
42
43 @RunWith(MockitoJUnitRunner.class)
44 public class BandwidthOnDemandOperationTest extends BasicSdncOperation {
45     private static final String MY_SERVICE = "my-service";
46     private static final String MY_VNF = "my-vnf";
47     private static final String MY_BANDWIDTH = "my-bandwidth";
48     private static final String MY_CHANGE_TIME = "my-change-time";
49
50     private BandwidthOnDemandOperation oper;
51
52     public BandwidthOnDemandOperationTest() {
53         super(DEFAULT_ACTOR, BandwidthOnDemandOperation.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     /**
67      * Set up.
68      */
69     @Override
70     @Before
71     public void setUp() throws Exception {
72         super.setUp();
73         oper = new BandwidthOnDemandOperation(params, config);
74     }
75
76     @Test
77     public void testConstructor() {
78         assertEquals(DEFAULT_ACTOR, oper.getActorName());
79         assertEquals(BandwidthOnDemandOperation.NAME, oper.getName());
80     }
81
82     @Test
83     public void testGetPropertyNames() {
84         // @formatter:off
85         assertThat(oper.getPropertyNames()).isEqualTo(
86                         List.of(
87                             OperationProperties.ENRICHMENT_SERVICE_ID,
88                             OperationProperties.ENRICHMENT_BANDWIDTH,
89                             OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME,
90                             OperationProperties.ENRICHMENT_VNF_ID));
91
92         // @formatter:on
93     }
94
95     /**
96      * Tests "success" case with simulator.
97      */
98     @Test
99     public void testSuccess() throws Exception {
100         HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT)
101                         .path("GENERIC-RESOURCE-API:vf-module-topology-operation").build();
102         config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
103
104         params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
105         oper = new BandwidthOnDemandOperation(params, config);
106
107         oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
108         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH);
109         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME);
110         oper.setProperty(OperationProperties.ENRICHMENT_VNF_ID, MY_VNF);
111
112         outcome = oper.start().get();
113         assertEquals(OperationResult.SUCCESS, outcome.getResult());
114         assertTrue(outcome.getResponse() instanceof SdncResponse);
115     }
116
117     @Test
118     public void testMakeRequest() throws Exception {
119         oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
120         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH);
121         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME);
122         oper.setProperty(OperationProperties.ENRICHMENT_VNF_ID, MY_VNF);
123
124         verifyRequest("bod.json", verifyOperation(oper), IGNORE_FIELDS);
125     }
126
127     /*
128      * Tests makeRequest() when a property is missing.
129      */
130
131     @Test
132     public void testMakeRequestMissingBandwidth() throws Exception {
133         oper = new BandwidthOnDemandOperation(params, config);
134         oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
135         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME);
136         oper.setProperty(OperationProperties.ENRICHMENT_VNF_ID, MY_VNF);
137
138         oper.generateSubRequestId(1);
139         outcome.setSubRequestId(oper.getSubRequestId());
140
141         assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest(1))
142                         .withMessageContaining("missing bandwidth from enrichment data");
143     }
144
145     @Test
146     public void testMakeRequestMissingBandwidthChangeTime() throws Exception {
147         oper = new BandwidthOnDemandOperation(params, config);
148         oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
149         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH);
150         oper.setProperty(OperationProperties.ENRICHMENT_VNF_ID, MY_VNF);
151
152         oper.generateSubRequestId(1);
153         outcome.setSubRequestId(oper.getSubRequestId());
154
155         assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest(1))
156                         .withMessageContaining("missing bandwidth change time from enrichment data");
157     }
158
159     @Test
160     public void testMakeRequestMissingVnfId() throws Exception {
161         oper = new BandwidthOnDemandOperation(params, config);
162         oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
163         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH);
164         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME);
165
166         oper.generateSubRequestId(1);
167         outcome.setSubRequestId(oper.getSubRequestId());
168
169         assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest(1))
170                         .withMessageContaining("missing VNF id from enrichment data");
171     }
172 }