2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-2021 AT&T Intellectual Property. 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.controlloop.actor.sdnc;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
28 import java.util.List;
29 import org.junit.AfterClass;
30 import org.junit.Before;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
34 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
35 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
36 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
37 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
38 import org.onap.policy.sdnc.SdncResponse;
40 public class BandwidthOnDemandOperationTest extends BasicSdncOperation {
41 private static final String MY_SERVICE = "my-service";
42 private static final String MY_VNF = "my-vnf";
43 private static final String MY_BANDWIDTH = "my-bandwidth";
44 private static final String MY_CHANGE_TIME = "my-change-time";
46 private BandwidthOnDemandOperation oper;
48 public BandwidthOnDemandOperationTest() {
49 super(DEFAULT_ACTOR, BandwidthOnDemandOperation.NAME);
53 public static void setUpBeforeClass() throws Exception {
58 public static void tearDownAfterClass() {
67 public void setUp() throws Exception {
69 oper = new BandwidthOnDemandOperation(params, config);
73 public void testConstructor() {
74 assertEquals(DEFAULT_ACTOR, oper.getActorName());
75 assertEquals(BandwidthOnDemandOperation.NAME, oper.getName());
79 public void testGetPropertyNames() {
81 assertThat(oper.getPropertyNames()).isEqualTo(
83 OperationProperties.ENRICHMENT_SERVICE_ID,
84 OperationProperties.ENRICHMENT_BANDWIDTH,
85 OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME,
86 OperationProperties.ENRICHMENT_VNF_ID));
92 * Tests "success" case with simulator.
95 public void testSuccess() throws Exception {
96 HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT)
97 .path("GENERIC-RESOURCE-API:vf-module-topology-operation").build();
98 config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
100 params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
101 oper = new BandwidthOnDemandOperation(params, config);
103 oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
104 oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH);
105 oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME);
106 oper.setProperty(OperationProperties.ENRICHMENT_VNF_ID, MY_VNF);
108 outcome = oper.start().get();
109 assertEquals(OperationResult.SUCCESS, outcome.getResult());
110 assertTrue(outcome.getResponse() instanceof SdncResponse);
114 public void testMakeRequest() throws Exception {
115 oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
116 oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH);
117 oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME);
118 oper.setProperty(OperationProperties.ENRICHMENT_VNF_ID, MY_VNF);
120 verifyRequest("bod.json", verifyOperation(oper), IGNORE_FIELDS);
124 * Tests makeRequest() when a property is missing.
128 public void testMakeRequestMissingBandwidth() throws Exception {
129 oper = new BandwidthOnDemandOperation(params, config);
130 oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
131 oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME);
132 oper.setProperty(OperationProperties.ENRICHMENT_VNF_ID, MY_VNF);
134 oper.generateSubRequestId(1);
135 outcome.setSubRequestId(oper.getSubRequestId());
137 assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest(1))
138 .withMessageContaining("missing bandwidth from enrichment data");
142 public void testMakeRequestMissingBandwidthChangeTime() throws Exception {
143 oper = new BandwidthOnDemandOperation(params, config);
144 oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
145 oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH);
146 oper.setProperty(OperationProperties.ENRICHMENT_VNF_ID, MY_VNF);
148 oper.generateSubRequestId(1);
149 outcome.setSubRequestId(oper.getSubRequestId());
151 assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest(1))
152 .withMessageContaining("missing bandwidth change time from enrichment data");
156 public void testMakeRequestMissingVnfId() throws Exception {
157 oper = new BandwidthOnDemandOperation(params, config);
158 oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
159 oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH);
160 oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME);
162 oper.generateSubRequestId(1);
163 outcome.setSubRequestId(oper.getSubRequestId());
165 assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest(1))
166 .withMessageContaining("missing VNF id from enrichment data");