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.impl.persistence.entity.ExecutionEntity
25 import org.junit.Before
27 import org.junit.runner.RunWith
28 import org.mockito.ArgumentCaptor
29 import org.mockito.MockitoAnnotations
30 import org.mockito.runners.MockitoJUnitRunner
31 import org.onap.so.bpmn.core.WorkflowException
33 import static org.assertj.core.api.Assertions.assertThat
34 import static org.assertj.core.api.Assertions.assertThatThrownBy
35 import static org.mockito.Matchers.eq
36 import static org.mockito.Mockito.*
38 @RunWith(MockitoJUnitRunner.class)
39 class CompleteMsoProcessTest {
42 MockitoAnnotations.initMocks(this)
45 private String completeMsoProcessRequest = """
46 <sdncadapterworkflow:MsoCompletionRequest xmlns:ns="http://org.onap/so/request/types/v1" xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1">
47 <ns:request-information>
48 <ns:request-id>uCPE1020_STUW105_5002</ns:request-id>
49 <ns:request-action>Layer3ServiceActivateRequest</ns:request-action>
50 <ns:request-sub-action>COMPLETE</ns:request-sub-action>
51 <ns:source>OMX</ns:source>
52 <ns:notification-url>http://localhost:28090/CCD/StatusNotification</ns:notification-url>
53 <ns:order-number>10205000</ns:order-number>
54 <ns:order-version>1</ns:order-version>
55 </ns:request-information>
56 <sdncadapterworkflow:mso-bpel-name>UCPELayer3ServiceActivateV1</sdncadapterworkflow:mso-bpel-name>
57 </sdncadapterworkflow:MsoCompletionRequest>
61 public void testPreProcessRequest() {
63 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
64 when(mockExecution.getVariable("CompleteMsoProcessRequest")).thenReturn(completeMsoProcessRequest)
65 when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC");
66 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7");
68 CompleteMsoProcess completeMsoProcess = new CompleteMsoProcess()
69 completeMsoProcess.preProcessRequest(mockExecution)
71 /* Initialize all the process request variables in this block */
72 verify(mockExecution).setVariable("prefix","CMSO_")
73 //verify(mockExecution).setVariable("getLayer3ServiceDetailsV1Response","")
74 verify(mockExecution).setVariable("CMSO_request_id","")
75 verify(mockExecution).setVariable("CMSO_notification-url","")
76 verify(mockExecution).setVariable("CMSO_mso-bpel-name","")
77 verify(mockExecution).setVariable("CMSO_request_action","")
79 verify(mockExecution).setVariable("CMSO_notification-url-Ok", false)
80 verify(mockExecution).setVariable("CMSO_request_id-Ok", false)
82 //updateRequest Adapter process variables
83 verify(mockExecution).setVariable("CMSO_updateRequestResponse", "")
84 verify(mockExecution).setVariable("CMSO_updateRequestResponseCode", "")
85 verify(mockExecution).setVariable("CMSO_updateFinalNotifyAckStatusFailedPayload", "")
87 //Set DB adapter variables here
88 verify(mockExecution).setVariable("CMSO_updateDBStatusToSuccessPayload", "")
89 verify(mockExecution).setVariable("CMSO_updateInfraRequestDBPayload", "")
90 verify(mockExecution).setVariable("CMSO_setUpdateDBstatustoSuccessPayload", "")
93 verify(mockExecution).setVariable("BasicAuthHeaderValue","")
96 verify(mockExecution).setVariable("CompletionHandlerResponse","")
97 verify(mockExecution).setVariable("CMSO_ErrorResponse", null)
98 verify(mockExecution).setVariable("CMSO_ResponseCode", "")
100 verify(mockExecution).setVariable("CMSO_notification-url-Ok",true)
101 verify(mockExecution).setVariable("CMSO_request_id-Ok",true)
102 verify(mockExecution).setVariable("CMSO_notification-url","http://localhost:28090/CCD/StatusNotification")
103 verify(mockExecution).setVariable("CMSO_request_id","uCPE1020_STUW105_5002")
104 verify(mockExecution).setVariable("CMSO_request_action","Layer3ServiceActivateRequest")
105 verify(mockExecution).setVariable("CMSO_source","OMX")
109 private String setUpdateDBstatustoSuccessPayload = """
110 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.onap.so/requestsdb">
113 <req:updateInfraRequest>
114 <requestId>testReqId</requestId>
115 <lastModifiedBy>BPEL</lastModifiedBy>
116 <statusMessage>Resource Completed Successfully</statusMessage>
117 <requestStatus>COMPLETE</requestStatus>
118 <progress>100</progress>
120 </req:updateInfraRequest>
122 </soapenv:Envelope>"""
125 public void testsetUpdateDBstatustoSuccessPayload(){
127 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
128 when(mockExecution.getVariable("CMSO_request_id")).thenReturn("testReqId")
129 when(mockExecution.getVariable("CMSO_mso-bpel-name")).thenReturn("BPEL")
130 when(mockExecution.getVariable("mso.adapters.db.auth")).thenReturn("757A94191D685FD2092AC1490730A4FC");
131 when(mockExecution.getVariable("mso.msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7");
133 CompleteMsoProcess completeMsoProcess = new CompleteMsoProcess()
134 completeMsoProcess.setUpdateDBstatustoSuccessPayload(mockExecution)
136 verify(mockExecution).setVariable("CMSO_setUpdateDBstatustoSuccessPayload",setUpdateDBstatustoSuccessPayload)
139 private String msoCompletionResponse = """onse xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1">
140 <sdncadapterworkflow:out>BPEL BPEL-NAME FAILED</sdncadapterworkflow:out>
141 </sdncadapterworkflow:MsoCompletionResponse>"""
144 private String msoCompletionResponse = """<sdncadapterworkflow:MsoCompletionResponse xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1">
145 <sdncadapterworkflow:out>BPEL BPEL-NAME FAILED</sdncadapterworkflow:out>
146 </sdncadapterworkflow:MsoCompletionResponse>"""
149 void testBuildDataError() {
151 def message = "Some-Message"
153 def mockExecution = mock ExecutionEntity.class
154 when mockExecution.getVariable("CMSO_mso-bpel-name") thenReturn "BPEL-NAME"
155 when mockExecution.getVariable("testProcessKey") thenReturn "CompleteMsoProcess"
157 def completeMsoProcess = new CompleteMsoProcess()
159 assertThatThrownBy { completeMsoProcess.buildDataError(mockExecution, message) } isInstanceOf BpmnError
161 verify mockExecution setVariable("CompleteMsoProcessResponse", msoCompletionResponse)
162 def argumentCaptor = ArgumentCaptor.forClass WorkflowException.class
163 verify mockExecution setVariable(eq("WorkflowException"), argumentCaptor.capture())
164 def capturedException = argumentCaptor.value
166 assertThat capturedException.processKey isEqualTo "CompleteMsoProcess"
167 assertThat capturedException.errorCode isEqualTo 500
168 assertThat capturedException.errorMessage isEqualTo message