aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src/test/groovy
diff options
context:
space:
mode:
authorzm330 <zhangminyj@chinamobile.com>2020-03-06 19:41:10 +0800
committerzm330 <zhangminyj@chinamobile.com>2020-03-07 18:54:38 +0800
commite28e37139a19f942ef683e891389c055fffdc224 (patch)
tree2fa7e12aeb9c8fbace46444a2268968f6f46c333 /bpmn/so-bpmn-infrastructure-common/src/test/groovy
parent4d1e251ebcde26583cc85abef7b6909e9808771c (diff)
Add test for deleting slice service
Issue-ID: SO-2368 Signed-off-by: zm330 <zhangminyj@chinamobile.com> Change-Id: Icd892109aeea94d544c4d0efdc108ffb4d7991cb
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/test/groovy')
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteCommunicationServiceTest.groovy10
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteSliceServiceTest.groovy171
2 files changed, 176 insertions, 5 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteCommunicationServiceTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteCommunicationServiceTest.groovy
index 3beae9aee0..29a976a72c 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteCommunicationServiceTest.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteCommunicationServiceTest.groovy
@@ -39,7 +39,7 @@ import static org.junit.Assert.assertNotNull
import static org.mockito.ArgumentMatchers.eq
import static org.mockito.Mockito.*
-public class DeleteCommunicationServiceTest extends MsoGroovyTest {
+class DeleteCommunicationServiceTest extends MsoGroovyTest {
@Before
void init() throws IOException {
@@ -79,7 +79,7 @@ public class DeleteCommunicationServiceTest extends MsoGroovyTest {
DeleteCommunicationService delCS = new DeleteCommunicationService()
delCS.preInitUpdateOperationStatus(mockExecution)
Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
- String updateOperationStatus= captor.getAllValues()
+ String updateOperationStatus= captor.getValue()
assertNotNull(updateOperationStatus)
}
@@ -145,7 +145,7 @@ public class DeleteCommunicationServiceTest extends MsoGroovyTest {
DeleteCommunicationService dcs = new DeleteCommunicationService()
dcs.prepareFailureStatus(mockExecution)
Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
- String updateOperationStatus= captor.getAllValues()
+ String updateOperationStatus= captor.getValue()
assertNotNull(updateOperationStatus)
}
@@ -162,7 +162,7 @@ public class DeleteCommunicationServiceTest extends MsoGroovyTest {
obj.delCSFromAAI(mockExecution)
Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
- String updateOperationStatus= captor.getAllValues()
+ String updateOperationStatus= captor.getValue()
assertNotNull(updateOperationStatus)
}
@@ -182,7 +182,7 @@ public class DeleteCommunicationServiceTest extends MsoGroovyTest {
deleteCommunicationService.preFailedOperationStatus(mockExecution)
Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
- String updateOperationStatus= captor.getAllValues()
+ String updateOperationStatus= captor.getValue()
assertNotNull(updateOperationStatus)
}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteSliceServiceTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteSliceServiceTest.groovy
new file mode 100644
index 0000000000..fb50fcc43b
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteSliceServiceTest.groovy
@@ -0,0 +1,171 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2019, CMCC Technologies Co., Ltd.
+ #
+ # Licensed under the Apache License, Version 2.0 (the "License")
+ # you may not use this file except in compliance with the License.
+ # You may obtain a copy of the License at
+ #
+ # http://www.apache.org/licenses/LICENSE-2.0
+ #
+ # Unless required by applicable law or agreed to in writing, software
+ # distributed under the License is distributed on an "AS IS" BASIS,
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ # See the License for the specific language governing permissions and
+ # limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.bpmn.infrastructure.scripts
+
+import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
+import org.junit.Before
+import org.junit.Test
+import org.mockito.ArgumentCaptor
+import org.mockito.Captor
+import org.mockito.Mockito
+import org.onap.so.bpmn.common.scripts.MsoGroovyTest
+import org.onap.so.bpmn.core.WorkflowException
+import org.onap.so.client.aai.AAIObjectType
+import org.onap.so.client.aai.entities.AAIResultWrapper
+import org.onap.so.client.aai.entities.uri.AAIResourceUri
+import org.onap.so.client.aai.entities.uri.AAIUriFactory
+
+import javax.ws.rs.NotFoundException
+
+import static org.junit.Assert.assertNotNull
+import static org.mockito.ArgumentMatchers.eq
+import static org.mockito.Mockito.doNothing
+import static org.mockito.Mockito.spy
+import static org.mockito.Mockito.times
+import static org.mockito.Mockito.when
+import static org.mockito.Mockito.when
+import static org.mockito.Mockito.when
+
+class DeleteSliceServiceTest extends MsoGroovyTest {
+ @Before
+ void init() throws IOException {
+ super.init("DeleteSliceServiceTest")
+ }
+
+ @Captor
+ static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
+
+ @Test
+ void testPreProcessRequest(){
+ when(mockExecution.getVariable("serviceInstanceId")).thenReturn("eb0863e9-a69b-4b17-8a56-f05ad110bef7")
+ when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
+ when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
+ when(mockExecution.getVariable("serviceInstanceName")).thenReturn("5G-test")
+ when(mockExecution.getVariable("serviceType")).thenReturn("5G")
+ when(mockExecution.getVariable("result")).thenReturn("processing")
+ when(mockExecution.getVariable("progress")).thenReturn("0")
+ when(mockExecution.getVariable("operationContent")).thenReturn("Delete Slice service operation start")
+ when(mockExecution.getVariable("bpmnRequest")).thenReturn("""
+ {
+ "globalSubscriberId ":"5GCustomer",
+ "serviceType ":"5G"
+ }""".replaceAll("\\\\s+", ""))
+ when(mockExecution.getVariable("mso-request-id")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82")
+
+ DeleteSliceService delSS = new DeleteSliceService()
+ delSS.preProcessRequest(mockExecution)
+ Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
+ String updateOperationStatus = captor.getValue()
+ assertNotNull(updateOperationStatus)
+ }
+
+ @Test
+ void testDeleteSliceServiceInstance(){
+ when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
+ when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
+ when(mockExecution.getVariable("serviceType")).thenReturn("5G")
+
+ when(mockExecution.getVariable("result")).thenReturn("finished")
+ when(mockExecution.getVariable("progress")).thenReturn("100")
+ when(mockExecution.getVariable("operationContent")).thenReturn("NSMF completes slicing service termination.")
+
+ AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be")
+ DeleteSliceService obj = spy(DeleteSliceService.class)
+ when(obj.getAAIClient()).thenReturn(client)
+ doNothing().when(client).delete(serviceInstanceUri)
+
+ obj.deleteSliceServiceInstance(mockExecution)
+ Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
+ String updateOperationStatus= captor.getValue()
+ assertNotNull(updateOperationStatus)
+ }
+
+ @Test
+ void testDelServiceProfileFromAAI(){
+ when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
+ when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
+ when(mockExecution.getVariable("serviceType")).thenReturn("5G")
+
+ AAIResultWrapper wrapper = new AAIResultWrapper(mockQuerySliceServiceProfile())
+ AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_PROFILE_ALL, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be")
+ AAIResourceUri profileUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_PROFILE, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be", "5G-2222222")
+
+ DeleteSliceService obj = spy(DeleteSliceService.class)
+ when(obj.getAAIClient()).thenReturn(client)
+ when(client.exists(resourceUri)).thenReturn(true)
+ when(client.exists(profileUri)).thenReturn(true)
+ when(client.get(resourceUri, NotFoundException.class)).thenReturn(wrapper)
+ doNothing().when(client).delete(profileUri)
+ obj.delServiceProfileFromAAI(mockExecution)
+ Mockito.verify(client,times(1)).delete(profileUri)
+ }
+
+ @Test
+ void testPrepareEndOperationStatus(){
+ when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
+ when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
+ when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
+ when(mockExecution.getVariable("serviceInstanceName")).thenReturn("5G-test")
+ when(mockExecution.getVariable("result")).thenReturn("error")
+ when(mockExecution.getVariable("progress")).thenReturn("100")
+ when(mockExecution.getVariable("operationContent")).thenReturn("terminate service failure")
+
+ DeleteSliceService deleteSliceService = new DeleteSliceService()
+ WorkflowException exception = new WorkflowException("11113",7000,"terminate service failure")
+ when(mockExecution.getVariable("WorkflowException")).thenReturn(exception)
+ deleteSliceService.prepareEndOperationStatus(mockExecution)
+
+ Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
+ String updateOperationStatus= captor.getValue()
+ assertNotNull(updateOperationStatus)
+
+ }
+
+ private String mockQuerySliceServiceProfile(){
+ String expect =
+ """{
+ "service-profile": [
+ {
+ "profile-id": "5G-2222222",
+ "latency": 50,
+ "max-number-of-UEs": 500,
+ "coverage-area-TA-list": "longgang,futian",
+ "ue-mobility-level": "stationary",
+ "resource-sharing-level": "Non-Shared",
+ "exp-data-rate-UL": 10,
+ "exp-data-rate-DL": 30,
+ "area-traffic-cap-UL": 100,
+ "area-traffic-cap-DL": 100,
+ "activity-factor": 80,
+ "jitter": 10,
+ "survival-time": 30,
+ "cs-availability": 95.5,
+ "reliability": 99.9,
+ "exp-data-rate": 80,
+ "traffic-density": 100,
+ "conn-density": 80,
+ "resource-version": "1577454958647"
+ }
+ ]
+ }"""
+ return expect
+ }
+
+}