a746bbb48ed56040a207b623ee64bcf711b32010
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / bpmn / common / WorkflowAsyncResourceTest.java
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * ONAP - SO 
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.onap.so.bpmn.common;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.util.HashMap;
26 import java.util.Map;
27 import java.util.UUID;
28
29 import org.camunda.bpm.engine.test.Deployment;
30 import org.camunda.bpm.engine.variable.impl.VariableMapImpl;
31 import org.junit.Ignore;
32 import org.junit.Test;
33 import org.onap.so.bpmn.common.workflow.context.WorkflowResponse;
34 import org.onap.so.bpmn.common.workflow.service.WorkflowAsyncResource;
35
36 @Ignore
37 public class WorkflowAsyncResourceTest extends WorkflowTest {
38
39         @Test
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.onap/so/workflow/schema/v1\" xmlns:sdncadapterworkflow=\"http://org.onap/so/workflow/schema/v1\" xmlns:ns5=\"http://org.onap/so/request/types/v1\">  <msoservtypes:service-information xmlns:msoservtypes=\"http://org.onap/so/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>";
44
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");
49                 
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.onap/so/workflow/schema/v1\" xmlns:sdncadapterworkflow=\"http://org.onap/so/workflow/schema/v1\" xmlns:ns5=\"http://org.onap/so/request/types/v1\">  <msoservtypes:service-information xmlns:msoservtypes=\"http://org.onap/so/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());
53         }
54
55         private void executeWorkflow(String request, String requestId, String processKey) throws InterruptedException {
56                 WorkflowAsyncResource workflowResource = new WorkflowAsyncResource();
57                 VariableMapImpl variableMap = new VariableMapImpl();
58
59                 Map<String, Object> variableValueType = new HashMap<>();
60
61                 Map<String, Object> requestMsg = new HashMap<>();
62                 requestMsg.put("value", request);
63                 requestMsg.put("type", "String");
64
65                 Map<String, Object> msorequestId = new HashMap<>();
66                 msorequestId.put("type", "String");
67                 msorequestId.put("value",requestId);
68
69                 Map<String, Object> timeout = new HashMap<>();
70                 timeout.put("type", "String");
71                 timeout.put("value","5"); 
72
73                 variableValueType.put("testAsyncRequestMsg", requestMsg);
74                 variableValueType.put("mso-request-id", msorequestId);
75                 variableValueType.put("mso-service-request-timeout", timeout);
76
77                 variableMap.put("variables", variableValueType);
78                 
79                 workflowResource.setProcessEngineServices4junit(processEngineRule);
80                 workflowResource.startProcessInstanceByKey( processKey, variableMap);
81         }
82
83         
84 }