+ //then
+ assertThat(filteredOrchestrationReqs).hasSize(2);
+ assertThat(filteredOrchestrationReqs).extracting("taskId", "type").
+ contains(
+ tuple("123123abc", "testTask"),
+ tuple("321321abc", "testTask")
+ );
+ }
+
+ @Test(expectedExceptions = GenericUncheckedException.class)
+ public void shouldThrowGenericUncheckedExceptionWhenGetManualTasksByRequestIdWithWrongJsonFile() throws Exception {
+ //given
+ String manualTasksList = getFileContentAsString("manual_tasks_by_requestId_wrongJson_test.json");
+
+ MsoResponseWrapper msoResponseWrapperMock = mock(MsoResponseWrapper.class);
+ given(msoInterface
+ .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
+ any(RestObject.class)))
+ .willReturn(msoResponseWrapperMock);
+ given(msoResponseWrapperMock.getEntity())
+ .willReturn(manualTasksList);
+
+ //when
+ msoBusinessLogic.getManualTasksByRequestId("TestId");
+ }
+
+ @Test(expectedExceptions = MsoTestException.class)
+ public void getManualTasksByRequestIdWithArgument_shouldThrowException() {
+ //given
+ given(msoInterface
+ .getManualTasksByRequestId(any(String.class), any(String.class), any(String.class),
+ any(RestObject.class)))
+ .willThrow(MsoTestException.class);
+
+ //when
+ msoBusinessLogic.getManualTasksByRequestId("TestId");
+ }
+
+ @Test
+ public void shouldProperlyCompleteManualTaskWithProperParameters() {
+ //given
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ RequestDetails requestDetails = new RequestDetails();
+ String taskId = "testTaskId";
+
+ String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
+ String path = url + "/" + taskId + "/complete";
+
+ given(msoInterface.completeManualTask(eq(requestDetails), any(String.class), any(String.class), eq(path), any(RestObject.class))).willReturn(expectedResponse);
+
+ //when
+ MsoResponseWrapper response = msoBusinessLogic.completeManualTask(requestDetails, taskId);
+
+ //then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+
+ }
+
+ @Test
+ public void shouldProperlyActivateServiceInstanceWithProperParameters() {
+ //given
+ RequestDetails detail = new RequestDetails();
+ String taskId = "testTaskId";
+
+ RestObject<String> restObjStr = new RestObject<>();
+ restObjStr.set("");
+ MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
+
+ //when
+ MsoResponseWrapper response = msoBusinessLogic.activateServiceInstance(detail, taskId);
+
+ //then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+
+ }
+
+ @Test(expectedExceptions = MsoTestException.class)
+ public void shouldThrowExceptionWhenManualTaskWithWrongParameters() {
+ //given
+ RequestDetails requestDetails = new RequestDetails();
+ String taskId = "";
+
+ String url = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
+ String path = url + "/" + taskId + "/complete";
+
+ given(msoInterface.completeManualTask(eq(requestDetails), any(String.class), any(String.class), eq(path), any(RestObject.class))).willThrow(new MsoTestException("empty path"));
+
+ //when
+ msoBusinessLogic.completeManualTask(requestDetails, taskId);
+ }
+
+ @Test
+ public void shouldProperlyUpdateVnfWithProperParameters() {
+ //given
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ String serviceInstanceId = "testServiceId";
+ String vnfInstanceId = "testVnfInstanceId";
+
+ String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
+ String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ vnfEndpoint = vnfEndpoint + '/' + vnfInstanceId;
+
+ given(msoInterface.updateVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
+
+ //when
+ MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnf(requestDetails, serviceInstanceId, vnfInstanceId);
+
+ //then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyReplaceVnfWithProperParameters() {
+ //given
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ String serviceInstanceId = "testServiceId";
+ String vnfInstanceId = "testVnfInstanceId";
+
+ String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE);
+ String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ vnfEndpoint = vnfEndpoint.replace(VNF_INSTANCE_ID, vnfInstanceId);
+ vnfEndpoint = vnfEndpoint.replace(REQUEST_TYPE, ChangeManagementRequest.MsoChangeManagementRequest.REPLACE);
+
+ given(msoInterface.replaceVnf(requestDetails, vnfEndpoint)).willReturn(expectedResponse);
+
+ //when
+ MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.replaceVnf(requestDetails, serviceInstanceId, vnfInstanceId);
+
+ //then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyGenerateInPlaceMsoRequestWithProperParameters() {
+ //given
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
+ "\"existing_software_version\": \"testExistingSoftwareParam\"," +
+ "\"new_software_version\": \"testNewSoftwareParam\"," +
+ "\"operations_timeout\": \"100\"" +
+ "}");
+
+ RequestDetails inPlaceSoftwareUpdateRequest = new RequestDetails();
+ inPlaceSoftwareUpdateRequest.setCloudConfiguration(requestDetails.getCloudConfiguration());
+ inPlaceSoftwareUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
+ inPlaceSoftwareUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
+ org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.changeManagement.RequestDetailsWrapper();
+ requestDetailsWrapper.requestDetails = inPlaceSoftwareUpdateRequest;
+
+ //when
+ org.onap.vid.changeManagement.RequestDetailsWrapper response = msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
+
+ //then
+ assertThat(response).isEqualToComparingFieldByField(requestDetailsWrapper);
+ }
+
+ @Test(expectedExceptions = BadRequestException.class)
+ public void shouldThrowExceptionWhenGenerateInPlaceMsoRequestWithParametersWithWrongCharacters() {
+ //given
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
+ "\"existing_software_version\": \"#####\"," +
+ "\"new_software_version\": \"testNewSoftwareParam\"" +
+ "}");
+
+ //when
+ msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
+ }
+
+ @Test(expectedExceptions = BadRequestException.class)
+ public void shouldThrowExceptionWhenGenerateInPlaceMsoRequestWithWrongParameters() {
+ //given
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
+ "\"test-wrong-parameter\": \"testParam\"," +
+ "\"new_software_version\": \"testNewSoftwareParam\"" +
+ "}");
+
+ //when
+ msoBusinessLogic.generateInPlaceMsoRequest(requestDetails);
+ }
+
+ @Test
+ public void shouldProprleyGenerateConfigMsoRequestWithProperParameters() {
+ //given
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
+ "\"request-parameters\": \"testRequestParam\"," +
+ "\"configuration-parameters\": \"testConfigParams\"" +
+ "}");
+
+ RequestDetails configUpdateRequest = new RequestDetails();
+ configUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
+ configUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
+
+ org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.changeManagement.RequestDetailsWrapper();
+ requestDetailsWrapper.requestDetails = configUpdateRequest;
+
+ //when
+ org.onap.vid.changeManagement.RequestDetailsWrapper response = msoBusinessLogic.generateConfigMsoRequest(requestDetails);
+
+ //then
+ assertThat(response).isEqualToComparingFieldByField(requestDetailsWrapper);
+ }
+
+ @Test(expectedExceptions = BadRequestException.class)
+ public void shouldThrowExceptionGenerateConfigMsoRequestWithoutAdditionalParameters() {
+ //given
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(null);
+
+ //when
+ msoBusinessLogic.generateConfigMsoRequest(requestDetails);
+ }
+
+ @Test(expectedExceptions = BadRequestException.class)
+ public void shouldThrowExceptionWhenGenerateConfigMsoRequestWithWrongPayload() {
+ //given
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", null);
+
+ //when
+ msoBusinessLogic.generateConfigMsoRequest(requestDetails);
+ }
+
+ @Test(expectedExceptions = BadRequestException.class)
+ public void shouldThrowExceptionGenerateConfigMsoRequestWithoutAnyParameter() {
+ //given
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
+ "\"test-wrong-parameter\": \"testParam\"," +
+ "\"configuration-parameters\": \"testConfigParam\"" +
+ "}");
+
+ //when
+ msoBusinessLogic.generateConfigMsoRequest(requestDetails);
+ }
+
+ @Test
+ public void shouldProperlyGetActivateFabricConfigurationPathWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String path = validateEndpointPath(MsoProperties.MSO_RESTAPI_SERVICE_INSTANCE);
+ path += "/" + serviceInstanceId + "/activateFabricConfiguration";
+
+ // when
+ String response = msoBusinessLogic.getActivateFabricConfigurationPath(serviceInstanceId);
+
+ // then
+ assertThat(response).isEqualTo(path);
+ }
+
+ @Test
+ public void shouldProperlyGetDeactivateAndCloudDeletePathWithProperParameters() {
+
+ // when
+ String response = msoBusinessLogic.getDeactivateAndCloudDeletePath("testServiceId", "testVnfInstanceId", "testVfModuleInstanceId");
+
+ // then
+ String expectedPath = "/serviceInstantiation/v7/serviceInstances/testServiceId/vnfs/testVnfInstanceId/"+
+ "vfModules/testVfModuleInstanceId/deactivateAndCloudDelete";
+ assertThat(response).isEqualTo(expectedPath);
+ }
+
+ @Test
+ public void shouldProperlyBuildRequestDetailsForSoftDeleteWithProperParameters() throws IOException {
+ SoftDeleteRequest request = new SoftDeleteRequest("testTenantId", "testCloudId", "testUserID");
+ String expected = IOUtils.toString(this.getClass().getResource("/payload_jsons/vfModuleDeactivateAndCloudDelete.json"), "UTF-8");
+ final RequestDetails result = msoBusinessLogic.buildRequestDetailsForSoftDelete(request);
+ MatcherAssert.assertThat(result, jsonEquals(expected));
+ }
+
+ private void setRequestParametersForRequestDetails(RequestDetails requestDetails) {
+ RequestParameters requestParameters = new RequestParameters();
+ requestParameters.setTestApi("GR_API");
+ requestDetails.setRequestParameters(requestParameters);
+ }
+
+ private void setModelInfoForRequestDetails(RequestDetails requestDetails) {
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelType("vfModule");
+ requestDetails.setModelInfo(modelInfo);
+ }
+
+ @Test
+ public void shouldProperlyUpdateVnfSoftwareWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String vnfInstanceId = "testVnfInstanceId";
+
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
+ "\"existing_software_version\": \"testExistingSoftwareParam\"," +
+ "\"new_software_version\": \"testNewSoftwareParam\"," +
+ "\"operations_timeout\": \"100\"" +
+ "}");
+
+ MsoResponseWrapper okResponse = createOkResponse();
+
+ given(msoInterface.changeManagementUpdate(isA(org.onap.vid.changeManagement.RequestDetailsWrapper.class), any(String.class))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnfSoftware(requestDetails, serviceInstanceId, vnfInstanceId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlyUpdateVnfConfigWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String vnfInstanceId = "testVnfInstanceId";
+
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ requestDetails.setRequestParameters(new RequestParameters());
+
+ requestDetails.getRequestParameters().setAdditionalProperty("payload", "{" +
+ "\"request-parameters\": \"testRequestParam\"," +
+ "\"configuration-parameters\": \"testConfigParams\"" +
+ "}");
+
+ MsoResponseWrapper okResponse = createOkResponse();
+
+ given(msoInterface.changeManagementUpdate(isA(org.onap.vid.changeManagement.RequestDetailsWrapper.class), any(String.class))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = (MsoResponseWrapper) msoBusinessLogic.updateVnfConfig(requestDetails, serviceInstanceId, vnfInstanceId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlyDeleteConfigurationWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String configurationId = "testConfigurationId";
+
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+
+ MsoResponseWrapper okResponse = createOkResponse();
+ RequestDetailsWrapper wrappedRequestDetail = new RequestDetailsWrapper(requestDetails);
+
+ given(msoInterface.deleteConfiguration(eq(wrappedRequestDetail), any(String.class))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.deleteConfiguration(wrappedRequestDetail, serviceInstanceId, configurationId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlySetConfigurationActiveStatusActiveWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String configurationId = "testConfigurationId";
+
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+
+ MsoResponseWrapper okResponse = createOkResponse();
+
+ String endpoint =
+ validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
+ .replace(SVC_INSTANCE_ID, serviceInstanceId)
+ .replace(CONFIGURATION_ID, configurationId)
+ + "/activate";
+
+ given(msoInterface.setConfigurationActiveStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.setConfigurationActiveStatus(requestDetails, serviceInstanceId, configurationId, true);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlySetConfigurationActiveStatusDeactivateWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String configurationId = "testConfigurationId";
+
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+
+ MsoResponseWrapper okResponse = createOkResponse();
+
+ String endpoint =
+ validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
+ .replace(SVC_INSTANCE_ID, serviceInstanceId)
+ .replace(CONFIGURATION_ID, configurationId)
+ + "/deactivate";
+
+ given(msoInterface.setConfigurationActiveStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.setConfigurationActiveStatus(requestDetails, serviceInstanceId, configurationId, false);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlySetServiceInstanceStatusActiveWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ MsoResponseWrapper okResponse = createOkResponse();
+
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ given(msoInterface.setServiceInstanceStatus(eq(requestDetails), endsWith(serviceInstanceId + "/activate"))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, true);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlySetServiceInstanceStatusDeactivateWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ MsoResponseWrapper okResponse = createOkResponse();
+
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ given(msoInterface.setServiceInstanceStatus(eq(requestDetails), endsWith(serviceInstanceId + "/deactivate"))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, false);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test(expectedExceptions = MsoTestException.class)
+ public void shouldThrowExceptionWhenSetServiceInstanceStatusWithWrongParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+
+ doThrow(new MsoTestException("testException")).
+ when(msoInterface).setServiceInstanceStatus(eq(null), any(String.class));
+
+ // when
+ msoBusinessLogic.setServiceInstanceStatus(null, serviceInstanceId, true);
+ }
+
+ @Test
+ public void shouldProperlySetPortOnConfigurationStatusEnableWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String configurationId = "testConfigurationId";
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ MsoResponseWrapper okResponse = createOkResponse();
+
+ String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
+ .replace(SVC_INSTANCE_ID, serviceInstanceId)
+ .replace(CONFIGURATION_ID, configurationId)
+ + "/enablePort";
+
+ given(msoInterface.setPortOnConfigurationStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.setPortOnConfigurationStatus(requestDetails, serviceInstanceId, configurationId, true);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlySetPortOnConfigurationStatusDisableWithProperParameters() {
+ // given
+ String serviceInstanceId = "testServiceId";
+ String configurationId = "testConfigurationId";
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+ requestDetails.setVnfInstanceId("testVnfInstanceId");
+ requestDetails.setVnfName("testVnfName");
+ MsoResponseWrapper okResponse = createOkResponse();
+
+ String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE)
+ .replace(SVC_INSTANCE_ID, serviceInstanceId)
+ .replace(CONFIGURATION_ID, configurationId)
+ + "/disablePort";
+
+ given(msoInterface.setPortOnConfigurationStatus(eq(requestDetails), eq(endpoint))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.setPortOnConfigurationStatus(requestDetails, serviceInstanceId, configurationId, false);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+ @Test
+ public void shouldProperlyCreateOperationalEnvironmentActivationRequestDetailsWithProperParameters() {
+ // given
+ OperationalEnvironmentActivateInfo details = createTestOperationalEnvironmentActivateInfo();
+ // when
+ org.onap.vid.changeManagement.RequestDetailsWrapper<RequestDetails> requestDetails = msoBusinessLogic.createOperationalEnvironmentActivationRequestDetails(details);
+
+ // then
+ assertThat(requestDetails.requestDetails.getRequestParameters().getAdditionalProperties().values()).contains(details.getWorkloadContext(), details.getManifest());
+ assertThat(requestDetails.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
+ }
+
+ @Test
+ public void shouldProperlyGetOperationalEnvironmentActivationPathWithProperParameters() {
+ // given
+ OperationalEnvironmentActivateInfo details = createTestOperationalEnvironmentActivateInfo();
+
+ // when
+ String response = msoBusinessLogic.getOperationalEnvironmentActivationPath(details);
+
+ // then
+ assertThat(response).contains(operationalEnvironmentId);
+ }
+
+ @Test
+ public void shouldProperlyCreateOperationalEnvironmentDeactivationRequestDetailsWithProperParameters() {
+ // given
+ OperationalEnvironmentDeactivateInfo details = createTestOperationalEnvironmentDeactivateInfo();
+
+ // when
+ org.onap.vid.changeManagement.RequestDetailsWrapper<RequestDetails> response;
+ response = msoBusinessLogic.createOperationalEnvironmentDeactivationRequestDetails(details);
+
+ // then
+ assertThat(response.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
+ }
+
+ @Test
+ public void shouldProperlyGetCloudResourcesRequestsStatusPathWithProperParameters() {
+ // given
+ String requestId = "testRequestId";
+
+ // when
+ String response = msoBusinessLogic.getCloudResourcesRequestsStatusPath(requestId);
+
+ // then
+ assertThat(response).contains(requestId);
+ }
+
+ @Test
+ public void shouldProperlyGetOperationalEnvironmentDeactivationPathWithProperParameters() {
+ // given
+ OperationalEnvironmentDeactivateInfo details = createTestOperationalEnvironmentDeactivateInfo();
+
+ // when
+ String response = msoBusinessLogic.getOperationalEnvironmentDeactivationPath(details);
+
+ // then
+ assertThat(response).contains(operationalEnvironmentId);
+ }
+
+ @Test
+ public void shouldProperlyGetOperationalEnvironmentCreationPathWithProperParameters() {
+ // when
+ String response = msoBusinessLogic.getOperationalEnvironmentCreationPath();
+
+ // then
+ assertThat(response).isNotBlank();
+ }
+
+ @Test
+ public void shouldProperlyConvertParametersToRequestDetailsWithProperParameters() {
+ // given
+ OperationalEnvironmentController.OperationalEnvironmentCreateBody input = createTestOperationalEnvironmentCreateBody();
+
+ // when
+ org.onap.vid.changeManagement.RequestDetailsWrapper<OperationEnvironmentRequestDetails> response
+ = msoBusinessLogic.convertParametersToRequestDetails(input, userId);
+
+ // then
+ assertThat(response.requestDetails.getRequestInfo().getInstanceName()).isEqualTo(input.getInstanceName());
+ assertThat(response.requestDetails.getRequestInfo().getRequestorId()).isEqualTo(userId);
+ assertThat(response.requestDetails.getRequestParameters().getOperationalEnvironmentType()).isEqualTo(input.getOperationalEnvironmentType());
+ assertThat(response.requestDetails.getRequestParameters().getTenantContext()).isEqualTo(input.getTenantContext());
+ assertThat(response.requestDetails.getRequestParameters().getWorkloadContext()).isEqualTo(input.getWorkloadContext());
+ }
+
+ @Test
+ public void shouldProperlyRemoveRelationshipFromServiceInstanceWithProperParameters() {
+ // given
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String serviceInstanceId = "testServiceId";
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ given(msoInterface.removeRelationshipFromServiceInstance(eq(requestDetails), endsWith("/" + serviceInstanceId + "/removeRelationships")))
+ .willReturn(expectedResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.removeRelationshipFromServiceInstance(requestDetails, serviceInstanceId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyAddRelationshipToServiceInstanceWithProperParameters() {
+ // given
+ MsoResponseWrapper expectedResponse = createOkResponse();
+ String serviceInstanceId = "testServiceId";
+ org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
+
+ given(msoInterface.addRelationshipToServiceInstance(eq(requestDetails), endsWith("/" + serviceInstanceId + "/addRelationships")))
+ .willReturn(expectedResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.addRelationshipToServiceInstance(requestDetails, serviceInstanceId);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(expectedResponse);
+ }
+
+ @Test
+ public void shouldProperlyRequestTypeFromValueWithValidParameters() {
+ // given
+ String testValue = "createInstance";
+ // when
+ MsoBusinessLogicImpl.RequestType response = MsoBusinessLogicImpl.RequestType.fromValue(testValue);
+
+ // then
+ assertThat(response.toString()).isEqualTo(testValue);
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void shouldThrowExceptionWhenRequestTypeFromValueWithWrongParameter() {
+ // given
+ String testValue = "notExistingParameter";
+ // when
+ MsoBusinessLogicImpl.RequestType.fromValue(testValue);
+ }
+
+ @Test
+ public void shouldProperlyInvokeVnfWorkflowWithValidParameters() {
+ // given
+ MsoResponseWrapper okResponse = createOkResponse();
+ WorkflowRequestDetail request = createWorkflowRequestDetail();
+ UUID serviceInstanceId = new UUID(1,10);
+ UUID vnfInstanceId = new UUID(2,20);
+ UUID workflow_UUID = new UUID(3,30);
+ String path = "/instanceManagement/v1/serviceInstances/"+serviceInstanceId+"/vnfs/"+vnfInstanceId+"/workflows/"+workflow_UUID;
+
+ given(msoInterface.invokeWorkflow(eq(request), eq(path), MockitoHamcrest.argThat(allOf(hasEntry("X-RequestorID", "testRequester"),hasEntry("X-ONAP-PartnerName", "VID"))))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.invokeVnfWorkflow(request, "testRequester", serviceInstanceId, vnfInstanceId, workflow_UUID);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+
+ @Test
+ public void shouldReturnWorkflowListForGivenModelId() {
+ given(msoInterface.getWorkflowListByModelId(anyString())).willReturn(workflowListResponse);
+ given(workflowListResponse.getBody()).willReturn(workflowList);
+ given(workflowListResponse.getStatus()).willReturn(HttpStatus.ACCEPTED.value());
+
+ SOWorkflowList workflows = msoBusinessLogic.getWorkflowListByModelId("sampleModelId");
+
+ assertThat(workflows).isEqualTo(workflowList);
+ }
+
+ @Test(expectedExceptions = {MsoBusinessLogicImpl.WorkflowListException.class})
+ public void shouldRaiseExceptionWhenRetrievingWorkflowsFailed() {
+ given(msoInterface.getWorkflowListByModelId(anyString())).willReturn(workflowListResponse);
+ given(workflowListResponse.getStatus()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR.value());
+
+ msoBusinessLogic.getWorkflowListByModelId("sampleModelId");
+ }
+
+
+ @Test
+ public void probeShouldReturnOrchestrationRequestsAndConnectionStatus(){
+ String body =
+ "{"
+ + " \"requestList\":"
+ + " [{"
+ + " \"request\": {}"
+ + " }"
+ + " ]"
+ + "}";
+ mockForGetOrchestrationRequest(200, body);
+
+ ExternalComponentStatus externalComponentStatus = msoBusinessLogic.probeComponent();
+
+ assertThat(externalComponentStatus.isAvailable()).isTrue();
+ assertThat(externalComponentStatus.getComponent()).isEqualTo(ExternalComponentStatus.Component.MSO);
+ }
+
+ private WorkflowRequestDetail createWorkflowRequestDetail() {
+ WorkflowRequestDetail workflowRequestDetail = new WorkflowRequestDetail();
+ org.onap.vid.changeManagement.RequestParameters requestParameters = new org.onap.vid.changeManagement.RequestParameters();
+ HashMap<String,String> paramsMap = new HashMap<>();
+ paramsMap.put("testKey1","testValue1");
+ paramsMap.put("testKey2","testValue2");
+
+ List<Map<String,String>> mapArray= new ArrayList<>();
+ mapArray.add(paramsMap);
+ requestParameters.setUserParams(mapArray);
+
+ CloudConfiguration cloudConfiguration = new CloudConfiguration();
+ cloudConfiguration.setCloudOwner("testOwne");
+ cloudConfiguration.setTenantId("testId");
+ cloudConfiguration.setLcpCloudRegionId("testLcpCloudId");
+
+ workflowRequestDetail.setRequestParameters(requestParameters);
+ workflowRequestDetail.setCloudConfiguration(cloudConfiguration);
+ return workflowRequestDetail;
+ }
+
+ private OperationalEnvironmentActivateInfo createTestOperationalEnvironmentActivateInfo() {
+ OperationalEnvironmentController.OperationalEnvironmentActivateBody operationalEnvironmentActivateBody = new OperationalEnvironmentController.OperationalEnvironmentActivateBody(
+ "testRelatedInstanceId",
+ "testRelatedInstanceName",
+ "testWorkloadContext",
+ new OperationalEnvironmentController.OperationalEnvironmentManifest()
+ );
+ return new OperationalEnvironmentActivateInfo(operationalEnvironmentActivateBody, userId, operationalEnvironmentId);
+ }
+
+ private OperationalEnvironmentDeactivateInfo createTestOperationalEnvironmentDeactivateInfo() {
+ return new OperationalEnvironmentDeactivateInfo(userId, operationalEnvironmentId);
+ }
+
+ private OperationalEnvironmentController.OperationalEnvironmentCreateBody createTestOperationalEnvironmentCreateBody() {
+ return new OperationalEnvironmentController.OperationalEnvironmentCreateBody(
+ "testInstanceName",
+ "testEcompInstanceId",
+ "testEcompInstanceName",
+ "testOperationalEnvironmentType",
+ "testTenantContext",
+ "testWorkloadContext"
+ );
+ }
+
+ private MsoResponseWrapper createOkResponse() {
+ HttpStatus expectedStatus = HttpStatus.ACCEPTED;
+ String expectedBody = " \"body\": {\n" +
+ " \"requestReferences\": {\n" +
+ " \"instanceId\": \" 123456 \",\n" +
+ " \"requestId\": \"b6dc9806-b094-42f7-9386-a48de8218ce8\"\n" +
+ " }";
+ MsoResponseWrapper responseWrapper = new MsoResponseWrapper();
+ responseWrapper.setEntity(expectedBody);
+ responseWrapper.setStatus(expectedStatus.value());
+ return responseWrapper;
+ }
+
+ private String getFileContentAsString(String resourceName) throws Exception {
+ Path path = Paths.get("payload_jsons", resourceName);
+ URL url = this.getClass().getClassLoader().getResource(path.toString());
+ String result = "";
+ if (url != null) {
+ result = IOUtils.toString(url.toURI(), "UTF-8");
+ }
+ return result;
+ }
+
+ private static class MsoRequestWrapperMatcher implements
+ ArgumentMatcher<org.onap.vid.changeManagement.RequestDetailsWrapper> {
+
+ private final org.onap.vid.changeManagement.RequestDetailsWrapper expectedRequest;
+
+ MsoRequestWrapperMatcher(org.onap.vid.changeManagement.RequestDetailsWrapper expectedRequest) {
+ this.expectedRequest = expectedRequest;
+ }
+
+ @Override
+ public boolean matches(org.onap.vid.changeManagement.RequestDetailsWrapper argument) {
+ return expectedRequest.requestDetails.equals(argument.requestDetails);
+ }
+ }
+
+ private class MsoTestException extends RuntimeException {
+ MsoTestException(String testException) {
+ super(testException);
+ }
+ }
+
+ //you need to add mocks to httpResponse
+ private HttpResponse<String> mockForGetOrchestrationRequest() {
+
+ HttpResponse<String> httpResponse = mock(HttpResponse.class);
+ HttpResponseWithRequestInfo<String> httpResponseWithRequestInfo = new HttpResponseWithRequestInfo<>(httpResponse, MY_PRETTY_URL, HttpMethod.GET);
+ when(msoInterface.getOrchestrationRequest(any(String.class),anyBoolean()))
+ .thenReturn(httpResponseWithRequestInfo);
+ return httpResponse;
+ }
+
+ private HttpResponse<String> mockForGetOrchestrationRequest(int statusCode, String body) {
+
+ HttpResponse<String> httpResponse = mockForGetOrchestrationRequest();
+ when(httpResponse.getStatus()).thenReturn(statusCode);
+ when(httpResponse.getBody()).thenReturn(body);
+ TestUtils.mockGetRawBodyWithStringBody(httpResponse, body);
+ return httpResponse;
+ }
+
+ @Test
+ public void probeComponent_verifyGoodRequest(){
+ String responseString = "" +
+ "{ " +
+ " \"requestList\": [{ " +
+ " \"request\": { " +
+ " \"requestDetails\": { " +
+ " \"cloudConfiguration\": { " +
+ " \"lcpCloudRegionId\": \"hvf6\", " +
+ " \"cloudOwner\": \"irma-aic\", " +
+ " \"tenantId\": \"ffdf52b5e5104b0e8f329b0b1637ee2e\" " +
+ " }, " +
+ " \"modelInfo\": { " +
+ " \"modelCustomizationName\": \"VSP1710PID298109_vWINIFRED 0\", " +
+ " \"modelCustomizationId\": \"24d43fdb-9aa6-4287-a68e-1e702ea89d13\", " +
+ " \"modelInvariantId\": \"e7961100-cde6-4b5a-bcda-b8945086950a\", " +
+ " \"modelVersionId\": \"959a7ba0-89ee-4984-9af6-65d5bdda4b0e\", " +
+ " \"modelName\": \"VSP1710PID298109_vWINIFRED\", " +
+ " \"modelType\": \"vnf\", " +
+ " \"modelVersion\": \"1.0\" " +
+ " }, " +
+ " \"relatedModelList\": [{ " +
+ " \"relatedInstance\": { " +
+ " \"instanceId\": \"6dd0f8de-93c7-48a2-914b-1a8d58e0eb48\", " +
+ " \"modelInfo\": { " +
+ " \"modelInvariantId\": \"57e00952-0af7-4f0f-b19a-408a6f73c8df\", " +
+ " \"modelType\": \"service\", " +
+ " \"modelName\": \"ServicevWINIFREDPID298109\", " +
+ " \"modelVersion\": \"1.0\", " +
+ " \"modelVersionId\": \"fe6985cd-ea33-3346-ac12-ab121484a3fe\" " +
+ " } " +
+ " } " +
+ " } " +
+ " ], " +
+ " \"requestInfo\": { " +
+ " \"source\": \"VID\", " +
+ " \"suppressRollback\": false, " +
+ " \"requestorId\": \"ds828e\" " +
+ " }, " +
+ " \"requestParameters\": { " +
+ " \"userParams\": [ " +
+ " ], " +
+ " \"aLaCarte\": false, " +
+ " \"usePreload\": true, " +
+ " \"rebuildVolumeGroups\": false, " +
+ " \"autoBuildVfModules\": false, " +
+ " \"cascadeDelete\": false " +
+ " }, " +
+ " \"relatedInstanceList\": [{ " +
+ " \"relatedInstance\": { " +
+ " \"instanceId\": \"6dd0f8de-93c7-48a2-914b-1a8d58e0eb48\", " +
+ " \"modelInfo\": { " +
+ " \"modelInvariantId\": \"57e00952-0af7-4f0f-b19a-408a6f73c8df\", " +
+ " \"modelType\": \"service\", " +
+ " \"modelName\": \"ServicevWINIFREDPID298109\", " +
+ " \"modelVersion\": \"1.0\", " +
+ " \"modelVersionId\": \"fe6985cd-ea33-3346-ac12-ab121484a3fe\" " +
+ " } " +
+ " } " +
+ " } " +
+ " ] " +
+ " }, " +
+ " \"requestId\": \"d352c70d-5ef8-4977-9ea8-4c8cbe860422\", " +
+ " \"requestScope\": \"vnf\", " +
+ " \"requestStatus\": { " +
+ " \"percentProgress\": 100.0, " +
+ " \"requestState\": \"Some Unknown Value\", " +
+ " \"statusMessage\": \"Update Is In Progress\", " +
+ " \"finishTime\": \"Fri, 08 Sep 2017 19:34:33 GMT\" " +
+ " }, " +
+ " \"requestType\": \"updateInstance\", " +
+ " \"startTime\": \"<IN_PROGRESS_DATE>\", " +
+ " \"instanceReferences\": { " +
+ " \"serviceInstanceId\": \"6dd0f8de-93c7-48a2-914b-1a8d58e0eb48\", " +
+ " \"vnfInstanceId\": \"7c00cc1e-6425-4fc3-afc3-0289db288d4c\", " +
+ " \"requestorId\": \"ds828e\" " +
+ " } " +
+ " } " +
+ " } " +
+ " ] " +
+ "} ";
+
+ mockForGetOrchestrationRequest(200, responseString);
+
+ final ExternalComponentStatus msoStatus = msoBusinessLogic.probeComponent();
+
+ assertMsoStatus(msoStatus, true);
+ assertMetadata(msoStatus, 200, startsWith(responseString.substring(0, 400)), MY_PRETTY_URL, equalTo("OK"));
+ }
+
+ @Test
+ public void probeComponent_response200OkButEmptyPayload_shouldDescribeCorrectly() {
+ String responseString = "" +
+ "{ " +
+ " \"requestList\": []" +
+ "}";
+
+ mockForGetOrchestrationRequest(200, responseString);
+
+ final ExternalComponentStatus msoStatus = msoBusinessLogic.probeComponent();
+
+ assertMsoStatus(msoStatus, true);
+
+ assertMetadata(msoStatus, 200, equalTo(responseString), MY_PRETTY_URL, containsString("OK"));
+ }
+
+ @Test
+ public void probeComponent_response200OkButInvalidPayload_shouldDescribeCorrectly() {
+ String responseString = "this payload is an invalid json";
+
+ mockForGetOrchestrationRequest(200, responseString);
+
+ final ExternalComponentStatus msoStatus = msoBusinessLogic.probeComponent();
+
+ assertMsoStatus(msoStatus, false);
+
+ assertMetadata(msoStatus, 200, equalTo(responseString), MY_PRETTY_URL, containsString("JsonParseException: Unrecognized token"));
+ }
+
+ @Test
+ public void probeComponent_verifyResponse406() {
+ String responseString = "my raw data";
+
+ when(msoInterface.getOrchestrationRequest(any(), eq(true))).thenThrow(
+ new ExceptionWithRequestInfo(HttpMethod.GET, MY_PRETTY_URL, responseString, 406,
+ new GenericUncheckedException(
+ new HttpException("Simulating as 406 was returned (200 or 202 expected)"))));
+
+ final ExternalComponentStatus msoStatus = msoBusinessLogic.probeComponent();
+
+ assertMsoStatus(msoStatus, false);
+
+ assertMetadata(msoStatus, 406, equalTo(responseString), MY_PRETTY_URL, containsString("HttpException: Simulating as 406 was returned"));
+ }
+
+
+ @Test
+ public void probeComponent_throwNullPointerException_resultIsWithErrorMetadata() {
+ when(msoInterface.getOrchestrationRequest(any(), eq(true))).thenThrow(new NullPointerException());
+
+ final ExternalComponentStatus msoStatus = msoBusinessLogic.probeComponent();
+
+ MatcherAssert.assertThat(msoStatus.isAvailable(), is(false));
+ MatcherAssert.assertThat(msoStatus.getComponent(), is(MSO));
+ MatcherAssert.assertThat(msoStatus.getMetadata(), instanceOf(ErrorMetadata.class));
+
+ final ErrorMetadata metadata = ((ErrorMetadata) msoStatus.getMetadata());
+ org.junit.Assert.assertThat(metadata.getDescription(), containsString("NullPointerException"));
+ }
+
+ private void assertMsoStatus(ExternalComponentStatus msoStatus, boolean isAvailable) {
+ MatcherAssert.assertThat(msoStatus.isAvailable(), is(isAvailable));
+ MatcherAssert.assertThat(msoStatus.getComponent(), is(MSO));
+ MatcherAssert.assertThat(msoStatus.getMetadata(), instanceOf(HttpRequestMetadata.class));
+ }
+
+ private void assertMetadata(ExternalComponentStatus msoStatus, int httpCode, Matcher<String> rawData, String url, Matcher<String> descriptionMatcher) {
+ final HttpRequestMetadata metadata = ((HttpRequestMetadata) msoStatus.getMetadata());
+ org.junit.Assert.assertThat(metadata.getHttpMethod(), equalTo(HttpMethod.GET));
+ org.junit.Assert.assertThat(metadata.getHttpCode(), equalTo(httpCode));
+ org.junit.Assert.assertThat(metadata.getUrl(), equalTo(url));
+ org.junit.Assert.assertThat(metadata.getRawData(), rawData);
+ org.junit.Assert.assertThat(metadata.getDescription(), descriptionMatcher);