From ec3bb1a85df07d4d65d428c40d45bacaab8bed8f Mon Sep 17 00:00:00 2001 From: ajay_dp001 Date: Fri, 20 Nov 2020 21:16:50 +0530 Subject: Update AAI-Simulator Support for Service Level Upgrade Issue-ID: INT-1592 Signed-off-by: ajay_dp001 Change-Id: I28f8cf22f7e6314ca746acef7850629cb8a85671 --- .../pnf-sw-upgrade/setup.sh | 6 + .../service-instance-aai.json | 45 +++ .../pnf-sw-upgrade/sorch/config/env | 2 +- .../sorch/config/populate-aai-simulator.sh | 17 +- .../controller/BusinessController.java | 328 +++------------- .../providers/ServiceInstanceCacheProvider.java | 32 ++ .../ServiceInstanceCacheProviderImpl.java | 78 ++++ .../org/onap/aaisimulator/utils/CacheName.java | 1 + .../controller/AaiSimulatorControllerTest.java | 65 ++++ .../controller/AbstractSpringBootTest.java | 65 ++++ .../controller/BusinessControllerTest.java | 109 ++++++ .../controller/LinesOfBusinessControllerTest.java | 143 +++++++ .../controller/PlatformControllerTest.java | 142 +++++++ .../controller/PnfsControllerTest.java | 72 ++++ .../ServiceDesignAndCreationControllerTest.java | 67 ++++ .../TestRestTemplateConfigration.java | 80 ++++ .../org/onap/aaisimulator/utils/TestConstants.java | 134 +++++++ .../utils/TestRestTemplateService.java | 79 ++++ .../org/onap/aaisimulator/utils/TestUtils.java | 190 +++++++++ .../controller/AaiSimulatorControllerTest.java | 65 ---- .../controller/AbstractSpringBootTest.java | 65 ---- .../controller/BusinessControllerTest.java | 397 ------------------- .../controller/CloudRegionsControllerTest.java | 420 -------------------- .../ExternalSystemEsrControllerTest.java | 233 ----------- .../controller/GenericVnfsControllerTest.java | 430 --------------------- .../controller/LinesOfBusinessControllerTest.java | 143 ------- .../controller/NodesControllerTest.java | 156 -------- .../controller/OwningEntityControllerTest.java | 199 ---------- .../controller/PlatformControllerTest.java | 142 ------- .../controller/PnfsControllerTest.java | 72 ---- .../controller/ProjectControllerTest.java | 205 ---------- .../ServiceDesignAndCreationControllerTest.java | 67 ---- .../TestRestTemplateConfigration.java | 80 ---- .../onap/so/aaisimulator/utils/TestConstants.java | 120 ------ .../utils/TestRestTemplateService.java | 79 ---- .../org/onap/so/aaisimulator/utils/TestUtils.java | 186 --------- .../resources/test-data/service-instance-aai.json | 45 +++ .../pnf-sw-upgrade/teardown.sh | 12 +- 38 files changed, 1420 insertions(+), 3351 deletions(-) create mode 100644 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/config/aai-simulator-populate-data/service-instance-aai.json create mode 100644 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/service/providers/ServiceInstanceCacheProvider.java create mode 100644 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/service/providers/ServiceInstanceCacheProviderImpl.java create mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/AaiSimulatorControllerTest.java create mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/AbstractSpringBootTest.java create mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/BusinessControllerTest.java create mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/LinesOfBusinessControllerTest.java create mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/PlatformControllerTest.java create mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/PnfsControllerTest.java create mode 100644 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java create mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/configuration/TestRestTemplateConfigration.java create mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/utils/TestConstants.java create mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/utils/TestRestTemplateService.java create mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/utils/TestUtils.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AaiSimulatorControllerTest.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AbstractSpringBootTest.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ExternalSystemEsrControllerTest.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PnfsControllerTest.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java delete mode 100644 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestRestTemplateService.java delete mode 100755 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java create mode 100644 plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/resources/test-data/service-instance-aai.json diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/setup.sh b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/setup.sh index b7d7e648..65cd576f 100755 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/setup.sh +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/setup.sh @@ -34,6 +34,12 @@ if [ "$MTU" == "" ]; then fi unset http_proxy https_proxy +# Prepare Environment +echo "Uninstall docker-py and reinstall docker." +pip uninstall -y docker-py +pip uninstall -y docker +pip install -U docker==2.7.0 + HOST_IP_ADDR=localhost ###################### setup so ############################## diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/config/aai-simulator-populate-data/service-instance-aai.json b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/config/aai-simulator-populate-data/service-instance-aai.json new file mode 100644 index 00000000..8ea4263b --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/config/aai-simulator-populate-data/service-instance-aai.json @@ -0,0 +1,45 @@ +{ + "service-instance-id": "5df8b6de-2083-11e7-93ae-92361f002676", + "service-instance-name": "Service_Ete_Name123452c4-3d7f-42ce-8188-818fab951269", + "environment-context": "General_Revenue-Bearing", + "workload-context": "Production", + "model-version-id": "d88da85c-d9e8-4f73-b837-3a72a431622b", + "modelInvariantId": "fe41489e-1563-46a3-b90a-1db629e4375b", + "resource-version": "1595258335377", + "selflink": "restconf/config/GENERIC-RESOURCE-API:services/service/5df8b6de-2083-11e7-93ae-92361f002676/service-data/service-topology/", + "orchestration-status": "Assigned", + "relationship-list": { + "relationship": [ + { + "related-to": "owning-entity", + "related-link": "/aai/v11/business/owning-entities/owning-entity/67f2e84c-734d-4e90-a1e4-d2ffa2e75849", + "relationship-data": [ + { + "relationship-key": "owning-entity.owning-entity-id", + "relationship-value": "67f2e84c-734d-4e90-a1e4-d2ffa2e75849" + } + ] + }, + { + "related-to": "pnf", + "related-link": "/aai/v11/network/pnfs/pnf/PNFDemo", + "relationship-data": [ + { + "relationship-key": "pnf.pnf-name", + "relationship-value": "PNFDemo" + } + ] + }, + { + "related-to": "pnf", + "related-link": "/aai/v11/network/pnfs/pnf/PNFDemo1", + "relationship-data": [ + { + "relationship-key": "pnf.pnf-name", + "relationship-value": "PNFDemo1" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/config/env b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/config/env index 95469f90..ab4e3df4 100644 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/config/env +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/config/env @@ -1,6 +1,6 @@ NEXUS_DOCKER_REPO_MSO=nexus3.onap.org:10001 DOCKER_ENVIRONMENT=remote -TAG=1.7.5 +TAG=1.7.7-STAGING-latest TIME_OUT_DEFAULT_VALUE_SEC=1200 PROJECT_NAME=pnfSwU DEFAULT_NETWORK_NAME=pnfswu_default diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/config/populate-aai-simulator.sh b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/config/populate-aai-simulator.sh index 6852e3f9..26673fcf 100755 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/config/populate-aai-simulator.sh +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/config/populate-aai-simulator.sh @@ -62,6 +62,7 @@ populate_aai_simulator() ESR_SYSTEM_INFO_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/esr-system-info.json CLOUD_ESR_SYSTEM_INFO_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/cloud-esr-system-info.json PNF_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/pnf.json + SERVICE_INSTANCE_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/service-instance-aai.json STATUS_CODE_ACCEPTED="202" echo "$SCRIPT_NAME $(current_timestamp): checking health of AAI Simulator" @@ -76,14 +77,6 @@ populate_aai_simulator() echo "$SCRIPT_NAME $(current_timestamp): Populating AAI Simulator" - echo "$SCRIPT_NAME $(current_timestamp): Adding Cloud-Customer Data" - status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/customers/customer/DemoCustomer -X PUT -d @"$CUSTOMER_JSON_FILE") - - if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then - echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put customer data in AAI Simulator. Status code received: $status_code" - exit 1 - fi - echo "$SCRIPT_NAME $(current_timestamp): Adding Project" status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/projects/project/PnfSwUCsitProject -X PUT -d @"$PROJECT_JSON_FILE") @@ -164,6 +157,14 @@ populate_aai_simulator() exit 1 fi + echo "$SCRIPT_NAME $(current_timestamp): Adding ServiceInstance" + status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/customers/customer/5df8b6de-2083-11e7-93ae-92361f002676/service-subscriptions/service-subscription/pNF/service-instances/service-instance/ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce -X PUT -d @$"$SERVICE_INSTANCE_JSON_FILE") + + if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then + echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put ServiceInstance data in AAI Simulator. Status code received: $status_code" + exit 1 + fi + echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator Populated Successfully" } diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/controller/BusinessController.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/controller/BusinessController.java index 8559e8aa..f6ee7e64 100755 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/controller/BusinessController.java +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/controller/BusinessController.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,38 +19,22 @@ */ package org.onap.aaisimulator.controller; -import static org.onap.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; -import static org.onap.aaisimulator.utils.Constants.CUSTOMER_TYPE; import static org.onap.aaisimulator.utils.Constants.CUSTOMER_URL; -import static org.onap.aaisimulator.utils.Constants.GENERIC_VNF; -import static org.onap.aaisimulator.utils.Constants.GENERIC_VNF_VNF_ID; import static org.onap.aaisimulator.utils.Constants.SERVICE_RESOURCE_TYPE; -import static org.onap.aaisimulator.utils.Constants.SERVICE_SUBSCRIPTION; import static org.onap.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; import static org.onap.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity; -import static org.onap.aaisimulator.utils.RequestErrorResponseUtils.getResourceVersion; + import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.MediaType; -import org.onap.aai.domain.yang.Customer; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.aai.domain.yang.GenericVnfs; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipData; import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aai.domain.yang.ServiceInstances; -import org.onap.aai.domain.yang.ServiceSubscription; -import org.onap.aaisimulator.models.NodeServiceInstance; -import org.onap.aaisimulator.service.providers.CustomerCacheServiceProvider; -import org.onap.aaisimulator.service.providers.GenericVnfCacheServiceProvider; -import org.onap.aaisimulator.service.providers.NodesCacheServiceProvider; +import org.onap.aaisimulator.service.providers.ServiceInstanceCacheProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -60,297 +44,87 @@ import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -/** - * @author waqas.ikram@ericsson.com - * - */ @Controller @RequestMapping(path = CUSTOMER_URL) public class BusinessController { private static final Logger LOGGER = LoggerFactory.getLogger(BusinessController.class); - private final CustomerCacheServiceProvider cacheServiceProvider; - private final NodesCacheServiceProvider nodesCacheServiceProvider; - private final GenericVnfCacheServiceProvider genericVnfCacheServiceProvider; - - @Autowired - public BusinessController(final CustomerCacheServiceProvider cacheServiceProvider, - final NodesCacheServiceProvider nodesCacheServiceProvider, - final GenericVnfCacheServiceProvider genericVnfCacheServiceProvider) { - this.cacheServiceProvider = cacheServiceProvider; - this.nodesCacheServiceProvider = nodesCacheServiceProvider; - this.genericVnfCacheServiceProvider = genericVnfCacheServiceProvider; - } - - @GetMapping(value = "{global-customer-id}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity getCustomer(@PathVariable("global-customer-id") final String globalCustomerId, - final HttpServletRequest request) { - LOGGER.info("Will retrieve customer for 'global customer id': {} ...", globalCustomerId); - - final Optional optional = cacheServiceProvider.getCustomer(globalCustomerId); - if (optional.isPresent()) { - final Customer customer = optional.get(); - LOGGER.info("found customer {} in cache", customer); - return ResponseEntity.ok(customer); - } - LOGGER.error("Couldn't find {} in cache", globalCustomerId); - return getRequestErrorResponseEntity(request, CUSTOMER_TYPE); - } - - @PutMapping(value = "/{global-customer-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity putCustomer(@RequestBody final Customer customer, - @PathVariable("global-customer-id") final String globalCustomerId, final HttpServletRequest request) { - LOGGER.info("Will put customer for 'global customer id': {} ...", globalCustomerId); - - if (customer.getResourceVersion() == null || customer.getResourceVersion().isEmpty()) { - customer.setResourceVersion(getResourceVersion()); - - } - cacheServiceProvider.putCustomer(globalCustomerId, customer); - return ResponseEntity.accepted().build(); + private final ServiceInstanceCacheProvider svcInstanceCacheSvcProvider; + @Autowired + public BusinessController(final ServiceInstanceCacheProvider serviceInstanceCacheProvider) { + this.svcInstanceCacheSvcProvider = serviceInstanceCacheProvider; } - @GetMapping(value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}", - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity getCustomer(@PathVariable("global-customer-id") final String globalCustomerId, - @PathVariable("service-type") final String serviceType, final HttpServletRequest request) { - LOGGER.info("Will retrieve service subscription for 'global customer id': {} and 'service type': {} ...", - globalCustomerId, serviceType); - - final Optional optional = - cacheServiceProvider.getServiceSubscription(globalCustomerId, serviceType); - if (optional.isPresent()) { - final ServiceSubscription serviceSubscription = optional.get(); - LOGGER.info("found service subscription {} in cache", serviceSubscription); - return ResponseEntity.ok(serviceSubscription); - } - - LOGGER.error("Couldn't find 'global customer id': {} and 'service type': {} in cache", globalCustomerId, - serviceType); - return getRequestErrorResponseEntity(request, SERVICE_SUBSCRIPTION); - } + @PutMapping(value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}", + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity putServiceInstance(@PathVariable("global-customer-id") final String globalCustomerId, + @PathVariable("service-type") final String serviceType, + @PathVariable(name = "service-instance-id") final String serviceInstanceId, + @RequestBody final ServiceInstance serviceInstance, final HttpServletRequest request) { - @PutMapping(value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}", - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity putServiceSubscription(@PathVariable("global-customer-id") final String globalCustomerId, - @PathVariable("service-type") final String serviceType, - @RequestBody final ServiceSubscription serviceSubscription, final HttpServletRequest request) { - LOGGER.info("Will add service subscription for 'global customer id': {} and 'service type': {} ...", - globalCustomerId, serviceType); + LOGGER.info("Add service instance to cache for 'global customer id': {}, 'service type': {} and " + + "'service instance id: '{}..", globalCustomerId, serviceType, serviceInstanceId); - if (cacheServiceProvider.putServiceSubscription(globalCustomerId, serviceType, serviceSubscription)) { - LOGGER.info("Successfully add service subscription in cache ..."); + if (svcInstanceCacheSvcProvider.putServiceInstance(globalCustomerId, serviceInstance)) { + LOGGER.info("Successfully added service instance to cache ..."); return ResponseEntity.accepted().build(); } - LOGGER.error("Couldn't add service subscription using 'global customer id': {} and 'service type': {}", - globalCustomerId, serviceType); - return getRequestErrorResponseEntity(request, SERVICE_SUBSCRIPTION); - } - - @GetMapping( - value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances", - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity getSericeInstances(@PathVariable("global-customer-id") final String globalCustomerId, - @PathVariable("service-type") final String serviceType, - @RequestParam(name = "service-instance-name") final String serviceInstanceName, - @RequestParam(name = "depth", required = false) final Integer depth, final HttpServletRequest request) { - - LOGGER.info( - "Will retrieve service instances for 'global customer id': {}, 'service type': {} and 'service instance name: '{} with depth: {}...", - globalCustomerId, serviceType, serviceInstanceName, depth); - - final Optional optional = - cacheServiceProvider.getServiceInstances(globalCustomerId, serviceType, serviceInstanceName); - if (optional.isPresent()) { - final ServiceInstances serviceInstances = optional.get(); - LOGGER.info("found service instance {} in cache", serviceInstances); - return ResponseEntity.ok(serviceInstances); - } - LOGGER.error( - "Couldn't find 'global customer id': {}, 'service type': {} and 'service instance name': {} with depth: {} in cache", - globalCustomerId, serviceType, serviceInstanceName, depth); - return getRequestErrorResponseEntity(request); - } - - @GetMapping( - value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}", - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity getSericeInstance(@PathVariable("global-customer-id") final String globalCustomerId, - @PathVariable("service-type") final String serviceType, - @PathVariable(name = "service-instance-id") final String serviceInstanceId, - @RequestParam(name = "depth", required = false) final Integer depth, - @RequestParam(name = "resultIndex", required = false) final Integer resultIndex, - @RequestParam(name = "resultSize", required = false) final Integer resultSize, - @RequestParam(name = "format", required = false) final String format, final HttpServletRequest request) { - - LOGGER.info( - "Will retrieve service instances for 'global customer id': {}, 'service type': {} and 'service instance id: '{} with depth: {}, resultIndex:{}, resultSize: {} and format: {}...", - globalCustomerId, serviceType, serviceInstanceId, depth, resultIndex, resultSize, format); - - final Optional optional = - cacheServiceProvider.getServiceInstance(globalCustomerId, serviceType, serviceInstanceId); - if (optional.isPresent()) { - final ServiceInstance serviceInstance = optional.get(); - LOGGER.info("found service instance {} in cache", serviceInstance); - return ResponseEntity.ok(serviceInstance); - } LOGGER.error( - "Couldn't find 'global customer id': {}, 'service type': {} and 'service instance id': {} with depth: {}, resultIndex:{}, resultSize: {} and format: {} in cache", - globalCustomerId, serviceType, serviceInstanceId, depth, resultIndex, resultSize, format); - return getRequestErrorResponseEntity(request); + "Couldn't add service instance for 'global customer id': {},'service type': {} and 'service instance id: '{} ...", + globalCustomerId, serviceType, serviceInstanceId); + return getRequestErrorResponseEntity(request, SERVICE_RESOURCE_TYPE); } - @PutMapping( - value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}", - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity putSericeInstance(@PathVariable("global-customer-id") final String globalCustomerId, - @PathVariable("service-type") final String serviceType, - @PathVariable(name = "service-instance-id") final String serviceInstanceId, - @RequestHeader(value = X_HTTP_METHOD_OVERRIDE, required = false) final String invocationId, - @RequestBody final ServiceInstance serviceInstance, final HttpServletRequest request) { + @GetMapping(value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}", + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity getServiceInstance(@PathVariable("global-customer-id") final String globalCustomerId, + @PathVariable("service-type") final String serviceType, + @PathVariable(name = "service-instance-id") final String serviceInstanceId, + @RequestParam(name = "depth", required = false) final Integer depth, + @RequestParam(name = "resultIndex", required = false) final Integer resultIndex, + @RequestParam(name = "resultSize", required = false) final Integer resultSize, + @RequestParam(name = "format", required = false) final String format, final HttpServletRequest request) { LOGGER.info( - "Will add service instance for 'global customer id': {}, 'service type': {} and 'service instance id: '{} ...", - globalCustomerId, serviceType, serviceInstanceId); + "Retrieve service instances for 'global customer id': {}, 'service type': {} and 'service instance id: '{} with depth: {}, resultIndex:{}, resultSize: {} and format: {}...", + globalCustomerId, serviceType, serviceInstanceId, depth, resultIndex, resultSize, format); - if (serviceInstance.getResourceVersion() == null || serviceInstance.getResourceVersion().isEmpty()) { - serviceInstance.setResourceVersion(getResourceVersion()); - } + final Optional svcInstance = + svcInstanceCacheSvcProvider.getServiceInstance(globalCustomerId); - if (cacheServiceProvider.putServiceInstance(globalCustomerId, serviceType, serviceInstanceId, - serviceInstance)) { - nodesCacheServiceProvider.putNodeServiceInstance(serviceInstanceId, new NodeServiceInstance( - globalCustomerId, serviceType, serviceInstanceId, SERVICE_RESOURCE_TYPE, request.getRequestURI())); - return ResponseEntity.accepted().build(); + if (svcInstance.isPresent()) { + final ServiceInstance serviceInstance = svcInstance.get(); + LOGGER.info("Found service instance {} in cache", serviceInstance); + return ResponseEntity.ok(serviceInstance); } - LOGGER.error("Couldn't add 'global customer id': {}, 'service type': {} and 'service instance id': {} to cache", - globalCustomerId, serviceType, serviceInstanceId); + LOGGER.error( + "Couldn't find 'global customer id': {}, 'service type': {} and 'service instance id': {} with depth: {}, resultIndex:{}, resultSize: {} and format: {} in cache", + globalCustomerId, serviceType, serviceInstanceId, depth, resultIndex, resultSize, format); return getRequestErrorResponseEntity(request); } - @PostMapping( - value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}", - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity patchSericeInstance(@PathVariable("global-customer-id") final String globalCustomerId, - @PathVariable("service-type") final String serviceType, - @PathVariable(name = "service-instance-id") final String serviceInstanceId, - @RequestHeader(value = X_HTTP_METHOD_OVERRIDE, required = false) final String xHttpHeaderOverride, - @RequestBody final ServiceInstance serviceInstance, final HttpServletRequest request) { + @PostMapping(value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}", + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity patchServiceInstance(@PathVariable("global-customer-id") final String globalCustomerId, + @PathVariable("service-type") final String serviceType, + @PathVariable(name = "service-instance-id") final String serviceInstanceId, + @RequestHeader(value = X_HTTP_METHOD_OVERRIDE, required = false) final String xHttpHeaderOverride, + @RequestBody final ServiceInstance serviceInstance, final HttpServletRequest request) { LOGGER.info( - "Will post service instance for 'global customer id': {}, 'service type': {}, 'service instance id: '{} and '{}': {}...", - globalCustomerId, serviceType, serviceInstanceId, X_HTTP_METHOD_OVERRIDE, xHttpHeaderOverride); + "Post service instance for 'global customer id': {}, 'service type': {}, 'service instance id: '{} and '{}': {}...", + globalCustomerId, serviceType, serviceInstanceId, X_HTTP_METHOD_OVERRIDE, xHttpHeaderOverride); if (HttpMethod.PATCH.toString().equalsIgnoreCase(xHttpHeaderOverride)) { - cacheServiceProvider.patchServiceInstance(globalCustomerId, serviceType, serviceInstanceId, - serviceInstance); + svcInstanceCacheSvcProvider.patchServiceInstance(globalCustomerId, serviceInstance); return ResponseEntity.accepted().build(); } LOGGER.error("{} not supported ... ", xHttpHeaderOverride); return getRequestErrorResponseEntity(request); } - - - @GetMapping( - value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}/related-to/generic-vnfs", - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity getRelatedToGenericVnf(@PathVariable("global-customer-id") final String globalCustomerId, - @PathVariable("service-type") final String serviceType, - @PathVariable(name = "service-instance-id") final String serviceInstanceId, - @RequestParam(name = "vnf-name", required = true) final String vnfName, final HttpServletRequest request) { - - LOGGER.info( - "Will retrieve generic vnf related to information for 'global customer id': {}, 'service type': {} and 'service instance id: '{} with vnfname: {}...", - globalCustomerId, serviceType, serviceInstanceId, vnfName); - - final Optional optional = - cacheServiceProvider.getRelationship(globalCustomerId, serviceType, serviceInstanceId, vnfName); - - if (optional.isPresent()) { - - final Relationship relationship = optional.get(); - final Optional relationshipDataOptional = relationship.getRelationshipData().stream() - .filter(existing -> GENERIC_VNF_VNF_ID.equals(existing.getRelationshipKey())).findFirst(); - - if (relationshipDataOptional.isPresent()) { - final RelationshipData relationshipData = relationshipDataOptional.get(); - final String vnfId = relationshipData.getRelationshipValue(); - final Optional genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(vnfId); - if (genericVnfOptional.isPresent()) { - final GenericVnfs genericVnfs = new GenericVnfs(); - genericVnfs.getGenericVnf().add(genericVnfOptional.get()); - LOGGER.info("found service instance {} in cache", relationship); - return ResponseEntity.ok(genericVnfs); - } - } - } - LOGGER.error( - "Couldn't find generic vnf related to information for 'global customer id': {}, 'service type': {} and 'service instance id: '{} with vnfname: {}...", - globalCustomerId, serviceType, serviceInstanceId, vnfName); - return getRequestErrorResponseEntity(request, GENERIC_VNF); - } - - @PutMapping( - value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}" - + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL, - consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity putSericeInstanceRelationShip( - @PathVariable("global-customer-id") final String globalCustomerId, - @PathVariable("service-type") final String serviceType, - @PathVariable(name = "service-instance-id") final String serviceInstanceId, - @RequestBody final Relationship relationship, final HttpServletRequest request) { - - LOGGER.info( - "Will add {} relationship for 'global customer id': {}, 'service type': {} and 'service instance id: '{} ...", - relationship.getRelatedTo(), globalCustomerId, serviceType, serviceInstanceId); - final Optional optional = cacheServiceProvider.addRelationShip(globalCustomerId, serviceType, - serviceInstanceId, relationship, request.getRequestURI()); - - if (optional.isPresent()) { - final Relationship resultantRelationship = optional.get(); - LOGGER.info("Relationship add, sending resultant relationship: {} in response ...", resultantRelationship); - return ResponseEntity.accepted().body(resultantRelationship); - } - - LOGGER.error( - "Couldn't add {} relationship for 'global customer id': {}, 'service type': {} and 'service instance id: '{} ...", - relationship.getRelatedTo(), globalCustomerId, serviceType, serviceInstanceId); - - return getRequestErrorResponseEntity(request); - } - - @DeleteMapping( - value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}", - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity deleteSericeInstance(@PathVariable("global-customer-id") final String globalCustomerId, - @PathVariable("service-type") final String serviceType, - @PathVariable(name = "service-instance-id") final String serviceInstanceId, - @RequestParam(name = "resource-version") final String resourceVersion, final HttpServletRequest request) { - - LOGGER.info( - "Will delete SericeInstance for 'global-customer-id': {}, 'service-type': {}, 'service-instance-id': {} and 'resource-version': {}", - globalCustomerId, serviceType, serviceInstanceId, resourceVersion); - - if (cacheServiceProvider.deleteSericeInstance(globalCustomerId, serviceType, serviceInstanceId, - resourceVersion)) { - LOGGER.info( - "Successfully deleted SericeInstance from cache for 'global-customer-id': {}, 'service-type': {}, 'service-instance-id': {} and 'resource-version': {}", - globalCustomerId, serviceType, serviceInstanceId, resourceVersion); - return ResponseEntity.noContent().build(); - } - - LOGGER.error( - "Unable to delete SericeInstance from cache for 'global-customer-id': {}, 'service-type': {}, 'service-instance-id': {} and 'resource-version': {}", - globalCustomerId, serviceType, serviceInstanceId, resourceVersion); - - return getRequestErrorResponseEntity(request); - - } -} +} \ No newline at end of file diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/service/providers/ServiceInstanceCacheProvider.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/service/providers/ServiceInstanceCacheProvider.java new file mode 100644 index 00000000..fc21eb69 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/service/providers/ServiceInstanceCacheProvider.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.aaisimulator.service.providers; + +import java.util.Optional; +import org.onap.aai.domain.yang.ServiceInstance; + +public interface ServiceInstanceCacheProvider { + + boolean patchServiceInstance(final String globalCustomerId, final ServiceInstance serviceInstance); + + Optional getServiceInstance(final String globalCustomerId); + + boolean putServiceInstance(final String serviceInstanceId, final ServiceInstance serviceInstance); +} \ No newline at end of file diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/service/providers/ServiceInstanceCacheProviderImpl.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/service/providers/ServiceInstanceCacheProviderImpl.java new file mode 100644 index 00000000..57450ed6 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/service/providers/ServiceInstanceCacheProviderImpl.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.aaisimulator.service.providers; + +import static org.onap.aaisimulator.utils.CacheName.SERVICE_INSTANCE_CACHE; + +import java.util.Optional; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.aaisimulator.cache.provider.AbstractCacheServiceProvider; +import org.onap.aaisimulator.utils.ShallowBeanCopy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.stereotype.Service; + +@Service +public class ServiceInstanceCacheProviderImpl extends AbstractCacheServiceProvider implements + ServiceInstanceCacheProvider { + + private static final Logger LOGGER = LoggerFactory.getLogger(ServiceInstanceCacheProviderImpl.class); + + private final Cache cache; + + @Autowired + public ServiceInstanceCacheProviderImpl(final CacheManager cacheManager) { + super(cacheManager); + cache = getCache(SERVICE_INSTANCE_CACHE.getName()); + } + + @Override + public boolean patchServiceInstance(String globalCustomerId, ServiceInstance serviceInstance) { + final Optional svcInstance = getServiceInstance(globalCustomerId); + if (svcInstance.isPresent()) { + final ServiceInstance cachedSvcInstance = svcInstance.get(); + try { + ShallowBeanCopy.copy(serviceInstance, cachedSvcInstance); + return true; + } catch (final Exception exception) { + LOGGER.error("Unable to update ServiceInstance for globalCustomerId: {}", globalCustomerId, exception); + } + } + LOGGER.error("Unable to find ServiceInstance for globalCustomerId : {}", globalCustomerId); + return false; + } + + @Override + public Optional getServiceInstance(final String globalCustomerId) { + LOGGER.info("Getting Service Instance with key: {} in cache ...", globalCustomerId); + final ServiceInstance svcInstance = cache.get(globalCustomerId, ServiceInstance.class); + return Optional.ofNullable(svcInstance); + } + + @Override + public boolean putServiceInstance(String globalCustomerId, ServiceInstance serviceInstance) { + LOGGER.info("Adding ServiceInstance: {} with key: {} in cache ...", serviceInstance, globalCustomerId); + cache.put(globalCustomerId, serviceInstance); + return true; + } +} \ No newline at end of file diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/utils/CacheName.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/utils/CacheName.java index 63e7e261..53d2dff2 100755 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/utils/CacheName.java +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/main/java/org/onap/aaisimulator/utils/CacheName.java @@ -26,6 +26,7 @@ package org.onap.aaisimulator.utils; public enum CacheName { CUSTOMER_CACHE("customer-cache"), + SERVICE_INSTANCE_CACHE("service-instance-cache"), PROJECT_CACHE("project-cache"), NODES_CACHE("nodes-cache"), GENERIC_VNF_CACHE("generic-vnf-cache"), diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/AaiSimulatorControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/AaiSimulatorControllerTest.java new file mode 100755 index 00000000..af9b2367 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/AaiSimulatorControllerTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aaisimulator.utils.Constants; +import org.onap.aaisimulator.utils.TestConstants; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ActiveProfiles("test") +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@Configuration +public class AaiSimulatorControllerTest { + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Test + public void test_healthCheck_matchContent() { + final String url = getBaseUrl() + "/healthcheck"; + final ResponseEntity object = restTemplate.getForEntity(url, String.class); + + assertEquals(Constants.HEALTHY, object.getBody()); + } + + private String getBaseUrl() { + return "https://localhost:" + port + TestConstants.BASE_URL_V17; + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/AbstractSpringBootTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/AbstractSpringBootTest.java new file mode 100755 index 00000000..4f2eab27 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/AbstractSpringBootTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.aaisimulator.controller; + +import java.util.List; +import org.junit.runner.RunWith; +import org.onap.aai.domain.yang.RelatedToProperty; +import org.onap.aai.domain.yang.RelationshipData; +import org.onap.aaisimulator.utils.TestRestTemplateService; +import org.onap.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ActiveProfiles("test") +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@Configuration +public abstract class AbstractSpringBootTest { + + @LocalServerPort + private int port; + + @Autowired + protected TestRestTemplateService testRestTemplateService; + + public String getUrl(final String... urls) { + return TestUtils.getUrl(port, urls); + } + + public RelationshipData getRelationshipData(final List relationshipData, final String key) { + return relationshipData.stream().filter(data -> data.getRelationshipKey().equals(key)).findFirst().orElse(null); + } + + public RelatedToProperty getRelatedToProperty(final List relatedToPropertyList, + final String key) { + return relatedToPropertyList.stream().filter(data -> data.getPropertyKey().equals(key)).findFirst() + .orElse(null); + } +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/BusinessControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/BusinessControllerTest.java new file mode 100755 index 00000000..9bab789d --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/BusinessControllerTest.java @@ -0,0 +1,109 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.onap.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; +import static org.onap.aaisimulator.utils.TestConstants.CUSTOMER_BASE_URL; +import static org.onap.aaisimulator.utils.TestConstants.SVC_INSTANCE_CUSTOMER_ID; +import static org.onap.aaisimulator.utils.TestConstants.SVC_INSTANCE_CUSTOMER_NAME; +import static org.onap.aaisimulator.utils.TestConstants.SVC_INSTANCE_URL; +import static org.onap.aaisimulator.utils.TestConstants.SVC_SUBSCRIPTIONS_URL; +import static org.onap.aaisimulator.utils.TestUtils.getSvcInstance; + +import java.io.IOException; +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.aaisimulator.service.providers.CustomerCacheServiceProvider; +import org.onap.aaisimulator.utils.Constants; +import org.onap.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +public class BusinessControllerTest extends AbstractSpringBootTest { + + @Autowired + private CustomerCacheServiceProvider cacheServiceProvider; + + @After + public void after() { + cacheServiceProvider.clearAll(); + } + + @Test + public void test_getSvcInstance_usingServiceInstanceId_fromCache() throws Exception { + final String url = getUrl(CUSTOMER_BASE_URL, SVC_SUBSCRIPTIONS_URL, SVC_INSTANCE_URL); + + final ResponseEntity responseEntity = testRestTemplateService + .invokeHttpPut(url, getSvcInstance(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + + final ResponseEntity actual = testRestTemplateService + .invokeHttpGet(url, ServiceInstance.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final ServiceInstance actualServiceInstance = actual.getBody(); + + assertEquals(SVC_INSTANCE_CUSTOMER_NAME, actualServiceInstance.getServiceInstanceName()); + assertEquals(SVC_INSTANCE_CUSTOMER_ID, actualServiceInstance.getServiceInstanceId()); + } + + @Test + public void test_postForServiceInstanceId_fromCache() throws Exception { + addServiceInstnceToCache(); + final HttpHeaders httpHeaders = testRestTemplateService.getHttpHeaders(); + httpHeaders.add(X_HTTP_METHOD_OVERRIDE, HttpMethod.PATCH.toString()); + httpHeaders.remove(HttpHeaders.CONTENT_TYPE); + httpHeaders.add(HttpHeaders.CONTENT_TYPE, Constants.APPLICATION_MERGE_PATCH_JSON); + + final String svcInstanceUrl = getUrl(CUSTOMER_BASE_URL, SVC_SUBSCRIPTIONS_URL, SVC_INSTANCE_URL); + final ResponseEntity postServiceInstanceResponse = testRestTemplateService + .invokeHttpPost(httpHeaders, svcInstanceUrl, TestUtils.getSvcInstance(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, postServiceInstanceResponse.getStatusCode()); + + final ResponseEntity response = + testRestTemplateService.invokeHttpGet(svcInstanceUrl, ServiceInstance.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final ServiceInstance actualServiceInstance = response.getBody(); + + assertEquals(SVC_INSTANCE_CUSTOMER_NAME, actualServiceInstance.getServiceInstanceName()); + assertEquals(SVC_INSTANCE_CUSTOMER_ID, actualServiceInstance.getServiceInstanceId()); + + } + + private void addServiceInstnceToCache() throws Exception, IOException { + final ResponseEntity serviceInstanceResponse = + testRestTemplateService.invokeHttpPut(getUrl(CUSTOMER_BASE_URL, SVC_SUBSCRIPTIONS_URL, SVC_INSTANCE_URL), + TestUtils.getSvcInstance(), Void.class); + assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode()); + } +} \ No newline at end of file diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/LinesOfBusinessControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/LinesOfBusinessControllerTest.java new file mode 100755 index 00000000..0b6cfb50 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/LinesOfBusinessControllerTest.java @@ -0,0 +1,143 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; +import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; +import static org.onap.aaisimulator.utils.TestConstants.LINE_OF_BUSINESS_NAME; +import static org.onap.aaisimulator.utils.TestConstants.VNF_ID; +import java.util.List; +import java.util.Optional; +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.LineOfBusiness; +import org.onap.aai.domain.yang.RelatedToProperty; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipData; +import org.onap.aaisimulator.models.Format; +import org.onap.aaisimulator.models.Results; +import org.onap.aaisimulator.service.providers.LinesOfBusinessCacheServiceProvider; +import org.onap.aaisimulator.utils.Constants; +import org.onap.aaisimulator.utils.TestConstants; +import org.onap.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class LinesOfBusinessControllerTest extends AbstractSpringBootTest { + + @Autowired + private LinesOfBusinessCacheServiceProvider linesOfBusinessCacheServiceProvider; + + @After + public void after() { + linesOfBusinessCacheServiceProvider.clearAll(); + } + + @Test + public void test_putLineOfBusiness_successfullyAddedToCache() throws Exception { + + final String url = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME); + final ResponseEntity lineOfBusinessResponse = + testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class); + assertEquals(HttpStatus.ACCEPTED, lineOfBusinessResponse.getStatusCode()); + + final ResponseEntity response = + testRestTemplateService.invokeHttpGet(url, LineOfBusiness.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final LineOfBusiness actualLineOfBusiness = response.getBody(); + assertEquals(LINE_OF_BUSINESS_NAME, actualLineOfBusiness.getLineOfBusinessName()); + assertNotNull("resource version should not be null", actualLineOfBusiness.getResourceVersion()); + + } + + @Test + public void test_getLineOfBusinessWithFormatCount() throws Exception { + + final String url = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME); + final ResponseEntity lineOfBusinessResponse = + testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class); + assertEquals(HttpStatus.ACCEPTED, lineOfBusinessResponse.getStatusCode()); + + final ResponseEntity response = testRestTemplateService + .invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final Results result = response.getBody(); + assertNotNull(result.getValues()); + assertFalse(result.getValues().isEmpty()); + assertEquals(1, result.getValues().get(0).get(Constants.LINE_OF_BUSINESS)); + } + + + @Test + public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception { + + final String url = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME); + final ResponseEntity response = + testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class); + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + final String relationShipUrl = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME, + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); + + final ResponseEntity responseEntity = testRestTemplateService.invokeHttpPut(relationShipUrl, + TestUtils.getGenericVnfRelationShip(), Relationship.class); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + + final Optional optional = + linesOfBusinessCacheServiceProvider.getLineOfBusiness(LINE_OF_BUSINESS_NAME); + assertTrue(optional.isPresent()); + + final LineOfBusiness actual = optional.get(); + + assertNotNull(actual.getRelationshipList()); + final List relationshipList = actual.getRelationshipList().getRelationship(); + assertFalse("Relationship list should not be empty", relationshipList.isEmpty()); + final Relationship relationship = relationshipList.get(0); + + assertEquals(GENERIC_VNF_URL + VNF_ID, relationship.getRelatedLink()); + assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty()); + assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty()); + + final RelationshipData relationshipData = relationship.getRelationshipData().get(0); + assertEquals(Constants.GENERIC_VNF_VNF_ID, relationshipData.getRelationshipKey()); + assertEquals(TestConstants.VNF_ID, relationshipData.getRelationshipValue()); + + final RelatedToProperty relatedToProperty = relationship.getRelatedToProperty().get(0); + assertEquals(Constants.GENERIC_VNF_VNF_NAME, relatedToProperty.getPropertyKey()); + assertEquals(TestConstants.GENERIC_VNF_NAME, relatedToProperty.getPropertyValue()); + + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/PlatformControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/PlatformControllerTest.java new file mode 100755 index 00000000..00c66388 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/PlatformControllerTest.java @@ -0,0 +1,142 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; +import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; +import static org.onap.aaisimulator.utils.TestConstants.PLATFORM_NAME; +import static org.onap.aaisimulator.utils.TestConstants.VNF_ID; +import java.util.List; +import java.util.Optional; +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.Platform; +import org.onap.aai.domain.yang.RelatedToProperty; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipData; +import org.onap.aaisimulator.models.Format; +import org.onap.aaisimulator.models.Results; +import org.onap.aaisimulator.service.providers.PlatformCacheServiceProvider; +import org.onap.aaisimulator.utils.Constants; +import org.onap.aaisimulator.utils.TestConstants; +import org.onap.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class PlatformControllerTest extends AbstractSpringBootTest { + + @Autowired + private PlatformCacheServiceProvider platformCacheServiceProvider; + + @After + public void after() { + platformCacheServiceProvider.clearAll(); + } + + @Test + public void test_putPlatform_successfullyAddedToCache() throws Exception { + + final String platformUrl = getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME); + final ResponseEntity platformResponse = + testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class); + assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode()); + + final ResponseEntity response = testRestTemplateService.invokeHttpGet(platformUrl, Platform.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final Platform actualPlatform = response.getBody(); + assertEquals(PLATFORM_NAME, actualPlatform.getPlatformName()); + assertNotNull("resource version should not be null", actualPlatform.getResourceVersion()); + + } + + @Test + public void test_getPlatformWithFormatCount() throws Exception { + + final String platformUrl = getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME); + + final ResponseEntity platformResponse = + testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class); + assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode()); + + final ResponseEntity response = testRestTemplateService.invokeHttpGet( + platformUrl + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final Results result = response.getBody(); + assertNotNull(result.getValues()); + assertFalse(result.getValues().isEmpty()); + assertEquals(1, result.getValues().get(0).get(Constants.PLATFORM)); + + } + + @Test + public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception { + + final String platformUrl = getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME); + final ResponseEntity platformResponse = + testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class); + assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode()); + + final String platformRelationShipUrl = + getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME, BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); + + final ResponseEntity responseEntity = testRestTemplateService + .invokeHttpPut(platformRelationShipUrl, TestUtils.getGenericVnfRelationShip(), Relationship.class); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + + final Optional optional = platformCacheServiceProvider.getPlatform(PLATFORM_NAME); + assertTrue(optional.isPresent()); + + final Platform actual = optional.get(); + + assertNotNull(actual.getRelationshipList()); + final List relationshipList = actual.getRelationshipList().getRelationship(); + assertFalse("Relationship list should not be empty", relationshipList.isEmpty()); + final Relationship relationship = relationshipList.get(0); + + assertEquals(GENERIC_VNF_URL + VNF_ID, relationship.getRelatedLink()); + assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty()); + assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty()); + + final RelationshipData relationshipData = relationship.getRelationshipData().get(0); + assertEquals(Constants.GENERIC_VNF_VNF_ID, relationshipData.getRelationshipKey()); + assertEquals(TestConstants.VNF_ID, relationshipData.getRelationshipValue()); + + final RelatedToProperty relatedToProperty = relationship.getRelatedToProperty().get(0); + assertEquals(Constants.GENERIC_VNF_VNF_NAME, relatedToProperty.getPropertyKey()); + assertEquals(TestConstants.GENERIC_VNF_NAME, relatedToProperty.getPropertyValue()); + + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/PnfsControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/PnfsControllerTest.java new file mode 100755 index 00000000..440c66d6 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/PnfsControllerTest.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.aaisimulator.controller; + +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.v15.Pnf; +import org.onap.aaisimulator.service.providers.PnfCacheServiceProvider; +import org.onap.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + + +/** + * @author Raj Gumma (raj.gumma@est.tech) + * + */ +public class PnfsControllerTest extends AbstractSpringBootTest { + + @Autowired + private PnfCacheServiceProvider cacheServiceProvider; + + private final String PNF="test-008"; + private final String PNF_URL= "/aai/v15/network/pnfs/pnf/"; + + + @After + public void after() { + cacheServiceProvider.clearAll(); + } + + @Test + public void test_pnf_successfullyAddedToCache() throws Exception { + + final String url = getUrl(PNF_URL, PNF); + final ResponseEntity pnfResponse = + testRestTemplateService.invokeHttpPut(url, TestUtils.getPnf(), Void.class); + assertEquals(HttpStatus.ACCEPTED, pnfResponse.getStatusCode()); + + final ResponseEntity response = + testRestTemplateService.invokeHttpGet(url, Pnf.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final Pnf actualPnf = response.getBody(); + assertEquals("test-008", actualPnf.getPnfName()); + assertEquals("5f2602dc-f647-4535-8f1d-9ec079e68a49", actualPnf.getPnfId()); + + } +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java new file mode 100644 index 00000000..d0e652bd --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.aaisimulator.controller; + +import org.junit.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.aaisimulator.utils.TestConstants.SERVICE_DESIGN_AND_CREATION_URL; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, + properties = "SERVICE_DESIGN_AND_CREATION_RESPONSES_LOCATION=./src/test/resources/test-data/service-design-and-creation-responses") +public class ServiceDesignAndCreationControllerTest extends AbstractSpringBootTest{ + + @Test + public void should_reply_sample_modelvers_response() { + final String url = getUrl(SERVICE_DESIGN_AND_CREATION_URL, + "/models/model/a51e2bef-961c-496f-b235-b4540400e885/model-vers"); + ResponseEntity actual = testRestTemplateService.invokeHttpGet(url, String.class); + String expectedXml = "\n" + + "\n" + + " \n" + + " c0818142-324d-4a8c-8065-45a61df247a5\n" + + " EricService\n" + + " 1.0\n" + + " blah\n" + + " 1594657102313\n" + + " \n" + + " \n" + + " 4442dfc1-0d2d-46b4-b0bc-a2ac10448269\n" + + " EricService\n" + + " 2.0\n" + + " blahhhh\n" + + " 1594707742646\n" + + " \n" + + ""; + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + MediaType contentType = actual.getHeaders().getContentType(); + assertNotNull(contentType); + assertTrue(contentType.isCompatibleWith(MediaType.APPLICATION_XML)); + assertEquals(expectedXml, actual.getBody()); + } +} \ No newline at end of file diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/configuration/TestRestTemplateConfigration.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/configuration/TestRestTemplateConfigration.java new file mode 100755 index 00000000..2e50d3d7 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/configuration/TestRestTemplateConfigration.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.aaisimulator.controller.configuration; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLSession; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustStrategy; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContexts; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Profile("test") +@Configuration +public class TestRestTemplateConfigration { + + private static final Logger LOGGER = LoggerFactory.getLogger(TestRestTemplateConfigration.class); + + @Bean + public TestRestTemplate testRestTemplate() throws Exception { + final TestRestTemplate testRestTemplate = new TestRestTemplate(); + ((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRestTemplate().getRequestFactory()) + .setHttpClient(httpClient()); + return testRestTemplate; + + } + + @Bean + public RestTemplate restTemplate() throws Exception { + final RestTemplate restTemplate = new RestTemplate(); + restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient())); + return restTemplate; + } + + private CloseableHttpClient httpClient() throws Exception { + final TrustStrategy acceptingTrustStrategy = (cert, authType) -> true; + + final SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory( + SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build(), new HostnameVerifier() { + @Override + public boolean verify(final String hostname, final SSLSession session) { + LOGGER.warn("Skiping hostname verification ... "); + return true; + } + + }); + + return HttpClients.custom().setSSLSocketFactory(csf).build(); + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/utils/TestConstants.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/utils/TestConstants.java new file mode 100755 index 00000000..bccb2f02 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/utils/TestConstants.java @@ -0,0 +1,134 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.aaisimulator.utils; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class TestConstants { + + public static final String BASE_URL_V17 = "/aai/v17"; + + public static final String SERVICE_INSTANCES_URL = "/service-instances"; + + public static final String SERVICE_NAME = "ServiceTest"; + + public static final String SERVICE_INSTANCE_ID = "ccece8fe-13da-456a-baf6-41b3a4a2bc2b"; + + public static final String SVC_INSTANCE_NAME = "ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce"; + + public static final String SERVICE_INSTANCE_URL = + SERVICE_INSTANCES_URL + "/service-instance/" + SERVICE_INSTANCE_ID; + + public static final String SVC_INSTANCE_URL = SERVICE_INSTANCES_URL + "/service-instance/" + SVC_INSTANCE_NAME; + + public static final String SERVICE_TYPE = "vCPE"; + + public static final String SVC_TYPE = "pNF"; + + public static final String SERVICE_SUBSCRIPTIONS_URL = + "/service-subscriptions/service-subscription/" + SERVICE_TYPE; + + public static final String SVC_SUBSCRIPTIONS_URL = "/service-subscriptions/service-subscription/"+ SVC_TYPE; + + public static final String GLOBAL_CUSTOMER_ID = "DemoCustomer"; + + public static final String SVC_INSTANCE_CUSTOMER_ID = "5df8b6de-2083-11e7-93ae-92361f002676"; + + public static final String SVC_INSTANCE_CUSTOMER_NAME = "Service_Ete_Name123452c4-3d7f-42ce-8188-818fab951269"; + + public static final String CUSTOMERS_URL = BASE_URL_V17 + "/business/customers/customer/" + GLOBAL_CUSTOMER_ID; + + public static final String CUSTOMER_BASE_URL = BASE_URL_V17 + "/business/customers/customer/" + SVC_INSTANCE_CUSTOMER_ID; + + public static final String VNF_ID = "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701"; + + public static final String GENERIC_VNF_NAME = "EsyVnfInstantiationTest2"; + + public static final String GENERIC_VNF_URL = BASE_URL_V17 + "/network/generic-vnfs/generic-vnf/"; + + public static final String GENERIC_VNFS_URL = "/generic-vnfs"; + + public static final String RELATED_TO_URL = "/related-to" + GENERIC_VNFS_URL; + + public static final String PLATFORM_NAME = "PLATFORM_APP_ID_1"; + + public static final String LINE_OF_BUSINESS_NAME = "LINE_OF_BUSINESS_1"; + + public static final String CLOUD_OWNER_NAME = "CloudOwner"; + + public static final String CLOUD_REGION_NAME = "PnfSwUCloudRegion"; + + public static final String TENANT_ID = "693c7729b2364a26a3ca602e6f66187d"; + + public static final String TENANTS_TENANT = "/tenants/tenant/"; + + public static final String ESR_VNFM_URL = BASE_URL_V17 + "/external-system/esr-vnfm-list/esr-vnfm/"; + + public static final String EXTERNAL_SYSTEM_ESR_VNFM_LIST_URL = BASE_URL_V17 + "/external-system/esr-vnfm-list"; + + public static final String ESR_VNFM_ID = "c5e99cee-1996-4606-b697-838d51d4e1a3"; + + public static final String ESR_VIM_ID = "PnfSwUVimId"; + + public static final String ESR_SYSTEM_INFO_LIST_URL = "/esr-system-info-list"; + + public static final String ESR_SYSTEM_INFO_ID = "5c067098-f2e3-40f7-a7ba-155e7c61e916"; + + public static final String ESR_SYSTEM_TYPE = "VNFM"; + + public static final String ESR_PASSWORD = "123456"; + + public static final String ESR_USERNAME = "vnfmadapter"; + + public static final String ESR_SERVICE_URL = "https://so-vnfm-simulator.onap:9095/vnflcm/v1"; + + public static final String ESR_VENDOR = "EST"; + + public static final String ESR_TYEP = "simulator"; + + public static final String SYSTEM_NAME = "vnfmSimulator"; + + public static final String VSERVER_URL = "/vservers/vserver/"; + + public static final String VSERVER_NAME = "CsitVServer"; + + public static final String VSERVER_ID = "f84fdb9b-ad7c-49db-a08f-e443b4cbd033"; + + public static final String OWNING_ENTITY_URL = BASE_URL_V17 + "/business/owning-entities/owning-entity/"; + + public static final String LINES_OF_BUSINESS_URL = BASE_URL_V17 + "/business/lines-of-business/line-of-business/"; + + public static final String PLATFORMS_URL = BASE_URL_V17 + "/business/platforms/platform/"; + + public static final String CLOUD_REGIONS = BASE_URL_V17 + "/cloud-infrastructure/cloud-regions/cloud-region/"; + + public static final String GENERIC_VNFS_URL_1 = BASE_URL_V17 + "/network/generic-vnfs"; + + public static final String NODES_URL = BASE_URL_V17 + "/nodes"; + + public static final String PROJECT_URL = BASE_URL_V17 + "/business/projects/project/"; + + public static final String SERVICE_DESIGN_AND_CREATION_URL = BASE_URL_V17 + "/service-design-and-creation"; + + private TestConstants() {} + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/utils/TestRestTemplateService.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/utils/TestRestTemplateService.java new file mode 100755 index 00000000..2e068bce --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/utils/TestRestTemplateService.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.aaisimulator.utils; + +import org.onap.aaisimulator.model.UserCredentials; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ + +@Service +public class TestRestTemplateService { + + @Autowired + private TestRestTemplate restTemplate; + + @Autowired + private UserCredentials userCredentials; + + + public ResponseEntity invokeHttpGet(final String url, final Class clazz) { + return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), clazz); + } + + public ResponseEntity invokeHttpPut(final String url, final Object obj, final Class clazz) { + final HttpEntity httpEntity = getHttpEntity(obj); + return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, clazz); + } + + public ResponseEntity invokeHttpDelete(final String url, final Class clazz) { + final HttpEntity request = new HttpEntity<>(getHttpHeaders()); + return restTemplate.exchange(url, HttpMethod.DELETE, request, clazz); + } + + public ResponseEntity invokeHttpPost(final String url, final Object obj, final Class clazz) { + final HttpEntity httpEntity = getHttpEntity(obj); + return restTemplate.exchange(url, HttpMethod.POST, httpEntity, clazz); + } + + public ResponseEntity invokeHttpPost(final HttpHeaders headers, final String url, final Object obj, + final Class clazz) { + final HttpEntity entity = new HttpEntity<>(obj, headers); + return restTemplate.exchange(url, HttpMethod.POST, entity, clazz); + } + + private HttpEntity getHttpEntity(final Object obj) { + return new HttpEntity<>(obj, getHttpHeaders()); + } + + public HttpHeaders getHttpHeaders() { + return TestUtils.getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/utils/TestUtils.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/utils/TestUtils.java new file mode 100755 index 00000000..77675745 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/utils/TestUtils.java @@ -0,0 +1,190 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.aaisimulator.utils; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Base64; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.web.util.UriComponentsBuilder; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class TestUtils { + + private static final String PASSWORD = "aai.onap.org:demo123456!"; + + public static HttpHeaders getHttpHeaders(final String username) { + final HttpHeaders requestHeaders = new HttpHeaders(); + requestHeaders.add("Authorization", getBasicAuth(username)); + requestHeaders.setContentType(MediaType.APPLICATION_JSON); + return requestHeaders; + } + + public static File getFile(final String file) throws IOException { + return new ClassPathResource(file).getFile(); + } + + public static String getJsonString(final String file) throws IOException { + return new String(Files.readAllBytes(getFile(file).toPath())); + } + + public static T getObjectFromFile(final File file, final Class clazz) throws Exception { + final ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JaxbAnnotationModule()); + + return mapper.readValue(file, clazz); + } + + public static String getBasicAuth(final String username) { + return "Basic " + new String(Base64.getEncoder().encodeToString((username + ":" + PASSWORD).getBytes())); + } + + public static String getBaseUrl(final int port) { + return "https://localhost:" + port; + } + + public static String getCustomer() throws Exception, IOException { + return getJsonString("test-data/business-customer.json"); + } + + public static String getServiceSubscription() throws IOException { + return getJsonString("test-data/service-subscription.json"); + } + + public static String getServiceInstance() throws IOException { + return getJsonString("test-data/service-instance.json"); + } + + public static String getSvcInstance() throws IOException { + return getJsonString("test-data/service-instance-aai.json"); + } + + public static String getGenericVnf() throws IOException { + return getJsonString("test-data/generic-vnf.json"); + } + + public static String getPnf() throws IOException { + return getJsonString("test-data/pnf.json"); + } + + public static String getRelationShip() throws IOException { + return getJsonString("test-data/relation-ship.json"); + } + + public static String getPlatformRelatedLink() throws IOException { + return getJsonString("test-data/platform-related-link.json"); + } + + public static String getLineOfBusinessRelatedLink() throws IOException { + return getJsonString("test-data/line-of-business-related-link.json"); + } + + public static String getPlatform() throws IOException { + return getJsonString("test-data/platform.json"); + } + + public static String getGenericVnfRelationShip() throws IOException { + return getJsonString("test-data/generic-vnf-relationship.json"); + } + + public static String getLineOfBusiness() throws IOException { + return getJsonString("test-data/line-of-business.json"); + } + + public static String getBusinessProject() throws IOException { + return getJsonString("test-data/business-project.json"); + } + + public static String getBusinessProjectRelationship() throws IOException { + return getJsonString("test-data/business-project-relation-ship.json"); + } + + public static String getOwningEntityRelationship() throws IOException { + return getJsonString("test-data/owning-entity-relation-ship.json"); + } + + public static String getOwningEntity() throws IOException { + return getJsonString("test-data/owning-entity.json"); + } + + public static String getOrchStatuUpdateServiceInstance() throws IOException { + return getJsonString("test-data/service-instance-orch-status-update.json"); + } + + public static String getRelationShipJsonObject() throws IOException { + return getJsonString("test-data/service-Instance-relationShip.json"); + } + + public static String getCloudRegion() throws IOException { + return getJsonString("test-data/cloud-region.json"); + } + + public static String getTenant() throws IOException { + return getJsonString("test-data/tenant.json"); + } + + public static String getCloudRegionRelatedLink() throws IOException { + return getJsonString("test-data/cloud-region-related-link.json"); + } + + public static String getGenericVnfRelatedLink() throws IOException { + return getJsonString("test-data/generic-vnf-related-link.json"); + } + + public static String getTenantRelationShip() throws IOException { + return getJsonString("test-data/tenant-relationship.json"); + } + + public static String getGenericVnfOrchStatuUpdate() throws IOException { + return getJsonString("test-data/generic-vnf-orch-status-update.json"); + } + + public static String getEsrVnfm() throws IOException { + return getJsonString("test-data/esr-vnfm.json"); + } + + public static String getEsrSystemInfo() throws IOException { + return getJsonString("test-data/esr-system-info.json"); + } + + public static String getVserver() throws IOException { + return getJsonString("test-data/vServer.json"); + } + + + public static String getUrl(final int port, final String... urls) { + final UriComponentsBuilder baseUri = UriComponentsBuilder.fromUriString("https://localhost:" + port); + for (final String url : urls) { + baseUri.path(url); + } + return baseUri.toUriString(); + } + + private TestUtils() {} + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AaiSimulatorControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AaiSimulatorControllerTest.java deleted file mode 100755 index af9b2367..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AaiSimulatorControllerTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.controller; - -import static org.junit.Assert.assertEquals; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.aaisimulator.utils.Constants; -import org.onap.aaisimulator.utils.TestConstants; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ActiveProfiles("test") -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@Configuration -public class AaiSimulatorControllerTest { - - @LocalServerPort - private int port; - - @Autowired - private TestRestTemplate restTemplate; - - @Test - public void test_healthCheck_matchContent() { - final String url = getBaseUrl() + "/healthcheck"; - final ResponseEntity object = restTemplate.getForEntity(url, String.class); - - assertEquals(Constants.HEALTHY, object.getBody()); - } - - private String getBaseUrl() { - return "https://localhost:" + port + TestConstants.BASE_URL_V17; - } - -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AbstractSpringBootTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AbstractSpringBootTest.java deleted file mode 100755 index 4f2eab27..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AbstractSpringBootTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.controller; - -import java.util.List; -import org.junit.runner.RunWith; -import org.onap.aai.domain.yang.RelatedToProperty; -import org.onap.aai.domain.yang.RelationshipData; -import org.onap.aaisimulator.utils.TestRestTemplateService; -import org.onap.aaisimulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ActiveProfiles("test") -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@Configuration -public abstract class AbstractSpringBootTest { - - @LocalServerPort - private int port; - - @Autowired - protected TestRestTemplateService testRestTemplateService; - - public String getUrl(final String... urls) { - return TestUtils.getUrl(port, urls); - } - - public RelationshipData getRelationshipData(final List relationshipData, final String key) { - return relationshipData.stream().filter(data -> data.getRelationshipKey().equals(key)).findFirst().orElse(null); - } - - public RelatedToProperty getRelatedToProperty(final List relatedToPropertyList, - final String key) { - return relatedToPropertyList.stream().filter(data -> data.getPropertyKey().equals(key)).findFirst() - .orElse(null); - } -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java deleted file mode 100755 index 70f5d21b..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java +++ /dev/null @@ -1,397 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.controller; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; -import static org.onap.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; -import static org.onap.aaisimulator.utils.TestConstants.CUSTOMERS_URL; -import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_NAME; -import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; -import static org.onap.aaisimulator.utils.TestConstants.GLOBAL_CUSTOMER_ID; -import static org.onap.aaisimulator.utils.TestConstants.RELATED_TO_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_INSTANCES_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_NAME; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_TYPE; -import static org.onap.aaisimulator.utils.TestConstants.VNF_ID; -import static org.onap.aaisimulator.utils.TestUtils.getCustomer; -import static org.onap.aaisimulator.utils.TestUtils.getServiceInstance; -import java.io.IOException; -import java.util.Optional; -import java.util.UUID; -import org.junit.After; -import org.junit.Test; -import org.onap.aai.domain.yang.Customer; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.aai.domain.yang.GenericVnfs; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aai.domain.yang.ServiceInstances; -import org.onap.aai.domain.yang.ServiceSubscription; -import org.onap.aaisimulator.service.providers.CustomerCacheServiceProvider; -import org.onap.aaisimulator.utils.RequestError; -import org.onap.aaisimulator.utils.RequestErrorResponseUtils; -import org.onap.aaisimulator.utils.ServiceException; -import org.onap.aaisimulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public class BusinessControllerTest extends AbstractSpringBootTest { - - private static final String FIREWALL_SERVICE_TYPE = "Firewall"; - - private static final String ORCHESTRATION_STATUS = "Active"; - - @Autowired - private CustomerCacheServiceProvider cacheServiceProvider; - - @After - public void after() { - cacheServiceProvider.clearAll(); - } - - @Test - public void test_putCustomer_successfullyAddedToCache() throws Exception { - invokeCustomerEndPointAndAssertResponse(); - assertTrue(cacheServiceProvider.getCustomer(GLOBAL_CUSTOMER_ID).isPresent()); - } - - @Test - public void test_getCustomer_ableToRetrieveCustomer() throws Exception { - final String url = getUrl(CUSTOMERS_URL); - - final ResponseEntity response = testRestTemplateService.invokeHttpPut(url, getCustomer(), Void.class); - assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - - final ResponseEntity actual = testRestTemplateService.invokeHttpGet(url, Customer.class); - - assertEquals(HttpStatus.OK, actual.getStatusCode()); - assertTrue(actual.hasBody()); - - final Customer actualCustomer = actual.getBody(); - assertEquals(GLOBAL_CUSTOMER_ID, actualCustomer.getGlobalCustomerId()); - assertNotNull(actualCustomer.getResourceVersion()); - assertFalse(actualCustomer.getResourceVersion().isEmpty()); - } - - @Test - public void test_getCustomer_returnRequestError_ifCustomerNotInCache() throws Exception { - final String url = getUrl(CUSTOMERS_URL); - - final ResponseEntity actual = testRestTemplateService.invokeHttpGet(url, RequestError.class); - - assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); - - final RequestError actualError = actual.getBody(); - final ServiceException serviceException = actualError.getServiceException(); - - assertNotNull(serviceException); - assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE_ID, serviceException.getMessageId()); - assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE, serviceException.getText()); - assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString())); - - } - - @Test - public void test_getServiceSubscription_ableToRetrieveServiceSubscriptionFromCache() throws Exception { - final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL); - - invokeCustomerEndPointAndAssertResponse(); - - final ResponseEntity actual = - testRestTemplateService.invokeHttpGet(url, ServiceSubscription.class); - - assertEquals(HttpStatus.OK, actual.getStatusCode()); - assertTrue(actual.hasBody()); - - final ServiceSubscription actualServiceSubscription = actual.getBody(); - assertEquals(SERVICE_TYPE, actualServiceSubscription.getServiceType()); - assertNotNull(actualServiceSubscription.getRelationshipList()); - assertFalse(actualServiceSubscription.getRelationshipList().getRelationship().isEmpty()); - } - - @Test - public void test_putSericeInstance_ableToRetrieveServiceInstanceFromCache() throws Exception { - - invokeCustomerEndPointAndAssertResponse(); - invokeServiceInstanceEndPointAndAssertResponse(); - - - final Optional actual = - cacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID); - - assertTrue(actual.isPresent()); - final ServiceInstance actualServiceInstance = actual.get(); - - assertEquals(SERVICE_INSTANCE_ID, actualServiceInstance.getServiceInstanceId()); - assertEquals(SERVICE_NAME, actualServiceInstance.getServiceInstanceName()); - - } - - @Test - public void test_getSericeInstance_usingServiceInstanceName_ableToRetrieveServiceInstanceFromCache() - throws Exception { - - invokeCustomerEndPointAndAssertResponse(); - invokeServiceInstanceEndPointAndAssertResponse(); - - - final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCES_URL) - + "?depth=2&service-instance-name=" + SERVICE_NAME; - - final ResponseEntity actual = - testRestTemplateService.invokeHttpGet(serviceInstanceUrl, ServiceInstances.class); - - assertEquals(HttpStatus.OK, actual.getStatusCode()); - assertTrue(actual.hasBody()); - - final ServiceInstances actualServiceInstances = actual.getBody(); - assertFalse(actualServiceInstances.getServiceInstance().isEmpty()); - - assertEquals(SERVICE_NAME, actualServiceInstances.getServiceInstance().get(0).getServiceInstanceName()); - - } - - @Test - public void test_getSericeInstance_usingServiceInstanceName_returnRequestErrorIfnoServiceInstanceFound() - throws Exception { - - invokeCustomerEndPointAndAssertResponse(); - - final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCES_URL) - + "?depth=2&service-instance-name=" + SERVICE_NAME; - - final ResponseEntity actual = - testRestTemplateService.invokeHttpGet(serviceInstanceUrl, RequestError.class); - - assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); - assertTrue(actual.hasBody()); - - assertNotNull(actual.getBody().getServiceException()); - - } - - @Test - public void test_getSericeInstance_usingServiceInstanceId_ableToRetrieveServiceInstanceFromCache() - throws Exception { - - final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); - - invokeCustomerEndPointAndAssertResponse(); - invokeServiceInstanceEndPointAndAssertResponse(); - - final ResponseEntity actual = - testRestTemplateService.invokeHttpGet(url, ServiceInstance.class); - - assertEquals(HttpStatus.OK, actual.getStatusCode()); - assertTrue(actual.hasBody()); - - final ServiceInstance actualServiceInstance = actual.getBody(); - - assertEquals(SERVICE_NAME, actualServiceInstance.getServiceInstanceName()); - assertEquals(SERVICE_INSTANCE_ID, actualServiceInstance.getServiceInstanceId()); - - } - - @Test - public void test_getSericeInstance_usinginvalidServiceInstanceId_shouldReturnError() throws Exception { - - invokeCustomerEndPointAndAssertResponse(); - - invokeServiceInstanceEndPointAndAssertResponse(); - - - final String invalidServiceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, - SERVICE_INSTANCES_URL + "/service-instance/" + UUID.randomUUID()); - - final ResponseEntity actual = - testRestTemplateService.invokeHttpGet(invalidServiceInstanceUrl, RequestError.class); - - assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); - - final RequestError actualError = actual.getBody(); - final ServiceException serviceException = actualError.getServiceException(); - - assertNotNull(serviceException); - assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE_ID, serviceException.getMessageId()); - assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE, serviceException.getText()); - assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString())); - - } - - @Test - public void test_getSericeInstance_usingInvalidServiceInstanceName_shouldReturnError() throws Exception { - - invokeCustomerEndPointAndAssertResponse(); - invokeServiceInstanceEndPointAndAssertResponse(); - - - final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCES_URL) - + "?service-instance-name=Dummy&depth=2"; - - final ResponseEntity actual = - testRestTemplateService.invokeHttpGet(serviceInstanceUrl, RequestError.class); - - assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); - - final RequestError actualError = actual.getBody(); - final ServiceException serviceException = actualError.getServiceException(); - - assertNotNull(serviceException); - assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE_ID, serviceException.getMessageId()); - assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE, serviceException.getText()); - assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString())); - - } - - @Test - public void test_PathSericeInstance_usingServiceInstanceId_OrchStatusChangedInCache() throws Exception { - - final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); - - invokeCustomerEndPointAndAssertResponse(); - invokeServiceInstanceEndPointAndAssertResponse(); - - final HttpHeaders httpHeaders = testRestTemplateService.getHttpHeaders(); - httpHeaders.add(X_HTTP_METHOD_OVERRIDE, HttpMethod.PATCH.toString()); - - final ResponseEntity orchStatuUpdateServiceInstanceResponse = testRestTemplateService - .invokeHttpPost(httpHeaders, url, TestUtils.getOrchStatuUpdateServiceInstance(), Void.class); - - assertEquals(HttpStatus.ACCEPTED, orchStatuUpdateServiceInstanceResponse.getStatusCode()); - - final ResponseEntity actual = - testRestTemplateService.invokeHttpGet(url, ServiceInstance.class); - - assertEquals(HttpStatus.OK, actual.getStatusCode()); - assertTrue(actual.hasBody()); - - final ServiceInstance actualServiceInstance = actual.getBody(); - - assertEquals(SERVICE_NAME, actualServiceInstance.getServiceInstanceName()); - assertEquals(SERVICE_INSTANCE_ID, actualServiceInstance.getServiceInstanceId()); - assertEquals(ORCHESTRATION_STATUS, actualServiceInstance.getOrchestrationStatus()); - - } - - @Test - public void test_putServiceSubscription_successfullyAddedToCache() throws Exception { - final String serviceSubscriptionurl = - getUrl(CUSTOMERS_URL, "/service-subscriptions/service-subscription/", FIREWALL_SERVICE_TYPE); - - invokeCustomerEndPointAndAssertResponse(); - - final ResponseEntity responseEntity = testRestTemplateService.invokeHttpPut(serviceSubscriptionurl, - TestUtils.getServiceSubscription(), Void.class); - assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); - - final ResponseEntity actual = - testRestTemplateService.invokeHttpGet(serviceSubscriptionurl, ServiceSubscription.class); - - assertEquals(HttpStatus.OK, actual.getStatusCode()); - assertTrue(actual.hasBody()); - - final ServiceSubscription actualServiceSubscription = actual.getBody(); - assertEquals(FIREWALL_SERVICE_TYPE, actualServiceSubscription.getServiceType()); - - } - - @Test - public void test_putSericeInstanceRelatedTo_ableToRetrieveServiceInstanceFromCache() throws Exception { - - final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); - - invokeCustomerEndPointAndAssertResponse(); - - invokeServiceInstanceEndPointAndAssertResponse(); - - final String relationShipUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL, - BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); - - final ResponseEntity responseEntity2 = testRestTemplateService.invokeHttpPut(relationShipUrl, - TestUtils.getRelationShipJsonObject(), Relationship.class); - - assertEquals(HttpStatus.ACCEPTED, responseEntity2.getStatusCode()); - - final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); - final ResponseEntity genericVnfResponse = - testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class); - assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode()); - - final ResponseEntity actual = testRestTemplateService - .invokeHttpGet(url + RELATED_TO_URL + "?vnf-name=" + GENERIC_VNF_NAME, GenericVnfs.class); - - assertEquals(HttpStatus.OK, actual.getStatusCode()); - - assertTrue(actual.hasBody()); - final GenericVnfs genericVnfs = actual.getBody(); - assertFalse(genericVnfs.getGenericVnf().isEmpty()); - final GenericVnf genericVnf = genericVnfs.getGenericVnf().get(0); - assertEquals(GENERIC_VNF_NAME, genericVnf.getVnfName()); - } - - @Test - public void test_DeleteSericeInstance_ServiceInstanceRemovedFromCache() throws Exception { - final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); - - invokeCustomerEndPointAndAssertResponse(); - - invokeServiceInstanceEndPointAndAssertResponse(); - - final Optional optional = - cacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID); - assertTrue(optional.isPresent()); - final ServiceInstance serviceInstance = optional.get(); - - final ResponseEntity responseEntity = testRestTemplateService - .invokeHttpDelete(url + "?resource-version=" + serviceInstance.getResourceVersion(), Void.class); - assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); - assertFalse(cacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID) - .isPresent()); - } - - private void invokeServiceInstanceEndPointAndAssertResponse() throws IOException { - final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); - final ResponseEntity responseEntity = - testRestTemplateService.invokeHttpPut(url, getServiceInstance(), Void.class); - assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); - } - - private void invokeCustomerEndPointAndAssertResponse() throws Exception, IOException { - final ResponseEntity response = - testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), getCustomer(), Void.class); - - assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - } - -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java deleted file mode 100755 index 29d03ce0..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java +++ /dev/null @@ -1,420 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.controller; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; -import static org.onap.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; -import static org.onap.aaisimulator.utils.Constants.VSERVER; -import static org.onap.aaisimulator.utils.TestConstants.CLOUD_OWNER_NAME; -import static org.onap.aaisimulator.utils.TestConstants.CLOUD_REGION_NAME; -import static org.onap.aaisimulator.utils.TestConstants.CUSTOMERS_URL; -import static org.onap.aaisimulator.utils.TestConstants.ESR_PASSWORD; -import static org.onap.aaisimulator.utils.TestConstants.ESR_SERVICE_URL; -import static org.onap.aaisimulator.utils.TestConstants.ESR_SYSTEM_INFO_ID; -import static org.onap.aaisimulator.utils.TestConstants.ESR_SYSTEM_INFO_LIST_URL; -import static org.onap.aaisimulator.utils.TestConstants.ESR_SYSTEM_TYPE; -import static org.onap.aaisimulator.utils.TestConstants.ESR_TYEP; -import static org.onap.aaisimulator.utils.TestConstants.ESR_USERNAME; -import static org.onap.aaisimulator.utils.TestConstants.ESR_VENDOR; -import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_NAME; -import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; -import static org.onap.aaisimulator.utils.TestConstants.SYSTEM_NAME; -import static org.onap.aaisimulator.utils.TestConstants.TENANTS_TENANT; -import static org.onap.aaisimulator.utils.TestConstants.TENANT_ID; -import static org.onap.aaisimulator.utils.TestConstants.VNF_ID; -import static org.onap.aaisimulator.utils.TestConstants.VSERVER_ID; -import static org.onap.aaisimulator.utils.TestConstants.VSERVER_NAME; -import static org.onap.aaisimulator.utils.TestConstants.VSERVER_URL; -import java.io.IOException; -import java.util.List; -import java.util.Optional; -import org.junit.After; -import org.junit.Test; -import org.onap.aai.domain.yang.CloudRegion; -import org.onap.aai.domain.yang.EsrSystemInfo; -import org.onap.aai.domain.yang.EsrSystemInfoList; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.aai.domain.yang.RelatedToProperty; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipData; -import org.onap.aai.domain.yang.RelationshipList; -import org.onap.aai.domain.yang.Tenant; -import org.onap.aai.domain.yang.Vserver; -import org.onap.aaisimulator.models.CloudRegionKey; -import org.onap.aaisimulator.service.providers.CloudRegionCacheServiceProvider; -import org.onap.aaisimulator.service.providers.CustomerCacheServiceProvider; -import org.onap.aaisimulator.service.providers.GenericVnfCacheServiceProvider; -import org.onap.aaisimulator.utils.Constants; -import org.onap.aaisimulator.utils.TestConstants; -import org.onap.aaisimulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public class CloudRegionsControllerTest extends AbstractSpringBootTest { - - private static final CloudRegionKey CLOUD_REGION_KEY = new CloudRegionKey(CLOUD_OWNER_NAME, CLOUD_REGION_NAME); - - @Autowired - private CloudRegionCacheServiceProvider cloudRegionCacheServiceProvider; - - @Autowired - private CustomerCacheServiceProvider customerCacheServiceProvider; - - @Autowired - private GenericVnfCacheServiceProvider genericVnfCacheServiceProvider; - - @After - public void after() { - cloudRegionCacheServiceProvider.clearAll(); - customerCacheServiceProvider.clearAll(); - genericVnfCacheServiceProvider.clearAll(); - } - - @Test - public void test_putCloudRegion_successfullyAddedToCache() throws Exception { - final String url = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); - - invokeCloudRegionHttpPutEndPointAndAssertResponse(url); - - final ResponseEntity response = testRestTemplateService.invokeHttpGet(url, CloudRegion.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - - final CloudRegion cloudRegion = response.getBody(); - assertEquals(CLOUD_OWNER_NAME, cloudRegion.getCloudOwner()); - assertEquals(CLOUD_REGION_NAME, cloudRegion.getCloudRegionId()); - - assertNotNull("ResourceVersion should not be null", cloudRegion.getResourceVersion()); - - } - - @Test - public void test_getCloudRegionWithDepthValue_shouldReturnMatchedCloudRegion() throws Exception { - final String url = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); - - invokeCloudRegionHttpPutEndPointAndAssertResponse(url); - - final ResponseEntity response = - testRestTemplateService.invokeHttpGet(url + "?depth=2", CloudRegion.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - - final CloudRegion cloudRegion = response.getBody(); - assertEquals(CLOUD_OWNER_NAME, cloudRegion.getCloudOwner()); - assertEquals(CLOUD_REGION_NAME, cloudRegion.getCloudRegionId()); - - assertNotNull("ResourceVersion should not be null", cloudRegion.getResourceVersion()); - - } - - @Test - public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception { - - final String url = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); - - invokeCloudRegionHttpPutEndPointAndAssertResponse(url); - - final String relationShipUrl = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME, - BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); - - final ResponseEntity responseEntity = testRestTemplateService.invokeHttpPut(relationShipUrl, - TestUtils.getGenericVnfRelationShip(), Relationship.class); - assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); - - final Optional optional = cloudRegionCacheServiceProvider.getCloudRegion(CLOUD_REGION_KEY); - assertTrue(optional.isPresent()); - - final CloudRegion actual = optional.get(); - - assertNotNull(actual.getRelationshipList()); - final List relationshipList = actual.getRelationshipList().getRelationship(); - assertFalse("Relationship list should not be empty", relationshipList.isEmpty()); - final Relationship relationship = relationshipList.get(0); - - assertEquals(GENERIC_VNF_URL + VNF_ID, relationship.getRelatedLink()); - - assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty()); - assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty()); - - final RelationshipData relationshipData = relationship.getRelationshipData().get(0); - assertEquals(Constants.GENERIC_VNF_VNF_ID, relationshipData.getRelationshipKey()); - assertEquals(TestConstants.VNF_ID, relationshipData.getRelationshipValue()); - - final RelatedToProperty relatedToProperty = relationship.getRelatedToProperty().get(0); - assertEquals(Constants.GENERIC_VNF_VNF_NAME, relatedToProperty.getPropertyKey()); - assertEquals(TestConstants.GENERIC_VNF_NAME, relatedToProperty.getPropertyValue()); - - } - - @Test - public void test_putTenant_successfullyAddedToCache() throws Exception { - final String cloudRegionUrl = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); - - invokeCloudRegionHttpPutEndPointAndAssertResponse(cloudRegionUrl); - - final String tenantUrl = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, - "/" + CLOUD_REGION_NAME + TENANTS_TENANT + TENANT_ID); - addTenantAndAssertResponse(tenantUrl); - - final ResponseEntity response = testRestTemplateService.invokeHttpGet(tenantUrl, Tenant.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - - final Tenant tenant = response.getBody(); - assertEquals(TENANT_ID, tenant.getTenantId()); - assertEquals("admin", tenant.getTenantName()); - - assertNotNull("ResourceVersion should not be null", tenant.getResourceVersion()); - - } - - @Test - public void test_putTenantRelationToGenericVnf_successfullyAddedToCache() throws Exception { - - addCustomerServiceAndGenericVnf(); - - final String cloudRegionUrl = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); - invokeCloudRegionHttpPutEndPointAndAssertResponse(cloudRegionUrl); - - final String tenantUrl = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME, - TENANTS_TENANT + TENANT_ID); - addTenantAndAssertResponse(tenantUrl); - - final String tenantRelationShipUrl = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, - "/" + CLOUD_REGION_NAME, TENANTS_TENANT + TENANT_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); - - final ResponseEntity tenantRelationShipResponse = testRestTemplateService - .invokeHttpPut(tenantRelationShipUrl, TestUtils.getGenericVnfRelatedLink(), Void.class); - assertEquals(HttpStatus.ACCEPTED, tenantRelationShipResponse.getStatusCode()); - - final Optional optional = cloudRegionCacheServiceProvider.getTenant(CLOUD_REGION_KEY, TENANT_ID); - - assertTrue(optional.isPresent()); - final Tenant actualTenant = optional.get(); - final RelationshipList relationshipList = actualTenant.getRelationshipList(); - assertNotNull(relationshipList); - assertFalse(relationshipList.getRelationship().isEmpty()); - - final Relationship relationship = relationshipList.getRelationship().get(0); - - assertEquals(Constants.BELONGS_TO, relationship.getRelationshipLabel()); - assertFalse(relationship.getRelationshipData().isEmpty()); - assertEquals(1, relationship.getRelationshipData().size()); - - final List relationshipDataList = relationship.getRelationshipData(); - - final RelationshipData relationshipData = - getRelationshipData(relationshipDataList, Constants.GENERIC_VNF_VNF_ID); - assertNotNull(relationshipData); - assertEquals(VNF_ID, relationshipData.getRelationshipValue()); - - final List relatedToPropertyList = relationship.getRelatedToProperty(); - - final RelatedToProperty property = getRelatedToProperty(relatedToPropertyList, Constants.GENERIC_VNF_VNF_NAME); - assertNotNull(property); - assertEquals(GENERIC_VNF_NAME, property.getPropertyValue()); - - final Optional genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); - assertTrue(genericVnfOptional.isPresent()); - final GenericVnf actualGenericVnf = genericVnfOptional.get(); - final RelationshipList relationshipListGenericVnf = actualGenericVnf.getRelationshipList(); - assertNotNull(relationshipListGenericVnf); - assertFalse(relationshipListGenericVnf.getRelationship().isEmpty()); - - final Relationship relationshipGenericVnf = relationshipListGenericVnf.getRelationship().get(0); - - assertEquals(Constants.BELONGS_TO, relationshipGenericVnf.getRelationshipLabel()); - assertFalse(relationshipGenericVnf.getRelationshipData().isEmpty()); - assertEquals(3, relationshipGenericVnf.getRelationshipData().size()); - - } - - @Test - public void test_putEsrSystemInfo_successfullyAddedToCache() throws Exception { - final String url = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); - - invokeCloudRegionHttpPutEndPointAndAssertResponse(url); - - final String esrSystemInfoListUrl = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, - "/" + CLOUD_REGION_NAME, ESR_SYSTEM_INFO_LIST_URL); - - final String esrSystemInfoUrl = esrSystemInfoListUrl + "/esr-system-info/" + ESR_SYSTEM_INFO_ID; - final ResponseEntity esrSystemInfoResponse = - testRestTemplateService.invokeHttpPut(esrSystemInfoUrl, TestUtils.getEsrSystemInfo(), Void.class); - assertEquals(HttpStatus.ACCEPTED, esrSystemInfoResponse.getStatusCode()); - - final ResponseEntity response = - testRestTemplateService.invokeHttpGet(esrSystemInfoListUrl, EsrSystemInfoList.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - final EsrSystemInfoList actualEsrSystemInfoList = response.getBody(); - - final List esrSystemInfoList = actualEsrSystemInfoList.getEsrSystemInfo(); - assertNotNull(esrSystemInfoList); - assertEquals(1, esrSystemInfoList.size()); - - final EsrSystemInfo esrSystemInfo = esrSystemInfoList.get(0); - assertEquals(ESR_SYSTEM_INFO_ID, esrSystemInfo.getEsrSystemInfoId()); - assertEquals(SYSTEM_NAME, esrSystemInfo.getSystemName()); - assertEquals(ESR_TYEP, esrSystemInfo.getType()); - assertEquals(ESR_VENDOR, esrSystemInfo.getVendor()); - assertEquals(ESR_SERVICE_URL, esrSystemInfo.getServiceUrl()); - assertEquals(ESR_USERNAME, esrSystemInfo.getUserName()); - assertEquals(ESR_PASSWORD, esrSystemInfo.getPassword()); - assertEquals(ESR_SYSTEM_TYPE, esrSystemInfo.getSystemType()); - } - - @Test - public void test_putVServer_successfullyAddedToCache() throws Exception { - final String url = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); - - invokeCloudRegionHttpPutEndPointAndAssertResponse(url); - addCustomerServiceAndGenericVnf(); - - final String tenantUrl = url + TENANTS_TENANT + TENANT_ID; - addTenantAndAssertResponse(tenantUrl); - - final String vServerUrl = tenantUrl + VSERVER_URL + VSERVER_ID; - - final ResponseEntity vServerResponse = - testRestTemplateService.invokeHttpPut(vServerUrl, TestUtils.getVserver(), Void.class); - assertEquals(HttpStatus.ACCEPTED, vServerResponse.getStatusCode()); - - final ResponseEntity response = testRestTemplateService.invokeHttpGet(vServerUrl, Vserver.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - final Vserver actualVserver = response.getBody(); - assertEquals(VSERVER_NAME, actualVserver.getVserverName()); - assertEquals(VSERVER_ID, actualVserver.getVserverId()); - assertEquals("active", actualVserver.getProvStatus()); - assertNotNull(actualVserver.getRelationshipList()); - assertFalse(actualVserver.getRelationshipList().getRelationship().isEmpty()); - - final Optional optional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); - assertTrue(optional.isPresent()); - final GenericVnf genericVnf = optional.get(); - assertNotNull(genericVnf.getRelationshipList()); - assertFalse(genericVnf.getRelationshipList().getRelationship().isEmpty()); - - final Relationship expectedRelationShip = genericVnf.getRelationshipList().getRelationship().get(0); - assertEquals(VSERVER, expectedRelationShip.getRelatedTo()); - assertNotNull(expectedRelationShip.getRelationshipData()); - assertEquals(4, expectedRelationShip.getRelationshipData().size()); - - final List relationshipDataList = expectedRelationShip.getRelationshipData(); - final RelationshipData vServerrelationshipData = - getRelationshipData(relationshipDataList, Constants.VSERVER_VSERVER_ID); - assertNotNull(vServerrelationshipData); - assertEquals(VSERVER_ID, vServerrelationshipData.getRelationshipValue()); - - final RelationshipData cloudOwnerRelationshipData = - getRelationshipData(relationshipDataList, Constants.CLOUD_REGION_CLOUD_OWNER); - assertNotNull(cloudOwnerRelationshipData); - assertEquals(CLOUD_OWNER_NAME, cloudOwnerRelationshipData.getRelationshipValue()); - - final RelationshipData cloudRegionIdRelationshipData = - getRelationshipData(relationshipDataList, Constants.CLOUD_REGION_CLOUD_REGION_ID); - assertNotNull(cloudRegionIdRelationshipData); - assertEquals(CLOUD_REGION_NAME, cloudRegionIdRelationshipData.getRelationshipValue()); - - final RelationshipData tenantRelationshipData = - getRelationshipData(relationshipDataList, Constants.TENANT_TENANT_ID); - assertNotNull(tenantRelationshipData); - assertEquals(TENANT_ID, tenantRelationshipData.getRelationshipValue()); - - } - - @Test - public void test_deleteVServer_successfullyRemoveFromCache() throws Exception { - final String url = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); - - invokeCloudRegionHttpPutEndPointAndAssertResponse(url); - addCustomerServiceAndGenericVnf(); - - final String tenantUrl = url + TENANTS_TENANT + TENANT_ID; - addTenantAndAssertResponse(tenantUrl); - - final String vServerAddUrl = tenantUrl + VSERVER_URL + VSERVER_ID; - - final ResponseEntity vServerAddResponse = - testRestTemplateService.invokeHttpPut(vServerAddUrl, TestUtils.getVserver(), Void.class); - assertEquals(HttpStatus.ACCEPTED, vServerAddResponse.getStatusCode()); - - final Optional optional = - cloudRegionCacheServiceProvider.getVserver(CLOUD_REGION_KEY, TENANT_ID, VSERVER_ID); - assertTrue(optional.isPresent()); - final Vserver vserver = optional.get(); - - final String vServerRemoveUrl = vServerAddUrl + "?resource-version=" + vserver.getResourceVersion(); - - final ResponseEntity responseEntity = - testRestTemplateService.invokeHttpDelete(vServerRemoveUrl, Void.class); - assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); - assertFalse(cloudRegionCacheServiceProvider.getVserver(CLOUD_REGION_KEY, TENANT_ID, VSERVER_ID).isPresent()); - - - } - - private void addTenantAndAssertResponse(final String tenantUrl) throws IOException { - final ResponseEntity responseEntity = - testRestTemplateService.invokeHttpPut(tenantUrl, TestUtils.getTenant(), Void.class); - assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); - } - - private void addCustomerServiceAndGenericVnf() throws Exception, IOException { - final ResponseEntity customerResponse = - testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class); - assertEquals(HttpStatus.ACCEPTED, customerResponse.getStatusCode()); - - final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); - final ResponseEntity serviceInstanceResponse = - testRestTemplateService.invokeHttpPut(serviceInstanceUrl, TestUtils.getServiceInstance(), Void.class); - assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode()); - - final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); - final ResponseEntity genericVnfResponse = - testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class); - assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode()); - - } - - private void invokeCloudRegionHttpPutEndPointAndAssertResponse(final String url) throws IOException { - final ResponseEntity responseEntity = - testRestTemplateService.invokeHttpPut(url, TestUtils.getCloudRegion(), Void.class); - assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); - } - -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ExternalSystemEsrControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ExternalSystemEsrControllerTest.java deleted file mode 100755 index fb406ab4..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ExternalSystemEsrControllerTest.java +++ /dev/null @@ -1,233 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.controller; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; -import static org.onap.aaisimulator.utils.TestConstants.CUSTOMERS_URL; -import static org.onap.aaisimulator.utils.TestConstants.ESR_PASSWORD; -import static org.onap.aaisimulator.utils.TestConstants.ESR_SERVICE_URL; -import static org.onap.aaisimulator.utils.TestConstants.ESR_SYSTEM_INFO_ID; -import static org.onap.aaisimulator.utils.TestConstants.ESR_SYSTEM_INFO_LIST_URL; -import static org.onap.aaisimulator.utils.TestConstants.ESR_SYSTEM_TYPE; -import static org.onap.aaisimulator.utils.TestConstants.ESR_TYEP; -import static org.onap.aaisimulator.utils.TestConstants.ESR_USERNAME; -import static org.onap.aaisimulator.utils.TestConstants.ESR_VENDOR; -import static org.onap.aaisimulator.utils.TestConstants.ESR_VIM_ID; -import static org.onap.aaisimulator.utils.TestConstants.ESR_VNFM_ID; -import static org.onap.aaisimulator.utils.TestConstants.ESR_VNFM_URL; -import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; -import static org.onap.aaisimulator.utils.TestConstants.SYSTEM_NAME; -import static org.onap.aaisimulator.utils.TestConstants.VNF_ID; -import java.io.IOException; -import java.util.List; -import java.util.Optional; -import org.junit.After; -import org.junit.Test; -import org.onap.aai.domain.yang.EsrSystemInfo; -import org.onap.aai.domain.yang.EsrSystemInfoList; -import org.onap.aai.domain.yang.EsrVnfm; -import org.onap.aai.domain.yang.EsrVnfmList; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipData; -import org.onap.aai.domain.yang.RelationshipList; -import org.onap.aaisimulator.service.providers.ExternalSystemCacheServiceProvider; -import org.onap.aaisimulator.service.providers.GenericVnfCacheServiceProvider; -import org.onap.aaisimulator.utils.Constants; -import org.onap.aaisimulator.utils.TestConstants; -import org.onap.aaisimulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public class ExternalSystemEsrControllerTest extends AbstractSpringBootTest { - - @Autowired - private ExternalSystemCacheServiceProvider externalSystemCacheServiceProvider; - - - @Autowired - private GenericVnfCacheServiceProvider genericVnfCacheServiceProvider; - - @After - public void after() { - externalSystemCacheServiceProvider.clearAll(); - genericVnfCacheServiceProvider.clearAll(); - } - - @Test - public void test_putEsrVnfm_successfullyAddedToCache() throws Exception { - final String esrVnfmUrl = getUrl(ESR_VNFM_URL, ESR_VNFM_ID); - addEsrVnfmAndAssertResponse(esrVnfmUrl); - - final ResponseEntity response = testRestTemplateService.invokeHttpGet(esrVnfmUrl, EsrVnfm.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - - final EsrVnfm actualEsrVnfm = response.getBody(); - assertEquals(ESR_VNFM_ID, actualEsrVnfm.getVnfmId()); - assertEquals(ESR_VIM_ID, actualEsrVnfm.getVimId()); - - } - - @Test - public void test_getEsrVnfmList_getAllEsrVnfmsFromCache() throws Exception { - final String esrVnfmUrl = getUrl(ESR_VNFM_URL, ESR_VNFM_ID); - addEsrVnfmAndAssertResponse(esrVnfmUrl); - - final String esrVnfmListUrl = getUrl(TestConstants.EXTERNAL_SYSTEM_ESR_VNFM_LIST_URL); - final ResponseEntity response = - testRestTemplateService.invokeHttpGet(esrVnfmListUrl, EsrVnfmList.class); - - assertTrue(response.hasBody()); - - final EsrVnfmList actualEsrVnfmList = response.getBody(); - - final List esrVnfmList = actualEsrVnfmList.getEsrVnfm(); - assertNotNull(esrVnfmList); - assertEquals(1, esrVnfmList.size()); - final EsrVnfm actualEsrVnfm = esrVnfmList.get(0); - assertEquals(ESR_VNFM_ID, actualEsrVnfm.getVnfmId()); - assertEquals(ESR_VIM_ID, actualEsrVnfm.getVimId()); - - } - - @Test - public void test_putEsrSystemInfo_successfullyAddedToCache() throws Exception { - final String esrVnfmUrl = getUrl(ESR_VNFM_URL, ESR_VNFM_ID); - addEsrVnfmAndAssertResponse(esrVnfmUrl); - final String esrSystemInfoListUrl = getUrl(ESR_VNFM_URL, ESR_VNFM_ID, ESR_SYSTEM_INFO_LIST_URL); - - final String esrSystemInfoUrl = esrSystemInfoListUrl + "/esr-system-info/" + ESR_SYSTEM_INFO_ID; - final ResponseEntity esrSystemInfoResponse = - testRestTemplateService.invokeHttpPut(esrSystemInfoUrl, TestUtils.getEsrSystemInfo(), Void.class); - assertEquals(HttpStatus.ACCEPTED, esrSystemInfoResponse.getStatusCode()); - - final ResponseEntity response = - testRestTemplateService.invokeHttpGet(esrSystemInfoListUrl, EsrSystemInfoList.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - final EsrSystemInfoList actualEsrSystemInfoList = response.getBody(); - - final List esrSystemInfoList = actualEsrSystemInfoList.getEsrSystemInfo(); - assertNotNull(esrSystemInfoList); - assertEquals(1, esrSystemInfoList.size()); - - final EsrSystemInfo esrSystemInfo = esrSystemInfoList.get(0); - assertEquals(ESR_SYSTEM_INFO_ID, esrSystemInfo.getEsrSystemInfoId()); - assertEquals(SYSTEM_NAME, esrSystemInfo.getSystemName()); - assertEquals(ESR_TYEP, esrSystemInfo.getType()); - assertEquals(ESR_VENDOR, esrSystemInfo.getVendor()); - assertEquals(ESR_SERVICE_URL, esrSystemInfo.getServiceUrl()); - assertEquals(ESR_USERNAME, esrSystemInfo.getUserName()); - assertEquals(ESR_PASSWORD, esrSystemInfo.getPassword()); - assertEquals(ESR_SYSTEM_TYPE, esrSystemInfo.getSystemType()); - - - } - - @Test - public void test_putEsrRelationToGenericVnfm_successfullyAddedToCache() throws Exception { - final String esrVnfmUrl = getUrl(ESR_VNFM_URL, ESR_VNFM_ID); - - addEsrVnfmAndAssertResponse(esrVnfmUrl); - addCustomerServiceAndGenericVnf(); - - final String relationShipUrl = esrVnfmUrl + RELATIONSHIP_LIST_RELATIONSHIP_URL; - - final ResponseEntity response = testRestTemplateService.invokeHttpPut(relationShipUrl, - TestUtils.getGenericVnfRelatedLink(), Void.class); - assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - - final Optional optional = externalSystemCacheServiceProvider.getEsrVnfm(ESR_VNFM_ID); - assertTrue(optional.isPresent()); - - final EsrVnfm actualEsrVnfm = optional.get(); - final RelationshipList relationshipList = actualEsrVnfm.getRelationshipList(); - assertNotNull(relationshipList); - assertFalse(relationshipList.getRelationship().isEmpty()); - - final Relationship relationship = relationshipList.getRelationship().get(0); - - assertEquals(Constants.DEPENDS_ON, relationship.getRelationshipLabel()); - assertFalse(relationship.getRelationshipData().isEmpty()); - assertEquals(1, relationship.getRelationshipData().size()); - - final RelationshipData relationshipData = - getRelationshipData(relationship.getRelationshipData(), Constants.GENERIC_VNF_VNF_ID); - assertNotNull(relationshipData); - assertEquals(VNF_ID, relationshipData.getRelationshipValue()); - - final Optional genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); - assertTrue(genericVnfOptional.isPresent()); - final GenericVnf actualGenericVnf = genericVnfOptional.get(); - final RelationshipList relationshipListGenericVnf = actualGenericVnf.getRelationshipList(); - assertNotNull(relationshipListGenericVnf); - assertFalse(relationshipListGenericVnf.getRelationship().isEmpty()); - - final Relationship relationshipGenericVnf = relationshipListGenericVnf.getRelationship().get(0); - - assertEquals(Constants.DEPENDS_ON, relationshipGenericVnf.getRelationshipLabel()); - assertFalse(relationshipGenericVnf.getRelationshipData().isEmpty()); - assertEquals(1, relationshipGenericVnf.getRelationshipData().size()); - - final RelationshipData esrRelationshipData = - getRelationshipData(relationshipGenericVnf.getRelationshipData(), Constants.ESR_VNFM_VNFM_ID); - assertNotNull(esrRelationshipData); - assertEquals(ESR_VNFM_ID, esrRelationshipData.getRelationshipValue()); - - - } - - private void addEsrVnfmAndAssertResponse(final String esrVnfmUrl) throws IOException { - final ResponseEntity esrVnfmResponse = - testRestTemplateService.invokeHttpPut(esrVnfmUrl, TestUtils.getEsrVnfm(), Void.class); - assertEquals(HttpStatus.ACCEPTED, esrVnfmResponse.getStatusCode()); - } - - private void addCustomerServiceAndGenericVnf() throws Exception, IOException { - final ResponseEntity customerResponse = - testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class); - assertEquals(HttpStatus.ACCEPTED, customerResponse.getStatusCode()); - - final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); - final ResponseEntity serviceInstanceResponse = - testRestTemplateService.invokeHttpPut(serviceInstanceUrl, TestUtils.getServiceInstance(), Void.class); - assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode()); - - final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); - final ResponseEntity genericVnfResponse = - testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class); - assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode()); - - } -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java deleted file mode 100755 index 8ec26065..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java +++ /dev/null @@ -1,430 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.controller; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; -import static org.onap.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; -import static org.onap.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; -import static org.onap.aaisimulator.utils.TestConstants.CLOUD_OWNER_NAME; -import static org.onap.aaisimulator.utils.TestConstants.CLOUD_REGION_NAME; -import static org.onap.aaisimulator.utils.TestConstants.CUSTOMERS_URL; -import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_NAME; -import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; -import static org.onap.aaisimulator.utils.TestConstants.GLOBAL_CUSTOMER_ID; -import static org.onap.aaisimulator.utils.TestConstants.LINE_OF_BUSINESS_NAME; -import static org.onap.aaisimulator.utils.TestConstants.PLATFORM_NAME; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_NAME; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_TYPE; -import static org.onap.aaisimulator.utils.TestConstants.VNF_ID; -import java.io.IOException; -import java.util.List; -import java.util.Optional; -import org.junit.After; -import org.junit.Test; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.aai.domain.yang.GenericVnfs; -import org.onap.aai.domain.yang.RelatedToProperty; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipData; -import org.onap.aai.domain.yang.RelationshipList; -import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aaisimulator.service.providers.CustomerCacheServiceProvider; -import org.onap.aaisimulator.service.providers.GenericVnfCacheServiceProvider; -import org.onap.aaisimulator.service.providers.LinesOfBusinessCacheServiceProvider; -import org.onap.aaisimulator.service.providers.PlatformCacheServiceProvider; -import org.onap.aaisimulator.utils.Constants; -import org.onap.aaisimulator.utils.TestConstants; -import org.onap.aaisimulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public class GenericVnfsControllerTest extends AbstractSpringBootTest { - - @Autowired - private CustomerCacheServiceProvider customerCacheServiceProvider; - - @Autowired - private GenericVnfCacheServiceProvider genericVnfCacheServiceProvider; - - @Autowired - private LinesOfBusinessCacheServiceProvider linesOfBusinessCacheServiceProvider; - - @Autowired - private PlatformCacheServiceProvider platformVnfCacheServiceProvider; - - @After - public void after() { - customerCacheServiceProvider.clearAll(); - genericVnfCacheServiceProvider.clearAll(); - platformVnfCacheServiceProvider.clearAll(); - linesOfBusinessCacheServiceProvider.clearAll(); - } - - @Test - public void test_putGenericVnf_successfullyAddedToCache() throws Exception { - - final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); - final ResponseEntity genericVnfResponse = - testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class); - assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode()); - - final ResponseEntity response = - testRestTemplateService.invokeHttpGet(genericVnfUrl, GenericVnf.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - - final GenericVnf actualGenericVnf = response.getBody(); - assertEquals(GENERIC_VNF_NAME, actualGenericVnf.getVnfName()); - assertEquals(VNF_ID, actualGenericVnf.getVnfId()); - - } - - @Test - public void test_putGenericVnfRelation_successfullyAddedToCache() throws Exception { - - addCustomerServiceAndGenericVnf(); - - final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); - final ResponseEntity genericVnfRelationShipResponse = testRestTemplateService - .invokeHttpPut(genericVnfRelationShipUrl, TestUtils.getRelationShip(), Void.class); - - assertEquals(HttpStatus.ACCEPTED, genericVnfRelationShipResponse.getStatusCode()); - - - final Optional optional = - customerCacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID); - - assertTrue(optional.isPresent()); - - final ServiceInstance actualServiceInstance = optional.get(); - final RelationshipList actualRelationshipList = actualServiceInstance.getRelationshipList(); - assertNotNull(actualRelationshipList); - assertFalse(actualRelationshipList.getRelationship().isEmpty()); - final Relationship actualRelationShip = actualRelationshipList.getRelationship().get(0); - - assertEquals(Constants.COMPOSED_OF, actualRelationShip.getRelationshipLabel()); - assertEquals(GENERIC_VNF_URL + VNF_ID, actualRelationShip.getRelatedLink()); - - - assertFalse(actualRelationShip.getRelatedToProperty().isEmpty()); - assertFalse(actualRelationShip.getRelationshipData().isEmpty()); - final RelatedToProperty actualRelatedToProperty = actualRelationShip.getRelatedToProperty().get(0); - final RelationshipData actualRelationshipData = actualRelationShip.getRelationshipData().get(0); - - assertEquals(Constants.GENERIC_VNF_VNF_NAME, actualRelatedToProperty.getPropertyKey()); - assertEquals(GENERIC_VNF_NAME, actualRelatedToProperty.getPropertyValue()); - assertEquals(Constants.GENERIC_VNF_VNF_ID, actualRelationshipData.getRelationshipKey()); - assertEquals(VNF_ID, actualRelationshipData.getRelationshipValue()); - - final Optional genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); - assertTrue(genericVnfOptional.isPresent()); - final GenericVnf actualGenericVnf = genericVnfOptional.get(); - final RelationshipList relationshipList = actualGenericVnf.getRelationshipList(); - assertNotNull(relationshipList); - assertFalse(relationshipList.getRelationship().isEmpty()); - - final Relationship relationship = relationshipList.getRelationship().get(0); - assertFalse(relationship.getRelatedToProperty().isEmpty()); - assertEquals(3, relationship.getRelationshipData().size()); - assertEquals(CUSTOMERS_URL + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL, relationship.getRelatedLink()); - - - final List relatedToProperty = relationship.getRelatedToProperty(); - final RelatedToProperty firstRelatedToProperty = relatedToProperty.get(0); - assertEquals(Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_NAME, firstRelatedToProperty.getPropertyKey()); - assertEquals(SERVICE_NAME, firstRelatedToProperty.getPropertyValue()); - - final List relationshipData = relationship.getRelationshipData(); - - final RelationshipData globalRelationshipData = - getRelationshipData(relationshipData, Constants.CUSTOMER_GLOBAL_CUSTOMER_ID); - assertNotNull(globalRelationshipData); - assertEquals(GLOBAL_CUSTOMER_ID, globalRelationshipData.getRelationshipValue()); - - final RelationshipData serviceSubscriptionRelationshipData = - getRelationshipData(relationshipData, Constants.SERVICE_SUBSCRIPTION_SERVICE_TYPE); - assertNotNull(serviceSubscriptionRelationshipData); - assertEquals(SERVICE_TYPE, serviceSubscriptionRelationshipData.getRelationshipValue()); - - final RelationshipData serviceInstanceRelationshipData = - getRelationshipData(relationshipData, Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_ID); - assertNotNull(serviceInstanceRelationshipData); - assertEquals(SERVICE_INSTANCE_ID, serviceInstanceRelationshipData.getRelationshipValue()); - - } - - @Test - public void test_putGenericVnfRelationToPlatform_successfullyAddedToCache() throws Exception { - addCustomerServiceAndGenericVnf(); - - final String platformUrl = getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME); - final ResponseEntity platformResponse = - testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class); - assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode()); - - final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); - final ResponseEntity genericVnfRelationShipResponse = testRestTemplateService - .invokeHttpPut(genericVnfRelationShipUrl, TestUtils.getPlatformRelatedLink(), Void.class); - - assertEquals(HttpStatus.ACCEPTED, genericVnfRelationShipResponse.getStatusCode()); - - final Optional genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); - assertTrue(genericVnfOptional.isPresent()); - final GenericVnf actualGenericVnf = genericVnfOptional.get(); - final RelationshipList relationshipList = actualGenericVnf.getRelationshipList(); - assertNotNull(relationshipList); - assertFalse(relationshipList.getRelationship().isEmpty()); - - final Relationship relationship = relationshipList.getRelationship().get(0); - - assertEquals(Constants.USES, relationship.getRelationshipLabel()); - assertFalse(relationship.getRelationshipData().isEmpty()); - assertEquals(1, relationship.getRelationshipData().size()); - assertEquals(TestConstants.PLATFORMS_URL + PLATFORM_NAME, relationship.getRelatedLink()); - - - final List relationshipData = relationship.getRelationshipData(); - - final RelationshipData platformRelationshipData = - getRelationshipData(relationshipData, Constants.PLATFORM_PLATFORM_NAME); - assertNotNull(platformRelationshipData); - assertEquals(PLATFORM_NAME, platformRelationshipData.getRelationshipValue()); - - } - - @Test - public void test_putGenericVnfRelationToLineOfBusiness_successfullyAddedToCache() throws Exception { - addCustomerServiceAndGenericVnf(); - - final String url = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME); - final ResponseEntity responseEntity = - testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class); - assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); - - final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); - final ResponseEntity genericVnfRelationShipResponse = testRestTemplateService - .invokeHttpPut(genericVnfRelationShipUrl, TestUtils.getLineOfBusinessRelatedLink(), Void.class); - - assertEquals(HttpStatus.ACCEPTED, genericVnfRelationShipResponse.getStatusCode()); - - final Optional genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); - assertTrue(genericVnfOptional.isPresent()); - final GenericVnf actualGenericVnf = genericVnfOptional.get(); - final RelationshipList relationshipList = actualGenericVnf.getRelationshipList(); - assertNotNull(relationshipList); - assertFalse(relationshipList.getRelationship().isEmpty()); - - final Relationship relationship = relationshipList.getRelationship().get(0); - - assertEquals(Constants.USES, relationship.getRelationshipLabel()); - assertEquals(TestConstants.LINES_OF_BUSINESS_URL + LINE_OF_BUSINESS_NAME, relationship.getRelatedLink()); - - assertFalse(relationship.getRelationshipData().isEmpty()); - assertEquals(1, relationship.getRelationshipData().size()); - - final List relationshipData = relationship.getRelationshipData(); - - final RelationshipData lineOfBusinessRelationshipData = - getRelationshipData(relationshipData, Constants.LINE_OF_BUSINESS_LINE_OF_BUSINESS_NAME); - assertNotNull(lineOfBusinessRelationshipData); - assertEquals(LINE_OF_BUSINESS_NAME, lineOfBusinessRelationshipData.getRelationshipValue()); - - } - - @Test - public void test_putGenericVnfRelationToCloudRegion_successfullyAddedToCache() throws Exception { - addCustomerServiceAndGenericVnf(); - - final String url = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); - - final ResponseEntity responseEntity = - testRestTemplateService.invokeHttpPut(url, TestUtils.getCloudRegion(), Void.class); - assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); - - final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); - final ResponseEntity genericVnfRelationShipResponse = testRestTemplateService - .invokeHttpPut(genericVnfRelationShipUrl, TestUtils.getCloudRegionRelatedLink(), Void.class); - - assertEquals(HttpStatus.ACCEPTED, genericVnfRelationShipResponse.getStatusCode()); - - final Optional genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); - assertTrue(genericVnfOptional.isPresent()); - final GenericVnf actualGenericVnf = genericVnfOptional.get(); - final RelationshipList relationshipList = actualGenericVnf.getRelationshipList(); - assertNotNull(relationshipList); - assertFalse(relationshipList.getRelationship().isEmpty()); - - final Relationship relationship = relationshipList.getRelationship().get(0); - - assertEquals(Constants.LOCATED_IN, relationship.getRelationshipLabel()); - assertEquals(TestConstants.CLOUD_REGIONS + CLOUD_OWNER_NAME + "/" + CLOUD_REGION_NAME, - relationship.getRelatedLink()); - - assertFalse(relationship.getRelationshipData().isEmpty()); - assertEquals(2, relationship.getRelationshipData().size()); - - final List relationshipDataList = relationship.getRelationshipData(); - - final RelationshipData cloudOwnerRelationshipData = - getRelationshipData(relationshipDataList, Constants.CLOUD_REGION_CLOUD_OWNER); - assertNotNull(cloudOwnerRelationshipData); - assertEquals(CLOUD_OWNER_NAME, cloudOwnerRelationshipData.getRelationshipValue()); - - final RelationshipData cloudRegionIdRelationshipData = - getRelationshipData(relationshipDataList, Constants.CLOUD_REGION_CLOUD_REGION_ID); - assertNotNull(cloudRegionIdRelationshipData); - assertEquals(CLOUD_REGION_NAME, cloudRegionIdRelationshipData.getRelationshipValue()); - - final List relatedToPropertyList = relationship.getRelatedToProperty(); - - final RelatedToProperty cloudRegionOwnerDefinedTypeProperty = - getRelatedToProperty(relatedToPropertyList, Constants.CLOUD_REGION_OWNER_DEFINED_TYPE); - assertNotNull(cloudRegionOwnerDefinedTypeProperty); - assertEquals("OwnerType", cloudRegionOwnerDefinedTypeProperty.getPropertyValue()); - - } - - @Test - public void test_putBiDirectionalRelationShip_successfullyAddedToCache() throws Exception { - addCustomerServiceAndGenericVnf(); - - final String relationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); - - final ResponseEntity responseEntity = testRestTemplateService.invokeHttpPut(relationShipUrl, - TestUtils.getTenantRelationShip(), Relationship.class); - assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); - - final Optional optional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); - assertTrue(optional.isPresent()); - - final GenericVnf actual = optional.get(); - - assertNotNull(actual.getRelationshipList()); - final List relationshipList = actual.getRelationshipList().getRelationship(); - assertFalse("Relationship list should not be empty", relationshipList.isEmpty()); - final Relationship relationship = relationshipList.get(0); - - assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty()); - assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty()); - } - - @Test - public void test_patchGenericVnf_usingVnfId_OrchStatusChangedInCache() throws Exception { - addCustomerServiceAndGenericVnf(); - - final HttpHeaders httpHeaders = testRestTemplateService.getHttpHeaders(); - httpHeaders.add(X_HTTP_METHOD_OVERRIDE, HttpMethod.PATCH.toString()); - httpHeaders.remove(HttpHeaders.CONTENT_TYPE); - httpHeaders.add(HttpHeaders.CONTENT_TYPE, Constants.APPLICATION_MERGE_PATCH_JSON); - - final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); - final ResponseEntity orchStatuUpdateServiceInstanceResponse = testRestTemplateService - .invokeHttpPost(httpHeaders, genericVnfUrl, TestUtils.getGenericVnfOrchStatuUpdate(), Void.class); - - assertEquals(HttpStatus.ACCEPTED, orchStatuUpdateServiceInstanceResponse.getStatusCode()); - - final ResponseEntity response = - testRestTemplateService.invokeHttpGet(genericVnfUrl, GenericVnf.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - - final GenericVnf actualGenericVnf = response.getBody(); - assertEquals(GENERIC_VNF_NAME, actualGenericVnf.getVnfName()); - assertEquals(VNF_ID, actualGenericVnf.getVnfId()); - assertEquals("Assigned", actualGenericVnf.getOrchestrationStatus()); - - } - - @Test - public void test_getGenericVnfs_usingSelfLink_getAllGenericVnfsInCache() throws Exception { - - addCustomerServiceAndGenericVnf(); - - final String selfLink = "http://localhost:9921/generic-vnf/" + VNF_ID; - final String url = getUrl(TestConstants.GENERIC_VNFS_URL_1) + "?selflink=" + selfLink; - final ResponseEntity response = testRestTemplateService.invokeHttpGet(url, GenericVnfs.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - - final GenericVnfs actualGenericVnfs = response.getBody(); - final List genericVnfList = actualGenericVnfs.getGenericVnf(); - assertNotNull(genericVnfList); - assertEquals(1, genericVnfList.size()); - final GenericVnf actualGenericVnf = genericVnfList.get(0); - assertEquals(selfLink, actualGenericVnf.getSelflink()); - assertEquals(GENERIC_VNF_NAME, actualGenericVnf.getVnfName()); - assertEquals(VNF_ID, actualGenericVnf.getVnfId()); - } - - @Test - public void test_deleteGenericVnf_usingVnfIdAndResourceVersion_removedFromCache() throws Exception { - - addCustomerServiceAndGenericVnf(); - - final Optional genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); - assertTrue(genericVnfOptional.isPresent()); - final GenericVnf genericVnf = genericVnfOptional.get(); - - final String genericVnfDeleteUrl = - getUrl(GENERIC_VNF_URL, genericVnf.getVnfId()) + "?resource-version=" + genericVnf.getResourceVersion(); - - final ResponseEntity responseEntity = - testRestTemplateService.invokeHttpDelete(genericVnfDeleteUrl, Void.class); - assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); - assertFalse(genericVnfCacheServiceProvider.getGenericVnf(VNF_ID).isPresent()); - - } - - private void addCustomerServiceAndGenericVnf() throws Exception, IOException { - final ResponseEntity customerResponse = - testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class); - assertEquals(HttpStatus.ACCEPTED, customerResponse.getStatusCode()); - - final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); - final ResponseEntity serviceInstanceResponse = - testRestTemplateService.invokeHttpPut(serviceInstanceUrl, TestUtils.getServiceInstance(), Void.class); - assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode()); - - final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); - final ResponseEntity genericVnfResponse = - testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class); - assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode()); - - } - - -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java deleted file mode 100755 index 0b6cfb50..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.controller; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; -import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; -import static org.onap.aaisimulator.utils.TestConstants.LINE_OF_BUSINESS_NAME; -import static org.onap.aaisimulator.utils.TestConstants.VNF_ID; -import java.util.List; -import java.util.Optional; -import org.junit.After; -import org.junit.Test; -import org.onap.aai.domain.yang.LineOfBusiness; -import org.onap.aai.domain.yang.RelatedToProperty; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipData; -import org.onap.aaisimulator.models.Format; -import org.onap.aaisimulator.models.Results; -import org.onap.aaisimulator.service.providers.LinesOfBusinessCacheServiceProvider; -import org.onap.aaisimulator.utils.Constants; -import org.onap.aaisimulator.utils.TestConstants; -import org.onap.aaisimulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public class LinesOfBusinessControllerTest extends AbstractSpringBootTest { - - @Autowired - private LinesOfBusinessCacheServiceProvider linesOfBusinessCacheServiceProvider; - - @After - public void after() { - linesOfBusinessCacheServiceProvider.clearAll(); - } - - @Test - public void test_putLineOfBusiness_successfullyAddedToCache() throws Exception { - - final String url = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME); - final ResponseEntity lineOfBusinessResponse = - testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class); - assertEquals(HttpStatus.ACCEPTED, lineOfBusinessResponse.getStatusCode()); - - final ResponseEntity response = - testRestTemplateService.invokeHttpGet(url, LineOfBusiness.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - - final LineOfBusiness actualLineOfBusiness = response.getBody(); - assertEquals(LINE_OF_BUSINESS_NAME, actualLineOfBusiness.getLineOfBusinessName()); - assertNotNull("resource version should not be null", actualLineOfBusiness.getResourceVersion()); - - } - - @Test - public void test_getLineOfBusinessWithFormatCount() throws Exception { - - final String url = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME); - final ResponseEntity lineOfBusinessResponse = - testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class); - assertEquals(HttpStatus.ACCEPTED, lineOfBusinessResponse.getStatusCode()); - - final ResponseEntity response = testRestTemplateService - .invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - - final Results result = response.getBody(); - assertNotNull(result.getValues()); - assertFalse(result.getValues().isEmpty()); - assertEquals(1, result.getValues().get(0).get(Constants.LINE_OF_BUSINESS)); - } - - - @Test - public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception { - - final String url = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME); - final ResponseEntity response = - testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class); - assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - - final String relationShipUrl = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME, - BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); - - final ResponseEntity responseEntity = testRestTemplateService.invokeHttpPut(relationShipUrl, - TestUtils.getGenericVnfRelationShip(), Relationship.class); - assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); - - final Optional optional = - linesOfBusinessCacheServiceProvider.getLineOfBusiness(LINE_OF_BUSINESS_NAME); - assertTrue(optional.isPresent()); - - final LineOfBusiness actual = optional.get(); - - assertNotNull(actual.getRelationshipList()); - final List relationshipList = actual.getRelationshipList().getRelationship(); - assertFalse("Relationship list should not be empty", relationshipList.isEmpty()); - final Relationship relationship = relationshipList.get(0); - - assertEquals(GENERIC_VNF_URL + VNF_ID, relationship.getRelatedLink()); - assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty()); - assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty()); - - final RelationshipData relationshipData = relationship.getRelationshipData().get(0); - assertEquals(Constants.GENERIC_VNF_VNF_ID, relationshipData.getRelationshipKey()); - assertEquals(TestConstants.VNF_ID, relationshipData.getRelationshipValue()); - - final RelatedToProperty relatedToProperty = relationship.getRelatedToProperty().get(0); - assertEquals(Constants.GENERIC_VNF_VNF_NAME, relatedToProperty.getPropertyKey()); - assertEquals(TestConstants.GENERIC_VNF_NAME, relatedToProperty.getPropertyValue()); - - } - -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java deleted file mode 100755 index 12412872..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java +++ /dev/null @@ -1,156 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.controller; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.aaisimulator.utils.Constants.RESOURCE_LINK; -import static org.onap.aaisimulator.utils.Constants.RESOURCE_TYPE; -import static org.onap.aaisimulator.utils.Constants.SERVICE_RESOURCE_TYPE; -import static org.onap.aaisimulator.utils.TestConstants.CUSTOMERS_URL; -import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNFS_URL; -import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_NAME; -import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_NAME; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; -import static org.onap.aaisimulator.utils.TestConstants.VNF_ID; -import java.io.IOException; -import java.util.Map; -import org.junit.After; -import org.junit.Test; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.aai.domain.yang.GenericVnfs; -import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aaisimulator.models.Format; -import org.onap.aaisimulator.models.Results; -import org.onap.aaisimulator.service.providers.CustomerCacheServiceProvider; -import org.onap.aaisimulator.service.providers.NodesCacheServiceProvider; -import org.onap.aaisimulator.utils.TestConstants; -import org.onap.aaisimulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public class NodesControllerTest extends AbstractSpringBootTest { - - @Autowired - private NodesCacheServiceProvider nodesCacheServiceProvider; - - @Autowired - private CustomerCacheServiceProvider customerCacheServiceProvider; - - @After - public void after() { - nodesCacheServiceProvider.clearAll(); - customerCacheServiceProvider.clearAll(); - } - - @Test - public void test_getNodesSericeInstance_usingServiceInstanceId_ableToRetrieveServiceInstanceFromCache() - throws Exception { - - invokeCustomerandServiceInstanceUrls(); - - final ResponseEntity actual = testRestTemplateService - .invokeHttpGet(getUrl(TestConstants.NODES_URL, SERVICE_INSTANCE_URL), ServiceInstance.class); - - assertEquals(HttpStatus.OK, actual.getStatusCode()); - assertTrue(actual.hasBody()); - - final ServiceInstance actualServiceInstance = actual.getBody(); - - assertEquals(SERVICE_NAME, actualServiceInstance.getServiceInstanceName()); - assertEquals(SERVICE_INSTANCE_ID, actualServiceInstance.getServiceInstanceId()); - - } - - @Test - public void test_getNodesSericeInstance_usingServiceInstanceIdAndFormatPathed_ableToRetrieveServiceInstanceFromCache() - throws Exception { - - invokeCustomerandServiceInstanceUrls(); - - final ResponseEntity actual = testRestTemplateService.invokeHttpGet( - getUrl(TestConstants.NODES_URL, SERVICE_INSTANCE_URL) + "?format=" + Format.PATHED.getValue(), - Results.class); - - assertEquals(HttpStatus.OK, actual.getStatusCode()); - assertTrue(actual.hasBody()); - - final Results result = actual.getBody(); - - assertNotNull(result.getValues()); - assertFalse(result.getValues().isEmpty()); - final Map actualMap = result.getValues().get(0); - - assertEquals(CUSTOMERS_URL + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL, actualMap.get(RESOURCE_LINK)); - assertEquals(SERVICE_RESOURCE_TYPE, actualMap.get(RESOURCE_TYPE)); - - } - - @Test - public void test_getNodesGenericVnfs_usingVnfName_ableToRetrieveItFromCache() throws Exception { - invokeCustomerandServiceInstanceUrls(); - - final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); - final ResponseEntity genericVnfResponse = - testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class); - assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode()); - - final String nodeGenericVnfsUrl = - getUrl(TestConstants.NODES_URL, GENERIC_VNFS_URL) + "?vnf-name=" + GENERIC_VNF_NAME; - - final ResponseEntity actual = - testRestTemplateService.invokeHttpGet(nodeGenericVnfsUrl, GenericVnfs.class); - - assertEquals(HttpStatus.OK, actual.getStatusCode()); - assertTrue(actual.hasBody()); - - final GenericVnfs genericVnfs = actual.getBody(); - assertEquals(1, genericVnfs.getGenericVnf().size()); - - final GenericVnf genericVnf = genericVnfs.getGenericVnf().get(0); - assertEquals(GENERIC_VNF_NAME, genericVnf.getVnfName()); - assertEquals(VNF_ID, genericVnf.getVnfId()); - - } - - private void invokeCustomerandServiceInstanceUrls() throws Exception, IOException { - final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); - - final ResponseEntity response = - testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class); - - assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - - final ResponseEntity response2 = - testRestTemplateService.invokeHttpPut(url, TestUtils.getServiceInstance(), Void.class); - assertEquals(HttpStatus.ACCEPTED, response2.getStatusCode()); - } - -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java deleted file mode 100755 index c5baad47..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java +++ /dev/null @@ -1,199 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.controller; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; -import static org.onap.aaisimulator.utils.TestConstants.CUSTOMERS_URL; -import static org.onap.aaisimulator.utils.TestConstants.GLOBAL_CUSTOMER_ID; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_TYPE; -import java.io.IOException; -import java.util.List; -import java.util.Optional; -import org.junit.After; -import org.junit.Test; -import org.onap.aai.domain.yang.OwningEntity; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipData; -import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aaisimulator.models.Format; -import org.onap.aaisimulator.models.Results; -import org.onap.aaisimulator.service.providers.CustomerCacheServiceProvider; -import org.onap.aaisimulator.service.providers.OwnEntityCacheServiceProvider; -import org.onap.aaisimulator.utils.Constants; -import org.onap.aaisimulator.utils.TestConstants; -import org.onap.aaisimulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public class OwningEntityControllerTest extends AbstractSpringBootTest { - - private static final String OWN_ENTITY_ID_VALUE = "oe_1"; - private static final String OWN_ENTITY_NAME_VALUE = "oe_2"; - - @Autowired - private OwnEntityCacheServiceProvider cacheServiceProvider; - - @Autowired - private CustomerCacheServiceProvider customerCacheServiceProvider; - - @After - public void after() { - cacheServiceProvider.clearAll(); - customerCacheServiceProvider.clearAll(); - } - - @Test - public void test_putOwningEntity_successfullyAddedToCache() throws Exception { - final String url = getUrl(TestConstants.OWNING_ENTITY_URL, OWN_ENTITY_ID_VALUE); - final ResponseEntity actual = - testRestTemplateService.invokeHttpPut(url, TestUtils.getOwningEntity(), Void.class); - - assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - - final ResponseEntity actualResponse = - testRestTemplateService.invokeHttpGet(url, OwningEntity.class); - - assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); - assertTrue(actualResponse.hasBody()); - final OwningEntity actualOwningEntity = actualResponse.getBody(); - assertEquals(OWN_ENTITY_ID_VALUE, actualOwningEntity.getOwningEntityId()); - assertEquals(OWN_ENTITY_NAME_VALUE, actualOwningEntity.getOwningEntityName()); - assertNotNull(actualOwningEntity.getResourceVersion()); - - } - - @Test - public void test_getOwningEntityCount_correctResult() throws Exception { - final String url = getUrl(TestConstants.OWNING_ENTITY_URL, OWN_ENTITY_ID_VALUE); - final ResponseEntity actual = - testRestTemplateService.invokeHttpPut(url, TestUtils.getOwningEntity(), Void.class); - - assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - - final ResponseEntity actualResponse = testRestTemplateService - .invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class); - - assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); - assertTrue(actualResponse.hasBody()); - final Results result = actualResponse.getBody(); - assertNotNull(result.getValues()); - assertFalse(result.getValues().isEmpty()); - assertEquals(1, result.getValues().get(0).get(Constants.OWNING_ENTITY)); - } - - @Test - public void test_putOwningEntityRelationShip_successfullyAddedToCache() throws Exception { - addCustomerAndServiceInstance(); - - final String url = getUrl(TestConstants.OWNING_ENTITY_URL, OWN_ENTITY_ID_VALUE); - final ResponseEntity actual = - testRestTemplateService.invokeHttpPut(url, TestUtils.getOwningEntity(), Void.class); - assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - - final String owningEntityRelationshipUrl = url + RELATIONSHIP_LIST_RELATIONSHIP_URL; - - final ResponseEntity putResponse = testRestTemplateService.invokeHttpPut(owningEntityRelationshipUrl, - TestUtils.getOwningEntityRelationship(), Void.class); - - assertEquals(HttpStatus.ACCEPTED, putResponse.getStatusCode()); - - final ResponseEntity actualResponse = - testRestTemplateService.invokeHttpGet(url, OwningEntity.class); - - assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); - assertTrue(actualResponse.hasBody()); - final OwningEntity actualOwningEntity = actualResponse.getBody(); - assertEquals(OWN_ENTITY_ID_VALUE, actualOwningEntity.getOwningEntityId()); - assertEquals(OWN_ENTITY_NAME_VALUE, actualOwningEntity.getOwningEntityName()); - assertNotNull(actualOwningEntity.getRelationshipList()); - assertFalse(actualOwningEntity.getRelationshipList().getRelationship().isEmpty()); - assertNotNull(actualOwningEntity.getRelationshipList().getRelationship().get(0)); - - final Relationship actualRelationship = actualOwningEntity.getRelationshipList().getRelationship().get(0); - final List relationshipDataList = actualRelationship.getRelationshipData(); - assertEquals(Constants.BELONGS_TO, actualRelationship.getRelationshipLabel()); - assertFalse(relationshipDataList.isEmpty()); - assertEquals(3, relationshipDataList.size()); - - final RelationshipData globalRelationshipData = - getRelationshipData(relationshipDataList, Constants.CUSTOMER_GLOBAL_CUSTOMER_ID); - assertNotNull(globalRelationshipData); - assertEquals(GLOBAL_CUSTOMER_ID, globalRelationshipData.getRelationshipValue()); - - final RelationshipData serviceSubscriptionRelationshipData = - getRelationshipData(relationshipDataList, Constants.SERVICE_SUBSCRIPTION_SERVICE_TYPE); - assertNotNull(serviceSubscriptionRelationshipData); - assertEquals(SERVICE_TYPE, serviceSubscriptionRelationshipData.getRelationshipValue()); - - final RelationshipData serviceInstanceRelationshipData = - getRelationshipData(relationshipDataList, Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_ID); - assertNotNull(serviceInstanceRelationshipData); - assertEquals(SERVICE_INSTANCE_ID, serviceInstanceRelationshipData.getRelationshipValue()); - - final Optional optional = - customerCacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID); - assertTrue(optional.isPresent()); - - final ServiceInstance serviceInstance = optional.get(); - - assertNotNull(serviceInstance.getRelationshipList()); - final List serviceRelationshipList = serviceInstance.getRelationshipList().getRelationship(); - assertFalse(serviceRelationshipList.isEmpty()); - assertEquals(1, serviceRelationshipList.size()); - final Relationship relationship = serviceRelationshipList.get(0); - assertEquals(Constants.BELONGS_TO, relationship.getRelationshipLabel()); - assertEquals(TestConstants.OWNING_ENTITY_URL + OWN_ENTITY_ID_VALUE, relationship.getRelatedLink()); - - final List serviceRelationshipDataList = serviceRelationshipList.get(0).getRelationshipData(); - assertFalse(serviceRelationshipDataList.isEmpty()); - assertEquals(1, serviceRelationshipDataList.size()); - - final RelationshipData owningEntityRelationshipData = - getRelationshipData(serviceRelationshipDataList, Constants.OWNING_ENTITY_OWNING_ENTITY_ID); - assertNotNull(owningEntityRelationshipData); - assertEquals(OWN_ENTITY_ID_VALUE, owningEntityRelationshipData.getRelationshipValue()); - - } - - private void addCustomerAndServiceInstance() throws Exception, IOException { - final ResponseEntity customerResponse = - testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class); - assertEquals(HttpStatus.ACCEPTED, customerResponse.getStatusCode()); - - final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); - final ResponseEntity serviceInstanceResponse = - testRestTemplateService.invokeHttpPut(serviceInstanceUrl, TestUtils.getServiceInstance(), Void.class); - assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode()); - - } - -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java deleted file mode 100755 index 00c66388..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.controller; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; -import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; -import static org.onap.aaisimulator.utils.TestConstants.PLATFORM_NAME; -import static org.onap.aaisimulator.utils.TestConstants.VNF_ID; -import java.util.List; -import java.util.Optional; -import org.junit.After; -import org.junit.Test; -import org.onap.aai.domain.yang.Platform; -import org.onap.aai.domain.yang.RelatedToProperty; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipData; -import org.onap.aaisimulator.models.Format; -import org.onap.aaisimulator.models.Results; -import org.onap.aaisimulator.service.providers.PlatformCacheServiceProvider; -import org.onap.aaisimulator.utils.Constants; -import org.onap.aaisimulator.utils.TestConstants; -import org.onap.aaisimulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public class PlatformControllerTest extends AbstractSpringBootTest { - - @Autowired - private PlatformCacheServiceProvider platformCacheServiceProvider; - - @After - public void after() { - platformCacheServiceProvider.clearAll(); - } - - @Test - public void test_putPlatform_successfullyAddedToCache() throws Exception { - - final String platformUrl = getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME); - final ResponseEntity platformResponse = - testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class); - assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode()); - - final ResponseEntity response = testRestTemplateService.invokeHttpGet(platformUrl, Platform.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - - final Platform actualPlatform = response.getBody(); - assertEquals(PLATFORM_NAME, actualPlatform.getPlatformName()); - assertNotNull("resource version should not be null", actualPlatform.getResourceVersion()); - - } - - @Test - public void test_getPlatformWithFormatCount() throws Exception { - - final String platformUrl = getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME); - - final ResponseEntity platformResponse = - testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class); - assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode()); - - final ResponseEntity response = testRestTemplateService.invokeHttpGet( - platformUrl + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - - final Results result = response.getBody(); - assertNotNull(result.getValues()); - assertFalse(result.getValues().isEmpty()); - assertEquals(1, result.getValues().get(0).get(Constants.PLATFORM)); - - } - - @Test - public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception { - - final String platformUrl = getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME); - final ResponseEntity platformResponse = - testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class); - assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode()); - - final String platformRelationShipUrl = - getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME, BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); - - final ResponseEntity responseEntity = testRestTemplateService - .invokeHttpPut(platformRelationShipUrl, TestUtils.getGenericVnfRelationShip(), Relationship.class); - assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); - - final Optional optional = platformCacheServiceProvider.getPlatform(PLATFORM_NAME); - assertTrue(optional.isPresent()); - - final Platform actual = optional.get(); - - assertNotNull(actual.getRelationshipList()); - final List relationshipList = actual.getRelationshipList().getRelationship(); - assertFalse("Relationship list should not be empty", relationshipList.isEmpty()); - final Relationship relationship = relationshipList.get(0); - - assertEquals(GENERIC_VNF_URL + VNF_ID, relationship.getRelatedLink()); - assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty()); - assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty()); - - final RelationshipData relationshipData = relationship.getRelationshipData().get(0); - assertEquals(Constants.GENERIC_VNF_VNF_ID, relationshipData.getRelationshipKey()); - assertEquals(TestConstants.VNF_ID, relationshipData.getRelationshipValue()); - - final RelatedToProperty relatedToProperty = relationship.getRelatedToProperty().get(0); - assertEquals(Constants.GENERIC_VNF_VNF_NAME, relatedToProperty.getPropertyKey()); - assertEquals(TestConstants.GENERIC_VNF_NAME, relatedToProperty.getPropertyValue()); - - } - -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PnfsControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PnfsControllerTest.java deleted file mode 100755 index 440c66d6..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PnfsControllerTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.controller; - -import org.junit.After; -import org.junit.Test; -import org.onap.aai.domain.yang.v15.Pnf; -import org.onap.aaisimulator.service.providers.PnfCacheServiceProvider; -import org.onap.aaisimulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - - -/** - * @author Raj Gumma (raj.gumma@est.tech) - * - */ -public class PnfsControllerTest extends AbstractSpringBootTest { - - @Autowired - private PnfCacheServiceProvider cacheServiceProvider; - - private final String PNF="test-008"; - private final String PNF_URL= "/aai/v15/network/pnfs/pnf/"; - - - @After - public void after() { - cacheServiceProvider.clearAll(); - } - - @Test - public void test_pnf_successfullyAddedToCache() throws Exception { - - final String url = getUrl(PNF_URL, PNF); - final ResponseEntity pnfResponse = - testRestTemplateService.invokeHttpPut(url, TestUtils.getPnf(), Void.class); - assertEquals(HttpStatus.ACCEPTED, pnfResponse.getStatusCode()); - - final ResponseEntity response = - testRestTemplateService.invokeHttpGet(url, Pnf.class); - assertEquals(HttpStatus.OK, response.getStatusCode()); - - assertTrue(response.hasBody()); - - final Pnf actualPnf = response.getBody(); - assertEquals("test-008", actualPnf.getPnfName()); - assertEquals("5f2602dc-f647-4535-8f1d-9ec079e68a49", actualPnf.getPnfId()); - - } -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java deleted file mode 100755 index 5478ef7c..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.controller; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; -import static org.onap.aaisimulator.utils.TestConstants.CUSTOMERS_URL; -import static org.onap.aaisimulator.utils.TestConstants.GLOBAL_CUSTOMER_ID; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_TYPE; -import java.io.IOException; -import java.util.List; -import java.util.Optional; -import org.junit.After; -import org.junit.Test; -import org.onap.aai.domain.yang.Project; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipData; -import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aaisimulator.models.Results; -import org.onap.aaisimulator.service.providers.CustomerCacheServiceProvider; -import org.onap.aaisimulator.service.providers.ProjectCacheServiceProvider; -import org.onap.aaisimulator.utils.Constants; -import org.onap.aaisimulator.utils.TestConstants; -import org.onap.aaisimulator.utils.TestRestTemplateService; -import org.onap.aaisimulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public class ProjectControllerTest extends AbstractSpringBootTest { - - private static final String PROJECT_NAME_VALUE = "PROJECT_NAME_VALUE"; - - @LocalServerPort - private int port; - - @Autowired - private TestRestTemplateService testRestTemplateService; - - @Autowired - private ProjectCacheServiceProvider cacheServiceProvider; - - @Autowired - private CustomerCacheServiceProvider customerCacheServiceProvider; - - @After - public void after() { - cacheServiceProvider.clearAll(); - customerCacheServiceProvider.clearAll(); - } - - @Test - public void test_putProject_successfullyAddedToCache() throws Exception { - final String url = getUrl(TestConstants.PROJECT_URL, PROJECT_NAME_VALUE); - final ResponseEntity actual = - testRestTemplateService.invokeHttpPut(url, TestUtils.getBusinessProject(), Void.class); - - assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - - final ResponseEntity actualResponse = testRestTemplateService.invokeHttpGet(url, Project.class); - - assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); - assertTrue(actualResponse.hasBody()); - final Project actualProject = actualResponse.getBody(); - assertEquals(PROJECT_NAME_VALUE, actualProject.getProjectName()); - assertNotNull(actualProject.getResourceVersion()); - - } - - @Test - public void test_putProjectRelationShip_successfullyAddedToCache() throws Exception { - addCustomerAndServiceInstance(); - - final String url = getUrl(TestConstants.PROJECT_URL, PROJECT_NAME_VALUE); - final ResponseEntity actual = - testRestTemplateService.invokeHttpPut(url, TestUtils.getBusinessProject(), Void.class); - assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - - final String projectRelationshipUrl = - getUrl(TestConstants.PROJECT_URL, PROJECT_NAME_VALUE, RELATIONSHIP_LIST_RELATIONSHIP_URL); - - final ResponseEntity putResponse = testRestTemplateService.invokeHttpPut(projectRelationshipUrl, - TestUtils.getBusinessProjectRelationship(), Void.class); - - assertEquals(HttpStatus.ACCEPTED, putResponse.getStatusCode()); - - final ResponseEntity actualResponse = testRestTemplateService.invokeHttpGet(url, Project.class); - - assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); - assertTrue(actualResponse.hasBody()); - final Project actualProject = actualResponse.getBody(); - assertEquals(PROJECT_NAME_VALUE, actualProject.getProjectName()); - assertNotNull(actualProject.getRelationshipList()); - assertFalse(actualProject.getRelationshipList().getRelationship().isEmpty()); - assertNotNull(actualProject.getRelationshipList().getRelationship().get(0)); - - final Relationship actualRelationship = actualProject.getRelationshipList().getRelationship().get(0); - final List relationshipDataList = actualRelationship.getRelationshipData(); - assertEquals(Constants.USES, actualRelationship.getRelationshipLabel()); - - assertFalse(relationshipDataList.isEmpty()); - assertEquals(3, relationshipDataList.size()); - - final RelationshipData globalRelationshipData = - getRelationshipData(relationshipDataList, Constants.CUSTOMER_GLOBAL_CUSTOMER_ID); - assertNotNull(globalRelationshipData); - assertEquals(GLOBAL_CUSTOMER_ID, globalRelationshipData.getRelationshipValue()); - - final RelationshipData serviceSubscriptionRelationshipData = - getRelationshipData(relationshipDataList, Constants.SERVICE_SUBSCRIPTION_SERVICE_TYPE); - assertNotNull(serviceSubscriptionRelationshipData); - assertEquals(SERVICE_TYPE, serviceSubscriptionRelationshipData.getRelationshipValue()); - - final RelationshipData serviceInstanceRelationshipData = - getRelationshipData(relationshipDataList, Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_ID); - assertNotNull(serviceInstanceRelationshipData); - assertEquals(SERVICE_INSTANCE_ID, serviceInstanceRelationshipData.getRelationshipValue()); - - final Optional optional = - customerCacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID); - assertTrue(optional.isPresent()); - - final ServiceInstance serviceInstance = optional.get(); - - assertNotNull(serviceInstance.getRelationshipList()); - final List serviceRelationshipList = serviceInstance.getRelationshipList().getRelationship(); - assertFalse(serviceRelationshipList.isEmpty()); - assertEquals(1, serviceRelationshipList.size()); - final Relationship relationship = serviceRelationshipList.get(0); - assertEquals(Constants.USES, relationship.getRelationshipLabel()); - assertEquals(TestConstants.PROJECT_URL + PROJECT_NAME_VALUE, relationship.getRelatedLink()); - - - final List serviceRelationshipDataList = serviceRelationshipList.get(0).getRelationshipData(); - assertFalse(serviceRelationshipDataList.isEmpty()); - assertEquals(1, serviceRelationshipDataList.size()); - - final RelationshipData projectRelationshipData = - getRelationshipData(serviceRelationshipDataList, Constants.PROJECT_PROJECT_NAME); - assertNotNull(projectRelationshipData); - assertEquals(PROJECT_NAME_VALUE, projectRelationshipData.getRelationshipValue()); - - } - - @Test - public void test_getProjectCount_correctResult() throws Exception { - final String url = getUrl(TestConstants.PROJECT_URL, PROJECT_NAME_VALUE); - final ResponseEntity actual = - testRestTemplateService.invokeHttpPut(url, TestUtils.getBusinessProject(), Void.class); - - assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - - final ResponseEntity actualResponse = - testRestTemplateService.invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=count", Results.class); - - assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); - assertTrue(actualResponse.hasBody()); - final Results result = actualResponse.getBody(); - assertNotNull(result.getValues()); - assertFalse(result.getValues().isEmpty()); - assertEquals(1, result.getValues().get(0).get(Constants.PROJECT)); - } - - - private void addCustomerAndServiceInstance() throws Exception, IOException { - final ResponseEntity customerResponse = - testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class); - assertEquals(HttpStatus.ACCEPTED, customerResponse.getStatusCode()); - - final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); - final ResponseEntity serviceInstanceResponse = - testRestTemplateService.invokeHttpPut(serviceInstanceUrl, TestUtils.getServiceInstance(), Void.class); - assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode()); - - } - -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java deleted file mode 100644 index d0e652bd..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.controller; - -import org.junit.Test; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.aaisimulator.utils.TestConstants.SERVICE_DESIGN_AND_CREATION_URL; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, - properties = "SERVICE_DESIGN_AND_CREATION_RESPONSES_LOCATION=./src/test/resources/test-data/service-design-and-creation-responses") -public class ServiceDesignAndCreationControllerTest extends AbstractSpringBootTest{ - - @Test - public void should_reply_sample_modelvers_response() { - final String url = getUrl(SERVICE_DESIGN_AND_CREATION_URL, - "/models/model/a51e2bef-961c-496f-b235-b4540400e885/model-vers"); - ResponseEntity actual = testRestTemplateService.invokeHttpGet(url, String.class); - String expectedXml = "\n" + - "\n" + - " \n" + - " c0818142-324d-4a8c-8065-45a61df247a5\n" + - " EricService\n" + - " 1.0\n" + - " blah\n" + - " 1594657102313\n" + - " \n" + - " \n" + - " 4442dfc1-0d2d-46b4-b0bc-a2ac10448269\n" + - " EricService\n" + - " 2.0\n" + - " blahhhh\n" + - " 1594707742646\n" + - " \n" + - ""; - - assertEquals(HttpStatus.OK, actual.getStatusCode()); - MediaType contentType = actual.getHeaders().getContentType(); - assertNotNull(contentType); - assertTrue(contentType.isCompatibleWith(MediaType.APPLICATION_XML)); - assertEquals(expectedXml, actual.getBody()); - } -} \ No newline at end of file diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java deleted file mode 100755 index 2e50d3d7..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.controller.configuration; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLSession; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.TrustStrategy; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.ssl.SSLContexts; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.springframework.web.client.RestTemplate; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@Profile("test") -@Configuration -public class TestRestTemplateConfigration { - - private static final Logger LOGGER = LoggerFactory.getLogger(TestRestTemplateConfigration.class); - - @Bean - public TestRestTemplate testRestTemplate() throws Exception { - final TestRestTemplate testRestTemplate = new TestRestTemplate(); - ((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRestTemplate().getRequestFactory()) - .setHttpClient(httpClient()); - return testRestTemplate; - - } - - @Bean - public RestTemplate restTemplate() throws Exception { - final RestTemplate restTemplate = new RestTemplate(); - restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient())); - return restTemplate; - } - - private CloseableHttpClient httpClient() throws Exception { - final TrustStrategy acceptingTrustStrategy = (cert, authType) -> true; - - final SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory( - SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build(), new HostnameVerifier() { - @Override - public boolean verify(final String hostname, final SSLSession session) { - LOGGER.warn("Skiping hostname verification ... "); - return true; - } - - }); - - return HttpClients.custom().setSSLSocketFactory(csf).build(); - } - -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java deleted file mode 100755 index 942e8701..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java +++ /dev/null @@ -1,120 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.utils; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public class TestConstants { - - public static final String BASE_URL_V17 = "/aai/v17"; - - public static final String SERVICE_INSTANCES_URL = "/service-instances"; - - public static final String SERVICE_NAME = "ServiceTest"; - - public static final String SERVICE_INSTANCE_ID = "ccece8fe-13da-456a-baf6-41b3a4a2bc2b"; - - public static final String SERVICE_INSTANCE_URL = - SERVICE_INSTANCES_URL + "/service-instance/" + SERVICE_INSTANCE_ID; - - public static final String SERVICE_TYPE = "vCPE"; - - public static final String SERVICE_SUBSCRIPTIONS_URL = - "/service-subscriptions/service-subscription/" + SERVICE_TYPE; - - public static final String GLOBAL_CUSTOMER_ID = "DemoCustomer"; - - public static final String CUSTOMERS_URL = BASE_URL_V17 + "/business/customers/customer/" + GLOBAL_CUSTOMER_ID; - - public static final String VNF_ID = "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701"; - - public static final String GENERIC_VNF_NAME = "EsyVnfInstantiationTest2"; - - public static final String GENERIC_VNF_URL = BASE_URL_V17 + "/network/generic-vnfs/generic-vnf/"; - - public static final String GENERIC_VNFS_URL = "/generic-vnfs"; - - public static final String RELATED_TO_URL = "/related-to" + GENERIC_VNFS_URL; - - public static final String PLATFORM_NAME = "PLATFORM_APP_ID_1"; - - public static final String LINE_OF_BUSINESS_NAME = "LINE_OF_BUSINESS_1"; - - public static final String CLOUD_OWNER_NAME = "CloudOwner"; - - public static final String CLOUD_REGION_NAME = "PnfSwUCloudRegion"; - - public static final String TENANT_ID = "693c7729b2364a26a3ca602e6f66187d"; - - public static final String TENANTS_TENANT = "/tenants/tenant/"; - - public static final String ESR_VNFM_URL = BASE_URL_V17 + "/external-system/esr-vnfm-list/esr-vnfm/"; - - public static final String EXTERNAL_SYSTEM_ESR_VNFM_LIST_URL = BASE_URL_V17 + "/external-system/esr-vnfm-list"; - - public static final String ESR_VNFM_ID = "c5e99cee-1996-4606-b697-838d51d4e1a3"; - - public static final String ESR_VIM_ID = "PnfSwUVimId"; - - public static final String ESR_SYSTEM_INFO_LIST_URL = "/esr-system-info-list"; - - public static final String ESR_SYSTEM_INFO_ID = "5c067098-f2e3-40f7-a7ba-155e7c61e916"; - - public static final String ESR_SYSTEM_TYPE = "VNFM"; - - public static final String ESR_PASSWORD = "123456"; - - public static final String ESR_USERNAME = "vnfmadapter"; - - public static final String ESR_SERVICE_URL = "https://so-vnfm-simulator.onap:9095/vnflcm/v1"; - - public static final String ESR_VENDOR = "EST"; - - public static final String ESR_TYEP = "simulator"; - - public static final String SYSTEM_NAME = "vnfmSimulator"; - - public static final String VSERVER_URL = "/vservers/vserver/"; - - public static final String VSERVER_NAME = "CsitVServer"; - - public static final String VSERVER_ID = "f84fdb9b-ad7c-49db-a08f-e443b4cbd033"; - - public static final String OWNING_ENTITY_URL = BASE_URL_V17 + "/business/owning-entities/owning-entity/"; - - public static final String LINES_OF_BUSINESS_URL = BASE_URL_V17 + "/business/lines-of-business/line-of-business/"; - - public static final String PLATFORMS_URL = BASE_URL_V17 + "/business/platforms/platform/"; - - public static final String CLOUD_REGIONS = BASE_URL_V17 + "/cloud-infrastructure/cloud-regions/cloud-region/"; - - public static final String GENERIC_VNFS_URL_1 = BASE_URL_V17 + "/network/generic-vnfs"; - - public static final String NODES_URL = BASE_URL_V17 + "/nodes"; - - public static final String PROJECT_URL = BASE_URL_V17 + "/business/projects/project/"; - - public static final String SERVICE_DESIGN_AND_CREATION_URL = BASE_URL_V17 + "/service-design-and-creation"; - - private TestConstants() {} - -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestRestTemplateService.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestRestTemplateService.java deleted file mode 100755 index 2e068bce..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestRestTemplateService.java +++ /dev/null @@ -1,79 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.utils; - -import org.onap.aaisimulator.model.UserCredentials; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ - -@Service -public class TestRestTemplateService { - - @Autowired - private TestRestTemplate restTemplate; - - @Autowired - private UserCredentials userCredentials; - - - public ResponseEntity invokeHttpGet(final String url, final Class clazz) { - return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), clazz); - } - - public ResponseEntity invokeHttpPut(final String url, final Object obj, final Class clazz) { - final HttpEntity httpEntity = getHttpEntity(obj); - return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, clazz); - } - - public ResponseEntity invokeHttpDelete(final String url, final Class clazz) { - final HttpEntity request = new HttpEntity<>(getHttpHeaders()); - return restTemplate.exchange(url, HttpMethod.DELETE, request, clazz); - } - - public ResponseEntity invokeHttpPost(final String url, final Object obj, final Class clazz) { - final HttpEntity httpEntity = getHttpEntity(obj); - return restTemplate.exchange(url, HttpMethod.POST, httpEntity, clazz); - } - - public ResponseEntity invokeHttpPost(final HttpHeaders headers, final String url, final Object obj, - final Class clazz) { - final HttpEntity entity = new HttpEntity<>(obj, headers); - return restTemplate.exchange(url, HttpMethod.POST, entity, clazz); - } - - private HttpEntity getHttpEntity(final Object obj) { - return new HttpEntity<>(obj, getHttpHeaders()); - } - - public HttpHeaders getHttpHeaders() { - return TestUtils.getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); - } - -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java deleted file mode 100755 index e8dc9df2..00000000 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java +++ /dev/null @@ -1,186 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.aaisimulator.utils; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.Base64; -import org.springframework.core.io.ClassPathResource; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.web.util.UriComponentsBuilder; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public class TestUtils { - - private static final String PASSWORD = "aai.onap.org:demo123456!"; - - public static HttpHeaders getHttpHeaders(final String username) { - final HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.add("Authorization", getBasicAuth(username)); - requestHeaders.setContentType(MediaType.APPLICATION_JSON); - return requestHeaders; - } - - public static File getFile(final String file) throws IOException { - return new ClassPathResource(file).getFile(); - } - - public static String getJsonString(final String file) throws IOException { - return new String(Files.readAllBytes(getFile(file).toPath())); - } - - public static T getObjectFromFile(final File file, final Class clazz) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule(new JaxbAnnotationModule()); - - return mapper.readValue(file, clazz); - } - - public static String getBasicAuth(final String username) { - return "Basic " + new String(Base64.getEncoder().encodeToString((username + ":" + PASSWORD).getBytes())); - } - - public static String getBaseUrl(final int port) { - return "https://localhost:" + port; - } - - public static String getCustomer() throws Exception, IOException { - return getJsonString("test-data/business-customer.json"); - } - - public static String getServiceSubscription() throws IOException { - return getJsonString("test-data/service-subscription.json"); - } - - public static String getServiceInstance() throws IOException { - return getJsonString("test-data/service-instance.json"); - } - - public static String getGenericVnf() throws IOException { - return getJsonString("test-data/generic-vnf.json"); - } - - public static String getPnf() throws IOException { - return getJsonString("test-data/pnf.json"); - } - - public static String getRelationShip() throws IOException { - return getJsonString("test-data/relation-ship.json"); - } - - public static String getPlatformRelatedLink() throws IOException { - return getJsonString("test-data/platform-related-link.json"); - } - - public static String getLineOfBusinessRelatedLink() throws IOException { - return getJsonString("test-data/line-of-business-related-link.json"); - } - - public static String getPlatform() throws IOException { - return getJsonString("test-data/platform.json"); - } - - public static String getGenericVnfRelationShip() throws IOException { - return getJsonString("test-data/generic-vnf-relationship.json"); - } - - public static String getLineOfBusiness() throws IOException { - return getJsonString("test-data/line-of-business.json"); - } - - public static String getBusinessProject() throws IOException { - return getJsonString("test-data/business-project.json"); - } - - public static String getBusinessProjectRelationship() throws IOException { - return getJsonString("test-data/business-project-relation-ship.json"); - } - - public static String getOwningEntityRelationship() throws IOException { - return getJsonString("test-data/owning-entity-relation-ship.json"); - } - - public static String getOwningEntity() throws IOException { - return getJsonString("test-data/owning-entity.json"); - } - - public static String getOrchStatuUpdateServiceInstance() throws IOException { - return getJsonString("test-data/service-instance-orch-status-update.json"); - } - - public static String getRelationShipJsonObject() throws IOException { - return getJsonString("test-data/service-Instance-relationShip.json"); - } - - public static String getCloudRegion() throws IOException { - return getJsonString("test-data/cloud-region.json"); - } - - public static String getTenant() throws IOException { - return getJsonString("test-data/tenant.json"); - } - - public static String getCloudRegionRelatedLink() throws IOException { - return getJsonString("test-data/cloud-region-related-link.json"); - } - - public static String getGenericVnfRelatedLink() throws IOException { - return getJsonString("test-data/generic-vnf-related-link.json"); - } - - public static String getTenantRelationShip() throws IOException { - return getJsonString("test-data/tenant-relationship.json"); - } - - public static String getGenericVnfOrchStatuUpdate() throws IOException { - return getJsonString("test-data/generic-vnf-orch-status-update.json"); - } - - public static String getEsrVnfm() throws IOException { - return getJsonString("test-data/esr-vnfm.json"); - } - - public static String getEsrSystemInfo() throws IOException { - return getJsonString("test-data/esr-system-info.json"); - } - - public static String getVserver() throws IOException { - return getJsonString("test-data/vServer.json"); - } - - - public static String getUrl(final int port, final String... urls) { - final UriComponentsBuilder baseUri = UriComponentsBuilder.fromUriString("https://localhost:" + port); - for (final String url : urls) { - baseUri.path(url); - } - return baseUri.toUriString(); - } - - private TestUtils() {} - -} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/resources/test-data/service-instance-aai.json b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/resources/test-data/service-instance-aai.json new file mode 100644 index 00000000..8ea4263b --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/resources/test-data/service-instance-aai.json @@ -0,0 +1,45 @@ +{ + "service-instance-id": "5df8b6de-2083-11e7-93ae-92361f002676", + "service-instance-name": "Service_Ete_Name123452c4-3d7f-42ce-8188-818fab951269", + "environment-context": "General_Revenue-Bearing", + "workload-context": "Production", + "model-version-id": "d88da85c-d9e8-4f73-b837-3a72a431622b", + "modelInvariantId": "fe41489e-1563-46a3-b90a-1db629e4375b", + "resource-version": "1595258335377", + "selflink": "restconf/config/GENERIC-RESOURCE-API:services/service/5df8b6de-2083-11e7-93ae-92361f002676/service-data/service-topology/", + "orchestration-status": "Assigned", + "relationship-list": { + "relationship": [ + { + "related-to": "owning-entity", + "related-link": "/aai/v11/business/owning-entities/owning-entity/67f2e84c-734d-4e90-a1e4-d2ffa2e75849", + "relationship-data": [ + { + "relationship-key": "owning-entity.owning-entity-id", + "relationship-value": "67f2e84c-734d-4e90-a1e4-d2ffa2e75849" + } + ] + }, + { + "related-to": "pnf", + "related-link": "/aai/v11/network/pnfs/pnf/PNFDemo", + "relationship-data": [ + { + "relationship-key": "pnf.pnf-name", + "relationship-value": "PNFDemo" + } + ] + }, + { + "related-to": "pnf", + "related-link": "/aai/v11/network/pnfs/pnf/PNFDemo1", + "relationship-data": [ + { + "relationship-key": "pnf.pnf-name", + "relationship-value": "PNFDemo1" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/teardown.sh b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/teardown.sh index a9d9bdd5..7257b366 100755 --- a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/teardown.sh +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/teardown.sh @@ -1,10 +1,10 @@ #!/bin/bash -source $SO_DOCKER_PATH/so_teardown.sh +echo 'Stop, Removing all running containers...' +docker stop $(docker ps -aq) && docker rm $(docker ps -aq) -source $SDNC_DOCKER_PATH/sdn_teardown.sh +echo 'Removing Volumes...' +echo y | docker volume prune -source $CDS_DOCKER_PATH/cds_teardown.sh - -PNFSIM_DOCKER_COMPOSE_PATH=$PNF_SIM_DOCKER_PATH/docker-compose.yml -docker-compose -f $PNFSIM_DOCKER_COMPOSE_PATH -p $PROJECT_NAME down +echo 'Removing Networks...' +echo y | docker network prune \ No newline at end of file -- cgit 1.2.3-korg