From b168125f237629b6dd7d73897548f2ee70139ed3 Mon Sep 17 00:00:00 2001 From: Lathish Date: Wed, 3 Apr 2019 14:29:14 +0000 Subject: Added Delete Job Monitoring Issue-ID: SO-1729 Change-Id: Ied97d2aafc481cf3fcdc27ee3b4e798c4fb86df4 Signed-off-by: Lathish --- .../subprocess/BuildingBlock/EtsiVnfDeleteBB.bpmn | 36 +++-- .../BuildingBlock/MonitorVnfmDeleteJob.bpmn | 160 +++++++++++++++++++ .../vnfm/tasks/MonitorVnfmCreateJobTask.java | 59 +------ .../vnfm/tasks/MonitorVnfmDeleteJobTask.java | 101 ++++++++++++ .../adapter/vnfm/tasks/MonitorVnfmJobTask.java | 104 +++++++++++++ .../vnfm/tasks/MonitorVnfmDeleteJobTaskTest.java | 173 +++++++++++++++++++++ 6 files changed, 568 insertions(+), 65 deletions(-) create mode 100644 bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/MonitorVnfmDeleteJob.bpmn create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmDeleteJobTask.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmJobTask.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmDeleteJobTaskTest.java (limited to 'bpmn') diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/EtsiVnfDeleteBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/EtsiVnfDeleteBB.bpmn index 7f70cc5756..cfb376c961 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/EtsiVnfDeleteBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/EtsiVnfDeleteBB.bpmn @@ -1,38 +1,56 @@ - + SequenceFlow_01pwrcr - + SequenceFlow_01pwrcr SequenceFlow_1064iul - SequenceFlow_1064iul + SequenceFlow_0qt5cvg - - + + + + + + + + + + SequenceFlow_1064iul + SequenceFlow_0qt5cvg + + - + - + - + - + + + + + + + + diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/MonitorVnfmDeleteJob.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/MonitorVnfmDeleteJob.bpmn new file mode 100644 index 0000000000..acd55e4fc2 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/MonitorVnfmDeleteJob.bpmn @@ -0,0 +1,160 @@ + + + + + SequenceFlow_1x3tbl0 + + + SequenceFlow_1543qy7 + + + SequenceFlow_1x3tbl0 + SequenceFlow_1v4yr3f + + SequenceFlow_0s1plu9 + + + SequenceFlow_153a3kp + SequenceFlow_1vmxw9g + SequenceFlow_0is7myf + + + SequenceFlow_1vmxw9g + SequenceFlow_0etw572 + + PT15S + + + + SequenceFlow_0is7myf + + + + + SequenceFlow_0etw572 + SequenceFlow_0s1plu9 + SequenceFlow_153a3kp + + + + ${MonitorVnfmCreateJobTask.hasOperationFinished(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")))} + + + + + SequenceFlow_0bcgtzj + + + + SequenceFlow_1i1o9sh + + PT3H + + + + + + + SequenceFlow_1i1o9sh + SequenceFlow_0bcgtzj + + + + SequenceFlow_1v4yr3f + SequenceFlow_1543qy7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmCreateJobTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmCreateJobTask.java index f89931063c..59ff71ab0c 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmCreateJobTask.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmCreateJobTask.java @@ -20,14 +20,11 @@ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.CREATE_VNF_RESPONSE_PARAM_NAME; -import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_FINISHED_STATES; -import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_RETRIEVAL_STATES; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_STATUS_PARAM_NAME; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.vnfmadapter.v1.model.CreateVnfResponse; import org.onap.vnfmadapter.v1.model.OperationStateEnum; -import org.onap.vnfmadapter.v1.model.QueryJobResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -40,17 +37,14 @@ import com.google.common.base.Optional; * */ @Component -public class MonitorVnfmCreateJobTask { +public class MonitorVnfmCreateJobTask extends MonitorVnfmJobTask{ private static final Logger LOGGER = LoggerFactory.getLogger(MonitorVnfmCreateJobTask.class); - private final ExceptionBuilder exceptionUtil; - private final VnfmAdapterServiceProvider vnfmAdapterServiceProvider; @Autowired public MonitorVnfmCreateJobTask(final VnfmAdapterServiceProvider vnfmAdapterServiceProvider, final ExceptionBuilder exceptionUtil) { - this.vnfmAdapterServiceProvider = vnfmAdapterServiceProvider; - this.exceptionUtil = exceptionUtil; + super(vnfmAdapterServiceProvider, exceptionUtil); } /** @@ -61,27 +55,10 @@ public class MonitorVnfmCreateJobTask { public void getCurrentOperationStatus(final BuildingBlockExecution execution) { LOGGER.debug("Executing getCurrentOperationStatus ..."); final CreateVnfResponse vnfInstantiateResponse = execution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME); - execution.setVariable(OPERATION_STATUS_PARAM_NAME, getOperationStatus(execution, vnfInstantiateResponse)); + execution.setVariable(OPERATION_STATUS_PARAM_NAME, getOperationStatus(execution, vnfInstantiateResponse.getJobId())); LOGGER.debug("Finished executing getCurrentOperationStatus ..."); } - /** - * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} - * @return boolean to indicate whether job has competed or not - */ - public boolean hasOperationFinished(final BuildingBlockExecution execution) { - LOGGER.debug("Executing hasOperationFinished ..."); - - final Optional operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME); - if (operationStatusOption != null && operationStatusOption.isPresent()) { - return OPERATION_FINISHED_STATES.contains(operationStatusOption.get()); - } - LOGGER.debug("OperationStatus is not present yet... "); - LOGGER.debug("Finished executing hasOperationFinished ..."); - return false; - - } - /** * Log and throw exception on timeout for job status * @@ -121,34 +98,4 @@ public class MonitorVnfmCreateJobTask { LOGGER.debug("Successfully completed instatiation of job {}", vnfInstantiateResponse); } } - - private Optional getOperationStatus(final BuildingBlockExecution execution, - final CreateVnfResponse vnfInstantiateResponse) { - - final Optional instantiateOperationJobStatus = - vnfmAdapterServiceProvider.getInstantiateOperationJobStatus(vnfInstantiateResponse.getJobId()); - - if (instantiateOperationJobStatus.isPresent()) { - final QueryJobResponse queryJobResponse = instantiateOperationJobStatus.get(); - - if (!OPERATION_RETRIEVAL_STATES.contains(queryJobResponse.getOperationStatusRetrievalStatus())) { - final String message = - "Recevied invalid operation reterivel state: " + queryJobResponse.getOperationStatusRetrievalStatus(); - LOGGER.error(message); - exceptionUtil.buildAndThrowWorkflowException(execution, 1203, message); - } - - if (queryJobResponse.getOperationState() != null) { - final OperationStateEnum operationStatus = queryJobResponse.getOperationState(); - LOGGER.debug("Operation {} with {} and operation retrieval status : {}", queryJobResponse.getId(), - operationStatus, queryJobResponse.getOperationStatusRetrievalStatus()); - return Optional.of(queryJobResponse.getOperationState()); - } - - LOGGER.debug("Operation {} without operationStatus and operation retrieval status :{}", queryJobResponse.getId(), - queryJobResponse.getOperationStatusRetrievalStatus()); - - } - return Optional.absent(); - } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmDeleteJobTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmDeleteJobTask.java new file mode 100644 index 0000000000..c4804c05c2 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmDeleteJobTask.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; + +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.DELETE_VNF_RESPONSE_PARAM_NAME; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_STATUS_PARAM_NAME; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; +import org.onap.vnfmadapter.v1.model.OperationStateEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.google.common.base.Optional; + + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * + */ +@Component +public class MonitorVnfmDeleteJobTask extends MonitorVnfmJobTask { + + private static final Logger LOGGER = LoggerFactory.getLogger(MonitorVnfmDeleteJobTask.class); + + @Autowired + public MonitorVnfmDeleteJobTask(final VnfmAdapterServiceProvider vnfmAdapterServiceProvider, + final ExceptionBuilder exceptionUtil) { + super(vnfmAdapterServiceProvider, exceptionUtil); + } + + /** + * Get the current operation status of Delete job + * + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + */ + public void getCurrentOperationStatus(final BuildingBlockExecution execution) { + LOGGER.debug("Executing getCurrentOperationStatus ..."); + final DeleteVnfResponse deleteVnfResponse = execution.getVariable(Constants.DELETE_VNF_RESPONSE_PARAM_NAME); + execution.setVariable(OPERATION_STATUS_PARAM_NAME, getOperationStatus(execution, deleteVnfResponse.getJobId())); + LOGGER.debug("Finished executing getCurrentOperationStatus ..."); + } + + /** + * Log and throw exception on timeout for job status + * + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + */ + public void timeOutLogFailue(final BuildingBlockExecution execution) { + final String message = "Delete operation time out"; + LOGGER.error(message); + exceptionUtil.buildAndThrowWorkflowException(execution, 1213, message); + } + + /** + * Check the final status of delete throw exception if not completed successfully + * + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + */ + public void checkIfOperationWasSuccessful(final BuildingBlockExecution execution) { + LOGGER.debug("Executing checkIfOperationWasSuccessful ..."); + final Optional operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME); + final DeleteVnfResponse deleteVnfResponse = execution.getVariable(DELETE_VNF_RESPONSE_PARAM_NAME); + if (operationStatusOption == null || !operationStatusOption.isPresent()) { + final String message = "Unable to delete jobId: " + + (deleteVnfResponse != null ? deleteVnfResponse.getJobId() : "null") + "Unable to retrieve OperationStatus"; + LOGGER.error(message); + exceptionUtil.buildAndThrowWorkflowException(execution, 1214, message); + } + if (operationStatusOption.isPresent()) { + final OperationStateEnum operationStatus = operationStatusOption.get(); + if (operationStatus != OperationStateEnum.COMPLETED) { + final String message = + "Unable to Delete jobId: " + (deleteVnfResponse != null ? deleteVnfResponse.getJobId() : "null") + + " OperationStatus: " + operationStatus; + LOGGER.error(message); + exceptionUtil.buildAndThrowWorkflowException(execution, 1215, message); + } + LOGGER.debug("Successfully completed Deletion of job {}", deleteVnfResponse); + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmJobTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmJobTask.java new file mode 100644 index 0000000000..e3992428cb --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmJobTask.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; + +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_FINISHED_STATES; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_RETRIEVAL_STATES; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_STATUS_PARAM_NAME; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.vnfmadapter.v1.model.OperationStateEnum; +import org.onap.vnfmadapter.v1.model.QueryJobResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.google.common.base.Optional; + + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * + */ +@Component +public class MonitorVnfmJobTask { + + private static final Logger LOGGER = LoggerFactory.getLogger(MonitorVnfmJobTask.class); + protected final ExceptionBuilder exceptionUtil; + protected final VnfmAdapterServiceProvider vnfmAdapterServiceProvider; + + @Autowired + public MonitorVnfmJobTask(final VnfmAdapterServiceProvider vnfmAdapterServiceProvider, + final ExceptionBuilder exceptionUtil) { + this.vnfmAdapterServiceProvider = vnfmAdapterServiceProvider; + this.exceptionUtil = exceptionUtil; + } + + /** + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + * @return boolean to indicate whether job has competed or not + */ + public boolean hasOperationFinished(final BuildingBlockExecution execution) { + LOGGER.debug("Executing hasOperationFinished ..."); + + final Optional operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME); + if (operationStatusOption != null && operationStatusOption.isPresent()) { + return OPERATION_FINISHED_STATES.contains(operationStatusOption.get()); + } + LOGGER.debug("OperationStatus is not present yet... "); + LOGGER.debug("Finished executing hasOperationFinished ..."); + return false; + } + + /** + * This method calls the Vnfm adapter and gets the Operation status of the job + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + * @param jobId unique job id + * @return Operation State + */ + protected Optional getOperationStatus(final BuildingBlockExecution execution, + final String jobId) { + + final Optional instantiateOperationJobStatus = + vnfmAdapterServiceProvider.getInstantiateOperationJobStatus(jobId); + + if (instantiateOperationJobStatus.isPresent()) { + final QueryJobResponse queryJobResponse = instantiateOperationJobStatus.get(); + + if (!OPERATION_RETRIEVAL_STATES.contains(queryJobResponse.getOperationStatusRetrievalStatus())) { + final String message = + "Recevied invalid operation reterivel state: " + queryJobResponse.getOperationStatusRetrievalStatus(); + LOGGER.error(message); + exceptionUtil.buildAndThrowWorkflowException(execution, 1203, message); + } + if (queryJobResponse.getOperationState() != null) { + final OperationStateEnum operationStatus = queryJobResponse.getOperationState(); + LOGGER.debug("Operation {} with {} and operation retrieval status : {}", queryJobResponse.getId(), + operationStatus, queryJobResponse.getOperationStatusRetrievalStatus()); + return Optional.of(queryJobResponse.getOperationState()); + } + + LOGGER.debug("Operation {} without operationStatus and operation retrieval status :{}", queryJobResponse.getId(), + queryJobResponse.getOperationStatusRetrievalStatus()); + } + return Optional.absent(); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmDeleteJobTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmDeleteJobTaskTest.java new file mode 100644 index 0000000000..e41c571765 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmDeleteJobTaskTest.java @@ -0,0 +1,173 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import java.util.UUID; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; +import org.onap.vnfmadapter.v1.model.OperationStateEnum; +import org.onap.vnfmadapter.v1.model.OperationStatusRetrievalStatusEnum; +import org.onap.vnfmadapter.v1.model.QueryJobResponse; +import com.google.common.base.Optional; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * + */ +public class MonitorVnfmDeleteJobTaskTest extends BaseTaskTest { + + private static final String JOB_ID = UUID.randomUUID().toString(); + + private MonitorVnfmDeleteJobTask objUnderTest; + + @Mock + private VnfmAdapterServiceProvider mockedVnfmAdapterServiceProvider; + + private final BuildingBlockExecution stubbedxecution = new StubbedBuildingBlockExecution(); + + @Before + public void setUp() { + objUnderTest = getEtsiVnfMonitorJobTask(); + stubbedxecution.setVariable(Constants.DELETE_VNF_RESPONSE_PARAM_NAME, getDeleteVnfResponse()); + } + + @Test + public void testGetCurrentOperationStatus() throws Exception { + Optional queryJobResponse = getQueryJobResponse(); + queryJobResponse.get().setOperationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.STATUS_FOUND); + queryJobResponse.get().setOperationState(OperationStateEnum.COMPLETED); + when(mockedVnfmAdapterServiceProvider.getInstantiateOperationJobStatus(JOB_ID)).thenReturn(queryJobResponse); + objUnderTest.getCurrentOperationStatus(stubbedxecution); + final Optional operationState = + stubbedxecution.getVariable(Constants.OPERATION_STATUS_PARAM_NAME); + assertNotNull(operationState); + assertEquals(OperationStateEnum.COMPLETED, operationState.get()); + } + + @Test + public void testGetCurrentOperationStatusFailed() throws Exception { + Optional queryJobResponse = getQueryJobResponse(); + queryJobResponse.get().setOperationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.CANNOT_RETRIEVE_STATUS); + queryJobResponse.get().setOperationState(OperationStateEnum.FAILED); + when(mockedVnfmAdapterServiceProvider.getInstantiateOperationJobStatus(JOB_ID)).thenReturn(queryJobResponse); + objUnderTest.getCurrentOperationStatus(stubbedxecution); + final Optional operationState = + stubbedxecution.getVariable(Constants.OPERATION_STATUS_PARAM_NAME); + assertNotNull(operationState); + assertEquals(OperationStateEnum.FAILED, operationState.get()); + } + + @Test + public void testGetCurrentOperationStatusEmpty() throws Exception { + Optional queryJobResponse = getQueryJobResponse(); + queryJobResponse.get().setOperationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.STATUS_FOUND); + when(mockedVnfmAdapterServiceProvider.getInstantiateOperationJobStatus(JOB_ID)).thenReturn(queryJobResponse); + objUnderTest.getCurrentOperationStatus(stubbedxecution); + final Optional operationState = + stubbedxecution.getVariable(Constants.OPERATION_STATUS_PARAM_NAME); + assertFalse(operationState.isPresent()); + } + + @Test + public void testGetCurrentOperationStatusException() throws Exception { + Optional queryJobResponse = getQueryJobResponse(); + queryJobResponse.get().setOperationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.STATUS_FOUND); + when(mockedVnfmAdapterServiceProvider.getInstantiateOperationJobStatus(JOB_ID)).thenReturn(queryJobResponse); + objUnderTest.getCurrentOperationStatus(stubbedxecution); + final Optional operationState = + stubbedxecution.getVariable(Constants.OPERATION_STATUS_PARAM_NAME); + assertFalse(operationState.isPresent()); + } + + @Test + public void testHasOperationFinished() throws Exception { + stubbedxecution.setVariable(Constants.OPERATION_STATUS_PARAM_NAME, Optional.of(OperationStateEnum.COMPLETED)); + assertTrue(objUnderTest.hasOperationFinished(stubbedxecution)); + } + + @Test + public void testHasOperationPending() throws Exception { + stubbedxecution.setVariable(Constants.OPERATION_STATUS_PARAM_NAME, Optional.absent()); + assertFalse(objUnderTest.hasOperationFinished(stubbedxecution)); + } + + @Test + public void testTimeOutLogFailue() throws Exception { + objUnderTest.timeOutLogFailue(stubbedxecution); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1213), + eq("Delete operation time out")); + } + + @Test + public void testCheckIfOperationWasSuccessful() throws Exception { + stubbedxecution.setVariable(Constants.OPERATION_STATUS_PARAM_NAME, Optional.of(OperationStateEnum.COMPLETED)); + MonitorVnfmDeleteJobTask spyObject = Mockito.spy(objUnderTest); + spyObject.checkIfOperationWasSuccessful(stubbedxecution); + verify(spyObject, times(1)).checkIfOperationWasSuccessful(stubbedxecution); + } + + @Test + public void testCheckIfOperationWasSuccessfulWithPending() throws Exception { + stubbedxecution.setVariable(Constants.OPERATION_STATUS_PARAM_NAME, Optional.of(OperationStateEnum.PROCESSING)); + objUnderTest.checkIfOperationWasSuccessful(stubbedxecution); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1215), anyString()); + } + + @Test + public void testCheckIfOperationWasSuccessfulEmpty() throws Exception { + stubbedxecution.setVariable(Constants.OPERATION_STATUS_PARAM_NAME, Optional.absent()); + objUnderTest.checkIfOperationWasSuccessful(stubbedxecution); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1214), anyString()); + } + + private DeleteVnfResponse getDeleteVnfResponse() { + final DeleteVnfResponse response = new DeleteVnfResponse(); + response.setJobId(JOB_ID); + return response; + } + + private Optional getQueryJobResponse() { + final QueryJobResponse queryJobResponse = new QueryJobResponse(); + queryJobResponse.setId(JOB_ID); + return Optional.of(queryJobResponse); + } + + private MonitorVnfmDeleteJobTask getEtsiVnfMonitorJobTask() { + return new MonitorVnfmDeleteJobTask(mockedVnfmAdapterServiceProvider, exceptionUtil); + } + +} -- cgit 1.2.3-korg