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