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 static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
27 import static org.assertj.core.api.Assertions.tuple;
28 import static org.hamcrest.Matchers.allOf;
29 import static org.hamcrest.Matchers.containsString;
30 import static org.hamcrest.Matchers.equalTo;
31 import static org.hamcrest.Matchers.hasEntry;
32 import static org.hamcrest.Matchers.instanceOf;
33 import static org.hamcrest.Matchers.is;
34 import static org.hamcrest.Matchers.startsWith;
35 import static org.junit.Assert.assertEquals;
36 import static org.mockito.ArgumentMatchers.any;
37 import static org.mockito.ArgumentMatchers.anyBoolean;
38 import static org.mockito.ArgumentMatchers.anyString;
39 import static org.mockito.ArgumentMatchers.argThat;
40 import static org.mockito.ArgumentMatchers.endsWith;
41 import static org.mockito.ArgumentMatchers.eq;
42 import static org.mockito.ArgumentMatchers.isA;
43 import static org.mockito.BDDMockito.given;
44 import static org.mockito.Mockito.doThrow;
45 import static org.mockito.Mockito.mock;
46 import static org.mockito.Mockito.when;
47 import static org.onap.vid.controller.MsoController.CONFIGURATION_ID;
48 import static org.onap.vid.controller.MsoController.REQUEST_TYPE;
49 import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
50 import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
51 import static org.onap.vid.model.probes.ExternalComponentStatus.Component.MSO;
52 import static org.onap.vid.mso.MsoBusinessLogicImpl.validateEndpointPath;
54 import com.fasterxml.jackson.core.type.TypeReference;
55 import com.fasterxml.jackson.databind.ObjectMapper;
56 import io.joshworks.restclient.http.HttpResponse;
57 import java.io.IOException;
59 import java.nio.file.Path;
60 import java.nio.file.Paths;
61 import java.util.ArrayList;
62 import java.util.HashMap;
63 import java.util.List;
65 import java.util.UUID;
66 import java.util.stream.Collectors;
67 import javax.ws.rs.BadRequestException;
68 import org.apache.commons.io.IOUtils;
69 import org.apache.http.HttpException;
70 import org.hamcrest.Matcher;
71 import org.hamcrest.MatcherAssert;
72 import org.jetbrains.annotations.NotNull;
73 import org.mockito.ArgumentMatcher;
74 import org.mockito.Mock;
75 import org.mockito.MockitoAnnotations;
76 import org.mockito.hamcrest.MockitoHamcrest;
77 import org.onap.portalsdk.core.util.SystemProperties;
78 import org.onap.vid.aai.ExceptionWithRequestInfo;
79 import org.onap.vid.aai.HttpResponseWithRequestInfo;
80 import org.onap.vid.changeManagement.ChangeManagementRequest;
81 import org.onap.vid.changeManagement.WorkflowRequestDetail;
82 import org.onap.vid.controller.OperationalEnvironmentController;
83 import org.onap.vid.exceptions.GenericUncheckedException;
84 import org.onap.vid.model.SOWorkflowList;
85 import org.onap.vid.model.SoftDeleteRequest;
86 import org.onap.vid.model.probes.ErrorMetadata;
87 import org.onap.vid.model.probes.ExternalComponentStatus;
88 import org.onap.vid.model.probes.HttpRequestMetadata;
89 import org.onap.vid.mso.model.CloudConfiguration;
90 import org.onap.vid.mso.model.ModelInfo;
91 import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo;
92 import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo;
93 import org.onap.vid.mso.model.RequestParameters;
94 import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails;
95 import org.onap.vid.mso.rest.Request;
96 import org.onap.vid.mso.rest.RequestDetails;
97 import org.onap.vid.mso.rest.RequestDetailsWrapper;
98 import org.onap.vid.mso.rest.Task;
99 import org.onap.vid.testUtils.TestUtils;
100 import org.springframework.http.HttpMethod;
101 import org.springframework.http.HttpStatus;
102 import org.springframework.test.context.ContextConfiguration;
103 import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
104 import org.testng.annotations.BeforeClass;
105 import org.testng.annotations.DataProvider;
106 import org.testng.annotations.Test;
108 @ContextConfiguration(classes = {SystemProperties.class})
109 public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
111 private static final ObjectMapper objectMapper = new ObjectMapper();
112 private static final String MY_PRETTY_URL = "my pretty url";
115 private MsoInterface msoInterface;
118 private SOWorkflowList workflowList;
121 private HttpResponse<SOWorkflowList> workflowListResponse;
124 private RequestDetails msoRequest;
127 private MsoBusinessLogicImpl msoBusinessLogic;
128 private String userId = "testUserId";
129 private String operationalEnvironmentId = "testOperationalEnvironmentId";
132 public void setUp() {
133 MockitoAnnotations.initMocks(this);
134 msoBusinessLogic = new MsoBusinessLogicImpl(msoInterface);
138 public void shouldProperlyCreateConfigurationInstanceWithCorrectServiceInstanceId() throws Exception {
140 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
141 String endpointTemplate = String.format("/serviceInstantiation/v7/serviceInstances/%s/configurations", serviceInstanceId);
142 RequestDetailsWrapper requestDetailsWrapper = createRequestDetails();
143 MsoResponseWrapper expectedResponse = createOkResponse();
144 given(msoInterface.createConfigurationInstance(requestDetailsWrapper, endpointTemplate))
145 .willReturn(expectedResponse);
148 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
149 .createConfigurationInstance(requestDetailsWrapper, serviceInstanceId);
152 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
155 private RequestDetailsWrapper createRequestDetails() throws Exception {
156 final URL resource = this.getClass().getResource("/payload_jsons/mso_request_create_configuration.json");
157 RequestDetails requestDetails = objectMapper.readValue(resource, RequestDetails.class);
158 return new RequestDetailsWrapper(requestDetails);
162 public void shouldProperlyValidateEndpointPathWheEendPointIsNotEmptyAndValid() {
163 System.setProperty("TestEnv", "123");
164 String foundEndPoint = validateEndpointPath("TestEnv");
165 assertEquals("123", foundEndPoint);
169 public void shouldThrowRuntimeExceptionWhenValidateEndpointPathEndPointIsNotEmptyAndValid() {
170 assertThatExceptionOfType(RuntimeException.class)
171 .isThrownBy(() -> validateEndpointPath("NotExists"));
175 public void shouldThrowRuntimeExceptionWhenValidateEndpointPathWhenEndPointIsNotEmptyButDoesntExists() {
176 String endPoint = "EmptyEndPoint";
177 System.setProperty(endPoint, "");
178 assertThatExceptionOfType(GenericUncheckedException.class)
179 .isThrownBy(() -> validateEndpointPath(endPoint))
180 .withMessage(endPoint + " env variable is not defined");
184 public void shouldProperlyCreateSvcInstanceWithProperParameters() {
186 MsoResponseWrapper expectedResponse = createOkResponse();
187 String svcEndpoint = SystemProperties.getProperty(MsoProperties.MSO_RESTAPI_SERVICE_INSTANCE);
188 given(msoInterface.createSvcInstance(msoRequest, svcEndpoint)).willReturn(expectedResponse);
190 MsoResponseWrapper response = msoBusinessLogic.createSvcInstance(msoRequest);
193 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
197 public void shouldProperlyCreateE2eSvcInstanceWithProperParameters() {
199 MsoResponseWrapper expectedResponse = createOkResponse();
200 String svcEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE);
201 given(msoInterface.createE2eSvcInstance(msoRequest, svcEndpoint)).willReturn(expectedResponse);
204 MsoResponseWrapper response = msoBusinessLogic.createE2eSvcInstance(msoRequest);
207 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
211 public void shouldProperlyCreateVnfWithProperParameters() {
213 MsoResponseWrapper expectedResponse = createOkResponse();
214 String endpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
215 String vnfInstanceId = "testVnfInstanceTempId";
216 String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId);
218 given(msoInterface.createVnf(msoRequest, vnfEndpoint)).willReturn(expectedResponse);
220 MsoResponseWrapper response = msoBusinessLogic.createVnf(msoRequest, vnfInstanceId);
223 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
227 public void shouldProperlyCreateNwInstanceWithProperParameters() {
229 MsoResponseWrapper expectedResponse = createOkResponse();
230 String vnfInstanceId = "testNwInstanceTempId";
231 String nwEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
232 String nw_endpoint = nwEndpoint.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId);
234 given(msoInterface.createNwInstance(msoRequest, nw_endpoint)).willReturn(expectedResponse);
236 MsoResponseWrapper response = msoBusinessLogic.createNwInstance(msoRequest, vnfInstanceId);
239 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
243 public void shouldProperlyCreateVolumeGroupInstanceWithProperParameters() {
244 MsoResponseWrapper expectedResponse = createOkResponse();
245 String serviceInstanceId = "testServiceInstanceTempId";
246 String vnfInstanceId = "testVnfInstanceTempId";
247 String nwEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
248 String vnfEndpoint = nwEndpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
249 vnfEndpoint = vnfEndpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
251 given(msoInterface.createVolumeGroupInstance(msoRequest, vnfEndpoint)).willReturn(expectedResponse);
253 MsoResponseWrapper response = msoBusinessLogic.createVolumeGroupInstance(msoRequest, serviceInstanceId, vnfInstanceId);
256 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
260 public void shouldProperlyCreateVfModuleInstanceWithProperParameters() {
261 MsoResponseWrapper expectedResponse = createOkResponse();
262 String serviceInstanceId = "testServiceInstanceTempId";
263 String vnfInstanceId = "testVnfInstanceTempId";
264 String partial_endpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
265 String vf_module_endpoint = partial_endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
266 vf_module_endpoint = vf_module_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
268 given(msoInterface.createVfModuleInstance(msoRequest, vf_module_endpoint)).willReturn(expectedResponse);
270 MsoResponseWrapper response = msoBusinessLogic.createVfModuleInstance(msoRequest, serviceInstanceId, vnfInstanceId);
273 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
277 public void shouldProperlyDeleteE2eSvcInstanceWithProperParameters() {
278 MsoResponseWrapper expectedResponse = createOkResponse();
279 String serviceInstanceId = "testDeleteE2eSvcInstanceTempId";
280 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE) + "/" + serviceInstanceId;
282 given(msoInterface.deleteE2eSvcInstance(msoRequest, endpoint)).willReturn(expectedResponse);
284 MsoResponseWrapper response = msoBusinessLogic.deleteE2eSvcInstance(msoRequest, serviceInstanceId);
287 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
291 public Object[][] deleteSvcInstanceShouldDelete() {
292 return new Object[][]{{"Active"}, {"unexpected-status"}};
296 public Object[][] deleteSvcInstanceShouldUnassign() {
297 return new Object[][]{{"Created"}, {"Pendingdelete"}, {"pending-Delete"}, {"Assigned"}};
301 @Test(dataProvider = "deleteSvcInstanceShouldDelete")
302 public void shouldProperlyDeleteSvcInstanceWithProperParametersShouldDelete(String status) {
304 String endpointTemplate = "/serviceInstantiation/v7/serviceInstances/%s";
305 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
306 String svcEndpoint = String.format(endpointTemplate, serviceInstanceId);
307 RequestDetails requestDetails = new RequestDetails();
308 MsoResponseWrapper expectedResponse = createOkResponse();
309 given(msoInterface.deleteSvcInstance(requestDetails, svcEndpoint)).willReturn(expectedResponse);
312 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
313 .deleteSvcInstance(requestDetails, serviceInstanceId, status);
316 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
319 @Test(dataProvider = "deleteSvcInstanceShouldUnassign")
320 public void shouldProperlyDeleteSvcInstanceWithProperParametersShouldUnassign(String status) {
322 String endpointTemplate = "/serviceInstantiation/v7/serviceInstances/%s/unassign";
323 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
324 String svcEndpoint = String.format(endpointTemplate, serviceInstanceId);
325 RequestDetails requestDetails = new RequestDetails();
326 MsoResponseWrapper expectedResponse = createOkResponse();
327 given(msoInterface.unassignSvcInstance(requestDetails, svcEndpoint)).willReturn(expectedResponse);
330 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
331 .deleteSvcInstance(requestDetails, serviceInstanceId, status);
334 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
338 public void shouldProperlyDeleteVnfWithProperParameters() {
340 String endpointTemplate = "/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s";
341 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
342 String vnfInstanceId = "testVnfInstanceTempId";
343 String vnfEndpoint = String.format(endpointTemplate, serviceInstanceId, vnfInstanceId);
344 RequestDetails requestDetails = new RequestDetails();
345 MsoResponseWrapper expectedResponse = createOkResponse();
346 given(msoInterface.deleteVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
349 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
350 .deleteVnf(requestDetails, serviceInstanceId, vnfInstanceId);
353 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
357 public void shouldProperlyDeleteVfModuleWithProperParameters() {
359 String endpointTemplate = "/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s/vfModules/%s";
360 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
361 String vnfInstanceId = "testVnfInstanceTempId";
362 String vfModuleId = "testVfModuleId";
363 String vnfEndpoint = String.format(endpointTemplate, serviceInstanceId, vnfInstanceId, vfModuleId);
364 RequestDetails requestDetails = new RequestDetails();
365 MsoResponseWrapper expectedResponse = createOkResponse();
366 given(msoInterface.deleteVfModule(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
369 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
370 .deleteVfModule(requestDetails, serviceInstanceId, vnfInstanceId, vfModuleId);
372 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
376 public void shouldProperlyDeleteVolumeGroupInstanceWithProperParameters() {
377 MsoResponseWrapper expectedResponse = createOkResponse();
378 String serviceInstanceId = "testServiceInstanceTempId";
379 String vnfInstanceId = "testVnfInstanceTempId";
380 String volumeGroupId = "testvolumeGroupIdTempId";
382 String deleteVolumeGroupEndpoint = getDeleteVolumeGroupEndpoint(serviceInstanceId, vnfInstanceId, volumeGroupId);
384 given(msoInterface.deleteVolumeGroupInstance(msoRequest, deleteVolumeGroupEndpoint)).willReturn(expectedResponse);
386 MsoResponseWrapper response = msoBusinessLogic.deleteVolumeGroupInstance(msoRequest, serviceInstanceId, vnfInstanceId, volumeGroupId);
389 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
393 private String getDeleteVolumeGroupEndpoint(String serviceInstanceId, String vnfInstanceId, String volumeGroupId) {
394 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
395 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
396 String vnfEndpoint = svc_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
397 return vnfEndpoint + "/" + volumeGroupId;
401 public void shouldProperlyDeleteNwInstanceWithProperParameters() {
402 MsoResponseWrapper expectedResponse = createOkResponse();
403 String serviceInstanceId = "testServiceInstanceTempId";
404 String networkInstanceId = "testNetworkInstanceTempId";
406 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
407 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
408 String delete_nw_endpoint = svc_endpoint + "/" + networkInstanceId;
410 given(msoInterface.deleteNwInstance(msoRequest, delete_nw_endpoint)).willReturn(expectedResponse);
412 MsoResponseWrapper response = msoBusinessLogic.deleteNwInstance(msoRequest, serviceInstanceId, networkInstanceId);
415 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
419 public void shouldProperlyGetOrchestrationRequestWithProperParameters() {
420 MsoResponseWrapper expectedResponse = createOkResponse();
421 String requestId = "testRequestTempId";
422 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
423 String path = p + "/" + requestId;
425 given(msoInterface.getOrchestrationRequest(path)).willReturn(expectedResponse);
427 MsoResponseWrapper response = msoBusinessLogic.getOrchestrationRequest(requestId);
428 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
431 @Test(expectedExceptions = MsoTestException.class)
432 public void shouldProperlyGetOrchestrationRequestWithWrongParameters() {
433 String requestId = "testWrongRequestTempId";
434 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
435 String path = p + "/" + requestId;
437 given(msoInterface.getOrchestrationRequest(path)).willThrow(new MsoTestException("testException"));
439 msoBusinessLogic.getOrchestrationRequest(requestId);
443 public void shouldProperlyGetOrchestrationRequestsWithProperParameters() {
444 MsoResponseWrapper expectedResponse = createOkResponse();
445 String filterString = "testRequestsTempId";
446 String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
447 String path = url + filterString;
449 given(msoInterface.getOrchestrationRequest(path)).willReturn(expectedResponse);
451 MsoResponseWrapper response = msoBusinessLogic.getOrchestrationRequests(filterString);
452 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
455 @Test(expectedExceptions = MsoTestException.class)
456 public void shouldThrowExceptionWhenGetOrchestrationRequestsWithWrongParameters() {
457 String filterString = "testRequestsTempId";
458 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
459 String path = p + filterString;
461 given(msoInterface.getOrchestrationRequest(path)).willThrow(new MsoTestException("testException"));
463 msoBusinessLogic.getOrchestrationRequests(filterString);
467 public void shouldSendProperScaleOutRequest() throws IOException {
469 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
470 String vnfInstanceId = "testVnfInstanceTempId";
471 String endpointTemplate = "/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s/vfModules/scaleOut";
472 String vnfEndpoint = String.format(endpointTemplate, serviceInstanceId, vnfInstanceId);
473 org.onap.vid.changeManagement.RequestDetails requestDetails = readRequest();
474 org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails> expectedRequest = readExpectedRequest();
475 MsoResponseWrapper expectedMsoResponseWrapper = createOkResponse();
478 .scaleOutVFModuleInstance(argThat(new MsoRequestWrapperMatcher(expectedRequest)),
480 .willReturn(expectedMsoResponseWrapper);
483 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
484 .scaleOutVfModuleInstance(requestDetails, serviceInstanceId, vnfInstanceId);
487 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedMsoResponseWrapper);
490 private org.onap.vid.changeManagement.RequestDetails readRequest() throws IOException {
491 Path path = Paths.get("payload_jsons", "scaleOutVfModulePayload.json");
492 URL url = this.getClass().getClassLoader().getResource(path.toString());
493 return objectMapper.readValue(url, org.onap.vid.changeManagement.RequestDetails.class);
496 private org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails> readExpectedRequest()
498 Path path = Paths.get("payload_jsons", "scaleOutVfModulePayloadToMso.json");
499 URL url = this.getClass().getClassLoader().getResource(path.toString());
500 return objectMapper.readValue(url,
501 new TypeReference<org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails>>() {
507 public void shouldFilterOutOrchestrationRequestsNotAllowedInDashboard() throws Exception {
509 String vnfModelTypeOrchestrationRequests = getFileContentAsString("mso_model_info_sample_response.json");
510 String scaleOutActionOrchestrationRequests = getFileContentAsString("mso_action_scaleout_sample_response.json");
512 HttpResponse<String> httpResponse = mockForGetOrchestrationRequest();
513 given(httpResponse.getBody())
514 .willReturn(vnfModelTypeOrchestrationRequests, scaleOutActionOrchestrationRequests);
517 List<Request> filteredOrchestrationReqs = msoBusinessLogic.getOrchestrationRequestsForDashboard();
519 assertThat(filteredOrchestrationReqs).hasSize(3);
520 assertThat(MsoBusinessLogicImpl.DASHBOARD_ALLOWED_TYPES)
521 .containsAll(filteredOrchestrationReqs
523 .map(el -> el.getRequestType().toUpperCase())
524 .collect(Collectors.toList()));
525 assertThat(filteredOrchestrationReqs)
526 .extracting(Request::getRequestScope)
527 .containsOnly("vnf", "vfModule");
530 @Test(expectedExceptions = GenericUncheckedException.class)
531 public void shouldThrowGenericUncheckedExceptionWhenGetOrchestrationRequestsForDashboardWithWrongJsonFile_() throws Exception {
533 String vnfModelTypeOrchestrationRequests = getFileContentAsString("mso_model_info_sample_wrong_response.json");
535 mockForGetOrchestrationRequest(200, vnfModelTypeOrchestrationRequests);
538 msoBusinessLogic.getOrchestrationRequestsForDashboard();
542 public void shouldProperlyGetManualTasksByRequestIdWithProperParameters() throws Exception {
544 String manualTasksList = getFileContentAsString("manual_tasks_by_requestId_test.json");
546 MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
548 .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
549 any(RestObject.class)))
550 .willReturn(msoResponseWrapperMock);
551 given(msoResponseWrapperMock.getEntity())
552 .willReturn(manualTasksList);
555 List<Task> filteredOrchestrationReqs = msoBusinessLogic.getManualTasksByRequestId("TestId");
558 assertThat(filteredOrchestrationReqs).hasSize(2);
559 assertThat(filteredOrchestrationReqs).extracting("taskId", "type").
561 tuple("123123abc", "testTask"),
562 tuple("321321abc", "testTask")
566 @Test(expectedExceptions = GenericUncheckedException.class)
567 public void shouldThrowGenericUncheckedExceptionWhenGetManualTasksByRequestIdWithWrongJsonFile() throws Exception {
569 String manualTasksList = getFileContentAsString("manual_tasks_by_requestId_wrongJson_test.json");
571 MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
573 .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
574 any(RestObject.class)))
575 .willReturn(msoResponseWrapperMock);
576 given(msoResponseWrapperMock.getEntity())
577 .willReturn(manualTasksList);
580 msoBusinessLogic.getManualTasksByRequestId("TestId");
583 @Test(expectedExceptions = MsoTestException.class)
584 public void getManualTasksByRequestIdWithArgument_shouldThrowException() {
587 .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
588 any(RestObject.class)))
589 .willThrow(MsoTestException.class);
592 msoBusinessLogic.getManualTasksByRequestId("TestId");
596 public void shouldProperlyCompleteManualTaskWithProperParameters() {
598 MsoResponseWrapper expectedResponse = createOkResponse();
599 RequestDetails requestDetails = new RequestDetails();
600 String taskId = "testTaskId";
602 String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
603 String path = url + "/" + taskId + "/complete";
605 given(msoInterface.completeManualTask(eq(requestDetails), any(String.class), any(String.class), eq(path), any(RestObject.class))).willReturn(expectedResponse);
608 MsoResponseWrapper response = msoBusinessLogic.completeManualTask(requestDetails, taskId);
611 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
616 public void shouldProperlyActivateServiceInstanceWithProperParameters() {
618 RequestDetails detail = new RequestDetails();
619 String taskId = "testTaskId";
621 RestObject<String> restObjStr = new RestObject<>();
623 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
626 MsoResponseWrapper response = msoBusinessLogic.activateServiceInstance(detail, taskId);
629 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
633 @Test(expectedExceptions = MsoTestException.class)
634 public void shouldThrowExceptionWhenManualTaskWithWrongParameters() {
636 RequestDetails requestDetails = new RequestDetails();
639 String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
640 String path = url + "/" + taskId + "/complete";
642 given(msoInterface.completeManualTask(eq(requestDetails), any(String.class), any(String.class), eq(path), any(RestObject.class))).willThrow(new MsoTestException("empty path"));
645 msoBusinessLogic.completeManualTask(requestDetails, taskId);
649 public void shouldProperlyUpdateVnfWithProperParameters() {
651 MsoResponseWrapper expectedResponse = createOkResponse();
652 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
654 String serviceInstanceId = "testServiceId";
655 String vnfInstanceId = "testVnfInstanceId";
657 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
658 String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
659 vnfEndpoint = vnfEndpoint + '/' + vnfInstanceId;
661 given(msoInterface.updateVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
664 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnf(requestDetails, serviceInstanceId, vnfInstanceId);
667 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
671 public void shouldProperlyReplaceVnfWithProperParameters() {
673 MsoResponseWrapper expectedResponse = createOkResponse();
674 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
676 String serviceInstanceId = "testServiceId";
677 String vnfInstanceId = "testVnfInstanceId";
679 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE);
680 String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
681 vnfEndpoint = vnfEndpoint.replace(VNF_INSTANCE_ID, vnfInstanceId);
682 vnfEndpoint = vnfEndpoint.replace(REQUEST_TYPE, ChangeManagementRequest.MsoChangeManagementRequest.REPLACE);
684 given(msoInterface.replaceVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
687 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.replaceVnf(requestDetails, serviceInstanceId, vnfInstanceId);
690 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
694 public void shouldProperlyGenerateInPlaceMsoRequestWithProperParameters() {
696 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
698 requestDetails.setVnfInstanceId("testVnfInstanceId");
699 requestDetails.setVnfName("testVnfName");
700 requestDetails.setRequestParameters(new RequestParameters());
702 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
703 "\"existing_software_version\": \"testExistingSoftwareParam\"," +
704 "\"new_software_version\": \"testNewSoftwareParam\"," +
705 "\"operations_timeout\": \"100\"" +
708 RequestDetails inPlaceSoftwareUpdateRequest = new RequestDetails();
709 inPlaceSoftwareUpdateRequest.setCloudConfiguration(requestDetails.getCloudConfiguration());
710 inPlaceSoftwareUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
711 inPlaceSoftwareUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
712 org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.changeManagement.RequestDetailsWrapper();
713 requestDetailsWrapper.requestDetails = inPlaceSoftwareUpdateRequest;
716 org.onap.vid.changeManagement.RequestDetailsWrapper response = msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
719 assertThat(response).isEqualToComparingFieldByField(requestDetailsWrapper);
722 @Test(expectedExceptions = BadRequestException.class)
723 public void shouldThrowExceptionWhenGenerateInPlaceMsoRequestWithParametersWithWrongCharacters() {
725 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
727 requestDetails.setVnfInstanceId("testVnfInstanceId");
728 requestDetails.setVnfName("testVnfName");
729 requestDetails.setRequestParameters(new RequestParameters());
731 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
732 "\"existing_software_version\": \"#####\"," +
733 "\"new_software_version\": \"testNewSoftwareParam\"" +
737 msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
740 @Test(expectedExceptions = BadRequestException.class)
741 public void shouldThrowExceptionWhenGenerateInPlaceMsoRequestWithWrongParameters() {
743 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
745 requestDetails.setVnfInstanceId("testVnfInstanceId");
746 requestDetails.setVnfName("testVnfName");
747 requestDetails.setRequestParameters(new RequestParameters());
749 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
750 "\"test-wrong-parameter\": \"testParam\"," +
751 "\"new_software_version\": \"testNewSoftwareParam\"" +
755 msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
759 public void shouldProprleyGenerateConfigMsoRequestWithProperParameters() {
761 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
763 requestDetails.setVnfInstanceId("testVnfInstanceId");
764 requestDetails.setVnfName("testVnfName");
765 requestDetails.setRequestParameters(new RequestParameters());
767 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
768 "\"request-parameters\": \"testRequestParam\"," +
769 "\"configuration-parameters\": \"testConfigParams\"" +
772 RequestDetails configUpdateRequest = new RequestDetails();
773 configUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
774 configUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
776 org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.changeManagement.RequestDetailsWrapper();
777 requestDetailsWrapper.requestDetails = configUpdateRequest;
780 org.onap.vid.changeManagement.RequestDetailsWrapper response = msoBusinessLogic.generateConfigMsoRequest(requestDetails);
783 assertThat(response).isEqualToComparingFieldByField(requestDetailsWrapper);
786 @Test(expectedExceptions = BadRequestException.class)
787 public void shouldThrowExceptionGenerateConfigMsoRequestWithoutAdditionalParameters() {
789 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
791 requestDetails.setVnfInstanceId("testVnfInstanceId");
792 requestDetails.setVnfName("testVnfName");
793 requestDetails.setRequestParameters(null);
796 msoBusinessLogic.generateConfigMsoRequest(requestDetails);
799 @Test(expectedExceptions = BadRequestException.class)
800 public void shouldThrowExceptionWhenGenerateConfigMsoRequestWithWrongPayload() {
802 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
804 requestDetails.setVnfInstanceId("testVnfInstanceId");
805 requestDetails.setVnfName("testVnfName");
806 requestDetails.setRequestParameters(new RequestParameters());
808 requestDetails.getRequestParameters().setAdditionalProperty("payload", null);
811 msoBusinessLogic.generateConfigMsoRequest(requestDetails);
814 @Test(expectedExceptions = BadRequestException.class)
815 public void shouldThrowExceptionGenerateConfigMsoRequestWithoutAnyParameter() {
817 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
819 requestDetails.setVnfInstanceId("testVnfInstanceId");
820 requestDetails.setVnfName("testVnfName");
821 requestDetails.setRequestParameters(new RequestParameters());
823 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
824 "\"test-wrong-parameter\": \"testParam\"," +
825 "\"configuration-parameters\": \"testConfigParam\"" +
829 msoBusinessLogic.generateConfigMsoRequest(requestDetails);
833 public void shouldProperlyGetActivateFabricConfigurationPathWithProperParameters() {
835 String serviceInstanceId = "testServiceId";
836 String path = validateEndpointPath(MsoProperties.MSO_RESTAPI_SERVICE_INSTANCE);
837 path += "/" + serviceInstanceId + "/activateFabricConfiguration";
840 String response = msoBusinessLogic.getActivateFabricConfigurationPath(serviceInstanceId);
843 assertThat(response).isEqualTo(path);
847 public void shouldProperlyGetDeactivateAndCloudDeletePathWithProperParameters() {
850 String response = msoBusinessLogic.getDeactivateAndCloudDeletePath("testServiceId", "testVnfInstanceId", "testVfModuleInstanceId");
853 String expectedPath = "/serviceInstantiation/v7/serviceInstances/testServiceId/vnfs/testVnfInstanceId/"+
854 "vfModules/testVfModuleInstanceId/deactivateAndCloudDelete";
855 assertThat(response).isEqualTo(expectedPath);
859 public void shouldProperlyBuildRequestDetailsForSoftDeleteWithProperParameters() throws IOException {
860 SoftDeleteRequest request = new SoftDeleteRequest("testTenantId", "testCloudId", "testUserID");
861 String expected = IOUtils.toString(this.getClass().getResource("/payload_jsons/vfModuleDeactivateAndCloudDelete.json"), "UTF-8");
862 final RequestDetails result = msoBusinessLogic.buildRequestDetailsForSoftDelete(request);
863 MatcherAssert.assertThat(result, jsonEquals(expected));
866 private void setRequestParametersForRequestDetails(RequestDetails requestDetails) {
867 RequestParameters requestParameters = new RequestParameters();
868 requestParameters.setTestApi("GR_API");
869 requestDetails.setRequestParameters(requestParameters);
872 private void setModelInfoForRequestDetails(RequestDetails requestDetails) {
873 ModelInfo modelInfo = new ModelInfo();
874 modelInfo.setModelType("vfModule");
875 requestDetails.setModelInfo(modelInfo);
879 public void shouldProperlyUpdateVnfSoftwareWithProperParameters() {
881 String serviceInstanceId = "testServiceId";
882 String vnfInstanceId = "testVnfInstanceId";
884 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
886 requestDetails.setVnfInstanceId("testVnfInstanceId");
887 requestDetails.setVnfName("testVnfName");
888 requestDetails.setRequestParameters(new RequestParameters());
890 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
891 "\"existing_software_version\": \"testExistingSoftwareParam\"," +
892 "\"new_software_version\": \"testNewSoftwareParam\"," +
893 "\"operations_timeout\": \"100\"" +
896 MsoResponseWrapper okResponse = createOkResponse();
898 given(msoInterface.changeManagementUpdate(isA(org.onap.vid.changeManagement.RequestDetailsWrapper.class), any(String.class))).willReturn(okResponse);
901 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnfSoftware(requestDetails, serviceInstanceId, vnfInstanceId);
904 assertThat(response).isEqualToComparingFieldByField(okResponse);
908 public void shouldProperlyUpdateVnfConfigWithProperParameters() {
910 String serviceInstanceId = "testServiceId";
911 String vnfInstanceId = "testVnfInstanceId";
913 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
915 requestDetails.setVnfInstanceId("testVnfInstanceId");
916 requestDetails.setVnfName("testVnfName");
917 requestDetails.setRequestParameters(new RequestParameters());
919 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
920 "\"request-parameters\": \"testRequestParam\"," +
921 "\"configuration-parameters\": \"testConfigParams\"" +
924 MsoResponseWrapper okResponse = createOkResponse();
926 given(msoInterface.changeManagementUpdate(isA(org.onap.vid.changeManagement.RequestDetailsWrapper.class), any(String.class))).willReturn(okResponse);
929 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnfConfig(requestDetails, serviceInstanceId, vnfInstanceId);
932 assertThat(response).isEqualToComparingFieldByField(okResponse);
936 public void shouldProperlyDeleteConfigurationWithProperParameters() {
938 String serviceInstanceId = "testServiceId";
939 String configurationId = "testConfigurationId";
941 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
943 requestDetails.setVnfInstanceId("testVnfInstanceId");
944 requestDetails.setVnfName("testVnfName");
946 MsoResponseWrapper okResponse = createOkResponse();
947 RequestDetailsWrapper wrappedRequestDetail = new RequestDetailsWrapper(requestDetails);
949 given(msoInterface.deleteConfiguration(eq(wrappedRequestDetail), any(String.class))).willReturn(okResponse);
952 MsoResponseWrapper response = msoBusinessLogic.deleteConfiguration(wrappedRequestDetail, serviceInstanceId, configurationId);
955 assertThat(response).isEqualToComparingFieldByField(okResponse);
959 public void shouldProperlySetConfigurationActiveStatusActiveWithProperParameters() {
961 String serviceInstanceId = "testServiceId";
962 String configurationId = "testConfigurationId";
964 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
966 requestDetails.setVnfInstanceId("testVnfInstanceId");
967 requestDetails.setVnfName("testVnfName");
969 MsoResponseWrapper okResponse = createOkResponse();
972 validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
973 .replace(SVC_INSTANCE_ID, serviceInstanceId)
974 .replace(CONFIGURATION_ID, configurationId)
977 given(msoInterface.setConfigurationActiveStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
980 MsoResponseWrapper response = msoBusinessLogic.setConfigurationActiveStatus(requestDetails, serviceInstanceId, configurationId, true);
983 assertThat(response).isEqualToComparingFieldByField(okResponse);
987 public void shouldProperlySetConfigurationActiveStatusDeactivateWithProperParameters() {
989 String serviceInstanceId = "testServiceId";
990 String configurationId = "testConfigurationId";
992 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
994 requestDetails.setVnfInstanceId("testVnfInstanceId");
995 requestDetails.setVnfName("testVnfName");
997 MsoResponseWrapper okResponse = createOkResponse();
1000 validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1001 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1002 .replace(CONFIGURATION_ID, configurationId)
1005 given(msoInterface.setConfigurationActiveStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1008 MsoResponseWrapper response = msoBusinessLogic.setConfigurationActiveStatus(requestDetails, serviceInstanceId, configurationId, false);
1011 assertThat(response).isEqualToComparingFieldByField(okResponse);
1015 public void shouldProperlySetServiceInstanceStatusActiveWithProperParameters() {
1017 String serviceInstanceId = "testServiceId";
1018 MsoResponseWrapper okResponse = createOkResponse();
1020 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1022 given(msoInterface.setServiceInstanceStatus(eq(requestDetails), endsWith(serviceInstanceId + "/activate"))).willReturn(okResponse);
1025 MsoResponseWrapper response = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, true);
1028 assertThat(response).isEqualToComparingFieldByField(okResponse);
1032 public void shouldProperlySetServiceInstanceStatusDeactivateWithProperParameters() {
1034 String serviceInstanceId = "testServiceId";
1035 MsoResponseWrapper okResponse = createOkResponse();
1037 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1039 given(msoInterface.setServiceInstanceStatus(eq(requestDetails), endsWith(serviceInstanceId + "/deactivate"))).willReturn(okResponse);
1042 MsoResponseWrapper response = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, false);
1045 assertThat(response).isEqualToComparingFieldByField(okResponse);
1048 @Test(expectedExceptions = MsoTestException.class)
1049 public void shouldThrowExceptionWhenSetServiceInstanceStatusWithWrongParameters() {
1051 String serviceInstanceId = "testServiceId";
1053 doThrow(new MsoTestException("testException")).
1054 when(msoInterface).setServiceInstanceStatus(eq(null), any(String.class));
1057 msoBusinessLogic.setServiceInstanceStatus(null, serviceInstanceId, true);
1061 public void shouldProperlySetPortOnConfigurationStatusEnableWithProperParameters() {
1063 String serviceInstanceId = "testServiceId";
1064 String configurationId = "testConfigurationId";
1065 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1066 requestDetails.setVnfInstanceId("testVnfInstanceId");
1067 requestDetails.setVnfName("testVnfName");
1068 MsoResponseWrapper okResponse = createOkResponse();
1070 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1071 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1072 .replace(CONFIGURATION_ID, configurationId)
1075 given(msoInterface.setPortOnConfigurationStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1078 MsoResponseWrapper response = msoBusinessLogic.setPortOnConfigurationStatus(requestDetails, serviceInstanceId, configurationId, true);
1081 assertThat(response).isEqualToComparingFieldByField(okResponse);
1085 public void shouldProperlySetPortOnConfigurationStatusDisableWithProperParameters() {
1087 String serviceInstanceId = "testServiceId";
1088 String configurationId = "testConfigurationId";
1089 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1090 requestDetails.setVnfInstanceId("testVnfInstanceId");
1091 requestDetails.setVnfName("testVnfName");
1092 MsoResponseWrapper okResponse = createOkResponse();
1094 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1095 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1096 .replace(CONFIGURATION_ID, configurationId)
1099 given(msoInterface.setPortOnConfigurationStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1102 MsoResponseWrapper response = msoBusinessLogic.setPortOnConfigurationStatus(requestDetails, serviceInstanceId, configurationId, false);
1105 assertThat(response).isEqualToComparingFieldByField(okResponse);
1109 public void shouldProperlyCreateOperationalEnvironmentActivationRequestDetailsWithProperParameters() {
1111 OperationalEnvironmentActivateInfo details = createTestOperationalEnvironmentActivateInfo();
1113 org.onap.vid.changeManagement.RequestDetailsWrapper<RequestDetails> requestDetails = msoBusinessLogic.createOperationalEnvironmentActivationRequestDetails(details);
1116 assertThat(requestDetails.requestDetails.getRequestParameters().getAdditionalProperties().values()).contains(details.getWorkloadContext(), details.getManifest());
1117 assertThat(requestDetails.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
1121 public void shouldProperlyGetOperationalEnvironmentActivationPathWithProperParameters() {
1123 OperationalEnvironmentActivateInfo details = createTestOperationalEnvironmentActivateInfo();
1126 String response = msoBusinessLogic.getOperationalEnvironmentActivationPath(details);
1129 assertThat(response).contains(operationalEnvironmentId);
1133 public void shouldProperlyCreateOperationalEnvironmentDeactivationRequestDetailsWithProperParameters() {
1135 OperationalEnvironmentDeactivateInfo details = createTestOperationalEnvironmentDeactivateInfo();
1138 org.onap.vid.changeManagement.RequestDetailsWrapper<RequestDetails> response;
1139 response = msoBusinessLogic.createOperationalEnvironmentDeactivationRequestDetails(details);
1142 assertThat(response.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
1146 public void shouldProperlyGetCloudResourcesRequestsStatusPathWithProperParameters() {
1148 String requestId = "testRequestId";
1151 String response = msoBusinessLogic.getCloudResourcesRequestsStatusPath(requestId);
1154 assertThat(response).contains(requestId);
1158 public void shouldProperlyGetOperationalEnvironmentDeactivationPathWithProperParameters() {
1160 OperationalEnvironmentDeactivateInfo details = createTestOperationalEnvironmentDeactivateInfo();
1163 String response = msoBusinessLogic.getOperationalEnvironmentDeactivationPath(details);
1166 assertThat(response).contains(operationalEnvironmentId);
1170 public void shouldProperlyGetOperationalEnvironmentCreationPathWithProperParameters() {
1172 String response = msoBusinessLogic.getOperationalEnvironmentCreationPath();
1175 assertThat(response).isNotBlank();
1179 public void shouldProperlyConvertParametersToRequestDetailsWithProperParameters() {
1181 OperationalEnvironmentController.OperationalEnvironmentCreateBody input = createTestOperationalEnvironmentCreateBody();
1184 org.onap.vid.changeManagement.RequestDetailsWrapper<OperationEnvironmentRequestDetails> response
1185 = msoBusinessLogic.convertParametersToRequestDetails(input, userId);
1188 assertThat(response.requestDetails.getRequestInfo().getInstanceName()).isEqualTo(input.getInstanceName());
1189 assertThat(response.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
1190 assertThat(response.requestDetails.getRequestParameters().getOperationalEnvironmentType()).isEqualTo(input.getOperationalEnvironmentType());
1191 assertThat(response.requestDetails.getRequestParameters().getTenantContext()).isEqualTo(input.getTenantContext());
1192 assertThat(response.requestDetails.getRequestParameters().getWorkloadContext()).isEqualTo(input.getWorkloadContext());
1196 public void shouldProperlyRemoveRelationshipFromServiceInstanceWithProperParameters() {
1198 MsoResponseWrapper expectedResponse = createOkResponse();
1199 String serviceInstanceId = "testServiceId";
1200 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1202 given(msoInterface.removeRelationshipFromServiceInstance(eq(requestDetails), endsWith("/" + serviceInstanceId + "/removeRelationships")))
1203 .willReturn(expectedResponse);
1206 MsoResponseWrapper response = msoBusinessLogic.removeRelationshipFromServiceInstance(requestDetails, serviceInstanceId);
1209 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
1213 public void shouldProperlyAddRelationshipToServiceInstanceWithProperParameters() {
1215 MsoResponseWrapper expectedResponse = createOkResponse();
1216 String serviceInstanceId = "testServiceId";
1217 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1219 given(msoInterface.addRelationshipToServiceInstance(eq(requestDetails), endsWith("/" + serviceInstanceId + "/addRelationships")))
1220 .willReturn(expectedResponse);
1223 MsoResponseWrapper response = msoBusinessLogic.addRelationshipToServiceInstance(requestDetails, serviceInstanceId);
1226 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
1230 public void shouldProperlyRequestTypeFromValueWithValidParameters() {
1232 String testValue = "createInstance";
1234 MsoBusinessLogicImpl.RequestType response = MsoBusinessLogicImpl.RequestType.fromValue(testValue);
1237 assertThat(response.toString()).isEqualTo(testValue);
1240 @Test(expectedExceptions = IllegalArgumentException.class)
1241 public void shouldThrowExceptionWhenRequestTypeFromValueWithWrongParameter() {
1243 String testValue = "notExistingParameter";
1245 MsoBusinessLogicImpl.RequestType.fromValue(testValue);
1249 public void shouldProperlyInvokeVnfWorkflowWithValidParameters() {
1251 MsoResponseWrapper okResponse = createOkResponse();
1252 WorkflowRequestDetail request = createWorkflowRequestDetail();
1253 UUID serviceInstanceId = new UUID(1,10);
1254 UUID vnfInstanceId = new UUID(2,20);
1255 UUID workflow_UUID = new UUID(3,30);
1256 String path = "/instanceManagement/v1/serviceInstances/"+serviceInstanceId+"/vnfs/"+vnfInstanceId+"/workflows/"+workflow_UUID;
1258 given(msoInterface.invokeWorkflow(eq(request), eq(path), MockitoHamcrest.argThat(allOf(hasEntry("X-RequestorID", "testRequester"),hasEntry("X-ONAP-PartnerName", "VID.VID"))))).willReturn(okResponse);
1261 MsoResponseWrapper response = msoBusinessLogic.invokeVnfWorkflow(request, "testRequester", serviceInstanceId, vnfInstanceId, workflow_UUID);
1264 assertThat(response).isEqualToComparingFieldByField(okResponse);
1269 public void shouldReturnWorkflowListForGivenModelId() {
1270 given(msoInterface.getWorkflowListByModelId(anyString())).willReturn(workflowListResponse);
1271 given(workflowListResponse.getBody()).willReturn(workflowList);
1272 given(workflowListResponse.getStatus()).willReturn(HttpStatus.ACCEPTED.value());
1274 SOWorkflowList workflows = msoBusinessLogic.getWorkflowListByModelId("sampleModelId");
1276 assertThat(workflows).isEqualTo(workflowList);
1279 @Test(expectedExceptions = {MsoBusinessLogicImpl.WorkflowListException.class})
1280 public void shouldRaiseExceptionWhenRetrievingWorkflowsFailed() {
1281 given(msoInterface.getWorkflowListByModelId(anyString())).willReturn(workflowListResponse);
1282 given(workflowListResponse.getStatus()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR.value());
1284 msoBusinessLogic.getWorkflowListByModelId("sampleModelId");
1289 public void probeShouldReturnOrchestrationRequestsAndConnectionStatus(){
1292 + " \"requestList\":"
1294 + " \"request\": {}"
1298 mockForGetOrchestrationRequest(200, body);
1300 ExternalComponentStatus externalComponentStatus = msoBusinessLogic.probeComponent();
1302 assertThat(externalComponentStatus.isAvailable()).isTrue();
1303 assertThat(externalComponentStatus.getComponent()).isEqualTo(ExternalComponentStatus.Component.MSO);
1306 private WorkflowRequestDetail createWorkflowRequestDetail() {
1307 WorkflowRequestDetail workflowRequestDetail = new WorkflowRequestDetail();
1308 org.onap.vid.changeManagement.RequestParameters requestParameters = new org.onap.vid.changeManagement.RequestParameters();
1309 HashMap<String,String> paramsMap = new HashMap<>();
1310 paramsMap.put("testKey1","testValue1");
1311 paramsMap.put("testKey2","testValue2");
1313 List<Map<String,String>> mapArray= new ArrayList<>();
1314 mapArray.add(paramsMap);
1315 requestParameters.setUserParams(mapArray);
1317 CloudConfiguration cloudConfiguration = new CloudConfiguration();
1318 cloudConfiguration.setCloudOwner("testOwne");
1319 cloudConfiguration.setTenantId("testId");
1320 cloudConfiguration.setLcpCloudRegionId("testLcpCloudId");
1322 workflowRequestDetail.setRequestParameters(requestParameters);
1323 workflowRequestDetail.setCloudConfiguration(cloudConfiguration);
1324 return workflowRequestDetail;
1327 private OperationalEnvironmentActivateInfo createTestOperationalEnvironmentActivateInfo() {
1328 OperationalEnvironmentController.OperationalEnvironmentActivateBody operationalEnvironmentActivateBody = new OperationalEnvironmentController.OperationalEnvironmentActivateBody(
1329 "testRelatedInstanceId",
1330 "testRelatedInstanceName",
1331 "testWorkloadContext",
1332 new OperationalEnvironmentController.OperationalEnvironmentManifest()
1334 return new OperationalEnvironmentActivateInfo(operationalEnvironmentActivateBody, userId, operationalEnvironmentId);
1337 private OperationalEnvironmentDeactivateInfo createTestOperationalEnvironmentDeactivateInfo() {
1338 return new OperationalEnvironmentDeactivateInfo(userId, operationalEnvironmentId);
1341 private OperationalEnvironmentController.OperationalEnvironmentCreateBody createTestOperationalEnvironmentCreateBody() {
1342 return new OperationalEnvironmentController.OperationalEnvironmentCreateBody(
1344 "testEcompInstanceId",
1345 "testEcompInstanceName",
1346 "testOperationalEnvironmentType",
1347 "testTenantContext",
1348 "testWorkloadContext"
1352 private MsoResponseWrapper createOkResponse() {
1353 HttpStatus expectedStatus = HttpStatus.ACCEPTED;
1354 String expectedBody = " \"body\": {\n" +
1355 " \"requestReferences\": {\n" +
1356 " \"instanceId\": \" 123456 \",\n" +
1357 " \"requestId\": \"b6dc9806-b094-42f7-9386-a48de8218ce8\"\n" +
1359 MsoResponseWrapper responseWrapper = new MsoResponseWrapper();
1360 responseWrapper.setEntity(expectedBody);
1361 responseWrapper.setStatus(expectedStatus.value());
1362 return responseWrapper;
1365 private String getFileContentAsString(String resourceName) throws Exception {
1366 Path path = Paths.get("payload_jsons", resourceName);
1367 URL url = this.getClass().getClassLoader().getResource(path.toString());
1370 result = IOUtils.toString(url.toURI(), "UTF-8");
1375 private static class MsoRequestWrapperMatcher implements
1376 ArgumentMatcher<org.onap.vid.changeManagement.RequestDetailsWrapper> {
1378 private final org.onap.vid.changeManagement.RequestDetailsWrapper expectedRequest;
1380 MsoRequestWrapperMatcher(org.onap.vid.changeManagement.RequestDetailsWrapper expectedRequest) {
1381 this.expectedRequest = expectedRequest;
1385 public boolean matches(org.onap.vid.changeManagement.RequestDetailsWrapper argument) {
1386 return expectedRequest.requestDetails.equals(argument.requestDetails);
1390 private class MsoTestException extends RuntimeException {
1391 MsoTestException(String testException) {
1392 super(testException);
1396 //you need to add mocks to httpResponse
1397 private HttpResponse<String> mockForGetOrchestrationRequest() {
1399 HttpResponse<String> httpResponse = mock(HttpResponse.class);
1400 HttpResponseWithRequestInfo<String> httpResponseWithRequestInfo = new HttpResponseWithRequestInfo<>(httpResponse, MY_PRETTY_URL, HttpMethod.GET);
1401 when(msoInterface.getOrchestrationRequest(any(String.class),anyBoolean()))
1402 .thenReturn(httpResponseWithRequestInfo);
1403 return httpResponse;
1406 private HttpResponse<String> mockForGetOrchestrationRequest(int statusCode, String body) {
1408 HttpResponse<String> httpResponse = mockForGetOrchestrationRequest();
1409 when(httpResponse.getStatus()).thenReturn(statusCode);
1410 when(httpResponse.getBody()).thenReturn(body);
1411 TestUtils.mockGetRawBodyWithStringBody(httpResponse, body);
1412 return httpResponse;
1416 public void probeComponent_verifyGoodRequest(){
1417 String responseString = "" +
1419 " \"requestList\": [{ " +
1420 " \"request\": { " +
1421 " \"requestDetails\": { " +
1422 " \"cloudConfiguration\": { " +
1423 " \"lcpCloudRegionId\": \"hvf6\", " +
1424 " \"cloudOwner\": \"irma-aic\", " +
1425 " \"tenantId\": \"ffdf52b5e5104b0e8f329b0b1637ee2e\" " +
1427 " \"modelInfo\": { " +
1428 " \"modelCustomizationName\": \"VSP1710PID298109_vWINIFRED 0\", " +
1429 " \"modelCustomizationId\": \"24d43fdb-9aa6-4287-a68e-1e702ea89d13\", " +
1430 " \"modelInvariantId\": \"e7961100-cde6-4b5a-bcda-b8945086950a\", " +
1431 " \"modelVersionId\": \"959a7ba0-89ee-4984-9af6-65d5bdda4b0e\", " +
1432 " \"modelName\": \"VSP1710PID298109_vWINIFRED\", " +
1433 " \"modelType\": \"vnf\", " +
1434 " \"modelVersion\": \"1.0\" " +
1436 " \"relatedModelList\": [{ " +
1437 " \"relatedInstance\": { " +
1438 " \"instanceId\": \"6dd0f8de-93c7-48a2-914b-1a8d58e0eb48\", " +
1439 " \"modelInfo\": { " +
1440 " \"modelInvariantId\": \"57e00952-0af7-4f0f-b19a-408a6f73c8df\", " +
1441 " \"modelType\": \"service\", " +
1442 " \"modelName\": \"ServicevWINIFREDPID298109\", " +
1443 " \"modelVersion\": \"1.0\", " +
1444 " \"modelVersionId\": \"fe6985cd-ea33-3346-ac12-ab121484a3fe\" " +
1449 " \"requestInfo\": { " +
1450 " \"source\": \"VID\", " +
1451 " \"suppressRollback\": false, " +
1452 " \"requestorId\": \"ds828e\" " +
1454 " \"requestParameters\": { " +
1455 " \"userParams\": [ " +
1457 " \"aLaCarte\": false, " +
1458 " \"usePreload\": true, " +
1459 " \"rebuildVolumeGroups\": false, " +
1460 " \"autoBuildVfModules\": false, " +
1461 " \"cascadeDelete\": false " +
1463 " \"relatedInstanceList\": [{ " +
1464 " \"relatedInstance\": { " +
1465 " \"instanceId\": \"6dd0f8de-93c7-48a2-914b-1a8d58e0eb48\", " +
1466 " \"modelInfo\": { " +
1467 " \"modelInvariantId\": \"57e00952-0af7-4f0f-b19a-408a6f73c8df\", " +
1468 " \"modelType\": \"service\", " +
1469 " \"modelName\": \"ServicevWINIFREDPID298109\", " +
1470 " \"modelVersion\": \"1.0\", " +
1471 " \"modelVersionId\": \"fe6985cd-ea33-3346-ac12-ab121484a3fe\" " +
1477 " \"requestId\": \"d352c70d-5ef8-4977-9ea8-4c8cbe860422\", " +
1478 " \"requestScope\": \"vnf\", " +
1479 " \"requestStatus\": { " +
1480 " \"percentProgress\": 100.0, " +
1481 " \"requestState\": \"Some Unknown Value\", " +
1482 " \"statusMessage\": \"Update Is In Progress\", " +
1483 " \"finishTime\": \"Fri, 08 Sep 2017 19:34:33 GMT\" " +
1485 " \"requestType\": \"updateInstance\", " +
1486 " \"startTime\": \"<IN_PROGRESS_DATE>\", " +
1487 " \"instanceReferences\": { " +
1488 " \"serviceInstanceId\": \"6dd0f8de-93c7-48a2-914b-1a8d58e0eb48\", " +
1489 " \"vnfInstanceId\": \"7c00cc1e-6425-4fc3-afc3-0289db288d4c\", " +
1490 " \"requestorId\": \"ds828e\" " +
1497 mockForGetOrchestrationRequest(200, responseString);
1499 final ExternalComponentStatus msoStatus = msoBusinessLogic.probeComponent();
1501 assertMsoStatus(msoStatus, true);
1502 assertMetadata(msoStatus, 200, startsWith(responseString.substring(0, 400)), MY_PRETTY_URL, equalTo("OK"));
1506 public void probeComponent_response200OkButEmptyPayload_shouldDescribeCorrectly() {
1507 String responseString = "" +
1509 " \"requestList\": []" +
1512 mockForGetOrchestrationRequest(200, responseString);
1514 final ExternalComponentStatus msoStatus = msoBusinessLogic.probeComponent();
1516 assertMsoStatus(msoStatus, true);
1518 assertMetadata(msoStatus, 200, equalTo(responseString), MY_PRETTY_URL, containsString("OK"));
1522 public void probeComponent_response200OkButInvalidPayload_shouldDescribeCorrectly() {
1523 String responseString = "this payload is an invalid json";
1525 mockForGetOrchestrationRequest(200, responseString);
1527 final ExternalComponentStatus msoStatus = msoBusinessLogic.probeComponent();
1529 assertMsoStatus(msoStatus, false);
1531 assertMetadata(msoStatus, 200, equalTo(responseString), MY_PRETTY_URL, containsString("JsonParseException: Unrecognized token"));
1535 public void probeComponent_verifyResponse406() {
1536 String responseString = "my raw data";
1538 when(msoInterface.getOrchestrationRequest(any(), eq(true))).thenThrow(
1539 new ExceptionWithRequestInfo(HttpMethod.GET, MY_PRETTY_URL, responseString, 406,
1540 new GenericUncheckedException(
1541 new HttpException("Simulating as 406 was returned (200 or 202 expected)"))));
1543 final ExternalComponentStatus msoStatus = msoBusinessLogic.probeComponent();
1545 assertMsoStatus(msoStatus, false);
1547 assertMetadata(msoStatus, 406, equalTo(responseString), MY_PRETTY_URL, containsString("HttpException: Simulating as 406 was returned"));
1552 public void probeComponent_throwNullPointerException_resultIsWithErrorMetadata() {
1553 when(msoInterface.getOrchestrationRequest(any(), eq(true))).thenThrow(new NullPointerException());
1555 final ExternalComponentStatus msoStatus = msoBusinessLogic.probeComponent();
1557 MatcherAssert.assertThat(msoStatus.isAvailable(), is(false));
1558 MatcherAssert.assertThat(msoStatus.getComponent(), is(MSO));
1559 MatcherAssert.assertThat(msoStatus.getMetadata(), instanceOf(ErrorMetadata.class));
1561 final ErrorMetadata metadata = ((ErrorMetadata) msoStatus.getMetadata());
1562 org.junit.Assert.assertThat(metadata.getDescription(), containsString("NullPointerException"));
1565 private void assertMsoStatus(ExternalComponentStatus msoStatus, boolean isAvailable) {
1566 MatcherAssert.assertThat(msoStatus.isAvailable(), is(isAvailable));
1567 MatcherAssert.assertThat(msoStatus.getComponent(), is(MSO));
1568 MatcherAssert.assertThat(msoStatus.getMetadata(), instanceOf(HttpRequestMetadata.class));
1571 private void assertMetadata(ExternalComponentStatus msoStatus, int httpCode, Matcher<String> rawData, String url, Matcher<String> descriptionMatcher) {
1572 final HttpRequestMetadata metadata = ((HttpRequestMetadata) msoStatus.getMetadata());
1573 org.junit.Assert.assertThat(metadata.getHttpMethod(), equalTo(HttpMethod.GET));
1574 org.junit.Assert.assertThat(metadata.getHttpCode(), equalTo(httpCode));
1575 org.junit.Assert.assertThat(metadata.getUrl(), equalTo(url));
1576 org.junit.Assert.assertThat(metadata.getRawData(), rawData);
1577 org.junit.Assert.assertThat(metadata.getDescription(), descriptionMatcher);