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.Mock
33 import org.mockito.MockitoAnnotations
34 import org.mockito.Spy
35 import org.mockito.runners.MockitoJUnitRunner
36 import org.onap.so.bpmn.common.scripts.MsoUtils;
37 import org.onap.so.db.request.beans.InfraActiveRequests
38 import org.onap.so.db.request.client.RequestsDbClient
39 import org.onap.so.bpmn.common.scripts.FalloutHandler;
41 @RunWith(MockitoJUnitRunner.class)
42 class FalloutHandlerTest {
44 public MsoUtils utils = new MsoUtils()
47 FalloutHandler falloutHandler = new FalloutHandler()
50 RequestsDbClient requestsDbClient;
54 MockitoAnnotations.initMocks(this)
57 private String falloutHandlerRequest = """
58 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1" xmlns:ns7="http://org.onap/so/request/types/v1">
60 <ns7:request-id>uCPE1020_STUW105_5002</ns7:request-id>
61 <ns7:request-action>Layer3ServiceActivateRequest</ns7:request-action>
62 <ns7:request-sub-action>CANCEL</ns7:request-sub-action>
63 <ns7:source>OMX</ns7:source>
64 <ns7:order-number>10205000</ns7:order-number>
65 <ns7:order-version>1</ns7:order-version>
67 <sdncadapterworkflow:WorkflowException>
68 <sdncadapterworkflow:ErrorMessage>Some Error Message - Fallout Handler</sdncadapterworkflow:ErrorMessage>
69 <sdncadapterworkflow:ErrorCode>Some Error Code - Fallout Handler</sdncadapterworkflow:ErrorCode>
70 <sdncadapterworkflow:SourceSystemErrorCode>Some Source System Error Code- Fallout Handler</sdncadapterworkflow:SourceSystemErrorCode>
71 </sdncadapterworkflow:WorkflowException>
72 </sdncadapterworkflow:FalloutHandlerRequest>
75 private String falloutHandlerResponse = """<workflow:FalloutHandlerResponse xmlns:workflow="http://org.onap/so/workflow/schema/v1">
76 <workflow:out>Fallout Handler Failed</workflow:out>
77 </workflow:FalloutHandlerResponse>"""
80 public void testPreProcessRequest() {
82 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
84 when(mockExecution.getVariable("FalloutHandlerRequest")).thenReturn(falloutHandlerRequest)
86 falloutHandler.preProcessRequest(mockExecution)
88 verify(mockExecution).setVariable("FH_success", true)
89 verify(mockExecution).setVariable("FH_request_id","uCPE1020_STUW105_5002")
90 verify(mockExecution).setVariable("FH_ErrorCode","Some Error Code - Fallout Handler")
91 verify(mockExecution).setVariable("FH_ErrorMessage","Some Error Message - Fallout Handler")
95 public void testpostProcessResponse(){
97 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
99 when(mockExecution.getVariable("FH_success")).thenReturn(false)
101 falloutHandler.postProcessResponse(mockExecution)
103 // Capture the arguments to setVariable
104 ArgumentCaptor<String> captor1 = ArgumentCaptor.forClass(String.class);
105 ArgumentCaptor<String> captor2 = ArgumentCaptor.forClass(String.class);
107 verify(mockExecution, times(4)).setVariable(captor1.capture(), captor2.capture())
108 List<String> arg2List = captor2.getAllValues()
109 String payloadResponseActual = arg2List.get(1)
111 assertEquals(falloutHandlerResponse.replaceAll("\\s+", ""), payloadResponseActual.replaceAll("\\s+", ""))
113 verify(mockExecution).setVariable("FH_ResponseCode","500")
118 public void testUpdateInfraRequestDB(){
120 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
121 when(mockExecution.getVariable("FH_request_id")).thenReturn("testReqId")
122 when(mockExecution.getVariable("FH_ErrorMessage")).thenReturn("ErrorMessage")
123 when(falloutHandler.getDbClient()).thenReturn(requestsDbClient)
125 falloutHandler.updateInfraRequestDB(mockExecution)
127 InfraActiveRequests infraRequest = new InfraActiveRequests();
128 infraRequest.setLastModifiedBy("BPMN")
129 infraRequest.setStatusMessage("ErrorMessage")
130 infraRequest.setRequestStatus("FAILED")
131 infraRequest.setProgress(100)
133 verify(requestsDbClient, times(1)).updateInfraActiveRequests(infraRequest, null, null)