2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.workflow.tasks;
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;
28 import java.util.ArrayList;
29 import java.util.List;
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.onap.so.db.request.beans.InfraActiveRequests;
41 import org.springframework.beans.factory.annotation.Autowired;
43 public class WorkflowActionBBTasksTest extends BaseTaskTest {
46 protected WorkflowAction workflowAction;
49 protected WorkflowActionBBTasks workflowActionBBTasks;
51 private DelegateExecution execution;
54 public ExpectedException thrown = ExpectedException.none();
57 public void before() throws Exception {
58 execution = new DelegateExecutionFake();
59 org.onap.aai.domain.yang.ServiceInstance servInstance = new org.onap.aai.domain.yang.ServiceInstance();
60 servInstance.setServiceInstanceId("TEST");
61 when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance);
62 workflowAction.setBbInputSetupUtils(bbSetupUtils);
63 workflowAction.setBbInputSetup(bbInputSetup);
67 public void selectBBTest() throws Exception{
68 String gAction = "Delete-Network-Collection";
69 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
70 execution.setVariable("requestAction", gAction);
71 execution.setVariable("gCurrentSequence", 0);
72 execution.setVariable("homing", false);
73 execution.setVariable("calledHoming", false);
74 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
75 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock();
76 flowsToExecute.add(ebb);
77 execution.setVariable("flowsToExecute", flowsToExecute);
78 workflowActionBBTasks.selectBB(execution);
79 boolean success = (boolean) execution.getVariable("completed");
80 assertEquals(true,success);
84 public void getUpdatedRequestTest() throws Exception{
85 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
86 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
87 BuildingBlock bb1 = new BuildingBlock();
88 bb1.setBpmnFlowName("CreateNetworkBB");
89 flowsToExecute.add(ebb1);
90 ebb1.setBuildingBlock(bb1);
91 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
92 BuildingBlock bb2 = new BuildingBlock();
93 bb2.setBpmnFlowName("ActivateNetworkBB");
94 flowsToExecute.add(ebb2);
95 ebb2.setBuildingBlock(bb2);
96 String requestId = "requestId";
97 execution.setVariable("mso-request-id", requestId);
98 execution.setVariable("flowsToExecute", flowsToExecute);
99 int currentSequence = 2;
100 String expectedStatusMessage = "Execution of CreateNetworkBB has completed successfully, next invoking ActivateNetworkBB (Execution Path progress: BBs completed = 1; BBs remaining = 1).";
101 Long expectedLong = new Long(52);
102 InfraActiveRequests mockedRequest = new InfraActiveRequests();
103 when(requestsDbClient.getInfraActiveRequestbyRequestId(requestId)).thenReturn(mockedRequest);
104 InfraActiveRequests actual = workflowActionBBTasks.getUpdatedRequest(execution, currentSequence);
105 assertEquals(expectedStatusMessage, actual.getStatusMessage());
106 assertEquals(expectedLong, actual.getProgress());
110 public void select2BBTest() throws Exception{
111 String gAction = "Delete-Network-Collection";
112 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
113 execution.setVariable("requestAction", gAction);
114 execution.setVariable("gCurrentSequence", 0);
115 execution.setVariable("homing", false);
116 execution.setVariable("calledHoming", false);
117 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
118 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock();
119 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
120 flowsToExecute.add(ebb);
121 flowsToExecute.add(ebb2);
122 execution.setVariable("flowsToExecute", flowsToExecute);
123 workflowActionBBTasks.selectBB(execution);
124 boolean success = (boolean) execution.getVariable("completed");
125 assertEquals(false,success);
129 public void msoCompleteProcessTest() throws Exception{
130 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
131 execution.setVariable("requestAction", "createInstance");
132 execution.setVariable("resourceId", "123");
133 execution.setVariable("source","MSO");
134 execution.setVariable("resourceName", "Service");
135 execution.setVariable("aLaCarte", true);
136 workflowActionBBTasks.setupCompleteMsoProcess(execution);
137 String response = (String) execution.getVariable("CompleteMsoProcessRequest");
138 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>");
142 public void setupFalloutHandlerTest(){
143 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
144 execution.setVariable("serviceInstanceId", "123");
145 execution.setVariable("WorkflowActionErrorMessage", "Error in WorkFlowAction");
146 execution.setVariable("requestAction", "createInstance");
147 workflowActionBBTasks.setupFalloutHandler(execution);
148 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>");
152 public void rollbackExecutionPathTest(){
153 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
154 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
155 BuildingBlock bb1 = new BuildingBlock();
156 bb1.setBpmnFlowName("AssignVfModuleBB");
157 flowsToExecute.add(ebb1);
158 ebb1.setBuildingBlock(bb1);
159 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
160 BuildingBlock bb2 = new BuildingBlock();
161 bb2.setBpmnFlowName("CreateVfModuleBB");
162 flowsToExecute.add(ebb2);
163 ebb2.setBuildingBlock(bb2);
164 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
165 BuildingBlock bb3 = new BuildingBlock();
166 bb3.setBpmnFlowName("ActivateVfModuleBB");
167 flowsToExecute.add(ebb3);
168 ebb3.setBuildingBlock(bb3);
170 execution.setVariable("flowsToExecute", flowsToExecute);
171 execution.setVariable("gCurrentSequence", 2);
173 workflowActionBBTasks.rollbackExecutionPath(execution);
174 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
175 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeactivateVfModuleBB");
176 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB");
177 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"UnassignVfModuleBB");
181 public void rollbackExecutionPathUnfinishedFlowTest(){
182 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
183 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
184 BuildingBlock bb1 = new BuildingBlock();
185 bb1.setBpmnFlowName("AssignVfModuleBB");
186 flowsToExecute.add(ebb1);
187 ebb1.setBuildingBlock(bb1);
188 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
189 BuildingBlock bb2 = new BuildingBlock();
190 bb2.setBpmnFlowName("CreateVfModuleBB");
191 flowsToExecute.add(ebb2);
192 ebb2.setBuildingBlock(bb2);
193 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
194 BuildingBlock bb3 = new BuildingBlock();
195 bb3.setBpmnFlowName("ActivateVfModuleBB");
196 flowsToExecute.add(ebb3);
197 ebb3.setBuildingBlock(bb3);
199 execution.setVariable("flowsToExecute", flowsToExecute);
200 execution.setVariable("gCurrentSequence", 1);
202 workflowActionBBTasks.rollbackExecutionPath(execution);
203 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
204 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB");
205 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"UnassignVfModuleBB");
209 public void checkRetryStatusTest(){
210 execution.setVariable("handlingCode","Retry");
211 execution.setVariable("retryCount", 1);
212 execution.setVariable("gCurrentSequence",1);
213 workflowActionBBTasks.checkRetryStatus(execution);
214 assertEquals(0,execution.getVariable("gCurrentSequence"));