099fc6f8aa4972e27ef65f36ea4b964a67b94391
[so.git] /
1 package org.onap.so.bpmn.infrastructure.scripts
2
3 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
4 import org.junit.Before
5 import org.junit.Test
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
15
16 import javax.ws.rs.NotFoundException
17
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
27
28 class DoDeleteSliceServiceTest extends MsoGroovyTest {
29     @Before
30     void init() throws IOException {
31         super.init("DoDeleteSliceServiceTest")
32     }
33
34     @Captor
35     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
36
37     @Test
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")
42
43         DoDeleteSliceService doDeleteSliceService = new DoDeleteSliceService()
44         doDeleteSliceService.preProcessRequest(mockExecution)
45
46         Mockito.verify(mockExecution,times(1)).setVariable(captor.capture() as String, captor.capture())
47         List<ExecutionEntity> values = captor.getAllValues()
48         assertNotNull(values)
49     }
50
51     @Test
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")
56
57         AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be")
58         DoDeleteSliceService obj = spy(DoDeleteSliceService.class)
59
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()
67         assertNotNull(snssai)
68     }
69
70     @Test
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")
75
76         AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.ALLOTTED_RESOURCE_ALL, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be")
77         DoDeleteSliceService obj = spy(DoDeleteSliceService.class)
78
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()
86         assertNotNull(nsiId)
87     }
88
89     @Test
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")
94
95         AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5GCustomer", "5G", "5G-888")
96         DoDeleteSliceService obj = spy(DoDeleteSliceService.class)
97
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)
106     }
107
108     @Test
109     void testGetNSSIListFromAAI(){
110         List<String> nssiIdList = []
111         nssiIdList.add("5G-999")
112
113         when(mockExecution.getVariable("nssiIdList")).thenReturn(nssiIdList)
114         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
115         when(mockExecution.getVariable("serviceType")).thenReturn("5G")
116
117         AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5GCustomer", "5G", "5G-999")
118         DoDeleteSliceService obj = spy(DoDeleteSliceService.class)
119
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)
128     }
129
130     @Test
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")
148
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)
154     }
155
156     @Test
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")
163
164         AAIResultWrapper wrapper = new AAIResultWrapper(mockSliceProfile())
165         AAIResourceUri profileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE_ALL, "5GCustomer", "5G", "5G-999")
166
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'))
175     }
176
177     @Test
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)
187
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)
193     }
194
195     private String mockSliceProfile(){
196         String expect =
197                 """{
198                         "slice-profile": [
199                             {
200                                 "profile-id": "ddf57704-fe8d-417b-882d-2f2a12ddb225",
201                                 "latency": 20,
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,
209                                 "e2e-latency": 0,
210                                 "jitter": 0,
211                                 "survival-time": 0,
212                                 "exp-data-rate": 0,
213                                 "payload-size": 0,
214                                 "traffic-density": 0,
215                                 "conn-density": 0,
216                                 "s-nssai": "01003",
217                                 "resource-version": "1580800791373"
218                             }
219                         ]
220                     }
221                 """
222         return expect
223     }
224
225     private String mockNSSIReturn(){
226         String expect =
227                 """
228                     {
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": {
240                             "relationship": [
241                                 {
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": [
246                                         {
247                                             "relationship-key": "customer.global-customer-id",
248                                             "relationship-value": "5GCustomer"
249                                         },
250                                         {
251                                             "relationship-key": "service-subscription.service-type",
252                                             "relationship-value": "5G"
253                                         },
254                                         {
255                                             "relationship-key": "service-instance.service-instance-id",
256                                             "relationship-value": "5G-888"
257                                         }
258                                     ],
259                                     "related-to-property": [
260                                         {
261                                             "property-key": "service-instance.service-instance-name",
262                                             "property-value": "eMBB_e2e_Slice_Service_5GCustomer"
263                                         }
264                                     ]
265                                 }
266                             ]
267                         }
268                     }
269                 """
270         return expect
271     }
272
273     private String mockNSIReturn(){
274         String expect =
275                 """
276                     {
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": {
287                             "relationship": [
288                                 {
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": [
293                                         {
294                                             "relationship-key": "customer.global-customer-id",
295                                             "relationship-value": "5GCustomer"
296                                         },
297                                         {
298                                             "relationship-key": "service-subscription.service-type",
299                                             "relationship-value": "5G"
300                                         },
301                                         {
302                                             "relationship-key": "service-instance.service-instance-id",
303                                             "relationship-value": "5G-999"
304                                         }
305                                     ],
306                                     "related-to-property": [
307                                         {
308                                             "property-key": "service-instance.service-instance-name",
309                                             "property-value": "eMBB_Slice_NSSI_5GCustomer"
310                                         }
311                                     ]
312                                 },
313                                 {
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": [
318                                         {
319                                             "relationship-key": "customer.global-customer-id",
320                                             "relationship-value": "5GCustomer"
321                                         },
322                                         {
323                                             "relationship-key": "service-subscription.service-type",
324                                             "relationship-value": "5G"
325                                         },
326                                         {
327                                             "relationship-key": "service-instance.service-instance-id",
328                                             "relationship-value": "5G-777"
329                                         },
330                                         {
331                                             "relationship-key": "allotted-resource.id",
332                                             "relationship-value": "5G-1234"
333                                         }
334                                     ],
335                                     "related-to-property": [
336                                         {
337                                             "property-key": "allotted-resource.description"
338                                         },
339                                         {
340                                             "property-key": "allotted-resource.allotted-resource-name"
341                                         }
342                                     ]
343                                 }
344                             ]
345                         }
346                     }
347                 """
348         return expect
349     }
350
351     private String mockQueryAllottedResource(){
352         String expect =
353                 """{
354                         "allotted-resource": [
355                             {
356                                 "id": "5G-1234",
357                                 "resource-version": "1577454983471",
358                                 "relationship-list": {
359                                     "relationship": [
360                                         {
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": [
365                                                 {
366                                                     "relationship-key": "customer.global-customer-id",
367                                                     "relationship-value": "5GCustomer"
368                                                 },
369                                                 {
370                                                     "relationship-key": "service-subscription.service-type",
371                                                     "relationship-value": "5G"
372                                                 },
373                                                 {
374                                                     "relationship-key": "service-instance.service-instance-id",
375                                                     "relationship-value": "5G-888"
376                                                 }
377                                             ],
378                                             "related-to-property": [
379                                                 {
380                                                     "property-key": "service-instance.service-instance-name",
381                                                     "property-value": "eMBB_e2e_Slice_Service_5GCustomer"
382                                                 }
383                                             ]
384                                         }
385                                     ]
386                                 }
387                             }
388                         ]
389                     }
390                 """
391         return expect
392     }
393
394     String mockQuerySliceServiceReturn(){
395         String expect =
396                 """{
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": {
408                             "relationship": [
409                                 {
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": [
414                                         {
415                                             "relationship-key": "customer.global-customer-id",
416                                             "relationship-value": "5GCustomer"
417                                         },
418                                         {
419                                             "relationship-key": "service-subscription.service-type",
420                                             "relationship-value": "5G"
421                                         },
422                                         {
423                                             "relationship-key": "service-instance.service-instance-id",
424                                             "relationship-value": "5G-666"
425                                         }
426                                     ],
427                                     "related-to-property": [
428                                         {
429                                             "property-key": "service-instance.service-instance-name",
430                                             "property-value": "eMBB_Slice_Communication_Service_5GCustomer"
431                                         }
432                                     ]
433                                 }
434                             ]
435                         }
436                     }
437                 """
438         return expect
439     }
440
441 }