Containerization feature of SO
[so.git] / bpmn / MSOCommonBPMN / src / test / groovy / org / onap / so / bpmn / common / scripts / CompleteMsoProcessTest.groovy
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.scripts
22
23 import org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
25 import org.junit.Before
26 import org.junit.Test
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
32
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.*
37
38 @RunWith(MockitoJUnitRunner.class)
39 class CompleteMsoProcessTest {
40         @Before
41         public void init() {
42                 MockitoAnnotations.initMocks(this)
43         }
44
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>
58                 """
59
60         @Test
61         public void testPreProcessRequest() {
62
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");
67
68                 CompleteMsoProcess completeMsoProcess = new CompleteMsoProcess()
69                 completeMsoProcess.preProcessRequest(mockExecution)
70
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","")
78
79                 verify(mockExecution).setVariable("CMSO_notification-url-Ok", false)
80                 verify(mockExecution).setVariable("CMSO_request_id-Ok", false)
81
82                 //updateRequest Adapter process variables
83                 verify(mockExecution).setVariable("CMSO_updateRequestResponse", "")
84                 verify(mockExecution).setVariable("CMSO_updateRequestResponseCode", "")
85                 verify(mockExecution).setVariable("CMSO_updateFinalNotifyAckStatusFailedPayload", "")
86
87                 //Set DB adapter variables here
88                 verify(mockExecution).setVariable("CMSO_updateDBStatusToSuccessPayload", "")
89                 verify(mockExecution).setVariable("CMSO_updateInfraRequestDBPayload", "")
90                 verify(mockExecution).setVariable("CMSO_setUpdateDBstatustoSuccessPayload", "")
91
92                 //Auth variables
93                 verify(mockExecution).setVariable("BasicAuthHeaderValue","")
94
95                 //Response variables
96                 verify(mockExecution).setVariable("CompletionHandlerResponse","")
97                 verify(mockExecution).setVariable("CMSO_ErrorResponse", null)
98                 verify(mockExecution).setVariable("CMSO_ResponseCode", "")
99
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")
106
107         }
108
109         private String setUpdateDBstatustoSuccessPayload = """
110                                                 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://org.onap.so/requestsdb">
111                                                    <soapenv:Header/>
112                                                    <soapenv:Body>
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>
119                                                                  
120                                                       </req:updateInfraRequest>
121                                                    </soapenv:Body>
122                                                 </soapenv:Envelope>"""
123
124         @Test
125         public void testsetUpdateDBstatustoSuccessPayload(){
126
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");
132                 
133                 CompleteMsoProcess completeMsoProcess = new CompleteMsoProcess()
134                 completeMsoProcess.setUpdateDBstatustoSuccessPayload(mockExecution)
135
136                 verify(mockExecution).setVariable("CMSO_setUpdateDBstatustoSuccessPayload",setUpdateDBstatustoSuccessPayload)
137         }
138
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>"""
142
143 /*
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>"""
147 */
148         @Test
149     void testBuildDataError() {
150                 // given
151                 def message = "Some-Message"
152
153                 def mockExecution = mock ExecutionEntity.class
154                 when mockExecution.getVariable("CMSO_mso-bpel-name") thenReturn "BPEL-NAME"
155                 when mockExecution.getVariable("testProcessKey") thenReturn "CompleteMsoProcess"
156
157                 def completeMsoProcess = new CompleteMsoProcess()
158                 // when
159                 assertThatThrownBy { completeMsoProcess.buildDataError(mockExecution, message) } isInstanceOf BpmnError
160                 // then
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
165
166                 assertThat capturedException.processKey isEqualTo "CompleteMsoProcess"
167                 assertThat capturedException.errorCode isEqualTo 500
168                 assertThat capturedException.errorMessage isEqualTo message
169     }
170 }