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=========================================================
20 package org.onap.so.bpmn.infrastructure.scripts
22 import static org.junit.Assert.assertNotNull
23 import static org.junit.Assert.assertTrue
24 import static org.mockito.ArgumentMatchers.eq
25 import static org.mockito.Mockito.spy
26 import static org.mockito.Mockito.times
27 import static org.mockito.Mockito.verify
28 import static org.mockito.Mockito.when
29 import javax.ws.rs.NotFoundException
30 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
31 import org.junit.Before
33 import org.mockito.ArgumentCaptor
34 import org.mockito.Captor
35 import org.mockito.Mockito
36 import org.onap.aai.domain.yang.ServiceInstance
37 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
38 import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri
39 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
40 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
41 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
42 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
43 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
45 class DoDeleteSliceServiceTest extends MsoGroovyTest {
47 void init() throws IOException {
48 super.init("DoDeleteSliceServiceTest")
52 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
55 void testPreProcessRequest(){
56 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
57 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
58 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("e2a747a0-2ca6-476d-ac28-de999cf3fbfe")
60 DoDeleteSliceService doDeleteSliceService = new DoDeleteSliceService()
61 doDeleteSliceService.preProcessRequest(mockExecution)
63 Mockito.verify(mockExecution,times(1)).setVariable(captor.capture() as String, captor.capture())
64 List<ExecutionEntity> values = captor.getAllValues()
69 void testQueryE2ESliceSeriveFromAAI(){
70 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
71 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
72 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
74 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("5GCustomer").serviceSubscription("5G").serviceInstance("5ad89cf9-0569-4a93-9306-d8324321e2be"))
75 DoDeleteSliceService obj = spy(DoDeleteSliceService.class)
77 AAIResultWrapper wrapper = new AAIResultWrapper(mockQuerySliceServiceReturn())
78 when(obj.getAAIClient()).thenReturn(client)
79 when(client.exists(resourceUri)).thenReturn(true)
80 when(client.get(resourceUri, NotFoundException.class)).thenReturn(wrapper)
81 obj.queryE2ESliceSeriveFromAAI(mockExecution)
82 Mockito.verify(mockExecution,times(1)).setVariable(eq("snssai"), captor.capture())
83 String snssai = captor.getValue()
88 void testGetAllottedResFromAAI(){
89 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
90 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
91 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
93 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(
94 AAIFluentTypeBuilder.business().customer("5GCustomer").serviceSubscription("5G").serviceInstance("5ad89cf9-0569-4a93-9306-d8324321e2be").allottedResources())
95 DoDeleteSliceService obj = spy(DoDeleteSliceService.class)
97 AAIResultWrapper wrapper = new AAIResultWrapper(mockQueryAllottedResource())
98 when(obj.getAAIClient()).thenReturn(client)
99 when(client.exists(resourceUri)).thenReturn(true)
100 when(client.get(resourceUri, NotFoundException.class)).thenReturn(wrapper)
101 obj.getAllottedResFromAAI(mockExecution)
102 Mockito.verify(mockExecution,times(1)).setVariable(eq("nsiId"), captor.capture())
103 String nsiId = captor.getValue()
108 void testGetNSIFromAAI(){
109 when(mockExecution.getVariable("nsiId")).thenReturn("5G-888")
110 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
111 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
113 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("5GCustomer").serviceSubscription("5G").serviceInstance("5G-888"))
114 DoDeleteSliceService obj = spy(DoDeleteSliceService.class)
116 AAIResultWrapper wrapper = new AAIResultWrapper(mockNSIReturn())
117 when(obj.getAAIClient()).thenReturn(client)
118 when(client.exists(resourceUri)).thenReturn(true)
119 when(client.get(resourceUri, NotFoundException.class)).thenReturn(wrapper)
120 obj.getNSIFromAAI(mockExecution)
121 Mockito.verify(mockExecution,times(1)).setVariable(eq("nssiIdList"), captor.capture())
122 List<String> nssiIdList = captor.getValue()
123 assertNotNull(nssiIdList)
127 void testGetNSSIListFromAAI(){
128 List<String> nssiIdList = []
129 nssiIdList.add("5G-999")
131 when(mockExecution.getVariable("nssiIdList")).thenReturn(nssiIdList)
132 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
133 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
135 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("5GCustomer").serviceSubscription("5G").serviceInstance("5G-999"))
136 DoDeleteSliceService obj = spy(DoDeleteSliceService.class)
138 AAIResultWrapper wrapper = new AAIResultWrapper(mockNSSIReturn())
139 when(obj.getAAIClient()).thenReturn(client)
140 when(client.exists(resourceUri)).thenReturn(true)
141 when(client.get(resourceUri, NotFoundException.class)).thenReturn(wrapper)
142 obj.getNSSIListFromAAI(mockExecution)
143 Mockito.verify(mockExecution,times(1)).setVariable(eq("nssiInstanceList"), captor.capture())
144 List<ServiceInstance> nssiInstanceList = captor.getValue()
145 assertNotNull(nssiInstanceList)
149 void testGetCurrentNSSI(){
150 ServiceInstance nssi = new ServiceInstance()
151 nssi.setServiceInstanceId("5G-999")
152 nssi.setModelInvariantId("21d57d4b-52ad-4d3c-a798-248b5bb9124a")
153 nssi.setModelVersionId("bfba363e-e39c-4bd9-a9d5-1371c28f4d22")
154 List<ServiceInstance> nssiInstanceList = []
155 nssiInstanceList.add(nssi)
156 when(mockExecution.getVariable("currentNSSIIndex")).thenReturn(0)
157 when(mockExecution.getVariable("nssiInstanceList")).thenReturn(nssiInstanceList)
158 when(mockExecution.getVariable("snssai")).thenReturn("01-010101")
159 when(mockExecution.getVariable("nsiId")).thenReturn("5G-888")
160 when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
161 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5G-777")
162 when(mockExecution.getVariable("msoRequestId")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82")
163 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
164 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
165 when(mockExecution.getVariable("proportion")).thenReturn("90")
167 DoDeleteSliceService ddss = new DoDeleteSliceService()
168 ddss.getCurrentNSSI(mockExecution)
169 verify(mockExecution,times(1)).setVariable(eq("currentNSSI"), captor.capture())
170 Map currentNSSI = captor.getValue()
171 assertTrue(currentNSSI.size()>0)
175 void testQuerySliceProfileFromAAI(){
176 def currentNSSI = [:]
177 currentNSSI.put("nssiServiceInstanceId","5G-999")
178 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
179 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
180 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
182 AAIResultWrapper wrapper = new AAIResultWrapper(mockSliceProfile())
183 AAIPluralResourceUri profileUri = AAIUriFactory.createResourceUri(
184 AAIFluentTypeBuilder.business().customer("5GCustomer").serviceSubscription("5G").serviceInstance("5G-999").sliceProfiles())
186 DoDeleteSliceService obj = spy(DoDeleteSliceService.class)
187 when(obj.getAAIClient()).thenReturn(client)
188 when(client.exists(profileUri)).thenReturn(true)
189 when(client.get(profileUri, NotFoundException.class)).thenReturn(wrapper)
190 obj.querySliceProfileFromAAI(mockExecution)
191 verify(mockExecution,times(1)).setVariable(eq("currentNSSI"), captor.capture())
192 Map value = captor.getValue()
193 assertNotNull(currentNSSI.get('profileId'))
197 void parseNextNSSI(){
198 ServiceInstance nssi = new ServiceInstance()
199 nssi.setServiceInstanceId("5G-999")
200 nssi.setModelInvariantId("21d57d4b-52ad-4d3c-a798-248b5bb9124b")
201 nssi.setModelVersionId("bfba363e-e39c-4bd9-a9d5-1371c28f4d22")
202 List<ServiceInstance> nssiInstanceList = []
203 nssiInstanceList.add(nssi)
204 when(mockExecution.getVariable("currentNSSIIndex")).thenReturn(0)
205 when(mockExecution.getVariable("nssiInstanceList")).thenReturn(nssiInstanceList)
207 DoDeleteSliceService ddss = new DoDeleteSliceService()
208 ddss.parseNextNSSI(mockExecution)
209 verify(mockExecution,times(1)).setVariable(eq("isAllNSSIFinished"), captor.capture())
210 boolean isAllNSSIFinished = captor.getValue()
211 assertTrue(isAllNSSIFinished)
214 private String mockSliceProfile(){
219 "profile-id": "ddf57704-fe8d-417b-882d-2f2a12ddb225",
221 "max-number-of-UEs": 0,
222 "coverage-area-TA-list": "[{\\"province\\":\\"??\\",\\"city\\":\\"???\\",\\"county\\":\\"???\\",\\"street\\":\\"?????\\"}]",
223 "ue-mobility-level": "stationary",
224 "resource-sharing-level": "0",
225 "exp-data-rate-UL": 100,
226 "exp-data-rate-DL": 100,
227 "activity-factor": 0,
233 "traffic-density": 0,
236 "resource-version": "1580800791373"
244 private String mockNSSIReturn(){
248 "service-instance-id": "5G-999",
249 "service-instance-name": "eMBB_Slice_NSSI_5GCustomer",
250 "service-type": "eMBB",
251 "service-role": "nssi",
252 "environment-context": "cn",
253 "model-invariant-id": "21d57d4b-52ad-4d3c-a798-248b5bb9124a",
254 "model-version-id": "bfba363e-e39c-4bd9-a9d5-1371c28f4d22",
255 "service-instance-location-id": "300-01|300-02",
256 "resource-version": "1578449638032",
257 "orchestration-status": "activated",
258 "relationship-list": {
261 "related-to": "service-instance",
262 "relationship-label": "org.onap.relationships.inventory.ComposedOf",
263 "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/5G-888",
264 "relationship-data": [
266 "relationship-key": "customer.global-customer-id",
267 "relationship-value": "5GCustomer"
270 "relationship-key": "service-subscription.service-type",
271 "relationship-value": "5G"
274 "relationship-key": "service-instance.service-instance-id",
275 "relationship-value": "5G-888"
278 "related-to-property": [
280 "property-key": "service-instance.service-instance-name",
281 "property-value": "eMBB_e2e_Slice_Service_5GCustomer"
292 private String mockNSIReturn(){
296 "service-instance-id": "5G-888",
297 "service-instance-name": "eMBB_e2e_Slice_Service_5GCustomer",
298 "service-type": "embb",
299 "service-role": "nsi",
300 "model-invariant-id": "0e9bcb9a-c832-433b-a0c1-74866768f608",
301 "model-version-id": "2c5fd79d-0f84-4057-9222-952cb6f27036",
302 "service-instance-location-id": "300-01|300-02",
303 "resource-version": "1579691104911",
304 "orchestration-status": "activated",
305 "relationship-list": {
308 "related-to": "service-instance",
309 "relationship-label": "org.onap.relationships.inventory.ComposedOf",
310 "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/5G-999",
311 "relationship-data": [
313 "relationship-key": "customer.global-customer-id",
314 "relationship-value": "5GCustomer"
317 "relationship-key": "service-subscription.service-type",
318 "relationship-value": "5G"
321 "relationship-key": "service-instance.service-instance-id",
322 "relationship-value": "5G-999"
325 "related-to-property": [
327 "property-key": "service-instance.service-instance-name",
328 "property-value": "eMBB_Slice_NSSI_5GCustomer"
333 "related-to": "allotted-resource",
334 "relationship-label": "org.onap.relationships.inventory.Uses",
335 "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",
336 "relationship-data": [
338 "relationship-key": "customer.global-customer-id",
339 "relationship-value": "5GCustomer"
342 "relationship-key": "service-subscription.service-type",
343 "relationship-value": "5G"
346 "relationship-key": "service-instance.service-instance-id",
347 "relationship-value": "5G-777"
350 "relationship-key": "allotted-resource.id",
351 "relationship-value": "5G-1234"
354 "related-to-property": [
356 "property-key": "allotted-resource.description"
359 "property-key": "allotted-resource.allotted-resource-name"
370 private String mockQueryAllottedResource(){
373 "allotted-resource": [
376 "resource-version": "1577454983471",
377 "relationship-list": {
380 "related-to": "service-instance",
381 "relationship-label": "org.onap.relationships.inventory.Uses",
382 "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/5G-888",
383 "relationship-data": [
385 "relationship-key": "customer.global-customer-id",
386 "relationship-value": "5GCustomer"
389 "relationship-key": "service-subscription.service-type",
390 "relationship-value": "5G"
393 "relationship-key": "service-instance.service-instance-id",
394 "relationship-value": "5G-888"
397 "related-to-property": [
399 "property-key": "service-instance.service-instance-name",
400 "property-value": "eMBB_e2e_Slice_Service_5GCustomer"
413 String mockQuerySliceServiceReturn(){
416 "service-instance-id": "5G-777",
417 "service-instance-name": "eMBB_e2e_Slice_Service_5GCustomer",
418 "service-type": "embb",
419 "service-role": "e2eslice-service",
420 "environment-context": "01-010101",
421 "model-invariant-id": "e65d737a-41e0-4ad1-958f-56defdf2e907",
422 "model-version-id": "f2f5967e-72d3-4c5c-b880-e214e71dba4e",
423 "service-instance-location-id": "300-01|300-02",
424 "resource-version": "1578449638436",
425 "orchestration-status": "activated",
426 "relationship-list": {
429 "related-to": "service-instance",
430 "relationship-label": "org.onap.relationships.inventory.ComposedOf",
431 "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/5G-666",
432 "relationship-data": [
434 "relationship-key": "customer.global-customer-id",
435 "relationship-value": "5GCustomer"
438 "relationship-key": "service-subscription.service-type",
439 "relationship-value": "5G"
442 "relationship-key": "service-instance.service-instance-id",
443 "relationship-value": "5G-666"
446 "related-to-property": [
448 "property-key": "service-instance.service-instance-name",
449 "property-value": "eMBB_Slice_Communication_Service_5GCustomer"