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;
27 import java.util.HashMap;
29 import java.util.UUID;
31 import javax.ws.rs.core.Response;
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;
39 public class WorkflowAsyncResourceExceptionHandlingTest {
42 @Deployment(resources = { "testAsyncResource.bpmn" })
43 public void asyncRequestSuccess() throws InterruptedException {
44 VariableMapImpl variableMap = new VariableMapImpl();
46 Map<String, Object> variableValueType = new HashMap<>();
48 Map<String, Object> requestMsg = new HashMap<>();
49 requestMsg.put("value", "");
50 requestMsg.put("type", "String");
52 Map<String, Object> msorequestId = new HashMap<>();
53 msorequestId.put("type", "String");
54 msorequestId.put("value",UUID.randomUUID().toString());
56 Map<String, Object> timeout = new HashMap<>();
57 timeout.put("type", "String");
58 timeout.put("value","5");
60 variableValueType.put("testAsyncRequestMsg", requestMsg);
61 variableValueType.put("mso-request-id", msorequestId);
62 variableValueType.put("mso-service-request-timeout", timeout);
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());