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 org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
23 import org.junit.Before
25 import org.mockito.ArgumentCaptor
26 import org.mockito.Captor
27 import org.mockito.Mockito
28 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
29 import org.onap.so.bpmn.core.WorkflowException
30 import org.onap.aaiclient.client.aai.AAIObjectType
31 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
32 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
33 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
35 import javax.ws.rs.NotFoundException
37 import static org.junit.Assert.assertNotNull
38 import static org.mockito.ArgumentMatchers.eq
39 import static org.mockito.Mockito.doNothing
40 import static org.mockito.Mockito.spy
41 import static org.mockito.Mockito.times
42 import static org.mockito.Mockito.when
43 import static org.mockito.Mockito.when
44 import static org.mockito.Mockito.when
46 class DeleteSliceServiceTest extends MsoGroovyTest {
48 void init() throws IOException {
49 super.init("DeleteSliceServiceTest")
53 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
56 void testPreProcessRequest(){
57 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("eb0863e9-a69b-4b17-8a56-f05ad110bef7")
58 when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
59 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
60 when(mockExecution.getVariable("serviceInstanceName")).thenReturn("5G-test")
61 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
62 when(mockExecution.getVariable("result")).thenReturn("processing")
63 when(mockExecution.getVariable("progress")).thenReturn("0")
64 when(mockExecution.getVariable("operationContent")).thenReturn("Delete Slice service operation start")
65 when(mockExecution.getVariable("bpmnRequest")).thenReturn("""
67 "globalSubscriberId ":"5GCustomer",
69 }""".replaceAll("\\\\s+", ""))
70 when(mockExecution.getVariable("mso-request-id")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82")
72 DeleteSliceService delSS = new DeleteSliceService()
73 delSS.preProcessRequest(mockExecution)
74 Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
75 String updateOperationStatus = captor.getValue()
76 assertNotNull(updateOperationStatus)
80 void testDeleteSliceServiceInstance(){
81 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
82 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
83 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
85 when(mockExecution.getVariable("result")).thenReturn("finished")
86 when(mockExecution.getVariable("progress")).thenReturn("100")
87 when(mockExecution.getVariable("operationContent")).thenReturn("NSMF completes slicing service termination.")
89 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be")
90 DeleteSliceService obj = spy(DeleteSliceService.class)
91 when(obj.getAAIClient()).thenReturn(client)
92 doNothing().when(client).delete(serviceInstanceUri)
94 obj.deleteSliceServiceInstance(mockExecution)
95 Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
96 String updateOperationStatus= captor.getValue()
97 assertNotNull(updateOperationStatus)
101 void testDelServiceProfileFromAAI(){
102 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
103 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
104 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
106 AAIResultWrapper wrapper = new AAIResultWrapper(mockQuerySliceServiceProfile())
107 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_PROFILE_ALL, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be")
108 AAIResourceUri profileUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_PROFILE, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be", "5G-2222222")
110 DeleteSliceService obj = spy(DeleteSliceService.class)
111 when(obj.getAAIClient()).thenReturn(client)
112 when(client.exists(resourceUri)).thenReturn(true)
113 when(client.exists(profileUri)).thenReturn(true)
114 when(client.get(resourceUri, NotFoundException.class)).thenReturn(wrapper)
115 doNothing().when(client).delete(profileUri)
116 obj.delServiceProfileFromAAI(mockExecution)
117 Mockito.verify(client,times(1)).delete(profileUri)
121 void testPrepareEndOperationStatus(){
122 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
123 when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
124 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
125 when(mockExecution.getVariable("serviceInstanceName")).thenReturn("5G-test")
126 when(mockExecution.getVariable("result")).thenReturn("error")
127 when(mockExecution.getVariable("progress")).thenReturn("100")
128 when(mockExecution.getVariable("operationContent")).thenReturn("terminate service failure")
130 DeleteSliceService deleteSliceService = new DeleteSliceService()
131 WorkflowException exception = new WorkflowException("11113",7000,"terminate service failure")
132 when(mockExecution.getVariable("WorkflowException")).thenReturn(exception)
133 deleteSliceService.prepareEndOperationStatus(mockExecution)
135 Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
136 String updateOperationStatus= captor.getValue()
137 assertNotNull(updateOperationStatus)
141 private String mockQuerySliceServiceProfile(){
146 "profile-id": "5G-2222222",
148 "max-number-of-UEs": 500,
149 "coverage-area-TA-list": "longgang,futian",
150 "ue-mobility-level": "stationary",
151 "resource-sharing-level": "Non-Shared",
152 "exp-data-rate-UL": 10,
153 "exp-data-rate-DL": 30,
154 "area-traffic-cap-UL": 100,
155 "area-traffic-cap-DL": 100,
156 "activity-factor": 80,
159 "cs-availability": 95.5,
162 "traffic-density": 100,
164 "resource-version": "1577454958647"