2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.common.workflow.service;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26 import java.util.HashMap;
28 import java.util.UUID;
29 import javax.ws.rs.core.Response;
30 import org.camunda.bpm.engine.test.Deployment;
31 import org.camunda.bpm.engine.variable.impl.VariableMapImpl;
32 import org.junit.Test;
33 import org.onap.so.bpmn.common.workflow.context.WorkflowResponse;
36 public class WorkflowAsyncResourceExceptionHandlingTest {
39 @Deployment(resources = {"testAsyncResource.bpmn"})
40 public void asyncRequestSuccess() throws InterruptedException {
41 VariableMapImpl variableMap = new VariableMapImpl();
43 Map<String, Object> variableValueType = new HashMap<>();
45 Map<String, Object> requestMsg = new HashMap<>();
46 requestMsg.put("value", "");
47 requestMsg.put("type", "String");
49 Map<String, Object> msorequestId = new HashMap<>();
50 msorequestId.put("type", "String");
51 msorequestId.put("value", UUID.randomUUID().toString());
53 Map<String, Object> timeout = new HashMap<>();
54 timeout.put("type", "String");
55 timeout.put("value", "5");
57 variableValueType.put("testAsyncRequestMsg", requestMsg);
58 variableValueType.put("mso-request-id", msorequestId);
59 variableValueType.put("mso-service-request-timeout", timeout);
61 variableMap.put("variables", variableValueType);
62 WorkflowAsyncResource workflowAsyncResource = new WorkflowAsyncResource();
63 workflowAsyncResource.setProcessor(new WorkflowProcessor());
64 Response res = workflowAsyncResource.startProcessInstanceByKey("randomKey", variableMap);
65 assertEquals(500, res.getStatus());
66 WorkflowResponse workflowResponse = (WorkflowResponse) res.getEntity();
67 assertNotNull(workflowResponse);
68 assertEquals(500, workflowResponse.getMessageCode());
69 assertTrue(workflowResponse.getResponse().startsWith("Error occurred while executing the process:"));
70 assertEquals("Fail", workflowResponse.getMessage());