Code changes in BPMN infra for RAN Slice Use case
[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         variables.put("homing", false);
51
52         mockSubprocess("MockFlow", "My Mock Process Name", "GenericStub");
53
54         ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
55
56         assertThat(pi).isNotNull();
57         assertThat(pi).isStarted().hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StatusPolicy",
58                 "CheckOrchestrationStatusValidationResults", "Task_PreValidate", "Call_BBToExecute",
59                 "Task_PostValidate", "Task_setHandlingCodeSuccess", "End_ExecuteBuildingBlock");
60         assertThat(pi).isEnded();
61
62
63     }
64
65     @Test
66     public void test_sunnyDayExecuteBuildingBlock_silentSuccess() throws Exception {
67         variables.put("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.SILENT_SUCCESS);
68         variables.put("homing", false);
69
70         ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
71         assertThat(pi).isNotNull();
72         assertThat(pi).isStarted().hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StatusPolicy",
73                 "CheckOrchestrationStatusValidationResults", "Task_setHandlingCodeSuccess", "End_ExecuteBuildingBlock")
74                 .hasNotPassed("Call_BBToExecute", "ErrorStart", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik",
75                         "ExclusiveGateway_1aonzik", "ErrorEnd2", "Task_SetRetryTimer");
76         assertThat(pi).isEnded();
77     }
78
79     @Test
80     @Ignore
81     public void test_rainyDayExecuteBuildingBlock_rollbackOrAbort() throws Exception {
82         doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
83         ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
84         variables.put("homing", false);
85         assertThat(pi).isNotNull();
86         assertThat(pi).isStarted()
87                 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StartEvent_0tmcs9g",
88                         "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "EndEvent_0mvmk3i", "SubProcess_0tv8zda")
89                 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults",
90                         "Task_setHandlingCodeSuccess", "Call_BBToExecute", "End_ExecuteBuildingBlock",
91                         "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         variables.put("homing", false);
103
104         ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
105         assertThat(pi).isNotNull();
106         assertThat(pi).isStarted()
107                 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StartEvent_0tmcs9g",
108                         "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_0ey4zpt", "ErrorEnd2")
109                 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults",
110                         "Task_setHandlingCodeSuccess", "Call_BBToExecute", "End_ExecuteBuildingBlock",
111                         "Task_SetRetryTimer");
112         assertThat(pi).isEnded();
113     }
114
115     @Test
116     @Ignore
117     public void test_rainyDayExecuteBuildingBlock_retryRetriesLeft() throws Exception {
118         doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
119
120         variables.put("handlingCode", "Retry");
121         variables.put("RetryCount", 4);
122         variables.put("RetryDuration", "PT1S");
123         variables.put("homing", false);
124
125         ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
126         assertThat(pi).isNotNull();
127         assertThat(pi).isStarted();
128         assertThat(pi).isWaitingAt("IntermediateCatchEvent_RetryTimer");
129         Job job = managementService.createJobQuery().activityId("IntermediateCatchEvent_RetryTimer").singleResult();
130         assertNotNull(job);
131         managementService.executeJob(job.getId());
132         assertThat(pi).isEnded()
133                 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "BoundaryEvent_0i3q236",
134                         "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_0ey4zpt",
135                         "Task_SetRetryTimer", "EndEvent_1sez2lh")
136                 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults",
137                         "Task_setHandlingCodeSuccess", "Call_BBToExecute", "End_ExecuteBuildingBlock", "ErrorEnd2");
138     }
139 }