summaryrefslogtreecommitdiffstats
path: root/bpmn
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AbstractServiceTaskProcessor.groovy5
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy23
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSITest.groovy258
3 files changed, 274 insertions, 12 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AbstractServiceTaskProcessor.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AbstractServiceTaskProcessor.groovy
index 976ad1466d..e83e7e2ea2 100644
--- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AbstractServiceTaskProcessor.groovy
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AbstractServiceTaskProcessor.groovy
@@ -32,6 +32,7 @@ import org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse
import org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder
import org.onap.so.bpmn.core.UrnPropertiesReader
import org.onap.so.bpmn.core.WorkflowException
+import org.onap.so.client.HttpClientFactory
import org.onap.so.client.aai.AAIResourcesClient
import org.springframework.web.util.UriUtils
import org.slf4j.Logger
@@ -677,4 +678,8 @@ public abstract class AbstractServiceTaskProcessor implements ServiceTaskProcess
public AAIResourcesClient getAAIClient(){
return new AAIResourcesClient();
}
+
+ HttpClientFactory getHttpClientFactory(){
+ return new HttpClientFactory()
+ }
}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy
index d8897a2468..8d8e97328d 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy
@@ -76,7 +76,7 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor
*
* @param execution
*/
- private void prepareDecomposeService(DelegateExecution execution)
+ void prepareDecomposeService(DelegateExecution execution)
{
LOGGER.trace(" *****${PREFIX} Start prepareDecomposeService *****")
try
@@ -103,7 +103,7 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor
* get vendor Info
* @param execution
*/
- private void processDecomposition(DelegateExecution execution) {
+ void processDecomposition(DelegateExecution execution) {
LOGGER.debug("*****${PREFIX} start processDecomposition *****")
try {
@@ -130,7 +130,7 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor
* send deallocate request to nssmf
* @param execution
*/
- private void sendRequestToNSSMF(DelegateExecution execution)
+ void sendRequestToNSSMF(DelegateExecution execution)
{
LOGGER.debug("*****${PREFIX} start sendRequestToNSSMF *****")
def currentNSSI = execution.getVariable("currentNSSI")
@@ -160,7 +160,7 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor
URL url = new URL(nssmfRequest)
LOGGER.info("deallocate nssmfRequest:${nssmfRequest}, reqBody: ${json}")
- HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.EXTERNAL)
+ HttpClient httpClient = getHttpClientFactory().newJsonClient(url, ONAPComponents.EXTERNAL)
Response httpResponse = httpClient.post(json)
checkNssmfResponse(httpResponse, execution)
@@ -176,7 +176,7 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor
* send to nssmf query progress
* @param execution
*/
- private void getJobStatus(DelegateExecution execution)
+ void getJobStatus(DelegateExecution execution)
{
def currentNSSI = execution.getVariable("currentNSSI")
String jobId = currentNSSI['jobId']
@@ -198,7 +198,7 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor
URL url = new URL(nssmfRequest)
LOGGER.info("get deallocate job status, nssmfRequest:${nssmfRequest}, requestBody: ${json}")
- HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.EXTERNAL)
+ HttpClient httpClient = getHttpClientFactory().newJsonClient(url, ONAPComponents.EXTERNAL)
Response httpResponse = httpClient.post(json)
checkNssmfResponse(httpResponse, execution)
@@ -248,7 +248,7 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor
* prepare update requestdb
* @param execution
*/
- private void handleJobStatus(DelegateExecution execution)
+ void handleJobStatus(DelegateExecution execution)
{
def currentNSSI = execution.getVariable("currentNSSI")
int currentProgress = currentNSSI["jobProgress"]
@@ -267,7 +267,7 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor
LOGGER.debug("update operation, currentProgress=${currentProgress}, proportion=${proportion}, progress = ${progress}" )
}
- private void timeDelay(DelegateExecution execution) {
+ void timeDelay(DelegateExecution execution) {
try {
Thread.sleep(10000);
} catch(InterruptedException e) {
@@ -279,7 +279,7 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor
* delete slice profile from aai
* @param execution
*/
- private void delSliceProfileFromAAI(DelegateExecution execution)
+ void delSliceProfileFromAAI(DelegateExecution execution)
{
LOGGER.debug("*****${PREFIX} start delSliceProfileFromAAI *****")
def currentNSSI = execution.getVariable("currentNSSI")
@@ -291,12 +291,11 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor
try
{
LOGGER.debug("delete nssiServiceInstanceId:${nssiServiceInstanceId}, profileId:${profileId}")
- AAIResourcesClient resourceClient = new AAIResourcesClient()
AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiServiceInstanceId, 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)
{
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSITest.groovy
new file mode 100644
index 0000000000..493e2c9e1e
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSITest.groovy
@@ -0,0 +1,258 @@
+/*-
+ * ============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.logging.filter.base.ONAPComponents
+import org.onap.so.beans.nsmf.JobStatusResponse
+import org.onap.so.beans.nsmf.NssiResponse
+import org.onap.so.beans.nsmf.ResponseDescriptor
+import org.onap.so.bpmn.common.scripts.MsoGroovyTest
+import org.onap.so.bpmn.core.domain.ServiceArtifact
+import org.onap.so.bpmn.core.domain.ServiceDecomposition
+import org.onap.so.bpmn.core.domain.ServiceInfo
+import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
+import org.onap.so.client.aai.AAIObjectType
+import org.onap.so.client.aai.entities.uri.AAIResourceUri
+import org.onap.so.client.aai.entities.uri.AAIUriFactory
+
+import javax.ws.rs.core.Response
+
+import static org.junit.Assert.assertNotNull
+import static org.junit.Assert.assertTrue
+import static org.mockito.ArgumentMatchers.anyString
+import static org.mockito.ArgumentMatchers.eq
+import static org.mockito.Mockito.doNothing
+import static org.mockito.Mockito.mock
+import static org.mockito.Mockito.spy
+import static org.mockito.Mockito.times
+import static org.mockito.Mockito.when
+
+class DoDeallocateNSSITest extends MsoGroovyTest {
+
+ private HttpClientFactory httpClientFactoryMock
+ private HttpClient httpClientMock
+
+ @Before
+ void init() throws IOException {
+ super.init("DoDeallocateNSSITest")
+ }
+
+ @Captor
+ static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
+
+
+ @Test
+ void testPreProcessRequest(){
+ def currentNSSI = [:]
+ currentNSSI.put("nssiServiceInstanceId","5G-999")
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ DoDeallocateNSSI ddnssi = new DoDeallocateNSSI()
+ ddnssi.preProcessRequest(mockExecution)
+ Mockito.verify(mockExecution,times(1)).getVariable("currentNSSI")
+ }
+
+ @Test
+ void testPrepareDecomposeService(){
+ def currentNSSI = [:]
+ currentNSSI.put("modelInvariantId", "21d57d4b-52ad-4d3c-a798-248b5bb9124b")
+ currentNSSI.put("modelVersionId", "bfba363e-e39c-4bd9-a9d5-1371c28f4d22")
+ currentNSSI.put("nssiServiceInstanceId","5G-999")
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ DoDeallocateNSSI ddnssi = new DoDeallocateNSSI()
+ ddnssi.prepareDecomposeService(mockExecution)
+ Mockito.verify(mockExecution,times(1)).setVariable(eq("serviceModelInfo"), captor.capture())
+ String serviceModelInfo = captor.getValue()
+ assertNotNull(serviceModelInfo)
+ }
+
+ @Test
+ void testProcessDecomposition(){
+ def currentNSSI = [:]
+ ServiceArtifact artifact = new ServiceArtifact()
+ artifact.setContent(getArtifactContent())
+ ServiceInfo serviceInfo = new ServiceInfo()
+ List<ServiceArtifact> artifactList = new ArrayList<>()
+ artifactList.add(artifact)
+ serviceInfo.setServiceArtifact(artifactList)
+ ServiceDecomposition decomposition = new ServiceDecomposition()
+ decomposition.setServiceInfo(serviceInfo)
+ when(mockExecution.getVariable("serviceDecomposition")).thenReturn(decomposition)
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ DoDeallocateNSSI ddnssi = new DoDeallocateNSSI()
+ ddnssi.processDecomposition(mockExecution)
+ String vendor = currentNSSI.get("vendor")
+ assertNotNull(vendor)
+ }
+
+ @Test
+ void testHandleJobStatus(){
+ def currentNSSI = [:]
+ currentNSSI.put("jobProgress", 10)
+ currentNSSI.put("proportion", 90)
+ currentNSSI.put("statusDescription","")
+ currentNSSI.put("e2eServiceInstanceId","21d57d4b-52ad-4d3c-a798-248b5bb9124b")
+ currentNSSI.put("operationId","4c614769-f58a-4556-8ad9-dcd903077c82")
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ DoDeallocateNSSI ddnssi = new DoDeallocateNSSI()
+ ddnssi.handleJobStatus(mockExecution)
+ Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
+ String updateOperationStatus= captor.getValue()
+ assertNotNull(updateOperationStatus)
+ }
+
+ @Test
+ void testDelSliceProfileFromAAI(){
+ def currentNSSI = [:]
+ currentNSSI.put("nssiServiceInstanceId", "5G-999")
+ currentNSSI.put("profileId", "ddf57704-fe8d-417b-882d-2f2a12ddb225")
+ currentNSSI.put("globalSubscriberId","5GCustomer")
+ currentNSSI.put("serviceType","5G")
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ AAIResourceUri profileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, "5GCustomer", "5G", "5G-999", "ddf57704-fe8d-417b-882d-2f2a12ddb225")
+ DoDeallocateNSSI obj = spy(DoDeallocateNSSI.class)
+ when(obj.getAAIClient()).thenReturn(client)
+ when(client.exists(profileUri)).thenReturn(true)
+ doNothing().when(client).delete(profileUri)
+
+ obj.delSliceProfileFromAAI(mockExecution)
+ Mockito.verify(client,times(1)).delete(profileUri)
+ }
+
+ @Test
+ void testSendRequestToNSSMF(){
+ httpClientFactoryMock = mock(HttpClientFactory.class)
+ httpClientMock = mock(HttpClient.class)
+
+ def currentNSSI = [:]
+ currentNSSI.put("snssai", "01-010101")
+ currentNSSI.put("profileId", "ddf57704-fe8d-417b-882d-2f2a12ddb225")
+ currentNSSI.put("nssiServiceInstanceId","5G-999")
+ currentNSSI.put("nsiServiceInstanceId","5G-888")
+
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+ when(mockExecution.getVariable("mso.adapters.nssmf.endpoint")).thenReturn("http://so-nssmf-adapter.onap:8088")
+ String nssmfRequest = "http://so-nssmf-adapter.onap:8088/api/rest/provMns/v1/NSS/SliceProfiles/ddf57704-fe8d-417b-882d-2f2a12ddb225"
+
+ when(httpClientFactoryMock.newJsonClient(new URL(nssmfRequest), ONAPComponents.EXTERNAL)).thenReturn(httpClientMock)
+ DoDeallocateNSSI obj = spy(DoDeallocateNSSI.class)
+ when(obj.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
+ Response responseMock = mock(Response.class)
+ NssiResponse response = new NssiResponse()
+ response.setNssiId("NSSI-C-004-HDBHZ-NSSMF-01-A-HW")
+ response.setJobId("a5c5913d-448a-bcb1-9b800a944d84")
+ when(httpClientMock.post(anyString())).thenReturn(responseMock)
+ when(responseMock.getStatus()).thenReturn(202)
+ when(responseMock.readEntity(NssiResponse.class)) thenReturn(response)
+ when(responseMock.hasEntity()).thenReturn(true)
+
+ obj.sendRequestToNSSMF(mockExecution)
+ String jobId = currentNSSI['jobId']
+ assertNotNull(jobId)
+ }
+
+ @Test
+ void testGetJobStatus(){
+ httpClientFactoryMock = mock(HttpClientFactory.class)
+ httpClientMock = mock(HttpClient.class)
+
+ def currentNSSI = [:]
+ currentNSSI.put("jobId", "a5c5913d-448a-bcb1-9b800a944d84")
+ currentNSSI.put("nssiServiceInstanceId","5G-999")
+ currentNSSI.put("nsiServiceInstanceId","5G-888")
+ currentNSSI.put("jobProgress",60)
+
+ when(mockExecution.getVariable("isNSSIDeAllocated")).thenReturn(false)
+ when(mockExecution.getVariable("isNSSIDeAllocated")).thenReturn(false)
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+ when(mockExecution.getVariable("mso.adapters.nssmf.endpoint")).thenReturn("http://so-nssmf-adapter.onap:8088")
+ String nssmfRequest = "http://so-nssmf-adapter.onap:8088/api/rest/provMns/v1/NSS/jobs/a5c5913d-448a-bcb1-9b800a944d84"
+
+ when(httpClientFactoryMock.newJsonClient(new URL(nssmfRequest), ONAPComponents.EXTERNAL)).thenReturn(httpClientMock)
+ DoDeallocateNSSI obj = spy(DoDeallocateNSSI.class)
+ when(obj.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
+ Response responseMock = mock(Response.class)
+ ResponseDescriptor descriptor = new ResponseDescriptor()
+ descriptor.setProgress(100)
+ descriptor.setStatusDescription("finished deallocate nssi")
+ JobStatusResponse jobStatusResponse = new JobStatusResponse()
+ jobStatusResponse.setResponseDescriptor(descriptor)
+ when(httpClientMock.post(anyString())).thenReturn(responseMock)
+ when(responseMock.getStatus()).thenReturn(202)
+ when(responseMock.readEntity(JobStatusResponse.class)) thenReturn(jobStatusResponse)
+ when(responseMock.hasEntity()).thenReturn(true)
+
+ obj.getJobStatus(mockExecution)
+ Mockito.verify(mockExecution,times(1)).setVariable(eq("isNSSIDeAllocated"), captor.capture())
+ boolean value = captor.getValue()
+ assertTrue(value)
+ }
+
+
+ private String getArtifactContent(){
+ String content =
+ """
+ {
+ "metadata":{
+ "id":"NSST-C-001-HDBNJ-NSSMF-01-A-HW",
+ "vendor":"HW",
+ "version":"1.0",
+ "name":"eMBB_demo",
+ "description":"eMBB for demo",
+ "type":"embb",
+ "domainType":"cn"
+ },
+ "capabilities":{
+ "latency":{
+ "type":"integer",
+ "constrainstsl":"less_or_equal",
+ "value":"20"
+ },
+ "areaTrafficCapDL":{
+ "type":"integer",
+ "constrainstsl":"less_or_equal",
+ "value":"300"
+ },
+ "areaTrafficCapUL":{
+ "type":"integer",
+ "constrainstsl":"less_or_equal",
+ "value":"300"
+ },
+ "maxNumberofUEs":{
+ "type":"integer",
+ "constrainstsl":"less_or_equal",
+ "value":"300"
+ }
+ }
+ }
+ """
+ }
+}