ff5e18c2108c9b4aeeba357658d75909d51482a5
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / bpmn / common / workflow / service / WorkflowAsyncResourceExceptionHandlingTest.java
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * ONAP - SO 
4  * ================================================================================ 
5  * Copyright (C) 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.common.workflow.service;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26
27 import java.util.HashMap;
28 import java.util.Map;
29 import java.util.UUID;
30
31 import javax.ws.rs.core.Response;
32
33 import org.camunda.bpm.engine.test.Deployment;
34 import org.camunda.bpm.engine.variable.impl.VariableMapImpl;
35 import org.junit.Test;
36 import org.onap.so.bpmn.common.workflow.context.WorkflowResponse;
37
38
39 public class WorkflowAsyncResourceExceptionHandlingTest {
40
41         @Test
42         @Deployment(resources = { "testAsyncResource.bpmn" })
43         public void asyncRequestSuccess() throws InterruptedException {
44                 VariableMapImpl variableMap = new VariableMapImpl();
45
46                 Map<String, Object> variableValueType = new HashMap<>();
47
48                 Map<String, Object> requestMsg = new HashMap<>();
49                 requestMsg.put("value", "");
50                 requestMsg.put("type", "String");
51
52                 Map<String, Object> msorequestId = new HashMap<>();
53                 msorequestId.put("type", "String");
54                 msorequestId.put("value",UUID.randomUUID().toString());
55
56                 Map<String, Object> timeout = new HashMap<>();
57                 timeout.put("type", "String");
58                 timeout.put("value","5");
59
60                 variableValueType.put("testAsyncRequestMsg", requestMsg);
61                 variableValueType.put("mso-request-id", msorequestId);
62                 variableValueType.put("mso-service-request-timeout", timeout);
63
64                 variableMap.put("variables", variableValueType);
65                 WorkflowAsyncResource workflowAsyncResource = new WorkflowAsyncResource();
66                 workflowAsyncResource.setProcessor(new WorkflowProcessor());
67                 Response res = workflowAsyncResource.startProcessInstanceByKey("randomKey", variableMap);
68                 assertEquals(500,res.getStatus());
69                 WorkflowResponse workflowResponse = (WorkflowResponse)res.getEntity();
70                 assertNotNull(workflowResponse);
71                 assertEquals(500, workflowResponse.getMessageCode());
72                 assertTrue(workflowResponse.getResponse().startsWith("Error occurred while executing the process:"));
73                 assertEquals("Fail", workflowResponse.getMessage());
74
75
76         }
77
78 }