aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteSliceService.groovy58
-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
3 files changed, 203 insertions, 36 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteSliceService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteSliceService.groovy
index f0d43cf8d7..d8160a97bc 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteSliceService.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteSliceService.groovy
@@ -45,19 +45,19 @@ import static org.apache.commons.lang3.StringUtils.isBlank
class DeleteSliceService extends AbstractServiceTaskProcessor {
- String Prefix="DELSS_"
+ private final String PREFIX ="DeleteSliceService"
ExceptionUtil exceptionUtil = new ExceptionUtil()
JsonUtils jsonUtil = new JsonUtils()
private RequestDBUtil requestDBUtil = new RequestDBUtil()
- private static final Logger logger = LoggerFactory.getLogger( DeleteSliceService.class)
+ private static final Logger LOGGER = LoggerFactory.getLogger( DeleteSliceService.class)
@Override
void preProcessRequest(DelegateExecution execution) {
- execution.setVariable("prefix", Prefix)
+ execution.setVariable("prefix", PREFIX)
String msg = ""
- logger.trace("Starting preProcessRequest")
+ LOGGER.debug("*****${PREFIX} preProcessRequest *****")
try {
// check for incoming json message/input
@@ -71,7 +71,7 @@ class DeleteSliceService extends AbstractServiceTaskProcessor {
msg = "e2eslice-service id is null"
exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
}
- logger.info("Input Request: ${siRequest}, reqId: ${requestId}, e2eslice-service: ${serviceInstanceId}")
+ LOGGER.info("Input Request: ${siRequest}, reqId: ${requestId}, e2eslice-service: ${serviceInstanceId}")
//subscriberInfo
checkAndSetRequestParam(siRequest,"globalSubscriberId",false, execution)
@@ -82,17 +82,17 @@ class DeleteSliceService extends AbstractServiceTaskProcessor {
execution.setVariable("progress", "0")
execution.setVariable("result", "processing")
execution.setVariable("operationType", "DELETE")
- execution.setVariable("operationContent", "Prepare init service")
+ execution.setVariable("operationContent", "Delete Slice service operation start")
updateServiceOperationStatus(execution)
} catch (BpmnError e) {
throw e
} catch (Exception ex) {
msg = "Exception in preProcessRequest " + ex.getMessage()
- logger.debug(msg)
+ LOGGER.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- logger.trace("Exit preProcessRequest")
+ LOGGER.debug("*****${PREFIX} Exit preProcessRequest *****")
}
/**
@@ -100,40 +100,39 @@ class DeleteSliceService extends AbstractServiceTaskProcessor {
* @param execution
*/
void sendAsyncResponse(DelegateExecution execution) {
- logger.trace("Staring sendSyncResponse")
+ LOGGER.trace("${PREFIX} Start sendSyncResponse ")
try {
String operationId = execution.getVariable("operationId")
String syncResponse = """{"operationId":"${operationId}"}""".trim()
- logger.info("sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse)
+ LOGGER.info("sendSynchResponse: xmlSyncResponse - " + "\n" + syncResponse)
sendWorkflowResponse(execution, 202, syncResponse)
} catch (Exception ex) {
String msg = "Exception in sendSyncResponse: " + ex.getMessage()
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- logger.trace("Exit sendSyncResponse")
+ LOGGER.trace("${PREFIX} Exit sendSyncResponse")
}
/**
* Deletes the slice service instance in aai
*/
void deleteSliceServiceInstance(DelegateExecution execution) {
- logger.trace("Entered deleteSliceServiceInstance")
+ LOGGER.trace("${PREFIX} Start deleteSliceServiceInstance")
try {
- AAIResourcesClient resourceClient = new AAIResourcesClient()
AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("serviceType"), execution.getVariable("serviceInstanceId"))
- resourceClient.delete(serviceInstanceUri)
+ getAAIClient().delete(serviceInstanceUri)
execution.setVariable("progress", "100")
execution.setVariable("result", "finished")
execution.setVariable("operationContent", "NSMF completes slicing service termination.")
updateServiceOperationStatus(execution)
- logger.trace("Exited deleteSliceServiceInstance")
+ LOGGER.trace("${PREFIX} Exited deleteSliceServiceInstance")
}catch(Exception e){
- logger.debug("Error occured within deleteSliceServiceInstance method: " + e)
+ LOGGER.debug("Error occured within deleteSliceServiceInstance method: " + e)
exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Error occured during deleteSliceServiceInstance from aai")
}
}
@@ -161,7 +160,7 @@ class DeleteSliceService extends AbstractServiceTaskProcessor {
* delete service profile from aai
* @param execution
*/
- private void delServiceProfileFromAAI(DelegateExecution execution)
+ void delServiceProfileFromAAI(DelegateExecution execution)
{
String globalSubscriberId = execution.getVariable("globalSubscriberId")
String serviceType = execution.getVariable("serviceType")
@@ -170,9 +169,8 @@ class DeleteSliceService extends AbstractServiceTaskProcessor {
try
{
- AAIResourcesClient resourceClient = new AAIResourcesClient()
AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_PROFILE_ALL, globalSubscriberId, serviceType, serviceInstanceId)
- AAIResultWrapper wrapper = resourceClient.get(resourceUri, NotFoundException.class)
+ AAIResultWrapper wrapper = getAAIClient().get(resourceUri, NotFoundException.class)
Optional<ServiceProfiles> serviceProfilesOpt =wrapper.asBean(ServiceProfiles.class)
if(serviceProfilesOpt.isPresent()){
ServiceProfiles serviceProfiles = serviceProfilesOpt.get()
@@ -180,29 +178,27 @@ class DeleteSliceService extends AbstractServiceTaskProcessor {
profileId = serviceProfile ? serviceProfile.getProfileId() : ""
}
resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_PROFILE, globalSubscriberId, serviceType, serviceInstanceId, profileId)
- if (!resourceClient.exists(resourceUri)) {
+ if (!getAAIClient().exists(resourceUri)) {
exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
}
- resourceClient.delete(resourceUri)
+ getAAIClient().delete(resourceUri)
}
catch (any)
{
String msg = "delete service profile from aai failed! cause-"+any.getCause()
- logger.error(any.printStackTrace())
+ LOGGER.error(any.printStackTrace())
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
}
}
void sendSyncError(DelegateExecution execution) {
- logger.info("Starting sendSyncError")
+ LOGGER.debug("${PREFIX} Start sendSyncError")
try {
- String errorMessage
+ String errorMessage = "Sending Sync Error."
if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
WorkflowException wfe = execution.getVariable("WorkflowException")
errorMessage = wfe.getErrorMessage()
- } else {
- errorMessage = "Sending Sync Error."
}
String buildworkflowException =
@@ -211,17 +207,17 @@ class DeleteSliceService extends AbstractServiceTaskProcessor {
<aetgt:ErrorCode>7000</aetgt:ErrorCode>
</aetgt:WorkflowException>"""
- logger.debug(buildworkflowException)
+ LOGGER.debug(buildworkflowException)
sendWorkflowResponse(execution, 500, buildworkflowException)
} catch (Exception ex) {
- logger.error("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
+ LOGGER.error("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
}
}
void prepareEndOperationStatus(DelegateExecution execution){
- logger.debug(" ======== STARTED prepareEndOperationStatus Process ======== ")
+ LOGGER.debug(" ======== ${PREFIX} STARTED prepareEndOperationStatus Process ======== ")
execution.setVariable("progress", "100")
execution.setVariable("result", "error")
@@ -233,7 +229,7 @@ class DeleteSliceService extends AbstractServiceTaskProcessor {
execution.setVariable("reason",errorMessage)
updateServiceOperationStatus(execution)
- logger.debug("======== COMPLETED prepareEndOperationStatus Process ======== ")
+ LOGGER.debug("======== ${PREFIX} COMPLETED prepareEndOperationStatus Process ======== ")
}
/**
@@ -250,7 +246,7 @@ class DeleteSliceService extends AbstractServiceTaskProcessor {
String paramValue = jsonUtil.getJsonValue(siRequest, paraName)
if (isBlank(paramValue)) {
msg = "Input ${paraName} is null"
- logger.error(msg)
+ LOGGER.error(msg)
if(isErrorException)
{
exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
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
+ }
+
+}