2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.controlloop.actor.sdnc;
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;
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;
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";
50 private BandwidthOnDemandOperation oper;
52 public BandwidthOnDemandOperationTest() {
53 super(DEFAULT_ACTOR, BandwidthOnDemandOperation.NAME);
57 public static void setUpBeforeClass() throws Exception {
62 public static void tearDownAfterClass() {
71 public void setUp() throws Exception {
73 oper = new BandwidthOnDemandOperation(params, config);
77 public void testConstructor() {
78 assertEquals(DEFAULT_ACTOR, oper.getActorName());
79 assertEquals(BandwidthOnDemandOperation.NAME, oper.getName());
83 public void testGetPropertyNames() {
85 assertThat(oper.getPropertyNames()).isEqualTo(
87 OperationProperties.ENRICHMENT_SERVICE_ID,
88 OperationProperties.ENRICHMENT_BANDWIDTH,
89 OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME,
90 OperationProperties.ENRICHMENT_VNF_ID));
96 * Tests "success" case with simulator.
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());
104 params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
105 oper = new BandwidthOnDemandOperation(params, config);
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);
112 outcome = oper.start().get();
113 assertEquals(OperationResult.SUCCESS, outcome.getResult());
114 assertTrue(outcome.getResponse() instanceof SdncResponse);
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);
124 verifyRequest("bod.json", verifyOperation(oper), IGNORE_FIELDS);
128 * Tests makeRequest() when a property is missing.
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);
138 oper.generateSubRequestId(1);
139 outcome.setSubRequestId(oper.getSubRequestId());
141 assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest(1))
142 .withMessageContaining("missing bandwidth from enrichment data");
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);
152 oper.generateSubRequestId(1);
153 outcome.setSubRequestId(oper.getSubRequestId());
155 assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest(1))
156 .withMessageContaining("missing bandwidth change time from enrichment data");
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);
166 oper.generateSubRequestId(1);
167 outcome.setSubRequestId(oper.getSubRequestId());
169 assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest(1))
170 .withMessageContaining("missing VNF id from enrichment data");