From 61affc6311906aee71b16ee8632c1e7468cd1990 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Mon, 5 Nov 2018 11:00:36 -0500 Subject: Catchup commits for Dublin added property for retry timer multiplier for testing Infra APIH table, fixed test assertNull condition. Infra APIH table, added tests for request-url = null. Infra APIH should write request_url to infra_active_requests. Return SelfLink URL on ServiceInstantiation SyncResponse. Added JUNITS. Added helper method to get AAI ResourceUri to faciliate unit test. Fixed code to correctly extract related generic vnf or vce id. updated unit test coverage for update network Handle REST NotFoundException for serviceInstance nodes query. Process should continue for new order request and throw exception only for SUPP request. Added disconnect functionality to the gw vnf test tool. Added conversion of vnf management option to dhv change speed sync subnet status with network update updated macroData vol assigned delete continue script Correct the name of DeleteVfModuleBB subprocess. fix the custom resolver to not convert int in string to int Write the returned value from Homing to gBBInput Use explicit conversion to JSON to read cloudConfiguration settings. added property for retry timer multiplier for testing avoid storing AAI yang models in execution added handlingCode to rollback test in workflowactionbb passed in alacarte flag to execute layer for rainy day added test cases for RollbackToAssigned rainy day hand added rollback to assign in catalog db rainy day hand Updated vnf adapter delete stubs to be a post for test. Added a javadoc to basic auth override method Added a check to not add blank headers to the headerMap in httpClient. Added check for if entity exist before calling readEntity. Fixed failing junits and updated way the body is obtained Added missing import statement for http client. Fixed mistakes and made updates caught during review. Removed post and httpPost methods from RESTClient and refactored references Refactored multiple http post references to use httpClient instead. Removed close connection method and randomized port in unit test Added http client unit test, coverage is currently at 90 percent Resolve conflict in sdnc adapter reste v1 method Began removing http delete and delete methods from RESTClient and aaiUtil. Removed http put method and executeput method, refactored references. fixed broken tests in the branch in jenkins build Fix Springboot 2.0 start up issues, and other issues added in implementation to generate self link if there isnt one removed dbcp2 from poms that still had them added rollbackstatusmessage to stub in testprocess added rollback_status_message to the schema sql file Added variable for rollbackStatusMessage Added rollbackStatusMessage to get response added rollback status message to archived infra request set rollback status message to successful on boolean added logic to split rollback and regular error message added rollback status message to infra active requests pushing the cloud config changes as well Added media type and fixed cast plural issue. Made various updated and fixes to code that was changed. Removed all no longer used RESTClient imports from classes Removed and refactored references for aaiUtil methods and all remaining RESTClient methods, removed RESTClient project and updated poms. Return canonical stack id on multicloud create Fix OOF Config Ingestion Fix variable to retrieve sdnc endpoint Prepare resources for service uuid req Fix swapped parameters for multicloud DELETE Update msb-java-sdk to resolve license issues cloud owner support for SDNC interface correlationId is now read from userParams Fix up request body of multicloud adapter body removed LinkedHashMap from java classes Cut over logging project to release not snapshot Update unit tests, revert test code, fix comments Fix remaining number of Unit Tests, on avpn flow Fix JUNITS add callback url, fix BPMN issues Update SDNC interaction to support a-sync updated bpm assert import and corrected tests updated test case to be mockito 2 compliant additional changes to import statements and tests Change the place where the data for multistage gets set Update treatment of PENDING_ACTIVATION VF_MODULE CREATE entries to SILENT_SUCCESS to support first stage of multistage. Implement second stage of multistage design VF Module Creation removed LinkedHashMap from java classes Removed SNAPSHOT from dependency Cut over logging project to release not snapshot Fixed failing BBInputSetup tests Update unit tests, revert test code, fix comments Updated apih tests to use networkInstanceGroup Updated ModelType enum and fixed compilation issues Fix remaining number of Unit Tests, on avpn flow Fix JUNITS add callback url, fix BPMN issues Implementation of the first stage of multistage design for VF Module creation. Update SDNC interaction to support a-sync no longer leave modified files after test runs Remove generated CSAR, that occurs during JUNIT Update Camunda Pods to use Flyway Migration in 1902 Updated hashcode method and removed comment. Added aggregate routes to the sdnw request and updated pom sdnw dependency. Began to set aggreagate route information for vrf configuration. modified remaining files with att-aic references Correct rollbackData setting and protect against potential null objects. correct AAIObjectPlurals enum value name Update POJO to use type URL for selfLink. Optional - construct SelfLink Url format. Construct SelfLink Url format from full Url. added missing properties to application-test.yaml fixed compliation error after merge of unit test restored files which should not have been deleted Fix SO vulnerabilities with cxf Fixing bpmn infra endpoint in so-monitoring yaml removed att-aic from codebase default cloud owner now configurable Set homingService in WorkflowAction Fix Java Ex in Homing Version should be 1.3.1 to release new dockers Pnf Spring Environment correction test property now has dynamic wiremock port removed test specific wiremock rule that was causing problems re-enabled and corrected integration tests for so-bpmn-tasks Test to get sniro homing v2 test working by splitting test suites for each spring application Reverted changes to old migration scripts.. Fixed spring context issue with test HomingV2. Removed unused import to fix compilation errors Fixed onap changes to homing, migrated homingV2 to homingBB, fixed broken junits again. - Updated isUseHttpsWithDmaapTest to check assertTrue rather than assertFalse. - Upgraded code to make the isUseHttpsWithDmaap configurable. It will default to true if no value is found in the config file. moved workflowaction test class to the test section added status message update for retry and rollback beefed up error message debug logging and req db msg added debug lines to workflowactionbbtasks reqdbcall Issue-ID: SO-1187 Change-Id: Iec1aff4ed30a43c0e0b2cdb06c28d8db8a99a830 Signed-off-by: Benjamin, Max (mb388a) --- bpmn/so-bpmn-tasks/pom.xml | 32 ++ .../onap/so/bpmn/buildingblock/SniroHomingV2.java | 3 +- .../infrastructure/sdnc/tasks/SDNCQueryTasks.java | 20 +- .../sdnc/tasks/SDNCRequestTasks.java | 99 ++++ .../workflow/tasks/WorkflowActionBBTasks.java | 118 +++-- .../orchestration/SDNCConfigurationResources.java | 159 ++++--- .../java/org/onap/so/client/sdnc/SDNCClient.java | 17 +- .../org/onap/so/client/sdnc/SdnCommonTasks.java | 7 +- .../org/onap/so/client/sdnc/beans/SDNCRequest.java | 94 ++++ .../mapper/GCTopologyOperationRequestMapper.java | 14 +- .../sdnc/mapper/GeneralTopologyObjectMapper.java | 10 + .../java/org/onap/so/client/sniro/SniroClient.java | 8 +- .../org/onap/so/client/sniro/SniroValidator.java | 4 +- .../java/org/onap/so/AllIntegrationTestSuites.java | 12 + .../test/java/org/onap/so/BaseIntegrationTest.java | 32 +- .../java/org/onap/so/IntegrationTestSuite.java | 12 + .../src/test/java/org/onap/so/UnitTestSuite.java | 13 + .../test/java/org/onap/so/bpmn/BaseTaskTest.java | 57 +-- .../onap/so/bpmn/common/data/TestDataSetup.java | 14 +- .../aai/tasks/AAIUpdateTasksTest.java | 1 + .../infrastructure/appc/tasks/AppcRunTasksIT.java | 101 +++++ .../appc/tasks/AppcRunTasksITTest.java | 101 ----- .../flowspecific/tasks/SniroHomingV2IT.java | 496 ++++++++++++++++++++ .../flowspecific/tasks/SniroHomingV2Test.java | 497 --------------------- .../sdnc/tasks/SDNCQueryTasksTest.java | 5 + .../sdnc/tasks/SDNCRequestTasksTest.java | 170 +++++++ .../workflow/tasks/WorkflowActionBBTasksTest.java | 92 ++-- .../WorkflowActionBBTasksUpdateReqDbTest.java | 74 +++ .../adapter/network/NetworkAdapterClientIT.java | 7 +- .../so/client/adapter/vnf/VnfAdapterClientIT.java | 6 +- .../org/onap/so/client/oof/OofClientTestIT.java | 15 +- .../SDNCConfigurationResourcesTest.java | 37 +- .../java/org/onap/so/client/sdnc/SDNCClientIT.java | 82 ++++ .../org/onap/so/client/sdnc/SDNCClientTest.java | 89 ---- .../GCTopologyOperationRequestMapperTest.java | 13 +- .../onap/so/client/sniro/SniroClientTestIT.java | 6 +- .../SniroHoming/SniroManagerRequest1Vpn.json | 2 +- .../SniroHoming/SniroManagerRequest3AR.json | 6 + .../SniroHoming/SniroManagerRequest3Vpn.json | 2 +- .../__files/SDNCClientPut200ResponseNotFinal.json | 15 + .../test/resources/__files/SDNC_ASYNC_Request.json | 15 + .../resources/__files/SDNC_Client_Request.json | 28 ++ .../src/test/resources/application-test.yaml | 5 +- 43 files changed, 1625 insertions(+), 965 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/beans/SDNCRequest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/AllIntegrationTestSuites.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/IntegrationTestSuite.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/UnitTestSuite.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksIT.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksITTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2Test.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksUpdateReqDbTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3AR.json create mode 100644 bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientPut200ResponseNotFinal.json create mode 100644 bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_ASYNC_Request.json create mode 100644 bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_Client_Request.json (limited to 'bpmn/so-bpmn-tasks') diff --git a/bpmn/so-bpmn-tasks/pom.xml b/bpmn/so-bpmn-tasks/pom.xml index 95e3a3ed07..63a65cdc24 100644 --- a/bpmn/so-bpmn-tasks/pom.xml +++ b/bpmn/so-bpmn-tasks/pom.xml @@ -14,6 +14,38 @@ 1.8 1.8 + + + + org.apache.maven.plugins + maven-surefire-plugin + + + default-test + + test + + + + **/UnitTestSuite.java + + + + + integration-test + + test + + + + **/IntegrationTestSuite.java + + + + + + + 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 = "" - + requestId + "" + action - + "VID" - + exceptionMsg - + "7000"; - 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> STOClient = new BaseClient<>(); + private BaseClient> 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 output = STOClient.post(jsonRequest, new ParameterizedTypeReference>() {}); 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 output = STOClient.post(jsonRequest, new ParameterizedTypeReference>() {}); + 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 output = STOClient.get(jsonRequest, new ParameterizedTypeReference>() {}); 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 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 embeddedResponse =(LinkedHashMap) 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 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> baseClient = new BaseClient<>(); + BaseClient> baseClient = new BaseClient<>(); baseClient.setTargetUrl(url); baseClient.setHttpHeader(header); - LinkedHashMap response = baseClient.post(homingRequest.toJsonString(), new ParameterizedTypeReference>() {}); + LinkedHashMap response = baseClient.post(homingRequest.toJsonString(), new ParameterizedTypeReference>() {}); 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> baseClient = new BaseClient<>(); + BaseClient> baseClient = new BaseClient<>(); baseClient.setTargetUrl(url); baseClient.setHttpHeader(header); - LinkedHashMap response = baseClient.post(releaseRequest.toJsonString(), new ParameterizedTypeReference>() {}); + LinkedHashMap response = baseClient.post(releaseRequest.toJsonString(), new ParameterizedTypeReference>() {}); 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 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 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/AppcRunTasksIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksIT.java new file mode 100644 index 0000000000..9cf1a1cdc9 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksIT.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.appc.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.HashMap; +import java.util.Optional; +import java.util.UUID; + +import org.junit.Before; +import org.junit.Test; +import org.onap.appc.client.lcm.model.Action; +import org.onap.so.BaseIntegrationTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +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 AppcRunTasksIT extends BaseIntegrationTest { + + @Autowired + private AppcRunTasks appcRunTasks; + + private GenericVnf genericVnf; + private RequestContext requestContext; + private String msoRequestId; + + @Before + public void before() { + genericVnf = setGenericVnf(); + msoRequestId = UUID.randomUUID().toString(); + requestContext = setRequestContext(); + requestContext.setMsoRequestId(msoRequestId); + gBBInput.setRequestContext(requestContext); + } + + @Test + public void preProcessActivityTest() throws Exception { + appcRunTasks.preProcessActivity(execution); + assertEquals(execution.getVariable("actionQuiesceTraffic"), Action.QuiesceTraffic); + assertEquals(execution.getVariable("rollbackQuiesceTraffic"), false); + } + + @Test + public void runAppcCommandTest() throws Exception { + Action action = Action.QuiesceTraffic; + ControllerSelectionReference controllerSelectionReference = new ControllerSelectionReference(); + controllerSelectionReference.setControllerName("testName"); + controllerSelectionReference.setActionCategory(action.toString()); + controllerSelectionReference.setVnfType("testVnfType"); + + doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.QuiesceTraffic.toString()); + + execution.setVariable("aicIdentity", "testAicIdentity"); + + String vnfId = genericVnf.getVnfId(); + genericVnf.setIpv4OamAddress("testOamIpAddress"); + String payload = "{\"testName\":\"testValue\",}"; + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setPayload(payload); + gBBInput.getRequestContext().setRequestParameters(requestParameters); + + String controllerType = "testName"; + HashMap payloadInfo = new HashMap(); + payloadInfo.put("vnfName", "testVnfName1"); + payloadInfo.put("aicIdentity", "testAicIdentity"); + payloadInfo.put("vnfHostIpAddress", "testOamIpAddress"); + payloadInfo.put("vserverIdList", null); + payloadInfo.put("vfModuleId", null); + payloadInfo.put("identityUrl", null); + payloadInfo.put("vmIdList", null); + + doNothing().when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); + + appcRunTasks.runAppcCommand(execution, action); + verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); + } +} 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/AppcRunTasksITTest.java deleted file mode 100644 index 942553b1dc..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksITTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 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.appc.tasks; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import java.util.HashMap; -import java.util.Optional; -import java.util.UUID; - -import org.junit.Before; -import org.junit.Test; -import org.onap.appc.client.lcm.model.Action; -import org.onap.so.BaseIntegrationTest; -import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; -import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; -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 { - - @Autowired - private AppcRunTasks appcRunTasks; - - private GenericVnf genericVnf; - private RequestContext requestContext; - private String msoRequestId; - - @Before - public void before() { - genericVnf = setGenericVnf(); - msoRequestId = UUID.randomUUID().toString(); - requestContext = setRequestContext(); - requestContext.setMsoRequestId(msoRequestId); - gBBInput.setRequestContext(requestContext); - } - - @Test - public void preProcessActivityTest() throws Exception { - appcRunTasks.preProcessActivity(execution); - assertEquals(execution.getVariable("actionQuiesceTraffic"), Action.QuiesceTraffic); - assertEquals(execution.getVariable("rollbackQuiesceTraffic"), false); - } - - @Test - public void runAppcCommandTest() throws Exception { - Action action = Action.QuiesceTraffic; - ControllerSelectionReference controllerSelectionReference = new ControllerSelectionReference(); - controllerSelectionReference.setControllerName("testName"); - controllerSelectionReference.setActionCategory(action.toString()); - controllerSelectionReference.setVnfType("testVnfType"); - - doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.QuiesceTraffic.toString()); - - execution.setVariable("aicIdentity", "testAicIdentity"); - - String vnfId = genericVnf.getVnfId(); - genericVnf.setIpv4OamAddress("testOamIpAddress"); - String payload = "{\"testName\":\"testValue\",}"; - RequestParameters requestParameters = new RequestParameters(); - requestParameters.setPayload(payload); - gBBInput.getRequestContext().setRequestParameters(requestParameters); - - String controllerType = "testName"; - HashMap payloadInfo = new HashMap(); - payloadInfo.put("vnfName", "testVnfName1"); - payloadInfo.put("aicIdentity", "testAicIdentity"); - payloadInfo.put("vnfHostIpAddress", "testOamIpAddress"); - payloadInfo.put("vserverIdList", null); - payloadInfo.put("vfModuleId", null); - payloadInfo.put("identityUrl", null); - payloadInfo.put("vmIdList", null); - - doNothing().when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); - - appcRunTasks.runAppcCommand(execution, action); - verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); - } -} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java new file mode 100644 index 0000000000..f0bb6a369c --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java @@ -0,0 +1,496 @@ +/*- + * ============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.flowspecific.tasks; + +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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; +import org.onap.so.bpmn.servicedecomposition.homingobjects.Candidate; +import org.onap.so.bpmn.servicedecomposition.homingobjects.CandidateType; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.client.sniro.beans.SniroManagerRequest; +import org.onap.so.BaseIntegrationTest; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class SniroHomingV2IT extends BaseIntegrationTest{ + + private ServiceInstance serviceInstance; + + private RequestContext requestContext; + + private Customer customer; + ObjectMapper mapper = new ObjectMapper(); + + private static final String RESOURCE_PATH = "__files/BuildingBlocks/SniroHoming/"; + + + String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}"; + + @Before + public void before() { + serviceInstance = setServiceInstance(); + customer = setCustomer(); + customer.setGlobalCustomerId("testCustomerId"); + customer.setSubscriberName("testCustomerName"); + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + + requestContext = setRequestContext(); + requestContext.setMsoRequestId("testRequestId"); + RequestParameters params = new RequestParameters(); + params.setaLaCarte(false); + params.setSubscriptionServiceType("iptollfree"); + requestContext.setRequestParameters(params); + } + + public void beforeVpnBondingLink(String id){ + VpnBondingLink bondingLink = new VpnBondingLink(); + bondingLink.setVpnBondingLinkId("testVpnBondingId" + id); + bondingLink.getServiceProxies().add(setServiceProxy("1", "transport")); + ServiceProxy sp2 = setServiceProxy("2", "infrastructure"); + Candidate requiredCandidate = new Candidate(); + requiredCandidate.setCandidateType(CandidateType.VNF_ID); + List c = new ArrayList(); + c.add("testVnfId"); + requiredCandidate.setCandidates(c); + sp2.addRequiredCandidates(requiredCandidate); + bondingLink.getServiceProxies().add(sp2); + serviceInstance.getVpnBondingLinks().add(bondingLink); + + } + + public void beforeAllottedResource(){ + serviceInstance.getAllottedResources().add(setAllottedResource("1")); + serviceInstance.getAllottedResources().add(setAllottedResource("2")); + serviceInstance.getAllottedResources().add(setAllottedResource("3")); + } + + public void beforeVnf(){ + setGenericVnf(); + } + + @Test(expected = Test.None.class) + public void testCallSniro_success_1VpnLink() throws BadResponseException, IOException{ + beforeVpnBondingLink("1"); + + stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + sniroHoming.callSniro(execution); + + String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest1Vpn.json"); + request = request.replace("28080", wireMockPort); + + ArgumentCaptor argument = ArgumentCaptor.forClass(SniroManagerRequest.class); + verify(sniroClient, times(1)).postDemands(argument.capture()); + assertEquals(request, argument.getValue().toJsonString()); + } + + @Test + public void testCallSniro_success_3VpnLink() throws JsonProcessingException, BadResponseException{ + beforeVpnBondingLink("1"); + beforeVpnBondingLink("2"); + beforeVpnBondingLink("3"); + + stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + sniroHoming.callSniro(execution); + + String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3Vpn.json"); + request = request.replace("28080", wireMockPort); + + ArgumentCaptor argument = ArgumentCaptor.forClass(SniroManagerRequest.class); + verify(sniroClient, times(1)).postDemands(argument.capture()); + assertEquals(request, argument.getValue().toJsonString()); + } + + @Test + public void testCallSniro_success_3Allotteds() throws BadResponseException, JsonProcessingException{ + beforeAllottedResource(); + + stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + sniroHoming.callSniro(execution); + + String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3AR.json"); + request = request.replace("28080", wireMockPort); + + ArgumentCaptor argument = ArgumentCaptor.forClass(SniroManagerRequest.class); + verify(sniroClient, times(1)).postDemands(argument.capture()); + assertEquals(request, argument.getValue().toJsonString()); + } + + @Test + public void testCallSniro_success_1Vnf() throws JsonProcessingException, BadResponseException{ + beforeVnf(); + + stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + sniroHoming.callSniro(execution); + + ArgumentCaptor argument = ArgumentCaptor.forClass(SniroManagerRequest.class); + verify(sniroClient, times(1)).postDemands(argument.capture()); + //TODO assertEquals(request, argument.getValue().toJsonString()); + } + + @Test + public void testCallSniro_success_3Allotteds1Vnf() throws JsonProcessingException, BadResponseException{ + beforeAllottedResource(); + beforeVnf(); + + stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + sniroHoming.callSniro(execution); + + verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class)); + } + + @Test(expected = Test.None.class) + public void testProcessSolution_success_1VpnLink_1Solution(){ + beforeVpnBondingLink("1"); + + JSONObject asyncResponse = new JSONObject(); + asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed"); + JSONArray solution1 = new JSONArray(); + solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject() + .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1"))) + .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False")) + .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1")) + .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) + .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1")))); + solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject() + .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2"))) + .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False")) + .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2")) + .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) + .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName2")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2")))); + + asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", new JSONArray())); + + sniroHoming.processSolution(execution, asyncResponse.toString()); + + ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0); + + assertFalse(si.getVpnBondingLinks().isEmpty()); + VpnBondingLink link = si.getVpnBondingLinks().get(0); + assertNotNull(link); + assertFalse(link.getServiceProxies().isEmpty()); + + assertEquals("testServiceInstanceId1", link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId()); + assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo()); + assertEquals("testVnfHostName1", link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName()); + + assertEquals("testServiceInstanceId2", link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId()); + assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo()); + assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty()); + assertEquals("testPrimaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName()); + assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole()); + assertEquals("testSecondaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName()); + assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole()); + } + + @Test + public void testProcessSolution_success_1VpnLink_2Solutions(){ + beforeVpnBondingLink("1"); + + JSONObject asyncResponse = new JSONObject(); + asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed"); + JSONArray solution1 = new JSONArray(); + solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject() + .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1"))) + .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False")) + .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1")) + .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) + .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1")))); + solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject() + .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2"))) + .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False")) + .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2")) + .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) + .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName2")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2")))); + + JSONArray solution2 = new JSONArray(); + solution2.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject() + .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId3"))) + .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False")) + .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName3")) + .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli3")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) + .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId3")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId3")))); + solution2.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject() + .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId4"))) + .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False")) + .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName4")) + .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli4")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) + .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName4")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId4")))); + + asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1).put(solution2)).put("licenseSolutions", new JSONArray())); + + sniroHoming.processSolution(execution, asyncResponse.toString()); + + ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0); + + assertFalse(si.getVpnBondingLinks().isEmpty()); + VpnBondingLink link = si.getVpnBondingLinks().get(0); + VpnBondingLink link2 = si.getVpnBondingLinks().get(1); + assertNotNull(link); + assertFalse(link.getServiceProxies().isEmpty()); + + assertEquals("testServiceInstanceId1", link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId()); + assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo()); + assertEquals("testVnfHostName1", link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName()); + + assertEquals("testServiceInstanceId2", link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId()); + assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo()); + assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty()); + assertEquals("testPrimaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName()); + assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole()); + assertEquals("testSecondaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName()); + assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole()); + + assertNotNull(link2); + assertFalse(link2.getServiceProxies().isEmpty()); + + assertEquals("testServiceInstanceId3", link2.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId()); + assertNotNull(link2.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo()); + assertEquals("testVnfHostName3", link2.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName()); + + assertEquals("testServiceInstanceId4", link2.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId()); + assertNotNull(link2.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo()); + assertFalse(link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty()); + assertEquals("testPrimaryPnfName4", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName()); + assertEquals("primary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole()); + assertEquals("testSecondaryPnfName4", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName()); + assertEquals("secondary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole()); + + } + + @Test + public void testProcessSolution_success_3VpnLink_2Solutions(){ + //TODO + } + + @Test + public void testProcessSolution_success_3Allotteds_1Solution(){ + beforeAllottedResource(); + + JSONObject asyncResponse = new JSONObject(); + asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed"); + JSONArray solution1 = new JSONArray(); + solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1").put("inventoryType", "service").put("solution", new JSONObject() + .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1"))) + .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True")) + .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1")) + .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) + .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1")))); + solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2").put("inventoryType", "service").put("solution", new JSONObject() + .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2"))) + .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True")) + .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2")) + .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) + .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2")))); + solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3").put("inventoryType", "cloud").put("solution", new JSONObject() + .put("identifierType", "cloudRegionId").put("identifiers", new JSONArray().put("testCloudRegionId3"))) + .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True")) + .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")) + .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3")))); + + asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", new JSONArray())); + + sniroHoming.processSolution(execution, asyncResponse.toString()); + + ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0); + + assertFalse(si.getAllottedResources().isEmpty()); + AllottedResource ar = si.getAllottedResources().get(0); + assertNotNull(ar); + assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId()); + assertNotNull(ar.getParentServiceInstance().getSolutionInfo()); + assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName()); + + AllottedResource ar2 = si.getAllottedResources().get(1); + assertNotNull(ar2); + assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId()); + assertNotNull(ar2.getParentServiceInstance().getSolutionInfo()); + assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName()); + + AllottedResource ar3 = si.getAllottedResources().get(2); + assertNotNull(ar3); + assertNotNull(ar3.getParentServiceInstance().getSolutionInfo()); + assertEquals("testCloudRegionId3", ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId()); + } + + @Test + public void testProcessSolution_success_3Allotteds1Vnf_1Solution(){ + beforeVnf(); + beforeAllottedResource(); + + JSONObject asyncResponse = new JSONObject(); + asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed"); + JSONArray solution1 = new JSONArray(); + JSONArray licenseSolution = new JSONArray(); + solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1").put("inventoryType", "service").put("solution", new JSONObject() + .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1"))) + .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True")) + .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1")) + .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) + .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1")))); + solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2").put("inventoryType", "service").put("solution", new JSONObject() + .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2"))) + .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True")) + .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2")) + .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) + .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2")))); + solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3").put("inventoryType", "cloud").put("solution", new JSONObject() + .put("identifierType", "cloudRegionId").put("identifiers", new JSONArray().put("testCloudRegionId3"))) + .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True")) + .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")) + .put(new JSONObject().put("key", "aicVersion").put("value", "3")))); + + licenseSolution.put( + new JSONObject().put("serviceResourceId", "testVnfId1").put("entitlementPoolUUID", new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e").put("j1d563e8-e714-4393-8f99-cc480144a05e")) + .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e").put("b1d563e8-e714-4393-8f99-cc480144a05e"))); + + asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", licenseSolution)); + + sniroHoming.processSolution(execution, asyncResponse.toString()); + + ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0); + + assertFalse(si.getAllottedResources().isEmpty()); + AllottedResource ar = si.getAllottedResources().get(0); + assertNotNull(ar); + assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId()); + assertNotNull(ar.getParentServiceInstance().getSolutionInfo()); + assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName()); + + AllottedResource ar2 = si.getAllottedResources().get(1); + assertNotNull(ar2); + assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId()); + assertNotNull(ar2.getParentServiceInstance().getSolutionInfo()); + assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName()); + + AllottedResource ar3 = si.getAllottedResources().get(2); + assertNotNull(ar3); + assertNotNull(ar3.getParentServiceInstance().getSolutionInfo()); + assertEquals("testCloudRegionId3", ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId()); + + GenericVnf vnf = si.getVnfs().get(0); + assertNotNull(vnf); + assertNotNull(vnf.getLicense()); + assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size()); + assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0)); + + } + + @Test + public void testProcessSolution_success_1Vnf_1Solution(){ + beforeVnf(); + + JSONObject asyncResponse = new JSONObject(); + asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed"); + JSONArray licenseSolution = new JSONArray(); + + licenseSolution.put( + new JSONObject().put("serviceResourceId", "testVnfId1").put("entitlementPoolUUID", new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e").put("j1d563e8-e714-4393-8f99-cc480144a05e")) + .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e").put("b1d563e8-e714-4393-8f99-cc480144a05e"))); + + asyncResponse.put("solutions", new JSONObject().put("licenseSolutions", licenseSolution)); + + sniroHoming.processSolution(execution, asyncResponse.toString()); + + ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0); + + GenericVnf vnf = si.getVnfs().get(0); + assertNotNull(vnf); + assertNotNull(vnf.getLicense()); + assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size()); + assertEquals(2, vnf.getLicense().getLicenseKeyGroupUuids().size()); + assertEquals("f1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getEntitlementPoolUuids().get(0)); + assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0)); + + + } + + @Test(expected = BpmnError.class) + public void testCallSniro_error_0Resources() throws BadResponseException, JsonProcessingException{ + + sniroHoming.callSniro(execution); + + verify(sniroClient, times(0)).postDemands(isA(SniroManagerRequest.class)); + } + + @Test(expected = BpmnError.class) + public void testCallSniro_error_badResponse() throws BadResponseException, JsonProcessingException{ + beforeAllottedResource(); + + mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}"; + stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + sniroHoming.callSniro(execution); + + verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class)); + } + +} 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/SniroHomingV2Test.java deleted file mode 100644 index 73e7215fc6..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2Test.java +++ /dev/null @@ -1,497 +0,0 @@ -/*- - * ============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.flowspecific.tasks; - -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 static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.camunda.bpm.engine.delegate.BpmnError; -import org.json.JSONArray; -import org.json.JSONObject; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; -import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy; -import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink; -import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; -import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; -import org.onap.so.bpmn.servicedecomposition.homingobjects.Candidate; -import org.onap.so.bpmn.servicedecomposition.homingobjects.CandidateType; -import org.onap.so.client.exception.BadResponseException; -import org.onap.so.client.sniro.beans.SniroManagerRequest; -import org.onap.so.BaseIntegrationTest; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -@Ignore -public class SniroHomingV2Test extends BaseIntegrationTest{ - - private ServiceInstance serviceInstance; - - private RequestContext requestContext; - - private Customer customer; - ObjectMapper mapper = new ObjectMapper(); - - private static final String RESOURCE_PATH = "__files/BuildingBlocks/SniroHoming/"; - - - String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}"; -/** - @Before - public void before() { - serviceInstance = setServiceInstance(); - customer = setCustomer(); - customer.setGlobalCustomerId("testCustomerId"); - customer.setSubscriberName("testCustomerName"); - customer.getServiceSubscription().getServiceInstances().add(serviceInstance); - - requestContext = setRequestContext(); - requestContext.setMsoRequestId("testRequestId"); - RequestParameters params = new RequestParameters(); - params.setaLaCarte(false); - params.setSubscriptionServiceType("iptollfree"); - requestContext.setRequestParameters(params); - } - - public void beforeVpnBondingLink(String id){ - VpnBondingLink bondingLink = new VpnBondingLink(); - bondingLink.setVpnBondingLinkId("testVpnBondingId" + id); - bondingLink.getServiceProxies().add(setServiceProxy("1", "transport")); - ServiceProxy sp2 = setServiceProxy("2", "infrastructure"); - Candidate requiredCandidate = new Candidate(); - requiredCandidate.setCandidateType(CandidateType.VNF_ID); - List c = new ArrayList(); - c.add("testVnfId"); - requiredCandidate.setCandidates(c); - sp2.addRequiredCandidates(requiredCandidate); - bondingLink.getServiceProxies().add(sp2); - serviceInstance.getVpnBondingLinks().add(bondingLink); - - } - - public void beforeAllottedResource(){ - serviceInstance.getAllottedResources().add(setAllottedResource("1")); - serviceInstance.getAllottedResources().add(setAllottedResource("2")); - serviceInstance.getAllottedResources().add(setAllottedResource("3")); - } - - public void beforeVnf(){ - setGenericVnf(); - } - - @Test(expected = Test.None.class) - public void testCallSniro_success_1VpnLink() throws BadResponseException, IOException{ - beforeVpnBondingLink("1"); - - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) - .willReturn(aResponse().withStatus(200) - .withHeader("Content-Type", "application/json") - .withBody(mockResponse))); - - sniroHoming.callSniro(execution); - - String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest1Vpn.json"); - request = request.replace("28080", wireMockPort); - - ArgumentCaptor argument = ArgumentCaptor.forClass(SniroManagerRequest.class); - verify(sniroClient, times(1)).postDemands(argument.capture()); - assertEquals(request, argument.getValue().toJsonString()); - } - - @Test - public void testCallSniro_success_3VpnLink() throws JsonProcessingException, BadResponseException{ - beforeVpnBondingLink("1"); - beforeVpnBondingLink("2"); - beforeVpnBondingLink("3"); - - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) - .willReturn(aResponse().withStatus(200) - .withHeader("Content-Type", "application/json") - .withBody(mockResponse))); - - sniroHoming.callSniro(execution); - - String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3Vpn.json"); - request = request.replace("28080", wireMockPort); - - ArgumentCaptor argument = ArgumentCaptor.forClass(SniroManagerRequest.class); - verify(sniroClient, times(1)).postDemands(argument.capture()); - assertEquals(request, argument.getValue().toJsonString()); - } - - @Test - public void testCallSniro_success_3Allotteds() throws BadResponseException, JsonProcessingException{ - beforeAllottedResource(); - - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) - .willReturn(aResponse().withStatus(200) - .withHeader("Content-Type", "application/json") - .withBody(mockResponse))); - - sniroHoming.callSniro(execution); - - String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest3AR.json"); - request = request.replace("28080", wireMockPort); - - ArgumentCaptor argument = ArgumentCaptor.forClass(SniroManagerRequest.class); - verify(sniroClient, times(1)).postDemands(argument.capture()); - assertEquals(request, argument.getValue().toJsonString()); - } - - @Test - public void testCallSniro_success_1Vnf() throws JsonProcessingException, BadResponseException{ - beforeVnf(); - - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) - .willReturn(aResponse().withStatus(200) - .withHeader("Content-Type", "application/json") - .withBody(mockResponse))); - - sniroHoming.callSniro(execution); - - ArgumentCaptor argument = ArgumentCaptor.forClass(SniroManagerRequest.class); - verify(sniroClient, times(1)).postDemands(argument.capture()); - //TODO assertEquals(request, argument.getValue().toJsonString()); - } - - @Test - public void testCallSniro_success_3Allotteds1Vnf() throws JsonProcessingException, BadResponseException{ - beforeAllottedResource(); - beforeVnf(); - - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) - .willReturn(aResponse().withStatus(200) - .withHeader("Content-Type", "application/json") - .withBody(mockResponse))); - - sniroHoming.callSniro(execution); - - verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class)); - } - - @Test(expected = Test.None.class) - public void testProcessSolution_success_1VpnLink_1Solution(){ - beforeVpnBondingLink("1"); - - JSONObject asyncResponse = new JSONObject(); - asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed"); - JSONArray solution1 = new JSONArray(); - solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject() - .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1"))) - .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False")) - .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1")) - .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) - .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1")))); - solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject() - .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2"))) - .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False")) - .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2")) - .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) - .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName2")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2")))); - - asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", new JSONArray())); - - sniroHoming.processSolution(execution, asyncResponse.toString()); - - ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0); - - assertFalse(si.getVpnBondingLinks().isEmpty()); - VpnBondingLink link = si.getVpnBondingLinks().get(0); - assertNotNull(link); - assertFalse(link.getServiceProxies().isEmpty()); - - assertEquals("testServiceInstanceId1", link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId()); - assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo()); - assertEquals("testVnfHostName1", link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName()); - - assertEquals("testServiceInstanceId2", link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId()); - assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo()); - assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty()); - assertEquals("testPrimaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName()); - assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole()); - assertEquals("testSecondaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName()); - assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole()); - } - - @Test - public void testProcessSolution_success_1VpnLink_2Solutions(){ - beforeVpnBondingLink("1"); - - JSONObject asyncResponse = new JSONObject(); - asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed"); - JSONArray solution1 = new JSONArray(); - solution1.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject() - .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1"))) - .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False")) - .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1")) - .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) - .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId1")))); - solution1.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject() - .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2"))) - .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False")) - .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName2")) - .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) - .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName2")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId2")))); - - JSONArray solution2 = new JSONArray(); - solution2.put(new JSONObject().put("serviceResourceId", "testProxyId1").put("inventoryType", "service").put("solution", new JSONObject() - .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId3"))) - .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False")) - .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName3")) - .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli3")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) - .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId3")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId3")))); - solution2.put(new JSONObject().put("serviceResourceId", "testProxyId2").put("inventoryType", "service").put("solution", new JSONObject() - .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId4"))) - .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False")) - .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "primaryPnfName").put("value", "testPrimaryPnfName4")) - .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli4")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) - .put(new JSONObject().put("key", "secondaryPnfName").put("value", "testSecondaryPnfName4")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testSloudRegionId4")))); - - asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1).put(solution2)).put("licenseSolutions", new JSONArray())); - - sniroHoming.processSolution(execution, asyncResponse.toString()); - - ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0); - - assertFalse(si.getVpnBondingLinks().isEmpty()); - VpnBondingLink link = si.getVpnBondingLinks().get(0); - VpnBondingLink link2 = si.getVpnBondingLinks().get(1); - assertNotNull(link); - assertFalse(link.getServiceProxies().isEmpty()); - - assertEquals("testServiceInstanceId1", link.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId()); - assertNotNull(link.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo()); - assertEquals("testVnfHostName1", link.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName()); - - assertEquals("testServiceInstanceId2", link.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId()); - assertNotNull(link.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo()); - assertFalse(link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty()); - assertEquals("testPrimaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName()); - assertEquals("primary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole()); - assertEquals("testSecondaryPnfName2", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName()); - assertEquals("secondary", link.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole()); - - assertNotNull(link2); - assertFalse(link2.getServiceProxies().isEmpty()); - - assertEquals("testServiceInstanceId3", link2.getServiceProxy("testProxyId1").getServiceInstance().getServiceInstanceId()); - assertNotNull(link2.getServiceProxy("testProxyId1").getServiceInstance().getSolutionInfo()); - assertEquals("testVnfHostName3", link2.getServiceProxy("testProxyId1").getServiceInstance().getVnfs().get(0).getVnfName()); - - assertEquals("testServiceInstanceId4", link2.getServiceProxy("testProxyId2").getServiceInstance().getServiceInstanceId()); - assertNotNull(link2.getServiceProxy("testProxyId2").getServiceInstance().getSolutionInfo()); - assertFalse(link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().isEmpty()); - assertEquals("testPrimaryPnfName4", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getPnfName()); - assertEquals("primary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(0).getRole()); - assertEquals("testSecondaryPnfName4", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getPnfName()); - assertEquals("secondary", link2.getServiceProxy("testProxyId2").getServiceInstance().getPnfs().get(1).getRole()); - - } - - @Test - public void testProcessSolution_success_3VpnLink_2Solutions(){ - //TODO - } - - @Test - public void testProcessSolution_success_3Allotteds_1Solution(){ - beforeAllottedResource(); - - JSONObject asyncResponse = new JSONObject(); - asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed"); - JSONArray solution1 = new JSONArray(); - solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1").put("inventoryType", "service").put("solution", new JSONObject() - .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1"))) - .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True")) - .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1")) - .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) - .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1")))); - solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2").put("inventoryType", "service").put("solution", new JSONObject() - .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2"))) - .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True")) - .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2")) - .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) - .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2")))); - solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3").put("inventoryType", "cloud").put("solution", new JSONObject() - .put("identifierType", "cloudRegionId").put("identifiers", new JSONArray().put("testCloudRegionId3"))) - .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True")) - .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")) - .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3")))); - - asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", new JSONArray())); - - sniroHoming.processSolution(execution, asyncResponse.toString()); - - ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0); - - assertFalse(si.getAllottedResources().isEmpty()); - AllottedResource ar = si.getAllottedResources().get(0); - assertNotNull(ar); - assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId()); - assertNotNull(ar.getParentServiceInstance().getSolutionInfo()); - assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName()); - - AllottedResource ar2 = si.getAllottedResources().get(1); - assertNotNull(ar2); - assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId()); - assertNotNull(ar2.getParentServiceInstance().getSolutionInfo()); - assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName()); - - AllottedResource ar3 = si.getAllottedResources().get(2); - assertNotNull(ar3); - assertNotNull(ar3.getParentServiceInstance().getSolutionInfo()); - assertEquals("testCloudRegionId3", ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId()); - } - - @Test - public void testProcessSolution_success_3Allotteds1Vnf_1Solution(){ - beforeVnf(); - beforeAllottedResource(); - - JSONObject asyncResponse = new JSONObject(); - asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed"); - JSONArray solution1 = new JSONArray(); - JSONArray licenseSolution = new JSONArray(); - solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId1").put("inventoryType", "service").put("solution", new JSONObject() - .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId1"))) - .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True")) - .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName1")) - .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) - .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId1")))); - solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId2").put("inventoryType", "service").put("solution", new JSONObject() - .put("identifierType", "serviceInstanceId").put("identifiers", new JSONArray().put("testServiceInstanceId2"))) - .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True")) - .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "vnfHostName").put("value", "testVnfHostName2")) - .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")).put(new JSONObject().put("key", "aicVersion").put("value", "3")) - .put(new JSONObject().put("key", "vnfId").put("value", "testVnfId1")).put(new JSONObject().put("key", "cloudRegionId").put("value", "testCloudRegionId2")))); - solution1.put(new JSONObject().put("serviceResourceId", "testAllottedResourceId3").put("inventoryType", "cloud").put("solution", new JSONObject() - .put("identifierType", "cloudRegionId").put("identifiers", new JSONArray().put("testCloudRegionId3"))) - .put("assignmentInfo", new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "True")) - .put(new JSONObject().put("key", "cloudOwner").put("value", "aic")).put(new JSONObject().put("key", "aicClli").put("value", "testAicClli2")) - .put(new JSONObject().put("key", "aicVersion").put("value", "3")))); - - licenseSolution.put( - new JSONObject().put("serviceResourceId", "testVnfId1").put("entitlementPoolUUID", new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e").put("j1d563e8-e714-4393-8f99-cc480144a05e")) - .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e").put("b1d563e8-e714-4393-8f99-cc480144a05e"))); - - asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)).put("licenseSolutions", licenseSolution)); - - sniroHoming.processSolution(execution, asyncResponse.toString()); - - ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0); - - assertFalse(si.getAllottedResources().isEmpty()); - AllottedResource ar = si.getAllottedResources().get(0); - assertNotNull(ar); - assertEquals("testServiceInstanceId1", ar.getParentServiceInstance().getServiceInstanceId()); - assertNotNull(ar.getParentServiceInstance().getSolutionInfo()); - assertEquals("testVnfHostName1", ar.getParentServiceInstance().getVnfs().get(0).getVnfName()); - - AllottedResource ar2 = si.getAllottedResources().get(1); - assertNotNull(ar2); - assertEquals("testServiceInstanceId2", ar2.getParentServiceInstance().getServiceInstanceId()); - assertNotNull(ar2.getParentServiceInstance().getSolutionInfo()); - assertEquals("testVnfHostName2", ar2.getParentServiceInstance().getVnfs().get(0).getVnfName()); - - AllottedResource ar3 = si.getAllottedResources().get(2); - assertNotNull(ar3); - assertNotNull(ar3.getParentServiceInstance().getSolutionInfo()); - assertEquals("testCloudRegionId3", ar3.getParentServiceInstance().getSolutionInfo().getTargetedCloudRegion().getLcpCloudRegionId()); - - GenericVnf vnf = si.getVnfs().get(0); - assertNotNull(vnf); - assertNotNull(vnf.getLicense()); - assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size()); - assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0)); - - } - - @Test - public void testProcessSolution_success_1Vnf_1Solution(){ - beforeVnf(); - - JSONObject asyncResponse = new JSONObject(); - asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", "completed"); - JSONArray licenseSolution = new JSONArray(); - - licenseSolution.put( - new JSONObject().put("serviceResourceId", "testVnfId1").put("entitlementPoolUUID", new JSONArray().put("f1d563e8-e714-4393-8f99-cc480144a05e").put("j1d563e8-e714-4393-8f99-cc480144a05e")) - .put("licenseKeyGroupUUID", new JSONArray().put("s1d563e8-e714-4393-8f99-cc480144a05e").put("b1d563e8-e714-4393-8f99-cc480144a05e"))); - - asyncResponse.put("solutions", new JSONObject().put("licenseSolutions", licenseSolution)); - - sniroHoming.processSolution(execution, asyncResponse.toString()); - - ServiceInstance si = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0); - - GenericVnf vnf = si.getVnfs().get(0); - assertNotNull(vnf); - assertNotNull(vnf.getLicense()); - assertEquals(2, vnf.getLicense().getEntitlementPoolUuids().size()); - assertEquals(2, vnf.getLicense().getLicenseKeyGroupUuids().size()); - assertEquals("f1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getEntitlementPoolUuids().get(0)); - assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0)); - - - } - - @Test(expected = BpmnError.class) - public void testCallSniro_error_0Resources() throws BadResponseException, JsonProcessingException{ - - sniroHoming.callSniro(execution); - - verify(sniroClient, times(0)).postDemands(isA(SniroManagerRequest.class)); - } - - @Test(expected = BpmnError.class) - public void testCallSniro_error_badResponse() throws BadResponseException, JsonProcessingException{ - beforeAllottedResource(); - - mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}"; - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) - .willReturn(aResponse().withStatus(200) - .withHeader("Content-Type", "application/json") - .withBody(mockResponse))); - - sniroHoming.callSniro(execution); - - 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; @@ -87,32 +84,6 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { assertEquals(true,success); } - @Test - public void getUpdatedRequestTest() throws Exception{ - List 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"; @@ -145,18 +116,9 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { assertEquals(response,"00f704ca-c5e5-4f95-a72c-6889db7b0688createInstanceMSOALaCarte-Service-createInstance request was executed correctly.123WorkflowActionBB"); } - @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"),"00f704ca-c5e5-4f95-a72c-6889db7b0688createInstanceVIDError in WorkFlowAction7000"); - } - @Test public void rollbackExecutionPathTest(){ + execution.setVariable("handlingCode", "Rollback"); execution.setVariable("isRollback", false); List 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 ebbs = (List) 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 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 ebbs = (List) 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 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 ebbs = (List) execution.getVariable("flowsToExecute"); assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"UnassignNetworkBB"); @@ -253,8 +220,45 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { assertEquals(0,execution.getVariable("gCurrentSequence")); } + @Test + public void rollbackExecutionRollbackToAssignedTest(){ + execution.setVariable("isRollback", false); + execution.setVariable("handlingCode", "RollbackToAssigned"); + List 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 ebbs = (List) 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 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/SDNCClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java new file mode 100644 index 0000000000..cc1c5c5329 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java @@ -0,0 +1,82 @@ +/*- + * ============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; + +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 java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.junit.Test; +import org.onap.so.BaseIntegrationTest; +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; + +public class SDNCClientIT extends BaseIntegrationTest { + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/"; + + @Test + public void getTest() throws BadResponseException, MapperException, IOException { + String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientGetResponse.json"))); + String queryLink = "/topologyQuery"; + + stubFor(get(urlEqualTo(queryLink)) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json").withBody(responseJson))); + String response = SPY_sdncClient.get(queryLink); + JSONAssert.assertEquals(responseJson, response, false); + } + + @Test(expected = BadResponseException.class) + public void post404Test() throws BadResponseException, MapperException, IOException { + String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut404Response.json"))); + + String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; + + stubFor(post(urlMatching(queryLink)) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json").withBody(responseJson))); + + SPY_sdncClient.post("", SDNCTopology.NETWORK); + } + + @Test + public void post200Test() throws BadResponseException, MapperException, IOException { + String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut200Response.json"))); + + String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; + + stubFor(post(urlMatching(queryLink)) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json").withBody(responseJson))); + + String response = SPY_sdncClient.post("", SDNCTopology.NETWORK); + JSONAssert.assertEquals("", response, false); + } +} 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/SDNCClientTest.java deleted file mode 100644 index 66ec514039..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/*- - * ============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; - -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.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 { - 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)) - .willReturn(aResponse().withStatus(200) - .withHeader("Content-Type", "application/json").withBody(responseJson))); - String response = SPY_sdncClient.get(queryLink); - JSONAssert.assertEquals(responseJson, response, false); - } - - @Test(expected = BadResponseException.class) - public void post404Test() throws BadResponseException, MapperException, IOException { - String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut404Response.json"))); - - String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; - - wireMockRule.stubFor(post(urlMatching(queryLink)) - .willReturn(aResponse().withStatus(200) - .withHeader("Content-Type", "application/json").withBody(responseJson))); - - SPY_sdncClient.post("", SDNCTopology.NETWORK); - } - - @Test - public void post200Test() throws BadResponseException, MapperException, IOException { - String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut200Response.json"))); - - String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; - - wireMockRule.stubFor(post(urlMatching(queryLink)) - .willReturn(aResponse().withStatus(200) - .withHeader("Content-Type", "application/json").withBody(responseJson))); - - String response = SPY_sdncClient.post("", SDNCTopology.NETWORK); - JSONAssert.assertEquals("", response, false); - } -} 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: -- cgit 1.2.3-korg