1 package org.onap.so.bpmn.infrastructure.scripts
3 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
4 import org.junit.Before
6 import org.mockito.ArgumentCaptor
7 import org.mockito.Captor
8 import org.mockito.Mockito
9 import org.onap.aai.domain.yang.ServiceInstance
10 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
11 import org.onap.so.client.aai.AAIObjectType
12 import org.onap.so.client.aai.entities.AAIResultWrapper
13 import org.onap.so.client.aai.entities.uri.AAIResourceUri
14 import org.onap.so.client.aai.entities.uri.AAIUriFactory
16 import javax.ws.rs.NotFoundException
18 import static org.junit.Assert.assertEquals
19 import static org.junit.Assert.assertNotNull
20 import static org.junit.Assert.assertTrue
21 import static org.mockito.ArgumentMatchers.eq
22 import static org.mockito.Mockito.doNothing
23 import static org.mockito.Mockito.spy
24 import static org.mockito.Mockito.times
25 import static org.mockito.Mockito.verify
26 import static org.mockito.Mockito.when
28 class DoDeleteSliceServiceTest extends MsoGroovyTest {
30 void init() throws IOException {
31 super.init("DoDeleteSliceServiceTest")
35 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
38 void testPreProcessRequest(){
39 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
40 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
41 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("e2a747a0-2ca6-476d-ac28-de999cf3fbfe")
43 DoDeleteSliceService doDeleteSliceService = new DoDeleteSliceService()
44 doDeleteSliceService.preProcessRequest(mockExecution)
46 Mockito.verify(mockExecution,times(1)).setVariable(captor.capture() as String, captor.capture())
47 List<ExecutionEntity> values = captor.getAllValues()
52 void testQueryE2ESliceSeriveFromAAI(){
53 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
54 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
55 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
57 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be")
58 DoDeleteSliceService obj = spy(DoDeleteSliceService.class)
60 AAIResultWrapper wrapper = new AAIResultWrapper(mockQuerySliceServiceReturn())
61 when(obj.getAAIClient()).thenReturn(client)
62 when(client.exists(resourceUri)).thenReturn(true)
63 when(client.get(resourceUri, NotFoundException.class)).thenReturn(wrapper)
64 obj.queryE2ESliceSeriveFromAAI(mockExecution)
65 Mockito.verify(mockExecution,times(1)).setVariable(eq("snssai"), captor.capture())
66 String snssai = captor.getValue()
71 void testGetAllottedResFromAAI(){
72 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
73 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
74 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
76 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.ALLOTTED_RESOURCE_ALL, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be")
77 DoDeleteSliceService obj = spy(DoDeleteSliceService.class)
79 AAIResultWrapper wrapper = new AAIResultWrapper(mockQueryAllottedResource())
80 when(obj.getAAIClient()).thenReturn(client)
81 when(client.exists(resourceUri)).thenReturn(true)
82 when(client.get(resourceUri, NotFoundException.class)).thenReturn(wrapper)
83 obj.getAllottedResFromAAI(mockExecution)
84 Mockito.verify(mockExecution,times(1)).setVariable(eq("nsiId"), captor.capture())
85 String nsiId = captor.getValue()
90 void testGetNSIFromAAI(){
91 when(mockExecution.getVariable("nsiId")).thenReturn("5G-888")
92 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
93 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
95 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5GCustomer", "5G", "5G-888")
96 DoDeleteSliceService obj = spy(DoDeleteSliceService.class)
98 AAIResultWrapper wrapper = new AAIResultWrapper(mockNSIReturn())
99 when(obj.getAAIClient()).thenReturn(client)
100 when(client.exists(resourceUri)).thenReturn(true)
101 when(client.get(resourceUri, NotFoundException.class)).thenReturn(wrapper)
102 obj.getNSIFromAAI(mockExecution)
103 Mockito.verify(mockExecution,times(1)).setVariable(eq("nssiIdList"), captor.capture())
104 List<String> nssiIdList = captor.getValue()
105 assertNotNull(nssiIdList)
109 void testGetNSSIListFromAAI(){
110 List<String> nssiIdList = []
111 nssiIdList.add("5G-999")
113 when(mockExecution.getVariable("nssiIdList")).thenReturn(nssiIdList)
114 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
115 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
117 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5GCustomer", "5G", "5G-999")
118 DoDeleteSliceService obj = spy(DoDeleteSliceService.class)
120 AAIResultWrapper wrapper = new AAIResultWrapper(mockNSSIReturn())
121 when(obj.getAAIClient()).thenReturn(client)
122 when(client.exists(resourceUri)).thenReturn(true)
123 when(client.get(resourceUri, NotFoundException.class)).thenReturn(wrapper)
124 obj.getNSSIListFromAAI(mockExecution)
125 Mockito.verify(mockExecution,times(1)).setVariable(eq("nssiInstanceList"), captor.capture())
126 List<ServiceInstance> nssiInstanceList = captor.getValue()
127 assertNotNull(nssiInstanceList)
131 void testGetCurrentNSSI(){
132 ServiceInstance nssi = new ServiceInstance()
133 nssi.setServiceInstanceId("5G-999")
134 nssi.setModelInvariantId("21d57d4b-52ad-4d3c-a798-248b5bb9124a")
135 nssi.setModelVersionId("bfba363e-e39c-4bd9-a9d5-1371c28f4d22")
136 List<ServiceInstance> nssiInstanceList = []
137 nssiInstanceList.add(nssi)
138 when(mockExecution.getVariable("currentNSSIIndex")).thenReturn(0)
139 when(mockExecution.getVariable("nssiInstanceList")).thenReturn(nssiInstanceList)
140 when(mockExecution.getVariable("snssai")).thenReturn("01-010101")
141 when(mockExecution.getVariable("nsiId")).thenReturn("5G-888")
142 when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
143 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5G-777")
144 when(mockExecution.getVariable("msoRequestId")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82")
145 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
146 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
147 when(mockExecution.getVariable("proportion")).thenReturn("90")
149 DoDeleteSliceService ddss = new DoDeleteSliceService()
150 ddss.getCurrentNSSI(mockExecution)
151 verify(mockExecution,times(1)).setVariable(eq("currentNSSI"), captor.capture())
152 Map currentNSSI = captor.getValue()
153 assertTrue(currentNSSI.size()>0)
157 void testQuerySliceProfileFromAAI(){
158 def currentNSSI = [:]
159 currentNSSI.put("nssiServiceInstanceId","5G-999")
160 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
161 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
162 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
164 AAIResultWrapper wrapper = new AAIResultWrapper(mockSliceProfile())
165 AAIResourceUri profileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE_ALL, "5GCustomer", "5G", "5G-999")
167 DoDeleteSliceService obj = spy(DoDeleteSliceService.class)
168 when(obj.getAAIClient()).thenReturn(client)
169 when(client.exists(profileUri)).thenReturn(true)
170 when(client.get(profileUri, NotFoundException.class)).thenReturn(wrapper)
171 obj.querySliceProfileFromAAI(mockExecution)
172 verify(mockExecution,times(1)).setVariable(eq("currentNSSI"), captor.capture())
173 Map value = captor.getValue()
174 assertNotNull(currentNSSI.get('profileId'))
178 void parseNextNSSI(){
179 ServiceInstance nssi = new ServiceInstance()
180 nssi.setServiceInstanceId("5G-999")
181 nssi.setModelInvariantId("21d57d4b-52ad-4d3c-a798-248b5bb9124b")
182 nssi.setModelVersionId("bfba363e-e39c-4bd9-a9d5-1371c28f4d22")
183 List<ServiceInstance> nssiInstanceList = []
184 nssiInstanceList.add(nssi)
185 when(mockExecution.getVariable("currentNSSIIndex")).thenReturn(0)
186 when(mockExecution.getVariable("nssiInstanceList")).thenReturn(nssiInstanceList)
188 DoDeleteSliceService ddss = new DoDeleteSliceService()
189 ddss.parseNextNSSI(mockExecution)
190 verify(mockExecution,times(1)).setVariable(eq("isAllNSSIFinished"), captor.capture())
191 boolean isAllNSSIFinished = captor.getValue()
192 assertTrue(isAllNSSIFinished)
195 private String mockSliceProfile(){
200 "profile-id": "ddf57704-fe8d-417b-882d-2f2a12ddb225",
202 "max-number-of-UEs": 0,
203 "coverage-area-TA-list": "[{\\"province\\":\\"??\\",\\"city\\":\\"???\\",\\"county\\":\\"???\\",\\"street\\":\\"?????\\"}]",
204 "ue-mobility-level": "stationary",
205 "resource-sharing-level": "0",
206 "exp-data-rate-UL": 100,
207 "exp-data-rate-DL": 100,
208 "activity-factor": 0,
214 "traffic-density": 0,
217 "resource-version": "1580800791373"
225 private String mockNSSIReturn(){
229 "service-instance-id": "5G-999",
230 "service-instance-name": "eMBB_Slice_NSSI_5GCustomer",
231 "service-type": "eMBB",
232 "service-role": "nssi",
233 "environment-context": "cn",
234 "model-invariant-id": "21d57d4b-52ad-4d3c-a798-248b5bb9124a",
235 "model-version-id": "bfba363e-e39c-4bd9-a9d5-1371c28f4d22",
236 "service-instance-location-id": "300-01|300-02",
237 "resource-version": "1578449638032",
238 "orchestration-status": "activated",
239 "relationship-list": {
242 "related-to": "service-instance",
243 "relationship-label": "org.onap.relationships.inventory.ComposedOf",
244 "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/5G-888",
245 "relationship-data": [
247 "relationship-key": "customer.global-customer-id",
248 "relationship-value": "5GCustomer"
251 "relationship-key": "service-subscription.service-type",
252 "relationship-value": "5G"
255 "relationship-key": "service-instance.service-instance-id",
256 "relationship-value": "5G-888"
259 "related-to-property": [
261 "property-key": "service-instance.service-instance-name",
262 "property-value": "eMBB_e2e_Slice_Service_5GCustomer"
273 private String mockNSIReturn(){
277 "service-instance-id": "5G-888",
278 "service-instance-name": "eMBB_e2e_Slice_Service_5GCustomer",
279 "service-type": "embb",
280 "service-role": "nsi",
281 "model-invariant-id": "0e9bcb9a-c832-433b-a0c1-74866768f608",
282 "model-version-id": "2c5fd79d-0f84-4057-9222-952cb6f27036",
283 "service-instance-location-id": "300-01|300-02",
284 "resource-version": "1579691104911",
285 "orchestration-status": "activated",
286 "relationship-list": {
289 "related-to": "service-instance",
290 "relationship-label": "org.onap.relationships.inventory.ComposedOf",
291 "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/5G-999",
292 "relationship-data": [
294 "relationship-key": "customer.global-customer-id",
295 "relationship-value": "5GCustomer"
298 "relationship-key": "service-subscription.service-type",
299 "relationship-value": "5G"
302 "relationship-key": "service-instance.service-instance-id",
303 "relationship-value": "5G-999"
306 "related-to-property": [
308 "property-key": "service-instance.service-instance-name",
309 "property-value": "eMBB_Slice_NSSI_5GCustomer"
314 "related-to": "allotted-resource",
315 "relationship-label": "org.onap.relationships.inventory.Uses",
316 "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/5G-777/allotted-resources/allotted-resource/5G-1234",
317 "relationship-data": [
319 "relationship-key": "customer.global-customer-id",
320 "relationship-value": "5GCustomer"
323 "relationship-key": "service-subscription.service-type",
324 "relationship-value": "5G"
327 "relationship-key": "service-instance.service-instance-id",
328 "relationship-value": "5G-777"
331 "relationship-key": "allotted-resource.id",
332 "relationship-value": "5G-1234"
335 "related-to-property": [
337 "property-key": "allotted-resource.description"
340 "property-key": "allotted-resource.allotted-resource-name"
351 private String mockQueryAllottedResource(){
354 "allotted-resource": [
357 "resource-version": "1577454983471",
358 "relationship-list": {
361 "related-to": "service-instance",
362 "relationship-label": "org.onap.relationships.inventory.Uses",
363 "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/5G-888",
364 "relationship-data": [
366 "relationship-key": "customer.global-customer-id",
367 "relationship-value": "5GCustomer"
370 "relationship-key": "service-subscription.service-type",
371 "relationship-value": "5G"
374 "relationship-key": "service-instance.service-instance-id",
375 "relationship-value": "5G-888"
378 "related-to-property": [
380 "property-key": "service-instance.service-instance-name",
381 "property-value": "eMBB_e2e_Slice_Service_5GCustomer"
394 String mockQuerySliceServiceReturn(){
397 "service-instance-id": "5G-777",
398 "service-instance-name": "eMBB_e2e_Slice_Service_5GCustomer",
399 "service-type": "embb",
400 "service-role": "e2eslice-service",
401 "environment-context": "01-010101",
402 "model-invariant-id": "e65d737a-41e0-4ad1-958f-56defdf2e907",
403 "model-version-id": "f2f5967e-72d3-4c5c-b880-e214e71dba4e",
404 "service-instance-location-id": "300-01|300-02",
405 "resource-version": "1578449638436",
406 "orchestration-status": "activated",
407 "relationship-list": {
410 "related-to": "service-instance",
411 "relationship-label": "org.onap.relationships.inventory.ComposedOf",
412 "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/5G-666",
413 "relationship-data": [
415 "relationship-key": "customer.global-customer-id",
416 "relationship-value": "5GCustomer"
419 "relationship-key": "service-subscription.service-type",
420 "relationship-value": "5G"
423 "relationship-key": "service-instance.service-instance-id",
424 "relationship-value": "5G-666"
427 "related-to-property": [
429 "property-key": "service-instance.service-instance-name",
430 "property-value": "eMBB_Slice_Communication_Service_5GCustomer"