diff options
author | pwielebs <piotr.wielebski@nokia.com> | 2021-01-08 07:53:41 +0100 |
---|---|---|
committer | pwielebs <piotr.wielebski@nokia.com> | 2021-01-19 11:45:09 +0100 |
commit | ac97466f6eae32ad13015b93527e8e6f18299bc3 (patch) | |
tree | 3d8105a6adae6ae36a540ac1b8d9bef056e4a65b /bpmn/so-bpmn-tasks/src/test/java/org | |
parent | 5e9676e8319a1867976ce2a09c607681c3445887 (diff) |
SO WorkflowAction refactor II
- extract buildExecuteBuildingBlock(), buildExecuteBuildingBlockList() methods from WorkflowAction class and move it to new ExecuteBuildingBlockBuilder class in the same package as WorkflowAction
- all methods used only in traverseUserParamsService() also moved
- all existing tests for moved methods, moved to corresponding test class
Issue-ID: SO-3422
Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Change-Id: I64110de339fed4a0c80c746e45302cefd5e194ff
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test/java/org')
2 files changed, 100 insertions, 45 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilderTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilderTest.java new file mode 100644 index 0000000000..c8914f6e02 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilderTest.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * Modifications Copyright (c) 2021 Nokia + * ================================================================================ + * Modifications Copyright (c) 2020 Tech Mahindra + * ================================================================================ + * 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; + +import org.junit.Test; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; +import java.util.ArrayList; +import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +public class ExecuteBuildingBlockBuilderTest { + + final private ExecuteBuildingBlockBuilder executeBBBuilder = new ExecuteBuildingBlockBuilder(); + + @Test + public void sortVfModulesByBaseFirstTest() { + List<Resource> resources = new ArrayList<>(); + Resource resource1 = new Resource(WorkflowType.VFMODULE, "111", false); + resource1.setBaseVfModule(false); + resources.add(resource1); + Resource resource2 = new Resource(WorkflowType.VFMODULE, "222", false); + resource2.setBaseVfModule(false); + resources.add(resource2); + Resource resource3 = new Resource(WorkflowType.VFMODULE, "333", false); + resource3.setBaseVfModule(true); + resources.add(resource3); + + List<Resource> result = executeBBBuilder.sortVfModulesByBaseFirst(resources); + assertEquals("333", result.get(0).getResourceId()); + assertEquals("222", result.get(1).getResourceId()); + assertEquals("111", result.get(2).getResourceId()); + } + + @Test + public void sortVfModulesByBaseLastTest() { + List<Resource> resources = new ArrayList<>(); + Resource resource1 = new Resource(WorkflowType.VFMODULE, "111", false); + resource1.setBaseVfModule(true); + resources.add(resource1); + Resource resource2 = new Resource(WorkflowType.VFMODULE, "222", false); + resource2.setBaseVfModule(false); + resources.add(resource2); + Resource resource3 = new Resource(WorkflowType.VFMODULE, "333", false); + resource3.setBaseVfModule(false); + resources.add(resource3); + List<Resource> result = executeBBBuilder.sortVfModulesByBaseLast(resources); + assertEquals("333", result.get(0).getResourceId()); + assertEquals("222", result.get(1).getResourceId()); + assertEquals("111", result.get(2).getResourceId()); + } + + @Test + public void verifyLackOfNullPointerExceptionForNullResource() { + ExecuteBuildingBlock result = null; + try { + result = executeBBBuilder.buildExecuteBuildingBlock(new OrchestrationFlow(), null, null, null, null, null, + false, null, null, null, false, null, null, true, null); + } catch (NullPointerException e) { + fail("NullPointerException should not be thrown when 'resource' is null"); + } + assertNotNull(result); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index c916e09c79..100c32f1c2 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -120,6 +120,7 @@ public class WorkflowActionTest extends BaseTaskTest { protected Environment environment; @Mock protected UserParamsServiceTraversal userParamsServiceTraversal; + @Mock private AaiResourceIdValidator aaiResourceIdValidator; @InjectMocks @@ -131,6 +132,9 @@ public class WorkflowActionTest extends BaseTaskTest { @Spy protected WorkflowAction SPY_workflowAction; + @Spy + protected ExecuteBuildingBlockBuilder executeBuildingBlockBuilder; + @Rule public ExpectedException thrown = ExpectedException.none(); @@ -159,6 +163,7 @@ public class WorkflowActionTest extends BaseTaskTest { when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance); workflowAction.setBbInputSetupUtils(bbSetupUtils); workflowAction.setBbInputSetup(bbInputSetup); + } /** @@ -179,6 +184,7 @@ public class WorkflowActionTest extends BaseTaskTest { when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, true, "my-custom-cloud-owner")).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEqualsBulkFlowName(ebbs, "AssignNetwork1802BB", "CreateNetworkBB", "ActivateNetworkBB"); @@ -199,6 +205,7 @@ public class WorkflowActionTest extends BaseTaskTest { when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, true, "my-custom-cloud-owner")).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEqualsBulkFlowName(ebbs, "DeactivateNetworkBB", "DeleteNetworkBB", "UnassignNetwork1802BB"); @@ -219,6 +226,7 @@ public class WorkflowActionTest extends BaseTaskTest { when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, true, "my-custom-cloud-owner")).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEqualsBulkFlowName(ebbs, "AssignServiceInstanceBB", "ActivateServiceInstanceBB"); @@ -292,6 +300,7 @@ public class WorkflowActionTest extends BaseTaskTest { .thenReturn(vfModuleCustomization2); when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("da4d4327-fb7d-4311-ac7a-be7ba60cf969")) .thenReturn(vfModuleCustomization3); + workflowAction.selectExecutionList(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEqualsBulkFlowName(ebbs, "AssignServiceInstanceBB", "AssignVnfBB", "AssignVolumeGroupBB", @@ -471,6 +480,7 @@ public class WorkflowActionTest extends BaseTaskTest { doReturn(service).when(catalogDbClient).getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a"); when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, false, "my-custom-cloud-owner")).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEqualsBulkFlowName(ebbs, "AssignServiceInstanceBB", "AssignNetworkBB", "CreateNetworkBB", @@ -2063,41 +2073,7 @@ public class WorkflowActionTest extends BaseTaskTest { workflowAction.traverseCatalogDbService(execution, sIRequest, resourceCounter, aaiResourceIds); } - @Test - public void sortVfModulesByBaseFirstTest() { - List<Resource> resources = new ArrayList<>(); - Resource resource1 = new Resource(WorkflowType.VFMODULE, "111", false); - resource1.setBaseVfModule(false); - resources.add(resource1); - Resource resource2 = new Resource(WorkflowType.VFMODULE, "222", false); - resource2.setBaseVfModule(false); - resources.add(resource2); - Resource resource3 = new Resource(WorkflowType.VFMODULE, "333", false); - resource3.setBaseVfModule(true); - resources.add(resource3); - List<Resource> result = workflowAction.sortVfModulesByBaseFirst(resources); - assertEquals("333", result.get(0).getResourceId()); - assertEquals("222", result.get(1).getResourceId()); - assertEquals("111", result.get(2).getResourceId()); - } - @Test - public void sortVfModulesByBaseLastTest() { - List<Resource> resources = new ArrayList<>(); - Resource resource1 = new Resource(WorkflowType.VFMODULE, "111", false); - resource1.setBaseVfModule(true); - resources.add(resource1); - Resource resource2 = new Resource(WorkflowType.VFMODULE, "222", false); - resource2.setBaseVfModule(false); - resources.add(resource2); - Resource resource3 = new Resource(WorkflowType.VFMODULE, "333", false); - resource3.setBaseVfModule(false); - resources.add(resource3); - List<Resource> result = workflowAction.sortVfModulesByBaseLast(resources); - assertEquals("333", result.get(0).getResourceId()); - assertEquals("222", result.get(1).getResourceId()); - assertEquals("111", result.get(2).getResourceId()); - } @Test public void findCatalogNetworkCollectionTest() { @@ -2136,17 +2112,6 @@ public class WorkflowActionTest extends BaseTaskTest { execution.getVariable("WorkflowActionErrorMessage")); } - @Test - public void verifyLackOfNullPointerExceptionForNullResource() { - ExecuteBuildingBlock result = null; - try { - result = workflowAction.buildExecuteBuildingBlock(new OrchestrationFlow(), null, null, null, null, null, - false, null, null, null, false, null, null, true, null); - } catch (NullPointerException e) { - fail("NullPointerException should not be thrown when 'resource' is null"); - } - assertNotNull(result); - } @Test public void traverseAAIServiceTest() { |