Merge "Reorder modifiers"
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / ReceiveWorkflowMessageTest.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.openecomp.mso.bpmn.common;
22
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;
28
29 import java.io.IOException;
30 import java.util.HashMap;
31 import java.util.Map;
32 import java.util.UUID;
33
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;
39
40 /**
41  * Unit tests for SDNCAdapterRestV1.
42  */
43 public class ReceiveWorkflowMessageTest extends WorkflowTest {
44
45         private static final String EOL = "\n";
46
47         private final CallbackSet callbacks = new CallbackSet();
48
49         public ReceiveWorkflowMessageTest() throws IOException {
50                 callbacks.put("sdnc-event-success", JSON, "SDNCAEvent",
51                         "{" + EOL +
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 +
58                         "        }" +EOL +
59                         "  }" + EOL +
60                         "}" + EOL);
61
62                 callbacks.put("sdnc-event-fail", JSON, "SDNCAEvent",
63                         "{" + EOL +
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 +
71                         "        }" +EOL +
72                         "  }" + EOL +
73                         "}" + EOL);
74         }
75
76         /**
77          * Test the happy path.
78          */
79         @Test
80         @Deployment(resources = {
81                 "subprocess/ReceiveWorkflowMessage.bpmn"
82                 })
83         public void happyPath() throws Exception {
84
85                 logStart();
86
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");
94
95                 invokeSubProcess("ReceiveWorkflowMessage", businessKey, variables);
96                 injectWorkflowMessages(callbacks, "sdnc-event-success");
97                 waitForProcessEnd(businessKey, 10000);
98
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"));
103
104                 logEnd();
105         }
106
107         /**
108          * Test the timeout scenario.
109          */
110         @Test
111         @Deployment(resources = {
112                 "subprocess/ReceiveWorkflowMessage.bpmn"
113                 })
114         public void timeout() throws Exception {
115
116                 logStart();
117
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");
125
126                 invokeSubProcess("ReceiveWorkflowMessage", businessKey, variables);
127
128                 // No injection
129
130                 waitForProcessEnd(businessKey, 10000);
131
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");
136                 assertNotNull(wfe);
137                 System.out.println(wfe.toString());
138                 assertEquals("Receive Workflow Message Timeout Error", wfe.getErrorMessage());
139                 assertFalse((boolean)getVariableFromHistory(businessKey, "RCVWFMSG_SuccessIndicator"));
140
141                 logEnd();
142         }
143 }