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.mockito.ArgumentMatchers.eq
24 import static org.mockito.Mockito.doNothing
25 import static org.mockito.Mockito.spy
26 import static org.mockito.Mockito.times
27 import static org.mockito.Mockito.when
28 import javax.ws.rs.NotFoundException
29 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
30 import org.junit.Before
32 import org.mockito.ArgumentCaptor
33 import org.mockito.Captor
34 import org.mockito.Mockito
35 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
36 import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri
37 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
38 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
39 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
40 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
41 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
42 import org.onap.so.bpmn.core.WorkflowException
44 class DeleteSliceServiceTest extends MsoGroovyTest {
46 void init() throws IOException {
47 super.init("DeleteSliceServiceTest")
51 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
54 void testPreProcessRequest(){
55 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("eb0863e9-a69b-4b17-8a56-f05ad110bef7")
56 when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
57 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
58 when(mockExecution.getVariable("serviceInstanceName")).thenReturn("5G-test")
59 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
60 when(mockExecution.getVariable("result")).thenReturn("processing")
61 when(mockExecution.getVariable("progress")).thenReturn("0")
62 when(mockExecution.getVariable("operationContent")).thenReturn("Delete Slice service operation start")
63 when(mockExecution.getVariable("bpmnRequest")).thenReturn("""
65 "globalSubscriberId ":"5GCustomer",
67 }""".replaceAll("\\\\s+", ""))
68 when(mockExecution.getVariable("mso-request-id")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82")
70 DeleteSliceService delSS = new DeleteSliceService()
71 delSS.preProcessRequest(mockExecution)
72 Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
73 String updateOperationStatus = captor.getValue()
74 assertNotNull(updateOperationStatus)
78 void testDeleteSliceServiceInstance(){
79 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
80 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
81 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
83 when(mockExecution.getVariable("result")).thenReturn("finished")
84 when(mockExecution.getVariable("progress")).thenReturn("100")
85 when(mockExecution.getVariable("operationContent")).thenReturn("NSMF completes slicing service termination.")
87 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("5GCustomer").serviceSubscription("5G").serviceInstance("5ad89cf9-0569-4a93-9306-d8324321e2be"))
88 DeleteSliceService obj = spy(DeleteSliceService.class)
89 when(obj.getAAIClient()).thenReturn(client)
90 doNothing().when(client).delete(serviceInstanceUri)
92 obj.deleteSliceServiceInstance(mockExecution)
93 Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
94 String updateOperationStatus= captor.getValue()
95 assertNotNull(updateOperationStatus)
99 void testDelServiceProfileFromAAI(){
100 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
101 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
102 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
104 AAIResultWrapper wrapper = new AAIResultWrapper(mockQuerySliceServiceProfile())
105 AAIPluralResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("5GCustomer").serviceSubscription("5G").serviceInstance("5ad89cf9-0569-4a93-9306-d8324321e2be").serviceProfiles())
106 AAIResourceUri profileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("5GCustomer").serviceSubscription("5G").serviceInstance("5ad89cf9-0569-4a93-9306-d8324321e2be").serviceProfile("5G-2222222"))
108 DeleteSliceService obj = spy(DeleteSliceService.class)
109 when(obj.getAAIClient()).thenReturn(client)
110 when(client.exists(resourceUri)).thenReturn(true)
111 when(client.exists(profileUri)).thenReturn(true)
112 when(client.get(resourceUri, NotFoundException.class)).thenReturn(wrapper)
113 doNothing().when(client).delete(profileUri)
114 obj.delServiceProfileFromAAI(mockExecution)
115 Mockito.verify(client,times(1)).delete(profileUri)
119 void testPrepareEndOperationStatus(){
120 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
121 when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
122 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
123 when(mockExecution.getVariable("serviceInstanceName")).thenReturn("5G-test")
124 when(mockExecution.getVariable("result")).thenReturn("error")
125 when(mockExecution.getVariable("progress")).thenReturn("100")
126 when(mockExecution.getVariable("operationContent")).thenReturn("terminate service failure")
128 DeleteSliceService deleteSliceService = new DeleteSliceService()
129 WorkflowException exception = new WorkflowException("11113",7000,"terminate service failure")
130 when(mockExecution.getVariable("WorkflowException")).thenReturn(exception)
131 deleteSliceService.prepareEndOperationStatus(mockExecution)
133 Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
134 String updateOperationStatus= captor.getValue()
135 assertNotNull(updateOperationStatus)
139 private String mockQuerySliceServiceProfile(){
144 "profile-id": "5G-2222222",
146 "max-number-of-UEs": 500,
147 "coverage-area-TA-list": "longgang,futian",
148 "ue-mobility-level": "stationary",
149 "resource-sharing-level": "Non-Shared",
150 "exp-data-rate-UL": 10,
151 "exp-data-rate-DL": 30,
152 "area-traffic-cap-UL": 100,
153 "area-traffic-cap-DL": 100,
154 "activity-factor": 80,
157 "cs-availability": 95.5,
160 "traffic-density": 100,
162 "resource-version": "1577454958647"