1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
package org.openecomp.mso.bpmn.common;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.camunda.bpm.engine.test.Deployment;
import org.junit.Test;
import org.openecomp.mso.bpmn.common.WorkflowTest;
import org.openecomp.mso.bpmn.common.WorkflowTest.CallbackSet;
import org.openecomp.mso.bpmn.core.WorkflowException;
/**
* Unit tests for SDNCAdapterRestV1.
*/
public class ReceiveWorkflowMessageTest extends WorkflowTest {
private static final String EOL = "\n";
private final CallbackSet callbacks = new CallbackSet();
public ReceiveWorkflowMessageTest() throws IOException {
callbacks.put("sdnc-event-success", JSON, "SDNCAEvent",
"{" + EOL +
" \"SDNCEvent\": {" + EOL +
" \"eventType\": \"UCPE-ACTIVATION\"," + EOL +
" \"eventCorrelatorType\": \"UCPE-HOST-NAME\"," + EOL +
" \"eventCorrelator\": \"((CORRELATOR))\"," + EOL +
" \"params\": {\"entry\":[" + EOL +
" {\"key\": \"success-indicator\", \"value\":\"Y\"}" + EOL +
" ]}" +EOL +
" }" + EOL +
"}" + EOL);
callbacks.put("sdnc-event-fail", JSON, "SDNCAEvent",
"{" + EOL +
" \"SDNCEvent\": {" + EOL +
" \"eventType\": \"UCPE-ACTIVATION\"," + EOL +
" \"eventCorrelatorType\": \"UCPE-HOST-NAME\"," + EOL +
" \"eventCorrelator\": \"((CORRELATOR))\"," + EOL +
" \"params\": {\"entry\":[" + EOL +
" {\"key\": \"success-indicator\", \"value\":\"N\"}" + EOL +
" {\"key\": \"error-message\", \"value\":\"SOMETHING BAD HAPPENED\"}" + EOL +
" ]}" +EOL +
" }" + EOL +
"}" + EOL);
}
/**
* Test the happy path.
*/
@Test
@Deployment(resources = {
"subprocess/ReceiveWorkflowMessage.bpmn"
})
public void happyPath() throws Exception {
logStart();
String businessKey = UUID.randomUUID().toString();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("mso-request-id", "dffbae0e-5588-4bd6-9749-b0f0adb52312");
variables.put("isDebugLogEnabled", "true");
variables.put("RCVWFMSG_timeout", "PT1M");
variables.put("RCVWFMSG_messageType", "SDNCAEvent");
variables.put("RCVWFMSG_correlator", "USOSTCDALTX0101UJZZ31");
invokeSubProcess("ReceiveWorkflowMessage", businessKey, variables);
injectWorkflowMessages(callbacks, "sdnc-event-success");
waitForProcessEnd(businessKey, 10000);
String response = (String) getVariableFromHistory(businessKey, "WorkflowResponse");
System.out.println("Response:\n" + response);
assertTrue(response.contains("\"SDNCEvent\""));
assertTrue((boolean)getVariableFromHistory(businessKey, "RCVWFMSG_SuccessIndicator"));
logEnd();
}
/**
* Test the timeout scenario.
*/
@Test
@Deployment(resources = {
"subprocess/ReceiveWorkflowMessage.bpmn"
})
public void timeout() throws Exception {
logStart();
String businessKey = UUID.randomUUID().toString();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("mso-request-id", "dffbae0e-5588-4bd6-9749-b0f0adb52312");
variables.put("isDebugLogEnabled", "true");
variables.put("RCVWFMSG_timeout", "PT0.1S");
variables.put("RCVWFMSG_messageType", "SDNCAEvent");
variables.put("RCVWFMSG_correlator", "USOSTCDALTX0101UJZZ31");
invokeSubProcess("ReceiveWorkflowMessage", businessKey, variables);
// No injection
waitForProcessEnd(businessKey, 10000);
// There is no response from SDNC, so the flow doesn't set WorkflowResponse.
String response = (String) getVariableFromHistory(businessKey, "WorkflowResponse");
assertNull(response);
WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
assertNotNull(wfe);
System.out.println(wfe.toString());
assertEquals("Receive Workflow Message Timeout Error", wfe.getErrorMessage());
assertFalse((boolean)getVariableFromHistory(businessKey, "RCVWFMSG_SuccessIndicator"));
logEnd();
}
}
|