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.onap.so.bpmn.common.scripts
23 import org.junit.runner.RunWith;
24 import static org.mockito.Mockito.*
25 import static org.junit.Assert.*;
27 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
28 import org.junit.Before
30 import org.junit.runner.RunWith
31 import org.mockito.ArgumentCaptor;
32 import org.mockito.MockitoAnnotations
33 import org.mockito.runners.MockitoJUnitRunner
34 import org.onap.so.bpmn.common.scripts.MsoUtils;
35 import org.onap.so.bpmn.common.scripts.FalloutHandler;
37 @RunWith(MockitoJUnitRunner.class)
38 class FalloutHandlerTest {
40 public MsoUtils utils = new MsoUtils()
44 MockitoAnnotations.initMocks(this)
47 private String falloutHandlerRequest = """
48 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1" xmlns:ns7="http://org.onap/so/request/types/v1">
49 <ns7:request-information>
50 <ns7:request-id>uCPE1020_STUW105_5002</ns7:request-id>
51 <ns7:request-action>Layer3ServiceActivateRequest</ns7:request-action>
52 <ns7:request-sub-action>CANCEL</ns7:request-sub-action>
53 <ns7:source>OMX</ns7:source>
54 <ns7:order-number>10205000</ns7:order-number>
55 <ns7:order-version>1</ns7:order-version>
56 </ns7:request-information>
57 <sdncadapterworkflow:WorkflowException>
58 <sdncadapterworkflow:ErrorMessage>Some Error Message - Fallout Handler</sdncadapterworkflow:ErrorMessage>
59 <sdncadapterworkflow:ErrorCode>Some Error Code - Fallout Handler</sdncadapterworkflow:ErrorCode>
60 <sdncadapterworkflow:SourceSystemErrorCode>Some Source System Error Code- Fallout Handler</sdncadapterworkflow:SourceSystemErrorCode>
61 </sdncadapterworkflow:WorkflowException>
62 </sdncadapterworkflow:FalloutHandlerRequest>
65 private String falloutHandlerResponse = """<workflow:FalloutHandlerResponse xmlns:workflow="http://org.onap/so/workflow/schema/v1">
66 <workflow:out>Fallout Handler Failed</workflow:out>
67 </workflow:FalloutHandlerResponse>"""
70 public void testPreProcessRequest() {
72 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
74 when(mockExecution.getVariable("FalloutHandlerRequest")).thenReturn(falloutHandlerRequest)
75 when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn("5E12ACACBD552A415E081E29F2C4772F9835792A51C766CCFDD7433DB5220B59969CB2798C");
76 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7");
78 FalloutHandler falloutHandler = new FalloutHandler()
79 falloutHandler.preProcessRequest(mockExecution)
81 /* Initialize all the process request variables in this block */
82 verify(mockExecution).setVariable("prefix","FH_")
83 //verify(mockExecution).setVariable("getLayer3ServiceDetailsV1Response","")
85 //These variables are form the input Message to the BPMN
86 verify(mockExecution).setVariable("FH_request_id","")
87 verify(mockExecution).setVariable("FH_request_action","")
88 verify(mockExecution).setVariable("FH_notification-url","")
89 verify(mockExecution).setVariable("FH_mso-bpel-name","")
90 verify(mockExecution).setVariable("FH_ErrorCode", "")
91 verify(mockExecution).setVariable("FH_ErrorMessage", "")
93 verify(mockExecution).setVariable("FH_notification-url-Ok", false)
94 verify(mockExecution).setVariable("FH_request_id-Ok", false)
96 //These variables are for Get Mso Aai Password Adapter
97 verify(mockExecution).setVariable("FH_deliveryStatus", true)
99 //update Response Status to pending ...Adapter variables
100 verify(mockExecution).setVariable("FH_updateResponseStatusPayload", null)
101 verify(mockExecution).setVariable("FH_updateResponseStatusResponse", null)
103 //update Request Gamma ...Adapter variables
104 verify(mockExecution).setVariable("FH_updateRequestGammaPayload", "")
105 verify(mockExecution).setVariable("FH_updateRequestGammaResponse", null)
106 verify(mockExecution).setVariable("FH_updateRequestGammaResponseCode", null)
108 //update Request Infra ...Adapter variables
109 verify(mockExecution).setVariable("FH_updateRequestInfraPayload", "")
110 verify(mockExecution).setVariable("FH_updateRequestInfraResponse", null)
111 verify(mockExecution).setVariable("FH_updateRequestInfraResponseCode", null)
113 //assign False to success variable
114 verify(mockExecution).setVariable("FH_success", true)
116 //Set notify status to Failed variable
117 verify(mockExecution).setVariable("FH_NOTIFY_STATUS", "SUCCESS")
119 //Set DB update variable
120 verify(mockExecution).setVariable("FH_updateRequestPayload", "")
121 verify(mockExecution).setVariable("FH_updateRequestResponse", null)
122 verify(mockExecution).setVariable("FH_updateRequestResponseCode", null)
125 verify(mockExecution).setVariable("BasicAuthHeaderValue","")
128 verify(mockExecution).setVariable("FalloutHandlerResponse","")
129 verify(mockExecution).setVariable("FH_ErrorResponse", null)
130 verify(mockExecution).setVariable("FH_ResponseCode", "")
132 verify(mockExecution).setVariable("FH_request_id-Ok",true)
133 verify(mockExecution).setVariable("FH_request_id","uCPE1020_STUW105_5002")
134 verify(mockExecution).setVariable("FH_request_action","Layer3ServiceActivateRequest")
135 verify(mockExecution).setVariable("FH_source","OMX")
136 verify(mockExecution).setVariable("FH_ErrorCode","Some Error Code - Fallout Handler")
137 verify(mockExecution).setVariable("FH_ErrorMessage","Some Error Message - Fallout Handler")
142 public void testpostProcessResponse(){
144 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
146 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
147 when(mockExecution.getVariable("FH_success")).thenReturn(false)
149 FalloutHandler falloutHandler = new FalloutHandler()
150 falloutHandler.postProcessResponse(mockExecution)
152 // Capture the arguments to setVariable
153 ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
154 ArgumentCaptor<String> captor2 = ArgumentCaptor.forClass(String.class);
156 verify(mockExecution, times(4)).setVariable(captor1.capture(), captor2.capture())
157 List<String> arg2List = captor2.getAllValues()
158 String payloadResponseActual = arg2List.get(1)
160 assertEquals(falloutHandlerResponse.replaceAll("\\s+", ""), payloadResponseActual.replaceAll("\\s+", ""))
162 verify(mockExecution).setVariable("FH_ResponseCode","500")
165 private String updateRequestPayload = """
166 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.onap.so/requestsdb">
170 <requestId>testReqId</requestId>
171 <lastModifiedBy>BPEL</lastModifiedBy>
172 <finalErrorMessage>ErrorMessage</finalErrorMessage>
173 <finalErrorCode>ErrorCode</finalErrorCode>
174 <status>FAILED</status>
175 <responseStatus>NotifyStatus</responseStatus>
182 public void testupdateRequestPayload(){
184 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
185 when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId")
186 when(mockExecution.getVariable("FH_ErrorMessage")).thenReturn("ErrorMessage")
187 when(mockExecution.getVariable("FH_ErrorCode")).thenReturn("ErrorCode")
188 when(mockExecution.getVariable("FH_NOTIFY_STATUS")).thenReturn("NotifyStatus")
190 FalloutHandler falloutHandler = new FalloutHandler()
191 falloutHandler.updateRequestPayload(mockExecution)
193 // Capture the arguments to setVariable
194 ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
195 ArgumentCaptor<String> captor2 = ArgumentCaptor.forClass(String.class);
197 verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture())
198 List<String> arg2List = captor2.getAllValues()
199 String payloadRequestActual = arg2List.get(0)
201 assertEquals(updateRequestPayload.replaceAll("\\s+", ""), payloadRequestActual.replaceAll("\\s+", ""))
204 private String updateRequestInfraPayload = """
205 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.onap.so/requestsdb">
208 <req:updateInfraRequest>
209 <requestId>testReqId</requestId>
210 <lastModifiedBy>BPEL</lastModifiedBy>
211 <statusMessage>ErrorMessage</statusMessage>
212 <requestStatus>FAILED</requestStatus>
213 <progress>100</progress>
214 </req:updateInfraRequest>
220 public void testupdateRequestInfraPayload(){
222 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
223 when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId")
224 when(mockExecution.getVariable("FH_ErrorMessage")).thenReturn("ErrorMessage")
226 FalloutHandler falloutHandler = new FalloutHandler()
227 falloutHandler.updateRequestInfraPayload(mockExecution)
229 // Capture the arguments to setVariable
230 ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
231 ArgumentCaptor<String> captor2 = ArgumentCaptor.forClass(String.class);
233 verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture())
234 List<String> arg2List = captor2.getAllValues()
235 String payloadRequestActual = arg2List.get(0)
237 assertEquals(updateRequestInfraPayload.replaceAll("\\s+", ""), payloadRequestActual.replaceAll("\\s+", ""))
240 private String updateRequestGammaPayload = """
241 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.onap.so/requestsdb">
245 <requestId>testReqId</requestId>
246 <lastModifiedBy>BPEL</lastModifiedBy>
247 <finalErrorMessage>ErrorMessage</finalErrorMessage>
248 <finalErrorCode>ErrorCode</finalErrorCode>
249 <status>FAILED</status>
256 public void testupdateRequestGammaPayload(){
258 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
259 when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId")
260 when(mockExecution.getVariable("FH_ErrorMessage")).thenReturn("ErrorMessage")
261 when(mockExecution.getVariable("FH_ErrorCode")).thenReturn("ErrorCode")
262 when(mockExecution.getVariable("mso.default.adapter.namespace")).thenReturn("http://org.onap.so");
264 FalloutHandler falloutHandler = new FalloutHandler()
265 falloutHandler.updateRequestGammaPayload(mockExecution)
267 // Capture the arguments to setVariable
268 ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
269 ArgumentCaptor<String> captor2 = ArgumentCaptor.forClass(String.class);
271 verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture())
272 List<String> arg2List = captor2.getAllValues()
273 String payloadRequestActual = arg2List.get(0)
275 assertEquals(updateRequestGammaPayload.replaceAll("\\s+", ""), payloadRequestActual.replaceAll("\\s+", ""))
279 String updateResponseStatusPayload = """
280 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.onap.so/requestsdb">
283 <req:updateResponseStatus>
284 <requestId>testReqId</requestId>
285 <lastModifiedBy>BPEL</lastModifiedBy>
286 <responseStatus>SENDING_FINAL_NOTIFY</responseStatus>
287 </req:updateResponseStatus>
293 public void testupdateResponseStatusPayload(){
295 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
296 when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId")
298 FalloutHandler falloutHandler = new FalloutHandler()
299 falloutHandler.updateResponseStatusPayload(mockExecution)
301 // Capture the arguments to setVariable
302 ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
303 ArgumentCaptor<String> captor2 = ArgumentCaptor.forClass(String.class);
305 verify(mockExecution, times(1)).setVariable(captor1.capture(), captor2.capture())
306 List<String> arg2List = captor2.getAllValues()
307 String payloadResponseActual = arg2List.get(0)
309 assertEquals(updateResponseStatusPayload.replaceAll("\\s+", ""), payloadResponseActual.replaceAll("\\s+", ""))