faf485f0d7278501f900f473f59f836f3d2f596f
[so.git] / bpmn / so-bpmn-building-blocks / src / test / java / org / onap / so / bpmn / infrastructure / bpmn / subprocess / PauseForManualTaskActivityTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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.Matchers.any;
25 import static org.mockito.Mockito.doThrow;
26
27 import org.camunda.bpm.engine.ManagementService;
28 import org.camunda.bpm.engine.TaskService;
29 import org.camunda.bpm.engine.delegate.BpmnError;
30 import org.camunda.bpm.engine.runtime.Job;
31 import org.camunda.bpm.engine.runtime.ProcessInstance;
32 import org.camunda.bpm.engine.delegate.DelegateExecution;
33 import org.camunda.bpm.engine.task.Task;
34 import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions;
35 import org.junit.Test;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.onap.so.bpmn.BaseBPMNTest;
38
39
40 public class PauseForManualTaskActivityTest extends BaseBPMNTest{
41         private static final String TIMEOUT_10_S = "PT10S";
42         
43         @Autowired
44         protected ManagementService managementService;
45         
46         @Autowired
47         protected TaskService taskService;
48         
49         @Test
50         public void sunnyDayPauseForManualTaskTimeout_Test() throws InterruptedException {
51                 variables.put("taskTimeout", TIMEOUT_10_S);
52                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("PauseForManualTaskActivity", variables);
53                 assertThat(pi).isNotNull();             
54                 BpmnAwareAssertions.assertThat(pi).isWaitingAt("ManualUserTask");
55                 Task task = taskService.createTaskQuery().active().list().get(0);       
56                 assertThat(pi).task().isNotNull();
57                 assertNotNull(task);
58                 
59                 Job job = managementService.createJobQuery().activityId("ManualTaskTimer").singleResult();
60                 assertNotNull(job);             
61                 managementService.executeJob(job.getId());
62                 
63                 assertThat(pi).isStarted().hasPassedInOrder("PauseForManualTaskActivity_Start",
64                                 "UpdateDbStatusToPendingManualTask",
65                                 "CreateExternalTicket",
66                                 "ManualTaskTimer",                              
67                                 "UpdateDBStatusToTimeout",
68                                 "ThrowTimeoutError");
69         }
70         
71         @Test
72         public void sunnyDayPauseForManualTaskCompleted_Test() throws InterruptedException {
73                 variables.put("taskTimeout", TIMEOUT_10_S);
74                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("PauseForManualTaskActivity", variables);
75                 assertThat(pi).isNotNull();
76                 BpmnAwareAssertions.assertThat(pi).isWaitingAt("ManualUserTask");
77                 assertThat(pi).task().isNotNull();
78                 Task task = taskService.createTaskQuery().active().list().get(0);       
79                 assertNotNull(task);            
80                 taskService.complete(task.getId());
81                 
82                 assertThat(pi).isStarted().hasPassedInOrder("PauseForManualTaskActivity_Start",
83                                 "UpdateDbStatusToPendingManualTask",
84                                 "CreateExternalTicket",
85                                 "ManualUserTask",
86                                 "UpdateDbStatusToInProgress",
87                                 "PauseForManualTaskActivity_End");
88                 assertThat(pi).isEnded();
89         }
90         
91         @Test   
92         public void rainyDayPauseForManualTask_Test() throws Exception {
93                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(manualHandlingTasks).createExternalTicket((any(DelegateExecution.class)));
94                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("PauseForManualTaskActivity", variables);
95                 assertThat(pi).isNotNull().isStarted().hasPassedInOrder("PauseForManualTaskActivity_Start",
96                                 "UpdateDbStatusToPendingManualTask",
97                                 "CreateExternalTicket").hasNotPassed(                                                              
98                                  "ManualUserTask",
99                                  "UpdateDbStatusToInProgress",
100                                  "PauseForManualTaskActivity_End");             
101         }
102         
103 }