Springboot 2.0 upgrade
[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 import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.assertThat;
23 import static org.junit.Assert.assertNotNull;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.doAnswer;
26 import static org.mockito.Mockito.doThrow;
27
28 import java.util.List;
29
30 import org.camunda.bpm.engine.ManagementService;
31 import org.camunda.bpm.engine.TaskService;
32 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.camunda.bpm.engine.delegate.DelegateExecution;
34 import org.camunda.bpm.engine.management.JobDefinition;
35 import org.camunda.bpm.engine.runtime.Job;
36 import org.camunda.bpm.engine.runtime.ProcessInstance;
37 import org.camunda.bpm.engine.task.Task;
38 import org.camunda.bpm.engine.test.ProcessEngineRule;
39 import org.junit.Ignore;
40 import org.junit.Rule;
41 import org.junit.Test;
42 import org.mockito.invocation.InvocationOnMock;
43 import org.mockito.stubbing.Answer;
44 import org.onap.so.bpmn.BaseBPMNTest;
45 import org.onap.so.db.catalog.beans.OrchestrationStatusValidationDirective;
46 import org.springframework.beans.factory.annotation.Autowired;
47
48 public class ExecuteBuildingBlockTest extends BaseBPMNTest {
49         @Autowired
50         private TaskService taskService;
51         @Autowired
52         private ManagementService managementService;
53         
54         @Test
55         public void runExecuteFlowTest() {
56                 
57                 variables.put("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.CONTINUE);
58                 variables.put("flowToBeCalled", "MockFlow");
59                 
60                 mockSubprocess("MockFlow", "My Mock Process Name", "GenericStub");
61
62                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
63
64                 assertThat(pi).isNotNull();
65                 assertThat(pi).isStarted()
66                         .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StatusPolicy", "CheckOrchestrationStatusValidationResults", "Task_PreValidate", "Call_BBToExecute", "Task_PostValidate", "Task_setHandlingCodeSuccess", "End_ExecuteBuildingBlock");
67                 assertThat(pi).isEnded();
68                 
69                 
70         }
71         @Test
72         public void test_sunnyDayExecuteBuildingBlock_silentSuccess() throws Exception {
73                 variables.put("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.SILENT_SUCCESS);
74                 
75                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
76                 assertThat(pi).isNotNull();
77                 assertThat(pi).isStarted()
78                         .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StatusPolicy", "CheckOrchestrationStatusValidationResults","Task_setHandlingCodeSuccess", "End_ExecuteBuildingBlock")
79                         .hasNotPassed("Call_BBToExecute", "ErrorStart", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_1aonzik", "ErrorEnd2", "Task_SetRetryTimer");
80                 assertThat(pi).isEnded();
81         }
82         
83         @Test
84         @Ignore
85         public void test_rainyDayExecuteBuildingBlock_rollbackOrAbort() throws Exception {
86                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
87                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
88                 assertThat(pi).isNotNull();
89                 assertThat(pi).isStarted()
90                         .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StartEvent_0tmcs9g", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "EndEvent_0mvmk3i", "SubProcess_0tv8zda")
91                         .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults", "Task_setHandlingCodeSuccess","Call_BBToExecute", "End_ExecuteBuildingBlock", "ExclusiveGateway_0ey4zpt", "Task_SetRetryTimer");
92                 assertThat(pi).isEnded();
93         }
94         
95         @Test
96         @Ignore
97         public void test_rainyDayExecuteBuildingBlock_retryNoRetriesLeft() throws Exception {
98                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
99                 
100                 variables.put("handlingCode", "Retry");
101                 variables.put("RetryCount", 5);
102                 
103                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
104                 assertThat(pi).isNotNull();
105                 assertThat(pi).isStarted()
106                         .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StartEvent_0tmcs9g", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_0ey4zpt", "ErrorEnd2")
107                         .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults", "Task_setHandlingCodeSuccess","Call_BBToExecute", "End_ExecuteBuildingBlock", "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", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_0ey4zpt", "Task_SetRetryTimer", "EndEvent_1sez2lh")
129                         .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults", "Task_setHandlingCodeSuccess","Call_BBToExecute", "End_ExecuteBuildingBlock", "ErrorEnd2");
130         }
131 }