From db6462b5c00c82324d9ea2867823e01050d45822 Mon Sep 17 00:00:00 2001 From: hetengjiao Date: Wed, 11 Mar 2020 15:48:07 +0800 Subject: Add ut for ActivateSliceService and update ut for ActivateCommunicationService Issue-ID: SO-2368 Change-Id: I0ec9db116fae10c63e0de9582491e80600a9b145 Signed-off-by: hetengjiao --- .../ActivateCommunicationServiceTest.groovy | 4 +- .../scripts/ActivateSliceServiceTest.groovy | 118 +++++++++++++++++++++ 2 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceServiceTest.groovy 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 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 = + """ + + + + 12345 + 54321 + activate + 11111 + ${result} + ${operationContent} + ${progress} + + + + + """ + 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+", "")) + } +} -- cgit 1.2.3-korg