2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
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.infrastructure.scripts
23 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
24 import org.junit.Before
26 import org.mockito.ArgumentCaptor
27 import org.mockito.Captor
28 import org.mockito.Mockito
29 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
31 import static org.junit.Assert.assertEquals
32 import static org.junit.Assert.assertNotNull
33 import static org.mockito.ArgumentMatchers.eq
34 import static org.mockito.Mockito.times
35 import static org.mockito.Mockito.when
37 class ActivateCommunicationServiceTest extends MsoGroovyTest {
40 void init() throws IOException {
41 super.init("ActivateCommunicationService")
45 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
48 void testPreProcessRequest() {
52 "globalSubscriberId": "5GCustomer",
54 "operationId": "test123"
57 when(mockExecution.getVariable("bpmnRequest")).thenReturn(req)
58 when(mockExecution.getVariable("mso-request-id")).thenReturn("54321")
59 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
62 ActivateCommunicationService service = new ActivateCommunicationService()
63 service.preProcessRequest(mockExecution)
64 Mockito.verify(mockExecution, times(5)).setVariable(captor.capture(), captor.capture())
68 void testPrepareInitOperationStatus() {
70 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
71 when(mockExecution.getVariable("operationId")).thenReturn("54321")
73 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("11111")
75 ActivateCommunicationService service = new ActivateCommunicationService()
77 service.prepareInitOperationStatus(mockExecution)
78 Mockito.verify(mockExecution, times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
79 String res = captor.getValue()
85 void testSendSyncResponse() {
86 when(mockExecution.getVariable("operationId")).thenReturn("123456")
87 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
88 ActivateCommunicationService service = new ActivateCommunicationService()
89 service.sendSyncResponse(mockExecution)
90 Mockito.verify(mockExecution, times(1)).setVariable(eq("sentSyncResponse"), captor.capture())
91 def updateVolumeGroupRequest = captor.getValue()
92 assertEquals(updateVolumeGroupRequest, true)
96 void testPreRequestSend2NSMF() {
97 when(mockExecution.getVariable("e2e_service-instance.service-instance-id")).thenReturn("12333")
98 when(mockExecution.getVariable("requestParam")).thenReturn("activate")
99 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("test111")
100 when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5GConsumer")
101 ActivateCommunicationService service = new ActivateCommunicationService()
102 service.preRequestSend2NSMF(mockExecution)
103 Mockito.verify(mockExecution, times(1)).setVariable(eq("CSMF_NSMFRequest"), captor.capture())
104 String resultSuccess = captor.getValue()
108 "globalSubscriberId":"test111",
109 "serviceType":"5GConsumer"
112 assertEquals(expect.replaceAll("\\s+", ""), resultSuccess.replaceAll("\\s+", ""))
116 void testProcessNSMFResponseSuccess() {
117 when(mockExecution.getVariable("CSMF_NSMFResponseCode")).thenReturn(202)
118 when(mockExecution.getVariable("CSMF_NSMFResponse")).thenReturn("""
120 "operationId": "e3819a23-3777-4172-a834-35ee78acf3f4"
124 ActivateCommunicationService service = new ActivateCommunicationService()
125 service.processNSMFResponse(mockExecution)
126 Mockito.verify(mockExecution, times(2)).setVariable(captor.capture(), captor.capture())
127 def resultSuccess = captor.getAllValues()
129 def expect = new ArrayList<>()
130 expect.add("e2eOperationId")
131 expect.add("e3819a23-3777-4172-a834-35ee78acf3f4")
132 expect.add("ProcessNsmfSuccess")
134 assertEquals(expect, resultSuccess)
138 void testProcessNSMFResponseError() {
139 when(mockExecution.getVariable("CSMF_NSMFResponseCode")).thenReturn(500)
140 ActivateCommunicationService service = new ActivateCommunicationService()
141 service.processNSMFResponse(mockExecution)
142 Mockito.verify(mockExecution, times(1)).setVariable(eq("ProcessNsmfSuccess"), captor.capture())
143 String resultSuccess = captor.getValue()
144 assertEquals("ERROR", resultSuccess)
148 void testPrepareUpdateOperationStatus() {
149 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
150 when(mockExecution.getVariable("operationId")).thenReturn("54321")
151 when(mockExecution.getVariable("operationType")).thenReturn("activate")
153 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("11111")
154 when(mockExecution.getVariable("mso.adapters.openecomp.db.endpoint"))
155 .thenReturn("http://localhost:28090/dbadapters/RequestsDbAdapter")
156 ActivateCommunicationService service = new ActivateCommunicationService()
158 service.prepareUpdateOperationStatus(mockExecution)
159 Mockito.verify(mockExecution, times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
160 String res = captor.getValue()
162 String expect = getExpectPayload("updateServiceOperationStatus", "processing", "20",
163 "communication service activate operation processing: waiting nsmf service create finished")
165 assertEquals(expect.replaceAll("\\s+", ""), res.replaceAll("\\s+", ""))
168 private static getExpectPayload = { String type, String result, String progress, String operationContent ->
170 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
171 xmlns:ns="http://org.onap.so/requestsdb">
174 <ns:${type} xmlns:ns="http://org.onap.so/requestsdb">
175 <serviceId>12345</serviceId>
176 <operationId>54321</operationId>
177 <operationType>activate</operationType>
178 <userId>11111</userId>
179 <result>${result}</result>
180 <operationContent>${operationContent}</operationContent>
181 <progress>${progress}</progress>
191 void testPrepareCallCheckProcessStatus() {
192 ActivateCommunicationService service = new ActivateCommunicationService()
193 service.prepareCallCheckProcessStatus(mockExecution)
194 Mockito.verify(mockExecution, times(9)).setVariable(captor.capture(), captor.capture())
195 def resultSuccess = captor.getAllValues()
196 assertNotNull(resultSuccess)
200 void testPrepareCompleteStatus() {
201 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
202 when(mockExecution.getVariable("operationId")).thenReturn("54321")
203 when(mockExecution.getVariable("operationType")).thenReturn("activate")
204 when(mockExecution.getVariable("operationContent"))
205 .thenReturn("communication service activate operation finished")
207 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("11111")
208 when(mockExecution.getVariable("operationStatus"))
209 .thenReturn("deactivated")
210 ActivateCommunicationService service = new ActivateCommunicationService()
212 service.prepareCompleteStatus(mockExecution)
213 Mockito.verify(mockExecution, times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
214 String res = captor.getValue()
216 String expect = getExpectPayload("updateServiceOperationStatus", "deactivated", "100",
217 "communication service activate operation finished")
219 assertEquals(expect.replaceAll("\\s+", ""), res.replaceAll("\\s+", ""))