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.onap.vid.controller.MsoController.CONFIGURATION_ID;
96 import static org.onap.vid.controller.MsoController.REQUEST_TYPE;
97 import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
98 import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
99 import static org.onap.vid.mso.MsoBusinessLogicImpl.validateEndpointPath;
101 @ContextConfiguration(classes = {SystemProperties.class})
102 public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
104 private static final ObjectMapper objectMapper = new ObjectMapper();
107 private FeatureManager featureManager;
110 private MsoInterface msoInterface;
113 private SOWorkflowList workflowList;
116 private HttpResponse<SOWorkflowList> workflowListResponse;
119 private RequestDetails msoRequest;
122 private MsoBusinessLogicImpl msoBusinessLogic;
123 private String userId = "testUserId";
124 private String operationalEnvironmentId = "testOperationalEnvironmentId";
127 public void setUp() {
128 MockitoAnnotations.initMocks(this);
129 msoBusinessLogic = new MsoBusinessLogicImpl(msoInterface, featureManager);
133 public void shouldProperlyCreateConfigurationInstanceWithCorrectServiceInstanceId() throws Exception {
135 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
136 String endpointTemplate = String.format("/serviceInstances/v6/%s/configurations", serviceInstanceId);
137 RequestDetailsWrapper requestDetailsWrapper = createRequestDetails();
138 MsoResponseWrapper expectedResponse = createOkResponse();
139 given(msoInterface.createConfigurationInstance(requestDetailsWrapper, endpointTemplate))
140 .willReturn(expectedResponse);
143 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
144 .createConfigurationInstance(requestDetailsWrapper, serviceInstanceId);
147 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
150 private RequestDetailsWrapper createRequestDetails() throws Exception {
151 final URL resource = this.getClass().getResource("/payload_jsons/mso_request_create_configuration.json");
152 RequestDetails requestDetails = objectMapper.readValue(resource, RequestDetails.class);
153 return new RequestDetailsWrapper(requestDetails);
157 public void shouldProperlyValidateEndpointPathWheEendPointIsNotEmptyAndValid() {
158 System.setProperty("TestEnv", "123");
159 String foundEndPoint = validateEndpointPath("TestEnv");
160 assertEquals("123", foundEndPoint);
164 public void shouldThrowRuntimeExceptionWhenValidateEndpointPathEndPointIsNotEmptyAndValid() {
165 assertThatExceptionOfType(RuntimeException.class)
166 .isThrownBy(() -> validateEndpointPath("NotExists"));
170 public void shouldThrowRuntimeExceptionWhenValidateEndpointPathWhenEndPointIsNotEmptyButDoesntExists() {
171 String endPoint = "EmptyEndPoint";
172 System.setProperty(endPoint, "");
173 assertThatExceptionOfType(GenericUncheckedException.class)
174 .isThrownBy(() -> validateEndpointPath(endPoint))
175 .withMessage(endPoint + " env variable is not defined");
179 public void shouldProperlyCreateSvcInstanceWithProperParameters() {
181 MsoResponseWrapper expectedResponse = createOkResponse();
182 String svcEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
183 given(msoInterface.createSvcInstance(msoRequest, svcEndpoint)).willReturn(expectedResponse);
185 MsoResponseWrapper response = msoBusinessLogic.createSvcInstance(msoRequest);
188 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
192 public void shouldProperlyCreateE2eSvcInstanceWithProperParameters() {
194 MsoResponseWrapper expectedResponse = createOkResponse();
195 String svcEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE);
196 given(msoInterface.createE2eSvcInstance(msoRequest, svcEndpoint)).willReturn(expectedResponse);
199 MsoResponseWrapper response = msoBusinessLogic.createE2eSvcInstance(msoRequest);
202 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
206 public void shouldProperlyCreateVnfWithProperParameters() {
208 MsoResponseWrapper expectedResponse = createOkResponse();
209 String endpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
210 String vnfInstanceId = "testVnfInstanceTempId";
211 String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId);
213 given(msoInterface.createVnf(msoRequest, vnfEndpoint)).willReturn(expectedResponse);
215 MsoResponseWrapper response = msoBusinessLogic.createVnf(msoRequest, vnfInstanceId);
218 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
222 public void shouldProperlyCreateNwInstanceWithProperParameters() {
224 MsoResponseWrapper expectedResponse = createOkResponse();
225 String vnfInstanceId = "testNwInstanceTempId";
226 String nwEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
227 String nw_endpoint = nwEndpoint.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId);
229 given(msoInterface.createNwInstance(msoRequest, nw_endpoint)).willReturn(expectedResponse);
231 MsoResponseWrapper response = msoBusinessLogic.createNwInstance(msoRequest, vnfInstanceId);
234 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
238 public void shouldProperlyCreateVolumeGroupInstanceWithProperParameters() {
239 MsoResponseWrapper expectedResponse = createOkResponse();
240 String serviceInstanceId = "testServiceInstanceTempId";
241 String vnfInstanceId = "testVnfInstanceTempId";
242 String nwEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
243 String vnfEndpoint = nwEndpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
244 vnfEndpoint = vnfEndpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
246 given(msoInterface.createVolumeGroupInstance(msoRequest, vnfEndpoint)).willReturn(expectedResponse);
248 MsoResponseWrapper response = msoBusinessLogic.createVolumeGroupInstance(msoRequest, serviceInstanceId, vnfInstanceId);
251 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
255 public void shouldProperlyCreateVfModuleInstanceWithProperParameters() {
256 MsoResponseWrapper expectedResponse = createOkResponse();
257 String serviceInstanceId = "testServiceInstanceTempId";
258 String vnfInstanceId = "testVnfInstanceTempId";
259 String partial_endpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
260 String vf_module_endpoint = partial_endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
261 vf_module_endpoint = vf_module_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
263 given(msoInterface.createVfModuleInstance(msoRequest, vf_module_endpoint)).willReturn(expectedResponse);
265 MsoResponseWrapper response = msoBusinessLogic.createVfModuleInstance(msoRequest, serviceInstanceId, vnfInstanceId);
268 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
272 public void shouldProperlyDeleteE2eSvcInstanceWithProperParameters() {
273 MsoResponseWrapper expectedResponse = createOkResponse();
274 String serviceInstanceId = "testDeleteE2eSvcInstanceTempId";
275 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE) + "/" + serviceInstanceId;
277 given(msoInterface.deleteE2eSvcInstance(msoRequest, endpoint)).willReturn(expectedResponse);
279 MsoResponseWrapper response = msoBusinessLogic.deleteE2eSvcInstance(msoRequest, serviceInstanceId);
282 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
286 public void shouldProperlyDeleteSvcInstanceWithProperParametersAndFalseFeatureFlag() {
288 String endpointTemplate = "/serviceInstances/v5/%s";
289 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
290 String svcEndpoint = String.format(endpointTemplate, serviceInstanceId);
291 RequestDetails requestDetails = new RequestDetails();
292 MsoResponseWrapper expectedResponse = createOkResponse();
293 given(msoInterface.deleteSvcInstance(requestDetails, svcEndpoint)).willReturn(expectedResponse);
294 given(featureManager.isActive(Features.FLAG_UNASSIGN_SERVICE)).willReturn(false);
297 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
298 .deleteSvcInstance(requestDetails, serviceInstanceId, "unAssignOrDeleteParams");
301 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
305 public void shouldProperlyDeleteSvcInstanceWithProperParametersAndTrueFeatureFlag() {
307 String endpointTemplate = "/serviceInstantiation/v5/serviceInstances/%s/unassign";
308 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
309 String svcEndpoint = String.format(endpointTemplate, serviceInstanceId);
310 RequestDetails requestDetails = new RequestDetails();
311 MsoResponseWrapper expectedResponse = createOkResponse();
312 given(msoInterface.unassignSvcInstance(requestDetails, svcEndpoint)).willReturn(expectedResponse);
313 given(featureManager.isActive(Features.FLAG_UNASSIGN_SERVICE)).willReturn(true);
316 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
317 .deleteSvcInstance(requestDetails, serviceInstanceId, "assigned");
320 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
324 public void shouldProperlyDeleteVnfWithProperParameters() {
326 String endpointTemplate = "/serviceInstances/v5/%s/vnfs/%s";
327 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
328 String vnfInstanceId = "testVnfInstanceTempId";
329 String vnfEndpoint = String.format(endpointTemplate, serviceInstanceId, vnfInstanceId);
330 RequestDetails requestDetails = new RequestDetails();
331 MsoResponseWrapper expectedResponse = createOkResponse();
332 given(msoInterface.deleteVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
335 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
336 .deleteVnf(requestDetails, serviceInstanceId, vnfInstanceId);
339 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
343 public void shouldProperlyDeleteVfModuleWithProperParameters() {
345 String endpointTemplate = "/serviceInstances/v7/%s/vnfs/%s/vfModules/%s";
346 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
347 String vnfInstanceId = "testVnfInstanceTempId";
348 String vfModuleId = "testVfModuleId";
349 String vnfEndpoint = String.format(endpointTemplate, serviceInstanceId, vnfInstanceId, vfModuleId);
350 RequestDetails requestDetails = new RequestDetails();
351 MsoResponseWrapper expectedResponse = createOkResponse();
352 given(msoInterface.deleteVfModule(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
355 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
356 .deleteVfModule(requestDetails, serviceInstanceId, vnfInstanceId, vfModuleId);
358 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
362 public void shouldProperlyDeleteVolumeGroupInstanceWithProperParameters() {
363 MsoResponseWrapper expectedResponse = createOkResponse();
364 String serviceInstanceId = "testServiceInstanceTempId";
365 String vnfInstanceId = "testVnfInstanceTempId";
366 String volumeGroupId = "testvolumeGroupIdTempId";
368 String deleteVolumeGroupEndpoint = getDeleteVolumeGroupEndpoint(serviceInstanceId, vnfInstanceId, volumeGroupId);
370 given(msoInterface.deleteVolumeGroupInstance(msoRequest, deleteVolumeGroupEndpoint)).willReturn(expectedResponse);
372 MsoResponseWrapper response = msoBusinessLogic.deleteVolumeGroupInstance(msoRequest, serviceInstanceId, vnfInstanceId, volumeGroupId);
375 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
379 private String getDeleteVolumeGroupEndpoint(String serviceInstanceId, String vnfInstanceId, String volumeGroupId) {
380 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
381 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
382 String vnfEndpoint = svc_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
383 return vnfEndpoint + "/" + volumeGroupId;
387 public void shouldProperlyDeleteNwInstanceWithProperParameters() {
388 MsoResponseWrapper expectedResponse = createOkResponse();
389 String serviceInstanceId = "testServiceInstanceTempId";
390 String networkInstanceId = "testNetworkInstanceTempId";
392 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
393 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
394 String delete_nw_endpoint = svc_endpoint + "/" + networkInstanceId;
396 given(msoInterface.deleteNwInstance(msoRequest, delete_nw_endpoint)).willReturn(expectedResponse);
398 MsoResponseWrapper response = msoBusinessLogic.deleteNwInstance(msoRequest, serviceInstanceId, networkInstanceId);
401 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
405 public void shouldProperlyGetOrchestrationRequestWithProperParameters() {
406 MsoResponseWrapper expectedResponse = createOkResponse();
407 String requestId = "testRequestTempId";
408 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
409 String path = p + "/" + requestId;
411 given(msoInterface.getOrchestrationRequest(path)).willReturn(expectedResponse);
413 MsoResponseWrapper response = msoBusinessLogic.getOrchestrationRequest(requestId);
414 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
417 @Test(expectedExceptions = MsoTestException.class)
418 public void shouldProperlyGetOrchestrationRequestWithWrongParameters() {
419 String requestId = "testWrongRequestTempId";
420 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
421 String path = p + "/" + requestId;
423 given(msoInterface.getOrchestrationRequest(path)).willThrow(new MsoTestException("testException"));
425 msoBusinessLogic.getOrchestrationRequest(requestId);
429 public void shouldProperlyGetOrchestrationRequestsWithProperParameters() {
430 MsoResponseWrapper expectedResponse = createOkResponse();
431 String filterString = "testRequestsTempId";
432 String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
433 String path = url + filterString;
435 given(msoInterface.getOrchestrationRequest(path)).willReturn(expectedResponse);
437 MsoResponseWrapper response = msoBusinessLogic.getOrchestrationRequests(filterString);
438 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
441 @Test(expectedExceptions = MsoTestException.class)
442 public void shouldThrowExceptionWhenGetOrchestrationRequestsWithWrongParameters() {
443 String filterString = "testRequestsTempId";
444 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
445 String path = p + filterString;
447 given(msoInterface.getOrchestrationRequest(path)).willThrow(new MsoTestException("testException"));
449 msoBusinessLogic.getOrchestrationRequests(filterString);
453 public void shouldSendProperScaleOutRequest() throws IOException {
455 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
456 String vnfInstanceId = "testVnfInstanceTempId";
457 String endpointTemplate = "/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s/vfModules/scaleOut";
458 String vnfEndpoint = String.format(endpointTemplate, serviceInstanceId, vnfInstanceId);
459 org.onap.vid.changeManagement.RequestDetails requestDetails = readRequest();
460 org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails> expectedRequest = readExpectedRequest();
461 MsoResponseWrapper expectedMsoResponseWrapper = createOkResponse();
464 .scaleOutVFModuleInstance(argThat(new MsoRequestWrapperMatcher(expectedRequest)),
466 .willReturn(expectedMsoResponseWrapper);
469 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
470 .scaleOutVfModuleInstance(requestDetails, serviceInstanceId, vnfInstanceId);
473 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedMsoResponseWrapper);
476 private org.onap.vid.changeManagement.RequestDetails readRequest() throws IOException {
477 Path path = Paths.get("payload_jsons", "scaleOutVfModulePayload.json");
478 URL url = this.getClass().getClassLoader().getResource(path.toString());
479 return objectMapper.readValue(url, org.onap.vid.changeManagement.RequestDetails.class);
482 private org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails> readExpectedRequest()
484 Path path = Paths.get("payload_jsons", "scaleOutVfModulePayloadToMso.json");
485 URL url = this.getClass().getClassLoader().getResource(path.toString());
486 return objectMapper.readValue(url,
487 new TypeReference<org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails>>() {
493 public void shouldFilterOutOrchestrationRequestsNotAllowedInDashboard() throws Exception {
495 String vnfModelTypeOrchestrationRequests = getFileContentAsString("mso_model_info_sample_response.json");
496 String scaleOutActionOrchestrationRequests = getFileContentAsString("mso_action_scaleout_sample_response.json");
498 MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
500 .getOrchestrationRequest(any(String.class), any(String.class), any(String.class),
501 any(RestObject.class), anyBoolean()))
502 .willReturn(msoResponseWrapperMock);
503 given(msoResponseWrapperMock.getEntity())
504 .willReturn(vnfModelTypeOrchestrationRequests, scaleOutActionOrchestrationRequests);
507 List<Request> filteredOrchestrationReqs = msoBusinessLogic.getOrchestrationRequestsForDashboard();
509 assertThat(filteredOrchestrationReqs).hasSize(3);
510 assertThat(MsoBusinessLogicImpl.DASHBOARD_ALLOWED_TYPES)
511 .containsAll(filteredOrchestrationReqs
513 .map(el -> el.getRequestType().toUpperCase())
514 .collect(Collectors.toList()));
515 assertThat(filteredOrchestrationReqs)
516 .extracting(Request::getRequestScope)
517 .containsOnly("vnf", "vfModule");
520 @Test(expectedExceptions = GenericUncheckedException.class)
521 public void shouldThrowGenericUncheckedExceptionWhenGetOrchestrationRequestsForDashboardWithWrongJsonFile_() throws Exception {
523 String vnfModelTypeOrchestrationRequests = getFileContentAsString("mso_model_info_sample_wrong_response.json");
525 MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
527 .getOrchestrationRequest(any(String.class), any(String.class), any(String.class),
528 any(RestObject.class), anyBoolean()))
529 .willReturn(msoResponseWrapperMock);
530 given(msoResponseWrapperMock.getEntity())
531 .willReturn(vnfModelTypeOrchestrationRequests);
534 msoBusinessLogic.getOrchestrationRequestsForDashboard();
538 public void shouldProperlyGetManualTasksByRequestIdWithProperParameters() throws Exception {
540 String manualTasksList = getFileContentAsString("manual_tasks_by_requestId_test.json");
542 MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
544 .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
545 any(RestObject.class)))
546 .willReturn(msoResponseWrapperMock);
547 given(msoResponseWrapperMock.getEntity())
548 .willReturn(manualTasksList);
551 List<Task> filteredOrchestrationReqs = msoBusinessLogic.getManualTasksByRequestId("TestId");
554 assertThat(filteredOrchestrationReqs).hasSize(2);
555 assertThat(filteredOrchestrationReqs).extracting("taskId", "type").
557 tuple("123123abc", "testTask"),
558 tuple("321321abc", "testTask")
562 @Test(expectedExceptions = GenericUncheckedException.class)
563 public void shouldThrowGenericUncheckedExceptionWhenGetManualTasksByRequestIdWithWrongJsonFile() throws Exception {
565 String manualTasksList = getFileContentAsString("manual_tasks_by_requestId_wrongJson_test.json");
567 MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
569 .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
570 any(RestObject.class)))
571 .willReturn(msoResponseWrapperMock);
572 given(msoResponseWrapperMock.getEntity())
573 .willReturn(manualTasksList);
576 msoBusinessLogic.getManualTasksByRequestId("TestId");
579 @Test(expectedExceptions = MsoTestException.class)
580 public void getManualTasksByRequestIdWithArgument_shouldThrowException() {
583 .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
584 any(RestObject.class)))
585 .willThrow(MsoTestException.class);
588 msoBusinessLogic.getManualTasksByRequestId("TestId");
592 public void shouldProperlyCompleteManualTaskWithProperParameters() {
594 MsoResponseWrapper expectedResponse = createOkResponse();
595 RequestDetails requestDetails = new RequestDetails();
596 String taskId = "testTaskId";
598 String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
599 String path = url + "/" + taskId + "/complete";
601 given(msoInterface.completeManualTask(eq(requestDetails), any(String.class), any(String.class), eq(path), any(RestObject.class))).willReturn(expectedResponse);
604 MsoResponseWrapper response = msoBusinessLogic.completeManualTask(requestDetails, taskId);
607 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
612 public void shouldProperlyActivateServiceInstanceWithProperParameters() {
614 RequestDetails detail = new RequestDetails();
615 String taskId = "testTaskId";
617 RestObject<String> restObjStr = new RestObject<>();
619 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
622 MsoResponseWrapper response = msoBusinessLogic.activateServiceInstance(detail, taskId);
625 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
629 @Test(expectedExceptions = MsoTestException.class)
630 public void shouldThrowExceptionWhenManualTaskWithWrongParameters() {
632 RequestDetails requestDetails = new RequestDetails();
635 String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
636 String path = url + "/" + taskId + "/complete";
638 given(msoInterface.completeManualTask(eq(requestDetails), any(String.class), any(String.class), eq(path), any(RestObject.class))).willThrow(new MsoTestException("empty path"));
641 msoBusinessLogic.completeManualTask(requestDetails, taskId);
645 public void shouldProperlyUpdateVnfWithProperParameters() {
647 MsoResponseWrapper expectedResponse = createOkResponse();
648 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
650 String serviceInstanceId = "testServiceId";
651 String vnfInstanceId = "testVnfInstanceId";
653 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
654 String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
655 vnfEndpoint = vnfEndpoint + '/' + vnfInstanceId;
657 given(msoInterface.updateVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
660 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnf(requestDetails, serviceInstanceId, vnfInstanceId);
663 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
667 public void shouldProperlyReplaceVnfWithProperParameters() {
669 MsoResponseWrapper expectedResponse = createOkResponse();
670 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
672 String serviceInstanceId = "testServiceId";
673 String vnfInstanceId = "testVnfInstanceId";
675 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE);
676 String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
677 vnfEndpoint = vnfEndpoint.replace(VNF_INSTANCE_ID, vnfInstanceId);
678 vnfEndpoint = vnfEndpoint.replace(REQUEST_TYPE, ChangeManagementRequest.MsoChangeManagementRequest.REPLACE);
680 given(msoInterface.replaceVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
683 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.replaceVnf(requestDetails, serviceInstanceId, vnfInstanceId);
686 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
690 public void shouldProperlyGenerateInPlaceMsoRequestWithProperParameters() {
692 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
694 requestDetails.setVnfInstanceId("testVnfInstanceId");
695 requestDetails.setVnfName("testVnfName");
696 requestDetails.setRequestParameters(new RequestParameters());
698 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
699 "\"existing_software_version\": \"testExistingSoftwareParam\"," +
700 "\"new_software_version\": \"testNewSoftwareParam\"," +
701 "\"operations_timeout\": \"100\"" +
704 RequestDetails inPlaceSoftwareUpdateRequest = new RequestDetails();
705 inPlaceSoftwareUpdateRequest.setCloudConfiguration(requestDetails.getCloudConfiguration());
706 inPlaceSoftwareUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
707 inPlaceSoftwareUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
708 org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.changeManagement.RequestDetailsWrapper();
709 requestDetailsWrapper.requestDetails = inPlaceSoftwareUpdateRequest;
712 org.onap.vid.changeManagement.RequestDetailsWrapper response = msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
715 assertThat(response).isEqualToComparingFieldByField(requestDetailsWrapper);
718 @Test(expectedExceptions = BadRequestException.class)
719 public void shouldThrowExceptionWhenGenerateInPlaceMsoRequestWithParametersWithWrongCharacters() {
721 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
723 requestDetails.setVnfInstanceId("testVnfInstanceId");
724 requestDetails.setVnfName("testVnfName");
725 requestDetails.setRequestParameters(new RequestParameters());
727 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
728 "\"existing_software_version\": \"#####\"," +
729 "\"new_software_version\": \"testNewSoftwareParam\"" +
733 msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
736 @Test(expectedExceptions = BadRequestException.class)
737 public void shouldThrowExceptionWhenGenerateInPlaceMsoRequestWithWrongParameters() {
739 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
741 requestDetails.setVnfInstanceId("testVnfInstanceId");
742 requestDetails.setVnfName("testVnfName");
743 requestDetails.setRequestParameters(new RequestParameters());
745 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
746 "\"test-wrong-parameter\": \"testParam\"," +
747 "\"new_software_version\": \"testNewSoftwareParam\"" +
751 msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
755 public void shouldProprleyGenerateConfigMsoRequestWithProperParameters() {
757 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
759 requestDetails.setVnfInstanceId("testVnfInstanceId");
760 requestDetails.setVnfName("testVnfName");
761 requestDetails.setRequestParameters(new RequestParameters());
763 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
764 "\"request-parameters\": \"testRequestParam\"," +
765 "\"configuration-parameters\": \"testConfigParams\"" +
768 RequestDetails configUpdateRequest = new RequestDetails();
769 configUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
770 configUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
772 org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.changeManagement.RequestDetailsWrapper();
773 requestDetailsWrapper.requestDetails = configUpdateRequest;
776 org.onap.vid.changeManagement.RequestDetailsWrapper response = msoBusinessLogic.generateConfigMsoRequest(requestDetails);
779 assertThat(response).isEqualToComparingFieldByField(requestDetailsWrapper);
782 @Test(expectedExceptions = BadRequestException.class)
783 public void shouldThrowExceptionGenerateConfigMsoRequestWithoutAdditionalParameters() {
785 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
787 requestDetails.setVnfInstanceId("testVnfInstanceId");
788 requestDetails.setVnfName("testVnfName");
789 requestDetails.setRequestParameters(null);
792 msoBusinessLogic.generateConfigMsoRequest(requestDetails);
795 @Test(expectedExceptions = BadRequestException.class)
796 public void shouldThrowExceptionWhenGenerateConfigMsoRequestWithWrongPayload() {
798 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
800 requestDetails.setVnfInstanceId("testVnfInstanceId");
801 requestDetails.setVnfName("testVnfName");
802 requestDetails.setRequestParameters(new RequestParameters());
804 requestDetails.getRequestParameters().setAdditionalProperty("payload", null);
807 msoBusinessLogic.generateConfigMsoRequest(requestDetails);
810 @Test(expectedExceptions = BadRequestException.class)
811 public void shouldThrowExceptionGenerateConfigMsoRequestWithoutAnyParameter() {
813 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
815 requestDetails.setVnfInstanceId("testVnfInstanceId");
816 requestDetails.setVnfName("testVnfName");
817 requestDetails.setRequestParameters(new RequestParameters());
819 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
820 "\"test-wrong-parameter\": \"testParam\"," +
821 "\"configuration-parameters\": \"testConfigParam\"" +
825 msoBusinessLogic.generateConfigMsoRequest(requestDetails);
829 public void shouldProperlyGetActivateFabricConfigurationPathWithProperParameters() {
831 String serviceInstanceId = "testServiceId";
832 String path = validateEndpointPath(MsoProperties.MSO_REST_API_SERVICE_INSTANCE_CREATE);
833 path += "/" + serviceInstanceId + "/activateFabricConfiguration";
836 String response = msoBusinessLogic.getActivateFabricConfigurationPath(serviceInstanceId);
839 assertThat(response).isEqualTo(path);
843 public void shouldProperlyGetDeactivateAndCloudDeletePathWithProperParameters() {
845 String serviceInstanceId = "testServiceId";
846 String vnfInstanceId = "testVnfInstanceId";
847 String vfModuleInstanceId = "testVfModuleInstanceId";
848 String path = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
849 path = path.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
850 path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
851 path += "/" + vfModuleInstanceId + "/deactivateAndCloudDelete";
854 String response = msoBusinessLogic.getDeactivateAndCloudDeletePath(serviceInstanceId, vnfInstanceId, vfModuleInstanceId);
857 assertThat(response).isEqualTo(path);
861 public void shouldProperlyBuildRequestDetailsForSoftDeleteWithProperParameters() {
863 SoftDeleteRequest softDeleteRequest = new SoftDeleteRequest();
864 RequestDetails requestDetails = new RequestDetails();
866 String userId = "testUserID";
867 String tenantId = "testTenantId ";
868 String cloudRegionId = "testCloudId";
871 RequestInfo requestInfo = new RequestInfo();
872 requestInfo.setSource("VID");
873 requestInfo.setRequestorId(userId);
874 requestDetails.setRequestInfo(requestInfo);
876 CloudConfiguration cloudConfiguration = new CloudConfiguration();
877 cloudConfiguration.setTenantId(tenantId);
878 cloudConfiguration.setLcpCloudRegionId(cloudRegionId);
879 requestDetails.setCloudConfiguration(cloudConfiguration);
881 setModelInfoForRequestDetails(requestDetails);
883 setRequestParametersForRequestDetails(requestDetails);
885 softDeleteRequest.setLcpCloudRegionId(cloudRegionId);
886 softDeleteRequest.setTenantId(tenantId);
887 softDeleteRequest.setUserId(userId);
890 RequestDetails response = msoBusinessLogic.buildRequestDetailsForSoftDelete(softDeleteRequest);
893 assertThat(response).isEqualTo(requestDetails);
896 private void setRequestParametersForRequestDetails(RequestDetails requestDetails) {
897 RequestParameters requestParameters = new RequestParameters();
898 requestParameters.setTestApi("GR_API");
899 requestDetails.setRequestParameters(requestParameters);
902 private void setModelInfoForRequestDetails(RequestDetails requestDetails) {
903 ModelInfo modelInfo = new ModelInfo();
904 modelInfo.setModelType("vfModule");
905 requestDetails.setModelInfo(modelInfo);
909 public void shouldProperlyDeactivateAndCloudDeleteWithProperParameters() {
911 String serviceInstanceId = "testServiceId";
912 String vnfInstanceId = "testVnfInstanceId";
913 String vfModuleInstanceId = "testVfModuleInstanceId";
914 RequestDetails requestDetails = new RequestDetails();
916 String path = msoBusinessLogic.getDeactivateAndCloudDeletePath(serviceInstanceId, vnfInstanceId, vfModuleInstanceId);
918 RequestReferences requestReferences = new RequestReferences();
919 requestReferences.setInstanceId("testInstance");
920 requestReferences.setRequestId("testRequest");
922 HttpResponse<RequestReferencesContainer> expectedResponse = HttpResponse.fallback(new RequestReferencesContainer(requestReferences));
924 MsoResponseWrapper2 responseWrapped = new MsoResponseWrapper2<>(expectedResponse);
926 given(msoInterface.post(eq(path), any(org.onap.vid.changeManagement.RequestDetailsWrapper.class), eq(RequestReferencesContainer.class))).willReturn(expectedResponse);
929 MsoResponseWrapper2 response = msoBusinessLogic.deactivateAndCloudDelete(serviceInstanceId, vnfInstanceId, vfModuleInstanceId, requestDetails);
932 assertThat(response).isEqualToComparingFieldByField(responseWrapped);
936 public void shouldProperlyActivateFabricConfigurationWithProperParameters() {
938 String serviceInstanceId = "testServiceId";
939 RequestDetails requestDetails = new RequestDetails();
941 String path = msoBusinessLogic.getActivateFabricConfigurationPath(serviceInstanceId);
943 RequestReferences requestReferences = new RequestReferences();
944 requestReferences.setInstanceId("testInstance");
945 requestReferences.setRequestId("testRequest");
947 HttpResponse<RequestReferencesContainer> expectedResponse = HttpResponse.fallback(new RequestReferencesContainer(requestReferences));
949 MsoResponseWrapper2 responseWrapped = new MsoResponseWrapper2<>(expectedResponse);
951 given(msoInterface.post(eq(path), any(org.onap.vid.changeManagement.RequestDetailsWrapper.class), eq(RequestReferencesContainer.class))).willReturn(expectedResponse);
954 MsoResponseWrapper2 response = msoBusinessLogic.activateFabricConfiguration(serviceInstanceId, requestDetails);
957 assertThat(response).isEqualToComparingFieldByField(responseWrapped);
961 public void shouldProperlyUpdateVnfSoftwareWithProperParameters() {
963 String serviceInstanceId = "testServiceId";
964 String vnfInstanceId = "testVnfInstanceId";
966 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
968 requestDetails.setVnfInstanceId("testVnfInstanceId");
969 requestDetails.setVnfName("testVnfName");
970 requestDetails.setRequestParameters(new RequestParameters());
972 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
973 "\"existing_software_version\": \"testExistingSoftwareParam\"," +
974 "\"new_software_version\": \"testNewSoftwareParam\"," +
975 "\"operations_timeout\": \"100\"" +
978 MsoResponseWrapper okResponse = createOkResponse();
980 given(msoInterface.changeManagementUpdate(isA(org.onap.vid.changeManagement.RequestDetailsWrapper.class), any(String.class))).willReturn(okResponse);
983 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnfSoftware(requestDetails, serviceInstanceId, vnfInstanceId);
986 assertThat(response).isEqualToComparingFieldByField(okResponse);
990 public void shouldProperlyUpdateVnfConfigWithProperParameters() {
992 String serviceInstanceId = "testServiceId";
993 String vnfInstanceId = "testVnfInstanceId";
995 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
997 requestDetails.setVnfInstanceId("testVnfInstanceId");
998 requestDetails.setVnfName("testVnfName");
999 requestDetails.setRequestParameters(new RequestParameters());
1001 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
1002 "\"request-parameters\": \"testRequestParam\"," +
1003 "\"configuration-parameters\": \"testConfigParams\"" +
1006 MsoResponseWrapper okResponse = createOkResponse();
1008 given(msoInterface.changeManagementUpdate(isA(org.onap.vid.changeManagement.RequestDetailsWrapper.class), any(String.class))).willReturn(okResponse);
1011 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnfConfig(requestDetails, serviceInstanceId, vnfInstanceId);
1014 assertThat(response).isEqualToComparingFieldByField(okResponse);
1018 public void shouldProperlyDeleteConfigurationWithProperParameters() {
1020 String serviceInstanceId = "testServiceId";
1021 String configurationId = "testConfigurationId";
1023 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1025 requestDetails.setVnfInstanceId("testVnfInstanceId");
1026 requestDetails.setVnfName("testVnfName");
1028 MsoResponseWrapper okResponse = createOkResponse();
1029 RequestDetailsWrapper wrappedRequestDetail = new RequestDetailsWrapper(requestDetails);
1031 given(msoInterface.deleteConfiguration(eq(wrappedRequestDetail), any(String.class))).willReturn(okResponse);
1034 MsoResponseWrapper response = msoBusinessLogic.deleteConfiguration(wrappedRequestDetail, serviceInstanceId, configurationId);
1037 assertThat(response).isEqualToComparingFieldByField(okResponse);
1041 public void shouldProperlySetConfigurationActiveStatusActiveWithProperParameters() {
1043 String serviceInstanceId = "testServiceId";
1044 String configurationId = "testConfigurationId";
1046 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1048 requestDetails.setVnfInstanceId("testVnfInstanceId");
1049 requestDetails.setVnfName("testVnfName");
1051 MsoResponseWrapper okResponse = createOkResponse();
1054 validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1055 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1056 .replace(CONFIGURATION_ID, configurationId)
1059 given(msoInterface.setConfigurationActiveStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1062 MsoResponseWrapper response = msoBusinessLogic.setConfigurationActiveStatus(requestDetails, serviceInstanceId, configurationId, true);
1065 assertThat(response).isEqualToComparingFieldByField(okResponse);
1069 public void shouldProperlySetConfigurationActiveStatusDeactivateWithProperParameters() {
1071 String serviceInstanceId = "testServiceId";
1072 String configurationId = "testConfigurationId";
1074 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1076 requestDetails.setVnfInstanceId("testVnfInstanceId");
1077 requestDetails.setVnfName("testVnfName");
1079 MsoResponseWrapper okResponse = createOkResponse();
1082 validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1083 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1084 .replace(CONFIGURATION_ID, configurationId)
1087 given(msoInterface.setConfigurationActiveStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1090 MsoResponseWrapper response = msoBusinessLogic.setConfigurationActiveStatus(requestDetails, serviceInstanceId, configurationId, false);
1093 assertThat(response).isEqualToComparingFieldByField(okResponse);
1097 public void shouldProperlySetServiceInstanceStatusActiveWithProperParameters() {
1099 String serviceInstanceId = "testServiceId";
1100 MsoResponseWrapper okResponse = createOkResponse();
1102 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1104 given(msoInterface.setServiceInstanceStatus(eq(requestDetails), endsWith(serviceInstanceId + "/activate"))).willReturn(okResponse);
1107 MsoResponseWrapper response = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, true);
1110 assertThat(response).isEqualToComparingFieldByField(okResponse);
1114 public void shouldProperlySetServiceInstanceStatusDeactivateWithProperParameters() {
1116 String serviceInstanceId = "testServiceId";
1117 MsoResponseWrapper okResponse = createOkResponse();
1119 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1121 given(msoInterface.setServiceInstanceStatus(eq(requestDetails), endsWith(serviceInstanceId + "/deactivate"))).willReturn(okResponse);
1124 MsoResponseWrapper response = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, false);
1127 assertThat(response).isEqualToComparingFieldByField(okResponse);
1130 @Test(expectedExceptions = MsoTestException.class)
1131 public void shouldThrowExceptionWhenSetServiceInstanceStatusWithWrongParameters() {
1133 String serviceInstanceId = "testServiceId";
1135 doThrow(new MsoTestException("testException")).
1136 when(msoInterface).setServiceInstanceStatus(eq(null), any(String.class));
1139 msoBusinessLogic.setServiceInstanceStatus(null, serviceInstanceId, true);
1143 public void shouldProperlySetPortOnConfigurationStatusEnableWithProperParameters() {
1145 String serviceInstanceId = "testServiceId";
1146 String configurationId = "testConfigurationId";
1147 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1148 requestDetails.setVnfInstanceId("testVnfInstanceId");
1149 requestDetails.setVnfName("testVnfName");
1150 MsoResponseWrapper okResponse = createOkResponse();
1152 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1153 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1154 .replace(CONFIGURATION_ID, configurationId)
1157 given(msoInterface.setPortOnConfigurationStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1160 MsoResponseWrapper response = msoBusinessLogic.setPortOnConfigurationStatus(requestDetails, serviceInstanceId, configurationId, true);
1163 assertThat(response).isEqualToComparingFieldByField(okResponse);
1167 public void shouldProperlySetPortOnConfigurationStatusDisableWithProperParameters() {
1169 String serviceInstanceId = "testServiceId";
1170 String configurationId = "testConfigurationId";
1171 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1172 requestDetails.setVnfInstanceId("testVnfInstanceId");
1173 requestDetails.setVnfName("testVnfName");
1174 MsoResponseWrapper okResponse = createOkResponse();
1176 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1177 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1178 .replace(CONFIGURATION_ID, configurationId)
1181 given(msoInterface.setPortOnConfigurationStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1184 MsoResponseWrapper response = msoBusinessLogic.setPortOnConfigurationStatus(requestDetails, serviceInstanceId, configurationId, false);
1187 assertThat(response).isEqualToComparingFieldByField(okResponse);
1191 public void shouldProperlyCreateOperationalEnvironmentActivationRequestDetailsWithProperParameters() {
1193 OperationalEnvironmentActivateInfo details = createTestOperationalEnvironmentActivateInfo();
1195 org.onap.vid.changeManagement.RequestDetailsWrapper<RequestDetails> requestDetails = msoBusinessLogic.createOperationalEnvironmentActivationRequestDetails(details);
1198 assertThat(requestDetails.requestDetails.getRequestParameters().getAdditionalProperties().values()).contains(details.getWorkloadContext(), details.getManifest());
1199 assertThat(requestDetails.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
1203 public void shouldProperlyGetOperationalEnvironmentActivationPathWithProperParameters() {
1205 OperationalEnvironmentActivateInfo details = createTestOperationalEnvironmentActivateInfo();
1208 String response = msoBusinessLogic.getOperationalEnvironmentActivationPath(details);
1211 assertThat(response).contains(operationalEnvironmentId);
1215 public void shouldProperlyCreateOperationalEnvironmentDeactivationRequestDetailsWithProperParameters() {
1217 OperationalEnvironmentDeactivateInfo details = createTestOperationalEnvironmentDeactivateInfo();
1220 org.onap.vid.changeManagement.RequestDetailsWrapper<RequestDetails> response;
1221 response = msoBusinessLogic.createOperationalEnvironmentDeactivationRequestDetails(details);
1224 assertThat(response.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
1228 public void shouldProperlyGetCloudResourcesRequestsStatusPathWithProperParameters() {
1230 String requestId = "testRequestId";
1233 String response = msoBusinessLogic.getCloudResourcesRequestsStatusPath(requestId);
1236 assertThat(response).contains(requestId);
1240 public void shouldProperlyGetOperationalEnvironmentDeactivationPathWithProperParameters() {
1242 OperationalEnvironmentDeactivateInfo details = createTestOperationalEnvironmentDeactivateInfo();
1245 String response = msoBusinessLogic.getOperationalEnvironmentDeactivationPath(details);
1248 assertThat(response).contains(operationalEnvironmentId);
1252 public void shouldProperlyGetOperationalEnvironmentCreationPathWithProperParameters() {
1254 String response = msoBusinessLogic.getOperationalEnvironmentCreationPath();
1257 assertThat(response).isNotBlank();
1261 public void shouldProperlyConvertParametersToRequestDetailsWithProperParameters() {
1263 OperationalEnvironmentController.OperationalEnvironmentCreateBody input = createTestOperationalEnvironmentCreateBody();
1266 org.onap.vid.changeManagement.RequestDetailsWrapper<OperationEnvironmentRequestDetails> response
1267 = msoBusinessLogic.convertParametersToRequestDetails(input, userId);
1270 assertThat(response.requestDetails.getRequestInfo().getInstanceName()).isEqualTo(input.getInstanceName());
1271 assertThat(response.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
1272 assertThat(response.requestDetails.getRequestParameters().getOperationalEnvironmentType()).isEqualTo(input.getOperationalEnvironmentType());
1273 assertThat(response.requestDetails.getRequestParameters().getTenantContext()).isEqualTo(input.getTenantContext());
1274 assertThat(response.requestDetails.getRequestParameters().getWorkloadContext()).isEqualTo(input.getWorkloadContext());
1278 public void shouldProperlyRemoveRelationshipFromServiceInstanceWithProperParameters() {
1280 MsoResponseWrapper expectedResponse = createOkResponse();
1281 String serviceInstanceId = "testServiceId";
1282 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1284 given(msoInterface.removeRelationshipFromServiceInstance(eq(requestDetails), endsWith("/" + serviceInstanceId + "/removeRelationships")))
1285 .willReturn(expectedResponse);
1288 MsoResponseWrapper response = msoBusinessLogic.removeRelationshipFromServiceInstance(requestDetails, serviceInstanceId);
1291 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
1295 public void shouldProperlyAddRelationshipToServiceInstanceWithProperParameters() {
1297 MsoResponseWrapper expectedResponse = createOkResponse();
1298 String serviceInstanceId = "testServiceId";
1299 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1301 given(msoInterface.addRelationshipToServiceInstance(eq(requestDetails), endsWith("/" + serviceInstanceId + "/addRelationships")))
1302 .willReturn(expectedResponse);
1305 MsoResponseWrapper response = msoBusinessLogic.addRelationshipToServiceInstance(requestDetails, serviceInstanceId);
1308 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
1312 public void shouldProperlyRequestTypeFromValueWithValidParameters() {
1314 String testValue = "createInstance";
1316 MsoBusinessLogicImpl.RequestType response = MsoBusinessLogicImpl.RequestType.fromValue(testValue);
1319 assertThat(response.toString()).isEqualTo(testValue);
1322 @Test(expectedExceptions = IllegalArgumentException.class)
1323 public void shouldThrowExceptionWhenRequestTypeFromValueWithWrongParameter() {
1325 String testValue = "notExistingParameter";
1327 MsoBusinessLogicImpl.RequestType.fromValue(testValue);
1331 public void shouldProperlyInvokeVnfWorkflowWithValidParameters() {
1333 MsoResponseWrapper okResponse = createOkResponse();
1334 WorkflowRequestDetail request = createWorkflowRequestDetail();
1335 UUID serviceInstanceId = new UUID(1,10);
1336 UUID vnfInstanceId = new UUID(2,20);
1337 UUID workflow_UUID = new UUID(3,30);
1338 String path = "/instanceManagement/v1/serviceInstances/"+serviceInstanceId+"/vnfs/"+vnfInstanceId+"/workflows/"+workflow_UUID;
1340 given(msoInterface.invokeWorkflow(eq(request), eq(path), MockitoHamcrest.argThat(allOf(hasEntry("X-RequestorID", "testRequester"),hasEntry("X-ONAP-PartnerName", "VID"))))).willReturn(okResponse);
1343 MsoResponseWrapper response = msoBusinessLogic.invokeVnfWorkflow(request, "testRequester", serviceInstanceId, vnfInstanceId, workflow_UUID);
1346 assertThat(response).isEqualToComparingFieldByField(okResponse);
1351 public void shouldReturnWorkflowListForGivenModelId() {
1352 given(msoInterface.getWorkflowListByModelId(anyString())).willReturn(workflowListResponse);
1353 given(workflowListResponse.getBody()).willReturn(workflowList);
1354 given(workflowListResponse.getStatus()).willReturn(HttpStatus.ACCEPTED.value());
1356 SOWorkflowList workflows = msoBusinessLogic.getWorkflowListByModelId("sampleModelId");
1358 assertThat(workflows).isEqualTo(workflowList);
1361 @Test(expectedExceptions = {MsoBusinessLogicImpl.WorkflowListException.class})
1362 public void shouldRaiseExceptionWhenRetrievingWorkflowsFailed() {
1363 given(msoInterface.getWorkflowListByModelId(anyString())).willReturn(workflowListResponse);
1364 given(workflowListResponse.getStatus()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR.value());
1366 msoBusinessLogic.getWorkflowListByModelId("sampleModelId");
1371 public void probeShouldReturnOrchestrationRequestsAndConnectionStatus(){
1372 MsoResponseWrapper wrapper = getMsoResponseWrapper();
1373 given(msoInterface.getOrchestrationRequest(anyString(),anyString(),
1374 anyString(),any(RestObject.class),anyBoolean())).willReturn(wrapper);
1376 ExternalComponentStatus externalComponentStatus = msoBusinessLogic.probeComponent();
1378 assertThat(externalComponentStatus.isAvailable()).isTrue();
1379 assertThat(externalComponentStatus.getComponent()).isEqualTo(ExternalComponentStatus.Component.MSO);
1383 private MsoResponseWrapper getMsoResponseWrapper() {
1384 MsoResponseWrapper wrapper=new MsoResponseWrapper();
1385 RequestWrapper requestWrapper = new RequestWrapper();
1386 requestWrapper.setRequest(new Request());
1387 RequestList requestList = new RequestList();
1388 List<RequestWrapper> response = Lists.newArrayList(requestWrapper);
1389 requestList.setRequestList(response);
1390 wrapper.setEntity(new Gson().toJson(requestList));
1394 private WorkflowRequestDetail createWorkflowRequestDetail() {
1395 WorkflowRequestDetail workflowRequestDetail = new WorkflowRequestDetail();
1396 org.onap.vid.changeManagement.RequestParameters requestParameters = new org.onap.vid.changeManagement.RequestParameters();
1397 HashMap<String,String> paramsMap = new HashMap<>();
1398 paramsMap.put("testKey1","testValue1");
1399 paramsMap.put("testKey2","testValue2");
1401 List<Map<String,String>> mapArray= new ArrayList<>();
1402 mapArray.add(paramsMap);
1403 requestParameters.setUserParams(mapArray);
1405 CloudConfiguration cloudConfiguration = new CloudConfiguration();
1406 cloudConfiguration.setCloudOwner("testOwne");
1407 cloudConfiguration.setTenantId("testId");
1408 cloudConfiguration.setLcpCloudRegionId("testLcpCloudId");
1410 workflowRequestDetail.setRequestParameters(requestParameters);
1411 workflowRequestDetail.setCloudConfiguration(cloudConfiguration);
1412 return workflowRequestDetail;
1415 private OperationalEnvironmentActivateInfo createTestOperationalEnvironmentActivateInfo() {
1416 OperationalEnvironmentController.OperationalEnvironmentActivateBody operationalEnvironmentActivateBody = new OperationalEnvironmentController.OperationalEnvironmentActivateBody(
1417 "testRelatedInstanceId",
1418 "testRelatedInstanceName",
1419 "testWorkloadContext",
1420 new OperationalEnvironmentController.OperationalEnvironmentManifest()
1422 return new OperationalEnvironmentActivateInfo(operationalEnvironmentActivateBody, userId, operationalEnvironmentId);
1425 private OperationalEnvironmentDeactivateInfo createTestOperationalEnvironmentDeactivateInfo() {
1426 return new OperationalEnvironmentDeactivateInfo(userId, operationalEnvironmentId);
1429 private OperationalEnvironmentController.OperationalEnvironmentCreateBody createTestOperationalEnvironmentCreateBody() {
1430 return new OperationalEnvironmentController.OperationalEnvironmentCreateBody(
1432 "testEcompInstanceId",
1433 "testEcompInstanceName",
1434 "testOperationalEnvironmentType",
1435 "testTenantContext",
1436 "testWorkloadContext"
1440 private MsoResponseWrapper createOkResponse() {
1441 HttpStatus expectedStatus = HttpStatus.ACCEPTED;
1442 String expectedBody = " \"body\": {\n" +
1443 " \"requestReferences\": {\n" +
1444 " \"instanceId\": \" 123456 \",\n" +
1445 " \"requestId\": \"b6dc9806-b094-42f7-9386-a48de8218ce8\"\n" +
1447 MsoResponseWrapper responseWrapper = new MsoResponseWrapper();
1448 responseWrapper.setEntity(expectedBody);
1449 responseWrapper.setStatus(expectedStatus.value());
1450 return responseWrapper;
1453 private String getFileContentAsString(String resourceName) throws Exception {
1454 Path path = Paths.get("payload_jsons", resourceName);
1455 URL url = this.getClass().getClassLoader().getResource(path.toString());
1458 result = IOUtils.toString(url.toURI(), "UTF-8");
1463 private static class MsoRequestWrapperMatcher implements
1464 ArgumentMatcher<org.onap.vid.changeManagement.RequestDetailsWrapper> {
1466 private final org.onap.vid.changeManagement.RequestDetailsWrapper expectedRequest;
1468 MsoRequestWrapperMatcher(org.onap.vid.changeManagement.RequestDetailsWrapper expectedRequest) {
1469 this.expectedRequest = expectedRequest;
1473 public boolean matches(org.onap.vid.changeManagement.RequestDetailsWrapper argument) {
1474 return expectedRequest.requestDetails.equals(argument.requestDetails);
1478 private class MsoTestException extends RuntimeException {
1479 MsoTestException(String testException) {
1480 super(testException);