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.onap.so.bpmn.common;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
29 import java.io.IOException;
30 import java.util.HashMap;
32 import java.util.UUID;
34 import org.camunda.bpm.engine.test.Deployment;
35 import org.junit.Ignore;
36 import org.junit.Test;
37 import org.onap.so.bpmn.common.WorkflowTest;
38 import org.onap.so.bpmn.common.WorkflowTest.CallbackSet;
39 import org.onap.so.bpmn.core.WorkflowException;
42 * Unit tests for SDNCAdapterRestV1.
45 public class ReceiveWorkflowMessageTest extends WorkflowTest {
47 private static final String EOL = "\n";
49 private final CallbackSet callbacks = new CallbackSet();
51 public ReceiveWorkflowMessageTest() throws IOException {
52 callbacks.put("sdnc-event-success", JSON, "SDNCAEvent",
54 " \"SDNCEvent\": {" + EOL +
55 " \"eventType\": \"evenType\"," + EOL +
56 " \"eventCorrelatorType\": \"HOST-NAME\"," + EOL +
57 " \"eventCorrelator\": \"((CORRELATOR))\"," + EOL +
58 " \"params\": {" + EOL +
59 " \"success-indicator\":\"Y\"" + EOL +
64 callbacks.put("sdnc-event-fail", JSON, "SDNCAEvent",
66 " \"SDNCEvent\": {" + EOL +
67 " \"eventType\": \"evenType\"," + EOL +
68 " \"eventCorrelatorType\": \"HOST-NAME\"," + EOL +
69 " \"eventCorrelator\": \"((CORRELATOR))\"," + EOL +
70 " \"params\": {" + EOL +
71 " \"success-indicator\":\"N\"," + EOL +
72 " \"error-message\":\"SOMETHING BAD HAPPENED\"" + EOL +
79 * Test the happy path.
82 @Deployment(resources = {
83 "subprocess/ReceiveWorkflowMessage.bpmn"
85 public void happyPath() throws Exception {
89 String businessKey = UUID.randomUUID().toString();
90 Map<String, Object> variables = new HashMap<>();
91 variables.put("mso-request-id", "dffbae0e-5588-4bd6-9749-b0f0adb52312");
92 variables.put("isDebugLogEnabled", "true");
93 variables.put("RCVWFMSG_timeout", "PT1M");
94 variables.put("RCVWFMSG_messageType", "SDNCAEvent");
95 variables.put("RCVWFMSG_correlator", "USOSTCDALTX0101UJZZ31");
97 invokeSubProcess("ReceiveWorkflowMessage", businessKey, variables);
98 injectWorkflowMessages(callbacks, "sdnc-event-success");
99 waitForProcessEnd(businessKey, 10000);
101 String response = (String) getVariableFromHistory(businessKey, "WorkflowResponse");
102 System.out.println("Response:\n" + response);
103 assertTrue(response.contains("\"SDNCEvent\""));
104 assertTrue((boolean)getVariableFromHistory(businessKey, "RCVWFMSG_SuccessIndicator"));
110 * Test the timeout scenario.
113 @Deployment(resources = {
114 "subprocess/ReceiveWorkflowMessage.bpmn"
116 public void timeout() throws Exception {
120 String businessKey = UUID.randomUUID().toString();
121 Map<String, Object> variables = new HashMap<>();
122 variables.put("mso-request-id", "dffbae0e-5588-4bd6-9749-b0f0adb52312");
123 variables.put("isDebugLogEnabled", "true");
124 variables.put("RCVWFMSG_timeout", "PT5S");
125 variables.put("RCVWFMSG_messageType", "SDNCAEvent");
126 variables.put("RCVWFMSG_correlator", "USOSTCDALTX0101UJZZ31");
128 invokeSubProcess("ReceiveWorkflowMessage", businessKey, variables);
132 waitForProcessEnd(businessKey, 10000);
134 // There is no response from SDNC, so the flow doesn't set WorkflowResponse.
135 String response = (String) getVariableFromHistory(businessKey, "WorkflowResponse");
136 assertNull(response);
137 WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
139 System.out.println(wfe.toString());
140 assertEquals("Receive Workflow Message Timeout Error", wfe.getErrorMessage());
141 assertFalse((boolean)getVariableFromHistory(businessKey, "RCVWFMSG_SuccessIndicator"));