2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nokia. All rights reserved.
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.vid.mso;
24 import com.fasterxml.jackson.core.type.TypeReference;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import com.google.common.collect.Lists;
27 import com.google.gson.Gson;
28 import io.joshworks.restclient.http.HttpResponse;
29 import org.apache.commons.io.IOUtils;
30 import org.jetbrains.annotations.NotNull;
31 import org.mockito.hamcrest.MockitoHamcrest;
32 import org.onap.vid.changeManagement.WorkflowRequestDetail;
33 import org.onap.vid.model.SOWorkflowList;
34 import org.onap.vid.model.probes.ExternalComponentStatus;
35 import org.onap.vid.mso.rest.RequestList;
36 import org.onap.vid.mso.rest.RequestWrapper;
37 import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
38 import org.testng.annotations.BeforeClass;
39 import org.testng.annotations.Test;
40 import org.mockito.ArgumentMatcher;
41 import org.mockito.Mock;
42 import org.mockito.MockitoAnnotations;
43 import org.onap.portalsdk.core.util.SystemProperties;
44 import org.onap.vid.changeManagement.ChangeManagementRequest;
45 import org.onap.vid.controller.OperationalEnvironmentController;
46 import org.onap.vid.exceptions.GenericUncheckedException;
47 import org.onap.vid.model.RequestReferencesContainer;
48 import org.onap.vid.model.SoftDeleteRequest;
49 import org.onap.vid.mso.model.CloudConfiguration;
50 import org.onap.vid.mso.model.ModelInfo;
51 import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo;
52 import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo;
53 import org.onap.vid.mso.model.RequestInfo;
54 import org.onap.vid.mso.model.RequestParameters;
55 import org.onap.vid.mso.model.RequestReferences;
56 import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails;
57 import org.onap.vid.mso.rest.Request;
58 import org.onap.vid.mso.rest.RequestDetails;
59 import org.onap.vid.mso.rest.RequestDetailsWrapper;
60 import org.onap.vid.mso.rest.Task;
61 import org.onap.vid.properties.Features;
62 import org.springframework.http.HttpStatus;
63 import org.springframework.test.context.ContextConfiguration;
64 import org.togglz.core.manager.FeatureManager;
66 import javax.ws.rs.BadRequestException;
67 import java.io.IOException;
69 import java.nio.file.Path;
70 import java.nio.file.Paths;
71 import java.util.ArrayList;
72 import java.util.HashMap;
73 import java.util.List;
75 import java.util.UUID;
76 import java.util.stream.Collectors;
78 import static org.assertj.core.api.Assertions.assertThat;
79 import static org.assertj.core.api.Assertions.tuple;
80 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
81 import static org.hamcrest.Matchers.allOf;
82 import static org.hamcrest.Matchers.hasEntry;
83 import static org.junit.Assert.assertEquals;
84 import static org.mockito.ArgumentMatchers.any;
85 import static org.mockito.ArgumentMatchers.anyBoolean;
86 import static org.mockito.ArgumentMatchers.anyString;
87 import static org.mockito.ArgumentMatchers.argThat;
88 import static org.mockito.ArgumentMatchers.eq;
89 import static org.mockito.ArgumentMatchers.isA;
90 import static org.mockito.ArgumentMatchers.endsWith;
91 import static org.mockito.BDDMockito.given;
92 import static org.mockito.Mockito.doReturn;
93 import static org.mockito.Mockito.doThrow;
94 import static org.mockito.Mockito.mock;
95 import static org.mockito.Mockito.when;
96 import static org.onap.vid.controller.MsoController.CONFIGURATION_ID;
97 import static org.onap.vid.controller.MsoController.REQUEST_TYPE;
98 import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
99 import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
100 import static org.onap.vid.mso.MsoBusinessLogicImpl.validateEndpointPath;
102 @ContextConfiguration(classes = {SystemProperties.class})
103 public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
105 private static final ObjectMapper objectMapper = new ObjectMapper();
108 private FeatureManager featureManager;
111 private MsoInterface msoInterface;
114 private SOWorkflowList workflowList;
117 private HttpResponse<SOWorkflowList> workflowListResponse;
120 private RequestDetails msoRequest;
123 private MsoBusinessLogicImpl msoBusinessLogic;
124 private String userId = "testUserId";
125 private String operationalEnvironmentId = "testOperationalEnvironmentId";
128 public void setUp() {
129 MockitoAnnotations.initMocks(this);
130 msoBusinessLogic = new MsoBusinessLogicImpl(msoInterface, featureManager);
134 public void shouldProperlyCreateConfigurationInstanceWithCorrectServiceInstanceId() throws Exception {
136 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
137 String endpointTemplate = String.format("/serviceInstances/v6/%s/configurations", serviceInstanceId);
138 RequestDetailsWrapper requestDetailsWrapper = createRequestDetails();
139 MsoResponseWrapper expectedResponse = createOkResponse();
140 given(msoInterface.createConfigurationInstance(requestDetailsWrapper, endpointTemplate))
141 .willReturn(expectedResponse);
144 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
145 .createConfigurationInstance(requestDetailsWrapper, serviceInstanceId);
148 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
151 private RequestDetailsWrapper createRequestDetails() throws Exception {
152 final URL resource = this.getClass().getResource("/payload_jsons/mso_request_create_configuration.json");
153 RequestDetails requestDetails = objectMapper.readValue(resource, RequestDetails.class);
154 return new RequestDetailsWrapper(requestDetails);
158 public void shouldProperlyValidateEndpointPathWheEendPointIsNotEmptyAndValid() {
159 System.setProperty("TestEnv", "123");
160 String foundEndPoint = validateEndpointPath("TestEnv");
161 assertEquals("123", foundEndPoint);
165 public void shouldThrowRuntimeExceptionWhenValidateEndpointPathEndPointIsNotEmptyAndValid() {
166 assertThatExceptionOfType(RuntimeException.class)
167 .isThrownBy(() -> validateEndpointPath("NotExists"));
171 public void shouldThrowRuntimeExceptionWhenValidateEndpointPathWhenEndPointIsNotEmptyButDoesntExists() {
172 String endPoint = "EmptyEndPoint";
173 System.setProperty(endPoint, "");
174 assertThatExceptionOfType(GenericUncheckedException.class)
175 .isThrownBy(() -> validateEndpointPath(endPoint))
176 .withMessage(endPoint + " env variable is not defined");
180 public void shouldProperlyCreateSvcInstanceWithProperParameters() {
182 MsoResponseWrapper expectedResponse = createOkResponse();
183 String svcEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
184 given(msoInterface.createSvcInstance(msoRequest, svcEndpoint)).willReturn(expectedResponse);
186 MsoResponseWrapper response = msoBusinessLogic.createSvcInstance(msoRequest);
189 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
193 public void shouldProperlyCreateE2eSvcInstanceWithProperParameters() {
195 MsoResponseWrapper expectedResponse = createOkResponse();
196 String svcEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE);
197 given(msoInterface.createE2eSvcInstance(msoRequest, svcEndpoint)).willReturn(expectedResponse);
200 MsoResponseWrapper response = msoBusinessLogic.createE2eSvcInstance(msoRequest);
203 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
207 public void shouldProperlyCreateVnfWithProperParameters() {
209 MsoResponseWrapper expectedResponse = createOkResponse();
210 String endpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
211 String vnfInstanceId = "testVnfInstanceTempId";
212 String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId);
214 given(msoInterface.createVnf(msoRequest, vnfEndpoint)).willReturn(expectedResponse);
216 MsoResponseWrapper response = msoBusinessLogic.createVnf(msoRequest, vnfInstanceId);
219 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
223 public void shouldProperlyCreateNwInstanceWithProperParameters() {
225 MsoResponseWrapper expectedResponse = createOkResponse();
226 String vnfInstanceId = "testNwInstanceTempId";
227 String nwEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
228 String nw_endpoint = nwEndpoint.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId);
230 given(msoInterface.createNwInstance(msoRequest, nw_endpoint)).willReturn(expectedResponse);
232 MsoResponseWrapper response = msoBusinessLogic.createNwInstance(msoRequest, vnfInstanceId);
235 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
239 public void shouldProperlyCreateVolumeGroupInstanceWithProperParameters() {
240 MsoResponseWrapper expectedResponse = createOkResponse();
241 String serviceInstanceId = "testServiceInstanceTempId";
242 String vnfInstanceId = "testVnfInstanceTempId";
243 String nwEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
244 String vnfEndpoint = nwEndpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
245 vnfEndpoint = vnfEndpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
247 given(msoInterface.createVolumeGroupInstance(msoRequest, vnfEndpoint)).willReturn(expectedResponse);
249 MsoResponseWrapper response = msoBusinessLogic.createVolumeGroupInstance(msoRequest, serviceInstanceId, vnfInstanceId);
252 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
256 public void shouldProperlyCreateVfModuleInstanceWithProperParameters() {
257 MsoResponseWrapper expectedResponse = createOkResponse();
258 String serviceInstanceId = "testServiceInstanceTempId";
259 String vnfInstanceId = "testVnfInstanceTempId";
260 String partial_endpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
261 String vf_module_endpoint = partial_endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
262 vf_module_endpoint = vf_module_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
264 given(msoInterface.createVfModuleInstance(msoRequest, vf_module_endpoint)).willReturn(expectedResponse);
266 MsoResponseWrapper response = msoBusinessLogic.createVfModuleInstance(msoRequest, serviceInstanceId, vnfInstanceId);
269 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
273 public void shouldProperlyDeleteE2eSvcInstanceWithProperParameters() {
274 MsoResponseWrapper expectedResponse = createOkResponse();
275 String serviceInstanceId = "testDeleteE2eSvcInstanceTempId";
276 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE) + "/" + serviceInstanceId;
278 given(msoInterface.deleteE2eSvcInstance(msoRequest, endpoint)).willReturn(expectedResponse);
280 MsoResponseWrapper response = msoBusinessLogic.deleteE2eSvcInstance(msoRequest, serviceInstanceId);
283 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
287 public void shouldProperlyDeleteSvcInstanceWithProperParametersAndFalseFeatureFlag() {
289 String endpointTemplate = "/serviceInstances/v5/%s";
290 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
291 String svcEndpoint = String.format(endpointTemplate, serviceInstanceId);
292 RequestDetails requestDetails = new RequestDetails();
293 MsoResponseWrapper expectedResponse = createOkResponse();
294 given(msoInterface.deleteSvcInstance(requestDetails, svcEndpoint)).willReturn(expectedResponse);
295 given(featureManager.isActive(Features.FLAG_UNASSIGN_SERVICE)).willReturn(false);
298 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
299 .deleteSvcInstance(requestDetails, serviceInstanceId, "unAssignOrDeleteParams");
302 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
306 public void shouldProperlyDeleteSvcInstanceWithProperParametersAndTrueFeatureFlag() {
308 String endpointTemplate = "/serviceInstantiation/v5/serviceInstances/%s/unassign";
309 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
310 String svcEndpoint = String.format(endpointTemplate, serviceInstanceId);
311 RequestDetails requestDetails = new RequestDetails();
312 MsoResponseWrapper expectedResponse = createOkResponse();
313 given(msoInterface.unassignSvcInstance(requestDetails, svcEndpoint)).willReturn(expectedResponse);
314 given(featureManager.isActive(Features.FLAG_UNASSIGN_SERVICE)).willReturn(true);
317 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
318 .deleteSvcInstance(requestDetails, serviceInstanceId, "assigned");
321 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
325 public void shouldProperlyDeleteVnfWithProperParameters() {
327 String endpointTemplate = "/serviceInstances/v5/%s/vnfs/%s";
328 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
329 String vnfInstanceId = "testVnfInstanceTempId";
330 String vnfEndpoint = String.format(endpointTemplate, serviceInstanceId, vnfInstanceId);
331 RequestDetails requestDetails = new RequestDetails();
332 MsoResponseWrapper expectedResponse = createOkResponse();
333 given(msoInterface.deleteVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
336 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
337 .deleteVnf(requestDetails, serviceInstanceId, vnfInstanceId);
340 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
344 public void shouldProperlyDeleteVfModuleWithProperParameters() {
346 String endpointTemplate = "/serviceInstances/v7/%s/vnfs/%s/vfModules/%s";
347 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
348 String vnfInstanceId = "testVnfInstanceTempId";
349 String vfModuleId = "testVfModuleId";
350 String vnfEndpoint = String.format(endpointTemplate, serviceInstanceId, vnfInstanceId, vfModuleId);
351 RequestDetails requestDetails = new RequestDetails();
352 MsoResponseWrapper expectedResponse = createOkResponse();
353 given(msoInterface.deleteVfModule(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
356 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
357 .deleteVfModule(requestDetails, serviceInstanceId, vnfInstanceId, vfModuleId);
359 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
363 public void shouldProperlyDeleteVolumeGroupInstanceWithProperParameters() {
364 MsoResponseWrapper expectedResponse = createOkResponse();
365 String serviceInstanceId = "testServiceInstanceTempId";
366 String vnfInstanceId = "testVnfInstanceTempId";
367 String volumeGroupId = "testvolumeGroupIdTempId";
369 String deleteVolumeGroupEndpoint = getDeleteVolumeGroupEndpoint(serviceInstanceId, vnfInstanceId, volumeGroupId);
371 given(msoInterface.deleteVolumeGroupInstance(msoRequest, deleteVolumeGroupEndpoint)).willReturn(expectedResponse);
373 MsoResponseWrapper response = msoBusinessLogic.deleteVolumeGroupInstance(msoRequest, serviceInstanceId, vnfInstanceId, volumeGroupId);
376 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
380 private String getDeleteVolumeGroupEndpoint(String serviceInstanceId, String vnfInstanceId, String volumeGroupId) {
381 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
382 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
383 String vnfEndpoint = svc_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
384 return vnfEndpoint + "/" + volumeGroupId;
388 public void shouldProperlyDeleteNwInstanceWithProperParameters() {
389 MsoResponseWrapper expectedResponse = createOkResponse();
390 String serviceInstanceId = "testServiceInstanceTempId";
391 String networkInstanceId = "testNetworkInstanceTempId";
393 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
394 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
395 String delete_nw_endpoint = svc_endpoint + "/" + networkInstanceId;
397 given(msoInterface.deleteNwInstance(msoRequest, delete_nw_endpoint)).willReturn(expectedResponse);
399 MsoResponseWrapper response = msoBusinessLogic.deleteNwInstance(msoRequest, serviceInstanceId, networkInstanceId);
402 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
406 public void shouldProperlyGetOrchestrationRequestWithProperParameters() {
407 MsoResponseWrapper expectedResponse = createOkResponse();
408 String requestId = "testRequestTempId";
409 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
410 String path = p + "/" + requestId;
412 given(msoInterface.getOrchestrationRequest(path)).willReturn(expectedResponse);
414 MsoResponseWrapper response = msoBusinessLogic.getOrchestrationRequest(requestId);
415 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
418 @Test(expectedExceptions = MsoTestException.class)
419 public void shouldProperlyGetOrchestrationRequestWithWrongParameters() {
420 String requestId = "testWrongRequestTempId";
421 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
422 String path = p + "/" + requestId;
424 given(msoInterface.getOrchestrationRequest(path)).willThrow(new MsoTestException("testException"));
426 msoBusinessLogic.getOrchestrationRequest(requestId);
430 public void shouldProperlyGetOrchestrationRequestsWithProperParameters() {
431 MsoResponseWrapper expectedResponse = createOkResponse();
432 String filterString = "testRequestsTempId";
433 String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
434 String path = url + filterString;
436 given(msoInterface.getOrchestrationRequest(path)).willReturn(expectedResponse);
438 MsoResponseWrapper response = msoBusinessLogic.getOrchestrationRequests(filterString);
439 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
442 @Test(expectedExceptions = MsoTestException.class)
443 public void shouldThrowExceptionWhenGetOrchestrationRequestsWithWrongParameters() {
444 String filterString = "testRequestsTempId";
445 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
446 String path = p + filterString;
448 given(msoInterface.getOrchestrationRequest(path)).willThrow(new MsoTestException("testException"));
450 msoBusinessLogic.getOrchestrationRequests(filterString);
454 public void shouldSendProperScaleOutRequest() throws IOException {
456 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
457 String vnfInstanceId = "testVnfInstanceTempId";
458 String endpointTemplate = "/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s/vfModules/scaleOut";
459 String vnfEndpoint = String.format(endpointTemplate, serviceInstanceId, vnfInstanceId);
460 org.onap.vid.changeManagement.RequestDetails requestDetails = readRequest();
461 org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails> expectedRequest = readExpectedRequest();
462 MsoResponseWrapper expectedMsoResponseWrapper = createOkResponse();
465 .scaleOutVFModuleInstance(argThat(new MsoRequestWrapperMatcher(expectedRequest)),
467 .willReturn(expectedMsoResponseWrapper);
470 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
471 .scaleOutVfModuleInstance(requestDetails, serviceInstanceId, vnfInstanceId);
474 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedMsoResponseWrapper);
477 private org.onap.vid.changeManagement.RequestDetails readRequest() throws IOException {
478 Path path = Paths.get("payload_jsons", "scaleOutVfModulePayload.json");
479 URL url = this.getClass().getClassLoader().getResource(path.toString());
480 return objectMapper.readValue(url, org.onap.vid.changeManagement.RequestDetails.class);
483 private org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails> readExpectedRequest()
485 Path path = Paths.get("payload_jsons", "scaleOutVfModulePayloadToMso.json");
486 URL url = this.getClass().getClassLoader().getResource(path.toString());
487 return objectMapper.readValue(url,
488 new TypeReference<org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails>>() {
494 public void shouldFilterOutOrchestrationRequestsNotAllowedInDashboard() throws Exception {
496 String vnfModelTypeOrchestrationRequests = getFileContentAsString("mso_model_info_sample_response.json");
497 String scaleOutActionOrchestrationRequests = getFileContentAsString("mso_action_scaleout_sample_response.json");
499 MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
501 .getOrchestrationRequest(any(String.class), any(String.class), any(String.class),
502 any(RestObject.class), anyBoolean()))
503 .willReturn(msoResponseWrapperMock);
504 given(msoResponseWrapperMock.getEntity())
505 .willReturn(vnfModelTypeOrchestrationRequests, scaleOutActionOrchestrationRequests);
508 List<Request> filteredOrchestrationReqs = msoBusinessLogic.getOrchestrationRequestsForDashboard();
510 assertThat(filteredOrchestrationReqs).hasSize(3);
511 assertThat(MsoBusinessLogicImpl.DASHBOARD_ALLOWED_TYPES)
512 .containsAll(filteredOrchestrationReqs
514 .map(el -> el.getRequestType().toUpperCase())
515 .collect(Collectors.toList()));
516 assertThat(filteredOrchestrationReqs)
517 .extracting(Request::getRequestScope)
518 .containsOnly("vnf", "vfModule");
521 @Test(expectedExceptions = GenericUncheckedException.class)
522 public void shouldThrowGenericUncheckedExceptionWhenGetOrchestrationRequestsForDashboardWithWrongJsonFile_() throws Exception {
524 String vnfModelTypeOrchestrationRequests = getFileContentAsString("mso_model_info_sample_wrong_response.json");
526 MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
528 .getOrchestrationRequest(any(String.class), any(String.class), any(String.class),
529 any(RestObject.class), anyBoolean()))
530 .willReturn(msoResponseWrapperMock);
531 given(msoResponseWrapperMock.getEntity())
532 .willReturn(vnfModelTypeOrchestrationRequests);
535 msoBusinessLogic.getOrchestrationRequestsForDashboard();
539 public void shouldProperlyGetManualTasksByRequestIdWithProperParameters() throws Exception {
541 String manualTasksList = getFileContentAsString("manual_tasks_by_requestId_test.json");
543 MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
545 .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
546 any(RestObject.class)))
547 .willReturn(msoResponseWrapperMock);
548 given(msoResponseWrapperMock.getEntity())
549 .willReturn(manualTasksList);
552 List<Task> filteredOrchestrationReqs = msoBusinessLogic.getManualTasksByRequestId("TestId");
555 assertThat(filteredOrchestrationReqs).hasSize(2);
556 assertThat(filteredOrchestrationReqs).extracting("taskId", "type").
558 tuple("123123abc", "testTask"),
559 tuple("321321abc", "testTask")
563 @Test(expectedExceptions = GenericUncheckedException.class)
564 public void shouldThrowGenericUncheckedExceptionWhenGetManualTasksByRequestIdWithWrongJsonFile() throws Exception {
566 String manualTasksList = getFileContentAsString("manual_tasks_by_requestId_wrongJson_test.json");
568 MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
570 .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
571 any(RestObject.class)))
572 .willReturn(msoResponseWrapperMock);
573 given(msoResponseWrapperMock.getEntity())
574 .willReturn(manualTasksList);
577 msoBusinessLogic.getManualTasksByRequestId("TestId");
580 @Test(expectedExceptions = MsoTestException.class)
581 public void getManualTasksByRequestIdWithArgument_shouldThrowException() {
584 .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
585 any(RestObject.class)))
586 .willThrow(MsoTestException.class);
589 msoBusinessLogic.getManualTasksByRequestId("TestId");
593 public void shouldProperlyCompleteManualTaskWithProperParameters() {
595 MsoResponseWrapper expectedResponse = createOkResponse();
596 RequestDetails requestDetails = new RequestDetails();
597 String taskId = "testTaskId";
599 String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
600 String path = url + "/" + taskId + "/complete";
602 given(msoInterface.completeManualTask(eq(requestDetails), any(String.class), any(String.class), eq(path), any(RestObject.class))).willReturn(expectedResponse);
605 MsoResponseWrapper response = msoBusinessLogic.completeManualTask(requestDetails, taskId);
608 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
613 public void shouldProperlyActivateServiceInstanceWithProperParameters() {
615 RequestDetails detail = new RequestDetails();
616 String taskId = "testTaskId";
618 RestObject<String> restObjStr = new RestObject<>();
620 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
623 MsoResponseWrapper response = msoBusinessLogic.activateServiceInstance(detail, taskId);
626 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
630 @Test(expectedExceptions = MsoTestException.class)
631 public void shouldThrowExceptionWhenActivateServiceInstanceWithWrongParameters() {
633 RequestDetails requestDetails = new RequestDetails();
634 String taskId = "testTaskId";
636 RestObject<String> restObjStr = new RestObject<>();
638 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
640 doThrow(new MsoTestException("testException")).
641 when(msoInterface).setServiceInstanceStatus(eq(requestDetails), any(String.class), any(String.class), any(String.class), any(RestObject.class));
644 MsoResponseWrapper response = msoBusinessLogic.activateServiceInstance(requestDetails, taskId);
647 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
650 @Test(expectedExceptions = MsoTestException.class)
651 public void shouldThrowExceptionWhenManualTaskWithWrongParameters() {
653 RequestDetails requestDetails = new RequestDetails();
656 String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
657 String path = url + "/" + taskId + "/complete";
659 given(msoInterface.completeManualTask(eq(requestDetails), any(String.class), any(String.class), eq(path), any(RestObject.class))).willThrow(new MsoTestException("empty path"));
662 msoBusinessLogic.completeManualTask(requestDetails, taskId);
666 public void shouldProperlyUpdateVnfWithProperParameters() {
668 MsoResponseWrapper expectedResponse = createOkResponse();
669 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
671 String serviceInstanceId = "testServiceId";
672 String vnfInstanceId = "testVnfInstanceId";
674 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
675 String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
676 vnfEndpoint = vnfEndpoint + '/' + vnfInstanceId;
678 given(msoInterface.updateVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
681 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnf(requestDetails, serviceInstanceId, vnfInstanceId);
684 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
688 public void shouldProperlyReplaceVnfWithProperParameters() {
690 MsoResponseWrapper expectedResponse = createOkResponse();
691 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
693 String serviceInstanceId = "testServiceId";
694 String vnfInstanceId = "testVnfInstanceId";
696 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE);
697 String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
698 vnfEndpoint = vnfEndpoint.replace(VNF_INSTANCE_ID, vnfInstanceId);
699 vnfEndpoint = vnfEndpoint.replace(REQUEST_TYPE, ChangeManagementRequest.MsoChangeManagementRequest.REPLACE);
701 given(msoInterface.replaceVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
704 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.replaceVnf(requestDetails, serviceInstanceId, vnfInstanceId);
707 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
711 public void shouldProperlyGenerateInPlaceMsoRequestWithProperParameters() {
713 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
715 requestDetails.setVnfInstanceId("testVnfInstanceId");
716 requestDetails.setVnfName("testVnfName");
717 requestDetails.setRequestParameters(new RequestParameters());
719 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
720 "\"existing_software_version\": \"testExistingSoftwareParam\"," +
721 "\"new_software_version\": \"testNewSoftwareParam\"," +
722 "\"operations_timeout\": \"100\"" +
725 RequestDetails inPlaceSoftwareUpdateRequest = new RequestDetails();
726 inPlaceSoftwareUpdateRequest.setCloudConfiguration(requestDetails.getCloudConfiguration());
727 inPlaceSoftwareUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
728 inPlaceSoftwareUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
729 org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.changeManagement.RequestDetailsWrapper();
730 requestDetailsWrapper.requestDetails = inPlaceSoftwareUpdateRequest;
733 org.onap.vid.changeManagement.RequestDetailsWrapper response = msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
736 assertThat(response).isEqualToComparingFieldByField(requestDetailsWrapper);
739 @Test(expectedExceptions = BadRequestException.class)
740 public void shouldThrowExceptionWhenGenerateInPlaceMsoRequestWithParametersWithWrongCharacters() {
742 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
744 requestDetails.setVnfInstanceId("testVnfInstanceId");
745 requestDetails.setVnfName("testVnfName");
746 requestDetails.setRequestParameters(new RequestParameters());
748 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
749 "\"existing_software_version\": \"#####\"," +
750 "\"new_software_version\": \"testNewSoftwareParam\"" +
754 msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
757 @Test(expectedExceptions = BadRequestException.class)
758 public void shouldThrowExceptionWhenGenerateInPlaceMsoRequestWithWrongParameters() {
760 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
762 requestDetails.setVnfInstanceId("testVnfInstanceId");
763 requestDetails.setVnfName("testVnfName");
764 requestDetails.setRequestParameters(new RequestParameters());
766 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
767 "\"test-wrong-parameter\": \"testParam\"," +
768 "\"new_software_version\": \"testNewSoftwareParam\"" +
772 msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
776 public void shouldProprleyGenerateConfigMsoRequestWithProperParameters() {
778 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
780 requestDetails.setVnfInstanceId("testVnfInstanceId");
781 requestDetails.setVnfName("testVnfName");
782 requestDetails.setRequestParameters(new RequestParameters());
784 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
785 "\"request-parameters\": \"testRequestParam\"," +
786 "\"configuration-parameters\": \"testConfigParams\"" +
789 RequestDetails configUpdateRequest = new RequestDetails();
790 configUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
791 configUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
793 org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.changeManagement.RequestDetailsWrapper();
794 requestDetailsWrapper.requestDetails = configUpdateRequest;
797 org.onap.vid.changeManagement.RequestDetailsWrapper response = msoBusinessLogic.generateConfigMsoRequest(requestDetails);
800 assertThat(response).isEqualToComparingFieldByField(requestDetailsWrapper);
803 @Test(expectedExceptions = BadRequestException.class)
804 public void shouldThrowExceptionGenerateConfigMsoRequestWithoutAdditionalParameters() {
806 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
808 requestDetails.setVnfInstanceId("testVnfInstanceId");
809 requestDetails.setVnfName("testVnfName");
810 requestDetails.setRequestParameters(null);
813 msoBusinessLogic.generateConfigMsoRequest(requestDetails);
816 @Test(expectedExceptions = BadRequestException.class)
817 public void shouldThrowExceptionWhenGenerateConfigMsoRequestWithWrongPayload() {
819 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
821 requestDetails.setVnfInstanceId("testVnfInstanceId");
822 requestDetails.setVnfName("testVnfName");
823 requestDetails.setRequestParameters(new RequestParameters());
825 requestDetails.getRequestParameters().setAdditionalProperty("payload", null);
828 msoBusinessLogic.generateConfigMsoRequest(requestDetails);
831 @Test(expectedExceptions = BadRequestException.class)
832 public void shouldThrowExceptionGenerateConfigMsoRequestWithoutAnyParameter() {
834 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
836 requestDetails.setVnfInstanceId("testVnfInstanceId");
837 requestDetails.setVnfName("testVnfName");
838 requestDetails.setRequestParameters(new RequestParameters());
840 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
841 "\"test-wrong-parameter\": \"testParam\"," +
842 "\"configuration-parameters\": \"testConfigParam\"" +
846 msoBusinessLogic.generateConfigMsoRequest(requestDetails);
850 public void shouldProperlyGetActivateFabricConfigurationPathWithProperParameters() {
852 String serviceInstanceId = "testServiceId";
853 String path = validateEndpointPath(MsoProperties.MSO_REST_API_SERVICE_INSTANCE_CREATE);
854 path += "/" + serviceInstanceId + "/activateFabricConfiguration";
857 String response = msoBusinessLogic.getActivateFabricConfigurationPath(serviceInstanceId);
860 assertThat(response).isEqualTo(path);
864 public void shouldProperlyGetDeactivateAndCloudDeletePathWithProperParameters() {
866 String serviceInstanceId = "testServiceId";
867 String vnfInstanceId = "testVnfInstanceId";
868 String vfModuleInstanceId = "testVfModuleInstanceId";
869 String path = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
870 path = path.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
871 path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
872 path += "/" + vfModuleInstanceId + "/deactivateAndCloudDelete";
875 String response = msoBusinessLogic.getDeactivateAndCloudDeletePath(serviceInstanceId, vnfInstanceId, vfModuleInstanceId);
878 assertThat(response).isEqualTo(path);
882 public void shouldProperlyBuildRequestDetailsForSoftDeleteWithProperParameters() {
884 SoftDeleteRequest softDeleteRequest = new SoftDeleteRequest();
885 RequestDetails requestDetails = new RequestDetails();
887 String userId = "testUserID";
888 String tenantId = "testTenantId ";
889 String cloudRegionId = "testCloudId";
892 RequestInfo requestInfo = new RequestInfo();
893 requestInfo.setSource("VID");
894 requestInfo.setRequestorId(userId);
895 requestDetails.setRequestInfo(requestInfo);
897 CloudConfiguration cloudConfiguration = new CloudConfiguration();
898 cloudConfiguration.setTenantId(tenantId);
899 cloudConfiguration.setLcpCloudRegionId(cloudRegionId);
900 requestDetails.setCloudConfiguration(cloudConfiguration);
902 setModelInfoForRequestDetails(requestDetails);
904 setRequestParametersForRequestDetails(requestDetails);
906 softDeleteRequest.setLcpCloudRegionId(cloudRegionId);
907 softDeleteRequest.setTenantId(tenantId);
908 softDeleteRequest.setUserId(userId);
911 RequestDetails response = msoBusinessLogic.buildRequestDetailsForSoftDelete(softDeleteRequest);
914 assertThat(response).isEqualTo(requestDetails);
917 private void setRequestParametersForRequestDetails(RequestDetails requestDetails) {
918 RequestParameters requestParameters = new RequestParameters();
919 requestParameters.setTestApi("GR_API");
920 requestDetails.setRequestParameters(requestParameters);
923 private void setModelInfoForRequestDetails(RequestDetails requestDetails) {
924 ModelInfo modelInfo = new ModelInfo();
925 modelInfo.setModelType("vfModule");
926 requestDetails.setModelInfo(modelInfo);
930 public void shouldProperlyDeactivateAndCloudDeleteWithProperParameters() {
932 String serviceInstanceId = "testServiceId";
933 String vnfInstanceId = "testVnfInstanceId";
934 String vfModuleInstanceId = "testVfModuleInstanceId";
935 RequestDetails requestDetails = new RequestDetails();
937 String path = msoBusinessLogic.getDeactivateAndCloudDeletePath(serviceInstanceId, vnfInstanceId, vfModuleInstanceId);
939 RequestReferences requestReferences = new RequestReferences();
940 requestReferences.setInstanceId("testInstance");
941 requestReferences.setRequestId("testRequest");
943 HttpResponse<RequestReferencesContainer> expectedResponse = HttpResponse.fallback(new RequestReferencesContainer(requestReferences));
945 MsoResponseWrapper2 responseWrapped = new MsoResponseWrapper2<>(expectedResponse);
947 given(msoInterface.post(eq(path), any(org.onap.vid.changeManagement.RequestDetailsWrapper.class), eq(RequestReferencesContainer.class))).willReturn(expectedResponse);
950 MsoResponseWrapper2 response = msoBusinessLogic.deactivateAndCloudDelete(serviceInstanceId, vnfInstanceId, vfModuleInstanceId, requestDetails);
953 assertThat(response).isEqualToComparingFieldByField(responseWrapped);
957 public void shouldProperlyActivateFabricConfigurationWithProperParameters() {
959 String serviceInstanceId = "testServiceId";
960 RequestDetails requestDetails = new RequestDetails();
962 String path = msoBusinessLogic.getActivateFabricConfigurationPath(serviceInstanceId);
964 RequestReferences requestReferences = new RequestReferences();
965 requestReferences.setInstanceId("testInstance");
966 requestReferences.setRequestId("testRequest");
968 HttpResponse<RequestReferencesContainer> expectedResponse = HttpResponse.fallback(new RequestReferencesContainer(requestReferences));
970 MsoResponseWrapper2 responseWrapped = new MsoResponseWrapper2<>(expectedResponse);
972 given(msoInterface.post(eq(path), any(org.onap.vid.changeManagement.RequestDetailsWrapper.class), eq(RequestReferencesContainer.class))).willReturn(expectedResponse);
975 MsoResponseWrapper2 response = msoBusinessLogic.activateFabricConfiguration(serviceInstanceId, requestDetails);
978 assertThat(response).isEqualToComparingFieldByField(responseWrapped);
982 public void shouldProperlyUpdateVnfSoftwareWithProperParameters() {
984 String serviceInstanceId = "testServiceId";
985 String vnfInstanceId = "testVnfInstanceId";
987 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
989 requestDetails.setVnfInstanceId("testVnfInstanceId");
990 requestDetails.setVnfName("testVnfName");
991 requestDetails.setRequestParameters(new RequestParameters());
993 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
994 "\"existing_software_version\": \"testExistingSoftwareParam\"," +
995 "\"new_software_version\": \"testNewSoftwareParam\"," +
996 "\"operations_timeout\": \"100\"" +
999 MsoResponseWrapper okResponse = createOkResponse();
1001 given(msoInterface.changeManagementUpdate(isA(org.onap.vid.changeManagement.RequestDetailsWrapper.class), any(String.class))).willReturn(okResponse);
1004 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnfSoftware(requestDetails, serviceInstanceId, vnfInstanceId);
1007 assertThat(response).isEqualToComparingFieldByField(okResponse);
1011 public void shouldProperlyUpdateVnfConfigWithProperParameters() {
1013 String serviceInstanceId = "testServiceId";
1014 String vnfInstanceId = "testVnfInstanceId";
1016 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1018 requestDetails.setVnfInstanceId("testVnfInstanceId");
1019 requestDetails.setVnfName("testVnfName");
1020 requestDetails.setRequestParameters(new RequestParameters());
1022 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
1023 "\"request-parameters\": \"testRequestParam\"," +
1024 "\"configuration-parameters\": \"testConfigParams\"" +
1027 MsoResponseWrapper okResponse = createOkResponse();
1029 given(msoInterface.changeManagementUpdate(isA(org.onap.vid.changeManagement.RequestDetailsWrapper.class), any(String.class))).willReturn(okResponse);
1032 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnfConfig(requestDetails, serviceInstanceId, vnfInstanceId);
1035 assertThat(response).isEqualToComparingFieldByField(okResponse);
1039 public void shouldProperlyDeleteConfigurationWithProperParameters() {
1041 String serviceInstanceId = "testServiceId";
1042 String configurationId = "testConfigurationId";
1044 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1046 requestDetails.setVnfInstanceId("testVnfInstanceId");
1047 requestDetails.setVnfName("testVnfName");
1049 MsoResponseWrapper okResponse = createOkResponse();
1050 RequestDetailsWrapper wrappedRequestDetail = new RequestDetailsWrapper(requestDetails);
1052 given(msoInterface.deleteConfiguration(eq(wrappedRequestDetail), any(String.class))).willReturn(okResponse);
1055 MsoResponseWrapper response = msoBusinessLogic.deleteConfiguration(wrappedRequestDetail, serviceInstanceId, configurationId);
1058 assertThat(response).isEqualToComparingFieldByField(okResponse);
1062 public void shouldProperlySetConfigurationActiveStatusActiveWithProperParameters() {
1064 String serviceInstanceId = "testServiceId";
1065 String configurationId = "testConfigurationId";
1067 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1069 requestDetails.setVnfInstanceId("testVnfInstanceId");
1070 requestDetails.setVnfName("testVnfName");
1072 MsoResponseWrapper okResponse = createOkResponse();
1075 validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1076 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1077 .replace(CONFIGURATION_ID, configurationId)
1080 given(msoInterface.setConfigurationActiveStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1083 MsoResponseWrapper response = msoBusinessLogic.setConfigurationActiveStatus(requestDetails, serviceInstanceId, configurationId, true);
1086 assertThat(response).isEqualToComparingFieldByField(okResponse);
1090 public void shouldProperlySetConfigurationActiveStatusDeactivateWithProperParameters() {
1092 String serviceInstanceId = "testServiceId";
1093 String configurationId = "testConfigurationId";
1095 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1097 requestDetails.setVnfInstanceId("testVnfInstanceId");
1098 requestDetails.setVnfName("testVnfName");
1100 MsoResponseWrapper okResponse = createOkResponse();
1103 validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1104 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1105 .replace(CONFIGURATION_ID, configurationId)
1108 given(msoInterface.setConfigurationActiveStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1111 MsoResponseWrapper response = msoBusinessLogic.setConfigurationActiveStatus(requestDetails, serviceInstanceId, configurationId, false);
1114 assertThat(response).isEqualToComparingFieldByField(okResponse);
1118 public void shouldProperlySetServiceInstanceStatusActiveWithProperParameters() {
1120 String serviceInstanceId = "testServiceId";
1122 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1124 RestObject<String> restObjStr = new RestObject<>();
1126 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
1129 MsoResponseWrapper response = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, true);
1132 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
1137 public void shouldProperlySetServiceInstanceStatusDeactivateWithProperParameters() {
1139 String serviceInstanceId = "testServiceId";
1141 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1143 RestObject<String> restObjStr = new RestObject<>();
1145 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
1148 MsoResponseWrapper response = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, false);
1151 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
1155 @Test(expectedExceptions = MsoTestException.class)
1156 public void shouldThrowExceptionWhenSetServiceInstanceStatusWithWrongParameters() {
1158 String serviceInstanceId = "testServiceId";
1160 doThrow(new MsoTestException("testException")).
1161 when(msoInterface).setServiceInstanceStatus(eq(null), any(String.class), any(String.class), any(String.class), any(RestObject.class));
1164 msoBusinessLogic.setServiceInstanceStatus(null, serviceInstanceId, true);
1168 public void shouldProperlySetPortOnConfigurationStatusEnableWithProperParameters() {
1170 String serviceInstanceId = "testServiceId";
1171 String configurationId = "testConfigurationId";
1172 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1173 requestDetails.setVnfInstanceId("testVnfInstanceId");
1174 requestDetails.setVnfName("testVnfName");
1175 MsoResponseWrapper okResponse = createOkResponse();
1177 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1178 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1179 .replace(CONFIGURATION_ID, configurationId)
1182 given(msoInterface.setPortOnConfigurationStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1185 MsoResponseWrapper response = msoBusinessLogic.setPortOnConfigurationStatus(requestDetails, serviceInstanceId, configurationId, true);
1188 assertThat(response).isEqualToComparingFieldByField(okResponse);
1192 public void shouldProperlySetPortOnConfigurationStatusDisableWithProperParameters() {
1194 String serviceInstanceId = "testServiceId";
1195 String configurationId = "testConfigurationId";
1196 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1197 requestDetails.setVnfInstanceId("testVnfInstanceId");
1198 requestDetails.setVnfName("testVnfName");
1199 MsoResponseWrapper okResponse = createOkResponse();
1201 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1202 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1203 .replace(CONFIGURATION_ID, configurationId)
1206 given(msoInterface.setPortOnConfigurationStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1209 MsoResponseWrapper response = msoBusinessLogic.setPortOnConfigurationStatus(requestDetails, serviceInstanceId, configurationId, false);
1212 assertThat(response).isEqualToComparingFieldByField(okResponse);
1216 public void shouldProperlyCreateOperationalEnvironmentActivationRequestDetailsWithProperParameters() {
1218 OperationalEnvironmentActivateInfo details = createTestOperationalEnvironmentActivateInfo();
1220 org.onap.vid.changeManagement.RequestDetailsWrapper<RequestDetails> requestDetails = msoBusinessLogic.createOperationalEnvironmentActivationRequestDetails(details);
1223 assertThat(requestDetails.requestDetails.getRequestParameters().getAdditionalProperties().values()).contains(details.getWorkloadContext(), details.getManifest());
1224 assertThat(requestDetails.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
1228 public void shouldProperlyGetOperationalEnvironmentActivationPathWithProperParameters() {
1230 OperationalEnvironmentActivateInfo details = createTestOperationalEnvironmentActivateInfo();
1233 String response = msoBusinessLogic.getOperationalEnvironmentActivationPath(details);
1236 assertThat(response).contains(operationalEnvironmentId);
1240 public void shouldProperlyCreateOperationalEnvironmentDeactivationRequestDetailsWithProperParameters() {
1242 OperationalEnvironmentDeactivateInfo details = createTestOperationalEnvironmentDeactivateInfo();
1245 org.onap.vid.changeManagement.RequestDetailsWrapper<RequestDetails> response;
1246 response = msoBusinessLogic.createOperationalEnvironmentDeactivationRequestDetails(details);
1249 assertThat(response.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
1253 public void shouldProperlyGetCloudResourcesRequestsStatusPathWithProperParameters() {
1255 String requestId = "testRequestId";
1258 String response = msoBusinessLogic.getCloudResourcesRequestsStatusPath(requestId);
1261 assertThat(response).contains(requestId);
1265 public void shouldProperlyGetOperationalEnvironmentDeactivationPathWithProperParameters() {
1267 OperationalEnvironmentDeactivateInfo details = createTestOperationalEnvironmentDeactivateInfo();
1270 String response = msoBusinessLogic.getOperationalEnvironmentDeactivationPath(details);
1273 assertThat(response).contains(operationalEnvironmentId);
1277 public void shouldProperlyGetOperationalEnvironmentCreationPathWithProperParameters() {
1279 String response = msoBusinessLogic.getOperationalEnvironmentCreationPath();
1282 assertThat(response).isNotBlank();
1286 public void shouldProperlyConvertParametersToRequestDetailsWithProperParameters() {
1288 OperationalEnvironmentController.OperationalEnvironmentCreateBody input = createTestOperationalEnvironmentCreateBody();
1291 org.onap.vid.changeManagement.RequestDetailsWrapper<OperationEnvironmentRequestDetails> response
1292 = msoBusinessLogic.convertParametersToRequestDetails(input, userId);
1295 assertThat(response.requestDetails.getRequestInfo().getInstanceName()).isEqualTo(input.getInstanceName());
1296 assertThat(response.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
1297 assertThat(response.requestDetails.getRequestParameters().getOperationalEnvironmentType()).isEqualTo(input.getOperationalEnvironmentType());
1298 assertThat(response.requestDetails.getRequestParameters().getTenantContext()).isEqualTo(input.getTenantContext());
1299 assertThat(response.requestDetails.getRequestParameters().getWorkloadContext()).isEqualTo(input.getWorkloadContext());
1303 public void shouldProperlyRemoveRelationshipFromServiceInstanceWithProperParameters() {
1305 MsoResponseWrapper expectedResponse = createOkResponse();
1306 String serviceInstanceId = "testServiceId";
1307 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1309 given(msoInterface.removeRelationshipFromServiceInstance(eq(requestDetails), endsWith("/" + serviceInstanceId + "/removeRelationships")))
1310 .willReturn(expectedResponse);
1313 MsoResponseWrapper response = msoBusinessLogic.removeRelationshipFromServiceInstance(requestDetails, serviceInstanceId);
1316 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
1320 public void shouldProperlyAddRelationshipToServiceInstanceWithProperParameters() {
1322 MsoResponseWrapper expectedResponse = createOkResponse();
1323 String serviceInstanceId = "testServiceId";
1324 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1326 given(msoInterface.addRelationshipToServiceInstance(eq(requestDetails), endsWith("/" + serviceInstanceId + "/addRelationships")))
1327 .willReturn(expectedResponse);
1330 MsoResponseWrapper response = msoBusinessLogic.addRelationshipToServiceInstance(requestDetails, serviceInstanceId);
1333 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
1337 public void shouldProperlyRequestTypeFromValueWithValidParameters() {
1339 String testValue = "createInstance";
1341 MsoBusinessLogicImpl.RequestType response = MsoBusinessLogicImpl.RequestType.fromValue(testValue);
1344 assertThat(response.toString()).isEqualTo(testValue);
1347 @Test(expectedExceptions = IllegalArgumentException.class)
1348 public void shouldThrowExceptionWhenRequestTypeFromValueWithWrongParameter() {
1350 String testValue = "notExistingParameter";
1352 MsoBusinessLogicImpl.RequestType.fromValue(testValue);
1356 public void shouldProperlyInvokeVnfWorkflowWithValidParameters() {
1358 MsoResponseWrapper okResponse = createOkResponse();
1359 WorkflowRequestDetail request = createWorkflowRequestDetail();
1360 UUID serviceInstanceId = new UUID(1,10);
1361 UUID vnfInstanceId = new UUID(2,20);
1362 UUID workflow_UUID = new UUID(3,30);
1363 String path = "/instanceManagement/v1/serviceInstances/"+serviceInstanceId+"/vnfs/"+vnfInstanceId+"/workflows/"+workflow_UUID;
1365 given(msoInterface.invokeWorkflow(eq(request), eq(path), MockitoHamcrest.argThat(allOf(hasEntry("X-RequestorID", "testRequester"),hasEntry("X-ONAP-PartnerName", "VID"))))).willReturn(okResponse);
1368 MsoResponseWrapper response = msoBusinessLogic.invokeVnfWorkflow(request, "testRequester", serviceInstanceId, vnfInstanceId, workflow_UUID);
1371 assertThat(response).isEqualToComparingFieldByField(okResponse);
1376 public void shouldReturnWorkflowListForGivenModelId() {
1377 given(msoInterface.getWorkflowListByModelId(anyString())).willReturn(workflowListResponse);
1378 given(workflowListResponse.getBody()).willReturn(workflowList);
1379 given(workflowListResponse.getStatus()).willReturn(HttpStatus.ACCEPTED.value());
1381 SOWorkflowList workflows = msoBusinessLogic.getWorkflowListByModelId("sampleModelId");
1383 assertThat(workflows).isEqualTo(workflowList);
1386 @Test(expectedExceptions = {MsoBusinessLogicImpl.WorkflowListException.class})
1387 public void shouldRaiseExceptionWhenRetrievingWorkflowsFailed() {
1388 given(msoInterface.getWorkflowListByModelId(anyString())).willReturn(workflowListResponse);
1389 given(workflowListResponse.getStatus()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR.value());
1391 msoBusinessLogic.getWorkflowListByModelId("sampleModelId");
1396 public void probeShouldReturnOrchestrationRequestsAndConnectionStatus(){
1397 MsoResponseWrapper wrapper = getMsoResponseWrapper();
1398 given(msoInterface.getOrchestrationRequest(anyString(),anyString(),
1399 anyString(),any(RestObject.class),anyBoolean())).willReturn(wrapper);
1401 ExternalComponentStatus externalComponentStatus = msoBusinessLogic.probeComponent();
1403 assertThat(externalComponentStatus.isAvailable()).isTrue();
1404 assertThat(externalComponentStatus.getComponent()).isEqualTo(ExternalComponentStatus.Component.MSO);
1408 private MsoResponseWrapper getMsoResponseWrapper() {
1409 MsoResponseWrapper wrapper=new MsoResponseWrapper();
1410 RequestWrapper requestWrapper = new RequestWrapper();
1411 requestWrapper.setRequest(new Request());
1412 RequestList requestList = new RequestList();
1413 List<RequestWrapper> response = Lists.newArrayList(requestWrapper);
1414 requestList.setRequestList(response);
1415 wrapper.setEntity(new Gson().toJson(requestList));
1419 private WorkflowRequestDetail createWorkflowRequestDetail() {
1420 WorkflowRequestDetail workflowRequestDetail = new WorkflowRequestDetail();
1421 org.onap.vid.changeManagement.RequestParameters requestParameters = new org.onap.vid.changeManagement.RequestParameters();
1422 HashMap<String,String> paramsMap = new HashMap<>();
1423 paramsMap.put("testKey1","testValue1");
1424 paramsMap.put("testKey2","testValue2");
1426 List<Map<String,String>> mapArray= new ArrayList<>();
1427 mapArray.add(paramsMap);
1428 requestParameters.setUserParams(mapArray);
1430 CloudConfiguration cloudConfiguration = new CloudConfiguration();
1431 cloudConfiguration.setCloudOwner("testOwne");
1432 cloudConfiguration.setTenantId("testId");
1433 cloudConfiguration.setLcpCloudRegionId("testLcpCloudId");
1435 workflowRequestDetail.setRequestParameters(requestParameters);
1436 workflowRequestDetail.setCloudConfiguration(cloudConfiguration);
1437 return workflowRequestDetail;
1440 private OperationalEnvironmentActivateInfo createTestOperationalEnvironmentActivateInfo() {
1441 OperationalEnvironmentController.OperationalEnvironmentActivateBody operationalEnvironmentActivateBody = new OperationalEnvironmentController.OperationalEnvironmentActivateBody(
1442 "testRelatedInstanceId",
1443 "testRelatedInstanceName",
1444 "testWorkloadContext",
1445 new OperationalEnvironmentController.OperationalEnvironmentManifest()
1447 return new OperationalEnvironmentActivateInfo(operationalEnvironmentActivateBody, userId, operationalEnvironmentId);
1450 private OperationalEnvironmentDeactivateInfo createTestOperationalEnvironmentDeactivateInfo() {
1451 return new OperationalEnvironmentDeactivateInfo(userId, operationalEnvironmentId);
1454 private OperationalEnvironmentController.OperationalEnvironmentCreateBody createTestOperationalEnvironmentCreateBody() {
1455 return new OperationalEnvironmentController.OperationalEnvironmentCreateBody(
1457 "testEcompInstanceId",
1458 "testEcompInstanceName",
1459 "testOperationalEnvironmentType",
1460 "testTenantContext",
1461 "testWorkloadContext"
1465 private MsoResponseWrapper createOkResponse() {
1466 HttpStatus expectedStatus = HttpStatus.ACCEPTED;
1467 String expectedBody = " \"body\": {\n" +
1468 " \"requestReferences\": {\n" +
1469 " \"instanceId\": \" 123456 \",\n" +
1470 " \"requestId\": \"b6dc9806-b094-42f7-9386-a48de8218ce8\"\n" +
1472 MsoResponseWrapper responseWrapper = new MsoResponseWrapper();
1473 responseWrapper.setEntity(expectedBody);
1474 responseWrapper.setStatus(expectedStatus.value());
1475 return responseWrapper;
1478 private String getFileContentAsString(String resourceName) throws Exception {
1479 Path path = Paths.get("payload_jsons", resourceName);
1480 URL url = this.getClass().getClassLoader().getResource(path.toString());
1483 result = IOUtils.toString(url.toURI(), "UTF-8");
1488 private static class MsoRequestWrapperMatcher implements
1489 ArgumentMatcher<org.onap.vid.changeManagement.RequestDetailsWrapper> {
1491 private final org.onap.vid.changeManagement.RequestDetailsWrapper expectedRequest;
1493 MsoRequestWrapperMatcher(org.onap.vid.changeManagement.RequestDetailsWrapper expectedRequest) {
1494 this.expectedRequest = expectedRequest;
1498 public boolean matches(org.onap.vid.changeManagement.RequestDetailsWrapper argument) {
1499 return expectedRequest.requestDetails.equals(argument.requestDetails);
1503 private class MsoTestException extends RuntimeException {
1504 MsoTestException(String testException) {
1505 super(testException);