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.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
26 import org.junit.Before
28 import org.junit.runner.RunWith
29 import org.mockito.ArgumentCaptor
30 import org.mockito.MockitoAnnotations
31 import org.mockito.runners.MockitoJUnitRunner
32 import org.onap.so.bpmn.core.WorkflowException
34 import static org.assertj.core.api.Assertions.assertThat
35 import static org.assertj.core.api.Assertions.assertThatThrownBy
36 import static org.mockito.Matchers.eq
37 import static org.mockito.Mockito.*
39 @RunWith(MockitoJUnitRunner.class)
40 class CompleteMsoProcessTest {
43 MockitoAnnotations.initMocks(this)
46 private String completeMsoProcessRequest = """
47 <sdncadapterworkflow:MsoCompletionRequest xmlns:ns="http://org.onap/so/request/types/v1" xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1">
48 <ns:request-information>
49 <ns:request-id>uCPE1020_STUW105_5002</ns:request-id>
50 <ns:request-action>Layer3ServiceActivateRequest</ns:request-action>
51 <ns:request-sub-action>COMPLETE</ns:request-sub-action>
52 <ns:source>OMX</ns:source>
53 <ns:notification-url>http://localhost:28090/CCD/StatusNotification</ns:notification-url>
54 <ns:order-number>10205000</ns:order-number>
55 <ns:order-version>1</ns:order-version>
56 </ns:request-information>
57 <sdncadapterworkflow:mso-bpel-name>UCPELayer3ServiceActivateV1</sdncadapterworkflow:mso-bpel-name>
58 </sdncadapterworkflow:MsoCompletionRequest>
61 private String completeMsoNetworkProcessRequest = """
62 <aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
63 xmlns:ns="http://org.onap/so/request/types/v1">
64 <request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
65 <request-id>bd631913-cfc6-488b-ba22-6b98504f703d</request-id>
66 <action>CREATE</action>
69 <aetgt:status-message>Resource Completed Successfully</aetgt:status-message>
70 <aetgt:networkId>bd631913-cfc6-488b-ba22-6b98504f703d</aetgt:networkId>
71 <aetgt:mso-bpel-name>BPMN Network action: CREATE</aetgt:mso-bpel-name>
72 </aetgt:MsoCompletionRequest>"""
75 public void testPreProcessRequest() {
77 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
78 when(mockExecution.getVariable("CompleteMsoProcessRequest")).thenReturn(completeMsoProcessRequest)
79 when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC");
80 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7");
82 CompleteMsoProcess completeMsoProcess = new CompleteMsoProcess()
83 completeMsoProcess.preProcessRequest(mockExecution)
85 /* Initialize all the process request variables in this block */
86 verify(mockExecution).setVariable("prefix","CMSO_")
87 //verify(mockExecution).setVariable("getLayer3ServiceDetailsV1Response","")
88 verify(mockExecution).setVariable("CMSO_request_id","")
89 verify(mockExecution).setVariable("CMSO_notification-url","")
90 verify(mockExecution).setVariable("CMSO_mso-bpel-name","")
91 verify(mockExecution).setVariable("CMSO_request_action","")
93 verify(mockExecution).setVariable("CMSO_notification-url-Ok", false)
94 verify(mockExecution).setVariable("CMSO_request_id-Ok", false)
96 //updateRequest Adapter process variables
97 verify(mockExecution).setVariable("CMSO_updateRequestResponse", "")
98 verify(mockExecution).setVariable("CMSO_updateRequestResponseCode", "")
99 verify(mockExecution).setVariable("CMSO_updateFinalNotifyAckStatusFailedPayload", "")
101 //Set DB adapter variables here
102 verify(mockExecution).setVariable("CMSO_updateDBStatusToSuccessPayload", "")
103 verify(mockExecution).setVariable("CMSO_updateInfraRequestDBPayload", "")
104 verify(mockExecution).setVariable("CMSO_setUpdateDBstatustoSuccessPayload", "")
107 verify(mockExecution).setVariable("BasicAuthHeaderValue","")
110 verify(mockExecution).setVariable("CompletionHandlerResponse","")
111 verify(mockExecution).setVariable("CMSO_ErrorResponse", null)
112 verify(mockExecution).setVariable("CMSO_ResponseCode", "")
114 verify(mockExecution).setVariable("CMSO_notification-url-Ok",true)
115 verify(mockExecution).setVariable("CMSO_request_id-Ok",true)
116 verify(mockExecution).setVariable("CMSO_notification-url","http://localhost:28090/CCD/StatusNotification")
117 verify(mockExecution).setVariable("CMSO_request_id","uCPE1020_STUW105_5002")
118 verify(mockExecution).setVariable("CMSO_request_action","Layer3ServiceActivateRequest")
119 verify(mockExecution).setVariable("CMSO_source","OMX")
123 private String setUpdateDBstatustoSuccessPayload = """
124 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.onap.so/requestsdb">
127 <req:updateInfraRequest>
128 <requestId>testReqId</requestId>
129 <lastModifiedBy>BPEL</lastModifiedBy>
130 <statusMessage>Resource Completed Successfully</statusMessage>
131 <requestStatus>COMPLETE</requestStatus>
132 <progress>100</progress>
133 <networkId>bd631913-cfc6-488b-ba22-6b98504f703d</networkId>
134 </req:updateInfraRequest>
136 </soapenv:Envelope>"""
139 public void testsetUpdateDBstatustoSuccessPayload(){
141 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
142 when(mockExecution.getVariable("CMSO_request_id")).thenReturn("testReqId")
143 when(mockExecution.getVariable("CMSO_mso-bpel-name")).thenReturn("BPEL")
144 when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC");
145 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7");
146 when(mockExecution.getVariable("CompleteMsoProcessRequest")).thenReturn(completeMsoNetworkProcessRequest);
148 CompleteMsoProcess completeMsoProcess = new CompleteMsoProcess()
149 completeMsoProcess.setUpdateDBstatustoSuccessPayload(mockExecution)
151 verify(mockExecution).setVariable("CMSO_setUpdateDBstatustoSuccessPayload",setUpdateDBstatustoSuccessPayload)
154 private String msoCompletionResponse = """onse xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1">
155 <sdncadapterworkflow:out>BPEL BPEL-NAME FAILED</sdncadapterworkflow:out>
156 </sdncadapterworkflow:MsoCompletionResponse>"""
159 void testBuildDataError() {
161 def message = "Some-Message"
163 def mockExecution = mock ExecutionEntity.class
164 when mockExecution.getVariable("CMSO_mso-bpel-name") thenReturn "BPEL-NAME"
165 when mockExecution.getVariable("testProcessKey") thenReturn "CompleteMsoProcess"
167 def completeMsoProcess = new CompleteMsoProcess()
169 assertThatThrownBy { completeMsoProcess.buildDataError(mockExecution, message) } isInstanceOf BpmnError
171 verify mockExecution setVariable("CompleteMsoProcessResponse", msoCompletionResponse)
172 def argumentCaptor = ArgumentCaptor.forClass WorkflowException.class
173 verify mockExecution setVariable(eq("WorkflowException"), argumentCaptor.capture())
174 def capturedException = argumentCaptor.value
176 assertThat capturedException.processKey isEqualTo "CompleteMsoProcess"
177 assertThat capturedException.errorCode isEqualTo 500
178 assertThat capturedException.errorMessage isEqualTo message
182 void postProcessResponse_successful() {
183 DelegateExecution mockExecution = mock(DelegateExecution.class)
184 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
185 when(mockExecution.getVariable("CMSO_mso-bpel-name")).thenReturn("mso-bpel-test")
186 new CompleteMsoProcess().postProcessResponse(mockExecution)
188 String expectedResponse = "<sdncadapterworkflow:MsoCompletionResponse xmlns:sdncadapterworkflow=\"http://ecomp.com/mso/workflow/schema/v1\">\n" +
189 " <sdncadapterworkflow:out>BPEL mso-bpel-test completed</sdncadapterworkflow:out>\n" +
190 "</sdncadapterworkflow:MsoCompletionResponse>"
192 verify(mockExecution).setVariable("WorkflowResponse", expectedResponse)
193 verify(mockExecution).setVariable("CompleteMsoProcessResponse", expectedResponse)
194 verify(mockExecution).setVariable("CMSO_ResponseCode", "200")