1b4ddf71c27e62486f192ae997acf27ab063887f
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.workflow.tasks.listeners;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.ArgumentMatchers.eq;
27 import static org.mockito.Mockito.when;
28 import java.util.ArrayList;
29 import java.util.List;
30 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.InjectMocks;
34 import org.mockito.Mock;
35 import org.mockito.junit.MockitoJUnitRunner;
36 import org.onap.so.bpmn.common.BBConstants;
37 import org.onap.so.bpmn.common.BuildingBlockExecution;
38 import org.onap.so.bpmn.common.DelegateExecutionImpl;
39 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
40 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
41 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
42 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
43 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
44 import org.onap.so.db.catalog.client.CatalogDbClient;
45 import org.onap.so.db.request.beans.InfraActiveRequests;
46
47 @RunWith(MockitoJUnitRunner.class)
48 public class MultiStageSkipListenerTest {
49
50     @Mock
51     private CatalogDbClient catalogDbClient;
52
53     @Mock
54     private BBInputSetupUtils bbInputSetupUtils;
55
56     @InjectMocks
57     private MultiStageSkipListener multiStageSkipListener;
58
59     @Test
60     public void testTrigger() {
61         BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
62         execution.setVariable(BBConstants.G_ALACARTE, true);
63
64         assertTrue("should be triggered", multiStageSkipListener.shouldRunFor("AssignVfModuleBB", true, execution));
65
66         execution.setVariable(BBConstants.G_ALACARTE, false);
67         assertFalse("should not be triggered",
68                 multiStageSkipListener.shouldRunFor("AssignVfModuleBB", true, execution));
69
70         execution.setVariable(BBConstants.G_ALACARTE, true);
71         assertFalse("should not be triggered",
72                 multiStageSkipListener.shouldRunFor("AssignVfModuleBB2", true, execution));
73
74         execution.setVariable("multiStageDesign", true);
75         assertTrue("should be triggered", multiStageSkipListener.shouldRunFor(execution));
76
77         execution.setVariable("multiStageDesign", false);
78         assertFalse("should not be triggered", multiStageSkipListener.shouldRunFor(execution));
79
80         execution.setVariable("multiStageDesign", null);
81         assertFalse("should not be triggered", multiStageSkipListener.shouldRunFor(execution));
82
83     }
84
85     @Test
86     public void testProcessMultiStageSkip() {
87         String vfModuleId = "vfModuleId";
88         String vnfId = "vnfId";
89         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
90         WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
91         workflowResourceIds.setServiceInstanceId("serviceInstanceId");
92         workflowResourceIds.setVnfId(vnfId);
93         BuildingBlock bb = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
94         ExecuteBuildingBlock ebb = new ExecuteBuildingBlock();
95         ebb.setResourceId(vfModuleId);
96         ebb.setBuildingBlock(bb);
97         ebb.setWorkflowResourceIds(workflowResourceIds);
98         flowsToExecute.add(ebb);
99         flowsToExecute.add(new ExecuteBuildingBlock());
100         flowsToExecute.add(new ExecuteBuildingBlock());
101
102         BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
103
104         org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule();
105         vfModule.setVfModuleId(vfModuleId);
106         org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf();
107         vnf.setModelCustomizationId("modelCustomizationUUID");
108         VnfResourceCustomization vnfCust = new VnfResourceCustomization();
109         vnfCust.setModelCustomizationUUID("modelCustomizationUUID");
110         vnfCust.setMultiStageDesign("true");
111         when(catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(vnf.getModelCustomizationId()))
112                 .thenReturn(vnfCust);
113         when(bbInputSetupUtils.getAAIVfModule(eq(vnfId), eq(vfModuleId))).thenReturn(null);
114         when(bbInputSetupUtils.getAAIGenericVnf(eq(vnfId))).thenReturn(vnf);
115
116         multiStageSkipListener.run(flowsToExecute, flowsToExecute.get(0), execution);
117         assertEquals("Flows should only have Assign", flowsToExecute.size(), 1);
118         assertEquals("Flows should only have Assign", flowsToExecute.get(0).getBuildingBlock().getBpmnFlowName(),
119                 "AssignVfModuleBB");
120     }
121
122     @Test
123     public void postCompletionRequestsDbListenerTest() {
124         InfraActiveRequests request = new InfraActiveRequests();
125         BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
126         multiStageSkipListener.run(request, execution);
127
128         assertEquals("Successfully completed Assign Building Block only due to multi-stage-design VNF",
129                 request.getFlowStatus());
130     }
131 }