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.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.Test;
36 import org.openecomp.mso.bpmn.common.WorkflowTest;
37 import org.openecomp.mso.bpmn.common.WorkflowTest.CallbackSet;
38 import org.openecomp.mso.bpmn.core.WorkflowException;
41 * Unit tests for SDNCAdapterRestV1.
43 public class ReceiveWorkflowMessageTest extends WorkflowTest {
45 private static final String EOL = "\n";
47 private final CallbackSet callbacks = new CallbackSet();
49 public ReceiveWorkflowMessageTest() throws IOException {
50 callbacks.put("sdnc-event-success", JSON, "SDNCAEvent",
52 " \"SDNCEvent\": {" + EOL +
53 " \"eventType\": \"UCPE-ACTIVATION\"," + EOL +
54 " \"eventCorrelatorType\": \"UCPE-HOST-NAME\"," + EOL +
55 " \"eventCorrelator\": \"((CORRELATOR))\"," + EOL +
56 " \"params\": {" + EOL +
57 " \"success-indicator\":\"Y\"" + EOL +
62 callbacks.put("sdnc-event-fail", JSON, "SDNCAEvent",
64 " \"SDNCEvent\": {" + EOL +
65 " \"eventType\": \"UCPE-ACTIVATION\"," + EOL +
66 " \"eventCorrelatorType\": \"UCPE-HOST-NAME\"," + EOL +
67 " \"eventCorrelator\": \"((CORRELATOR))\"," + EOL +
68 " \"params\": {" + EOL +
69 " \"success-indicator\":\"N\"," + EOL +
70 " \"error-message\":\"SOMETHING BAD HAPPENED\"" + EOL +
77 * Test the happy path.
80 @Deployment(resources = {
81 "subprocess/ReceiveWorkflowMessage.bpmn"
83 public void happyPath() throws Exception {
87 String businessKey = UUID.randomUUID().toString();
88 Map<String, Object> variables = new HashMap<>();
89 variables.put("mso-request-id", "dffbae0e-5588-4bd6-9749-b0f0adb52312");
90 variables.put("isDebugLogEnabled", "true");
91 variables.put("RCVWFMSG_timeout", "PT1M");
92 variables.put("RCVWFMSG_messageType", "SDNCAEvent");
93 variables.put("RCVWFMSG_correlator", "USOSTCDALTX0101UJZZ31");
95 invokeSubProcess("ReceiveWorkflowMessage", businessKey, variables);
96 injectWorkflowMessages(callbacks, "sdnc-event-success");
97 waitForProcessEnd(businessKey, 10000);
99 String response = (String) getVariableFromHistory(businessKey, "WorkflowResponse");
100 System.out.println("Response:\n" + response);
101 assertTrue(response.contains("\"SDNCEvent\""));
102 assertTrue((boolean)getVariableFromHistory(businessKey, "RCVWFMSG_SuccessIndicator"));
108 * Test the timeout scenario.
111 @Deployment(resources = {
112 "subprocess/ReceiveWorkflowMessage.bpmn"
114 public void timeout() throws Exception {
118 String businessKey = UUID.randomUUID().toString();
119 Map<String, Object> variables = new HashMap<>();
120 variables.put("mso-request-id", "dffbae0e-5588-4bd6-9749-b0f0adb52312");
121 variables.put("isDebugLogEnabled", "true");
122 variables.put("RCVWFMSG_timeout", "PT5S");
123 variables.put("RCVWFMSG_messageType", "SDNCAEvent");
124 variables.put("RCVWFMSG_correlator", "USOSTCDALTX0101UJZZ31");
126 invokeSubProcess("ReceiveWorkflowMessage", businessKey, variables);
130 waitForProcessEnd(businessKey, 10000);
132 // There is no response from SDNC, so the flow doesn't set WorkflowResponse.
133 String response = (String) getVariableFromHistory(businessKey, "WorkflowResponse");
134 assertNull(response);
135 WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
137 System.out.println(wfe.toString());
138 assertEquals("Receive Workflow Message Timeout Error", wfe.getErrorMessage());
139 assertFalse((boolean)getVariableFromHistory(businessKey, "RCVWFMSG_SuccessIndicator"));