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 io.joshworks.restclient.http.HttpResponse;
27 import org.apache.commons.io.IOUtils;
28 import org.jetbrains.annotations.NotNull;
29 import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
30 import org.testng.annotations.BeforeClass;
31 import org.testng.annotations.Test;
32 import org.mockito.ArgumentMatcher;
33 import org.mockito.Mock;
34 import org.mockito.MockitoAnnotations;
35 import org.onap.portalsdk.core.util.SystemProperties;
36 import org.onap.vid.changeManagement.ChangeManagementRequest;
37 import org.onap.vid.controller.OperationalEnvironmentController;
38 import org.onap.vid.exceptions.GenericUncheckedException;
39 import org.onap.vid.model.RequestReferencesContainer;
40 import org.onap.vid.model.SoftDeleteRequest;
41 import org.onap.vid.mso.model.CloudConfiguration;
42 import org.onap.vid.mso.model.ModelInfo;
43 import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo;
44 import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo;
45 import org.onap.vid.mso.model.RequestInfo;
46 import org.onap.vid.mso.model.RequestParameters;
47 import org.onap.vid.mso.model.RequestReferences;
48 import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails;
49 import org.onap.vid.mso.rest.Request;
50 import org.onap.vid.mso.rest.RequestDetails;
51 import org.onap.vid.mso.rest.RequestDetailsWrapper;
52 import org.onap.vid.mso.rest.Task;
53 import org.onap.vid.properties.Features;
54 import org.springframework.http.HttpStatus;
55 import org.springframework.test.context.ContextConfiguration;
56 import org.togglz.core.manager.FeatureManager;
58 import javax.ws.rs.BadRequestException;
59 import java.io.IOException;
61 import java.nio.file.Path;
62 import java.nio.file.Paths;
63 import java.util.List;
64 import java.util.stream.Collectors;
66 import static org.assertj.core.api.Assertions.assertThat;
67 import static org.assertj.core.api.Assertions.tuple;
68 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
69 import static org.junit.Assert.assertEquals;
70 import static org.mockito.ArgumentMatchers.any;
71 import static org.mockito.ArgumentMatchers.anyBoolean;
72 import static org.mockito.ArgumentMatchers.argThat;
73 import static org.mockito.ArgumentMatchers.eq;
74 import static org.mockito.ArgumentMatchers.isA;
75 import static org.mockito.ArgumentMatchers.endsWith;
76 import static org.mockito.BDDMockito.given;
77 import static org.mockito.Mockito.doThrow;
78 import static org.mockito.Mockito.mock;
79 import static org.onap.vid.controller.MsoController.CONFIGURATION_ID;
80 import static org.onap.vid.controller.MsoController.REQUEST_TYPE;
81 import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
82 import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
83 import static org.onap.vid.mso.MsoBusinessLogicImpl.validateEndpointPath;
85 @ContextConfiguration(classes = {SystemProperties.class})
86 public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
88 private static final ObjectMapper objectMapper = new ObjectMapper();
91 private FeatureManager featureManager;
94 private MsoInterface msoInterface;
97 private RequestDetails msoRequest;
100 private MsoBusinessLogicImpl msoBusinessLogic;
101 private String userId = "testUserId";
102 private String operationalEnvironmentId = "testOperationalEnvironmentId";
105 public void setUp() {
106 MockitoAnnotations.initMocks(this);
107 msoBusinessLogic = new MsoBusinessLogicImpl(msoInterface, featureManager);
111 public void shouldProperlyCreateConfigurationInstanceWithCorrectServiceInstanceId() throws Exception {
113 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
114 String endpointTemplate = String.format("/serviceInstances/v6/%s/configurations", serviceInstanceId);
115 RequestDetailsWrapper requestDetailsWrapper = createRequestDetails();
116 MsoResponseWrapper expectedResponse = createOkResponse();
117 given(msoInterface.createConfigurationInstance(requestDetailsWrapper, endpointTemplate))
118 .willReturn(expectedResponse);
121 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
122 .createConfigurationInstance(requestDetailsWrapper, serviceInstanceId);
125 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
128 private RequestDetailsWrapper createRequestDetails() throws Exception {
129 final URL resource = this.getClass().getResource("/payload_jsons/mso_request_create_configuration.json");
130 RequestDetails requestDetails = objectMapper.readValue(resource, RequestDetails.class);
131 return new RequestDetailsWrapper(requestDetails);
135 public void shouldProperlyValidateEndpointPathWheEendPointIsNotEmptyAndValid() {
136 System.setProperty("TestEnv", "123");
137 String foundEndPoint = validateEndpointPath("TestEnv");
138 assertEquals("123", foundEndPoint);
142 public void shouldThrowRuntimeExceptionWhenValidateEndpointPathEndPointIsNotEmptyAndValid() {
143 assertThatExceptionOfType(RuntimeException.class)
144 .isThrownBy(() -> validateEndpointPath("NotExists"));
148 public void shouldThrowRuntimeExceptionWhenValidateEndpointPathWhenEndPointIsNotEmptyButDoesntExists() {
149 String endPoint = "EmptyEndPoint";
150 System.setProperty(endPoint, "");
151 assertThatExceptionOfType(GenericUncheckedException.class)
152 .isThrownBy(() -> validateEndpointPath(endPoint))
153 .withMessage(endPoint + " env variable is not defined");
157 public void shouldProperlyCreateSvcInstanceWithProperParameters() {
159 MsoResponseWrapper expectedResponse = createOkResponse();
160 String svcEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
161 given(msoInterface.createSvcInstance(msoRequest, svcEndpoint)).willReturn(expectedResponse);
163 MsoResponseWrapper response = msoBusinessLogic.createSvcInstance(msoRequest);
166 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
170 public void shouldProperlyCreateE2eSvcInstanceWithProperParameters() {
172 MsoResponseWrapper expectedResponse = createOkResponse();
173 String svcEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE);
174 given(msoInterface.createE2eSvcInstance(msoRequest, svcEndpoint)).willReturn(expectedResponse);
177 MsoResponseWrapper response = msoBusinessLogic.createE2eSvcInstance(msoRequest);
180 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
184 public void shouldProperlyCreateVnfWithProperParameters() {
186 MsoResponseWrapper expectedResponse = createOkResponse();
187 String endpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
188 String vnfInstanceId = "testVnfInstanceTempId";
189 String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId);
191 given(msoInterface.createVnf(msoRequest, vnfEndpoint)).willReturn(expectedResponse);
193 MsoResponseWrapper response = msoBusinessLogic.createVnf(msoRequest, vnfInstanceId);
196 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
200 public void shouldProperlyCreateNwInstanceWithProperParameters() {
202 MsoResponseWrapper expectedResponse = createOkResponse();
203 String vnfInstanceId = "testNwInstanceTempId";
204 String nwEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
205 String nw_endpoint = nwEndpoint.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId);
207 given(msoInterface.createNwInstance(msoRequest, nw_endpoint)).willReturn(expectedResponse);
209 MsoResponseWrapper response = msoBusinessLogic.createNwInstance(msoRequest, vnfInstanceId);
212 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
216 public void shouldProperlyCreateVolumeGroupInstanceWithProperParameters() {
217 MsoResponseWrapper expectedResponse = createOkResponse();
218 String serviceInstanceId = "testServiceInstanceTempId";
219 String vnfInstanceId = "testVnfInstanceTempId";
220 String nwEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
221 String vnfEndpoint = nwEndpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
222 vnfEndpoint = vnfEndpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
224 given(msoInterface.createVolumeGroupInstance(msoRequest, vnfEndpoint)).willReturn(expectedResponse);
226 MsoResponseWrapper response = msoBusinessLogic.createVolumeGroupInstance(msoRequest, serviceInstanceId, vnfInstanceId);
229 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
233 public void shouldProperlyCreateVfModuleInstanceWithProperParameters() {
234 MsoResponseWrapper expectedResponse = createOkResponse();
235 String serviceInstanceId = "testServiceInstanceTempId";
236 String vnfInstanceId = "testVnfInstanceTempId";
237 String partial_endpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
238 String vf_module_endpoint = partial_endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
239 vf_module_endpoint = vf_module_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
241 given(msoInterface.createVfModuleInstance(msoRequest, vf_module_endpoint)).willReturn(expectedResponse);
243 MsoResponseWrapper response = msoBusinessLogic.createVfModuleInstance(msoRequest, serviceInstanceId, vnfInstanceId);
246 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
250 public void shouldProperlyDeleteE2eSvcInstanceWithProperParameters() {
251 MsoResponseWrapper expectedResponse = createOkResponse();
252 String serviceInstanceId = "testDeleteE2eSvcInstanceTempId";
253 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE) + "/" + serviceInstanceId;
255 given(msoInterface.deleteE2eSvcInstance(msoRequest, endpoint)).willReturn(expectedResponse);
257 MsoResponseWrapper response = msoBusinessLogic.deleteE2eSvcInstance(msoRequest, serviceInstanceId);
260 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
264 public void shouldProperlyDeleteSvcInstanceWithProperParametersAndFalseFeatureFlag() {
266 String endpointTemplate = "/serviceInstances/v5/%s";
267 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
268 String svcEndpoint = String.format(endpointTemplate, serviceInstanceId);
269 RequestDetails requestDetails = new RequestDetails();
270 MsoResponseWrapper expectedResponse = createOkResponse();
271 given(msoInterface.deleteSvcInstance(requestDetails, svcEndpoint)).willReturn(expectedResponse);
272 given(featureManager.isActive(Features.FLAG_UNASSIGN_SERVICE)).willReturn(false);
275 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
276 .deleteSvcInstance(requestDetails, serviceInstanceId, "unAssignOrDeleteParams");
279 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
283 public void shouldProperlyDeleteSvcInstanceWithProperParametersAndTrueFeatureFlag() {
285 String endpointTemplate = "/serviceInstantiation/v5/serviceInstances/%s/unassign";
286 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
287 String svcEndpoint = String.format(endpointTemplate, serviceInstanceId);
288 RequestDetails requestDetails = new RequestDetails();
289 MsoResponseWrapper expectedResponse = createOkResponse();
290 given(msoInterface.unassignSvcInstance(requestDetails, svcEndpoint)).willReturn(expectedResponse);
291 given(featureManager.isActive(Features.FLAG_UNASSIGN_SERVICE)).willReturn(true);
294 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
295 .deleteSvcInstance(requestDetails, serviceInstanceId, "assigned");
298 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
302 public void shouldProperlyDeleteVnfWithProperParameters() {
304 String endpointTemplate = "/serviceInstances/v5/%s/vnfs/%s";
305 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
306 String vnfInstanceId = "testVnfInstanceTempId";
307 String vnfEndpoint = String.format(endpointTemplate, serviceInstanceId, vnfInstanceId);
308 RequestDetails requestDetails = new RequestDetails();
309 MsoResponseWrapper expectedResponse = createOkResponse();
310 given(msoInterface.deleteVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
313 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
314 .deleteVnf(requestDetails, serviceInstanceId, vnfInstanceId);
317 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
321 public void shouldProperlyDeleteVfModuleWithProperParameters() {
323 String endpointTemplate = "/serviceInstances/v7/%s/vnfs/%s/vfModules/%s";
324 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
325 String vnfInstanceId = "testVnfInstanceTempId";
326 String vfModuleId = "testVfModuleId";
327 String vnfEndpoint = String.format(endpointTemplate, serviceInstanceId, vnfInstanceId, vfModuleId);
328 RequestDetails requestDetails = new RequestDetails();
329 MsoResponseWrapper expectedResponse = createOkResponse();
330 given(msoInterface.deleteVfModule(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
333 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
334 .deleteVfModule(requestDetails, serviceInstanceId, vnfInstanceId, vfModuleId);
336 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedResponse);
340 public void shouldProperlyDeleteVolumeGroupInstanceWithProperParameters() {
341 MsoResponseWrapper expectedResponse = createOkResponse();
342 String serviceInstanceId = "testServiceInstanceTempId";
343 String vnfInstanceId = "testVnfInstanceTempId";
344 String volumeGroupId = "testvolumeGroupIdTempId";
346 String deleteVolumeGroupEndpoint = getDeleteVolumeGroupEndpoint(serviceInstanceId, vnfInstanceId, volumeGroupId);
348 given(msoInterface.deleteVolumeGroupInstance(msoRequest, deleteVolumeGroupEndpoint)).willReturn(expectedResponse);
350 MsoResponseWrapper response = msoBusinessLogic.deleteVolumeGroupInstance(msoRequest, serviceInstanceId, vnfInstanceId, volumeGroupId);
353 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
357 private String getDeleteVolumeGroupEndpoint(String serviceInstanceId, String vnfInstanceId, String volumeGroupId) {
358 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
359 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
360 String vnfEndpoint = svc_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
361 return vnfEndpoint + "/" + volumeGroupId;
365 public void shouldProperlyDeleteNwInstanceWithProperParameters() {
366 MsoResponseWrapper expectedResponse = createOkResponse();
367 String serviceInstanceId = "testServiceInstanceTempId";
368 String networkInstanceId = "testNetworkInstanceTempId";
370 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
371 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
372 String delete_nw_endpoint = svc_endpoint + "/" + networkInstanceId;
374 given(msoInterface.deleteNwInstance(msoRequest, delete_nw_endpoint)).willReturn(expectedResponse);
376 MsoResponseWrapper response = msoBusinessLogic.deleteNwInstance(msoRequest, serviceInstanceId, networkInstanceId);
379 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
383 public void shouldProperlyGetOrchestrationRequestWithProperParameters() {
384 MsoResponseWrapper expectedResponse = createOkResponse();
385 String requestId = "testRequestTempId";
386 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
387 String path = p + "/" + requestId;
389 given(msoInterface.getOrchestrationRequest(path)).willReturn(expectedResponse);
391 MsoResponseWrapper response = msoBusinessLogic.getOrchestrationRequest(requestId);
392 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
395 @Test(expectedExceptions = MsoTestException.class)
396 public void shouldProperlyGetOrchestrationRequestWithWrongParameters() {
397 String requestId = "testWrongRequestTempId";
398 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
399 String path = p + "/" + requestId;
401 given(msoInterface.getOrchestrationRequest(path)).willThrow(new MsoTestException("testException"));
403 msoBusinessLogic.getOrchestrationRequest(requestId);
407 public void shouldProperlyGetOrchestrationRequestsWithProperParameters() {
408 MsoResponseWrapper expectedResponse = createOkResponse();
409 String filterString = "testRequestsTempId";
410 String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
411 String path = url + filterString;
413 given(msoInterface.getOrchestrationRequest(path)).willReturn(expectedResponse);
415 MsoResponseWrapper response = msoBusinessLogic.getOrchestrationRequests(filterString);
416 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
419 @Test(expectedExceptions = MsoTestException.class)
420 public void shouldThrowExceptionWhenGetOrchestrationRequestsWithWrongParameters() {
421 String filterString = "testRequestsTempId";
422 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
423 String path = p + filterString;
425 given(msoInterface.getOrchestrationRequest(path)).willThrow(new MsoTestException("testException"));
427 msoBusinessLogic.getOrchestrationRequests(filterString);
431 public void shouldSendProperScaleOutRequest() throws IOException {
433 String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
434 String vnfInstanceId = "testVnfInstanceTempId";
435 String endpointTemplate = "/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s/vfModules/scaleOut";
436 String vnfEndpoint = String.format(endpointTemplate, serviceInstanceId, vnfInstanceId);
437 org.onap.vid.changeManagement.RequestDetails requestDetails = readRequest();
438 org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails> expectedRequest = readExpectedRequest();
439 MsoResponseWrapper expectedMsoResponseWrapper = createOkResponse();
442 .scaleOutVFModuleInstance(argThat(new MsoRequestWrapperMatcher(expectedRequest)),
444 .willReturn(expectedMsoResponseWrapper);
447 MsoResponseWrapper msoResponseWrapper = msoBusinessLogic
448 .scaleOutVfModuleInstance(requestDetails, serviceInstanceId, vnfInstanceId);
451 assertThat(msoResponseWrapper).isEqualToComparingFieldByField(expectedMsoResponseWrapper);
454 private org.onap.vid.changeManagement.RequestDetails readRequest() throws IOException {
455 Path path = Paths.get("payload_jsons", "scaleOutVfModulePayload.json");
456 URL url = this.getClass().getClassLoader().getResource(path.toString());
457 return objectMapper.readValue(url, org.onap.vid.changeManagement.RequestDetails.class);
460 private org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails> readExpectedRequest()
462 Path path = Paths.get("payload_jsons", "scaleOutVfModulePayloadToMso.json");
463 URL url = this.getClass().getClassLoader().getResource(path.toString());
464 return objectMapper.readValue(url,
465 new TypeReference<org.onap.vid.changeManagement.RequestDetailsWrapper<org.onap.vid.changeManagement.RequestDetails>>() {
471 public void shouldFilterOutOrchestrationRequestsNotAllowedInDashboard() throws Exception {
473 String vnfModelTypeOrchestrationRequests = getFileContentAsString("mso_model_info_sample_response.json");
474 String scaleOutActionOrchestrationRequests = getFileContentAsString("mso_action_scaleout_sample_response.json");
476 MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
478 .getOrchestrationRequest(any(String.class), any(String.class), any(String.class),
479 any(RestObject.class), anyBoolean()))
480 .willReturn(msoResponseWrapperMock);
481 given(msoResponseWrapperMock.getEntity())
482 .willReturn(vnfModelTypeOrchestrationRequests, scaleOutActionOrchestrationRequests);
485 List<Request> filteredOrchestrationReqs = msoBusinessLogic.getOrchestrationRequestsForDashboard();
487 assertThat(filteredOrchestrationReqs).hasSize(3);
488 assertThat(MsoBusinessLogicImpl.DASHBOARD_ALLOWED_TYPES)
489 .containsAll(filteredOrchestrationReqs
491 .map(el -> el.getRequestType().toUpperCase())
492 .collect(Collectors.toList()));
493 assertThat(filteredOrchestrationReqs)
494 .extracting(Request::getRequestScope)
495 .containsOnly("vnf", "vfModule");
498 @Test(expectedExceptions = GenericUncheckedException.class)
499 public void shouldThrowGenericUncheckedExceptionWhenGetOrchestrationRequestsForDashboardWithWrongJsonFile_() throws Exception {
501 String vnfModelTypeOrchestrationRequests = getFileContentAsString("mso_model_info_sample_wrong_response.json");
503 MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
505 .getOrchestrationRequest(any(String.class), any(String.class), any(String.class),
506 any(RestObject.class), anyBoolean()))
507 .willReturn(msoResponseWrapperMock);
508 given(msoResponseWrapperMock.getEntity())
509 .willReturn(vnfModelTypeOrchestrationRequests);
512 msoBusinessLogic.getOrchestrationRequestsForDashboard();
516 public void shouldProperlyGetManualTasksByRequestIdWithProperParameters() throws Exception {
518 String manualTasksList = getFileContentAsString("manual_tasks_by_requestId_test.json");
520 MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
522 .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
523 any(RestObject.class)))
524 .willReturn(msoResponseWrapperMock);
525 given(msoResponseWrapperMock.getEntity())
526 .willReturn(manualTasksList);
529 List<Task> filteredOrchestrationReqs = msoBusinessLogic.getManualTasksByRequestId("TestId");
532 assertThat(filteredOrchestrationReqs).hasSize(2);
533 assertThat(filteredOrchestrationReqs).extracting("taskId", "type").
535 tuple("123123abc", "testTask"),
536 tuple("321321abc", "testTask")
540 @Test(expectedExceptions = GenericUncheckedException.class)
541 public void shouldThrowGenericUncheckedExceptionWhenGetManualTasksByRequestIdWithWrongJsonFile() throws Exception {
543 String manualTasksList = getFileContentAsString("manual_tasks_by_requestId_wrongJson_test.json");
545 MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
547 .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
548 any(RestObject.class)))
549 .willReturn(msoResponseWrapperMock);
550 given(msoResponseWrapperMock.getEntity())
551 .willReturn(manualTasksList);
554 msoBusinessLogic.getManualTasksByRequestId("TestId");
557 @Test(expectedExceptions = MsoTestException.class)
558 public void getManualTasksByRequestIdWithArgument_shouldThrowException() {
561 .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
562 any(RestObject.class)))
563 .willThrow(MsoTestException.class);
566 msoBusinessLogic.getManualTasksByRequestId("TestId");
570 public void shouldProperlyCompleteManualTaskWithProperParameters() {
572 MsoResponseWrapper expectedResponse = createOkResponse();
573 RequestDetails requestDetails = new RequestDetails();
574 String taskId = "testTaskId";
576 String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
577 String path = url + "/" + taskId + "/complete";
579 given(msoInterface.completeManualTask(eq(requestDetails), any(String.class), any(String.class), eq(path), any(RestObject.class))).willReturn(expectedResponse);
582 MsoResponseWrapper response = msoBusinessLogic.completeManualTask(requestDetails, taskId);
585 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
590 public void shouldProperlyActivateServiceInstanceWithProperParameters() {
592 RequestDetails detail = new RequestDetails();
593 String taskId = "testTaskId";
595 RestObject<String> restObjStr = new RestObject<>();
597 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
600 MsoResponseWrapper response = msoBusinessLogic.activateServiceInstance(detail, taskId);
603 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
607 @Test(expectedExceptions = MsoTestException.class)
608 public void shouldThrowExceptionWhenActivateServiceInstanceWithWrongParameters() {
610 RequestDetails requestDetails = new RequestDetails();
611 String taskId = "testTaskId";
613 RestObject<String> restObjStr = new RestObject<>();
615 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
617 doThrow(new MsoTestException("testException")).
618 when(msoInterface).setServiceInstanceStatus(eq(requestDetails), any(String.class), any(String.class), any(String.class), any(RestObject.class));
621 MsoResponseWrapper response = msoBusinessLogic.activateServiceInstance(requestDetails, taskId);
624 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
627 @Test(expectedExceptions = MsoTestException.class)
628 public void shouldThrowExceptionWhenManualTaskWithWrongParameters() {
630 RequestDetails requestDetails = new RequestDetails();
633 String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
634 String path = url + "/" + taskId + "/complete";
636 given(msoInterface.completeManualTask(eq(requestDetails), any(String.class), any(String.class), eq(path), any(RestObject.class))).willThrow(new MsoTestException("empty path"));
639 msoBusinessLogic.completeManualTask(requestDetails, taskId);
643 public void shouldProperlyUpdateVnfWithProperParameters() {
645 MsoResponseWrapper expectedResponse = createOkResponse();
646 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
648 String serviceInstanceId = "testServiceId";
649 String vnfInstanceId = "testVnfInstanceId";
651 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
652 String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
653 vnfEndpoint = vnfEndpoint + '/' + vnfInstanceId;
655 given(msoInterface.updateVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
658 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnf(requestDetails, serviceInstanceId, vnfInstanceId);
661 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
665 public void shouldProperlyReplaceVnfWithProperParameters() {
667 MsoResponseWrapper expectedResponse = createOkResponse();
668 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
670 String serviceInstanceId = "testServiceId";
671 String vnfInstanceId = "testVnfInstanceId";
673 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE);
674 String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
675 vnfEndpoint = vnfEndpoint.replace(VNF_INSTANCE_ID, vnfInstanceId);
676 vnfEndpoint = vnfEndpoint.replace(REQUEST_TYPE, ChangeManagementRequest.MsoChangeManagementRequest.REPLACE);
678 given(msoInterface.replaceVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
681 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.replaceVnf(requestDetails, serviceInstanceId, vnfInstanceId);
684 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
688 public void shouldProperlyGenerateInPlaceMsoRequestWithProperParameters() {
690 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
692 requestDetails.setVnfInstanceId("testVnfInstanceId");
693 requestDetails.setVnfName("testVnfName");
694 requestDetails.setRequestParameters(new RequestParameters());
696 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
697 "\"existing_software_version\": \"testExistingSoftwareParam\"," +
698 "\"new_software_version\": \"testNewSoftwareParam\"," +
699 "\"operations_timeout\": \"100\"" +
702 RequestDetails inPlaceSoftwareUpdateRequest = new RequestDetails();
703 inPlaceSoftwareUpdateRequest.setCloudConfiguration(requestDetails.getCloudConfiguration());
704 inPlaceSoftwareUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
705 inPlaceSoftwareUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
706 org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.changeManagement.RequestDetailsWrapper();
707 requestDetailsWrapper.requestDetails = inPlaceSoftwareUpdateRequest;
710 org.onap.vid.changeManagement.RequestDetailsWrapper response = msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
713 assertThat(response).isEqualToComparingFieldByField(requestDetailsWrapper);
716 @Test(expectedExceptions = BadRequestException.class)
717 public void shouldThrowExceptionWhenGenerateInPlaceMsoRequestWithParametersWithWrongCharacters() {
719 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
721 requestDetails.setVnfInstanceId("testVnfInstanceId");
722 requestDetails.setVnfName("testVnfName");
723 requestDetails.setRequestParameters(new RequestParameters());
725 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
726 "\"existing_software_version\": \"#####\"," +
727 "\"new_software_version\": \"testNewSoftwareParam\"" +
731 msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
734 @Test(expectedExceptions = BadRequestException.class)
735 public void shouldThrowExceptionWhenGenerateInPlaceMsoRequestWithWrongParameters() {
737 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
739 requestDetails.setVnfInstanceId("testVnfInstanceId");
740 requestDetails.setVnfName("testVnfName");
741 requestDetails.setRequestParameters(new RequestParameters());
743 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
744 "\"test-wrong-parameter\": \"testParam\"," +
745 "\"new_software_version\": \"testNewSoftwareParam\"" +
749 msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
753 public void shouldProprleyGenerateConfigMsoRequestWithProperParameters() {
755 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
757 requestDetails.setVnfInstanceId("testVnfInstanceId");
758 requestDetails.setVnfName("testVnfName");
759 requestDetails.setRequestParameters(new RequestParameters());
761 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
762 "\"request-parameters\": \"testRequestParam\"," +
763 "\"configuration-parameters\": \"testConfigParams\"" +
766 RequestDetails configUpdateRequest = new RequestDetails();
767 configUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
768 configUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
770 org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.changeManagement.RequestDetailsWrapper();
771 requestDetailsWrapper.requestDetails = configUpdateRequest;
774 org.onap.vid.changeManagement.RequestDetailsWrapper response = msoBusinessLogic.generateConfigMsoRequest(requestDetails);
777 assertThat(response).isEqualToComparingFieldByField(requestDetailsWrapper);
780 @Test(expectedExceptions = BadRequestException.class)
781 public void shouldThrowExceptionGenerateConfigMsoRequestWithoutAdditionalParameters() {
783 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
785 requestDetails.setVnfInstanceId("testVnfInstanceId");
786 requestDetails.setVnfName("testVnfName");
787 requestDetails.setRequestParameters(null);
790 msoBusinessLogic.generateConfigMsoRequest(requestDetails);
793 @Test(expectedExceptions = BadRequestException.class)
794 public void shouldThrowExceptionWhenGenerateConfigMsoRequestWithWrongPayload() {
796 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
798 requestDetails.setVnfInstanceId("testVnfInstanceId");
799 requestDetails.setVnfName("testVnfName");
800 requestDetails.setRequestParameters(new RequestParameters());
802 requestDetails.getRequestParameters().setAdditionalProperty("payload", null);
805 msoBusinessLogic.generateConfigMsoRequest(requestDetails);
808 @Test(expectedExceptions = BadRequestException.class)
809 public void shouldThrowExceptionGenerateConfigMsoRequestWithoutAnyParameter() {
811 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
813 requestDetails.setVnfInstanceId("testVnfInstanceId");
814 requestDetails.setVnfName("testVnfName");
815 requestDetails.setRequestParameters(new RequestParameters());
817 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
818 "\"test-wrong-parameter\": \"testParam\"," +
819 "\"configuration-parameters\": \"testConfigParam\"" +
823 msoBusinessLogic.generateConfigMsoRequest(requestDetails);
827 public void shouldProperlyGetActivateFabricConfigurationPathWithProperParameters() {
829 String serviceInstanceId = "testServiceId";
830 String path = validateEndpointPath(MsoProperties.MSO_REST_API_SERVICE_INSTANCE_CREATE);
831 path += "/" + serviceInstanceId + "/activateFabricConfiguration";
834 String response = msoBusinessLogic.getActivateFabricConfigurationPath(serviceInstanceId);
837 assertThat(response).isEqualTo(path);
841 public void shouldProperlyGetDeactivateAndCloudDeletePathWithProperParameters() {
843 String serviceInstanceId = "testServiceId";
844 String vnfInstanceId = "testVnfInstanceId";
845 String vfModuleInstanceId = "testVfModuleInstanceId";
846 String path = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
847 path = path.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
848 path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
849 path += "/" + vfModuleInstanceId + "/deactivateAndCloudDelete";
852 String response = msoBusinessLogic.getDeactivateAndCloudDeletePath(serviceInstanceId, vnfInstanceId, vfModuleInstanceId);
855 assertThat(response).isEqualTo(path);
859 public void shouldProperlyBuildRequestDetailsForSoftDeleteWithProperParameters() {
861 SoftDeleteRequest softDeleteRequest = new SoftDeleteRequest();
862 RequestDetails requestDetails = new RequestDetails();
864 String userId = "testUserID";
865 String tenantId = "testTenantId ";
866 String cloudRegionId = "testCloudId";
869 RequestInfo requestInfo = new RequestInfo();
870 requestInfo.setSource("VID");
871 requestInfo.setRequestorId(userId);
872 requestDetails.setRequestInfo(requestInfo);
874 CloudConfiguration cloudConfiguration = new CloudConfiguration();
875 cloudConfiguration.setTenantId(tenantId);
876 cloudConfiguration.setLcpCloudRegionId(cloudRegionId);
877 requestDetails.setCloudConfiguration(cloudConfiguration);
879 setModelInfoForRequestDetails(requestDetails);
881 setRequestParametersForRequestDetails(requestDetails);
883 softDeleteRequest.setLcpCloudRegionId(cloudRegionId);
884 softDeleteRequest.setTenantId(tenantId);
885 softDeleteRequest.setUserId(userId);
888 RequestDetails response = msoBusinessLogic.buildRequestDetailsForSoftDelete(softDeleteRequest);
891 assertThat(response).isEqualTo(requestDetails);
894 private void setRequestParametersForRequestDetails(RequestDetails requestDetails) {
895 RequestParameters requestParameters = new RequestParameters();
896 requestParameters.setTestApi("GR_API");
897 requestDetails.setRequestParameters(requestParameters);
900 private void setModelInfoForRequestDetails(RequestDetails requestDetails) {
901 ModelInfo modelInfo = new ModelInfo();
902 modelInfo.setModelType("vfModule");
903 requestDetails.setModelInfo(modelInfo);
907 public void shouldProperlyDeactivateAndCloudDeleteWithProperParameters() {
909 String serviceInstanceId = "testServiceId";
910 String vnfInstanceId = "testVnfInstanceId";
911 String vfModuleInstanceId = "testVfModuleInstanceId";
912 RequestDetails requestDetails = new RequestDetails();
914 String path = msoBusinessLogic.getDeactivateAndCloudDeletePath(serviceInstanceId, vnfInstanceId, vfModuleInstanceId);
916 RequestReferences requestReferences = new RequestReferences();
917 requestReferences.setInstanceId("testInstance");
918 requestReferences.setRequestId("testRequest");
920 HttpResponse<RequestReferencesContainer> expectedResponse = HttpResponse.fallback(new RequestReferencesContainer(requestReferences));
922 MsoResponseWrapper2 responseWrapped = new MsoResponseWrapper2<>(expectedResponse);
924 given(msoInterface.post(eq(path), any(org.onap.vid.changeManagement.RequestDetailsWrapper.class), eq(RequestReferencesContainer.class))).willReturn(expectedResponse);
927 MsoResponseWrapper2 response = msoBusinessLogic.deactivateAndCloudDelete(serviceInstanceId, vnfInstanceId, vfModuleInstanceId, requestDetails);
930 assertThat(response).isEqualToComparingFieldByField(responseWrapped);
934 public void shouldProperlyActivateFabricConfigurationWithProperParameters() {
936 String serviceInstanceId = "testServiceId";
937 RequestDetails requestDetails = new RequestDetails();
939 String path = msoBusinessLogic.getActivateFabricConfigurationPath(serviceInstanceId);
941 RequestReferences requestReferences = new RequestReferences();
942 requestReferences.setInstanceId("testInstance");
943 requestReferences.setRequestId("testRequest");
945 HttpResponse<RequestReferencesContainer> expectedResponse = HttpResponse.fallback(new RequestReferencesContainer(requestReferences));
947 MsoResponseWrapper2 responseWrapped = new MsoResponseWrapper2<>(expectedResponse);
949 given(msoInterface.post(eq(path), any(org.onap.vid.changeManagement.RequestDetailsWrapper.class), eq(RequestReferencesContainer.class))).willReturn(expectedResponse);
952 MsoResponseWrapper2 response = msoBusinessLogic.activateFabricConfiguration(serviceInstanceId, requestDetails);
955 assertThat(response).isEqualToComparingFieldByField(responseWrapped);
959 public void shouldProperlyUpdateVnfSoftwareWithProperParameters() {
961 String serviceInstanceId = "testServiceId";
962 String vnfInstanceId = "testVnfInstanceId";
964 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
966 requestDetails.setVnfInstanceId("testVnfInstanceId");
967 requestDetails.setVnfName("testVnfName");
968 requestDetails.setRequestParameters(new RequestParameters());
970 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
971 "\"existing_software_version\": \"testExistingSoftwareParam\"," +
972 "\"new_software_version\": \"testNewSoftwareParam\"," +
973 "\"operations_timeout\": \"100\"" +
976 MsoResponseWrapper okResponse = createOkResponse();
978 given(msoInterface.changeManagementUpdate(isA(org.onap.vid.changeManagement.RequestDetailsWrapper.class), any(String.class))).willReturn(okResponse);
981 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnfSoftware(requestDetails, serviceInstanceId, vnfInstanceId);
984 assertThat(response).isEqualToComparingFieldByField(okResponse);
988 public void shouldProperlyUpdateVnfConfigWithProperParameters() {
990 String serviceInstanceId = "testServiceId";
991 String vnfInstanceId = "testVnfInstanceId";
993 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
995 requestDetails.setVnfInstanceId("testVnfInstanceId");
996 requestDetails.setVnfName("testVnfName");
997 requestDetails.setRequestParameters(new RequestParameters());
999 requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
1000 "\"request-parameters\": \"testRequestParam\"," +
1001 "\"configuration-parameters\": \"testConfigParams\"" +
1004 MsoResponseWrapper okResponse = createOkResponse();
1006 given(msoInterface.changeManagementUpdate(isA(org.onap.vid.changeManagement.RequestDetailsWrapper.class), any(String.class))).willReturn(okResponse);
1009 MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnfConfig(requestDetails, serviceInstanceId, vnfInstanceId);
1012 assertThat(response).isEqualToComparingFieldByField(okResponse);
1016 public void shouldProperlyDeleteConfigurationWithProperParameters() {
1018 String serviceInstanceId = "testServiceId";
1019 String configurationId = "testConfigurationId";
1021 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1023 requestDetails.setVnfInstanceId("testVnfInstanceId");
1024 requestDetails.setVnfName("testVnfName");
1026 MsoResponseWrapper okResponse = createOkResponse();
1027 RequestDetailsWrapper wrappedRequestDetail = new RequestDetailsWrapper(requestDetails);
1029 given(msoInterface.deleteConfiguration(eq(wrappedRequestDetail), any(String.class))).willReturn(okResponse);
1032 MsoResponseWrapper response = msoBusinessLogic.deleteConfiguration(wrappedRequestDetail, serviceInstanceId, configurationId);
1035 assertThat(response).isEqualToComparingFieldByField(okResponse);
1039 public void shouldProperlySetConfigurationActiveStatusActiveWithProperParameters() {
1041 String serviceInstanceId = "testServiceId";
1042 String configurationId = "testConfigurationId";
1044 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1046 requestDetails.setVnfInstanceId("testVnfInstanceId");
1047 requestDetails.setVnfName("testVnfName");
1049 MsoResponseWrapper okResponse = createOkResponse();
1052 validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1053 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1054 .replace(CONFIGURATION_ID, configurationId)
1057 given(msoInterface.setConfigurationActiveStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1060 MsoResponseWrapper response = msoBusinessLogic.setConfigurationActiveStatus(requestDetails, serviceInstanceId, configurationId, true);
1063 assertThat(response).isEqualToComparingFieldByField(okResponse);
1067 public void shouldProperlySetConfigurationActiveStatusDeactivateWithProperParameters() {
1069 String serviceInstanceId = "testServiceId";
1070 String configurationId = "testConfigurationId";
1072 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1074 requestDetails.setVnfInstanceId("testVnfInstanceId");
1075 requestDetails.setVnfName("testVnfName");
1077 MsoResponseWrapper okResponse = createOkResponse();
1080 validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1081 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1082 .replace(CONFIGURATION_ID, configurationId)
1085 given(msoInterface.setConfigurationActiveStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1088 MsoResponseWrapper response = msoBusinessLogic.setConfigurationActiveStatus(requestDetails, serviceInstanceId, configurationId, false);
1091 assertThat(response).isEqualToComparingFieldByField(okResponse);
1095 public void shouldProperlySetServiceInstanceStatusActiveWithProperParameters() {
1097 String serviceInstanceId = "testServiceId";
1099 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1101 RestObject<String> restObjStr = new RestObject<>();
1103 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
1106 MsoResponseWrapper response = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, true);
1109 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
1114 public void shouldProperlySetServiceInstanceStatusDeactivateWithProperParameters() {
1116 String serviceInstanceId = "testServiceId";
1118 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1120 RestObject<String> restObjStr = new RestObject<>();
1122 MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
1125 MsoResponseWrapper response = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, false);
1128 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
1132 @Test(expectedExceptions = MsoTestException.class)
1133 public void shouldThrowExceptionWhenSetServiceInstanceStatusWithWrongParameters() {
1135 String serviceInstanceId = "testServiceId";
1137 doThrow(new MsoTestException("testException")).
1138 when(msoInterface).setServiceInstanceStatus(eq(null), any(String.class), any(String.class), any(String.class), any(RestObject.class));
1141 msoBusinessLogic.setServiceInstanceStatus(null, serviceInstanceId, true);
1145 public void shouldProperlySetPortOnConfigurationStatusEnableWithProperParameters() {
1147 String serviceInstanceId = "testServiceId";
1148 String configurationId = "testConfigurationId";
1149 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1150 requestDetails.setVnfInstanceId("testVnfInstanceId");
1151 requestDetails.setVnfName("testVnfName");
1152 MsoResponseWrapper okResponse = createOkResponse();
1154 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1155 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1156 .replace(CONFIGURATION_ID, configurationId)
1159 given(msoInterface.setPortOnConfigurationStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1162 MsoResponseWrapper response = msoBusinessLogic.setPortOnConfigurationStatus(requestDetails, serviceInstanceId, configurationId, true);
1165 assertThat(response).isEqualToComparingFieldByField(okResponse);
1169 public void shouldProperlySetPortOnConfigurationStatusDisableWithProperParameters() {
1171 String serviceInstanceId = "testServiceId";
1172 String configurationId = "testConfigurationId";
1173 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1174 requestDetails.setVnfInstanceId("testVnfInstanceId");
1175 requestDetails.setVnfName("testVnfName");
1176 MsoResponseWrapper okResponse = createOkResponse();
1178 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
1179 .replace(SVC_INSTANCE_ID, serviceInstanceId)
1180 .replace(CONFIGURATION_ID, configurationId)
1183 given(msoInterface.setPortOnConfigurationStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
1186 MsoResponseWrapper response = msoBusinessLogic.setPortOnConfigurationStatus(requestDetails, serviceInstanceId, configurationId, false);
1189 assertThat(response).isEqualToComparingFieldByField(okResponse);
1193 public void shouldProperlyCreateOperationalEnvironmentActivationRequestDetailsWithProperParameters() {
1195 OperationalEnvironmentActivateInfo details = createTestOperationalEnvironmentActivateInfo();
1197 org.onap.vid.changeManagement.RequestDetailsWrapper<RequestDetails> requestDetails = msoBusinessLogic.createOperationalEnvironmentActivationRequestDetails(details);
1200 assertThat(requestDetails.requestDetails.getRequestParameters().getAdditionalProperties().values()).contains(details.getWorkloadContext(), details.getManifest());
1201 assertThat(requestDetails.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
1205 public void shouldProperlyGetOperationalEnvironmentActivationPathWithProperParameters() {
1207 OperationalEnvironmentActivateInfo details = createTestOperationalEnvironmentActivateInfo();
1210 String response = msoBusinessLogic.getOperationalEnvironmentActivationPath(details);
1213 assertThat(response).contains(operationalEnvironmentId);
1217 public void shouldProperlyCreateOperationalEnvironmentDeactivationRequestDetailsWithProperParameters() {
1219 OperationalEnvironmentDeactivateInfo details = createTestOperationalEnvironmentDeactivateInfo();
1222 org.onap.vid.changeManagement.RequestDetailsWrapper<RequestDetails> response;
1223 response = msoBusinessLogic.createOperationalEnvironmentDeactivationRequestDetails(details);
1226 assertThat(response.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
1230 public void shouldProperlyGetCloudResourcesRequestsStatusPathWithProperParameters() {
1232 String requestId = "testRequestId";
1235 String response = msoBusinessLogic.getCloudResourcesRequestsStatusPath(requestId);
1238 assertThat(response).contains(requestId);
1242 public void shouldProperlyGetOperationalEnvironmentDeactivationPathWithProperParameters() {
1244 OperationalEnvironmentDeactivateInfo details = createTestOperationalEnvironmentDeactivateInfo();
1247 String response = msoBusinessLogic.getOperationalEnvironmentDeactivationPath(details);
1250 assertThat(response).contains(operationalEnvironmentId);
1254 public void shouldProperlyGetOperationalEnvironmentCreationPathWithProperParameters() {
1256 String response = msoBusinessLogic.getOperationalEnvironmentCreationPath();
1259 assertThat(response).isNotBlank();
1263 public void shouldProperlyConvertParametersToRequestDetailsWithProperParameters() {
1265 OperationalEnvironmentController.OperationalEnvironmentCreateBody input = createTestOperationalEnvironmentCreateBody();
1268 org.onap.vid.changeManagement.RequestDetailsWrapper<OperationEnvironmentRequestDetails> response
1269 = msoBusinessLogic.convertParametersToRequestDetails(input, userId);
1272 assertThat(response.requestDetails.getRequestInfo().getInstanceName()).isEqualTo(input.getInstanceName());
1273 assertThat(response.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
1274 assertThat(response.requestDetails.getRequestParameters().getOperationalEnvironmentType()).isEqualTo(input.getOperationalEnvironmentType());
1275 assertThat(response.requestDetails.getRequestParameters().getTenantContext()).isEqualTo(input.getTenantContext());
1276 assertThat(response.requestDetails.getRequestParameters().getWorkloadContext()).isEqualTo(input.getWorkloadContext());
1280 public void shouldProperlyRemoveRelationshipFromServiceInstanceWithProperParameters() {
1282 MsoResponseWrapper expectedResponse = createOkResponse();
1283 String serviceInstanceId = "testServiceId";
1284 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1286 given(msoInterface.removeRelationshipFromServiceInstance(eq(requestDetails), endsWith("/" + serviceInstanceId + "/removeRelationships")))
1287 .willReturn(expectedResponse);
1290 MsoResponseWrapper response = msoBusinessLogic.removeRelationshipFromServiceInstance(requestDetails, serviceInstanceId);
1293 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
1297 public void shouldProperlyAddRelationshipToServiceInstanceWithProperParameters() {
1299 MsoResponseWrapper expectedResponse = createOkResponse();
1300 String serviceInstanceId = "testServiceId";
1301 org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
1303 given(msoInterface.addRelationshipToServiceInstance(eq(requestDetails), endsWith("/" + serviceInstanceId + "/addRelationships")))
1304 .willReturn(expectedResponse);
1307 MsoResponseWrapper response = msoBusinessLogic.addRelationshipToServiceInstance(requestDetails, serviceInstanceId);
1310 assertThat(response).isEqualToComparingFieldByField(expectedResponse);
1314 public void shouldProperlyRequestTypeFromValueWithValidParameters() {
1316 String testValue = "createInstance";
1318 MsoBusinessLogicImpl.RequestType response = MsoBusinessLogicImpl.RequestType.fromValue(testValue);
1321 assertThat(response.toString()).isEqualTo(testValue);
1324 @Test(expectedExceptions = IllegalArgumentException.class)
1325 public void shouldThrowExceptionWhenRequestTypeFromValueWithWrongParameter() {
1327 String testValue = "notExistingParameter";
1329 MsoBusinessLogicImpl.RequestType.fromValue(testValue);
1333 private OperationalEnvironmentActivateInfo createTestOperationalEnvironmentActivateInfo() {
1334 OperationalEnvironmentController.OperationalEnvironmentActivateBody operationalEnvironmentActivateBody = new OperationalEnvironmentController.OperationalEnvironmentActivateBody(
1335 "testRelatedInstanceId",
1336 "testRelatedInstanceName",
1337 "testWorkloadContext",
1338 new OperationalEnvironmentController.OperationalEnvironmentManifest()
1340 return new OperationalEnvironmentActivateInfo(operationalEnvironmentActivateBody, userId, operationalEnvironmentId);
1343 private OperationalEnvironmentDeactivateInfo createTestOperationalEnvironmentDeactivateInfo() {
1344 return new OperationalEnvironmentDeactivateInfo(userId, operationalEnvironmentId);
1347 private OperationalEnvironmentController.OperationalEnvironmentCreateBody createTestOperationalEnvironmentCreateBody() {
1348 return new OperationalEnvironmentController.OperationalEnvironmentCreateBody(
1350 "testEcompInstanceId",
1351 "testEcompInstanceName",
1352 "testOperationalEnvironmentType",
1353 "testTenantContext",
1354 "testWorkloadContext"
1358 private MsoResponseWrapper createOkResponse() {
1359 HttpStatus expectedStatus = HttpStatus.ACCEPTED;
1360 String expectedBody = " \"body\": {\n" +
1361 " \"requestReferences\": {\n" +
1362 " \"instanceId\": \" 123456 \",\n" +
1363 " \"requestId\": \"b6dc9806-b094-42f7-9386-a48de8218ce8\"\n" +
1365 MsoResponseWrapper responseWrapper = new MsoResponseWrapper();
1366 responseWrapper.setEntity(expectedBody);
1367 responseWrapper.setStatus(expectedStatus.value());
1368 return responseWrapper;
1371 private String getFileContentAsString(String resourceName) throws Exception {
1372 Path path = Paths.get("payload_jsons", resourceName);
1373 URL url = this.getClass().getClassLoader().getResource(path.toString());
1376 result = IOUtils.toString(url.toURI(), "UTF-8");
1381 private static class MsoRequestWrapperMatcher implements
1382 ArgumentMatcher<org.onap.vid.changeManagement.RequestDetailsWrapper> {
1384 private final org.onap.vid.changeManagement.RequestDetailsWrapper expectedRequest;
1386 MsoRequestWrapperMatcher(org.onap.vid.changeManagement.RequestDetailsWrapper expectedRequest) {
1387 this.expectedRequest = expectedRequest;
1391 public boolean matches(org.onap.vid.changeManagement.RequestDetailsWrapper argument) {
1392 return expectedRequest.requestDetails.equals(argument.requestDetails);
1396 private class MsoTestException extends RuntimeException {
1397 MsoTestException(String testException) {
1398 super(testException);