Containerization feature of SO
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / 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.onap.so.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.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;
40
41 /**
42  * Unit tests for SDNCAdapterRestV1.
43  */
44 @Ignore
45 public class ReceiveWorkflowMessageTest extends WorkflowTest {
46
47         private static final String EOL = "\n";
48
49         private final CallbackSet callbacks = new CallbackSet();
50
51         public ReceiveWorkflowMessageTest() throws IOException {
52                 callbacks.put("sdnc-event-success", JSON, "SDNCAEvent",
53                         "{" + EOL +
54                         "  \"SDNCEvent\": {" + EOL +
55                         "    \"eventType\": \"evenType\"," + EOL +
56                         "    \"eventCorrelatorType\": \"HOST-NAME\"," + EOL +
57                         "    \"eventCorrelator\": \"((CORRELATOR))\"," + EOL +
58                         "    \"params\": {" + EOL +
59                         "      \"success-indicator\":\"Y\"" + EOL +
60                         "        }" +EOL +
61                         "  }" + EOL +
62                         "}" + EOL);
63
64                 callbacks.put("sdnc-event-fail", JSON, "SDNCAEvent",
65                         "{" + EOL +
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 +
73                         "        }" +EOL +
74                         "  }" + EOL +
75                         "}" + EOL);
76         }
77
78         /**
79          * Test the happy path.
80          */
81         @Test
82         @Deployment(resources = {
83                 "subprocess/ReceiveWorkflowMessage.bpmn"
84                 })
85         public void happyPath() throws Exception {
86
87                 logStart();
88
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");
96
97                 invokeSubProcess("ReceiveWorkflowMessage", businessKey, variables);
98                 injectWorkflowMessages(callbacks, "sdnc-event-success");
99                 waitForProcessEnd(businessKey, 10000);
100
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"));
105
106                 logEnd();
107         }
108
109         /**
110          * Test the timeout scenario.
111          */
112         @Test
113         @Deployment(resources = {
114                 "subprocess/ReceiveWorkflowMessage.bpmn"
115                 })
116         public void timeout() throws Exception {
117
118                 logStart();
119
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");
127
128                 invokeSubProcess("ReceiveWorkflowMessage", businessKey, variables);
129
130                 // No injection
131
132                 waitForProcessEnd(businessKey, 10000);
133
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");
138                 assertNotNull(wfe);
139                 System.out.println(wfe.toString());
140                 assertEquals("Receive Workflow Message Timeout Error", wfe.getErrorMessage());
141                 assertFalse((boolean)getVariableFromHistory(businessKey, "RCVWFMSG_SuccessIndicator"));
142
143                 logEnd();
144         }
145 }