Containerization feature of SO
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / workflow / tasks / WorkflowActionBBTasksTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 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;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Matchers.anyObject;
25 import static org.mockito.Matchers.anyString;
26 import static org.mockito.Mockito.when;
27
28 import java.util.ArrayList;
29 import java.util.List;
30
31 import org.camunda.bpm.engine.delegate.DelegateExecution;
32 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
33 import org.junit.Before;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.rules.ExpectedException;
37 import org.onap.so.bpmn.BaseTaskTest;
38 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
39 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
40 import org.springframework.beans.factory.annotation.Autowired;
41
42 public class WorkflowActionBBTasksTest extends BaseTaskTest {
43
44         @Autowired
45         protected WorkflowAction workflowAction;
46         
47         @Autowired
48         protected WorkflowActionBBTasks workflowActionBBTasks;
49         
50         private DelegateExecution execution;
51         
52         @Rule
53         public ExpectedException thrown = ExpectedException.none();
54         
55         @Before
56         public void before() throws Exception {
57                 execution = new DelegateExecutionFake();
58                 org.onap.aai.domain.yang.ServiceInstance servInstance = new org.onap.aai.domain.yang.ServiceInstance();
59                 servInstance.setServiceInstanceId("TEST");
60                 when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance);
61                 workflowAction.setBbInputSetupUtils(bbSetupUtils);
62                 workflowAction.setBbInputSetup(bbInputSetup);
63         }
64         
65         @Test
66         public void selectBBTest() throws Exception{
67                 String gAction = "Delete-Network-Collection";
68                 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
69                 execution.setVariable("requestAction", gAction);
70                 execution.setVariable("gCurrentSequence", 0);
71                 execution.setVariable("homing", false);
72                 execution.setVariable("calledHoming", false);
73                 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
74                 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock();
75                 flowsToExecute.add(ebb);
76                 execution.setVariable("flowsToExecute", flowsToExecute);
77                 workflowActionBBTasks.selectBB(execution);
78                 boolean success = (boolean) execution.getVariable("completed");
79                 assertEquals(true,success);
80         }
81         
82         @Test
83         public void select2BBTest() throws Exception{
84                 String gAction = "Delete-Network-Collection";
85                 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
86                 execution.setVariable("requestAction", gAction);
87                 execution.setVariable("gCurrentSequence", 0);
88                 execution.setVariable("homing", false);
89                 execution.setVariable("calledHoming", false);
90                 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
91                 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock();
92                 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
93                 flowsToExecute.add(ebb);
94                 flowsToExecute.add(ebb2);
95                 execution.setVariable("flowsToExecute", flowsToExecute);
96                 workflowActionBBTasks.selectBB(execution);
97                 boolean success = (boolean) execution.getVariable("completed");
98                 assertEquals(false,success);
99         }
100         
101         @Test
102         public void msoCompleteProcessTest() throws Exception{
103                 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
104                 execution.setVariable("requestAction", "createInstance");
105                 execution.setVariable("resourceId", "123");
106                 execution.setVariable("source","MSO");
107                 execution.setVariable("resourceName", "Service");
108                 execution.setVariable("aLaCarte", true);
109                 workflowActionBBTasks.setupCompleteMsoProcess(execution);
110                 String response = (String) execution.getVariable("CompleteMsoProcessRequest");
111                 assertEquals(response,"<aetgt:MsoCompletionRequest xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\" xmlns:ns=\"http://org.onap/so/request/types/v1\"><request-info xmlns=\"http://org.onap/so/infra/vnf-request/v1\"><request-id>00f704ca-c5e5-4f95-a72c-6889db7b0688</request-id><action>createInstance</action><source>MSO</source></request-info><status-message>ALaCarte-Service-createInstance request was executed correctly.</status-message><serviceInstanceId>123</serviceInstanceId><mso-bpel-name>WorkflowActionBB</mso-bpel-name></aetgt:MsoCompletionRequest>");
112         }
113         
114         @Test
115         public void setupFalloutHandlerTest(){
116                 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
117                 execution.setVariable("serviceInstanceId", "123");
118                 execution.setVariable("WorkflowActionErrorMessage", "Error in WorkFlowAction");
119                 execution.setVariable("requestAction", "createInstance");
120                 workflowActionBBTasks.setupFalloutHandler(execution);
121                 assertEquals(execution.getVariable("falloutRequest"),"<aetgt:FalloutHandlerRequest xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"xmlns:ns=\"http://org.onap/so/request/types/v1\"xmlns:wfsch=\"http://org.onap/so/workflow/schema/v1\"><request-info xmlns=\"http://org.onap/so/infra/vnf-request/v1\"><request-id>00f704ca-c5e5-4f95-a72c-6889db7b0688</request-id><action>createInstance</action><source>VID</source></request-info><aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>Error in WorkFlowAction</aetgt:ErrorMessage><aetgt:ErrorCode>7000</aetgt:ErrorCode></aetgt:WorkflowException></aetgt:FalloutHandlerRequest>");
122         }
123         
124         @Test
125         public void rollbackExecutionPathTest(){
126                 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
127                 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
128                 BuildingBlock bb1 = new BuildingBlock();
129                 bb1.setBpmnFlowName("CreateNetworkBB");
130                 flowsToExecute.add(ebb1);
131                 ebb1.setBuildingBlock(bb1);
132                 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
133                 BuildingBlock bb2 = new BuildingBlock();
134                 bb2.setBpmnFlowName("ActivateNetworkBB");
135                 flowsToExecute.add(ebb2);
136                 ebb2.setBuildingBlock(bb2);
137                 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
138                 BuildingBlock bb3 = new BuildingBlock();
139                 bb3.setBpmnFlowName("CreateVolumeGroupBB");
140                 flowsToExecute.add(ebb3);
141                 ebb3.setBuildingBlock(bb3);
142                 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock();
143                 BuildingBlock bb4 = new BuildingBlock();
144                 bb4.setBpmnFlowName("ActivateVolumeGroupBB");
145                 flowsToExecute.add(ebb4);
146                 ebb4.setBuildingBlock(bb4);
147                 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock();
148                 BuildingBlock bb5 = new BuildingBlock();
149                 bb5.setBpmnFlowName("CreateVfModuleBB");
150                 flowsToExecute.add(ebb5);
151                 ebb5.setBuildingBlock(bb5);
152                 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock();
153                 BuildingBlock bb6 = new BuildingBlock();
154                 bb6.setBpmnFlowName("ActivateVfModuleBB");
155                 flowsToExecute.add(ebb6);
156                 ebb6.setBuildingBlock(bb6);
157                 ExecuteBuildingBlock ebb7 = new ExecuteBuildingBlock();
158                 BuildingBlock bb7 = new BuildingBlock();
159                 bb7.setBpmnFlowName("ActivateVnfBB");
160                 ebb7.setBuildingBlock(bb7);
161                 flowsToExecute.add(ebb7);
162                 ExecuteBuildingBlock ebb8 = new ExecuteBuildingBlock();
163                 BuildingBlock bb8 = new BuildingBlock();
164                 bb8.setBpmnFlowName("ActivateServiceInstance");
165                 ebb8.setBuildingBlock(bb8);
166                 flowsToExecute.add(ebb8);
167                 
168                 execution.setVariable("flowsToExecute", flowsToExecute);
169                 execution.setVariable("gCurrentSequence", 6);
170                 
171                 workflowActionBBTasks.rollbackExecutionPath(execution);
172                 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
173                 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB");
174                 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"DeactivateVolumeGroupBB");
175                 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"DeleteVolumeGroupBB");
176                 assertEquals(ebbs.get(3).getBuildingBlock().getBpmnFlowName(),"DeactivateNetworkBB");
177                 assertEquals(ebbs.get(4).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkBB");               
178         }
179         
180         @Test
181         public void checkRetryStatusTest(){
182                 execution.setVariable("handlingCode","Retry");
183                 execution.setVariable("retryCount", 1);
184                 execution.setVariable("gCurrentSequence",1);
185                 workflowActionBBTasks.checkRetryStatus(execution);
186                 assertEquals(0,execution.getVariable("gCurrentSequence"));
187         }
188 }