3beae9aee041df6cb76e99c5ec26448c5e9cec7c
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  # Copyright (c) 2019, CMCC Technologies Co., Ltd.
6  #
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
10  #
11  #       http://www.apache.org/licenses/LICENSE-2.0
12  #
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=========================================================
19  */
20 package org.onap.so.bpmn.infrastructure.scripts
21
22 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
23 import org.junit.Before
24 import org.junit.Test
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.so.client.aai.AAIObjectType
31 import org.onap.so.client.aai.entities.AAIResultWrapper
32 import org.onap.so.client.aai.entities.uri.AAIResourceUri
33 import org.onap.so.client.aai.entities.uri.AAIUriFactory
34
35 import javax.ws.rs.NotFoundException
36
37 import static org.junit.Assert.assertEquals
38 import static org.junit.Assert.assertNotNull
39 import static org.mockito.ArgumentMatchers.eq
40 import static org.mockito.Mockito.*
41
42 public class DeleteCommunicationServiceTest extends MsoGroovyTest {
43
44     @Before
45     void init() throws IOException {
46         super.init("DeleteCommunicationServiceTest")
47     }
48
49     @Captor
50     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
51
52     @Test
53     void testPreProcessRequest(){
54         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
55         when(mockExecution.getVariable("bpmnRequest")).thenReturn("""
56         {
57             "globalSubscriberId ":"5GCustomer",
58             "serviceType ":"5G"
59         }""".replaceAll("\\\\s+", ""))
60         when(mockExecution.getVariable("mso-request-id")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82")
61
62         DeleteCommunicationService delCS = new DeleteCommunicationService()
63         delCS.preProcessRequest(mockExecution)
64         Mockito.verify(mockExecution,times(3)).setVariable(captor.capture() as String, captor.capture())
65         List<ExecutionEntity> values = captor.getAllValues()
66         assertNotNull(values)
67     }
68
69     @Test
70     void testPreInitUpdateOperationStatus(){
71         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
72         when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
73         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
74         when(mockExecution.getVariable("serviceInstanceName")).thenReturn("5G-test")
75         when(mockExecution.getVariable("result")).thenReturn("processing")
76         when(mockExecution.getVariable("progress")).thenReturn("0")
77         when(mockExecution.getVariable("operationContent")).thenReturn("delete communication service operation start")
78
79         DeleteCommunicationService delCS = new DeleteCommunicationService()
80         delCS.preInitUpdateOperationStatus(mockExecution)
81         Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
82         String updateOperationStatus= captor.getAllValues()
83         assertNotNull(updateOperationStatus)
84     }
85
86     @Test
87     void testQueryCommunicationSeriveFromAAI(){
88         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
89         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
90         when(mockExecution.getVariable("serviceType")).thenReturn("5G")
91
92         AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be")
93         DeleteCommunicationService obj = spy(DeleteCommunicationService.class)
94
95         AAIResultWrapper wrapper = new AAIResultWrapper(mockQueryCommunicationServiceReturn())
96         when(obj.getAAIClient()).thenReturn(client)
97         when(client.exists(resourceUri)).thenReturn(true)
98         when(client.get(resourceUri, NotFoundException.class)).thenReturn(wrapper)
99         obj.queryCommunicationSeriveFromAAI(mockExecution)
100         Mockito.verify(mockExecution,times(1)).setVariable(eq("e2eSliceServiceInstanceId"), captor.capture())
101         String e2eSliceServiceInstanceId = captor.getValue()
102         assertNotNull(e2eSliceServiceInstanceId)
103     }
104
105     @Test
106     void testPrepareCallCheckProcessStatus(){
107         DeleteCommunicationService dcs = new DeleteCommunicationService()
108         dcs.prepareCallCheckProcessStatus(mockExecution)
109         Mockito.verify(mockExecution,times(1)).setVariable(eq("endProgress"), captor.capture())
110         int endProgress = captor.getValue()
111         assertEquals(90,endProgress)
112     }
113
114     @Test
115     void testDelCSProfileFromAAI()
116     {
117         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
118         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
119         when(mockExecution.getVariable("serviceType")).thenReturn("5G")
120
121         AAIResultWrapper wrapper = new AAIResultWrapper(mockQueryCommunicationServiceProfile())
122         AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.COMMUNICATION_PROFILE_ALL, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be")
123         AAIResourceUri profileUri = AAIUriFactory.createResourceUri(AAIObjectType.COMMUNICATION_SERVICE_PROFILE, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be", "5G-111111")
124
125         DeleteCommunicationService obj = spy(DeleteCommunicationService.class)
126         when(obj.getAAIClient()).thenReturn(client)
127         when(client.exists(resourceUri)).thenReturn(true)
128         when(client.exists(profileUri)).thenReturn(true)
129         when(client.get(resourceUri, NotFoundException.class)).thenReturn(wrapper)
130         doNothing().when(client).delete(profileUri)
131         obj.delCSProfileFromAAI(mockExecution)
132         Mockito.verify(client,times(1)).delete(profileUri)
133     }
134
135     @Test
136     void testPrepareFailureStatus(){
137         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
138         when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
139         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
140         when(mockExecution.getVariable("serviceInstanceName")).thenReturn("5G-test")
141         when(mockExecution.getVariable("result")).thenReturn("finished")
142         when(mockExecution.getVariable("progress")).thenReturn("100")
143         when(mockExecution.getVariable("operationContent")).thenReturn("terminate service failure.")
144
145         DeleteCommunicationService dcs = new DeleteCommunicationService()
146         dcs.prepareFailureStatus(mockExecution)
147         Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
148         String updateOperationStatus= captor.getAllValues()
149         assertNotNull(updateOperationStatus)
150     }
151
152     @Test
153     void testDelCSFromAAI(){
154         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
155         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
156         when(mockExecution.getVariable("serviceType")).thenReturn("5G")
157
158         AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be")
159         DeleteCommunicationService obj = spy(DeleteCommunicationService.class)
160         when(obj.getAAIClient()).thenReturn(client)
161         doNothing().when(client).delete(serviceInstanceUri)
162
163         obj.delCSFromAAI(mockExecution)
164         Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
165         String updateOperationStatus= captor.getAllValues()
166         assertNotNull(updateOperationStatus)
167     }
168
169     @Test
170     void testPreFailedOperationStatus(){
171         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
172         when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
173         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
174         when(mockExecution.getVariable("serviceInstanceName")).thenReturn("5G-test")
175         when(mockExecution.getVariable("result")).thenReturn("error")
176         when(mockExecution.getVariable("progress")).thenReturn("100")
177         when(mockExecution.getVariable("operationContent")).thenReturn("terminate service failure")
178
179         DeleteCommunicationService deleteCommunicationService = new DeleteCommunicationService()
180         WorkflowException exception = new WorkflowException("11113",7000,"terminate service failure")
181         when(mockExecution.getVariable("WorkflowException")).thenReturn(exception)
182         deleteCommunicationService.preFailedOperationStatus(mockExecution)
183
184         Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
185         String updateOperationStatus= captor.getAllValues()
186         assertNotNull(updateOperationStatus)
187     }
188
189
190     private String mockQueryCommunicationServiceReturn()
191     {
192         String expect =
193                 """{
194                         "service-instance-id": "5G-666",
195                         "service-instance-name": "eMBB_Slice_Communication_Service_5GCustomer",
196                         "service-type": "eMBB",
197                         "service-role": "communication-service",
198                         "environment-context": "01-010101",
199                         "workload-context": "12",
200                         "created-at": "2019-12-11 19:56:00",
201                         "description": "",
202                         "model-invariant-id": "e75698d9-925a-4cdd-a6c0-edacbe6a0b51",
203                         "model-version-id": "8ee5926d-720b-4bb2-86f9-d20e921c143b",
204                         "service-instance-location-id": "300-01|300-02",
205                         "resource-version": "1582623470778",
206                         "orchestration-status": "created",
207                         "relationship-list": {
208                             "relationship": [
209                                 {
210                                     "related-to": "service-instance",
211                                     "relationship-label": "org.onap.relationships.inventory.ComposedOf",
212                                     "related-link": "/aai/v16/business/customers/customer/5GCustomer/service-subscriptions/service-subscription/5G/service-instances/service-instance/5G-777",
213                                     "relationship-data": [
214                                         {
215                                             "relationship-key": "customer.global-customer-id",
216                                             "relationship-value": "5GCustomer"
217                                         },
218                                         {
219                                             "relationship-key": "service-subscription.service-type",
220                                             "relationship-value": "5G"
221                                         },
222                                         {
223                                             "relationship-key": "service-instance.service-instance-id",
224                                             "relationship-value": "5G-777"
225                                         }
226                                     ],
227                                     "related-to-property": [
228                                         {
229                                             "property-key": "service-instance.service-instance-name",
230                                             "property-value": "eMBB_e2e_Slice_Service_5GCustomer"
231                                         }
232                                     ]
233                                 }
234                             ]
235                         }
236                     }"""
237         return expect
238     }
239
240     private String mockQueryCommunicationServiceProfile()
241     {
242         String expect =
243         """{
244             "communication-service-profile": [
245                 {
246                     "profile-id": "5G-111111",
247                     "max-number-of-UEs": 50,
248                     "coverage-area-list": "longgang,futian",
249                     "latency": 20,
250                     "exp-data-rate-UL": 300,
251                     "exp-data-rate-DL": 500,
252                     "ue-mobility-level": "stationary",
253                     "resource-sharing-level": "Non-Shared",
254                     "resource-version": "1577454950460"
255                 }
256         ]
257         }"""
258         return expect
259     }
260
261
262
263
264 }