diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
39 files changed, 923 insertions, 295 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java index 0190f3df56..7d0927e498 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java @@ -29,7 +29,6 @@ import java.util.UUID; import org.apache.commons.lang.SerializationUtils; import org.camunda.bpm.engine.delegate.BpmnError; -import org.camunda.bpm.engine.delegate.DelegateExecution; import org.json.JSONArray; import org.json.JSONObject; import org.onap.so.bpmn.common.BuildingBlockExecution; @@ -107,7 +106,7 @@ public class SniroHomingV2 { * @param execution */ public void callSniro(BuildingBlockExecution execution){ - log.trace("Started Sniro Homing Call Sniro"); + log.debug("Started Sniro Homing Call Sniro"); try{ GeneralBuildingBlock bb = execution.getGeneralBuildingBlock(); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java index 1fe3143c4a..4506699ce8 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java @@ -22,6 +22,7 @@ package org.onap.so.bpmn.infrastructure.sdnc.tasks; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; @@ -46,10 +47,17 @@ public class SDNCQueryTasks { @Autowired private ExtractPojosForBB extractPojosForBB; - public void queryVnf(BuildingBlockExecution execution) throws Exception { + public void queryVnf(BuildingBlockExecution execution) throws Exception { + ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); + String selfLink = "restconf/config/GENERIC-RESOURCE-API:services/service/" + + serviceInstance.getServiceInstanceId() + "/service-data/vnfs/vnf/" + + genericVnf.getVnfId() + "/vnf-data/vnf-topology/"; try { + if(genericVnf.getSelflink() == null) { + genericVnf.setSelflink(selfLink); + } String response = sdncVnfResources.queryVnf(genericVnf); execution.setVariable("SDNCQueryResponse_" + genericVnf.getVnfId(), response); } catch (Exception ex) { @@ -59,12 +67,18 @@ public class SDNCQueryTasks { public void queryVfModule(BuildingBlockExecution execution) throws Exception { + ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID)); - + String selfLink = "restconf/config/GENERIC-RESOURCE-API:services/service/" + + serviceInstance.getServiceInstanceId() + "/service-data/vnfs/vnf/" + + genericVnf.getVnfId() + "/vnf-data/vf-modules/vf-module/" + + vfModule.getVfModuleId() + "/vf-module-data/vf-module-topology/"; try { + vfModule.setSelflink(selfLink); if(vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) { String response = sdncVfModuleResources.queryVfModule(vfModule); - execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), response); + execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), response); } else { throw new Exception("Vf Module " + vfModule.getVfModuleId() + " exists in gBuildingBlock but does not have a selflink value"); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java new file mode 100644 index 0000000000..fedec4f732 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java @@ -0,0 +1,99 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.sdnc.tasks; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.exception.MapperException; +import org.onap.so.client.sdnc.SDNCClient; +import org.onap.so.client.sdnc.beans.SDNCRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.jayway.jsonpath.JsonPath; + +@Component +public class SDNCRequestTasks { + + private static final Logger logger = LoggerFactory.getLogger(SDNCRequestTasks.class); + + private static final String SDNC_REQUEST = "SDNCRequest"; + private static final String MESSAGE = "_MESSAGE"; + private static final String CORRELATOR = "_CORRELATOR"; + protected static final String IS_CALLBACK_COMPLETED = "isCallbackCompleted"; + + @Autowired + private ExceptionBuilder exceptionBuilder; + + @Autowired + private SDNCClient sdncClient; + + public void createCorrelationVariables (DelegateExecution execution) { + SDNCRequest request = (SDNCRequest)execution.getVariable(SDNC_REQUEST); + execution.setVariable(request.getCorrelationName()+CORRELATOR, request.getCorrelationValue()); + execution.setVariable("sdncTimeout", request.getTimeOut()); + } + + public void callSDNC (DelegateExecution execution) { + SDNCRequest request = (SDNCRequest)execution.getVariable(SDNC_REQUEST); + try { + String response = sdncClient.post(request.getSDNCPayload(),request.getTopology()); + String finalMessageIndicator = JsonPath.read(response, "$.output.ack-final-indicator"); + execution.setVariable("isSDNCCompleted", convertIndicatorToBoolean(finalMessageIndicator)); + } catch (MapperException e) { + logger.error("Error Parsing SDNC Response", e); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000,"Error Parsing SDNC Response"); + } catch (BadResponseException e) { + logger.error("Error Reading SDNC Response", e); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "Error Reading SDNC Response"); + } + } + + public void processCallback (DelegateExecution execution) { + try { + SDNCRequest request = (SDNCRequest)execution.getVariable(SDNC_REQUEST); + String asyncRequest = (String) execution.getVariable(request.getCorrelationName()+MESSAGE); + String finalMessageIndicator = JsonPath.read(asyncRequest, "$.input.ack-final-indicator"); + boolean isCallbackCompleted = convertIndicatorToBoolean(finalMessageIndicator); + execution.setVariable(IS_CALLBACK_COMPLETED, isCallbackCompleted); + } catch (Exception e) { + logger.error("Error procesing SDNC callback", e); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "Error procesing SDNC callback"); + } + } + + public void handleTimeOutException (DelegateExecution execution) { + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "Error timed out waiting on SDNC Async-Response"); + } + + public void handleSyncError (DelegateExecution execution) { + String msg = (String) execution.getVariable("SDNCSyncError"); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); + } + + protected boolean convertIndicatorToBoolean(String finalMessageIndicator) { + return "Y".equals(finalMessageIndicator); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java index fabe8a159d..505c61da6b 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java @@ -201,30 +201,11 @@ public class WorkflowActionBBTasks { execution.setVariable("mso-service-instance-id", resourceId); } - public void setupFalloutHandler(DelegateExecution execution) { - final String requestId = (String) execution.getVariable(G_REQUEST_ID); - final String action = (String) execution.getVariable(G_ACTION); - final String resourceId = (String) execution.getVariable("resourceId"); - String exceptionMsg = ""; - if (execution.getVariable("WorkflowActionErrorMessage") != null) { - exceptionMsg = (String) execution.getVariable("WorkflowActionErrorMessage"); - } else { - exceptionMsg = "Error in WorkflowAction"; - } - execution.setVariable("mso-service-instance-id", resourceId); - execution.setVariable("mso-request-id", requestId); - String falloutRequest = "<aetgt:FalloutHandlerRequest xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"xmlns:ns=\"http://org.onap/so/request/types/v1\"xmlns:wfsch=\"http://org.onap/so/workflow/schema/v1\"><request-info xmlns=\"http://org.onap/so/infra/vnf-request/v1\"><request-id>" - + requestId + "</request-id><action>" + action - + "</action><source>VID</source></request-info><aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>" - + exceptionMsg - + "</aetgt:ErrorMessage><aetgt:ErrorCode>7000</aetgt:ErrorCode></aetgt:WorkflowException></aetgt:FalloutHandlerRequest>"; - execution.setVariable("falloutRequest", falloutRequest); - } - public void checkRetryStatus(DelegateExecution execution) { String handlingCode = (String) execution.getVariable("handlingCode"); int retryCount = (int) execution.getVariable(RETRY_COUNT); if (handlingCode.equals("Retry")){ + updateRequestErrorStatusMessage(execution); if(retryCount<5){ int currSequence = (int) execution.getVariable("gCurrentSequence"); execution.setVariable("gCurrentSequence", currSequence-1); @@ -266,6 +247,19 @@ public class WorkflowActionBBTasks { rollbackFlows.add(flowsToExecute.get(i)); } } + + int flowSize = rollbackFlows.size(); + String handlingCode = (String) execution.getVariable("handlingCode"); + if(handlingCode.equals("RollbackToAssigned")){ + for(int i = 0; i<flowSize -1; i++){ + if(rollbackFlows.get(i).getBuildingBlock().getBpmnFlowName().contains("Unassign")){ + rollbackFlows.remove(i); + } + } + } + + updateRequestErrorStatusMessage(execution); + if (rollbackFlows.isEmpty()) execution.setVariable("isRollbackNeeded", false); else @@ -280,40 +274,59 @@ public class WorkflowActionBBTasks { } } + protected void updateRequestErrorStatusMessage(DelegateExecution execution) { + try { + String requestId = (String) execution.getVariable(G_REQUEST_ID); + InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); + String errorMsg = retrieveErrorMessage(execution); + if(errorMsg == null || errorMsg.equals("")){ + errorMsg = "Failed to determine error message"; + } + request.setStatusMessage(errorMsg); + logger.debug("Updating RequestDB to failed: errorMsg = " + errorMsg); + requestDbclient.updateInfraActiveRequests(request); + } catch (Exception e) { + logger.error("Failed to update Request db with the status message after retry or rollback has been initialized.",e); + } + } + public void abortCallErrorHandling(DelegateExecution execution) { String msg = "Flow has failed. Rainy day handler has decided to abort the process."; logger.error(msg); throw new BpmnError(msg); } - + public void updateRequestStatusToFailed(DelegateExecution execution) { try { String requestId = (String) execution.getVariable(G_REQUEST_ID); InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); String errorMsg = null; - boolean rollback = (boolean) execution.getVariable("isRollbackComplete"); - try { - WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException"); - if(exception != null && (exception.getErrorMessage()!=null || !exception.getErrorMessage().equals(""))){ - errorMsg = exception.getErrorMessage(); - } - } catch (Exception ex) { - //log error and attempt to extact WorkflowExceptionMessage - logger.error("Failed to extract workflow exception from execution.",ex); - } - if (errorMsg == null){ - try { - errorMsg = (String) execution.getVariable("WorkflowExceptionErrorMessage"); - } catch (Exception ex) { - logger.error("Failed to extract workflow exception message from WorkflowException",ex); - errorMsg = "Unexpected Error in BPMN."; + String rollbackErrorMsg = null; + boolean rollbackCompleted = (boolean) execution.getVariable("isRollbackComplete"); + boolean isRollbackFailure = (boolean) execution.getVariable("isRollback"); + + if(rollbackCompleted){ + rollbackErrorMsg = "Rollback has been completed successfully."; + request.setRollbackStatusMessage(rollbackErrorMsg); + logger.debug("Updating RequestDB to failed: Rollback has been completed successfully"); + }else{ + if(isRollbackFailure){ + rollbackErrorMsg = retrieveErrorMessage(execution); + if(rollbackErrorMsg == null || rollbackErrorMsg.equals("")){ + rollbackErrorMsg = "Failed to determine rollback error message."; + } + request.setRollbackStatusMessage(rollbackErrorMsg); + logger.debug("Updating RequestDB to failed: rollbackErrorMsg = " + rollbackErrorMsg); + }else{ + errorMsg = retrieveErrorMessage(execution); + if(errorMsg == null || errorMsg.equals("")){ + errorMsg = "Failed to determine error message"; + } + request.setStatusMessage(errorMsg); + logger.debug("Updating RequestDB to failed: errorMsg = " + errorMsg); } } - if(rollback){ - errorMsg = errorMsg + " + Rollback has been completed successfully."; - } request.setProgress(Long.valueOf(100)); - request.setStatusMessage(errorMsg); request.setRequestStatus("FAILED"); request.setLastModifiedBy("CamundaBPMN"); requestDbclient.updateInfraActiveRequests(request); @@ -322,6 +335,29 @@ public class WorkflowActionBBTasks { } } + private String retrieveErrorMessage (DelegateExecution execution){ + String errorMsg = ""; + try { + WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException"); + if(exception != null && (exception.getErrorMessage()!=null || !exception.getErrorMessage().equals(""))){ + errorMsg = exception.getErrorMessage(); + } + } catch (Exception ex) { + //log error and attempt to extact WorkflowExceptionMessage + logger.error("Failed to extract workflow exception from execution.",ex); + } + + if (errorMsg == null){ + try { + errorMsg = (String) execution.getVariable("WorkflowExceptionErrorMessage"); + } catch (Exception ex) { + logger.error("Failed to extract workflow exception message from WorkflowException",ex); + errorMsg = "Unexpected Error in BPMN."; + } + } + return errorMsg; + } + public void updateRequestStatusToFailedWithRollback(DelegateExecution execution) { execution.setVariable("isRollbackComplete", true); updateRequestStatusToFailed(execution); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/SDNCConfigurationResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/SDNCConfigurationResources.java index 5e3e23e2d0..9dc03ecb88 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/SDNCConfigurationResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/SDNCConfigurationResources.java @@ -35,96 +35,89 @@ import org.onap.so.client.sdnc.mapper.GCTopologyOperationRequestMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.net.URI; + import org.onap.sdnc.northbound.client.model.GenericResourceApiGcTopologyOperationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration; @Component public class SDNCConfigurationResources { - @Autowired - private GCTopologyOperationRequestMapper sdncRM; - - @Autowired - private SDNCClient sdncClient; - - /** - * SDN-C call to assign configuration after it was created in A&AI - * - * @param serviceInstance - * @param requestContext - * @param vnrConfiguration - * @param voiceVnf - * @return - * @throws MapperException - * @throws BadResponseException - */ - public String assignVnrConfiguration(ServiceInstance serviceInstance, - RequestContext requestContext, - Customer customer, - Configuration vnrConfiguration, - GenericVnf voiceVnf) - throws MapperException, BadResponseException { - GenericResourceApiGcTopologyOperationInformation sdncReq = sdncRM.assignOrActivateVnrReqMapper( - SDNCSvcAction.ASSIGN, - GenericResourceApiRequestActionEnumeration.CREATEGENERICCONFIGURATIONINSTANCE , - serviceInstance , requestContext, customer, vnrConfiguration,voiceVnf); - return sdncClient.post(sdncReq, SDNCTopology.CONFIGURATION); - } - - /** - * SDNC Call to Activate VNR Configuration - * - * @param serviceInstance - * @param requestContext - * @param vnrConfiguration - * @param voiceVnf - * @return - * @throws MapperException - * @throws BadResponseException - */ - public String activateVnrConfiguration(ServiceInstance serviceInstance, - RequestContext requestContext, - Customer customer, - Configuration vnrConfiguration, - GenericVnf voiceVnf) - throws MapperException, BadResponseException { + @Autowired + private GCTopologyOperationRequestMapper sdncRM; - GenericResourceApiGcTopologyOperationInformation sdncReq = sdncRM.assignOrActivateVnrReqMapper( - SDNCSvcAction.ACTIVATE, - GenericResourceApiRequestActionEnumeration.CREATEGENERICCONFIGURATIONINSTANCE , - serviceInstance , requestContext, customer, vnrConfiguration, voiceVnf); - return sdncClient.post(sdncReq, SDNCTopology.CONFIGURATION); - } + /** + * SDN-C call to assign configuration after it was created in A&AI + * + * @param serviceInstance + * @param requestContext + * @param vnrConfiguration + * @param voiceVnf + * @return + * @throws MapperException + * @throws BadResponseException + */ + public GenericResourceApiGcTopologyOperationInformation assignVnrConfiguration(ServiceInstance serviceInstance, + RequestContext requestContext, + Customer customer, + Configuration vnrConfiguration, + GenericVnf voiceVnf, String sdncRequestId, URI callbackUri) + throws MapperException, BadResponseException { + return sdncRM.assignOrActivateVnrReqMapper( + SDNCSvcAction.ASSIGN, + GenericResourceApiRequestActionEnumeration.CREATEGENERICCONFIGURATIONINSTANCE , + serviceInstance , requestContext, customer, vnrConfiguration,voiceVnf,sdncRequestId,callbackUri); + } - /** - * method to unAssign Vnr Configuration in SDNC - * - * @param serviceInstance - * @param requestContext - * @param vnrConfiguration - * @return - * @throws BadResponseException - * @throws MapperException - */ - public String unAssignVnrConfiguration(ServiceInstance serviceInstance, RequestContext requestContext, - Configuration vnrConfiguration) throws BadResponseException, MapperException { + /** + * SDNC Call to Activate VNR Configuration + * + * @param serviceInstance + * @param requestContext + * @param vnrConfiguration + * @param voiceVnf + * @return + * @throws MapperException + * @throws BadResponseException + */ + public GenericResourceApiGcTopologyOperationInformation activateVnrConfiguration(ServiceInstance serviceInstance, + RequestContext requestContext, + Customer customer, + Configuration vnrConfiguration, + GenericVnf voiceVnf, String sdncRequestId, URI callbackUri) + throws MapperException, BadResponseException { + return sdncRM.assignOrActivateVnrReqMapper( + SDNCSvcAction.ACTIVATE, + GenericResourceApiRequestActionEnumeration.CREATEGENERICCONFIGURATIONINSTANCE, + serviceInstance , requestContext, customer, vnrConfiguration, voiceVnf,sdncRequestId,callbackUri); + } - GenericResourceApiGcTopologyOperationInformation sdncReq = sdncRM.deactivateOrUnassignVnrReqMapper - (SDNCSvcAction.UNASSIGN,serviceInstance, requestContext, vnrConfiguration); - return sdncClient.post(sdncReq, SDNCTopology.CONFIGURATION); - } + /** + * method to unAssign Vnr Configuration in SDNC + * + * @param serviceInstance + * @param requestContext + * @param vnrConfiguration + * @return + * @throws BadResponseException + * @throws MapperException + */ + public GenericResourceApiGcTopologyOperationInformation unAssignVnrConfiguration(ServiceInstance serviceInstance, RequestContext requestContext, + Configuration vnrConfiguration, String sdncRequestId, URI callbackUri) throws BadResponseException, MapperException { + return sdncRM.deactivateOrUnassignVnrReqMapper + (SDNCSvcAction.UNASSIGN,serviceInstance, requestContext, vnrConfiguration,sdncRequestId,callbackUri); + } - /*** - * Deactivate VNR SDNC Call - * @param serviceInstance - * @param requestContext - * @param vnrConfiguration - * @throws BadResponseException - * @throws MapperException - */ - public String deactivateVnrConfiguration(ServiceInstance serviceInstance, RequestContext requestContext, Configuration vnrConfiguration) throws BadResponseException, MapperException { - GenericResourceApiGcTopologyOperationInformation sdncReq = sdncRM.deactivateOrUnassignVnrReqMapper( - SDNCSvcAction.DEACTIVATE, - serviceInstance , requestContext, vnrConfiguration); - return sdncClient.post(sdncReq, SDNCTopology.CONFIGURATION); - } + /*** + * Deactivate VNR SDNC Call + * @param serviceInstance + * @param requestContext + * @param vnrConfiguration + * @throws BadResponseException + * @throws MapperException + */ + public GenericResourceApiGcTopologyOperationInformation deactivateVnrConfiguration(ServiceInstance serviceInstance, RequestContext requestContext, Configuration vnrConfiguration, String sdncRequestId, URI callbackUri) throws BadResponseException, MapperException { + return sdncRM.deactivateOrUnassignVnrReqMapper( + SDNCSvcAction.DEACTIVATE, + serviceInstance , requestContext, vnrConfiguration,sdncRequestId,callbackUri); + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SDNCClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SDNCClient.java index 67843a7ef9..7d92a5304a 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SDNCClient.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SDNCClient.java @@ -43,7 +43,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class SDNCClient { private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, SDNCClient.class); - private BaseClient<String, LinkedHashMap<?, ?>> STOClient = new BaseClient<>(); + private BaseClient<String, LinkedHashMap<String, Object>> STOClient = new BaseClient<>(); @Autowired private SDNCProperties properties; @@ -64,9 +64,20 @@ public class SDNCClient { STOClient.setTargetUrl(targetUrl); HttpHeaders httpHeader = sdnCommonTasks.getHttpHeaders(properties.getAuth()); STOClient.setHttpHeader(httpHeader); - LinkedHashMap<?, ?> output = STOClient.post(jsonRequest, new ParameterizedTypeReference<LinkedHashMap<? ,?>>() {}); + LinkedHashMap<String, Object> output = STOClient.post(jsonRequest, new ParameterizedTypeReference<LinkedHashMap<String, Object>>() {}); return sdnCommonTasks.validateSDNResponse(output); } + + + public String post(Object request, String url) throws MapperException, BadResponseException { + String jsonRequest = sdnCommonTasks.buildJsonRequest(request); + STOClient.setTargetUrl(url); + HttpHeaders httpHeader = sdnCommonTasks.getHttpHeaders(properties.getAuth()); + STOClient.setHttpHeader(httpHeader); + LinkedHashMap<String, Object> output = STOClient.post(jsonRequest, new ParameterizedTypeReference<LinkedHashMap<String, Object>>() {}); + return sdnCommonTasks.validateSDNResponse(output); +} + /** * @@ -86,7 +97,7 @@ public class SDNCClient { STOClient.setTargetUrl(targetUrl); HttpHeaders httpHeader = sdnCommonTasks.getHttpHeaders(properties.getAuth()); STOClient.setHttpHeader(httpHeader); - LinkedHashMap<?, ?> output = STOClient.get(jsonRequest, new ParameterizedTypeReference<LinkedHashMap<? ,?>>() {}); + LinkedHashMap<String, Object> output = STOClient.get(jsonRequest, new ParameterizedTypeReference<LinkedHashMap<String, Object>>() {}); return sdnCommonTasks.validateSDNGetResponse(output); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SdnCommonTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SdnCommonTasks.java index ee1d432b6f..37e13fb8d8 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SdnCommonTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SdnCommonTasks.java @@ -92,13 +92,13 @@ public class SdnCommonTasks { * @return * @throws BadResponseException */ - public String validateSDNResponse(LinkedHashMap<?, ?> output) throws BadResponseException { + public String validateSDNResponse(LinkedHashMap<String, Object> output) throws BadResponseException { if (CollectionUtils.isEmpty(output)) { msoLogger.error(MessageEnum.RA_RESPONSE_FROM_SDNC, NO_RESPONSE_FROM_SDNC, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, NO_RESPONSE_FROM_SDNC); throw new BadResponseException(NO_RESPONSE_FROM_SDNC); } - LinkedHashMap<?, ?> embeddedResponse =(LinkedHashMap<?, ?>) output.get("output"); + LinkedHashMap<String, Object> embeddedResponse =(LinkedHashMap<String, Object>) output.get("output"); String responseCode = ""; String responseMessage = ""; if (embeddedResponse != null) { @@ -125,7 +125,7 @@ public class SdnCommonTasks { * @return * @throws BadResponseException */ - public String validateSDNGetResponse(LinkedHashMap<?, ?> output) throws BadResponseException { + public String validateSDNGetResponse(LinkedHashMap<String, Object> output) throws BadResponseException { if (CollectionUtils.isEmpty(output)) { msoLogger.error(MessageEnum.RA_RESPONSE_FROM_SDNC, NO_RESPONSE_FROM_SDNC, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, NO_RESPONSE_FROM_SDNC); throw new BadResponseException(NO_RESPONSE_FROM_SDNC); @@ -143,6 +143,7 @@ public class SdnCommonTasks { msoLogger.debug("Received from GET request: " + stringOutput); return stringOutput; } + private boolean isHttpCodeSuccess(int code) { return code >= HttpStatus.SC_OK && code < HttpStatus.SC_MULTIPLE_CHOICES || code == 0; diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/beans/SDNCRequest.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/beans/SDNCRequest.java new file mode 100644 index 0000000000..3ee560f4f4 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/beans/SDNCRequest.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.client.sdnc.beans; + +import java.io.Serializable; +import java.time.Duration; +import java.util.UUID; + +import org.onap.so.client.sdnc.endpoint.SDNCTopology; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.EqualsBuilder; + +public class SDNCRequest implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 4679678988657593282L; + private String timeOut = "PT1H"; + private SDNCTopology topology; + private String CorrelationValue = UUID.randomUUID().toString(); + private String CorrelationName = "SDNCCallback"; + private Object SDNCPayload; + + + public String getTimeOut() { + return timeOut; + } + + public void setTimeOut(String timeOut) { + this.timeOut = timeOut; + } + + public SDNCTopology getTopology() { + return topology; + } + + public void setTopology(SDNCTopology topology) { + this.topology = topology; + } + + public String getCorrelationValue() { + return CorrelationValue; + } + public void setCorrelationValue(String correlationValue) { + CorrelationValue = correlationValue; + } + public String getCorrelationName() { + return CorrelationName; + } + public void setCorrelationName(String correlationName) { + CorrelationName = correlationName; + } + public Object getSDNCPayload() { + return SDNCPayload; + } + public void setSDNCPayload(Object sDNCPayload) { + SDNCPayload = sDNCPayload; + } + + @Override + public boolean equals(final Object other) { + if (!(other instanceof SDNCRequest)) { + return false; + } + SDNCRequest castOther = (SDNCRequest) other; + return new EqualsBuilder().append(CorrelationValue, castOther.CorrelationValue) + .append(CorrelationName, castOther.CorrelationName).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(CorrelationValue).append(CorrelationName).toHashCode(); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapper.java index 76a947a299..2cd0947fa8 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapper.java @@ -20,6 +20,8 @@ package org.onap.so.client.sdnc.mapper; +import java.net.URI; + import org.onap.sdnc.northbound.client.model.*; import org.onap.so.bpmn.servicedecomposition.bbobjects.*; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; @@ -37,11 +39,10 @@ public class GCTopologyOperationRequestMapper { RequestContext requestContext, Customer customer, Configuration vnrConfiguration, - GenericVnf voiceVnf) { + GenericVnf voiceVnf, String sdncReqId,URI callbackUri) { GenericResourceApiGcTopologyOperationInformation req = new GenericResourceApiGcTopologyOperationInformation(); - String sdncReqId = requestContext.getMsoRequestId(); - GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = generalTopologyObjectMapper.buildSdncRequestHeader(svcAction, sdncReqId);// TODO Set URL + GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = generalTopologyObjectMapper.buildSdncRequestHeader(svcAction, sdncReqId,callbackUri.toString()); GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper.buildGenericResourceApiRequestinformationRequestInformation(sdncReqId, reqAction); GenericResourceApiServiceinformationServiceInformation serviceInformation = generalTopologyObjectMapper.buildServiceInformation(serviceInstance, requestContext, customer, false); GenericResourceApiConfigurationinformationConfigurationInformation configurationInformation = generalTopologyObjectMapper.buildConfigurationInformation(vnrConfiguration,true); @@ -60,12 +61,11 @@ public class GCTopologyOperationRequestMapper { public GenericResourceApiGcTopologyOperationInformation deactivateOrUnassignVnrReqMapper(SDNCSvcAction svcAction, ServiceInstance serviceInstance, RequestContext requestContext, - Configuration vnrConfiguration) { + Configuration vnrConfiguration, String sdncReqId, URI callbackUri) { - GenericResourceApiGcTopologyOperationInformation req = new GenericResourceApiGcTopologyOperationInformation(); - String sdncReqId = requestContext.getMsoRequestId(); + GenericResourceApiGcTopologyOperationInformation req = new GenericResourceApiGcTopologyOperationInformation(); GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = - generalTopologyObjectMapper.buildSdncRequestHeader(svcAction, sdncReqId);// TODO Set URL + generalTopologyObjectMapper.buildSdncRequestHeader(svcAction, sdncReqId,callbackUri.toString()); GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper .buildGenericResourceApiRequestinformationRequestInformation(sdncReqId, GenericResourceApiRequestActionEnumeration.DELETEGENERICCONFIGURATIONINSTANCE); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GeneralTopologyObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GeneralTopologyObjectMapper.java index 3975b25356..9bbd665e4c 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GeneralTopologyObjectMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GeneralTopologyObjectMapper.java @@ -24,11 +24,14 @@ import org.onap.sdnc.northbound.client.model.*; import org.onap.so.bpmn.servicedecomposition.bbobjects.*; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; import org.onap.so.client.sdnc.beans.SDNCSvcAction; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import org.onap.so.client.exception.MapperException; @Component public class GeneralTopologyObjectMapper { + /* * Build GenericResourceApiRequestinformationRequestInformation @@ -135,10 +138,17 @@ public class GeneralTopologyObjectMapper { vfModuleInformation.setFromPreload(null); return vfModuleInformation; } + + public GenericResourceApiSdncrequestheaderSdncRequestHeader buildSdncRequestHeader(SDNCSvcAction svcAction, String sdncReqId){ + return buildSdncRequestHeader(svcAction, sdncReqId, null); + } + + public GenericResourceApiSdncrequestheaderSdncRequestHeader buildSdncRequestHeader(SDNCSvcAction svcAction, String sdncReqId, String callbackUrl){ GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = new GenericResourceApiSdncrequestheaderSdncRequestHeader(); sdncRequestHeader.setSvcAction(svcAction.getSdncApiAction()); sdncRequestHeader.setSvcRequestId(sdncReqId); + sdncRequestHeader.setSvcNotificationUrl(callbackUrl); return sdncRequestHeader; } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroClient.java index eb12278528..7f09305d95 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroClient.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroClient.java @@ -72,12 +72,12 @@ public class SniroClient { header.set("X-patchVersion", managerProperties.getHeaders().get("patchVersion")); header.set("X-minorVersion", managerProperties.getHeaders().get("minorVersion")); header.set("X-latestVersion", managerProperties.getHeaders().get("latestVersion")); - BaseClient<String, LinkedHashMap<?, ?>> baseClient = new BaseClient<>(); + BaseClient<String, LinkedHashMap<String, Object>> baseClient = new BaseClient<>(); baseClient.setTargetUrl(url); baseClient.setHttpHeader(header); - LinkedHashMap<?, ?> response = baseClient.post(homingRequest.toJsonString(), new ParameterizedTypeReference<LinkedHashMap<? ,?>>() {}); + LinkedHashMap<String, Object> response = baseClient.post(homingRequest.toJsonString(), new ParameterizedTypeReference<LinkedHashMap<String, Object>>() {}); validator.validateDemandsResponse(response); log.trace("Completed Sniro Client Post Demands"); } @@ -102,12 +102,12 @@ public class SniroClient { HttpHeaders header = new HttpHeaders(); header.setContentType(MediaType.APPLICATION_JSON); header.set("Authorization", UrnPropertiesReader.getVariable("sniro.conductor.headers.auth")); - BaseClient<String, LinkedHashMap<?, ?>> baseClient = new BaseClient<>(); + BaseClient<String, LinkedHashMap<String, Object>> baseClient = new BaseClient<>(); baseClient.setTargetUrl(url); baseClient.setHttpHeader(header); - LinkedHashMap<?, ?> response = baseClient.post(releaseRequest.toJsonString(), new ParameterizedTypeReference<LinkedHashMap<? ,?>>() {}); + LinkedHashMap<String, Object> response = baseClient.post(releaseRequest.toJsonString(), new ParameterizedTypeReference<LinkedHashMap<String, Object>>() {}); SniroValidator v = new SniroValidator(); v.validateReleaseResponse(response); log.trace("Completed Sniro Client Post Release"); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroValidator.java index bad45c87f2..0d0c1be5aa 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroValidator.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroValidator.java @@ -43,7 +43,7 @@ public class SniroValidator { * * @throws BadResponseException */ - public void validateDemandsResponse(LinkedHashMap<?, ?> response) throws BadResponseException { + public void validateDemandsResponse(LinkedHashMap<String, Object> response) throws BadResponseException { log.debug("Validating Sniro Managers synchronous response"); if(!response.isEmpty()){ JSONObject jsonResponse = new JSONObject(response); @@ -105,7 +105,7 @@ public class SniroValidator { * * @throws BadResponseException */ - public void validateReleaseResponse(LinkedHashMap<?, ?> response) throws BadResponseException { + public void validateReleaseResponse(LinkedHashMap<String, Object> response) throws BadResponseException { log.debug("Validating Sniro Conductors response"); if(!response.isEmpty()){ String status = (String) response.get("status"); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/AllIntegrationTestSuites.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/AllIntegrationTestSuites.java new file mode 100644 index 0000000000..8a57d5d43a --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/AllIntegrationTestSuites.java @@ -0,0 +1,12 @@ +package org.onap.so; + +import org.junit.runner.RunWith; + +import com.googlecode.junittoolbox.SuiteClasses; +import com.googlecode.junittoolbox.WildcardPatternSuite; + +@RunWith(WildcardPatternSuite.class) +@SuiteClasses({"**/SniroHomingV2IT.class"}) +public class AllIntegrationTestSuites{ + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseIntegrationTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseIntegrationTest.java index 4bf6f0e185..6500e3a850 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseIntegrationTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseIntegrationTest.java @@ -22,13 +22,16 @@ package org.onap.so; import java.io.IOException; import java.io.InputStream; +import org.junit.Before; import org.junit.runner.RunWith; import org.onap.so.bpmn.buildingblock.SniroHomingV2; import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.client.appc.ApplicationControllerAction; import org.onap.so.client.orchestration.SDNOHealthCheckResources; import org.onap.so.client.sdnc.SDNCClient; +import org.onap.so.client.sniro.SniroClient; import org.onap.so.db.catalog.client.CatalogDbClient; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; @@ -37,29 +40,40 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; +import com.github.tomakehurst.wiremock.client.WireMock; + @RunWith(SpringRunner.class) @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("test") @ContextConfiguration @AutoConfigureWireMock(port = 0) public abstract class BaseIntegrationTest extends TestDataSetup { - + + @Value("${wiremock.server.port}") + protected String wireMockPort; + @SpyBean protected SDNCClient SPY_sdncClient; - + @SpyBean protected SDNOHealthCheckResources MOCK_sdnoHealthCheckResources; - @MockBean + @SpyBean protected SniroHomingV2 sniroHoming; - + + @SpyBean + protected SniroClient sniroClient; + @MockBean protected ApplicationControllerAction appCClient; - - + @MockBean protected CatalogDbClient catalogDbClient; - + + @Before + public void baseTestBefore() { + WireMock.reset(); + } public String readResourceFile(String fileName) { InputStream stream; try { @@ -73,7 +87,7 @@ public abstract class BaseIntegrationTest extends TestDataSetup { stream.close(); return ""; } - } catch (IOException e) { + } catch (IOException e) { return ""; } } @@ -85,7 +99,7 @@ public abstract class BaseIntegrationTest extends TestDataSetup { throw new IOException("Can't access resource '" + resourceName + "'"); } return stream; - } + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/IntegrationTestSuite.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/IntegrationTestSuite.java new file mode 100644 index 0000000000..ab999a9889 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/IntegrationTestSuite.java @@ -0,0 +1,12 @@ +package org.onap.so; + +import org.junit.runner.RunWith; + +import com.googlecode.junittoolbox.SuiteClasses; +import com.googlecode.junittoolbox.WildcardPatternSuite; + +@RunWith(WildcardPatternSuite.class) +@SuiteClasses({"**/*IT.class"}) +public class IntegrationTestSuite { + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/UnitTestSuite.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/UnitTestSuite.java new file mode 100644 index 0000000000..5ac9f229f6 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/UnitTestSuite.java @@ -0,0 +1,13 @@ +package org.onap.so; + + +import org.junit.runner.RunWith; + +import com.googlecode.junittoolbox.SuiteClasses; +import com.googlecode.junittoolbox.WildcardPatternSuite; + +@RunWith(WildcardPatternSuite.class) +@SuiteClasses({"**/*Test.class"}) +public class UnitTestSuite { + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java index 09ca0e543e..95201d555d 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java @@ -7,9 +7,9 @@ * 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. @@ -23,6 +23,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.buildingblock.SniroHomingV2; import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils; @@ -51,89 +52,92 @@ import org.onap.so.client.orchestration.SDNCVnfResources; import org.onap.so.client.orchestration.VnfAdapterVfModuleResources; import org.onap.so.client.orchestration.VnfAdapterVolumeGroupResources; import org.onap.so.client.sdnc.SDNCClient; +import org.onap.so.client.sniro.SniroClient; import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.client.RequestsDbClient; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; @RunWith(MockitoJUnitRunner.Silent.class) public abstract class BaseTaskTest extends TestDataSetup { @Mock protected AAIVolumeGroupResources aaiVolumeGroupResources; - + @Mock protected AAIServiceInstanceResources aaiServiceInstanceResources; - + @Mock protected AAIVnfResources aaiVnfResources; - + @Mock protected AAIVfModuleResources aaiVfModuleResources; - + @Mock protected AAIVpnBindingResources aaiVpnBindingResources; - + @Mock protected AAINetworkResources aaiNetworkResources; - + @Mock protected AAICollectionResources aaiCollectionResources; - + @Mock protected NetworkAdapterResources networkAdapterResources; - + @Mock protected VnfAdapterVolumeGroupResources vnfAdapterVolumeGroupResources; - + @Mock protected VnfAdapterVfModuleResources vnfAdapterVfModuleResources; - + @Mock protected SDNCVnfResources sdncVnfResources; - + @Mock protected SDNCNetworkResources sdncNetworkResources; - + @Mock protected SDNCVfModuleResources sdncVfModuleResources; - + @Mock protected SDNCServiceInstanceResources sdncServiceInstanceResources; - + @Mock protected AssignNetworkBBUtils assignNetworkBBUtils; - + @Mock protected NetworkAdapterObjectMapper networkAdapterObjectMapper; - + @Mock protected AAIInstanceGroupResources aaiInstanceGroupResources; - + @Mock protected ApplicationControllerAction appCClient; - + @Mock protected CatalogDbClient catalogDbClient; - + @Mock protected RequestsDbClient requestsDbClient; - + @Mock protected BBInputSetupUtils bbSetupUtils; - + @Mock protected BBInputSetup bbInputSetup; @Mock protected AAIConfigurationResources aaiConfigurationResources; - + @Mock protected AAIObjectMapper MOCK_aaiObjectMapper; @Mock protected InjectionHelper MOCK_injectionHelper; - + @Mock - protected AAIResourcesClient MOCK_aaiResourcesClient; + protected AAIResourcesClient MOCK_aaiResourcesClient; @Mock protected ExtractPojosForBB extractPojosForBB; @@ -141,4 +145,5 @@ public abstract class BaseTaskTest extends TestDataSetup { @Mock protected ExceptionBuilder exceptionUtil; + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java index 1901a08f28..c96c38dab1 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java @@ -478,6 +478,8 @@ public class TestDataSetup{ modelInfoGenericVnf.setModelInvariantUuid("testModelInvariantUUID" + genericVnfCounter); modelInfoGenericVnf.setModelVersion("testModelVersion" + genericVnfCounter); modelInfoGenericVnf.setModelUuid("testModelUUID" + genericVnfCounter); + modelInfoGenericVnf.setModelInstanceName("testInstanceName" + genericVnfCounter); + genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf); License license = new License(); @@ -652,6 +654,7 @@ public class TestDataSetup{ modelInfo.setModelName("testProxyModelName" + uniqueIdentifier); modelInfo.setModelUuid("testProxyModelUuid" + uniqueIdentifier); modelInfo.setModelVersion("testProxyModelVersion" + uniqueIdentifier); + modelInfo.setModelInstanceName("testProxyInstanceName" + uniqueIdentifier); serviceProxy.setModelInfoServiceProxy(modelInfo); @@ -663,10 +666,11 @@ public class TestDataSetup{ ar.setId("testAllottedResourceId" + uniqueIdentifier); ModelInfoAllottedResource modelInfo = new ModelInfoAllottedResource(); - modelInfo.setModelInvariantUuid("testProxyModelInvariantUuid" + uniqueIdentifier); - modelInfo.setModelName("testProxyModelName" + uniqueIdentifier); - modelInfo.setModelUuid("testProxyModelUuid" + uniqueIdentifier); - modelInfo.setModelVersion("testProxyModelVersion" + uniqueIdentifier); + modelInfo.setModelInvariantUuid("testAllottedModelInvariantUuid" + uniqueIdentifier); + modelInfo.setModelName("testAllottedModelName" + uniqueIdentifier); + modelInfo.setModelUuid("testAllottedModelUuid" + uniqueIdentifier); + modelInfo.setModelVersion("testAllottedModelVersion" + uniqueIdentifier); + modelInfo.setModelInstanceName("testAllottedModelInstanceName" + uniqueIdentifier); ar.setModelInfoAllottedResource(modelInfo); @@ -688,7 +692,7 @@ public class TestDataSetup{ serviceInstance.setConfigurations(configurations); return config; } - + public Subnet buildSubnet() { Subnet subnet = new Subnet(); subnet.setSubnetId("testSubnetId"); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java index 52a64f4863..bf66283b17 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java @@ -35,6 +35,7 @@ import static org.mockito.Mockito.when; import java.util.HashMap; import org.camunda.bpm.engine.delegate.BpmnError; +import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatchers; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksITTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksIT.java index 942553b1dc..9cf1a1cdc9 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksITTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksIT.java @@ -39,7 +39,7 @@ import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; import org.onap.so.db.catalog.beans.ControllerSelectionReference; import org.springframework.beans.factory.annotation.Autowired; -public class AppcRunTasksITTest extends BaseIntegrationTest { +public class AppcRunTasksIT extends BaseIntegrationTest { @Autowired private AppcRunTasks appcRunTasks; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2Test.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java index 73e7215fc6..f0bb6a369c 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2Test.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java @@ -58,8 +58,7 @@ import org.onap.so.BaseIntegrationTest; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -@Ignore -public class SniroHomingV2Test extends BaseIntegrationTest{ +public class SniroHomingV2IT extends BaseIntegrationTest{ private ServiceInstance serviceInstance; @@ -72,7 +71,7 @@ public class SniroHomingV2Test extends BaseIntegrationTest{ String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}"; -/** + @Before public void before() { serviceInstance = setServiceInstance(); @@ -493,5 +492,5 @@ public class SniroHomingV2Test extends BaseIntegrationTest{ verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class)); } -**/ + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java index 4ba6339f0a..4c5c50ebbf 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java @@ -40,6 +40,7 @@ import org.mockito.InjectMocks; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.client.exception.BBObjectNotFoundException; @@ -51,15 +52,19 @@ public class SDNCQueryTasksTest extends BaseTaskTest{ @Rule public ExpectedException expectedException = ExpectedException.none(); + private ServiceInstance serviceInstance; private GenericVnf genericVnf; private VfModule vfModule; @Before public void before() throws BBObjectNotFoundException { + serviceInstance = setServiceInstance(); genericVnf = setGenericVnf(); vfModule = setVfModule(); doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class)); + when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID), any())).thenReturn(serviceInstance); + when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf); when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java new file mode 100644 index 0000000000..a6efbd5989 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java @@ -0,0 +1,170 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.sdnc.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; + +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.exception.MapperException; +import org.onap.so.client.sdnc.SDNCClient; +import org.onap.so.client.sdnc.beans.SDNCRequest; +import org.onap.so.client.sdnc.endpoint.SDNCTopology; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(MockitoJUnitRunner.class) +public class SDNCRequestTasksTest extends SDNCRequestTasks{ + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @InjectMocks + SDNCRequestTasks sndcRequestTasks = new SDNCRequestTasks(); + + @Mock + SDNCClient sdncClient; + + @Spy + private ExceptionBuilder exceptionBuilder; + + protected DelegateExecution delegateExecution; + + + @Before + public void setup(){ + delegateExecution = new DelegateExecutionFake(); + delegateExecution.setVariable("SDNCRequest", createSDNCRequest()); + } + + @Test + public void createCorrelationVariables_Test(){ + sndcRequestTasks.createCorrelationVariables(delegateExecution); + assertEquals("correlationValue",delegateExecution.getVariable("correlationName_CORRELATOR")); + } + + @Test + public void callSDNC_Final_Test() throws MapperException, BadResponseException, IOException{ + final String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNCClientPut200Response.json"))); + doReturn(sdncResponse).when(sdncClient).post(createSDNCRequest().getSDNCPayload(),SDNCTopology.CONFIGURATION); + sndcRequestTasks.callSDNC(delegateExecution); + assertEquals(true,delegateExecution.getVariable("isSDNCCompleted")); + } + + @Test + public void callSDNC_Not_Final_Test() throws MapperException, BadResponseException, IOException{ + final String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNCClientPut200ResponseNotFinal.json"))); + doReturn(sdncResponse).when(sdncClient).post(createSDNCRequest().getSDNCPayload(),SDNCTopology.CONFIGURATION); + sndcRequestTasks.callSDNC(delegateExecution); + assertEquals(false,delegateExecution.getVariable("isSDNCCompleted")); + } + + @Test + public void callSDNC_Error_Test() throws MapperException, BadResponseException{ + doThrow(MapperException.class).when(sdncClient).post(createSDNCRequest().getSDNCPayload(),SDNCTopology.CONFIGURATION); + doReturn("processKey").when(exceptionBuilder).getProcessKey(delegateExecution); + expectedException.expect(BpmnError.class); + sndcRequestTasks.callSDNC(delegateExecution); + } + + @Test + public void convertIndicatorToBoolean_True_Test() throws MapperException, BadResponseException{ + boolean testValue = sndcRequestTasks.convertIndicatorToBoolean("Y"); + assertEquals(true,testValue); + } + + @Test + public void convertIndicatorToBoolean_False_Test() throws MapperException, BadResponseException{ + boolean testValue = sndcRequestTasks.convertIndicatorToBoolean("N"); + assertEquals(false,testValue); + } + + @Test + public void HandleTimeout_Test() throws MapperException, BadResponseException{ + doReturn("processKey").when(exceptionBuilder).getProcessKey(delegateExecution); + expectedException.expect(BpmnError.class); + sndcRequestTasks.handleTimeOutException(delegateExecution); + } + + + @Test + public void HandleSyncError_Test() throws MapperException, BadResponseException{ + delegateExecution.setVariable("SDNCSyncError", "Error in SDNC Request"); + doReturn("processKey").when(exceptionBuilder).getProcessKey(delegateExecution); + expectedException.expect(BpmnError.class); + sndcRequestTasks.handleSyncError(delegateExecution); + } + + @Test + public void processCallBack_Final_Test() throws MapperException, BadResponseException, IOException{ + final String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNC_ASYNC_Request.json"))); + delegateExecution.setVariable("correlationName_MESSAGE", sdncResponse); + sndcRequestTasks.processCallback(delegateExecution); + assertEquals(true,delegateExecution.getVariable(IS_CALLBACK_COMPLETED)); + } + + public SDNCRequest createSDNCRequest(){ + SDNCRequest request = new SDNCRequest(); + request.setCorrelationName("correlationName"); + request.setCorrelationValue("correlationValue"); + request.setTopology(SDNCTopology.CONFIGURATION); + ObjectMapper mapper = new ObjectMapper(); + try { + GenericResourceApiServiceOperationInformation sdncReq = + mapper.readValue(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNC_Client_Request.json")), GenericResourceApiServiceOperationInformation.class); + request.setSDNCPayload(sdncReq); + } catch (JsonParseException e) { + + } catch (JsonMappingException e) { + + } catch (IOException e) { + + } + + return request; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java index 8a2230feb5..b0a80ebc72 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java @@ -25,27 +25,23 @@ import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.isA; import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.List; -import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Spy; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; -import org.onap.so.db.request.beans.InfraActiveRequests; -import org.springframework.beans.factory.annotation.Autowired; public class WorkflowActionBBTasksTest extends BaseTaskTest { @@ -53,6 +49,7 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { protected WorkflowAction workflowAction; @InjectMocks + @Spy protected WorkflowActionBBTasks workflowActionBBTasks; private DelegateExecution execution; @@ -88,32 +85,6 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { } @Test - public void getUpdatedRequestTest() throws Exception{ - List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); - ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); - BuildingBlock bb1 = new BuildingBlock(); - bb1.setBpmnFlowName("CreateNetworkBB"); - flowsToExecute.add(ebb1); - ebb1.setBuildingBlock(bb1); - ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock(); - BuildingBlock bb2 = new BuildingBlock(); - bb2.setBpmnFlowName("ActivateNetworkBB"); - flowsToExecute.add(ebb2); - ebb2.setBuildingBlock(bb2); - String requestId = "requestId"; - execution.setVariable("mso-request-id", requestId); - execution.setVariable("flowsToExecute", flowsToExecute); - int currentSequence = 2; - String expectedStatusMessage = "Execution of CreateNetworkBB has completed successfully, next invoking ActivateNetworkBB (Execution Path progress: BBs completed = 1; BBs remaining = 1)."; - Long expectedLong = new Long(52); - InfraActiveRequests mockedRequest = new InfraActiveRequests(); - when(requestsDbClient.getInfraActiveRequestbyRequestId(requestId)).thenReturn(mockedRequest); - InfraActiveRequests actual = workflowActionBBTasks.getUpdatedRequest(execution, currentSequence); - assertEquals(expectedStatusMessage, actual.getStatusMessage()); - assertEquals(expectedLong, actual.getProgress()); - } - - @Test public void select2BBTest() throws Exception{ String gAction = "Delete-Network-Collection"; execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); @@ -146,17 +117,8 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { } @Test - public void setupFalloutHandlerTest(){ - execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); - execution.setVariable("serviceInstanceId", "123"); - execution.setVariable("WorkflowActionErrorMessage", "Error in WorkFlowAction"); - execution.setVariable("requestAction", "createInstance"); - workflowActionBBTasks.setupFalloutHandler(execution); - assertEquals(execution.getVariable("falloutRequest"),"<aetgt:FalloutHandlerRequest xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"xmlns:ns=\"http://org.onap/so/request/types/v1\"xmlns:wfsch=\"http://org.onap/so/workflow/schema/v1\"><request-info xmlns=\"http://org.onap/so/infra/vnf-request/v1\"><request-id>00f704ca-c5e5-4f95-a72c-6889db7b0688</request-id><action>createInstance</action><source>VID</source></request-info><aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>Error in WorkFlowAction</aetgt:ErrorMessage><aetgt:ErrorCode>7000</aetgt:ErrorCode></aetgt:WorkflowException></aetgt:FalloutHandlerRequest>"); - } - - @Test public void rollbackExecutionPathTest(){ + execution.setVariable("handlingCode", "Rollback"); execution.setVariable("isRollback", false); List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); @@ -177,7 +139,8 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("flowsToExecute", flowsToExecute); execution.setVariable("gCurrentSequence", 3); - + doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeactivateVfModuleBB"); @@ -188,6 +151,7 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { @Test public void rollbackExecutionPathUnfinishedFlowTest(){ + execution.setVariable("handlingCode", "Rollback"); execution.setVariable("isRollback", false); List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); @@ -208,7 +172,8 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("flowsToExecute", flowsToExecute); execution.setVariable("gCurrentSequence", 2); - + doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB"); @@ -219,6 +184,7 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { @Test public void rollbackExecutionTest(){ + execution.setVariable("handlingCode", "Rollback"); execution.setVariable("isRollback", false); List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); @@ -244,7 +210,8 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("flowsToExecute", flowsToExecute); execution.setVariable("gCurrentSequence", 3); - + doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"UnassignNetworkBB"); @@ -254,7 +221,44 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { } @Test + public void rollbackExecutionRollbackToAssignedTest(){ + execution.setVariable("isRollback", false); + execution.setVariable("handlingCode", "RollbackToAssigned"); + List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); + ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); + BuildingBlock bb1 = new BuildingBlock(); + bb1.setBpmnFlowName("AssignServiceInstanceBB"); + ebb1.setBuildingBlock(bb1); + flowsToExecute.add(ebb1); + ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock(); + BuildingBlock bb2 = new BuildingBlock(); + bb2.setBpmnFlowName("CreateNetworkCollectionBB"); + ebb2.setBuildingBlock(bb2); + flowsToExecute.add(ebb2); + ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock(); + BuildingBlock bb3 = new BuildingBlock(); + bb3.setBpmnFlowName("AssignNetworkBB"); + ebb3.setBuildingBlock(bb3); + flowsToExecute.add(ebb3); + ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock(); + BuildingBlock bb4 = new BuildingBlock(); + bb4.setBpmnFlowName("CreateNetworkBB"); + ebb4.setBuildingBlock(bb4); + flowsToExecute.add(ebb4); + + execution.setVariable("flowsToExecute", flowsToExecute); + execution.setVariable("gCurrentSequence", 3); + doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + + workflowActionBBTasks.rollbackExecutionPath(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkCollectionBB"); + assertEquals(0,execution.getVariable("gCurrentSequence")); + } + + @Test public void checkRetryStatusTest(){ + doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); execution.setVariable("handlingCode","Retry"); execution.setVariable("retryCount", 1); execution.setVariable("gCurrentSequence",1); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksUpdateReqDbTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksUpdateReqDbTest.java new file mode 100644 index 0000000000..1e2558b580 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksUpdateReqDbTest.java @@ -0,0 +1,74 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.InjectMocks; +import org.mockito.Spy; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.db.request.beans.InfraActiveRequests; + +public class WorkflowActionBBTasksUpdateReqDbTest extends BaseTaskTest{ + + protected WorkflowAction workflowAction = new WorkflowAction(); + + @Spy + @InjectMocks + protected WorkflowActionBBTasks workflowActionBBTasks; + + private DelegateExecution execution; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void before() throws Exception { + execution = new DelegateExecutionFake(); + org.onap.aai.domain.yang.ServiceInstance servInstance = new org.onap.aai.domain.yang.ServiceInstance(); + servInstance.setServiceInstanceId("TEST"); + when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), any())).thenReturn(servInstance); + workflowAction.setBbInputSetupUtils(bbSetupUtils); + workflowAction.setBbInputSetup(bbInputSetup); + } + + @Test + public void getUpdatedRequestTest() throws Exception{ + List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); + ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); + BuildingBlock bb1 = new BuildingBlock(); + bb1.setBpmnFlowName("CreateNetworkBB"); + flowsToExecute.add(ebb1); + ebb1.setBuildingBlock(bb1); + ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock(); + BuildingBlock bb2 = new BuildingBlock(); + bb2.setBpmnFlowName("ActivateNetworkBB"); + flowsToExecute.add(ebb2); + ebb2.setBuildingBlock(bb2); + String requestId = "requestId"; + execution.setVariable("mso-request-id", requestId); + execution.setVariable("flowsToExecute", flowsToExecute); + int currentSequence = 2; + String expectedStatusMessage = "Execution of CreateNetworkBB has completed successfully, next invoking ActivateNetworkBB (Execution Path progress: BBs completed = 1; BBs remaining = 1)."; + Long expectedLong = new Long(52); + InfraActiveRequests mockedRequest = new InfraActiveRequests(); + doReturn(mockedRequest).when(requestsDbClient).getInfraActiveRequestbyRequestId(isA(String.class)); + InfraActiveRequests actual = workflowActionBBTasks.getUpdatedRequest(execution, currentSequence); + assertEquals(expectedStatusMessage, actual.getStatusMessage()); + assertEquals(expectedLong, actual.getProgress()); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java index 9ca49788ae..a2880ce07f 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java @@ -25,11 +25,13 @@ import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.Assert.assertEquals; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.so.BaseIntegrationTest; import org.onap.so.adapters.nwrest.CreateNetworkError; import org.onap.so.adapters.nwrest.CreateNetworkRequest; import org.onap.so.adapters.nwrest.CreateNetworkResponse; @@ -44,12 +46,11 @@ import org.onap.so.adapters.nwrest.RollbackNetworkResponse; import org.onap.so.adapters.nwrest.UpdateNetworkError; import org.onap.so.adapters.nwrest.UpdateNetworkRequest; import org.onap.so.adapters.nwrest.UpdateNetworkResponse; -import org.onap.so.BaseIntegrationTest; +import org.onap.so.client.policy.JettisonStyleMapperProvider; import org.onap.so.openstack.beans.NetworkRollback; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import static com.github.tomakehurst.wiremock.client.WireMock.*; public class NetworkAdapterClientIT extends BaseIntegrationTest{ @@ -58,7 +59,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ private static final String REST_ENDPOINT = "/networks/rest/v1/networks"; private NetworkAdapterClientImpl client = new NetworkAdapterClientImpl(); - private ObjectMapper mapper = new ObjectMapper(); + private ObjectMapper mapper = new JettisonStyleMapperProvider().getMapper(); @BeforeClass public static void setUp() { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java index 0f9e11f354..3387920d40 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java @@ -31,6 +31,7 @@ import static org.junit.Assert.assertEquals; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.so.BaseIntegrationTest; import org.onap.so.adapters.vnfrest.CreateVfModuleRequest; import org.onap.so.adapters.vnfrest.CreateVfModuleResponse; import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest; @@ -42,7 +43,8 @@ import org.onap.so.adapters.vnfrest.UpdateVfModuleRequest; import org.onap.so.adapters.vnfrest.UpdateVfModuleResponse; import org.onap.so.adapters.vnfrest.VfModuleExceptionResponse; import org.onap.so.adapters.vnfrest.VfModuleRollback; -import org.onap.so.BaseIntegrationTest; +import org.onap.so.client.policy.JettisonStyleMapperProvider; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -54,7 +56,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ private static final String REST_ENDPOINT = "/services/rest/v1/vnfs"; private VnfAdapterClientImpl client = new VnfAdapterClientImpl(); - private ObjectMapper mapper = new ObjectMapper(); + private ObjectMapper mapper = new JettisonStyleMapperProvider().getMapper(); @BeforeClass public static void setUp() { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/oof/OofClientTestIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/oof/OofClientTestIT.java index 149417d89b..0b33b1d187 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/oof/OofClientTestIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/oof/OofClientTestIT.java @@ -20,20 +20,21 @@ package org.onap.so.client.oof; -import com.fasterxml.jackson.core.JsonProcessingException; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; + import org.junit.Test; +import org.onap.so.BaseIntegrationTest; import org.onap.so.client.exception.BadResponseException; -import org.onap.so.client.oof.OofClient; import org.onap.so.client.oof.beans.OofRequest; import org.springframework.beans.factory.annotation.Autowired; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import com.fasterxml.jackson.core.JsonProcessingException; -public class OofClientTestIT { +public class OofClientTestIT extends BaseIntegrationTest { @Autowired private OofClient client; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCConfigurationResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCConfigurationResourcesTest.java index 8bb46d80d7..4d90a3fcc9 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCConfigurationResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCConfigurationResourcesTest.java @@ -27,11 +27,15 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import java.net.URI; +import java.net.URISyntaxException; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.bpmn.common.data.TestDataSetup; @@ -68,49 +72,34 @@ public class SDNCConfigurationResourcesTest extends TestDataSetup{ @Before public void setUp(){ - customer = buildCustomer(); - requestContext = buildRequestContext(); - serviceInstance = buildServiceInstance(); - - vpnBondingLink = buildVpnBondingLink(); - + vpnBondingLink = buildVpnBondingLink(); vnf = vpnBondingLink.getInfrastructureServiceProxy().getServiceInstance().getVnfs().get(0); } @Test - public void activateVnrConfigurationTest() throws BadResponseException, MapperException { - - doReturn("success").when(MOCK_sdncClient).post(isA(GenericResourceApiGcTopologyOperationInformation.class), isA(SDNCTopology.class)); - String response = sdncConfigurationResources.activateVnrConfiguration(serviceInstance,requestContext,customer,vpnBondingLink.getVnrConfiguration(),vnf); - verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiGcTopologyOperationInformation.class), any(SDNCTopology.class)); + public void activateVnrConfigurationTest() throws BadResponseException, MapperException, URISyntaxException { + GenericResourceApiGcTopologyOperationInformation response = sdncConfigurationResources.activateVnrConfiguration(serviceInstance,requestContext,customer,vpnBondingLink.getVnrConfiguration(),vnf,"uuid",new URI("http://localhost")); assertNotNull(response); } @Test - public void assignVnrConfigurationTest() throws BadResponseException, MapperException { - - doReturn("success").when(MOCK_sdncClient).post(isA(GenericResourceApiGcTopologyOperationInformation.class), isA(SDNCTopology.class)); - String response = sdncConfigurationResources.assignVnrConfiguration(serviceInstance,requestContext,customer,vpnBondingLink.getVnrConfiguration(),vnf); - verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiGcTopologyOperationInformation.class), any(SDNCTopology.class)); + public void assignVnrConfigurationTest() throws BadResponseException, MapperException, URISyntaxException { + GenericResourceApiGcTopologyOperationInformation response = sdncConfigurationResources.assignVnrConfiguration(serviceInstance,requestContext,customer,vpnBondingLink.getVnrConfiguration(),vnf,"uuid",new URI("http://localhost")); assertNotNull(response); } @Test - public void unAssignVnrConfigurationTest() throws BadResponseException, MapperException { - doReturn("success").when(MOCK_sdncClient).post(isA(GenericResourceApiGcTopologyOperationInformation.class), isA(SDNCTopology.class)); - String response = sdncConfigurationResources.unAssignVnrConfiguration(serviceInstance,requestContext,vpnBondingLink.getVnrConfiguration()); - verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiGcTopologyOperationInformation.class), any(SDNCTopology.class)); + public void unAssignVnrConfigurationTest() throws BadResponseException, MapperException , URISyntaxException{ + GenericResourceApiGcTopologyOperationInformation response = sdncConfigurationResources.unAssignVnrConfiguration(serviceInstance,requestContext,vpnBondingLink.getVnrConfiguration(),"uuid",new URI("http://localhost")); assertNotNull(response); } @Test - public void deactivateVnrConfigurationTest() throws BadResponseException, MapperException { - doReturn("success").when(MOCK_sdncClient).post(isA(GenericResourceApiGcTopologyOperationInformation.class), isA(SDNCTopology.class)); - String response = sdncConfigurationResources.deactivateVnrConfiguration(serviceInstance,requestContext,vpnBondingLink.getVnrConfiguration()); - verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiGcTopologyOperationInformation.class), any(SDNCTopology.class)); + public void deactivateVnrConfigurationTest() throws BadResponseException, MapperException , URISyntaxException{ + GenericResourceApiGcTopologyOperationInformation response = sdncConfigurationResources.deactivateVnrConfiguration(serviceInstance,requestContext,vpnBondingLink.getVnrConfiguration(),"uuid",new URI("http://localhost")); assertNotNull(response); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java index 66ec514039..cc1c5c5329 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java @@ -23,37 +23,30 @@ package org.onap.so.client.sdnc; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import org.junit.Rule; import org.junit.Test; import org.onap.so.BaseIntegrationTest; -import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.MapperException; import org.onap.so.client.sdnc.endpoint.SDNCTopology; import org.skyscreamer.jsonassert.JSONAssert; -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class SDNCClientTest extends BaseIntegrationTest { +public class SDNCClientIT extends BaseIntegrationTest { private final static String JSON_FILE_LOCATION = "src/test/resources/__files/"; - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8446)); - @Test public void getTest() throws BadResponseException, MapperException, IOException { String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientGetResponse.json"))); String queryLink = "/topologyQuery"; - wireMockRule.stubFor(get(urlEqualTo(queryLink)) + stubFor(get(urlEqualTo(queryLink)) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json").withBody(responseJson))); String response = SPY_sdncClient.get(queryLink); @@ -66,7 +59,7 @@ public class SDNCClientTest extends BaseIntegrationTest { String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; - wireMockRule.stubFor(post(urlMatching(queryLink)) + stubFor(post(urlMatching(queryLink)) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json").withBody(responseJson))); @@ -79,7 +72,7 @@ public class SDNCClientTest extends BaseIntegrationTest { String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; - wireMockRule.stubFor(post(urlMatching(queryLink)) + stubFor(post(urlMatching(queryLink)) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json").withBody(responseJson))); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java index 7c5e9ccf26..f01eeaeae8 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java @@ -20,6 +20,8 @@ package org.onap.so.client.sdnc.mapper; +import java.net.URI; +import java.net.URISyntaxException; import java.util.HashMap; import java.util.List; @@ -44,7 +46,7 @@ public class GCTopologyOperationRequestMapperTest extends TestDataSetup{ private GCTopologyOperationRequestMapper genObjMapper = new GCTopologyOperationRequestMapper(); @Test - public void deactivateOrUnassignVnrReqMapperTest() { + public void deactivateOrUnassignVnrReqMapperTest() throws URISyntaxException { RequestContext requestContext = new RequestContext(); requestContext.setMsoRequestId("MsoRequestId"); ServiceInstance serviceInstance = new ServiceInstance(); @@ -52,10 +54,15 @@ public class GCTopologyOperationRequestMapperTest extends TestDataSetup{ Configuration Configuration = new Configuration(); Configuration.setConfigurationId("ConfigurationId"); GenericResourceApiGcTopologyOperationInformation genericInfo = genObjMapper.deactivateOrUnassignVnrReqMapper - (SDNCSvcAction.UNASSIGN, serviceInstance, requestContext, Configuration); + (SDNCSvcAction.UNASSIGN, serviceInstance, requestContext, Configuration,"uuid",new URI("http://localhost")); Assert.assertNotNull(genericInfo); - Assert.assertNotNull(genericInfo.getSdncRequestHeader().getSvcRequestId()); + Assert.assertNotNull(genericInfo.getRequestInformation()); + Assert.assertNotNull(genericInfo.getSdncRequestHeader()); + Assert.assertNotNull(genericInfo.getClass()); + Assert.assertNotNull(genericInfo.getServiceInformation()); + Assert.assertEquals("uuid",genericInfo.getSdncRequestHeader().getSvcRequestId()); + Assert.assertEquals("http://localhost",genericInfo.getSdncRequestHeader().getSvcNotificationUrl()); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java index e5eb6bce54..3387e9ddef 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java @@ -22,18 +22,20 @@ package org.onap.so.client.sniro; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; + import org.junit.Test; +import org.onap.so.BaseIntegrationTest; import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.sniro.beans.SniroConductorRequest; import org.onap.so.client.sniro.beans.SniroManagerRequest; import org.springframework.beans.factory.annotation.Autowired; import com.fasterxml.jackson.core.JsonProcessingException; -import static com.github.tomakehurst.wiremock.client.WireMock.*; -public class SniroClientTestIT{ +public class SniroClientTestIT extends BaseIntegrationTest { @Autowired private SniroClient client; diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1Vpn.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1Vpn.json index ba7ab9e3b8..55aa2ef58c 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1Vpn.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1Vpn.json @@ -2,5 +2,5 @@ "requestInfo" : {"sourceId":"mso","requestType":"create","requestId":"testRequestId","callbackUrl":"http://localhost:28080/mso/WorkflowMesssage/SNIROResponse/testRequestId","transactionId":"testRequestId","timeout":1800}, "serviceInfo" : {"modelInfo":{"modelName":"testModelName1","modelVersionId":"testModelUUID1","modelVersion":"testModelVersion1","modelInvariantId":"testModelInvariantUUID1"},"serviceInstanceId":"testServiceInstanceId1","serviceName":"testServiceType1"}, "placementInfo" : {"subscriberInfo":{"subscriberName":"testCustomerName","globalSubscriberId":"testCustomerId"},"placementDemands":[{"resourceModelInfo":{"modelName":"testProxyModelName1","modelVersionId":"testProxyModelUuid1","modelVersion":"testProxyModelVersion1","modelInvariantId":"testProxyModelInvariantUuid1"},"resourceModuleName":"testProxyInstanceName1","serviceResourceId":"testProxyId1"},{"resourceModelInfo":{"modelName":"testProxyModelName2","modelVersionId":"testProxyModelUuid2","modelVersion":"testProxyModelVersion2","modelInvariantId":"testProxyModelInvariantUuid2"},"requiredCandidates":[{"candidateType":{"name":"vnfId"},"candidates":["testVnfId"]}],"resourceModuleName":"testProxyInstanceName2","serviceResourceId":"testProxyId2"}],"requestParameters":{"aLaCarte":false,"subscriptionServiceType":"iptollfree"}}, - "licenseInfo" : [] + "licenseInfo" : {"licenseDemands":[]} }
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3AR.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3AR.json new file mode 100644 index 0000000000..6977224ffa --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3AR.json @@ -0,0 +1,6 @@ +{ + "requestInfo" : {"sourceId":"mso","requestType":"create","requestId":"testRequestId","callbackUrl":"http://localhost:28080/mso/WorkflowMesssage/SNIROResponse/testRequestId","transactionId":"testRequestId","timeout":1800}, + "serviceInfo" : {"modelInfo":{"modelName":"testModelName1","modelVersionId":"testModelUUID1","modelVersion":"testModelVersion1","modelInvariantId":"testModelInvariantUUID1"},"serviceInstanceId":"testServiceInstanceId1","serviceName":"testServiceType1"}, + "placementInfo" : {"subscriberInfo":{"subscriberName":"testCustomerName","globalSubscriberId":"testCustomerId"},"placementDemands":[{"resourceModelInfo":{"modelName":"testAllottedModelName1","modelVersionId":"testAllottedModelUuid1","modelVersion":"testAllottedModelVersion1","modelInvariantId":"testAllottedModelInvariantUuid1"},"resourceModuleName":"testAllottedModelInstanceName1","serviceResourceId":"testAllottedResourceId1"},{"resourceModelInfo":{"modelName":"testAllottedModelName2","modelVersionId":"testAllottedModelUuid2","modelVersion":"testAllottedModelVersion2","modelInvariantId":"testAllottedModelInvariantUuid2"},"resourceModuleName":"testAllottedModelInstanceName2","serviceResourceId":"testAllottedResourceId2"},{"resourceModelInfo":{"modelName":"testAllottedModelName3","modelVersionId":"testAllottedModelUuid3","modelVersion":"testAllottedModelVersion3","modelInvariantId":"testAllottedModelInvariantUuid3"},"resourceModuleName":"testAllottedModelInstanceName3","serviceResourceId":"testAllottedResourceId3"}],"requestParameters":{"aLaCarte":false,"subscriptionServiceType":"iptollfree"}}, + "licenseInfo" : {"licenseDemands":[]} +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3Vpn.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3Vpn.json index c5d0ffe38d..c72831b79f 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3Vpn.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3Vpn.json @@ -2,5 +2,5 @@ "requestInfo" : {"sourceId":"mso","requestType":"create","requestId":"testRequestId","callbackUrl":"http://localhost:28080/mso/WorkflowMesssage/SNIROResponse/testRequestId","transactionId":"testRequestId","timeout":1800}, "serviceInfo" : {"modelInfo":{"modelName":"testModelName1","modelVersionId":"testModelUUID1","modelVersion":"testModelVersion1","modelInvariantId":"testModelInvariantUUID1"},"serviceInstanceId":"testServiceInstanceId1","serviceName":"testServiceType1"}, "placementInfo" : {"subscriberInfo":{"subscriberName":"testCustomerName","globalSubscriberId":"testCustomerId"},"placementDemands":[{"resourceModelInfo":{"modelName":"testProxyModelName1","modelVersionId":"testProxyModelUuid1","modelVersion":"testProxyModelVersion1","modelInvariantId":"testProxyModelInvariantUuid1"},"resourceModuleName":"testProxyInstanceName1","serviceResourceId":"testProxyId1"},{"resourceModelInfo":{"modelName":"testProxyModelName2","modelVersionId":"testProxyModelUuid2","modelVersion":"testProxyModelVersion2","modelInvariantId":"testProxyModelInvariantUuid2"},"requiredCandidates":[{"candidateType":{"name":"vnfId"},"candidates":["testVnfId"]}],"resourceModuleName":"testProxyInstanceName2","serviceResourceId":"testProxyId2"},{"resourceModelInfo":{"modelName":"testProxyModelName1","modelVersionId":"testProxyModelUuid1","modelVersion":"testProxyModelVersion1","modelInvariantId":"testProxyModelInvariantUuid1"},"resourceModuleName":"testProxyInstanceName1","serviceResourceId":"testProxyId1"},{"resourceModelInfo":{"modelName":"testProxyModelName2","modelVersionId":"testProxyModelUuid2","modelVersion":"testProxyModelVersion2","modelInvariantId":"testProxyModelInvariantUuid2"},"requiredCandidates":[{"candidateType":{"name":"vnfId"},"candidates":["testVnfId"]}],"resourceModuleName":"testProxyInstanceName2","serviceResourceId":"testProxyId2"},{"resourceModelInfo":{"modelName":"testProxyModelName1","modelVersionId":"testProxyModelUuid1","modelVersion":"testProxyModelVersion1","modelInvariantId":"testProxyModelInvariantUuid1"},"resourceModuleName":"testProxyInstanceName1","serviceResourceId":"testProxyId1"},{"resourceModelInfo":{"modelName":"testProxyModelName2","modelVersionId":"testProxyModelUuid2","modelVersion":"testProxyModelVersion2","modelInvariantId":"testProxyModelInvariantUuid2"},"requiredCandidates":[{"candidateType":{"name":"vnfId"},"candidates":["testVnfId"]}],"resourceModuleName":"testProxyInstanceName2","serviceResourceId":"testProxyId2"}],"requestParameters":{"aLaCarte":false,"subscriptionServiceType":"iptollfree"}}, - "licenseInfo" : [] + "licenseInfo" : {"licenseDemands":[]} }
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientPut200ResponseNotFinal.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientPut200ResponseNotFinal.json new file mode 100644 index 0000000000..deb4de0219 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientPut200ResponseNotFinal.json @@ -0,0 +1,15 @@ +{ + "output": { + "svc-request-id": "5d24d40e-4c77-4c06-94a3-6d168c47a57c", + "network-response-information": { + "instance-id": "4063e0aa-af13-4872-8473-b40c94f9316b", + "object-path": "restconf/config/GENERIC-RESOURCE-API:services/service/2c9c7996-75a7-4f92-becc-9e13e8bd288a/service-data/networks/network/4063e0aa-af13-4872-8473-b40c94f9316b/network-data/network-topology/" + }, + "response-code": "200", + "service-response-information": { + "instance-id": "2c9c7996-75a7-4f92-becc-9e13e8bd288a" + }, + "response-message": "", + "ack-final-indicator": "N" + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_ASYNC_Request.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_ASYNC_Request.json new file mode 100644 index 0000000000..c1ea682068 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_ASYNC_Request.json @@ -0,0 +1,15 @@ +{ + "input": { + "svc-request-id": "5d24d40e-4c77-4c06-94a3-6d168c47a57c", + "network-response-information": { + "instance-id": "4063e0aa-af13-4872-8473-b40c94f9316b", + "object-path": "restconf/config/GENERIC-RESOURCE-API:services/service/2c9c7996-75a7-4f92-becc-9e13e8bd288a/service-data/networks/network/4063e0aa-af13-4872-8473-b40c94f9316b/network-data/network-topology/" + }, + "response-code": "200", + "service-response-information": { + "instance-id": "2c9c7996-75a7-4f92-becc-9e13e8bd288a" + }, + "response-message": "", + "ack-final-indicator": "Y" + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_Client_Request.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_Client_Request.json new file mode 100644 index 0000000000..f60767b85e --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_Client_Request.json @@ -0,0 +1,28 @@ +: { + "input": { + "request-information": { + "request-action": "CreateServiceInstance", + "source": "MSO", + "request-id": "5a09ab96-032b-41cd-ad81-4fb9ec5fade7" + }, + "sdnc-request-header": { + "svc-request-id": "5a09ab96-032b-41cd-ad81-4fb9ec5fade7", + "svc-action": "assign" + }, + "service-information": { + "onap-model-information": { + "model-name": "Vf zrdm5bpxmc02092017-Service", + "model-version": "1.0", + "model-uuid": "bad955c3-29b2-4a27-932e-28e942cc6480", + "model-invariant-uuid": "b16a9398-ffa3-4041-b78c-2956b8ad9c7b" + }, + "subscription-service-type": "Robot_Test_Service_Type", + "service-id": "48121c5e-dde0-42a6-a78a-89556ff355d0", + "global-customer-id": "Robot_Test_Subscriber_ID", + "service-instance-id": "48121c5e-dde0-42a6-a78a-89556ff355d0" + }, + "service-request-input": { + "service-instance-name": "Robot_SI_For_VolumeGroup" + } + } +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml index 69d2e18e7a..4ecdc721f0 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml +++ b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml @@ -160,7 +160,7 @@ policy: environment: TEST sdnc: auth: Basic YWRtaW46YWRtaW4= - host: http://localhost:8446 + host: http://localhost:${wiremock.server.port} path: /restconf/operations/GENERIC-RESOURCE-API sniro: conductor: @@ -180,8 +180,7 @@ sniro: oof: timeout: PT30M host: http://localhost:${wiremock.server.port} - uri.v1: /api/oof/v1/placement - uri.v2: /api/oof/v2/placement + uri: /api/oof/v1/placement headers.auth: Basic dGVzdDp0ZXN0cHdk spring: datasource: |