From 8813ba72c340e45f586b71c9ee12382cdecec91f Mon Sep 17 00:00:00 2001 From: "Mnushkin, Dmitry" Date: Wed, 24 Jul 2019 12:44:16 -0400 Subject: set multi-stage flag in listener to log success set multi-stage flag in listener to log success msg added post listener for requests db object Issue-ID: SO-2153 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I4b27cbb69b983bd2f7c0d72c8ebb4d9c43201120 --- .../listeners/MultiStageSkipListenerTest.java | 127 +++++++++++++++++++++ .../tasks/listeners/MultiStageSkipTest.java | 112 ------------------ 2 files changed, 127 insertions(+), 112 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipListenerTest.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipTest.java (limited to 'bpmn/so-bpmn-tasks/src/test') diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipListenerTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipListenerTest.java new file mode 100644 index 0000000000..9e2eac416c --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipListenerTest.java @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.workflow.tasks.listeners; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.List; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.common.BBConstants; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.DelegateExecutionImpl; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.db.request.beans.InfraActiveRequests; + +@RunWith(MockitoJUnitRunner.class) +public class MultiStageSkipListenerTest { + + @Mock + private CatalogDbClient catalogDbClient; + + @Mock + private BBInputSetupUtils bbInputSetupUtils; + + @InjectMocks + private MultiStageSkipListener multiStageSkipListener; + + @Test + public void testTrigger() { + BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake()); + execution.setVariable(BBConstants.G_ALACARTE, true); + + assertTrue("should be triggered", multiStageSkipListener.shouldRunFor("AssignVfModuleBB", true, execution)); + + execution.setVariable(BBConstants.G_ALACARTE, false); + assertFalse("should not be triggered", + multiStageSkipListener.shouldRunFor("AssignVfModuleBB", true, execution)); + + execution.setVariable(BBConstants.G_ALACARTE, true); + assertFalse("should not be triggered", + multiStageSkipListener.shouldRunFor("AssignVfModuleBB2", true, execution)); + + execution.setVariable("multiStageDesign", true); + assertTrue("should be triggered", multiStageSkipListener.shouldRunFor(execution)); + + execution.setVariable("multiStageDesign", false); + assertFalse("should not be triggered", multiStageSkipListener.shouldRunFor(execution)); + + + } + + @Test + public void testProcessMultiStageSkip() { + String vfModuleId = "vfModuleId"; + String vnfId = "vnfId"; + List flowsToExecute = new ArrayList<>(); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setServiceInstanceId("serviceInstanceId"); + workflowResourceIds.setVnfId(vnfId); + flowsToExecute.add(new ExecuteBuildingBlock()); + flowsToExecute.add(new ExecuteBuildingBlock()); + flowsToExecute.add(new ExecuteBuildingBlock()); + flowsToExecute.get(0).setResourceId(vfModuleId); + flowsToExecute.get(0).setBuildingBlock(new BuildingBlock()); + flowsToExecute.get(0).getBuildingBlock().setBpmnFlowName("AssignVfModuleBB"); + flowsToExecute.get(0).setWorkflowResourceIds(workflowResourceIds); + BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake()); + + org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule(); + vfModule.setVfModuleId(vfModuleId); + org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf(); + vnf.setModelCustomizationId("modelCustomizationUUID"); + VnfResourceCustomization vnfCust = new VnfResourceCustomization(); + vnfCust.setModelCustomizationUUID("modelCustomizationUUID"); + vnfCust.setMultiStageDesign("true"); + when(catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(vnf.getModelCustomizationId())) + .thenReturn(vnfCust); + when(bbInputSetupUtils.getAAIVfModule(eq(vnfId), eq(vfModuleId))).thenReturn(null); + when(bbInputSetupUtils.getAAIGenericVnf(eq(vnfId))).thenReturn(vnf); + + multiStageSkipListener.run(flowsToExecute, flowsToExecute.get(0), execution); + assertEquals("Flows should only have Assign", flowsToExecute.size(), 1); + assertEquals("Flows should only have Assign", flowsToExecute.get(0).getBuildingBlock().getBpmnFlowName(), + "AssignVfModuleBB"); + } + + @Test + public void postCompletionRequestsDbListenerTest() { + InfraActiveRequests request = new InfraActiveRequests(); + BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake()); + multiStageSkipListener.run(request, execution); + + assertEquals("Successfully completed Assign Building Block only due to multi-stage-design VNF", + request.getFlowStatus()); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipTest.java deleted file mode 100644 index b6f8aafa55..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/MultiStageSkipTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.infrastructure.workflow.tasks.listeners; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; -import java.util.ArrayList; -import java.util.List; -import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.so.bpmn.common.BBConstants; -import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.common.DelegateExecutionImpl; -import org.onap.so.bpmn.infrastructure.workflow.tasks.listeners.MultiStageSkipListener; -import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; -import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; -import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; -import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; -import org.onap.so.db.catalog.beans.VnfResourceCustomization; -import org.onap.so.db.catalog.client.CatalogDbClient; - -@RunWith(MockitoJUnitRunner.class) -public class MultiStageSkipTest { - - @Mock - private CatalogDbClient catalogDbClient; - - @Mock - private BBInputSetupUtils bbInputSetupUtils; - - @InjectMocks - private MultiStageSkipListener multiStageSkipListener; - - @Test - public void testTrigger() { - BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake()); - execution.setVariable(BBConstants.G_ALACARTE, true); - - assertTrue("should be triggered", multiStageSkipListener.shouldRunFor("AssignVfModuleBB", true, execution)); - - execution.setVariable(BBConstants.G_ALACARTE, false); - assertFalse("should not be triggered", - multiStageSkipListener.shouldRunFor("AssignVfModuleBB", true, execution)); - - execution.setVariable(BBConstants.G_ALACARTE, true); - assertFalse("should not be triggered", - multiStageSkipListener.shouldRunFor("AssignVfModuleBB2", true, execution)); - - - } - - @Test - public void testProcessMultiStageSkip() { - String vfModuleId = "vfModuleId"; - String vnfId = "vnfId"; - List flowsToExecute = new ArrayList<>(); - WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); - workflowResourceIds.setServiceInstanceId("serviceInstanceId"); - workflowResourceIds.setVnfId(vnfId); - flowsToExecute.add(new ExecuteBuildingBlock()); - flowsToExecute.add(new ExecuteBuildingBlock()); - flowsToExecute.add(new ExecuteBuildingBlock()); - flowsToExecute.get(0).setResourceId(vfModuleId); - flowsToExecute.get(0).setBuildingBlock(new BuildingBlock()); - flowsToExecute.get(0).getBuildingBlock().setBpmnFlowName("AssignVfModuleBB"); - flowsToExecute.get(0).setWorkflowResourceIds(workflowResourceIds); - BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake()); - - org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule(); - vfModule.setVfModuleId(vfModuleId); - org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf(); - vnf.setModelCustomizationId("modelCustomizationUUID"); - VnfResourceCustomization vnfCust = new VnfResourceCustomization(); - vnfCust.setModelCustomizationUUID("modelCustomizationUUID"); - vnfCust.setMultiStageDesign("true"); - when(catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(vnf.getModelCustomizationId())) - .thenReturn(vnfCust); - when(bbInputSetupUtils.getAAIVfModule(eq(vnfId), eq(vfModuleId))).thenReturn(null); - when(bbInputSetupUtils.getAAIGenericVnf(eq(vnfId))).thenReturn(vnf); - - multiStageSkipListener.run(flowsToExecute, flowsToExecute.get(0), execution); - assertEquals("Flows should only have Assign", flowsToExecute.size(), 1); - assertEquals("Flows should only have Assign", flowsToExecute.get(0).getBuildingBlock().getBpmnFlowName(), - "AssignVfModuleBB"); - - } -} -- cgit 1.2.3-korg