aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src/test
diff options
context:
space:
mode:
authorhetengjiao <hetengjiao@chinamobile.com>2020-03-11 15:48:07 +0800
committerHE TENGJIAO <hetengjiao@chinamobile.com>2020-03-12 02:48:11 +0000
commitdb6462b5c00c82324d9ea2867823e01050d45822 (patch)
treeadd5fd5f5fd31ac9750b71be07613178405c86cb /bpmn/so-bpmn-infrastructure-common/src/test
parentbafa097c93d617ee19f7f8d14e35a66178bc92e4 (diff)
Add ut for ActivateSliceService and update ut for ActivateCommunicationService
Issue-ID: SO-2368 Change-Id: I0ec9db116fae10c63e0de9582491e80600a9b145 Signed-off-by: hetengjiao <hetengjiao@chinamobile.com>
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/test')
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateCommunicationServiceTest.groovy4
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceServiceTest.groovy118
2 files changed, 120 insertions, 2 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateCommunicationServiceTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateCommunicationServiceTest.groovy
index 7e02779f10..3eefd31e63 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateCommunicationServiceTest.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateCommunicationServiceTest.groovy
@@ -57,11 +57,11 @@ class ActivateCommunicationServiceTest extends MsoGroovyTest {
when(mockExecution.getVariable("bpmnRequest")).thenReturn(req)
when(mockExecution.getVariable("mso-request-id")).thenReturn("54321")
when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
-
+ when(mockExecution.getVariable("operationType")).thenReturn("activation")
ActivateCommunicationService service = new ActivateCommunicationService()
service.preProcessRequest(mockExecution)
- Mockito.verify(mockExecution, times(5)).setVariable(captor.capture(), captor.capture())
+ Mockito.verify(mockExecution, times(6)).setVariable(captor.capture(), captor.capture())
}
@Test
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceServiceTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceServiceTest.groovy
new file mode 100644
index 0000000000..f3c61dd628
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceServiceTest.groovy
@@ -0,0 +1,118 @@
+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 static org.junit.Assert.assertEquals
+import static org.junit.Assert.assertNotNull
+import static org.mockito.ArgumentMatchers.eq
+import static org.mockito.Mockito.times
+import static org.mockito.Mockito.when
+
+class ActivateSliceServiceTest extends MsoGroovyTest {
+ @Before
+ void init() throws IOException {
+ super.init("ActivateSliceService")
+ }
+
+ @Captor
+ static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
+
+ @Test
+ void testPreProcessRequest() {
+
+ String req = """
+ {
+ "globalSubscriberId": "5GCustomer",
+ "serviceType": "5G",
+ "operationId": "test123"
+ }
+ """
+ when(mockExecution.getVariable("bpmnRequest")).thenReturn(req)
+ when(mockExecution.getVariable("mso-request-id")).thenReturn("54321")
+ when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
+ when(mockExecution.getVariable("operationType")).thenReturn("activation")
+
+
+ ActivateSliceService service = new ActivateSliceService()
+ service.preProcessRequest(mockExecution)
+ Mockito.verify(mockExecution, times(7)).setVariable(captor.capture(), captor.capture())
+ }
+
+ @Test
+ void testPrepareInitOperationStatus() {
+
+ when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
+ when(mockExecution.getVariable("operationId")).thenReturn("54321")
+
+ when(mockExecution.getVariable("globalSubscriberId")).thenReturn("11111")
+
+ ActivateSliceService service = new ActivateSliceService()
+
+ service.prepareInitServiceOperationStatus(mockExecution)
+ Mockito.verify(mockExecution, times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
+ String res = captor.getValue()
+ assertNotNull(res)
+ }
+
+ @Test
+ void testSendSyncResponse() {
+ when(mockExecution.getVariable("operationId")).thenReturn("123456")
+ when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
+ ActivateSliceService service = new ActivateSliceService()
+ service.sendSyncResponse(mockExecution)
+ Mockito.verify(mockExecution, times(1)).setVariable(eq("sentSyncResponse"), captor.capture())
+ def updateVolumeGroupRequest = captor.getValue()
+ assertEquals(updateVolumeGroupRequest, true)
+ }
+
+ private static getExpectPayload = { String type, String result, String progress, String operationContent ->
+ String expect =
+ """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:ns="http://org.onap.so/requestsdb">
+ <soapenv:Header/>
+ <soapenv:Body>
+ <ns:${type} xmlns:ns="http://org.onap.so/requestsdb">
+ <serviceId>12345</serviceId>
+ <operationId>54321</operationId>
+ <operationType>activate</operationType>
+ <userId>11111</userId>
+ <result>${result}</result>
+ <operationContent>${operationContent}</operationContent>
+ <progress>${progress}</progress>
+ <reason></reason>
+ </ns:${type}>
+ </soapenv:Body>
+ </soapenv:Envelope>
+ """
+ return expect
+ }
+
+ @Test
+ void testPrepareCompleteStatus() {
+ when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
+ when(mockExecution.getVariable("operationId")).thenReturn("54321")
+ when(mockExecution.getVariable("operationType")).thenReturn("activate")
+ when(mockExecution.getVariable("operationContent"))
+ .thenReturn("slice service activate operation finished")
+
+ when(mockExecution.getVariable("globalSubscriberId")).thenReturn("11111")
+ when(mockExecution.getVariable("operationStatus"))
+ .thenReturn("deactivated")
+ ActivateSliceService service = new ActivateSliceService()
+
+ service.prepareCompletionRequest(mockExecution)
+ Mockito.verify(mockExecution, times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
+ String res = captor.getValue()
+
+ String expect = getExpectPayload("updateServiceOperationStatus", "finished", "100",
+ "slice service activate operation finished")
+
+ assertEquals(expect.replaceAll("\\s+", ""), res.replaceAll("\\s+", ""))
+ }
+}