summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common')
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy6
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy267
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy105
3 files changed, 216 insertions, 162 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy
index b07f5c965d..a28dbbf9b1 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy
@@ -742,7 +742,11 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor {
Map<String, Object> instanceParamsMap = new HashMap<>()
// Supported S-NSSAI
- List<String> snssais = (List<String>) currentNSSI['S-NSSAIs']
+ def snssaisList = currentNSSI['S-NSSAIs']
+ List<String> snssais = new ArrayList<>()
+ if(snssaisList != null) {
+ snssais = new ArrayList<String>((List<String>)snssaisList)
+ }
LOGGER.debug("prepareInstanceParams: snssais size = " + snssais.size())
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy
index 11058748fd..e563471d2a 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy
@@ -21,13 +21,13 @@
package org.onap.so.bpmn.infrastructure.scripts
import com.fasterxml.jackson.databind.ObjectMapper
-import com.google.gson.JsonObject
+import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
-import org.onap.aai.domain.yang.v19.AllottedResource
-import org.onap.aai.domain.yang.v19.GenericVnf
+import org.json.JSONArray
+import org.json.JSONObject
+import org.onap.aai.domain.yang.v19.ModelVer
import org.onap.aai.domain.yang.v19.ServiceInstance
import org.onap.aai.domain.yang.v19.SliceProfile
-import org.onap.aai.domain.yang.v19.SliceProfiles
import org.onap.aaiclient.client.aai.AAIResourcesClient
import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
import org.onap.aaiclient.client.aai.entities.Relationships
@@ -37,22 +37,19 @@ import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
import org.onap.logging.filter.base.ONAPComponents
import org.onap.so.bpmn.common.scripts.ExceptionUtil
+import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
+import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
import org.onap.so.bpmn.common.scripts.MsoUtils
import org.onap.so.bpmn.common.scripts.OofUtils
import org.onap.so.bpmn.common.scripts.RequestDBUtil
import org.onap.so.bpmn.core.UrnPropertiesReader
import org.onap.so.bpmn.core.json.JsonUtils
import org.onap.so.client.HttpClient
-import org.onap.so.client.HttpClientFactory
-import org.onap.so.client.oof.adapter.beans.payload.OofRequest
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import javax.ws.rs.core.Response
-import static org.apache.commons.lang3.StringUtils.isBlank
-import static org.apache.commons.lang3.StringUtils.isBlank
-import static org.onap.so.bpmn.common.scripts.GenericUtils.isBlank
import static org.onap.so.bpmn.common.scripts.GenericUtils.isBlank
class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
@@ -88,7 +85,6 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
LOGGER.debug("${PREFIX} Start executeTerminateNSSIQuery")
String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
- // String urlString = UrnPropertiesReader.getVariable("mso.adapters.oof.endpoint", execution)
//API Path
String apiPath = "/api/oof/terminate/nxi/v1"
@@ -102,20 +98,6 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
String msokey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
String basicAuthValue = utils.encrypt(basicAuth, msokey)
- /* if (basicAuthValue != null) {
- LOGGER.debug( "Obtained BasicAuth username and password for OOF Adapter: " + basicAuthValue)
- try {
- authHeader = utils.getBasicAuth(basicAuthValue, msokey)
- execution.setVariable("BasicAuthHeaderValue", authHeader)
- } catch (Exception ex) {
- LOGGER.error( "Unable to encode username and password string: " + ex)
- exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - Unable to encode username and password string")
- }
- } else {
- LOGGER.error( "Unable to obtain BasicAuth - BasicAuth value null")
- exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth value null")
- } */
-
try {
authHeader = utils.getBasicAuth(basicAuthValue, msokey)
@@ -177,7 +159,6 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
" \"errorCode\": \"${errorCode}\",\n" +
" \"errorMessage\": \"${errorMessage}\"\n" +
"}"
- //exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.")
}
if (httpResponse.hasEntity()) {
@@ -282,71 +263,124 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
}
-
/**
- * Invokes deleteServiceOrder external API
+ * Prepares ServiceOrderRequest
* @param execution
*/
- void deleteServiceOrder(DelegateExecution execution) {
- LOGGER.debug("${PREFIX} Start deleteServiceOrder")
+ private void prepareServiceOrderRequest(DelegateExecution execution) {
+ LOGGER.debug("${PREFIX} Start prepareServiceOrderRequest")
def currentNSSI = execution.getVariable("currentNSSI")
- try {
- //url:/nbi/api/v4/serviceOrder/"
- def nsmfЕndPoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution)
-
- ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
-
- //String url = String.format("${nbiEndpointUrl}/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId())
-
- GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf']
-
- // http://so.onap:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances/de6a0aa2-19f2-41fe-b313-a5a9f159acd7/vnfs/3abbb373-8d33-4977-aa4b-2bfee496b6d5
- String url = String.format("${nsmfЕndPoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId())
+ //extAPI path hardcoded for testing purposes, will be updated in next patch
+ String extAPIPath = "https://nbi.onap:8443/nbi/api/v4" + "/serviceOrder"
+ execution.setVariable("ExternalAPIURL", extAPIPath)
+ ObjectMapper objectMapper = new ObjectMapper();
+ Map<String, Object> serviceOrder = new LinkedHashMap()
+ //ExternalId
+ serviceOrder.put("externalId", "ONAP001")
+
+ //Requested Start Date
+ String requestedStartDate = utils.generateCurrentTimeInUtc()
+ String requestedCompletionDate = utils.generateCurrentTimeInUtc()
+ serviceOrder.put("requestedStartDate", requestedStartDate)
+ serviceOrder.put("requestedCompletionDate", requestedCompletionDate)
+
+ //RelatedParty Fields
+ String relatedPartyId = execution.getVariable("globalSubscriberId")
+ String relatedPartyRole = "ONAPcustomer"
+ Map<String, String> relatedParty = new LinkedHashMap()
+ relatedParty.put("id", relatedPartyId)
+ relatedParty.put("role", relatedPartyRole)
+ List<Map<String, String>> relatedPartyList = new ArrayList()
+ relatedPartyList.add(relatedParty)
+ serviceOrder.put("relatedParty", relatedPartyList)
+
+ Map<String, Object> orderItem = new LinkedHashMap()
+ //orderItem id
+ String orderItemId = "1"
+ orderItem.put("id", orderItemId)
+
+ //order item action will always be delete as we are triggering request for deletion
+ String orderItemAction = "delete"
+ orderItem.put("action", orderItemAction)
+
+ // service Details
+ AAIResourcesClient client = getAAIClient()
+ ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance'] //(ServiceInstance) currentNSSI['nssi']
+ AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(networkServiceInstance.getModelInvariantId()).modelVer(networkServiceInstance.getModelVersionId()))
+
+ Map<String, Object> service = new LinkedHashMap()
+ // Service id
+ service.put("id", networkServiceInstance.getServiceInstanceId())
+
+ //ServiceName
+ String serviceName = networkServiceInstance.getServiceInstanceName()
+ service.put("name", serviceName)
+
+ // Service Type
+ service.put("serviceType", networkServiceInstance.getServiceType())
+ //Service State
+ service.put("serviceState", "active")
+
+ Map<String, String> serviceSpecification = new LinkedHashMap()
+ String modelUuid = networkServiceInstance.getModelVersionId()
+ serviceSpecification.put("id", modelUuid)
+ service.put("serviceSpecification", serviceSpecification)
+
+ orderItem.put("service", service)
+ List<Map<String, String>> orderItemList = new ArrayList()
+ orderItemList.add(orderItem)
+ serviceOrder.put("orderItem", orderItemList)
+ String jsonServiceOrder = objectMapper.writeValueAsString(serviceOrder)
+ LOGGER.debug("******* ServiceOrder :: "+jsonServiceOrder)
+ execution.setVariable("serviceOrderRequest", jsonServiceOrder)
+
+ LOGGER.debug("${PREFIX} End prepareServiceOrderRequest")
+ }
- LOGGER.debug("url = " + url)
- currentNSSI['deleteServiceOrderURL'] = url
- String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
- String basicAuth = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
+ /**
+ * Invokes deleteServiceOrder external API
+ * @param execution
+ */
+ void deleteServiceOrder(DelegateExecution execution) {
+ LOGGER.debug("${PREFIX} Start deleteServiceOrder")
- def authHeader = utils.getBasicAuth(basicAuth, msoKey)
+ def currentNSSI = execution.getVariable("currentNSSI")
- def requestDetails = ""
+ prepareServiceOrderRequest(execution)
- String prepareRequestDetailsResponse = prepareRequestDetails(execution)
- LOGGER.debug("deleteServiceOrder: prepareRequestDetailsResponse=" + prepareRequestDetailsResponse)
+ try {
+ String extAPIPath = execution.getVariable("ExternalAPIURL")
+ String payload = execution.getVariable("serviceOrderRequest")
+ LOGGER.debug("externalAPIURL is: " + extAPIPath)
+ LOGGER.debug("ServiceOrder payload is: " + payload)
- String errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode")
- LOGGER.debug("deleteServiceOrder: errorCode=" + errorCode)
- if(errorCode == null || errorCode.isEmpty()) { // No error
- requestDetails = prepareRequestDetailsResponse
- }
- else {
- exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorMessage"))
- }
+ execution.setVariable("ServiceOrderId", "")
- String callDeleteServiceOrderResponse = callDeleteServiceOrder(url, authHeader, requestDetails)
- errorCode = jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "errorCode")
+ String callDeleteServiceOrderResponse = callDeleteServiceOrder(execution, extAPIPath, payload)
+ String errorCode = jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "errorCode")
if(errorCode == null || errorCode.isEmpty()) { // No error
- String macroOperationId = jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "requestReferences.requestId")
- String requestSelfLink = jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "requestReferences.requestSelfLink")
+ JSONObject responseObj = new JSONObject(callDeleteServiceOrderResponse)
- execution.setVariable("macroOperationId", macroOperationId)
- execution.setVariable("requestSelfLink", requestSelfLink)
+ String serviceOrderId = responseObj.get("id")
- currentNSSI['requestSelfLink'] = requestSelfLink
+ execution.setVariable("ServiceOrderId", serviceOrderId)
+ LOGGER.info("Delete ServiceOrderid is: " + serviceOrderId)
}
else {
LOGGER.error(jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "errorMessage"))
exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "errorMessage"))
}
- } catch (any) {
- String msg = "Exception in DoDeallocateCoreNSSI.deleteServiceOrder. " + any.getCause()
- LOGGER.error(msg)
+
+ }catch (BpmnError e) {
+ throw e;
+ } catch (Exception ex) {
+ String msg = "Exception in ServiceOrder ExtAPI" + ex.getMessage()
+ LOGGER.debug(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
@@ -354,33 +388,38 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
}
- String callDeleteServiceOrder(String url, String authHeader, String requestDetailsStr) {
+ String callDeleteServiceOrder(DelegateExecution execution, String extAPIPath, String payload) {
LOGGER.debug("${PREFIX} Start callDeleteServiceOrder")
String errorCode = ""
String errorMessage = ""
String response = ""
- LOGGER.debug("callDeleteServiceOrder: url = " + url)
- LOGGER.debug("callDeleteServiceOrder: authHeader = " + authHeader)
+ LOGGER.debug("callDeleteServiceOrder: url = " + extAPIPath)
try {
- HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO)
- httpClient.addAdditionalHeader("Authorization", authHeader)
- httpClient.addAdditionalHeader("Accept", "application/json")
- Response httpResponse = httpClient.delete(requestDetailsStr)
+ ExternalAPIUtil externalAPIUtil = getExternalAPIUtil()
+ Response httpResponse = externalAPIUtil.executeExternalAPIPostCall(execution, extAPIPath, payload)
- int soResponseCode = httpResponse.getStatus()
- LOGGER.debug("callDeleteServiceOrder: soResponseCode = " + soResponseCode)
+ int responseCode = httpResponse.getStatus()
+ execution.setVariable("ServiceOrderResponseCode", responseCode)
+ LOGGER.debug("Delete ServiceOrder response code is: " + responseCode)
+
+ //Process Response
+ if(responseCode == 200 || responseCode == 201 || responseCode == 202 ) {
+ //200 OK 201 CREATED 202 ACCEPTED
+ LOGGER.debug("Delete ServiceOrder Received a Good Response")
- if (soResponseCode >= 200 && soResponseCode < 204 && httpResponse.hasEntity()) {
response = httpResponse.readEntity(String.class)
LOGGER.debug("callDeleteServiceInstance: response = " + response)
+
+ execution.setVariable("DeleteServiceOrderResponse", response)
+
}
else {
errorCode = 500
- errorMessage = "Response code is " + soResponseCode
+ errorMessage = "Response code is " + responseCode
response = "{\n" +
" \"errorCode\": \"${errorCode}\",\n" +
@@ -503,18 +542,64 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
void getDeleteServiceOrderProgress(DelegateExecution execution) {
LOGGER.debug("${getPrefix()} Start getDeleteServiceOrderProgress")
- def currentNSSI = execution.getVariable("currentNSSI")
-
- String url = currentNSSI['requestSelfLink']
-
- String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
-
- String basicAuth = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
-
- def authHeader = ""
- String basicAuthValue = utils.getBasicAuth(basicAuth, msoKey)
+ String msg
+ try {
+ String extAPIPath = execution.getVariable("ExternalAPIURL")
+ extAPIPath += "/" + execution.getVariable("ServiceOrderId")
+ LOGGER.debug("externalAPIURL is: " + extAPIPath)
+
+ ExternalAPIUtil externalAPIUtil = getExternalAPIUtil()
+ Response response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
+ int responseCode = response.getStatus()
+ execution.setVariable("GetServiceOrderResponseCode", responseCode)
+ LOGGER.debug("Get ServiceOrder response code is: " + responseCode)
+ String extApiResponse = response.readEntity(String.class)
+ JSONObject responseObj = new JSONObject(extApiResponse)
+ execution.setVariable("GetServiceOrderResponse", extApiResponse)
+ LOGGER.debug("Get response body is: " + extApiResponse)
+ //Process Response //200 OK 201 CREATED 202 ACCEPTED
+ if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
+ {
+ LOGGER.debug("Get Delete ServiceOrder Received a Good Response")
+ String orderState = responseObj.get("state")
+ if("REJECTED".equalsIgnoreCase(orderState)) {
+ prepareFailedOperationStatusUpdate(execution)
+ return
+ }
+ JSONArray items = responseObj.getJSONArray("orderItem")
+ JSONObject item = items.get(0) as JSONObject
+ JSONObject service = item.get("service") as JSONObject
+ String networkServiceId = service.get("id")
+
+ execution.setVariable("networkServiceId", networkServiceId)
+ String serviceOrderState = item.get("state")
+ execution.setVariable("ServiceOrderState", serviceOrderState)
+ // Get serviceOrder State and process progress
+ if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState) || "INPROGRESS".equalsIgnoreCase(serviceOrderState) || "IN_PROGRESS".equalsIgnoreCase(serviceOrderState)) {
+ execution.setVariable("deleteStatus", "processing")
+ }
+ else if("COMPLETED".equalsIgnoreCase(serviceOrderState)) {
+ execution.setVariable("deleteStatus", "completed")
+ }
+ else if("FAILED".equalsIgnoreCase(serviceOrderState)) {
+ msg = "ServiceOrder failed"
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ else {
+ msg = "ServiceOrder failed"
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ LOGGER.debug("NBI serviceOrder state: "+serviceOrderState)
+ }
+ else{
+ msg = "Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode
+ prepareFailedOperationStatusUpdate(execution)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
- getProgress(execution, url, basicAuthValue, "deleteStatus")
+ }catch(Exception e){
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e.getMessage())
+ }
LOGGER.debug("${getPrefix()} Exit getDeleteServiceOrderProgress")
}
@@ -574,4 +659,8 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
String getAction() {
return ACTION
}
+
+ ExternalAPIUtil getExternalAPIUtil() {
+ return new ExternalAPIUtilFactory().create()
+ }
}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy
index acace8c1c7..9ee9255499 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy
@@ -20,31 +20,30 @@
package org.onap.so.bpmn.infrastructure.scripts
-import com.fasterxml.jackson.databind.ObjectMapper
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito
-import org.onap.aai.domain.yang.v19.*
+import org.onap.aai.domain.yang.v19.AllottedResource
+import org.onap.aai.domain.yang.v19.AllottedResources
+import org.onap.aai.domain.yang.v19.ServiceInstance
+import org.onap.aai.domain.yang.v19.SliceProfile
import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
import org.onap.aaiclient.client.aai.entities.Relationships
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
-import org.onap.logging.filter.base.ONAPComponents
import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
-import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
import org.onap.so.bpmn.common.scripts.MsoGroovyTest
-import org.onap.so.bpmn.common.scripts.MsoUtils
import org.onap.so.bpmn.common.scripts.OofUtils
import org.onap.so.client.HttpClient
import org.onap.so.client.HttpClientFactory
-import org.onap.so.serviceinstancebeans.RequestDetails
import javax.ws.rs.core.Response
import static org.junit.Assert.assertNotNull
import static org.junit.Assert.assertTrue
+import static org.mockito.ArgumentMatchers.any
import static org.mockito.Mockito.*
class DoDeallocateCoreNSSITest extends MsoGroovyTest {
@@ -115,11 +114,6 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
String authHeaderResponse = "auth-header"
- /* String authHeaderResponse = "{\n" +
- " \"errorCode\": \"401\",\n" +
- " \"errorMessage\": \"Bad request\"\n" +
- "}" */
-
when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
@@ -209,60 +203,32 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
currentNSSI.put("networkServiceInstance", networkServiceInstance)
- when(mockExecution.getVariable("mso.infra.endpoint.url")).thenReturn("http://mso.onap:8088")
- when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
- when(mockExecution.getVariable("mso.infra.endpoint.auth")).thenReturn("mso.infra.endpoint.auth")
+ String externalAPIURL = "https://nbi.onap:8443/nbi/api/v4/serviceOrder"
+ when(mockExecution.getVariable("ExternalAPIURL")).thenReturn(externalAPIURL)
DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
when(spy.getAAIClient()).thenReturn(client)
- GenericVnf genericVnf = new GenericVnf()
- genericVnf.setServiceId("service-id")
- genericVnf.setVnfName("vnf-name")
- genericVnf.setModelInvariantId("model-invariant-id")
- genericVnf.setModelCustomizationId("model-customization-id")
- genericVnf.setVnfName("vnf-name")
- genericVnf.setVnfId("vnf-id")
-
-
- currentNSSI.put("constituteVnf", genericVnf)
+ String serviceOrderRequest = ""
- String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), genericVnf.getVnfId())
+ when(mockExecution.getVariable("serviceOrderRequest")).thenReturn(serviceOrderRequest)
- RequestDetails requestDetails = new RequestDetails()
- ObjectMapper mapper = new ObjectMapper()
- String requestDetailsStr = mapper.writeValueAsString(requestDetails)
-
- when(spy.prepareRequestDetails(mockExecution)).thenReturn(requestDetailsStr)
-
- MsoUtils msoUtilsMock = mock(MsoUtils.class)
- String basicAuth = "basicAuth"
- when(msoUtilsMock.getBasicAuth(anyString(), anyString())).thenReturn(basicAuth)
-
- HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class)
- when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
Response responseMock = mock(Response.class)
- HttpClient httpClientMock = mock(HttpClient.class)
-
- when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock)
-
- when(httpClientMock.delete(requestDetailsStr)).thenReturn(responseMock)
+ ExternalAPIUtil externalAPIUtil = mock(ExternalAPIUtil.class)
+ when(spy.getExternalAPIUtil()).thenReturn(externalAPIUtil)
+ when(externalAPIUtil.executeExternalAPIPostCall(mockExecution, externalAPIURL, serviceOrderRequest)).thenReturn(responseMock)
when(responseMock.getStatus()).thenReturn(200)
- when(responseMock.hasEntity()).thenReturn(true)
- String macroOperationId = "request-id"
- String requestSelfLink = "request-self-link"
- String entity = "{\"requestReferences\":{\"requestId\": \"${macroOperationId}\",\"requestSelfLink\":\"${requestSelfLink}\"}}"
+ String id = UUID.randomUUID().toString()
+ String entity = "{\"id\":\"${id}\"}"
when(responseMock.readEntity(String.class)).thenReturn(entity)
spy.deleteServiceOrder(mockExecution)
- Mockito.verify(mockExecution,times(1)).setVariable("macroOperationId", macroOperationId)
- Mockito.verify(mockExecution,times(1)).setVariable("requestSelfLink", requestSelfLink)
+ verify(mockExecution,times(1)).setVariable("ServiceOrderId", id)
- assertTrue(currentNSSI['requestSelfLink'].equals(requestSelfLink))
}
@@ -436,49 +402,44 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
@Test
void testDeleteServiceOrderProgressCompleted() {
- executeDeleteServiceOrderProgress("COMPLETE")
+ executeDeleteServiceOrderProgress("COMPLETED")
Mockito.verify(mockExecution,times(1)).setVariable("deleteStatus", "completed")
}
void executeDeleteServiceOrderProgress(String state) {
def currentNSSI = [:]
+ currentNSSI.put("nssiId","5G-999")
- when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
-
- String url = "http://nbi.onap:8088/api/v4/serviceOrder/NS-777"
+ ServiceInstance networkServiceInstance = new ServiceInstance()
+ networkServiceInstance.setServiceInstanceId("NS-777")
+ networkServiceInstance.setServiceRole("Network Service")
- currentNSSI['requestSelfLink'] = url
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
- DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
+ currentNSSI.put("networkServiceInstance", networkServiceInstance)
- /*ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class)
- when(spy.getExternalAPIUtilFactory()).thenReturn(externalAPIUtilFactoryMock)
+ String serviceOrder = UUID.randomUUID().toString()
- ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class)
+ when(mockExecution.getVariable("ServiceOrderId")).thenReturn(serviceOrder)
- when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock) */
+ String externalAPIURL = "https://nbi.onap:8443/nbi/api/v4/serviceOrder"
+ when(mockExecution.getVariable("ExternalAPIURL")).thenReturn(externalAPIURL)
- MsoUtils msoUtilsMock = mock(MsoUtils.class)
- String basicAuth = "basicAuth"
- when(msoUtilsMock.getBasicAuth(anyString(), anyString())).thenReturn(basicAuth)
+ DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
- HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class)
- when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
Response responseMock = mock(Response.class)
- HttpClient httpClientMock = mock(HttpClient.class)
+ ExternalAPIUtil externalAPIUtil = mock(ExternalAPIUtil.class)
+ when(spy.getExternalAPIUtil()).thenReturn(externalAPIUtil)
-
- when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock)
-
- when(httpClientMock.get()).thenReturn(responseMock)
-// when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock)
+ externalAPIURL += "/" + serviceOrder
+ when(externalAPIUtil.executeExternalAPIGetCall(mockExecution, externalAPIURL)).thenReturn(responseMock)
when(responseMock.getStatus()).thenReturn(200)
- when(responseMock.hasEntity()).thenReturn(true)
- String entity = "{\"request\":{\"requestStatus\":{\"requestState\":\"${state}\"}},\"state\":\"ACCEPTED\"}"
+ String id = UUID.randomUUID().toString()
+ String entity = "{\"state\":\"ACCEPTED\",\"orderItem\":[{\"state\":\"${state}\",\"service\":{\"id\":\"${id}\"}}]}"
when(responseMock.readEntity(String.class)).thenReturn(entity)
spy.getDeleteServiceOrderProgress(mockExecution)