aec118b7fbd838d0b076382606090b0b59a918bd
[so.git] / bpmn / so-bpmn-building-blocks / src / test / java / org / onap / so / bpmn / infrastructure / bpmn / subprocess / ExecuteBuildingBlockTest.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.bpmn.subprocess;
22
23 import org.camunda.bpm.engine.ManagementService;
24 import org.camunda.bpm.engine.TaskService;
25 import org.camunda.bpm.engine.delegate.BpmnError;
26 import org.camunda.bpm.engine.delegate.DelegateExecution;
27 import org.camunda.bpm.engine.runtime.Job;
28 import org.camunda.bpm.engine.runtime.ProcessInstance;
29 import org.junit.Ignore;
30 import org.junit.Test;
31 import org.onap.so.bpmn.BaseBPMNTest;
32 import org.onap.so.db.catalog.beans.OrchestrationStatusValidationDirective;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.assertThat;
35 import static org.junit.Assert.assertNotNull;
36 import static org.mockito.ArgumentMatchers.any;
37 import static org.mockito.Mockito.doThrow;
38
39 public class ExecuteBuildingBlockTest extends BaseBPMNTest {
40     @Autowired
41     private TaskService taskService;
42     @Autowired
43     private ManagementService managementService;
44
45     @Test
46     public void runExecuteFlowTest() {
47
48         variables.put("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.CONTINUE);
49         variables.put("flowToBeCalled", "MockFlow");
50
51         mockSubprocess("MockFlow", "My Mock Process Name", "GenericStub");
52
53         ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
54
55         assertThat(pi).isNotNull();
56         assertThat(pi).isStarted().hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StatusPolicy",
57                 "CheckOrchestrationStatusValidationResults", "Task_PreValidate", "Call_BBToExecute",
58                 "Task_PostValidate", "Task_setHandlingCodeSuccess", "End_ExecuteBuildingBlock");
59         assertThat(pi).isEnded();
60
61
62     }
63
64     @Test
65     public void test_sunnyDayExecuteBuildingBlock_silentSuccess() throws Exception {
66         variables.put("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.SILENT_SUCCESS);
67
68         ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
69         assertThat(pi).isNotNull();
70         assertThat(pi).isStarted().hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StatusPolicy",
71                 "CheckOrchestrationStatusValidationResults", "Task_setHandlingCodeSuccess", "End_ExecuteBuildingBlock")
72                 .hasNotPassed("Call_BBToExecute", "ErrorStart", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik",
73                         "ExclusiveGateway_1aonzik", "ErrorEnd2", "Task_SetRetryTimer");
74         assertThat(pi).isEnded();
75     }
76
77     @Test
78     @Ignore
79     public void test_rainyDayExecuteBuildingBlock_rollbackOrAbort() throws Exception {
80         doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
81         ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
82         assertThat(pi).isNotNull();
83         assertThat(pi).isStarted()
84                 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StartEvent_0tmcs9g",
85                         "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "EndEvent_0mvmk3i", "SubProcess_0tv8zda")
86                 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults",
87                         "Task_setHandlingCodeSuccess", "Call_BBToExecute", "End_ExecuteBuildingBlock",
88                         "ExclusiveGateway_0ey4zpt", "Task_SetRetryTimer");
89         assertThat(pi).isEnded();
90     }
91
92     @Test
93     @Ignore
94     public void test_rainyDayExecuteBuildingBlock_retryNoRetriesLeft() throws Exception {
95         doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
96
97         variables.put("handlingCode", "Retry");
98         variables.put("RetryCount", 5);
99
100         ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
101         assertThat(pi).isNotNull();
102         assertThat(pi).isStarted()
103                 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StartEvent_0tmcs9g",
104                         "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_0ey4zpt", "ErrorEnd2")
105                 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults",
106                         "Task_setHandlingCodeSuccess", "Call_BBToExecute", "End_ExecuteBuildingBlock",
107                         "Task_SetRetryTimer");
108         assertThat(pi).isEnded();
109     }
110
111     @Test
112     @Ignore
113     public void test_rainyDayExecuteBuildingBlock_retryRetriesLeft() throws Exception {
114         doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
115
116         variables.put("handlingCode", "Retry");
117         variables.put("RetryCount", 4);
118         variables.put("RetryDuration", "PT1S");
119
120         ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
121         assertThat(pi).isNotNull();
122         assertThat(pi).isStarted();
123         assertThat(pi).isWaitingAt("IntermediateCatchEvent_RetryTimer");
124         Job job = managementService.createJobQuery().activityId("IntermediateCatchEvent_RetryTimer").singleResult();
125         assertNotNull(job);
126         managementService.executeJob(job.getId());
127         assertThat(pi).isEnded()
128                 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "BoundaryEvent_0i3q236",
129                         "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_0ey4zpt",
130                         "Task_SetRetryTimer", "EndEvent_1sez2lh")
131                 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults",
132                         "Task_setHandlingCodeSuccess", "Call_BBToExecute", "End_ExecuteBuildingBlock", "ErrorEnd2");
133     }
134 }