a8065159747938eb80f7a11bb2b4c47f889afae2
[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\": {\"entry\":[" + EOL +
57                         "      {\"key\": \"success-indicator\", \"value\":\"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\": {\"entry\":[" + EOL +
69                         "      {\"key\": \"success-indicator\", \"value\":\"N\"}" + EOL +
70                         "      {\"key\": \"error-message\", \"value\":\"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                 logStart();
116
117                 String businessKey = UUID.randomUUID().toString();
118                 Map<String, Object> variables = new HashMap<>();
119                 variables.put("mso-request-id", "dffbae0e-5588-4bd6-9749-b0f0adb52312");
120                 variables.put("isDebugLogEnabled", "true");
121                 variables.put("RCVWFMSG_timeout", "PT0.1S");
122                 variables.put("RCVWFMSG_messageType", "SDNCAEvent");
123                 variables.put("RCVWFMSG_correlator", "USOSTCDALTX0101UJZZ31");
124
125                 invokeSubProcess("ReceiveWorkflowMessage", businessKey, variables);
126
127                 // No injection
128                 
129                 waitForProcessEnd(businessKey, 10000);
130                 
131                 // There is no response from SDNC, so the flow doesn't set WorkflowResponse.
132                 String response = (String) getVariableFromHistory(businessKey, "WorkflowResponse");
133                 assertNull(response);
134                 WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
135                 assertNotNull(wfe);
136                 System.out.println(wfe.toString());
137                 assertEquals("Receive Workflow Message Timeout Error", wfe.getErrorMessage());
138                 assertFalse((boolean)getVariableFromHistory(businessKey, "RCVWFMSG_SuccessIndicator"));
139                 
140                 logEnd();
141         }
142 }