c68c7bb184fc812b2c62d7edd37c3eab0be50071
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / ManualHandlingTest.java
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * OPENECOMP - MSO 
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.openecomp.mso.bpmn.common;
22
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24
25 import org.camunda.bpm.engine.TaskService;
26 import org.camunda.bpm.ProcessEngineService;
27 import org.camunda.bpm.engine.task.TaskQuery;
28 import org.camunda.bpm.engine.task.Task;
29 import org.camunda.bpm.engine.delegate.BpmnError;
30 import org.camunda.bpm.engine.delegate.DelegateTask;
31 import org.camunda.bpm.engine.runtime.Execution;
32
33 import static org.openecomp.mso.bpmn.common.BPMNUtil.executeWorkFlow;
34 import static org.openecomp.mso.bpmn.common.BPMNUtil.waitForWorkflowToFinish;
35 import static com.github.tomakehurst.wiremock.client.WireMock.containing;
36 import static com.github.tomakehurst.wiremock.client.WireMock.put;
37 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
38 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
39 import static org.openecomp.mso.bpmn.common.BPMNUtil.executeWorkFlow;
40 import static org.openecomp.mso.bpmn.common.BPMNUtil.waitForWorkflowToFinish;
41 import static org.openecomp.mso.bpmn.mock.StubResponsePolicy.MockPolicyAbort;
42
43 import java.io.DataOutputStream;
44 import java.net.HttpURLConnection;
45 import java.net.URL;
46 import java.util.HashMap;
47 import java.util.Map;
48 import java.util.UUID;
49 import java.util.List;
50
51 import org.camunda.bpm.engine.RuntimeService;
52 import org.camunda.bpm.engine.test.Deployment;
53 import org.junit.Assert;
54 import org.junit.Test;
55 import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
56 import org.openecomp.mso.bpmn.core.WorkflowException;
57
58 /**
59  * Unit test for RainyDayHandler.bpmn.
60  */
61 public class ManualHandlingTest extends WorkflowTest {
62         
63         @Test   
64         @Deployment(resources = {                       
65                         "subprocess/BuildingBlock/ManualHandling.bpmn"
66                 })
67         public void  TestManualHandlingSuccess() {
68
69                 RuntimeService runtimeService = processEngineRule.getRuntimeService();                          
70                 Map<String, Object> variables = new HashMap<String, Object>();          
71                 variables.put("isDebugLogEnabled","true");
72                 variables.put("msoRequestId", "testRequestId");
73                 variables.put("serviceType", "X");
74                 variables.put("vnfType", "Y");
75                 variables.put("currentActivity", "BB1");                
76                 variables.put("workStep", "1");
77                 variables.put("failedActivity", "");
78                 variables.put("errorCode", "123");
79                 variables.put("errorText", "update failed");
80                 variables.put("validResponses", "Rollback");
81                 
82
83                 String businessKey = UUID.randomUUID().toString();
84                 invokeSubProcess("ManualHandling", businessKey, variables);
85                 
86                 try {
87                         Thread.sleep(5);
88                 } catch (Exception e) {
89                         
90                 }
91                 
92                 TaskService taskService = processEngineRule.getTaskService();
93                 
94                 TaskQuery q = taskService.createTaskQuery();            
95         
96                 List<Task> tasks = q.orderByTaskCreateTime().asc().list();
97                   int i = 0;
98                   
99                   for (Task task : tasks) {               
100                          
101                     
102                         System.out.println("TASK ID: " + task.getId());
103                         System.out.println("TASK NAME: " + task.getName());
104                         try {
105                                 System.out.println("Completing the task");
106                                 Map<String,Object> completeVariables = new HashMap<String,Object>();
107                                 completeVariables.put("responseValue", "skip");
108                                 taskService.complete(task.getId(), completeVariables);                  
109                         }
110                         catch(Exception e) {
111                                 System.out.println("GOT EXCEPTION: " + e.getMessage());
112                         }                       
113                         }       
114
115                 waitForProcessEnd(businessKey, 100000);
116
117                 Assert.assertTrue(isProcessEnded(businessKey));
118                 
119         }
120         
121         
122 }