2 * ============LICENSE_START=======================================================
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
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.openecomp.mso.bpmn.common;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.mock;
26 import java.util.HashMap;
28 import java.util.UUID;
30 import org.camunda.bpm.engine.test.Deployment;
31 import org.camunda.bpm.engine.variable.impl.VariableMapImpl;
32 import org.jboss.resteasy.spi.AsynchronousResponse;
33 import org.junit.Test;
34 import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncResource;
35 import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
37 public class WorkflowAsyncResourceTest extends WorkflowTest {
40 @Deployment(resources = { "testAsyncResource.bpmn" })
41 public void asyncRequestSuccess() throws InterruptedException {
42 //it can be any request which asynchronously processed by the workflow
43 String request = "<aetgt:CreateTenantRequest xmlns:aetgt=\"http://org.openecomp/mso/workflow/schema/v1\" xmlns:sdncadapterworkflow=\"http://org.openecomp/mso/workflow/schema/v1\" xmlns:ns5=\"http://org.openecomp/mso/request/types/v1\"> <msoservtypes:service-information xmlns:msoservtypes=\"http://org.openecomp/mso/request/types/v1\"> <msoservtypes:service-type>SDN-ETHERNET-INTERNET</msoservtypes:service-type> <msoservtypes:service-instance-id>HI/VLXM/950604//SW_INTERNET</msoservtypes:service-instance-id> <msoservtypes:subscriber-name>SubName01</msoservtypes:subscriber-name> </msoservtypes:service-information> </aetgt:CreateTenantRequest>";
45 Map<String,String> variables = new HashMap<>();
46 variables.put("testAsyncRequestMsg", request);
47 variables.put("mso-request-id", UUID.randomUUID().toString());
48 variables.put("mso-service-request-timeout", "5");
50 WorkflowResponse workflowResponse = BPMNUtil.executeAsyncWorkflow(processEngineRule, "testAsyncProcess", variables);
51 assertEquals("Received the request, the process is getting executed, request message<aetgt:CreateTenantRequest xmlns:aetgt=\"http://org.openecomp/mso/workflow/schema/v1\" xmlns:sdncadapterworkflow=\"http://org.openecomp/mso/workflow/schema/v1\" xmlns:ns5=\"http://org.openecomp/mso/request/types/v1\"> <msoservtypes:service-information xmlns:msoservtypes=\"http://org.openecomp/mso/request/types/v1\"> <msoservtypes:service-type>SDN-ETHERNET-INTERNET</msoservtypes:service-type> <msoservtypes:service-instance-id>HI/VLXM/950604//SW_INTERNET</msoservtypes:service-instance-id> <msoservtypes:subscriber-name>SubName01</msoservtypes:subscriber-name> </msoservtypes:service-information> </aetgt:CreateTenantRequest>", workflowResponse.getResponse());
52 assertEquals(200, workflowResponse.getMessageCode());
55 private void executeWorkflow(String request, String requestId, AsynchronousResponse asyncResponse, String processKey) {
56 WorkflowAsyncResource workflowResource = new WorkflowAsyncResource();
57 VariableMapImpl variableMap = new VariableMapImpl();
59 Map<String, Object> variableValueType = new HashMap<>();
61 Map<String, Object> requestMsg = new HashMap<>();
62 requestMsg.put("value", request);
63 requestMsg.put("type", "String");
65 Map<String, Object> msorequestId = new HashMap<>();
66 msorequestId.put("type", "String");
67 msorequestId.put("value",requestId);
69 Map<String, Object> timeout = new HashMap<>();
70 timeout.put("type", "String");
71 timeout.put("value","5");
73 variableValueType.put("testAsyncRequestMsg", requestMsg);
74 variableValueType.put("mso-request-id", msorequestId);
75 variableValueType.put("mso-service-request-timeout", timeout);
77 variableMap.put("variables", variableValueType);
79 workflowResource.setProcessEngineServices4junit(processEngineRule);
80 workflowResource.startProcessInstanceByKey(asyncResponse, processKey, variableMap);
83 class ProcessThread extends Thread {
85 public WorkflowResponse workflowResponse;
86 public String requestId;
87 public String processKey;
88 public AsynchronousResponse asyncResponse = mock(AsynchronousResponse.class);
89 public String request;
90 public boolean started;
93 executeWorkflow(request, requestId, asyncResponse, processKey);