67ae7de92838c8d3ed535ac8e727129a3c057c06
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / bpmn / common / ManualHandlingIT.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.common;
24
25 import static org.onap.so.bpmn.mock.StubResponseDatabase.MockPostRequestDB;
26
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.UUID;
31
32 import org.camunda.bpm.engine.TaskService;
33 import org.camunda.bpm.engine.task.Task;
34 import org.camunda.bpm.engine.task.TaskQuery;
35 import org.junit.Assert;
36 import org.junit.Test;
37 import org.onap.so.BaseIntegrationTest;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 /**
42  * Unit test for RainyDayHandler.bpmn.
43  */
44 public class ManualHandlingIT extends BaseIntegrationTest {
45         Logger logger = LoggerFactory.getLogger(ManualHandlingIT.class);
46         
47         @Test
48         public void  TestManualHandlingSuccess() {
49                 MockPostRequestDB();
50                 
51                 Map<String, Object> variables = new HashMap<>();
52                 variables.put("isDebugLogEnabled","true");
53                 variables.put("msoRequestId", "testRequestId");
54                 variables.put("serviceType", "X");
55                 variables.put("vnfType", "Y");
56                 variables.put("currentActivity", "BB1");
57                 variables.put("workStep", "1");
58                 variables.put("failedActivity", "AAI");
59                 variables.put("vnfName", "vSAMP12");
60                 variables.put("errorCode", "123");
61                 variables.put("errorText", "update failed");
62                 variables.put("validResponses", "Rollback");
63                 variables.put("vnfName", "vSAMP1");
64
65
66                 String businessKey = UUID.randomUUID().toString();
67                 invokeSubProcess("ManualHandling", businessKey, variables);
68                 
69                 try {
70                         Thread.sleep(5);
71                 } catch (Exception e) {
72
73                 }
74
75                 TaskService taskService = processEngine.getTaskService();
76
77                 TaskQuery q = taskService.createTaskQuery();
78
79                 List<Task> tasks = q.orderByTaskCreateTime().asc().list();
80                 
81                 for (Task task : tasks) {
82                         logger.debug("TASK ID: {}", task.getId());
83                         logger.debug("TASK NAME: {}", task.getName());
84                         
85                         try {
86                                 logger.debug("Completing the task");
87                                 Map<String,Object> completeVariables = new HashMap<>();
88                                 completeVariables.put("responseValue", "skip");
89                                 taskService.complete(task.getId(), completeVariables);
90                         } catch(Exception e) {
91                                 logger.debug("GOT EXCEPTION: {}", e.getMessage());
92                         }
93                 }
94                 
95                 waitForProcessEnd(businessKey, 100000);
96                 
97                 Assert.assertTrue(isProcessEnded(businessKey));
98         }
99 }