From 24805416f0502a1e06bf57fd15c27d56150f3b30 Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Thu, 1 Aug 2019 16:19:31 +0000 Subject: Adding infrastructure for sdnc simulator - Changing package names as csit jenkins jobs are trigger based on component names defined in file path Change-Id: Ib8b75ce11185c37bed0d8f4e3918b6660cf24ec8 Issue-ID: SO-1950 Signed-off-by: waqas.ikram --- .../so/integration-etsi-testing/docker-compose.yml | 19 + .../so-simulators/aai-simulator/pom.xml | 2 +- .../so/aai/simulator/AaiSimulatorApplication.java | 38 -- .../configration/ApplicationConfigration.java | 61 ---- .../configration/WebSecurityConfigImpl.java | 71 ---- .../controller/AaiSimulatorController.java | 51 --- .../simulator/controller/BusinessController.java | 248 ------------- .../aai/simulator/controller/NodesController.java | 110 ------ .../controller/OwningEntityController.java | 127 ------- .../simulator/controller/ProjectController.java | 125 ------- .../org/onap/so/aai/simulator/models/Format.java | 49 --- .../aai/simulator/models/NodeServiceInstance.java | 139 ------- .../org/onap/so/aai/simulator/models/Result.java | 64 ---- .../providers/AbstractCacheServiceProvider.java | 55 --- .../providers/CustomerCacheServiceProvider.java | 57 --- .../CustomerCacheServiceProviderImpl.java | 232 ------------ .../providers/NodesCacheServiceProvider.java | 37 -- .../providers/NodesCacheServiceProviderImpl.java | 73 ---- .../providers/OwnEntityCacheServiceProvider.java | 39 -- .../OwnEntityCacheServiceProviderImpl.java | 98 ----- .../providers/ProjectCacheServiceProvider.java | 39 -- .../providers/ProjectCacheServiceProviderImpl.java | 101 ------ .../org/onap/so/aai/simulator/utils/Constants.java | 68 ---- .../onap/so/aai/simulator/utils/RequestError.java | 59 --- .../aai/simulator/utils/RequestErrorBuilder.java | 59 --- .../so/aai/simulator/utils/ServiceException.java | 88 ----- .../org/onap/so/aai/simulator/utils/Utils.java | 58 --- .../so/aaisimulator/AaiSimulatorApplication.java | 38 ++ .../configration/ApplicationConfigration.java | 61 ++++ .../configration/WebSecurityConfigImpl.java | 71 ++++ .../controller/AaiSimulatorController.java | 51 +++ .../controller/BusinessController.java | 248 +++++++++++++ .../aaisimulator/controller/NodesController.java | 110 ++++++ .../controller/OwningEntityController.java | 127 +++++++ .../aaisimulator/controller/ProjectController.java | 125 +++++++ .../org/onap/so/aaisimulator/models/Format.java | 49 +++ .../aaisimulator/models/NodeServiceInstance.java | 139 +++++++ .../org/onap/so/aaisimulator/models/Result.java | 64 ++++ .../providers/AbstractCacheServiceProvider.java | 55 +++ .../providers/CustomerCacheServiceProvider.java | 57 +++ .../CustomerCacheServiceProviderImpl.java | 232 ++++++++++++ .../providers/NodesCacheServiceProvider.java | 37 ++ .../providers/NodesCacheServiceProviderImpl.java | 73 ++++ .../providers/OwnEntityCacheServiceProvider.java | 39 ++ .../OwnEntityCacheServiceProviderImpl.java | 98 +++++ .../providers/ProjectCacheServiceProvider.java | 39 ++ .../providers/ProjectCacheServiceProviderImpl.java | 101 ++++++ .../org/onap/so/aaisimulator/utils/Constants.java | 68 ++++ .../onap/so/aaisimulator/utils/RequestError.java | 59 +++ .../so/aaisimulator/utils/RequestErrorBuilder.java | 59 +++ .../so/aaisimulator/utils/ServiceException.java | 88 +++++ .../java/org/onap/so/aaisimulator/utils/Utils.java | 58 +++ .../controller/AaiSimulatorControllerTest.java | 64 ---- .../controller/BusinessControllerTest.java | 398 --------------------- .../simulator/controller/NodesControllerTest.java | 180 ---------- .../controller/OwningEntityControllerTest.java | 172 --------- .../controller/ProjectControllerTest.java | 169 --------- .../TestRestTemplateConfigration.java | 71 ---- .../onap/so/aai/simulator/utils/TestConstants.java | 50 --- .../org/onap/so/aai/simulator/utils/TestUtils.java | 73 ---- .../controller/AaiSimulatorControllerTest.java | 64 ++++ .../controller/BusinessControllerTest.java | 398 +++++++++++++++++++++ .../controller/NodesControllerTest.java | 180 ++++++++++ .../controller/OwningEntityControllerTest.java | 172 +++++++++ .../controller/ProjectControllerTest.java | 169 +++++++++ .../TestRestTemplateConfigration.java | 71 ++++ .../onap/so/aaisimulator/utils/TestConstants.java | 52 +++ .../org/onap/so/aaisimulator/utils/TestUtils.java | 73 ++++ .../so-simulators/package/docker/pom.xml | 32 +- .../integration-etsi-testing/so-simulators/pom.xml | 1 + .../so-simulators/sdc-simulator/pom.xml | 2 +- .../so/sdc/simulator/SdcSimulatorApplication.java | 36 -- .../configration/WebSecurityConfigImpl.java | 71 ---- .../simulator/controller/CatalogController.java | 64 ---- .../controller/SdcSimulatorController.java | 48 --- .../sdc/simulator/providers/ResourceProvider.java | 36 -- .../simulator/providers/ResourceProviderImpl.java | 88 ----- .../org/onap/so/sdc/simulator/utils/Constants.java | 41 --- .../so/sdcsimulator/SdcSimulatorApplication.java | 36 ++ .../configration/WebSecurityConfigImpl.java | 71 ++++ .../sdcsimulator/controller/CatalogController.java | 64 ++++ .../controller/SdcSimulatorController.java | 48 +++ .../sdcsimulator/providers/ResourceProvider.java | 36 ++ .../providers/ResourceProviderImpl.java | 88 +++++ .../org/onap/so/sdcsimulator/utils/Constants.java | 45 +++ .../controller/CatalogControllerTest.java | 110 ------ .../controller/SdcSimulatorControllerTest.java | 61 ---- .../providers/ResourceProviderImplTest.java | 98 ----- .../controller/CatalogControllerTest.java | 111 ++++++ .../controller/SdcSimulatorControllerTest.java | 61 ++++ .../providers/ResourceProviderImplTest.java | 99 +++++ .../so-simulators/sdnc-simulator/pom.xml | 33 ++ .../so/sdncsimulator/SdncSimulatorApplication.java | 36 ++ .../controller/SdncSimulatorController.java | 47 +++ .../org/onap/so/sdncsimulator/utils/Constants.java | 32 ++ .../src/main/resources/application.yaml | 5 + .../controller/SdncSimulatorControllerTest.java | 60 ++++ 97 files changed, 4249 insertions(+), 3980 deletions(-) delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/AaiSimulatorApplication.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/ApplicationConfigration.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/WebSecurityConfigImpl.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/AaiSimulatorController.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/BusinessController.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/NodesController.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/OwningEntityController.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/ProjectController.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/Format.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/NodeServiceInstance.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/Result.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/AbstractCacheServiceProvider.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProvider.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProviderImpl.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProvider.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProviderImpl.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProvider.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProviderImpl.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProvider.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProviderImpl.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Constants.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/RequestError.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/RequestErrorBuilder.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/ServiceException.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Utils.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/AaiSimulatorApplication.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/ApplicationConfigration.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/WebSecurityConfigImpl.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/AaiSimulatorController.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/NodesController.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/OwningEntityController.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/ProjectController.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/Format.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/NodeServiceInstance.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/Result.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/AbstractCacheServiceProvider.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProvider.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProvider.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProvider.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/RequestError.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/RequestErrorBuilder.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/ServiceException.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Utils.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/AaiSimulatorControllerTest.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/BusinessControllerTest.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/NodesControllerTest.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/OwningEntityControllerTest.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/ProjectControllerTest.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/configuration/TestRestTemplateConfigration.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestConstants.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestUtils.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AaiSimulatorControllerTest.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/SdcSimulatorApplication.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/configration/WebSecurityConfigImpl.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/controller/CatalogController.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/controller/SdcSimulatorController.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/providers/ResourceProvider.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/providers/ResourceProviderImpl.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/utils/Constants.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/SdcSimulatorApplication.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/configration/WebSecurityConfigImpl.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/CatalogController.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/SdcSimulatorController.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/ResourceProvider.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/ResourceProviderImpl.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/utils/Constants.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdc/simulator/controller/CatalogControllerTest.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdc/simulator/controller/SdcSimulatorControllerTest.java delete mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdc/simulator/providers/ResourceProviderImplTest.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/SdcSimulatorControllerTest.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/providers/ResourceProviderImplTest.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/pom.xml create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/SdncSimulatorApplication.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/SdncSimulatorController.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/Constants.java create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/resources/application.yaml create mode 100644 plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/SdncSimulatorControllerTest.java (limited to 'plans/so') diff --git a/plans/so/integration-etsi-testing/docker-compose.yml b/plans/so/integration-etsi-testing/docker-compose.yml index 068349f8..22fc221a 100644 --- a/plans/so/integration-etsi-testing/docker-compose.yml +++ b/plans/so/integration-etsi-testing/docker-compose.yml @@ -343,3 +343,22 @@ services: command: - "/config/apply-workarounds.sh" ################################################################################# + sdnc-simulator: + image: simulators/sdnc-simulator:latest + ports: + - "9994:9994" + environment: + - APP=SDNC-SIMULATOR + - JVM_ARGS=-Xms64m -Xmx512m + hostname: + sdnc-simulator + depends_on: + - mariadb + - vnfm-adapter + logging: + driver: "json-file" + options: + max-size: "30m" + max-file: "5" +################################################################################ + diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml index 3dd82228..3c3ed718 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml @@ -45,7 +45,7 @@ org.springframework.boot spring-boot-maven-plugin - org.onap.so.aai.simulator.AaiSimulatorApplication + org.onap.so.aaisimulator.AaiSimulatorApplication diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/AaiSimulatorApplication.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/AaiSimulatorApplication.java deleted file mode 100644 index 26f52e32..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/AaiSimulatorApplication.java +++ /dev/null @@ -1,38 +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.so.aai.simulator; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.cache.annotation.EnableCaching; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@EnableCaching -@SpringBootApplication(scanBasePackages = {"org.onap"}) -public class AaiSimulatorApplication extends SpringBootServletInitializer { - - public static void main(final String[] args) { - SpringApplication.run(AaiSimulatorApplication.class, args); - } -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/ApplicationConfigration.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/ApplicationConfigration.java deleted file mode 100644 index b1f17796..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/ApplicationConfigration.java +++ /dev/null @@ -1,61 +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.so.aai.simulator.configration; - -import static org.onap.so.aai.simulator.utils.Constants.CUSTOMER_CACHE; -import static org.onap.so.aai.simulator.utils.Constants.NODES_CACHE; -import static org.onap.so.aai.simulator.utils.Constants.OWNING_ENTITY_CACHE; -import static org.onap.so.aai.simulator.utils.Constants.PROJECT_CACHE; -import java.util.Arrays; -import java.util.List; -import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; -import org.springframework.cache.concurrent.ConcurrentMapCache; -import org.springframework.cache.support.SimpleCacheManager; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@Configuration -public class ApplicationConfigration { - - @Bean - public Jackson2ObjectMapperBuilderCustomizer jacksonCustomizer() { - return (mapperBuilder) -> mapperBuilder.modulesToInstall(new JaxbAnnotationModule()); - } - - @Bean - public CacheManager cacheManager() { - final SimpleCacheManager manager = new SimpleCacheManager(); - final List caches = Arrays.asList(getCache(CUSTOMER_CACHE), getCache(PROJECT_CACHE), - getCache(NODES_CACHE), getCache(OWNING_ENTITY_CACHE)); - manager.setCaches(caches); - return manager; - } - - private Cache getCache(final String name) { - return new ConcurrentMapCache(name); - } -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/WebSecurityConfigImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/WebSecurityConfigImpl.java deleted file mode 100644 index a4a1fb11..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/WebSecurityConfigImpl.java +++ /dev/null @@ -1,71 +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.so.aai.simulator.configration; - -import org.onap.so.aai.simulator.utils.Constants; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@Configuration -@EnableWebSecurity -public class WebSecurityConfigImpl extends WebSecurityConfigurerAdapter { - - private final String username; - private final String password; - private final String role; - - public WebSecurityConfigImpl(@Value("${spring.security.username}") final String username, - @Value("${spring.security.password}") final String password, - @Value("${spring.security.role}") final String role) { - this.username = username; - this.password = password; - this.role = role; - } - - - @Override - protected void configure(final HttpSecurity http) throws Exception { - http.csrf().disable().authorizeRequests().antMatchers(Constants.BUSINESS_URL + "/**/**").authenticated().and() - .httpBasic(); - } - - @Bean - public BCryptPasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); - } - - @Autowired - public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()).withUser(username).password(password) - .roles(role); - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/AaiSimulatorController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/AaiSimulatorController.java deleted file mode 100644 index af0a0150..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/AaiSimulatorController.java +++ /dev/null @@ -1,51 +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.so.aai.simulator.controller; - -import static org.onap.so.aai.simulator.utils.Constants.HEALTHY; -import javax.ws.rs.core.MediaType; -import org.onap.so.aai.simulator.utils.Constants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.ResponseStatus; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@Controller -@RequestMapping(path = Constants.BASE_URL) -public class AaiSimulatorController { - private static final Logger LOGGER = LoggerFactory.getLogger(AaiSimulatorController.class); - - @ResponseBody - @GetMapping(value = "/healthcheck", produces = MediaType.TEXT_PLAIN) - @ResponseStatus(code = HttpStatus.OK) - public String healthCheck() { - LOGGER.info("Running health check ..."); - return HEALTHY; - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/BusinessController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/BusinessController.java deleted file mode 100644 index 0189a427..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/BusinessController.java +++ /dev/null @@ -1,248 +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.so.aai.simulator.controller; - -import static org.onap.so.aai.simulator.utils.Constants.CUSTOMER_URL; -import static org.onap.so.aai.simulator.utils.Constants.SERVICE_RESOURCE_TYPE; -import static org.onap.so.aai.simulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; -import static org.onap.so.aai.simulator.utils.Utils.getRequestErrorResponseEntity; -import static org.onap.so.aai.simulator.utils.Utils.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.ServiceInstance; -import org.onap.aai.domain.yang.ServiceInstances; -import org.onap.aai.domain.yang.ServiceSubscription; -import org.onap.so.aai.simulator.models.NodeServiceInstance; -import org.onap.so.aai.simulator.service.providers.CustomerCacheServiceProvider; -import org.onap.so.aai.simulator.service.providers.NodesCacheServiceProvider; -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.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -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 String SERVICE_SUBSCRIPTION = "service-subscription"; - private static final String CUSTOMER_TYPE = "Customer"; - private static final Logger LOGGER = LoggerFactory.getLogger(BusinessController.class); - private final CustomerCacheServiceProvider cacheServiceProvider; - private final NodesCacheServiceProvider nodesCacheServiceProvider; - - @Autowired - public BusinessController(final CustomerCacheServiceProvider cacheServiceProvider, - final NodesCacheServiceProvider nodesCacheServiceProvider) { - this.cacheServiceProvider = cacheServiceProvider; - this.nodesCacheServiceProvider = nodesCacheServiceProvider; - } - - @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(); - - } - - @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}", - 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); - - if (cacheServiceProvider.putServiceSubscription(globalCustomerId, serviceType, serviceSubscription)) { - LOGGER.info("Successfully add service subscription in 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); - } - - @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) { - - LOGGER.info( - "Will add service instance for 'global customer id': {}, 'service type': {} and 'service instance id: '{} ...", - globalCustomerId, serviceType, serviceInstanceId); - - if (serviceInstance.getResourceVersion() == null || serviceInstance.getResourceVersion().isEmpty()) { - serviceInstance.setResourceVersion(getResourceVersion()); - } - - if (cacheServiceProvider.putServiceInstance(globalCustomerId, serviceType, serviceInstanceId, - serviceInstance)) { - nodesCacheServiceProvider.putNodeServiceInstance(serviceInstanceId, new NodeServiceInstance( - globalCustomerId, serviceType, serviceInstanceId, SERVICE_RESOURCE_TYPE, request.getRequestURI())); - return ResponseEntity.accepted().build(); - } - - LOGGER.error("Couldn't add 'global customer id': {}, 'service type': {} and 'service instance id': {} to cache", - globalCustomerId, serviceType, serviceInstanceId); - 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) { - - LOGGER.info( - "Will 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); - return ResponseEntity.accepted().build(); - } - LOGGER.error("{} not supported ... ", xHttpHeaderOverride); - - return getRequestErrorResponseEntity(request); - } - - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/NodesController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/NodesController.java deleted file mode 100644 index 4fa4d408..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/NodesController.java +++ /dev/null @@ -1,110 +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.so.aai.simulator.controller; - -import static org.onap.so.aai.simulator.utils.Constants.NODES_URL; -import static org.onap.so.aai.simulator.utils.Constants.RESOURCE_LINK; -import static org.onap.so.aai.simulator.utils.Constants.RESOURCE_TYPE; -import static org.onap.so.aai.simulator.utils.Utils.getRequestErrorResponseEntity; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.core.MediaType; -import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.so.aai.simulator.models.Format; -import org.onap.so.aai.simulator.models.NodeServiceInstance; -import org.onap.so.aai.simulator.models.Result; -import org.onap.so.aai.simulator.service.providers.CustomerCacheServiceProvider; -import org.onap.so.aai.simulator.service.providers.NodesCacheServiceProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@Controller -@RequestMapping(path = NODES_URL) -public class NodesController { - - - private static final Logger LOGGER = LoggerFactory.getLogger(NodesController.class); - - private final NodesCacheServiceProvider cacheServiceProvider; - - private final CustomerCacheServiceProvider customerCacheServiceProvider; - - @Autowired - public NodesController(final CustomerCacheServiceProvider customerCacheServiceProvider, - final NodesCacheServiceProvider cacheServiceProvider) { - this.customerCacheServiceProvider = customerCacheServiceProvider; - this.cacheServiceProvider = cacheServiceProvider; - } - - @GetMapping(value = "/service-instances/service-instance/{service-instance-id}", - consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity getProject(@PathVariable(name = "service-instance-id") final String serviceInstanceId, - @RequestParam(name = "format", required = false) final String format, final HttpServletRequest request) { - LOGGER.info("retrieving service instance using 'service-instance-id': {} and format: {}...", serviceInstanceId, - format); - - final Optional optional = cacheServiceProvider.getNodeServiceInstance(serviceInstanceId); - if (!optional.isPresent()) { - LOGGER.error("Couldn't find {} in cache", serviceInstanceId); - return getRequestErrorResponseEntity(request); - } - - final Format value = Format.forValue(format); - final NodeServiceInstance nodeServiceInstance = optional.get(); - switch (value) { - case PATHED: - LOGGER.info("found project {} in cache", nodeServiceInstance); - final Map map = new HashMap<>(); - map.put(RESOURCE_TYPE, nodeServiceInstance.getResourceType()); - map.put(RESOURCE_LINK, nodeServiceInstance.getResourceLink()); - return ResponseEntity.ok(new Result(map)); - case RAW: - final Optional serviceInstance = - customerCacheServiceProvider.getServiceInstance(nodeServiceInstance.getGlobalCustomerId(), - nodeServiceInstance.getServiceType(), nodeServiceInstance.getServiceInstanceId()); - if (serviceInstance.isPresent()) { - return ResponseEntity.ok(serviceInstance.get()); - } - LOGGER.info("Unable to find Service instance in cahce using {}", nodeServiceInstance); - return getRequestErrorResponseEntity(request); - default: - break; - } - LOGGER.error("invalid format type :{}", format); - return getRequestErrorResponseEntity(request); - - - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/OwningEntityController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/OwningEntityController.java deleted file mode 100644 index e3d6b4f7..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/OwningEntityController.java +++ /dev/null @@ -1,127 +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.so.aai.simulator.controller; - -import static org.onap.so.aai.simulator.utils.Constants.OWNING_ENTITY; -import static org.onap.so.aai.simulator.utils.Constants.OWNING_ENTITY_URL; -import static org.onap.so.aai.simulator.utils.Utils.getRequestErrorResponseEntity; -import static org.onap.so.aai.simulator.utils.Utils.getResourceVersion; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.core.MediaType; -import org.onap.aai.domain.yang.OwningEntity; -import org.onap.aai.domain.yang.Relationship; -import org.onap.so.aai.simulator.models.Format; -import org.onap.so.aai.simulator.models.Result; -import org.onap.so.aai.simulator.service.providers.OwnEntityCacheServiceProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@Controller -@RequestMapping(path = OWNING_ENTITY_URL) -public class OwningEntityController { - - private static final Logger LOGGER = LoggerFactory.getLogger(OwningEntityController.class); - - private final OwnEntityCacheServiceProvider cacheServiceProvider; - - @Autowired - public OwningEntityController(final OwnEntityCacheServiceProvider cacheServiceProvider) { - this.cacheServiceProvider = cacheServiceProvider; - } - - - @PutMapping(value = "{owning-entity-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity putOwningEntity(@RequestBody final OwningEntity owningEntity, - @PathVariable("owning-entity-id") final String owningEntityId, final HttpServletRequest request) { - LOGGER.info("Will add OwningEntity to cache with key 'owning-entity-id': {} ...", - owningEntity.getOwningEntityId()); - - if (owningEntity.getResourceVersion() == null || owningEntity.getResourceVersion().isEmpty()) { - owningEntity.setResourceVersion(getResourceVersion()); - - } - cacheServiceProvider.putOwningEntity(owningEntityId, owningEntity); - return ResponseEntity.accepted().build(); - } - - @GetMapping(value = "{owning-entity-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity getOwningEntity(@PathVariable("owning-entity-id") final String owningEntityId, - @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("retrieving owning entity for 'owning-entity-id': {} ...", owningEntityId); - - final Optional optional = cacheServiceProvider.getOwningEntity(owningEntityId); - if (!optional.isPresent()) { - LOGGER.error("Couldn't find {} in cache", owningEntityId); - return getRequestErrorResponseEntity(request); - } - - final Format value = Format.forValue(format); - switch (value) { - case RAW: - final OwningEntity owningEntity = optional.get(); - LOGGER.info("found OwningEntity {} in cache", owningEntity); - return ResponseEntity.ok(owningEntity); - case COUNT: - final Map map = new HashMap<>(); - map.put(OWNING_ENTITY, 1); - return ResponseEntity.ok(new Result(map)); - default: - break; - } - LOGGER.error("invalid format type :{}", format); - return getRequestErrorResponseEntity(request); - } - - @PutMapping(value = "/{owning-entity-id}/relationship-list/relationship", - consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity putOwningEntityRelationShip(@RequestBody final Relationship relationship, - @PathVariable("owning-entity-id") final String owningEntityId, final HttpServletRequest request) { - - LOGGER.info("adding relationship for owning-entity-id: {} ...", owningEntityId); - if (cacheServiceProvider.putOwningEntityRelationShip(owningEntityId, relationship)) { - LOGGER.info("added OwningEntity relationship {} in cache", relationship); - return ResponseEntity.accepted().build(); - } - LOGGER.error("Couldn't add relationship for {} in cache", owningEntityId); - return getRequestErrorResponseEntity(request); - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/ProjectController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/ProjectController.java deleted file mode 100644 index 0c3b3b7b..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/ProjectController.java +++ /dev/null @@ -1,125 +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.so.aai.simulator.controller; - -import static org.onap.so.aai.simulator.utils.Constants.PROJECT; -import static org.onap.so.aai.simulator.utils.Constants.PROJECT_URL; -import static org.onap.so.aai.simulator.utils.Utils.getRequestErrorResponseEntity; -import static org.onap.so.aai.simulator.utils.Utils.getResourceVersion; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.core.MediaType; -import org.onap.aai.domain.yang.Project; -import org.onap.aai.domain.yang.Relationship; -import org.onap.so.aai.simulator.models.Format; -import org.onap.so.aai.simulator.models.Result; -import org.onap.so.aai.simulator.service.providers.ProjectCacheServiceProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@Controller -@RequestMapping(path = PROJECT_URL) -public class ProjectController { - private static final Logger LOGGER = LoggerFactory.getLogger(ProjectController.class); - - private final ProjectCacheServiceProvider cacheServiceProvider; - - @Autowired - public ProjectController(final ProjectCacheServiceProvider cacheServiceProvider) { - this.cacheServiceProvider = cacheServiceProvider; - } - - @PutMapping(value = "/{project-name}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity putProject(@RequestBody final Project project, - @PathVariable("project-name") final String projectName, final HttpServletRequest request) { - LOGGER.info("Will put project for 'project-name': {} ...", project.getProjectName()); - - if (project.getResourceVersion() == null || project.getResourceVersion().isEmpty()) { - project.setResourceVersion(getResourceVersion()); - - } - cacheServiceProvider.putProject(projectName, project); - return ResponseEntity.accepted().build(); - - } - - @GetMapping(value = "/{project-name}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity getProject(@PathVariable("project-name") final String projectName, - @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("retrieving project for 'project-name': {} ...", projectName); - - final Optional optional = cacheServiceProvider.getProject(projectName); - if (!optional.isPresent()) { - LOGGER.error("Couldn't find {} in cache", projectName); - return getRequestErrorResponseEntity(request); - } - - final Format value = Format.forValue(format); - switch (value) { - case RAW: - final Project project = optional.get(); - LOGGER.info("found project {} in cache", project); - return ResponseEntity.ok(project); - case COUNT: - final Map map = new HashMap<>(); - map.put(PROJECT, 1); - return ResponseEntity.ok(new Result(map)); - default: - break; - } - LOGGER.error("invalid format type :{}", format); - return getRequestErrorResponseEntity(request); - } - - @PutMapping(value = "/{project-name}/relationship-list/relationship", - consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity putProjectRelationShip(@RequestBody final Relationship relationship, - @PathVariable("project-name") final String projectName, final HttpServletRequest request) { - - LOGGER.info("adding relationship for project-name: {} ...", projectName); - if (cacheServiceProvider.putProjectRelationShip(projectName, relationship)) { - LOGGER.info("added project relationship {} in cache", relationship); - return ResponseEntity.accepted().build(); - } - LOGGER.error("Couldn't find {} in cache", projectName); - return getRequestErrorResponseEntity(request); - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/Format.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/Format.java deleted file mode 100644 index f6ff2403..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/Format.java +++ /dev/null @@ -1,49 +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.so.aai.simulator.models; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public enum Format { - - COUNT("count"), RAW("raw"), PATHED("pathed"); - - private final String value; - - private Format(final String value) { - this.value = value; - } - - public String getValue() { - return value; - } - - public static Format forValue(final String value) { - for (final Format format : Format.values()) { - if (format.getValue().equals(value)) { - return format; - } - } - return RAW; - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/NodeServiceInstance.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/NodeServiceInstance.java deleted file mode 100644 index f549850d..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/NodeServiceInstance.java +++ /dev/null @@ -1,139 +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.so.aai.simulator.models; - -import java.io.Serializable; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public class NodeServiceInstance implements Serializable { - - private static final long serialVersionUID = -3314166327618070948L; - - private String globalCustomerId; - private String serviceType; - private String serviceInstanceId; - private String resourceType; - private String resourceLink; - - public NodeServiceInstance() {} - - - public NodeServiceInstance(final String globalCustomerId, final String serviceType, final String serviceInstanceId, - final String resourceType, final String resourceLink) { - this.globalCustomerId = globalCustomerId; - this.serviceType = serviceType; - this.serviceInstanceId = serviceInstanceId; - this.resourceType = resourceType; - this.resourceLink = resourceLink; - } - - - /** - * @return the globalCustomerId - */ - public String getGlobalCustomerId() { - return globalCustomerId; - } - - - /** - * @param globalCustomerId the globalCustomerId to set - */ - public void setGlobalCustomerId(final String globalCustomerId) { - this.globalCustomerId = globalCustomerId; - } - - - /** - * @return the serviceType - */ - public String getServiceType() { - return serviceType; - } - - - /** - * @param serviceType the serviceType to set - */ - public void setServiceType(final String serviceType) { - this.serviceType = serviceType; - } - - - /** - * @return the serviceInstanceId - */ - public String getServiceInstanceId() { - return serviceInstanceId; - } - - - /** - * @param serviceInstanceId the serviceInstanceId to set - */ - public void setServiceInstanceId(final String serviceInstanceId) { - this.serviceInstanceId = serviceInstanceId; - } - - - /** - * @return the resourceType - */ - public String getResourceType() { - return resourceType; - } - - - /** - * @param resourceType the resourceType to set - */ - public void setResourceType(final String resourceType) { - this.resourceType = resourceType; - } - - - /** - * @return the resourceLink - */ - public String getResourceLink() { - return resourceLink; - } - - - /** - * @param resourceLink the resourceLink to set - */ - public void setResourceLink(final String resourceLink) { - this.resourceLink = resourceLink; - } - - - @Override - public String toString() { - return "NodeServiceInstance [globalCustomerId=" + globalCustomerId + ", serviceType=" + serviceType - + ", serviceInstanceId=" + serviceInstanceId + ", resourceType=" + resourceType + ", resourceLink=" - + resourceLink + "]"; - } - - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/Result.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/Result.java deleted file mode 100644 index 6aa92562..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/Result.java +++ /dev/null @@ -1,64 +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.so.aai.simulator.models; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonRootName; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@JsonRootName(value = "result") -public class Result { - - private List> values = new ArrayList<>(); - - public Result() {} - - public Result(final Map value) { - this.values.add(value); - } - - /** - * @return the values - */ - public List> getValues() { - return values; - } - - /** - * @param values the values to set - */ - public void setValues(final List> values) { - this.values = values; - } - - - @JsonIgnore - @Override - public String toString() { - return "Result [values=" + values + "]"; - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/AbstractCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/AbstractCacheServiceProvider.java deleted file mode 100644 index 4a45e81e..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/AbstractCacheServiceProvider.java +++ /dev/null @@ -1,55 +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.so.aai.simulator.service.providers; - -import java.util.concurrent.ConcurrentHashMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public abstract class AbstractCacheServiceProvider { - - private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); - - private final CacheManager cacheManager; - - public AbstractCacheServiceProvider(final CacheManager cacheManager) { - this.cacheManager = cacheManager; - } - - protected void clearCahce(final String name) { - final Cache cache = cacheManager.getCache(name); - if (cache != null) { - final ConcurrentHashMap nativeCache = (ConcurrentHashMap) cache.getNativeCache(); - LOGGER.info("Clear all entries from cahce: {}", cache.getName()); - nativeCache.clear(); - } - } - - protected Cache getCache(final String name) { - return cacheManager.getCache(name); - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProvider.java deleted file mode 100644 index 713da545..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProvider.java +++ /dev/null @@ -1,57 +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.so.aai.simulator.service.providers; - -import java.util.Optional; -import org.onap.aai.domain.yang.Customer; -import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aai.domain.yang.ServiceInstances; -import org.onap.aai.domain.yang.ServiceSubscription; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public interface CustomerCacheServiceProvider { - - Optional getCustomer(final String globalCustomerId); - - void putCustomer(final String globalCustomerId, final Customer customer); - - Optional getServiceSubscription(final String globalCustomerId, final String serviceType); - - boolean putServiceSubscription(final String globalCustomerId, final String serviceType, - final ServiceSubscription serviceSubscription); - - Optional getServiceInstances(final String globalCustomerId, final String serviceType, - final String serviceInstanceName); - - Optional getServiceInstance(final String globalCustomerId, final String serviceType, - final String serviceInstanceId); - - boolean putServiceInstance(final String globalCustomerId, final String serviceType, final String serviceInstanceId, - final ServiceInstance serviceInstance); - - boolean patchServiceInstance(final String globalCustomerId, final String serviceType, - final String serviceInstanceId, final ServiceInstance serviceInstance); - - void clearAll(); - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProviderImpl.java deleted file mode 100644 index c3b5a47d..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProviderImpl.java +++ /dev/null @@ -1,232 +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.so.aai.simulator.service.providers; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import org.onap.aai.domain.yang.Customer; -import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aai.domain.yang.ServiceInstances; -import org.onap.aai.domain.yang.ServiceSubscription; -import org.onap.aai.domain.yang.ServiceSubscriptions; -import org.onap.so.aai.simulator.utils.Constants; -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; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@Service -public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvider - implements CustomerCacheServiceProvider { - private static final Logger LOGGER = LoggerFactory.getLogger(CustomerCacheServiceProviderImpl.class); - - - @Autowired - public CustomerCacheServiceProviderImpl(final CacheManager cacheManager) { - super(cacheManager); - } - - @Override - public Optional getCustomer(final String globalCustomerId) { - LOGGER.info("getting customer from cache using key: {}", globalCustomerId); - final Cache cache = getCache(Constants.CUSTOMER_CACHE); - final Customer value = cache.get(globalCustomerId, Customer.class); - if (value != null) { - return Optional.of(value); - } - return Optional.empty(); - } - - @Override - public void putCustomer(final String globalCustomerId, final Customer customer) { - LOGGER.info("Adding customer: {} with key: {} in cache ...", customer, globalCustomerId); - final Cache cache = getCache(Constants.CUSTOMER_CACHE); - - cache.put(globalCustomerId, customer); - } - - @Override - public Optional getServiceSubscription(final String globalCustomerId, - final String serviceType) { - LOGGER.info("getting service subscription from cache for globalCustomerId: {} and serviceType: {}", - globalCustomerId, serviceType); - - final Cache cache = getCache(Constants.CUSTOMER_CACHE); - - final Customer value = cache.get(globalCustomerId, Customer.class); - - if (value != null) { - return Optional.ofNullable(value.getServiceSubscriptions().getServiceSubscription().stream() - .filter(s -> serviceType.equals(s.getServiceType())).findFirst().orElse(null)); - } - return Optional.empty(); - - } - - @Override - public Optional getServiceInstances(final String globalCustomerId, final String serviceType, - final String serviceInstanceName) { - - final Cache cache = getCache(Constants.CUSTOMER_CACHE); - final Customer value = cache.get(globalCustomerId, Customer.class); - - if (value != null) { - final Optional serviceSubscription = value.getServiceSubscriptions() - .getServiceSubscription().stream().filter(s -> serviceType.equals(s.getServiceType())).findFirst(); - - if (serviceSubscription.isPresent()) { - LOGGER.info("Found service subscription ..."); - final List serviceInstancesList = serviceSubscription.get().getServiceInstances() - .getServiceInstance().stream() - .filter(serviceInstance -> serviceInstanceName.equals(serviceInstance.getServiceInstanceName())) - .collect(Collectors.toList()); - if (serviceInstancesList != null && !serviceInstancesList.isEmpty()) { - LOGGER.info("Found {} service instances ", serviceInstancesList.size()); - final ServiceInstances serviceInstances = new ServiceInstances(); - serviceInstances.getServiceInstance().addAll(serviceInstancesList); - return Optional.of(serviceInstances); - - } - } - } - return Optional.empty(); - } - - @Override - public Optional getServiceInstance(final String globalCustomerId, final String serviceType, - final String serviceInstanceId) { - final Cache cache = getCache(Constants.CUSTOMER_CACHE); - final Customer value = cache.get(globalCustomerId, Customer.class); - - if (value != null) { - final Optional serviceSubscription = value.getServiceSubscriptions() - .getServiceSubscription().stream().filter(s -> serviceType.equals(s.getServiceType())).findFirst(); - - if (serviceSubscription.isPresent()) { - LOGGER.info("Found service subscription ..."); - final ServiceInstances serviceInstances = serviceSubscription.get().getServiceInstances(); - if (serviceInstances != null) { - return Optional.ofNullable(serviceInstances.getServiceInstance().stream() - .filter(serviceInstance -> serviceInstanceId.equals(serviceInstance.getServiceInstanceId())) - .findFirst().orElse(null)); - } - - } - } - return Optional.empty(); - } - - @Override - public boolean putServiceInstance(final String globalCustomerId, final String serviceType, - final String serviceInstanceId, final ServiceInstance serviceInstance) { - LOGGER.info("Adding serviceInstance: {} in cache ...", serviceInstance, globalCustomerId); - - final Cache cache = getCache(Constants.CUSTOMER_CACHE); - final Customer value = cache.get(globalCustomerId, Customer.class); - - if (value != null) { - final Optional serviceSubscription = value.getServiceSubscriptions() - .getServiceSubscription().stream().filter(s -> serviceType.equals(s.getServiceType())).findFirst(); - - if (serviceSubscription.isPresent()) { - final ServiceInstances serviceInstances = getServiceInstances(serviceSubscription); - - - if (!serviceInstances.getServiceInstance().stream() - .filter(existing -> serviceInstanceId.equals(existing.getServiceInstanceId())).findFirst() - .isPresent()) { - return serviceInstances.getServiceInstance().add(serviceInstance); - } - LOGGER.error("Service {} already exists ....", serviceInstanceId); - return false; - } - LOGGER.error("Couldn't find service subscription with serviceType: {} in cache ", serviceType); - return false; - } - LOGGER.error("Couldn't find Customer with key: {} in cache ", globalCustomerId); - return false; - } - - @Override - public boolean putServiceSubscription(final String globalCustomerId, final String serviceType, - final ServiceSubscription serviceSubscription) { - - final Optional customerOptional = getCustomer(globalCustomerId); - - if (customerOptional.isPresent()) { - final Customer customer = customerOptional.get(); - if (customer.getServiceSubscriptions() == null) { - final ServiceSubscriptions serviceSubscriptions = new ServiceSubscriptions(); - customer.setServiceSubscriptions(serviceSubscriptions); - return serviceSubscriptions.getServiceSubscription().add(serviceSubscription); - } - - final Optional serviceSubscriptionOptional = customer.getServiceSubscriptions() - .getServiceSubscription().stream().filter(s -> serviceType.equals(s.getServiceType())).findFirst(); - - if (!serviceSubscriptionOptional.isPresent()) { - return customer.getServiceSubscriptions().getServiceSubscription().add(serviceSubscription); - } - LOGGER.error("ServiceSubscription already exists {}", serviceSubscriptionOptional.get().getServiceType()); - return false; - } - LOGGER.error("Unable to add ServiceSubscription to cache becuase customer does not exits ..."); - return false; - } - - @Override - public boolean patchServiceInstance(final String globalCustomerId, final String serviceType, - final String serviceInstanceId, final ServiceInstance serviceInstance) { - final Optional instance = getServiceInstance(globalCustomerId, serviceType, serviceInstanceId); - if (instance.isPresent()) { - final ServiceInstance cachedServiceInstance = instance.get(); - LOGGER.info("Changing OrchestrationStatus from {} to {} ", cachedServiceInstance.getOrchestrationStatus(), - serviceInstance.getOrchestrationStatus()); - cachedServiceInstance.setOrchestrationStatus(serviceInstance.getOrchestrationStatus()); - return true; - } - LOGGER.error("Unable to find ServiceInstance ..."); - return false; - } - - private ServiceInstances getServiceInstances(final Optional optional) { - final ServiceSubscription serviceSubscription = optional.get(); - final ServiceInstances serviceInstances = serviceSubscription.getServiceInstances(); - if (serviceInstances == null) { - final ServiceInstances instances = new ServiceInstances(); - serviceSubscription.setServiceInstances(instances); - return instances; - } - return serviceInstances; - } - - @Override - public void clearAll() { - clearCahce(Constants.CUSTOMER_CACHE); - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProvider.java deleted file mode 100644 index bf444f2f..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProvider.java +++ /dev/null @@ -1,37 +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.so.aai.simulator.service.providers; - -import java.util.Optional; -import org.onap.so.aai.simulator.models.NodeServiceInstance; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public interface NodesCacheServiceProvider { - - void putNodeServiceInstance(final String serviceInstanceId, final NodeServiceInstance nodeServiceInstance); - - Optional getNodeServiceInstance(final String serviceInstanceId); - - void clearAll(); - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProviderImpl.java deleted file mode 100644 index 0f0ac114..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProviderImpl.java +++ /dev/null @@ -1,73 +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.so.aai.simulator.service.providers; - -import static org.onap.so.aai.simulator.utils.Constants.NODES_CACHE; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import org.onap.so.aai.simulator.models.NodeServiceInstance; -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; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@Service -public class NodesCacheServiceProviderImpl extends AbstractCacheServiceProvider implements NodesCacheServiceProvider { - private static final Logger LOGGER = LoggerFactory.getLogger(NodesCacheServiceProviderImpl.class); - - - @Autowired - public NodesCacheServiceProviderImpl(final CacheManager cacheManager) { - super(cacheManager); - } - - @Override - public void putNodeServiceInstance(final String serviceInstanceId, final NodeServiceInstance nodeServiceInstance) { - final Cache cache = getCache(NODES_CACHE); - LOGGER.info("Adding {} to cache with key: {}...", nodeServiceInstance, serviceInstanceId); - cache.put(serviceInstanceId, nodeServiceInstance); - } - - @Override - public Optional getNodeServiceInstance(final String serviceInstanceId) { - final Cache cache = getCache(NODES_CACHE); - final NodeServiceInstance value = cache.get(serviceInstanceId, NodeServiceInstance.class); - if (value != null) { - return Optional.of(value); - } - LOGGER.error("Unable to find node service instance in cache using key:{} ", serviceInstanceId); - return Optional.empty(); - } - - @Override - public void clearAll() { - final Cache cache = getCache(NODES_CACHE); - final ConcurrentHashMap nativeCache = (ConcurrentHashMap) cache.getNativeCache(); - LOGGER.info("Clear all entries from cahce: {}", cache.getName()); - nativeCache.clear(); - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProvider.java deleted file mode 100644 index a7b6409c..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProvider.java +++ /dev/null @@ -1,39 +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.so.aai.simulator.service.providers; - -import java.util.Optional; -import org.onap.aai.domain.yang.OwningEntity; -import org.onap.aai.domain.yang.Relationship; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public interface OwnEntityCacheServiceProvider { - - void putOwningEntity(final String owningEntityId, final OwningEntity owningEntity); - - Optional getOwningEntity(final String owningEntityId); - - boolean putOwningEntityRelationShip(String owningEntityId, Relationship relationship); - - void clearAll(); -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProviderImpl.java deleted file mode 100644 index 6b7af022..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProviderImpl.java +++ /dev/null @@ -1,98 +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.so.aai.simulator.service.providers; - -import static org.onap.so.aai.simulator.utils.Constants.OWNING_ENTITY_CACHE; -import static org.onap.so.aai.simulator.utils.Constants.SERVICE_RESOURCE_TYPE; -import java.util.Optional; -import org.onap.aai.domain.yang.OwningEntity; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipList; -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; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@Service -public class OwnEntityCacheServiceProviderImpl extends AbstractCacheServiceProvider - implements OwnEntityCacheServiceProvider { - - private static final Logger LOGGER = LoggerFactory.getLogger(OwnEntityCacheServiceProviderImpl.class); - private static final String RELATIONSHIPS_LABEL = "org.onap.relationships.inventory.BelongsTo"; - - @Autowired - public OwnEntityCacheServiceProviderImpl(final CacheManager cacheManager) { - super(cacheManager); - } - - @Override - public void putOwningEntity(final String owningEntityId, final OwningEntity owningEntity) { - LOGGER.info("Adding OwningEntity: {} with name to cache", owningEntityId, owningEntity); - final Cache cache = getCache(OWNING_ENTITY_CACHE); - cache.put(owningEntityId, owningEntity); - } - - @Override - public Optional getOwningEntity(final String owningEntityId) { - LOGGER.info("getting OwningEntity from cache using key: {}", owningEntityId); - final Cache cache = getCache(OWNING_ENTITY_CACHE); - final OwningEntity value = cache.get(owningEntityId, OwningEntity.class); - if (value != null) { - return Optional.of(value); - } - return Optional.empty(); - } - - @Override - public boolean putOwningEntityRelationShip(final String owningEntityId, final Relationship relationship) { - final Cache cache = getCache(OWNING_ENTITY_CACHE); - final OwningEntity value = cache.get(owningEntityId, OwningEntity.class); - if (value != null) { - RelationshipList relationshipList = value.getRelationshipList(); - if (relationshipList == null) { - relationshipList = new RelationshipList(); - value.setRelationshipList(relationshipList); - } - - if (relationship.getRelatedTo() == null) { - relationship.setRelatedTo(SERVICE_RESOURCE_TYPE); - } - if (relationship.getRelationshipLabel() == null) { - relationship.setRelationshipLabel(RELATIONSHIPS_LABEL); - } - - return relationshipList.getRelationship().add(relationship); - } - LOGGER.error("OwningEntity not found in cache for {}", owningEntityId); - return false; - } - - @Override - public void clearAll() { - clearCahce(OWNING_ENTITY_CACHE); - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProvider.java deleted file mode 100644 index 59060f27..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProvider.java +++ /dev/null @@ -1,39 +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.so.aai.simulator.service.providers; - -import java.util.Optional; -import org.onap.aai.domain.yang.Project; -import org.onap.aai.domain.yang.Relationship; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public interface ProjectCacheServiceProvider { - - void putProject(final String projectName, final Project project); - - Optional getProject(final String projectName); - - boolean putProjectRelationShip(final String projectName, final Relationship relationship); - - void clearAll(); -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProviderImpl.java deleted file mode 100644 index 4fca3119..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProviderImpl.java +++ /dev/null @@ -1,101 +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.so.aai.simulator.service.providers; - -import static org.onap.so.aai.simulator.utils.Constants.PROJECT_CACHE; -import static org.onap.so.aai.simulator.utils.Constants.SERVICE_RESOURCE_TYPE; -import java.util.Optional; -import org.onap.aai.domain.yang.Project; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipList; -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; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@Service -public class ProjectCacheServiceProviderImpl extends AbstractCacheServiceProvider - implements ProjectCacheServiceProvider { - - private static final String RELATIONSHIPS_LABEL = "org.onap.relationships.inventory.Uses"; - - private static final Logger LOGGER = LoggerFactory.getLogger(ProjectCacheServiceProviderImpl.class); - - - @Autowired - public ProjectCacheServiceProviderImpl(final CacheManager cacheManager) { - super(cacheManager); - } - - @Override - public void putProject(final String projectName, final Project project) { - LOGGER.info("Adding project: {} with name to cache", project, projectName); - final Cache cache = getCache(PROJECT_CACHE); - cache.put(projectName, project); - } - - - @Override - public Optional getProject(final String projectName) { - LOGGER.info("getting project from cache using key: {}", projectName); - final Cache cache = getCache(PROJECT_CACHE); - final Project value = cache.get(projectName, Project.class); - if (value != null) { - return Optional.of(value); - } - return Optional.empty(); - } - - @Override - public boolean putProjectRelationShip(final String projectName, final Relationship relationship) { - final Cache cache = getCache(PROJECT_CACHE); - final Project value = cache.get(projectName, Project.class); - if (value != null) { - RelationshipList relationshipList = value.getRelationshipList(); - if (relationshipList == null) { - relationshipList = new RelationshipList(); - value.setRelationshipList(relationshipList); - } - - if (relationship.getRelatedTo() == null) { - relationship.setRelatedTo(SERVICE_RESOURCE_TYPE); - } - if (relationship.getRelationshipLabel() == null) { - relationship.setRelationshipLabel(RELATIONSHIPS_LABEL); - } - - return relationshipList.getRelationship().add(relationship); - } - LOGGER.error("Project not found in cache for {}", projectName); - return false; - - } - - @Override - public void clearAll() { - clearCahce(PROJECT_CACHE); - } -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Constants.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Constants.java deleted file mode 100644 index 3d1f85df..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Constants.java +++ /dev/null @@ -1,68 +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.so.aai.simulator.utils; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public class Constants { - - public static final String BASE_URL = "/aai/v15"; - - public static final String NODES_URL = BASE_URL + "/nodes"; - - public static final String BUSINESS_URL = BASE_URL + "/business"; - - public static final String CUSTOMER_URL = BUSINESS_URL + "/customers/customer/"; - - public static final String PROJECT_URL = BUSINESS_URL + "/projects/project/"; - - public static final String OWNING_ENTITY_URL = BUSINESS_URL + "/owning-entities/owning-entity"; - - public static final String HEALTHY = "healthy"; - - public static final String CUSTOMER_CACHE = "customer-cache"; - - public static final String PROJECT_CACHE = "project-cache"; - - public static final String NODES_CACHE = "nodes-cache"; - - public static final String OWNING_ENTITY_CACHE = "owning-entity-cache"; - - public static final String PROJECT = "project"; - - public static final String OWNING_ENTITY = "owning-entity"; - - public static final String X_HTTP_METHOD_OVERRIDE = "X-HTTP-Method-Override"; - - public static final String ERROR_MESSAGE_ID = "SVC3001"; - - public static final String ERROR_MESSAGE = "Resource not found for %1 using id %2 (msg=%3) (ec=%4)"; - - public static final String SERVICE_RESOURCE_TYPE = "service-instance"; - - public static final String RESOURCE_LINK = "resource-link"; - - public static final String RESOURCE_TYPE = "resource-type"; - - private Constants() {} - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/RequestError.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/RequestError.java deleted file mode 100644 index 471e884d..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/RequestError.java +++ /dev/null @@ -1,59 +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.so.aai.simulator.utils; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@XmlRootElement(name = "requestError") -@XmlAccessorType(XmlAccessType.FIELD) -public class RequestError { - - @XmlElement(name = "serviceException") - private ServiceException serviceException; - - /** - * @return the serviceException - */ - public ServiceException getServiceException() { - return serviceException; - } - - /** - * @param serviceException the serviceException to set - */ - public void setServiceException(final ServiceException serviceException) { - this.serviceException = serviceException; - } - - @Override - public String toString() { - return "RequestError [serviceException=" + serviceException + "]"; - } - - - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/RequestErrorBuilder.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/RequestErrorBuilder.java deleted file mode 100644 index 9dbd4a3d..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/RequestErrorBuilder.java +++ /dev/null @@ -1,59 +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.so.aai.simulator.utils; - -import java.util.Arrays; -import java.util.List; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public class RequestErrorBuilder { - - private final ServiceException serviceException = new ServiceException(); - - public RequestErrorBuilder messageId(final String messageId) { - this.serviceException.setMessageId(messageId); - return this; - } - - public RequestErrorBuilder text(final String text) { - this.serviceException.setText(text); - return this; - } - - public RequestErrorBuilder variables(final List variables) { - this.serviceException.setVariables(variables); - return this; - } - - public RequestErrorBuilder variables(final String... variables) { - this.serviceException.setVariables(Arrays.asList(variables)); - return this; - } - - public RequestError build() { - final RequestError requestError = new RequestError(); - requestError.setServiceException(serviceException); - return requestError; - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/ServiceException.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/ServiceException.java deleted file mode 100644 index ba2ee782..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/ServiceException.java +++ /dev/null @@ -1,88 +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.so.aai.simulator.utils; - -import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@XmlRootElement(name = "serviceException") -@XmlAccessorType(XmlAccessType.FIELD) -public class ServiceException { - - private String messageId; - - private String text; - - private List variables; - - /** - * @return the messageId - */ - public String getMessageId() { - return messageId; - } - - /** - * @param messageId the messageId to set - */ - public void setMessageId(final String messageId) { - this.messageId = messageId; - } - - /** - * @return the text - */ - public String getText() { - return text; - } - - /** - * @param text the text to set - */ - public void setText(final String text) { - this.text = text; - } - - /** - * @return the variables - */ - public List getVariables() { - return variables; - } - - /** - * @param variables the variables to set - */ - public void setVariables(final List variables) { - this.variables = variables; - } - - @Override - public String toString() { - return "ServiceException [messageId=" + messageId + ", text=" + text + ", variables=" + variables + "]"; - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Utils.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Utils.java deleted file mode 100644 index 81deb86b..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Utils.java +++ /dev/null @@ -1,58 +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.so.aai.simulator.utils; - -import static org.onap.so.aai.simulator.utils.Constants.ERROR_MESSAGE; -import static org.onap.so.aai.simulator.utils.Constants.ERROR_MESSAGE_ID; -import javax.servlet.http.HttpServletRequest; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public class Utils { - - private static final String EMPTY_STRING = ""; - - public static final String getResourceVersion() { - return System.currentTimeMillis() + EMPTY_STRING; - } - - public static ResponseEntity getRequestErrorResponseEntity(final HttpServletRequest request, - final String nodeType) { - return new ResponseEntity<>( - new RequestErrorBuilder().messageId(ERROR_MESSAGE_ID).text(ERROR_MESSAGE) - .variables(request.getMethod(), request.getRequestURI(), "Node Not Found:No Node of " + nodeType - + " service-instance found at: " + request.getRequestURI(), "ERR.5.4.6114") - .build(), - HttpStatus.NOT_FOUND); - } - - - public static ResponseEntity getRequestErrorResponseEntity(final HttpServletRequest request) { - return getRequestErrorResponseEntity(request, Constants.SERVICE_RESOURCE_TYPE); - } - - - private Utils() {} - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/AaiSimulatorApplication.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/AaiSimulatorApplication.java new file mode 100644 index 00000000..bb1b190d --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/AaiSimulatorApplication.java @@ -0,0 +1,38 @@ +/*- + * ============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.so.aaisimulator; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.cache.annotation.EnableCaching; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@EnableCaching +@SpringBootApplication(scanBasePackages = {"org.onap"}) +public class AaiSimulatorApplication extends SpringBootServletInitializer { + + public static void main(final String[] args) { + SpringApplication.run(AaiSimulatorApplication.class, args); + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/ApplicationConfigration.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/ApplicationConfigration.java new file mode 100644 index 00000000..2a55760b --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/ApplicationConfigration.java @@ -0,0 +1,61 @@ +/*- + * ============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.so.aaisimulator.configration; + +import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_CACHE; +import static org.onap.so.aaisimulator.utils.Constants.NODES_CACHE; +import static org.onap.so.aaisimulator.utils.Constants.OWNING_ENTITY_CACHE; +import static org.onap.so.aaisimulator.utils.Constants.PROJECT_CACHE; +import java.util.Arrays; +import java.util.List; +import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.cache.concurrent.ConcurrentMapCache; +import org.springframework.cache.support.SimpleCacheManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Configuration +public class ApplicationConfigration { + + @Bean + public Jackson2ObjectMapperBuilderCustomizer jacksonCustomizer() { + return (mapperBuilder) -> mapperBuilder.modulesToInstall(new JaxbAnnotationModule()); + } + + @Bean + public CacheManager cacheManager() { + final SimpleCacheManager manager = new SimpleCacheManager(); + final List caches = Arrays.asList(getCache(CUSTOMER_CACHE), getCache(PROJECT_CACHE), + getCache(NODES_CACHE), getCache(OWNING_ENTITY_CACHE)); + manager.setCaches(caches); + return manager; + } + + private Cache getCache(final String name) { + return new ConcurrentMapCache(name); + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/WebSecurityConfigImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/WebSecurityConfigImpl.java new file mode 100644 index 00000000..eb92c246 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/WebSecurityConfigImpl.java @@ -0,0 +1,71 @@ +/*- + * ============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.so.aaisimulator.configration; + +import org.onap.so.aaisimulator.utils.Constants; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Configuration +@EnableWebSecurity +public class WebSecurityConfigImpl extends WebSecurityConfigurerAdapter { + + private final String username; + private final String password; + private final String role; + + public WebSecurityConfigImpl(@Value("${spring.security.username}") final String username, + @Value("${spring.security.password}") final String password, + @Value("${spring.security.role}") final String role) { + this.username = username; + this.password = password; + this.role = role; + } + + + @Override + protected void configure(final HttpSecurity http) throws Exception { + http.csrf().disable().authorizeRequests().antMatchers(Constants.BUSINESS_URL + "/**/**").authenticated().and() + .httpBasic(); + } + + @Bean + public BCryptPasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + + @Autowired + public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception { + auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()).withUser(username).password(password) + .roles(role); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/AaiSimulatorController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/AaiSimulatorController.java new file mode 100644 index 00000000..f5912908 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/AaiSimulatorController.java @@ -0,0 +1,51 @@ +/*- + * ============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.so.aaisimulator.controller; + +import static org.onap.so.aaisimulator.utils.Constants.HEALTHY; +import javax.ws.rs.core.MediaType; +import org.onap.so.aaisimulator.utils.Constants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Controller +@RequestMapping(path = Constants.BASE_URL) +public class AaiSimulatorController { + private static final Logger LOGGER = LoggerFactory.getLogger(AaiSimulatorController.class); + + @ResponseBody + @GetMapping(value = "/healthcheck", produces = MediaType.TEXT_PLAIN) + @ResponseStatus(code = HttpStatus.OK) + public String healthCheck() { + LOGGER.info("Running health check ..."); + return HEALTHY; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java new file mode 100644 index 00000000..190d86e6 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java @@ -0,0 +1,248 @@ +/*- + * ============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.so.aaisimulator.controller; + +import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_URL; +import static org.onap.so.aaisimulator.utils.Constants.SERVICE_RESOURCE_TYPE; +import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; +import static org.onap.so.aaisimulator.utils.Utils.getRequestErrorResponseEntity; +import static org.onap.so.aaisimulator.utils.Utils.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.ServiceInstance; +import org.onap.aai.domain.yang.ServiceInstances; +import org.onap.aai.domain.yang.ServiceSubscription; +import org.onap.so.aaisimulator.models.NodeServiceInstance; +import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider; +import org.onap.so.aaisimulator.service.providers.NodesCacheServiceProvider; +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.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +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 String SERVICE_SUBSCRIPTION = "service-subscription"; + private static final String CUSTOMER_TYPE = "Customer"; + private static final Logger LOGGER = LoggerFactory.getLogger(BusinessController.class); + private final CustomerCacheServiceProvider cacheServiceProvider; + private final NodesCacheServiceProvider nodesCacheServiceProvider; + + @Autowired + public BusinessController(final CustomerCacheServiceProvider cacheServiceProvider, + final NodesCacheServiceProvider nodesCacheServiceProvider) { + this.cacheServiceProvider = cacheServiceProvider; + this.nodesCacheServiceProvider = nodesCacheServiceProvider; + } + + @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(); + + } + + @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}", + 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); + + if (cacheServiceProvider.putServiceSubscription(globalCustomerId, serviceType, serviceSubscription)) { + LOGGER.info("Successfully add service subscription in 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); + } + + @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) { + + LOGGER.info( + "Will add service instance for 'global customer id': {}, 'service type': {} and 'service instance id: '{} ...", + globalCustomerId, serviceType, serviceInstanceId); + + if (serviceInstance.getResourceVersion() == null || serviceInstance.getResourceVersion().isEmpty()) { + serviceInstance.setResourceVersion(getResourceVersion()); + } + + if (cacheServiceProvider.putServiceInstance(globalCustomerId, serviceType, serviceInstanceId, + serviceInstance)) { + nodesCacheServiceProvider.putNodeServiceInstance(serviceInstanceId, new NodeServiceInstance( + globalCustomerId, serviceType, serviceInstanceId, SERVICE_RESOURCE_TYPE, request.getRequestURI())); + return ResponseEntity.accepted().build(); + } + + LOGGER.error("Couldn't add 'global customer id': {}, 'service type': {} and 'service instance id': {} to cache", + globalCustomerId, serviceType, serviceInstanceId); + 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) { + + LOGGER.info( + "Will 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); + return ResponseEntity.accepted().build(); + } + LOGGER.error("{} not supported ... ", xHttpHeaderOverride); + + return getRequestErrorResponseEntity(request); + } + + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/NodesController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/NodesController.java new file mode 100644 index 00000000..4e660c90 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/NodesController.java @@ -0,0 +1,110 @@ +/*- + * ============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.so.aaisimulator.controller; + +import static org.onap.so.aaisimulator.utils.Constants.NODES_URL; +import static org.onap.so.aaisimulator.utils.Constants.RESOURCE_LINK; +import static org.onap.so.aaisimulator.utils.Constants.RESOURCE_TYPE; +import static org.onap.so.aaisimulator.utils.Utils.getRequestErrorResponseEntity; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.MediaType; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.NodeServiceInstance; +import org.onap.so.aaisimulator.models.Result; +import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider; +import org.onap.so.aaisimulator.service.providers.NodesCacheServiceProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Controller +@RequestMapping(path = NODES_URL) +public class NodesController { + + + private static final Logger LOGGER = LoggerFactory.getLogger(NodesController.class); + + private final NodesCacheServiceProvider cacheServiceProvider; + + private final CustomerCacheServiceProvider customerCacheServiceProvider; + + @Autowired + public NodesController(final CustomerCacheServiceProvider customerCacheServiceProvider, + final NodesCacheServiceProvider cacheServiceProvider) { + this.customerCacheServiceProvider = customerCacheServiceProvider; + this.cacheServiceProvider = cacheServiceProvider; + } + + @GetMapping(value = "/service-instances/service-instance/{service-instance-id}", + consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity getProject(@PathVariable(name = "service-instance-id") final String serviceInstanceId, + @RequestParam(name = "format", required = false) final String format, final HttpServletRequest request) { + LOGGER.info("retrieving service instance using 'service-instance-id': {} and format: {}...", serviceInstanceId, + format); + + final Optional optional = cacheServiceProvider.getNodeServiceInstance(serviceInstanceId); + if (!optional.isPresent()) { + LOGGER.error("Couldn't find {} in cache", serviceInstanceId); + return getRequestErrorResponseEntity(request); + } + + final Format value = Format.forValue(format); + final NodeServiceInstance nodeServiceInstance = optional.get(); + switch (value) { + case PATHED: + LOGGER.info("found project {} in cache", nodeServiceInstance); + final Map map = new HashMap<>(); + map.put(RESOURCE_TYPE, nodeServiceInstance.getResourceType()); + map.put(RESOURCE_LINK, nodeServiceInstance.getResourceLink()); + return ResponseEntity.ok(new Result(map)); + case RAW: + final Optional serviceInstance = + customerCacheServiceProvider.getServiceInstance(nodeServiceInstance.getGlobalCustomerId(), + nodeServiceInstance.getServiceType(), nodeServiceInstance.getServiceInstanceId()); + if (serviceInstance.isPresent()) { + return ResponseEntity.ok(serviceInstance.get()); + } + LOGGER.info("Unable to find Service instance in cahce using {}", nodeServiceInstance); + return getRequestErrorResponseEntity(request); + default: + break; + } + LOGGER.error("invalid format type :{}", format); + return getRequestErrorResponseEntity(request); + + + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/OwningEntityController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/OwningEntityController.java new file mode 100644 index 00000000..cd7c4001 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/OwningEntityController.java @@ -0,0 +1,127 @@ +/*- + * ============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.so.aaisimulator.controller; + +import static org.onap.so.aaisimulator.utils.Constants.OWNING_ENTITY; +import static org.onap.so.aaisimulator.utils.Constants.OWNING_ENTITY_URL; +import static org.onap.so.aaisimulator.utils.Utils.getRequestErrorResponseEntity; +import static org.onap.so.aaisimulator.utils.Utils.getResourceVersion; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.MediaType; +import org.onap.aai.domain.yang.OwningEntity; +import org.onap.aai.domain.yang.Relationship; +import org.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Result; +import org.onap.so.aaisimulator.service.providers.OwnEntityCacheServiceProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Controller +@RequestMapping(path = OWNING_ENTITY_URL) +public class OwningEntityController { + + private static final Logger LOGGER = LoggerFactory.getLogger(OwningEntityController.class); + + private final OwnEntityCacheServiceProvider cacheServiceProvider; + + @Autowired + public OwningEntityController(final OwnEntityCacheServiceProvider cacheServiceProvider) { + this.cacheServiceProvider = cacheServiceProvider; + } + + + @PutMapping(value = "{owning-entity-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity putOwningEntity(@RequestBody final OwningEntity owningEntity, + @PathVariable("owning-entity-id") final String owningEntityId, final HttpServletRequest request) { + LOGGER.info("Will add OwningEntity to cache with key 'owning-entity-id': {} ...", + owningEntity.getOwningEntityId()); + + if (owningEntity.getResourceVersion() == null || owningEntity.getResourceVersion().isEmpty()) { + owningEntity.setResourceVersion(getResourceVersion()); + + } + cacheServiceProvider.putOwningEntity(owningEntityId, owningEntity); + return ResponseEntity.accepted().build(); + } + + @GetMapping(value = "{owning-entity-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity getOwningEntity(@PathVariable("owning-entity-id") final String owningEntityId, + @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("retrieving owning entity for 'owning-entity-id': {} ...", owningEntityId); + + final Optional optional = cacheServiceProvider.getOwningEntity(owningEntityId); + if (!optional.isPresent()) { + LOGGER.error("Couldn't find {} in cache", owningEntityId); + return getRequestErrorResponseEntity(request); + } + + final Format value = Format.forValue(format); + switch (value) { + case RAW: + final OwningEntity owningEntity = optional.get(); + LOGGER.info("found OwningEntity {} in cache", owningEntity); + return ResponseEntity.ok(owningEntity); + case COUNT: + final Map map = new HashMap<>(); + map.put(OWNING_ENTITY, 1); + return ResponseEntity.ok(new Result(map)); + default: + break; + } + LOGGER.error("invalid format type :{}", format); + return getRequestErrorResponseEntity(request); + } + + @PutMapping(value = "/{owning-entity-id}/relationship-list/relationship", + consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity putOwningEntityRelationShip(@RequestBody final Relationship relationship, + @PathVariable("owning-entity-id") final String owningEntityId, final HttpServletRequest request) { + + LOGGER.info("adding relationship for owning-entity-id: {} ...", owningEntityId); + if (cacheServiceProvider.putOwningEntityRelationShip(owningEntityId, relationship)) { + LOGGER.info("added OwningEntity relationship {} in cache", relationship); + return ResponseEntity.accepted().build(); + } + LOGGER.error("Couldn't add relationship for {} in cache", owningEntityId); + return getRequestErrorResponseEntity(request); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/ProjectController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/ProjectController.java new file mode 100644 index 00000000..bf1770ef --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/ProjectController.java @@ -0,0 +1,125 @@ +/*- + * ============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.so.aaisimulator.controller; + +import static org.onap.so.aaisimulator.utils.Constants.PROJECT; +import static org.onap.so.aaisimulator.utils.Constants.PROJECT_URL; +import static org.onap.so.aaisimulator.utils.Utils.getRequestErrorResponseEntity; +import static org.onap.so.aaisimulator.utils.Utils.getResourceVersion; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.MediaType; +import org.onap.aai.domain.yang.Project; +import org.onap.aai.domain.yang.Relationship; +import org.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Result; +import org.onap.so.aaisimulator.service.providers.ProjectCacheServiceProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Controller +@RequestMapping(path = PROJECT_URL) +public class ProjectController { + private static final Logger LOGGER = LoggerFactory.getLogger(ProjectController.class); + + private final ProjectCacheServiceProvider cacheServiceProvider; + + @Autowired + public ProjectController(final ProjectCacheServiceProvider cacheServiceProvider) { + this.cacheServiceProvider = cacheServiceProvider; + } + + @PutMapping(value = "/{project-name}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity putProject(@RequestBody final Project project, + @PathVariable("project-name") final String projectName, final HttpServletRequest request) { + LOGGER.info("Will put project for 'project-name': {} ...", project.getProjectName()); + + if (project.getResourceVersion() == null || project.getResourceVersion().isEmpty()) { + project.setResourceVersion(getResourceVersion()); + + } + cacheServiceProvider.putProject(projectName, project); + return ResponseEntity.accepted().build(); + + } + + @GetMapping(value = "/{project-name}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity getProject(@PathVariable("project-name") final String projectName, + @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("retrieving project for 'project-name': {} ...", projectName); + + final Optional optional = cacheServiceProvider.getProject(projectName); + if (!optional.isPresent()) { + LOGGER.error("Couldn't find {} in cache", projectName); + return getRequestErrorResponseEntity(request); + } + + final Format value = Format.forValue(format); + switch (value) { + case RAW: + final Project project = optional.get(); + LOGGER.info("found project {} in cache", project); + return ResponseEntity.ok(project); + case COUNT: + final Map map = new HashMap<>(); + map.put(PROJECT, 1); + return ResponseEntity.ok(new Result(map)); + default: + break; + } + LOGGER.error("invalid format type :{}", format); + return getRequestErrorResponseEntity(request); + } + + @PutMapping(value = "/{project-name}/relationship-list/relationship", + consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity putProjectRelationShip(@RequestBody final Relationship relationship, + @PathVariable("project-name") final String projectName, final HttpServletRequest request) { + + LOGGER.info("adding relationship for project-name: {} ...", projectName); + if (cacheServiceProvider.putProjectRelationShip(projectName, relationship)) { + LOGGER.info("added project relationship {} in cache", relationship); + return ResponseEntity.accepted().build(); + } + LOGGER.error("Couldn't find {} in cache", projectName); + return getRequestErrorResponseEntity(request); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/Format.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/Format.java new file mode 100644 index 00000000..1c851fc3 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/Format.java @@ -0,0 +1,49 @@ +/*- + * ============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.so.aaisimulator.models; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public enum Format { + + COUNT("count"), RAW("raw"), PATHED("pathed"); + + private final String value; + + private Format(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static Format forValue(final String value) { + for (final Format format : Format.values()) { + if (format.getValue().equals(value)) { + return format; + } + } + return RAW; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/NodeServiceInstance.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/NodeServiceInstance.java new file mode 100644 index 00000000..4a645915 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/NodeServiceInstance.java @@ -0,0 +1,139 @@ +/*- + * ============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.so.aaisimulator.models; + +import java.io.Serializable; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class NodeServiceInstance implements Serializable { + + private static final long serialVersionUID = -3314166327618070948L; + + private String globalCustomerId; + private String serviceType; + private String serviceInstanceId; + private String resourceType; + private String resourceLink; + + public NodeServiceInstance() {} + + + public NodeServiceInstance(final String globalCustomerId, final String serviceType, final String serviceInstanceId, + final String resourceType, final String resourceLink) { + this.globalCustomerId = globalCustomerId; + this.serviceType = serviceType; + this.serviceInstanceId = serviceInstanceId; + this.resourceType = resourceType; + this.resourceLink = resourceLink; + } + + + /** + * @return the globalCustomerId + */ + public String getGlobalCustomerId() { + return globalCustomerId; + } + + + /** + * @param globalCustomerId the globalCustomerId to set + */ + public void setGlobalCustomerId(final String globalCustomerId) { + this.globalCustomerId = globalCustomerId; + } + + + /** + * @return the serviceType + */ + public String getServiceType() { + return serviceType; + } + + + /** + * @param serviceType the serviceType to set + */ + public void setServiceType(final String serviceType) { + this.serviceType = serviceType; + } + + + /** + * @return the serviceInstanceId + */ + public String getServiceInstanceId() { + return serviceInstanceId; + } + + + /** + * @param serviceInstanceId the serviceInstanceId to set + */ + public void setServiceInstanceId(final String serviceInstanceId) { + this.serviceInstanceId = serviceInstanceId; + } + + + /** + * @return the resourceType + */ + public String getResourceType() { + return resourceType; + } + + + /** + * @param resourceType the resourceType to set + */ + public void setResourceType(final String resourceType) { + this.resourceType = resourceType; + } + + + /** + * @return the resourceLink + */ + public String getResourceLink() { + return resourceLink; + } + + + /** + * @param resourceLink the resourceLink to set + */ + public void setResourceLink(final String resourceLink) { + this.resourceLink = resourceLink; + } + + + @Override + public String toString() { + return "NodeServiceInstance [globalCustomerId=" + globalCustomerId + ", serviceType=" + serviceType + + ", serviceInstanceId=" + serviceInstanceId + ", resourceType=" + resourceType + ", resourceLink=" + + resourceLink + "]"; + } + + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/Result.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/Result.java new file mode 100644 index 00000000..437aaf06 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/Result.java @@ -0,0 +1,64 @@ +/*- + * ============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.so.aaisimulator.models; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonRootName; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@JsonRootName(value = "result") +public class Result { + + private List> values = new ArrayList<>(); + + public Result() {} + + public Result(final Map value) { + this.values.add(value); + } + + /** + * @return the values + */ + public List> getValues() { + return values; + } + + /** + * @param values the values to set + */ + public void setValues(final List> values) { + this.values = values; + } + + + @JsonIgnore + @Override + public String toString() { + return "Result [values=" + values + "]"; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/AbstractCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/AbstractCacheServiceProvider.java new file mode 100644 index 00000000..35e35917 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/AbstractCacheServiceProvider.java @@ -0,0 +1,55 @@ +/*- + * ============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.so.aaisimulator.service.providers; + +import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public abstract class AbstractCacheServiceProvider { + + private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); + + private final CacheManager cacheManager; + + public AbstractCacheServiceProvider(final CacheManager cacheManager) { + this.cacheManager = cacheManager; + } + + protected void clearCahce(final String name) { + final Cache cache = cacheManager.getCache(name); + if (cache != null) { + final ConcurrentHashMap nativeCache = (ConcurrentHashMap) cache.getNativeCache(); + LOGGER.info("Clear all entries from cahce: {}", cache.getName()); + nativeCache.clear(); + } + } + + protected Cache getCache(final String name) { + return cacheManager.getCache(name); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java new file mode 100644 index 00000000..32d5ca0b --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java @@ -0,0 +1,57 @@ +/*- + * ============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.so.aaisimulator.service.providers; + +import java.util.Optional; +import org.onap.aai.domain.yang.Customer; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.aai.domain.yang.ServiceInstances; +import org.onap.aai.domain.yang.ServiceSubscription; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public interface CustomerCacheServiceProvider { + + Optional getCustomer(final String globalCustomerId); + + void putCustomer(final String globalCustomerId, final Customer customer); + + Optional getServiceSubscription(final String globalCustomerId, final String serviceType); + + boolean putServiceSubscription(final String globalCustomerId, final String serviceType, + final ServiceSubscription serviceSubscription); + + Optional getServiceInstances(final String globalCustomerId, final String serviceType, + final String serviceInstanceName); + + Optional getServiceInstance(final String globalCustomerId, final String serviceType, + final String serviceInstanceId); + + boolean putServiceInstance(final String globalCustomerId, final String serviceType, final String serviceInstanceId, + final ServiceInstance serviceInstance); + + boolean patchServiceInstance(final String globalCustomerId, final String serviceType, + final String serviceInstanceId, final ServiceInstance serviceInstance); + + void clearAll(); + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java new file mode 100644 index 00000000..374737ec --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java @@ -0,0 +1,232 @@ +/*- + * ============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.so.aaisimulator.service.providers; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import org.onap.aai.domain.yang.Customer; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.aai.domain.yang.ServiceInstances; +import org.onap.aai.domain.yang.ServiceSubscription; +import org.onap.aai.domain.yang.ServiceSubscriptions; +import org.onap.so.aaisimulator.utils.Constants; +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; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Service +public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvider + implements CustomerCacheServiceProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(CustomerCacheServiceProviderImpl.class); + + + @Autowired + public CustomerCacheServiceProviderImpl(final CacheManager cacheManager) { + super(cacheManager); + } + + @Override + public Optional getCustomer(final String globalCustomerId) { + LOGGER.info("getting customer from cache using key: {}", globalCustomerId); + final Cache cache = getCache(Constants.CUSTOMER_CACHE); + final Customer value = cache.get(globalCustomerId, Customer.class); + if (value != null) { + return Optional.of(value); + } + return Optional.empty(); + } + + @Override + public void putCustomer(final String globalCustomerId, final Customer customer) { + LOGGER.info("Adding customer: {} with key: {} in cache ...", customer, globalCustomerId); + final Cache cache = getCache(Constants.CUSTOMER_CACHE); + + cache.put(globalCustomerId, customer); + } + + @Override + public Optional getServiceSubscription(final String globalCustomerId, + final String serviceType) { + LOGGER.info("getting service subscription from cache for globalCustomerId: {} and serviceType: {}", + globalCustomerId, serviceType); + + final Cache cache = getCache(Constants.CUSTOMER_CACHE); + + final Customer value = cache.get(globalCustomerId, Customer.class); + + if (value != null) { + return Optional.ofNullable(value.getServiceSubscriptions().getServiceSubscription().stream() + .filter(s -> serviceType.equals(s.getServiceType())).findFirst().orElse(null)); + } + return Optional.empty(); + + } + + @Override + public Optional getServiceInstances(final String globalCustomerId, final String serviceType, + final String serviceInstanceName) { + + final Cache cache = getCache(Constants.CUSTOMER_CACHE); + final Customer value = cache.get(globalCustomerId, Customer.class); + + if (value != null) { + final Optional serviceSubscription = value.getServiceSubscriptions() + .getServiceSubscription().stream().filter(s -> serviceType.equals(s.getServiceType())).findFirst(); + + if (serviceSubscription.isPresent()) { + LOGGER.info("Found service subscription ..."); + final List serviceInstancesList = serviceSubscription.get().getServiceInstances() + .getServiceInstance().stream() + .filter(serviceInstance -> serviceInstanceName.equals(serviceInstance.getServiceInstanceName())) + .collect(Collectors.toList()); + if (serviceInstancesList != null && !serviceInstancesList.isEmpty()) { + LOGGER.info("Found {} service instances ", serviceInstancesList.size()); + final ServiceInstances serviceInstances = new ServiceInstances(); + serviceInstances.getServiceInstance().addAll(serviceInstancesList); + return Optional.of(serviceInstances); + + } + } + } + return Optional.empty(); + } + + @Override + public Optional getServiceInstance(final String globalCustomerId, final String serviceType, + final String serviceInstanceId) { + final Cache cache = getCache(Constants.CUSTOMER_CACHE); + final Customer value = cache.get(globalCustomerId, Customer.class); + + if (value != null) { + final Optional serviceSubscription = value.getServiceSubscriptions() + .getServiceSubscription().stream().filter(s -> serviceType.equals(s.getServiceType())).findFirst(); + + if (serviceSubscription.isPresent()) { + LOGGER.info("Found service subscription ..."); + final ServiceInstances serviceInstances = serviceSubscription.get().getServiceInstances(); + if (serviceInstances != null) { + return Optional.ofNullable(serviceInstances.getServiceInstance().stream() + .filter(serviceInstance -> serviceInstanceId.equals(serviceInstance.getServiceInstanceId())) + .findFirst().orElse(null)); + } + + } + } + return Optional.empty(); + } + + @Override + public boolean putServiceInstance(final String globalCustomerId, final String serviceType, + final String serviceInstanceId, final ServiceInstance serviceInstance) { + LOGGER.info("Adding serviceInstance: {} in cache ...", serviceInstance, globalCustomerId); + + final Cache cache = getCache(Constants.CUSTOMER_CACHE); + final Customer value = cache.get(globalCustomerId, Customer.class); + + if (value != null) { + final Optional serviceSubscription = value.getServiceSubscriptions() + .getServiceSubscription().stream().filter(s -> serviceType.equals(s.getServiceType())).findFirst(); + + if (serviceSubscription.isPresent()) { + final ServiceInstances serviceInstances = getServiceInstances(serviceSubscription); + + + if (!serviceInstances.getServiceInstance().stream() + .filter(existing -> serviceInstanceId.equals(existing.getServiceInstanceId())).findFirst() + .isPresent()) { + return serviceInstances.getServiceInstance().add(serviceInstance); + } + LOGGER.error("Service {} already exists ....", serviceInstanceId); + return false; + } + LOGGER.error("Couldn't find service subscription with serviceType: {} in cache ", serviceType); + return false; + } + LOGGER.error("Couldn't find Customer with key: {} in cache ", globalCustomerId); + return false; + } + + @Override + public boolean putServiceSubscription(final String globalCustomerId, final String serviceType, + final ServiceSubscription serviceSubscription) { + + final Optional customerOptional = getCustomer(globalCustomerId); + + if (customerOptional.isPresent()) { + final Customer customer = customerOptional.get(); + if (customer.getServiceSubscriptions() == null) { + final ServiceSubscriptions serviceSubscriptions = new ServiceSubscriptions(); + customer.setServiceSubscriptions(serviceSubscriptions); + return serviceSubscriptions.getServiceSubscription().add(serviceSubscription); + } + + final Optional serviceSubscriptionOptional = customer.getServiceSubscriptions() + .getServiceSubscription().stream().filter(s -> serviceType.equals(s.getServiceType())).findFirst(); + + if (!serviceSubscriptionOptional.isPresent()) { + return customer.getServiceSubscriptions().getServiceSubscription().add(serviceSubscription); + } + LOGGER.error("ServiceSubscription already exists {}", serviceSubscriptionOptional.get().getServiceType()); + return false; + } + LOGGER.error("Unable to add ServiceSubscription to cache becuase customer does not exits ..."); + return false; + } + + @Override + public boolean patchServiceInstance(final String globalCustomerId, final String serviceType, + final String serviceInstanceId, final ServiceInstance serviceInstance) { + final Optional instance = getServiceInstance(globalCustomerId, serviceType, serviceInstanceId); + if (instance.isPresent()) { + final ServiceInstance cachedServiceInstance = instance.get(); + LOGGER.info("Changing OrchestrationStatus from {} to {} ", cachedServiceInstance.getOrchestrationStatus(), + serviceInstance.getOrchestrationStatus()); + cachedServiceInstance.setOrchestrationStatus(serviceInstance.getOrchestrationStatus()); + return true; + } + LOGGER.error("Unable to find ServiceInstance ..."); + return false; + } + + private ServiceInstances getServiceInstances(final Optional optional) { + final ServiceSubscription serviceSubscription = optional.get(); + final ServiceInstances serviceInstances = serviceSubscription.getServiceInstances(); + if (serviceInstances == null) { + final ServiceInstances instances = new ServiceInstances(); + serviceSubscription.setServiceInstances(instances); + return instances; + } + return serviceInstances; + } + + @Override + public void clearAll() { + clearCahce(Constants.CUSTOMER_CACHE); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProvider.java new file mode 100644 index 00000000..0dbd45eb --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProvider.java @@ -0,0 +1,37 @@ +/*- + * ============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.so.aaisimulator.service.providers; + +import java.util.Optional; +import org.onap.so.aaisimulator.models.NodeServiceInstance; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public interface NodesCacheServiceProvider { + + void putNodeServiceInstance(final String serviceInstanceId, final NodeServiceInstance nodeServiceInstance); + + Optional getNodeServiceInstance(final String serviceInstanceId); + + void clearAll(); + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java new file mode 100644 index 00000000..7e8450f7 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java @@ -0,0 +1,73 @@ +/*- + * ============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.so.aaisimulator.service.providers; + +import static org.onap.so.aaisimulator.utils.Constants.NODES_CACHE; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import org.onap.so.aaisimulator.models.NodeServiceInstance; +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; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Service +public class NodesCacheServiceProviderImpl extends AbstractCacheServiceProvider implements NodesCacheServiceProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(NodesCacheServiceProviderImpl.class); + + + @Autowired + public NodesCacheServiceProviderImpl(final CacheManager cacheManager) { + super(cacheManager); + } + + @Override + public void putNodeServiceInstance(final String serviceInstanceId, final NodeServiceInstance nodeServiceInstance) { + final Cache cache = getCache(NODES_CACHE); + LOGGER.info("Adding {} to cache with key: {}...", nodeServiceInstance, serviceInstanceId); + cache.put(serviceInstanceId, nodeServiceInstance); + } + + @Override + public Optional getNodeServiceInstance(final String serviceInstanceId) { + final Cache cache = getCache(NODES_CACHE); + final NodeServiceInstance value = cache.get(serviceInstanceId, NodeServiceInstance.class); + if (value != null) { + return Optional.of(value); + } + LOGGER.error("Unable to find node service instance in cache using key:{} ", serviceInstanceId); + return Optional.empty(); + } + + @Override + public void clearAll() { + final Cache cache = getCache(NODES_CACHE); + final ConcurrentHashMap nativeCache = (ConcurrentHashMap) cache.getNativeCache(); + LOGGER.info("Clear all entries from cahce: {}", cache.getName()); + nativeCache.clear(); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProvider.java new file mode 100644 index 00000000..e34aa70a --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProvider.java @@ -0,0 +1,39 @@ +/*- + * ============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.so.aaisimulator.service.providers; + +import java.util.Optional; +import org.onap.aai.domain.yang.OwningEntity; +import org.onap.aai.domain.yang.Relationship; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public interface OwnEntityCacheServiceProvider { + + void putOwningEntity(final String owningEntityId, final OwningEntity owningEntity); + + Optional getOwningEntity(final String owningEntityId); + + boolean putOwningEntityRelationShip(String owningEntityId, Relationship relationship); + + void clearAll(); +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java new file mode 100644 index 00000000..32590cb0 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java @@ -0,0 +1,98 @@ +/*- + * ============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.so.aaisimulator.service.providers; + +import static org.onap.so.aaisimulator.utils.Constants.OWNING_ENTITY_CACHE; +import static org.onap.so.aaisimulator.utils.Constants.SERVICE_RESOURCE_TYPE; +import java.util.Optional; +import org.onap.aai.domain.yang.OwningEntity; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipList; +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; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Service +public class OwnEntityCacheServiceProviderImpl extends AbstractCacheServiceProvider + implements OwnEntityCacheServiceProvider { + + private static final Logger LOGGER = LoggerFactory.getLogger(OwnEntityCacheServiceProviderImpl.class); + private static final String RELATIONSHIPS_LABEL = "org.onap.relationships.inventory.BelongsTo"; + + @Autowired + public OwnEntityCacheServiceProviderImpl(final CacheManager cacheManager) { + super(cacheManager); + } + + @Override + public void putOwningEntity(final String owningEntityId, final OwningEntity owningEntity) { + LOGGER.info("Adding OwningEntity: {} with name to cache", owningEntityId, owningEntity); + final Cache cache = getCache(OWNING_ENTITY_CACHE); + cache.put(owningEntityId, owningEntity); + } + + @Override + public Optional getOwningEntity(final String owningEntityId) { + LOGGER.info("getting OwningEntity from cache using key: {}", owningEntityId); + final Cache cache = getCache(OWNING_ENTITY_CACHE); + final OwningEntity value = cache.get(owningEntityId, OwningEntity.class); + if (value != null) { + return Optional.of(value); + } + return Optional.empty(); + } + + @Override + public boolean putOwningEntityRelationShip(final String owningEntityId, final Relationship relationship) { + final Cache cache = getCache(OWNING_ENTITY_CACHE); + final OwningEntity value = cache.get(owningEntityId, OwningEntity.class); + if (value != null) { + RelationshipList relationshipList = value.getRelationshipList(); + if (relationshipList == null) { + relationshipList = new RelationshipList(); + value.setRelationshipList(relationshipList); + } + + if (relationship.getRelatedTo() == null) { + relationship.setRelatedTo(SERVICE_RESOURCE_TYPE); + } + if (relationship.getRelationshipLabel() == null) { + relationship.setRelationshipLabel(RELATIONSHIPS_LABEL); + } + + return relationshipList.getRelationship().add(relationship); + } + LOGGER.error("OwningEntity not found in cache for {}", owningEntityId); + return false; + } + + @Override + public void clearAll() { + clearCahce(OWNING_ENTITY_CACHE); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProvider.java new file mode 100644 index 00000000..60f763c7 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProvider.java @@ -0,0 +1,39 @@ +/*- + * ============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.so.aaisimulator.service.providers; + +import java.util.Optional; +import org.onap.aai.domain.yang.Project; +import org.onap.aai.domain.yang.Relationship; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public interface ProjectCacheServiceProvider { + + void putProject(final String projectName, final Project project); + + Optional getProject(final String projectName); + + boolean putProjectRelationShip(final String projectName, final Relationship relationship); + + void clearAll(); +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java new file mode 100644 index 00000000..047a3881 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java @@ -0,0 +1,101 @@ +/*- + * ============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.so.aaisimulator.service.providers; + +import static org.onap.so.aaisimulator.utils.Constants.PROJECT_CACHE; +import static org.onap.so.aaisimulator.utils.Constants.SERVICE_RESOURCE_TYPE; +import java.util.Optional; +import org.onap.aai.domain.yang.Project; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipList; +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; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Service +public class ProjectCacheServiceProviderImpl extends AbstractCacheServiceProvider + implements ProjectCacheServiceProvider { + + private static final String RELATIONSHIPS_LABEL = "org.onap.relationships.inventory.Uses"; + + private static final Logger LOGGER = LoggerFactory.getLogger(ProjectCacheServiceProviderImpl.class); + + + @Autowired + public ProjectCacheServiceProviderImpl(final CacheManager cacheManager) { + super(cacheManager); + } + + @Override + public void putProject(final String projectName, final Project project) { + LOGGER.info("Adding project: {} with name to cache", project, projectName); + final Cache cache = getCache(PROJECT_CACHE); + cache.put(projectName, project); + } + + + @Override + public Optional getProject(final String projectName) { + LOGGER.info("getting project from cache using key: {}", projectName); + final Cache cache = getCache(PROJECT_CACHE); + final Project value = cache.get(projectName, Project.class); + if (value != null) { + return Optional.of(value); + } + return Optional.empty(); + } + + @Override + public boolean putProjectRelationShip(final String projectName, final Relationship relationship) { + final Cache cache = getCache(PROJECT_CACHE); + final Project value = cache.get(projectName, Project.class); + if (value != null) { + RelationshipList relationshipList = value.getRelationshipList(); + if (relationshipList == null) { + relationshipList = new RelationshipList(); + value.setRelationshipList(relationshipList); + } + + if (relationship.getRelatedTo() == null) { + relationship.setRelatedTo(SERVICE_RESOURCE_TYPE); + } + if (relationship.getRelationshipLabel() == null) { + relationship.setRelationshipLabel(RELATIONSHIPS_LABEL); + } + + return relationshipList.getRelationship().add(relationship); + } + LOGGER.error("Project not found in cache for {}", projectName); + return false; + + } + + @Override + public void clearAll() { + clearCahce(PROJECT_CACHE); + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java new file mode 100644 index 00000000..f81d6bd1 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java @@ -0,0 +1,68 @@ +/*- + * ============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.so.aaisimulator.utils; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class Constants { + + public static final String BASE_URL = "/aai/v15"; + + public static final String NODES_URL = BASE_URL + "/nodes"; + + public static final String BUSINESS_URL = BASE_URL + "/business"; + + public static final String CUSTOMER_URL = BUSINESS_URL + "/customers/customer/"; + + public static final String PROJECT_URL = BUSINESS_URL + "/projects/project/"; + + public static final String OWNING_ENTITY_URL = BUSINESS_URL + "/owning-entities/owning-entity"; + + public static final String HEALTHY = "healthy"; + + public static final String CUSTOMER_CACHE = "customer-cache"; + + public static final String PROJECT_CACHE = "project-cache"; + + public static final String NODES_CACHE = "nodes-cache"; + + public static final String OWNING_ENTITY_CACHE = "owning-entity-cache"; + + public static final String PROJECT = "project"; + + public static final String OWNING_ENTITY = "owning-entity"; + + public static final String X_HTTP_METHOD_OVERRIDE = "X-HTTP-Method-Override"; + + public static final String ERROR_MESSAGE_ID = "SVC3001"; + + public static final String ERROR_MESSAGE = "Resource not found for %1 using id %2 (msg=%3) (ec=%4)"; + + public static final String SERVICE_RESOURCE_TYPE = "service-instance"; + + public static final String RESOURCE_LINK = "resource-link"; + + public static final String RESOURCE_TYPE = "resource-type"; + + private Constants() {} + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/RequestError.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/RequestError.java new file mode 100644 index 00000000..782625f7 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/RequestError.java @@ -0,0 +1,59 @@ +/*- + * ============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.so.aaisimulator.utils; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@XmlRootElement(name = "requestError") +@XmlAccessorType(XmlAccessType.FIELD) +public class RequestError { + + @XmlElement(name = "serviceException") + private ServiceException serviceException; + + /** + * @return the serviceException + */ + public ServiceException getServiceException() { + return serviceException; + } + + /** + * @param serviceException the serviceException to set + */ + public void setServiceException(final ServiceException serviceException) { + this.serviceException = serviceException; + } + + @Override + public String toString() { + return "RequestError [serviceException=" + serviceException + "]"; + } + + + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/RequestErrorBuilder.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/RequestErrorBuilder.java new file mode 100644 index 00000000..f3742220 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/RequestErrorBuilder.java @@ -0,0 +1,59 @@ +/*- + * ============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.so.aaisimulator.utils; + +import java.util.Arrays; +import java.util.List; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class RequestErrorBuilder { + + private final ServiceException serviceException = new ServiceException(); + + public RequestErrorBuilder messageId(final String messageId) { + this.serviceException.setMessageId(messageId); + return this; + } + + public RequestErrorBuilder text(final String text) { + this.serviceException.setText(text); + return this; + } + + public RequestErrorBuilder variables(final List variables) { + this.serviceException.setVariables(variables); + return this; + } + + public RequestErrorBuilder variables(final String... variables) { + this.serviceException.setVariables(Arrays.asList(variables)); + return this; + } + + public RequestError build() { + final RequestError requestError = new RequestError(); + requestError.setServiceException(serviceException); + return requestError; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/ServiceException.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/ServiceException.java new file mode 100644 index 00000000..7ba47fa7 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/ServiceException.java @@ -0,0 +1,88 @@ +/*- + * ============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.so.aaisimulator.utils; + +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@XmlRootElement(name = "serviceException") +@XmlAccessorType(XmlAccessType.FIELD) +public class ServiceException { + + private String messageId; + + private String text; + + private List variables; + + /** + * @return the messageId + */ + public String getMessageId() { + return messageId; + } + + /** + * @param messageId the messageId to set + */ + public void setMessageId(final String messageId) { + this.messageId = messageId; + } + + /** + * @return the text + */ + public String getText() { + return text; + } + + /** + * @param text the text to set + */ + public void setText(final String text) { + this.text = text; + } + + /** + * @return the variables + */ + public List getVariables() { + return variables; + } + + /** + * @param variables the variables to set + */ + public void setVariables(final List variables) { + this.variables = variables; + } + + @Override + public String toString() { + return "ServiceException [messageId=" + messageId + ", text=" + text + ", variables=" + variables + "]"; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Utils.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Utils.java new file mode 100644 index 00000000..1963728c --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Utils.java @@ -0,0 +1,58 @@ +/*- + * ============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.so.aaisimulator.utils; + +import static org.onap.so.aaisimulator.utils.Constants.ERROR_MESSAGE; +import static org.onap.so.aaisimulator.utils.Constants.ERROR_MESSAGE_ID; +import javax.servlet.http.HttpServletRequest; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class Utils { + + private static final String EMPTY_STRING = ""; + + public static final String getResourceVersion() { + return System.currentTimeMillis() + EMPTY_STRING; + } + + public static ResponseEntity getRequestErrorResponseEntity(final HttpServletRequest request, + final String nodeType) { + return new ResponseEntity<>( + new RequestErrorBuilder().messageId(ERROR_MESSAGE_ID).text(ERROR_MESSAGE) + .variables(request.getMethod(), request.getRequestURI(), "Node Not Found:No Node of " + nodeType + + " service-instance found at: " + request.getRequestURI(), "ERR.5.4.6114") + .build(), + HttpStatus.NOT_FOUND); + } + + + public static ResponseEntity getRequestErrorResponseEntity(final HttpServletRequest request) { + return getRequestErrorResponseEntity(request, Constants.SERVICE_RESOURCE_TYPE); + } + + + private Utils() {} + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/AaiSimulatorControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/AaiSimulatorControllerTest.java deleted file mode 100644 index 59d3a556..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/AaiSimulatorControllerTest.java +++ /dev/null @@ -1,64 +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.so.aai.simulator.controller; - -import static org.junit.Assert.assertEquals; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.so.aai.simulator.utils.Constants; -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 + Constants.BASE_URL; - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/BusinessControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/BusinessControllerTest.java deleted file mode 100644 index ed9a129d..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/BusinessControllerTest.java +++ /dev/null @@ -1,398 +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.so.aai.simulator.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.so.aai.simulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; -import static org.onap.so.aai.simulator.utils.TestConstants.CUSTOMERS_URL; -import static org.onap.so.aai.simulator.utils.TestConstants.GLOBAL_CUSTOMER_ID; -import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_INSTANCES_URL; -import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_INSTANCE_ID; -import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_INSTANCE_URL; -import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_NAME; -import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; -import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_TYPE; -import static org.onap.so.aai.simulator.utils.TestUtils.getJsonString; -import java.io.IOException; -import java.util.Optional; -import java.util.UUID; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.aai.domain.yang.Customer; -import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aai.domain.yang.ServiceInstances; -import org.onap.aai.domain.yang.ServiceSubscription; -import org.onap.so.aai.simulator.service.providers.CustomerCacheServiceProvider; -import org.onap.so.aai.simulator.utils.Constants; -import org.onap.so.aai.simulator.utils.RequestError; -import org.onap.so.aai.simulator.utils.ServiceException; -import org.onap.so.aai.simulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -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.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -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 BusinessControllerTest { - - private static final String FIREWALL_SERVICE_TTYPE = "Firewall"; - - private static final String ORCHESTRATION_STATUS = "Active"; - - @LocalServerPort - private int port; - - @Autowired - private TestRestTemplate restTemplate; - - @Value("${spring.security.username}") - private String username; - - @Autowired - private CustomerCacheServiceProvider cacheServiceProvider; - - @After - public void after() { - cacheServiceProvider.clearAll(); - } - - @Test - public void test_putCustomer_successfullyAddedToCache() throws Exception { - final ResponseEntity actual = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); - - assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - assertTrue(cacheServiceProvider.getCustomer(GLOBAL_CUSTOMER_ID).isPresent()); - } - - @Test - public void test_getCustomer_ableToRetrieveCustomer() throws Exception { - final String url = getCustomerEndPointUrl(); - - invokeHttpPut(url, getCustomer()); - - final ResponseEntity actual = - restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), 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 = getCustomerEndPointUrl(); - - final ResponseEntity actual = - restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), RequestError.class); - - assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); - - final RequestError actualError = actual.getBody(); - final ServiceException serviceException = actualError.getServiceException(); - - assertNotNull(serviceException); - assertEquals(Constants.ERROR_MESSAGE_ID, serviceException.getMessageId()); - assertEquals(Constants.ERROR_MESSAGE, serviceException.getText()); - assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString())); - - } - - @Test - public void test_getServiceSubscription_ableToRetrieveServiceSubscriptionFromCache() throws Exception { - final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL; - - invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); - - final ResponseEntity actual = restTemplate.exchange(url, HttpMethod.GET, - new HttpEntity<>(getHttpHeaders()), 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 { - - final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; - - final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); - - assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - - invokeHttpPut(url, getServiceInstance()); - - 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 { - - final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; - - final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); - - assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - - invokeHttpPut(url, getServiceInstance()); - - final String serviceInstanceUrl = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCES_URL - + "?service-instance-name=" + SERVICE_NAME; - - final ResponseEntity actual = restTemplate.exchange(serviceInstanceUrl, HttpMethod.GET, - new HttpEntity<>(getHttpHeaders()), 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_usingServiceInstanceId_ableToRetrieveServiceInstanceFromCache() - throws Exception { - - final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; - - final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); - - assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - - invokeHttpPut(url, getServiceInstance()); - - final ResponseEntity actual = - restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), 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 { - - final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; - - final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); - - assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - - invokeHttpPut(url, getServiceInstance()); - - final String invalidServiceInstanceUrl = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL - + SERVICE_INSTANCES_URL + "/service-instance/" + UUID.randomUUID(); - - final ResponseEntity actual = restTemplate.exchange(invalidServiceInstanceUrl, HttpMethod.GET, - new HttpEntity<>(getHttpHeaders()), RequestError.class); - - assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); - - final RequestError actualError = actual.getBody(); - final ServiceException serviceException = actualError.getServiceException(); - - assertNotNull(serviceException); - assertEquals(Constants.ERROR_MESSAGE_ID, serviceException.getMessageId()); - assertEquals(Constants.ERROR_MESSAGE, serviceException.getText()); - assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString())); - - } - - @Test - public void test_getSericeInstance_usingInvalidServiceInstanceName_shouldReturnError() throws Exception { - - final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; - - final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); - - assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - - final ResponseEntity putRequestReponse = invokeHttpPut(url, getServiceInstance()); - assertEquals(HttpStatus.ACCEPTED, putRequestReponse.getStatusCode()); - - - final String serviceInstanceUrl = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCES_URL - + "?service-instance-name=Dummy&depth=2"; - - final ResponseEntity actual = restTemplate.exchange(serviceInstanceUrl, HttpMethod.GET, - new HttpEntity<>(getHttpHeaders()), RequestError.class); - - assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); - - final RequestError actualError = actual.getBody(); - final ServiceException serviceException = actualError.getServiceException(); - - assertNotNull(serviceException); - assertEquals(Constants.ERROR_MESSAGE_ID, serviceException.getMessageId()); - assertEquals(Constants.ERROR_MESSAGE, serviceException.getText()); - assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString())); - - } - - @Test - public void test_PathSericeInstance_usingServiceInstanceId_OrchStatusChangedInCache() throws Exception { - - final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; - - final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); - - assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - - final ResponseEntity serviceInstancePutResponse = invokeHttpPut(url, getServiceInstance()); - assertEquals(HttpStatus.ACCEPTED, serviceInstancePutResponse.getStatusCode()); - - final HttpHeaders httpHeaders = getHttpHeaders(); - httpHeaders.add(X_HTTP_METHOD_OVERRIDE, HttpMethod.PATCH.toString()); - - final HttpEntity orchStatuUpdateServiceInstance = - getHttpEntity(getOrchStatuUpdateServiceInstance(), httpHeaders); - - final ResponseEntity orchStatuUpdateServiceInstanceResponse = - invokeHttpPost(orchStatuUpdateServiceInstance, url, getOrchStatuUpdateServiceInstance()); - - assertEquals(HttpStatus.ACCEPTED, orchStatuUpdateServiceInstanceResponse.getStatusCode()); - - - final ResponseEntity actual = - restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), 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 = - getCustomerEndPointUrl() + "/service-subscriptions/service-subscription/" + FIREWALL_SERVICE_TTYPE; - - final ResponseEntity customerPutResponse = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); - assertEquals(HttpStatus.ACCEPTED, customerPutResponse.getStatusCode()); - - final ResponseEntity serviceSubscriptionPutResponse = - invokeHttpPut(serviceSubscriptionurl, getServiceSubscription()); - assertEquals(HttpStatus.ACCEPTED, serviceSubscriptionPutResponse.getStatusCode()); - - final ResponseEntity actual = restTemplate.exchange(serviceSubscriptionurl, HttpMethod.GET, - new HttpEntity<>(getHttpHeaders()), ServiceSubscription.class); - - assertEquals(HttpStatus.OK, actual.getStatusCode()); - assertTrue(actual.hasBody()); - - final ServiceSubscription actualServiceSubscription = actual.getBody(); - assertEquals(FIREWALL_SERVICE_TTYPE, actualServiceSubscription.getServiceType()); - - } - - private String getCustomer() throws Exception, IOException { - return getJsonString("test-data/business-customer.json"); - } - - private String getServiceSubscription() throws Exception, IOException { - return getJsonString("test-data/service-subscription.json"); - } - - - private String getCustomerEndPointUrl() { - return TestUtils.getBaseUrl(port) + CUSTOMERS_URL; - } - - private ResponseEntity invokeHttpPut(final String url, final Object obj) { - final HttpEntity httpEntity = getHttpEntity(obj); - return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Void.class); - } - - private ResponseEntity invokeHttpPost(final HttpEntity httpEntity, final String url, final Object obj) { - return restTemplate.exchange(url, HttpMethod.POST, httpEntity, Void.class); - } - - private HttpEntity getHttpEntity(final Object obj) { - return new HttpEntity<>(obj, getHttpHeaders()); - } - - private HttpEntity getHttpEntity(final Object obj, final HttpHeaders headers) { - return new HttpEntity<>(obj, headers); - } - - private HttpHeaders getHttpHeaders() { - return TestUtils.getHttpHeaders(username); - } - - private String getServiceInstance() throws Exception, IOException { - return getJsonString("test-data/service-instance.json"); - } - - private String getOrchStatuUpdateServiceInstance() throws Exception, IOException { - return getJsonString("test-data/service-instance-orch-status-update.json"); - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/NodesControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/NodesControllerTest.java deleted file mode 100644 index 5ea6dff0..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/NodesControllerTest.java +++ /dev/null @@ -1,180 +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.so.aai.simulator.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.so.aai.simulator.utils.Constants.RESOURCE_LINK; -import static org.onap.so.aai.simulator.utils.Constants.RESOURCE_TYPE; -import static org.onap.so.aai.simulator.utils.Constants.SERVICE_RESOURCE_TYPE; -import static org.onap.so.aai.simulator.utils.TestConstants.CUSTOMERS_URL; -import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_INSTANCE_ID; -import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_INSTANCE_URL; -import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_NAME; -import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; -import static org.onap.so.aai.simulator.utils.TestUtils.getJsonString; -import java.io.IOException; -import java.util.Map; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.so.aai.simulator.models.Format; -import org.onap.so.aai.simulator.models.Result; -import org.onap.so.aai.simulator.service.providers.CustomerCacheServiceProvider; -import org.onap.so.aai.simulator.service.providers.NodesCacheServiceProvider; -import org.onap.so.aai.simulator.utils.Constants; -import org.onap.so.aai.simulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -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.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -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 NodesControllerTest { - - @LocalServerPort - private int port; - - @Autowired - private TestRestTemplate restTemplate; - - @Value("${spring.security.username}") - private String username; - - @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 { - - final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; - - final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); - - assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - - final ResponseEntity response2 = invokeHttpPut(url, getServiceInstance()); - assertEquals(HttpStatus.ACCEPTED, response2.getStatusCode()); - - final ResponseEntity actual = - restTemplate.exchange(getNodesEndPointUrl() + SERVICE_INSTANCE_URL, HttpMethod.GET, - new HttpEntity<>(getHttpHeaders()), 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 { - - final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; - - final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); - - assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - - final ResponseEntity response2 = invokeHttpPut(url, getServiceInstance()); - assertEquals(HttpStatus.ACCEPTED, response2.getStatusCode()); - - final ResponseEntity actual = restTemplate.exchange( - getNodesEndPointUrl() + SERVICE_INSTANCE_URL + "?format=" + Format.PATHED.getValue(), HttpMethod.GET, - new HttpEntity<>(getHttpHeaders()), Result.class); - - assertEquals(HttpStatus.OK, actual.getStatusCode()); - assertTrue(actual.hasBody()); - - final Result 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)); - - } - - private String getNodesEndPointUrl() { - return TestUtils.getBaseUrl(port) + Constants.NODES_URL; - } - - - private String getCustomerEndPointUrl() { - return TestUtils.getBaseUrl(port) + CUSTOMERS_URL; - } - - private String getCustomer() throws Exception, IOException { - return getJsonString("test-data/business-customer.json"); - } - - private String getServiceInstance() throws Exception, IOException { - return getJsonString("test-data/service-instance.json"); - } - - private ResponseEntity invokeHttpPut(final String url, final Object obj) { - final HttpEntity httpEntity = getHttpEntity(obj); - return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Void.class); - } - - private HttpEntity getHttpEntity(final Object obj) { - return new HttpEntity<>(obj, getHttpHeaders()); - } - - private HttpHeaders getHttpHeaders() { - return TestUtils.getHttpHeaders(username); - } -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/OwningEntityControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/OwningEntityControllerTest.java deleted file mode 100644 index bbb2cad7..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/OwningEntityControllerTest.java +++ /dev/null @@ -1,172 +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.so.aai.simulator.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.so.aai.simulator.utils.TestConstants.RELATIONSHIP_URL; -import static org.onap.so.aai.simulator.utils.TestUtils.getFile; -import static org.onap.so.aai.simulator.utils.TestUtils.getHttpHeaders; -import static org.onap.so.aai.simulator.utils.TestUtils.getJsonString; -import java.io.IOException; -import java.nio.file.Files; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.aai.domain.yang.OwningEntity; -import org.onap.so.aai.simulator.models.Format; -import org.onap.so.aai.simulator.models.Result; -import org.onap.so.aai.simulator.service.providers.OwnEntityCacheServiceProvider; -import org.onap.so.aai.simulator.utils.Constants; -import org.onap.so.aai.simulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -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.HttpEntity; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -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 OwningEntityControllerTest { - private static final String OWNING_ENTITY_JSON_FILE = "test-data/owning-entity.json"; - - private static final String OWN_ENTITY_ID_VALUE = "oe_1"; - private static final String OWN_ENTITY_NAME_VALUE = "oe_2"; - - private static final String OWNING_ENTITY_RELATION_SHIP_JSON_FILE = "test-data/owning-entity-relation-ship.json"; - - @LocalServerPort - private int port; - - @Autowired - private TestRestTemplate restTemplate; - - @Value("${spring.security.username}") - private String username; - - @Autowired - private OwnEntityCacheServiceProvider cacheServiceProvider; - - @After - public void after() { - cacheServiceProvider.clearAll(); - } - - @Test - public void test_putOwningEntity_successfullyAddedToCache() throws Exception { - final String url = getOwningEntityEndPointUrl() + "/" + OWN_ENTITY_ID_VALUE; - final String body = new String(Files.readAllBytes(getFile(OWNING_ENTITY_JSON_FILE).toPath())); - final ResponseEntity actual = invokeHttpPut(url, body); - - assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - - final ResponseEntity actualResponse = 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 = getOwningEntityEndPointUrl() + "/" + OWN_ENTITY_ID_VALUE; - final String body = new String(Files.readAllBytes(getFile(OWNING_ENTITY_JSON_FILE).toPath())); - final ResponseEntity actual = invokeHttpPut(url, body); - - assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - - final ResponseEntity actualResponse = - invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Result.class); - - assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); - assertTrue(actualResponse.hasBody()); - final Result 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 { - final String url = getOwningEntityEndPointUrl() + "/" + OWN_ENTITY_ID_VALUE; - final ResponseEntity actual = invokeHttpPut(url, getJsonString(OWNING_ENTITY_JSON_FILE)); - assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - - final String owningEntityRelationshipUrl = url + RELATIONSHIP_URL; - - final ResponseEntity putResponse = invokeHttpPut(owningEntityRelationshipUrl, getRelationship()); - - assertEquals(HttpStatus.ACCEPTED, putResponse.getStatusCode()); - - final ResponseEntity actualResponse = 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)); - - } - - private String getRelationship() throws IOException { - return TestUtils.getJsonString(OWNING_ENTITY_RELATION_SHIP_JSON_FILE); - } - - private ResponseEntity invokeHttpGet(final String url, final Class clazz) { - return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(username)), clazz); - } - - private ResponseEntity invokeHttpPut(final String url, final Object obj) { - final HttpEntity httpEntity = getHttpEntity(obj); - return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Void.class); - } - - private HttpEntity getHttpEntity(final Object obj) { - return new HttpEntity<>(obj, getHttpHeaders(username)); - } - - private String getOwningEntityEndPointUrl() { - return TestUtils.getBaseUrl(port) + Constants.OWNING_ENTITY_URL; - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/ProjectControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/ProjectControllerTest.java deleted file mode 100644 index ba6ad978..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/ProjectControllerTest.java +++ /dev/null @@ -1,169 +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.so.aai.simulator.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.so.aai.simulator.utils.TestUtils.getFile; -import static org.onap.so.aai.simulator.utils.TestUtils.getHttpHeaders; -import static org.onap.so.aai.simulator.utils.TestUtils.getJsonString; -import java.io.IOException; -import java.nio.file.Files; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.aai.domain.yang.Project; -import org.onap.so.aai.simulator.models.Result; -import org.onap.so.aai.simulator.service.providers.ProjectCacheServiceProvider; -import org.onap.so.aai.simulator.utils.Constants; -import org.onap.so.aai.simulator.utils.TestUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -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.HttpEntity; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -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 ProjectControllerTest { - - private static final String RELATIONSHIP_URL = "/relationship-list/relationship"; - - private static final String BUSINESS_PROJECT_JSON_FILE = "test-data/business-project.json"; - - private static final String PROJECT_RELATION_SHIP_JSON_FILE = "test-data/business-project-relation-ship.json"; - - private static final String PROJECT_NAME_VALUE = "PROJECT_NAME_VALUE"; - - @LocalServerPort - private int port; - - @Autowired - private TestRestTemplate restTemplate; - - @Value("${spring.security.username}") - private String username; - - @Autowired - private ProjectCacheServiceProvider cacheServiceProvider; - - @After - public void after() { - cacheServiceProvider.clearAll(); - } - - @Test - public void test_putProject_successfullyAddedToCache() throws Exception { - final String url = getProjectEndPointUrl() + "/" + PROJECT_NAME_VALUE; - final String body = new String(Files.readAllBytes(getFile(BUSINESS_PROJECT_JSON_FILE).toPath())); - final ResponseEntity actual = invokeHttpPut(url, body); - - assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - - final ResponseEntity actualResponse = 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 { - final String url = getProjectEndPointUrl() + "/" + PROJECT_NAME_VALUE; - final ResponseEntity actual = invokeHttpPut(url, getJsonString(BUSINESS_PROJECT_JSON_FILE)); - assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - - final String projectRelationshipUrl = url + RELATIONSHIP_URL; - - final ResponseEntity putResponse = invokeHttpPut(projectRelationshipUrl, getRelationship()); - - assertEquals(HttpStatus.ACCEPTED, putResponse.getStatusCode()); - - final ResponseEntity actualResponse = 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)); - - } - - @Test - public void test_getProjectCount_correctResult() throws Exception { - final String url = getProjectEndPointUrl() + "/" + PROJECT_NAME_VALUE; - final String body = new String(Files.readAllBytes(getFile(BUSINESS_PROJECT_JSON_FILE).toPath())); - final ResponseEntity actual = invokeHttpPut(url, body); - - assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - - final ResponseEntity actualResponse = - invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=count", Result.class); - - assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); - assertTrue(actualResponse.hasBody()); - final Result result = actualResponse.getBody(); - assertNotNull(result.getValues()); - assertFalse(result.getValues().isEmpty()); - assertEquals(1, result.getValues().get(0).get(Constants.PROJECT)); - } - - private ResponseEntity invokeHttpGet(final String url, final Class clazz) { - return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(username)), clazz); - } - - private ResponseEntity invokeHttpPut(final String url, final Object obj) { - final HttpEntity httpEntity = getHttpEntity(obj); - return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Void.class); - } - - private HttpEntity getHttpEntity(final Object obj) { - return new HttpEntity<>(obj, getHttpHeaders(username)); - } - - private String getProjectEndPointUrl() { - return TestUtils.getBaseUrl(port) + Constants.PROJECT_URL; - } - - private String getRelationship() throws IOException, Exception { - return TestUtils.getJsonString(PROJECT_RELATION_SHIP_JSON_FILE); - } -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/configuration/TestRestTemplateConfigration.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/configuration/TestRestTemplateConfigration.java deleted file mode 100644 index 6e8ccac6..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/configuration/TestRestTemplateConfigration.java +++ /dev/null @@ -1,71 +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.so.aai.simulator.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.http.client.HttpComponentsClientHttpRequestFactory; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@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; - - } - - 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/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestConstants.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestConstants.java deleted file mode 100644 index f57c946d..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestConstants.java +++ /dev/null @@ -1,50 +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.so.aai.simulator.utils; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public class TestConstants { - - 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 = Constants.CUSTOMER_URL + GLOBAL_CUSTOMER_ID; - - public static final String RELATIONSHIP_URL = "/relationship-list/relationship"; - - private TestConstants() {} - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestUtils.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestUtils.java deleted file mode 100644 index 73e43b10..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestUtils.java +++ /dev/null @@ -1,73 +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.so.aai.simulator.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 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; - } - - private TestUtils() {} - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AaiSimulatorControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AaiSimulatorControllerTest.java new file mode 100644 index 00000000..610aaa70 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AaiSimulatorControllerTest.java @@ -0,0 +1,64 @@ +/*- + * ============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.so.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.aaisimulator.utils.Constants; +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 + Constants.BASE_URL; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java new file mode 100644 index 00000000..478651cc --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java @@ -0,0 +1,398 @@ +/*- + * ============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.so.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.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; +import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.GLOBAL_CUSTOMER_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCES_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_TYPE; +import static org.onap.so.aaisimulator.utils.TestUtils.getJsonString; +import java.io.IOException; +import java.util.Optional; +import java.util.UUID; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.domain.yang.Customer; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.aai.domain.yang.ServiceInstances; +import org.onap.aai.domain.yang.ServiceSubscription; +import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider; +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.aaisimulator.utils.RequestError; +import org.onap.so.aaisimulator.utils.ServiceException; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +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.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +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 BusinessControllerTest { + + private static final String FIREWALL_SERVICE_TTYPE = "Firewall"; + + private static final String ORCHESTRATION_STATUS = "Active"; + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Value("${spring.security.username}") + private String username; + + @Autowired + private CustomerCacheServiceProvider cacheServiceProvider; + + @After + public void after() { + cacheServiceProvider.clearAll(); + } + + @Test + public void test_putCustomer_successfullyAddedToCache() throws Exception { + final ResponseEntity actual = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + assertTrue(cacheServiceProvider.getCustomer(GLOBAL_CUSTOMER_ID).isPresent()); + } + + @Test + public void test_getCustomer_ableToRetrieveCustomer() throws Exception { + final String url = getCustomerEndPointUrl(); + + invokeHttpPut(url, getCustomer()); + + final ResponseEntity actual = + restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), 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 = getCustomerEndPointUrl(); + + final ResponseEntity actual = + restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), RequestError.class); + + assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); + + final RequestError actualError = actual.getBody(); + final ServiceException serviceException = actualError.getServiceException(); + + assertNotNull(serviceException); + assertEquals(Constants.ERROR_MESSAGE_ID, serviceException.getMessageId()); + assertEquals(Constants.ERROR_MESSAGE, serviceException.getText()); + assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString())); + + } + + @Test + public void test_getServiceSubscription_ableToRetrieveServiceSubscriptionFromCache() throws Exception { + final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL; + + invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + + final ResponseEntity actual = restTemplate.exchange(url, HttpMethod.GET, + new HttpEntity<>(getHttpHeaders()), 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 { + + final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; + + final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + invokeHttpPut(url, getServiceInstance()); + + 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 { + + final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; + + final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + invokeHttpPut(url, getServiceInstance()); + + final String serviceInstanceUrl = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCES_URL + + "?service-instance-name=" + SERVICE_NAME; + + final ResponseEntity actual = restTemplate.exchange(serviceInstanceUrl, HttpMethod.GET, + new HttpEntity<>(getHttpHeaders()), 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_usingServiceInstanceId_ableToRetrieveServiceInstanceFromCache() + throws Exception { + + final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; + + final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + invokeHttpPut(url, getServiceInstance()); + + final ResponseEntity actual = + restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), 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 { + + final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; + + final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + invokeHttpPut(url, getServiceInstance()); + + final String invalidServiceInstanceUrl = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + + SERVICE_INSTANCES_URL + "/service-instance/" + UUID.randomUUID(); + + final ResponseEntity actual = restTemplate.exchange(invalidServiceInstanceUrl, HttpMethod.GET, + new HttpEntity<>(getHttpHeaders()), RequestError.class); + + assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); + + final RequestError actualError = actual.getBody(); + final ServiceException serviceException = actualError.getServiceException(); + + assertNotNull(serviceException); + assertEquals(Constants.ERROR_MESSAGE_ID, serviceException.getMessageId()); + assertEquals(Constants.ERROR_MESSAGE, serviceException.getText()); + assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString())); + + } + + @Test + public void test_getSericeInstance_usingInvalidServiceInstanceName_shouldReturnError() throws Exception { + + final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; + + final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + final ResponseEntity putRequestReponse = invokeHttpPut(url, getServiceInstance()); + assertEquals(HttpStatus.ACCEPTED, putRequestReponse.getStatusCode()); + + + final String serviceInstanceUrl = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCES_URL + + "?service-instance-name=Dummy&depth=2"; + + final ResponseEntity actual = restTemplate.exchange(serviceInstanceUrl, HttpMethod.GET, + new HttpEntity<>(getHttpHeaders()), RequestError.class); + + assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); + + final RequestError actualError = actual.getBody(); + final ServiceException serviceException = actualError.getServiceException(); + + assertNotNull(serviceException); + assertEquals(Constants.ERROR_MESSAGE_ID, serviceException.getMessageId()); + assertEquals(Constants.ERROR_MESSAGE, serviceException.getText()); + assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString())); + + } + + @Test + public void test_PathSericeInstance_usingServiceInstanceId_OrchStatusChangedInCache() throws Exception { + + final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; + + final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + final ResponseEntity serviceInstancePutResponse = invokeHttpPut(url, getServiceInstance()); + assertEquals(HttpStatus.ACCEPTED, serviceInstancePutResponse.getStatusCode()); + + final HttpHeaders httpHeaders = getHttpHeaders(); + httpHeaders.add(X_HTTP_METHOD_OVERRIDE, HttpMethod.PATCH.toString()); + + final HttpEntity orchStatuUpdateServiceInstance = + getHttpEntity(getOrchStatuUpdateServiceInstance(), httpHeaders); + + final ResponseEntity orchStatuUpdateServiceInstanceResponse = + invokeHttpPost(orchStatuUpdateServiceInstance, url, getOrchStatuUpdateServiceInstance()); + + assertEquals(HttpStatus.ACCEPTED, orchStatuUpdateServiceInstanceResponse.getStatusCode()); + + + final ResponseEntity actual = + restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), 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 = + getCustomerEndPointUrl() + "/service-subscriptions/service-subscription/" + FIREWALL_SERVICE_TTYPE; + + final ResponseEntity customerPutResponse = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + assertEquals(HttpStatus.ACCEPTED, customerPutResponse.getStatusCode()); + + final ResponseEntity serviceSubscriptionPutResponse = + invokeHttpPut(serviceSubscriptionurl, getServiceSubscription()); + assertEquals(HttpStatus.ACCEPTED, serviceSubscriptionPutResponse.getStatusCode()); + + final ResponseEntity actual = restTemplate.exchange(serviceSubscriptionurl, HttpMethod.GET, + new HttpEntity<>(getHttpHeaders()), ServiceSubscription.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final ServiceSubscription actualServiceSubscription = actual.getBody(); + assertEquals(FIREWALL_SERVICE_TTYPE, actualServiceSubscription.getServiceType()); + + } + + private String getCustomer() throws Exception, IOException { + return getJsonString("test-data/business-customer.json"); + } + + private String getServiceSubscription() throws Exception, IOException { + return getJsonString("test-data/service-subscription.json"); + } + + + private String getCustomerEndPointUrl() { + return TestUtils.getBaseUrl(port) + CUSTOMERS_URL; + } + + private ResponseEntity invokeHttpPut(final String url, final Object obj) { + final HttpEntity httpEntity = getHttpEntity(obj); + return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Void.class); + } + + private ResponseEntity invokeHttpPost(final HttpEntity httpEntity, final String url, final Object obj) { + return restTemplate.exchange(url, HttpMethod.POST, httpEntity, Void.class); + } + + private HttpEntity getHttpEntity(final Object obj) { + return new HttpEntity<>(obj, getHttpHeaders()); + } + + private HttpEntity getHttpEntity(final Object obj, final HttpHeaders headers) { + return new HttpEntity<>(obj, headers); + } + + private HttpHeaders getHttpHeaders() { + return TestUtils.getHttpHeaders(username); + } + + private String getServiceInstance() throws Exception, IOException { + return getJsonString("test-data/service-instance.json"); + } + + private String getOrchStatuUpdateServiceInstance() throws Exception, IOException { + return getJsonString("test-data/service-instance-orch-status-update.json"); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java new file mode 100644 index 00000000..59246f56 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java @@ -0,0 +1,180 @@ +/*- + * ============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.so.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.so.aaisimulator.utils.Constants.RESOURCE_LINK; +import static org.onap.so.aaisimulator.utils.Constants.RESOURCE_TYPE; +import static org.onap.so.aaisimulator.utils.Constants.SERVICE_RESOURCE_TYPE; +import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; +import static org.onap.so.aaisimulator.utils.TestUtils.getJsonString; +import java.io.IOException; +import java.util.Map; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Result; +import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider; +import org.onap.so.aaisimulator.service.providers.NodesCacheServiceProvider; +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +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.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +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 NodesControllerTest { + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Value("${spring.security.username}") + private String username; + + @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 { + + final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; + + final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + final ResponseEntity response2 = invokeHttpPut(url, getServiceInstance()); + assertEquals(HttpStatus.ACCEPTED, response2.getStatusCode()); + + final ResponseEntity actual = + restTemplate.exchange(getNodesEndPointUrl() + SERVICE_INSTANCE_URL, HttpMethod.GET, + new HttpEntity<>(getHttpHeaders()), 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 { + + final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; + + final ResponseEntity response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + final ResponseEntity response2 = invokeHttpPut(url, getServiceInstance()); + assertEquals(HttpStatus.ACCEPTED, response2.getStatusCode()); + + final ResponseEntity actual = restTemplate.exchange( + getNodesEndPointUrl() + SERVICE_INSTANCE_URL + "?format=" + Format.PATHED.getValue(), HttpMethod.GET, + new HttpEntity<>(getHttpHeaders()), Result.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final Result 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)); + + } + + private String getNodesEndPointUrl() { + return TestUtils.getBaseUrl(port) + Constants.NODES_URL; + } + + + private String getCustomerEndPointUrl() { + return TestUtils.getBaseUrl(port) + CUSTOMERS_URL; + } + + private String getCustomer() throws Exception, IOException { + return getJsonString("test-data/business-customer.json"); + } + + private String getServiceInstance() throws Exception, IOException { + return getJsonString("test-data/service-instance.json"); + } + + private ResponseEntity invokeHttpPut(final String url, final Object obj) { + final HttpEntity httpEntity = getHttpEntity(obj); + return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Void.class); + } + + private HttpEntity getHttpEntity(final Object obj) { + return new HttpEntity<>(obj, getHttpHeaders()); + } + + private HttpHeaders getHttpHeaders() { + return TestUtils.getHttpHeaders(username); + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java new file mode 100644 index 00000000..a443a458 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java @@ -0,0 +1,172 @@ +/*- + * ============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.so.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.so.aaisimulator.utils.TestConstants.RELATIONSHIP_URL; +import static org.onap.so.aaisimulator.utils.TestUtils.getFile; +import static org.onap.so.aaisimulator.utils.TestUtils.getHttpHeaders; +import static org.onap.so.aaisimulator.utils.TestUtils.getJsonString; +import java.io.IOException; +import java.nio.file.Files; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.domain.yang.OwningEntity; +import org.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Result; +import org.onap.so.aaisimulator.service.providers.OwnEntityCacheServiceProvider; +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +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.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +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 OwningEntityControllerTest { + private static final String OWNING_ENTITY_JSON_FILE = "test-data/owning-entity.json"; + + private static final String OWN_ENTITY_ID_VALUE = "oe_1"; + private static final String OWN_ENTITY_NAME_VALUE = "oe_2"; + + private static final String OWNING_ENTITY_RELATION_SHIP_JSON_FILE = "test-data/owning-entity-relation-ship.json"; + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Value("${spring.security.username}") + private String username; + + @Autowired + private OwnEntityCacheServiceProvider cacheServiceProvider; + + @After + public void after() { + cacheServiceProvider.clearAll(); + } + + @Test + public void test_putOwningEntity_successfullyAddedToCache() throws Exception { + final String url = getOwningEntityEndPointUrl() + "/" + OWN_ENTITY_ID_VALUE; + final String body = new String(Files.readAllBytes(getFile(OWNING_ENTITY_JSON_FILE).toPath())); + final ResponseEntity actual = invokeHttpPut(url, body); + + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final ResponseEntity actualResponse = 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 = getOwningEntityEndPointUrl() + "/" + OWN_ENTITY_ID_VALUE; + final String body = new String(Files.readAllBytes(getFile(OWNING_ENTITY_JSON_FILE).toPath())); + final ResponseEntity actual = invokeHttpPut(url, body); + + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final ResponseEntity actualResponse = + invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Result.class); + + assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); + assertTrue(actualResponse.hasBody()); + final Result 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 { + final String url = getOwningEntityEndPointUrl() + "/" + OWN_ENTITY_ID_VALUE; + final ResponseEntity actual = invokeHttpPut(url, getJsonString(OWNING_ENTITY_JSON_FILE)); + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final String owningEntityRelationshipUrl = url + RELATIONSHIP_URL; + + final ResponseEntity putResponse = invokeHttpPut(owningEntityRelationshipUrl, getRelationship()); + + assertEquals(HttpStatus.ACCEPTED, putResponse.getStatusCode()); + + final ResponseEntity actualResponse = 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)); + + } + + private String getRelationship() throws IOException { + return TestUtils.getJsonString(OWNING_ENTITY_RELATION_SHIP_JSON_FILE); + } + + private ResponseEntity invokeHttpGet(final String url, final Class clazz) { + return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(username)), clazz); + } + + private ResponseEntity invokeHttpPut(final String url, final Object obj) { + final HttpEntity httpEntity = getHttpEntity(obj); + return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Void.class); + } + + private HttpEntity getHttpEntity(final Object obj) { + return new HttpEntity<>(obj, getHttpHeaders(username)); + } + + private String getOwningEntityEndPointUrl() { + return TestUtils.getBaseUrl(port) + Constants.OWNING_ENTITY_URL; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java new file mode 100644 index 00000000..1b702513 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java @@ -0,0 +1,169 @@ +/*- + * ============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.so.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.so.aaisimulator.utils.TestUtils.getFile; +import static org.onap.so.aaisimulator.utils.TestUtils.getHttpHeaders; +import static org.onap.so.aaisimulator.utils.TestUtils.getJsonString; +import java.io.IOException; +import java.nio.file.Files; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.domain.yang.Project; +import org.onap.so.aaisimulator.models.Result; +import org.onap.so.aaisimulator.service.providers.ProjectCacheServiceProvider; +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +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.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +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 ProjectControllerTest { + + private static final String RELATIONSHIP_URL = "/relationship-list/relationship"; + + private static final String BUSINESS_PROJECT_JSON_FILE = "test-data/business-project.json"; + + private static final String PROJECT_RELATION_SHIP_JSON_FILE = "test-data/business-project-relation-ship.json"; + + private static final String PROJECT_NAME_VALUE = "PROJECT_NAME_VALUE"; + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Value("${spring.security.username}") + private String username; + + @Autowired + private ProjectCacheServiceProvider cacheServiceProvider; + + @After + public void after() { + cacheServiceProvider.clearAll(); + } + + @Test + public void test_putProject_successfullyAddedToCache() throws Exception { + final String url = getProjectEndPointUrl() + "/" + PROJECT_NAME_VALUE; + final String body = new String(Files.readAllBytes(getFile(BUSINESS_PROJECT_JSON_FILE).toPath())); + final ResponseEntity actual = invokeHttpPut(url, body); + + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final ResponseEntity actualResponse = 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 { + final String url = getProjectEndPointUrl() + "/" + PROJECT_NAME_VALUE; + final ResponseEntity actual = invokeHttpPut(url, getJsonString(BUSINESS_PROJECT_JSON_FILE)); + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final String projectRelationshipUrl = url + RELATIONSHIP_URL; + + final ResponseEntity putResponse = invokeHttpPut(projectRelationshipUrl, getRelationship()); + + assertEquals(HttpStatus.ACCEPTED, putResponse.getStatusCode()); + + final ResponseEntity actualResponse = 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)); + + } + + @Test + public void test_getProjectCount_correctResult() throws Exception { + final String url = getProjectEndPointUrl() + "/" + PROJECT_NAME_VALUE; + final String body = new String(Files.readAllBytes(getFile(BUSINESS_PROJECT_JSON_FILE).toPath())); + final ResponseEntity actual = invokeHttpPut(url, body); + + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final ResponseEntity actualResponse = + invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=count", Result.class); + + assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); + assertTrue(actualResponse.hasBody()); + final Result result = actualResponse.getBody(); + assertNotNull(result.getValues()); + assertFalse(result.getValues().isEmpty()); + assertEquals(1, result.getValues().get(0).get(Constants.PROJECT)); + } + + private ResponseEntity invokeHttpGet(final String url, final Class clazz) { + return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(username)), clazz); + } + + private ResponseEntity invokeHttpPut(final String url, final Object obj) { + final HttpEntity httpEntity = getHttpEntity(obj); + return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Void.class); + } + + private HttpEntity getHttpEntity(final Object obj) { + return new HttpEntity<>(obj, getHttpHeaders(username)); + } + + private String getProjectEndPointUrl() { + return TestUtils.getBaseUrl(port) + Constants.PROJECT_URL; + } + + private String getRelationship() throws IOException, Exception { + return TestUtils.getJsonString(PROJECT_RELATION_SHIP_JSON_FILE); + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java new file mode 100644 index 00000000..7683721c --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java @@ -0,0 +1,71 @@ +/*- + * ============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.so.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.http.client.HttpComponentsClientHttpRequestFactory; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@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; + + } + + 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/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java new file mode 100644 index 00000000..f59e8b58 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java @@ -0,0 +1,52 @@ +/*- + * ============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.so.aaisimulator.utils; + +import org.onap.so.aaisimulator.utils.Constants; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class TestConstants { + + 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 = Constants.CUSTOMER_URL + GLOBAL_CUSTOMER_ID; + + public static final String RELATIONSHIP_URL = "/relationship-list/relationship"; + + private TestConstants() {} + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java new file mode 100644 index 00000000..fecfd85a --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java @@ -0,0 +1,73 @@ +/*- + * ============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.so.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 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; + } + + private TestUtils() {} + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/package/docker/pom.xml b/plans/so/integration-etsi-testing/so-simulators/package/docker/pom.xml index 755e5418..8cf8c7f5 100644 --- a/plans/so/integration-etsi-testing/so-simulators/package/docker/pom.xml +++ b/plans/so/integration-etsi-testing/so-simulators/package/docker/pom.xml @@ -76,6 +76,29 @@ + + simulators/sdnc-simulator + + try + docker-files + Dockerfile.so-simulator-base-image + + ${project.version} + + + + + + + org.onap.so.simulators:sdnc-simulator + + app.jar + + + + + + @@ -110,14 +133,19 @@ - org.onap.so.simulators + ${project.parent.groupId} sdc-simulator ${project.version} - org.onap.so.simulators + ${project.parent.groupId} aai-simulator ${project.version} + + ${project.parent.groupId} + sdnc-simulator + ${project.version} + \ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/pom.xml b/plans/so/integration-etsi-testing/so-simulators/pom.xml index c18e1709..ee895a46 100644 --- a/plans/so/integration-etsi-testing/so-simulators/pom.xml +++ b/plans/so/integration-etsi-testing/so-simulators/pom.xml @@ -19,6 +19,7 @@ sdc-simulator aai-simulator + sdnc-simulator package diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/pom.xml b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/pom.xml index e5cc3d32..27e7c3ea 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/pom.xml +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/pom.xml @@ -26,7 +26,7 @@ org.springframework.boot spring-boot-maven-plugin - org.onap.so.sdc.simulator.SdcSimulatorApplication + org.onap.so.sdcsimulator.SdcSimulatorApplication diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/SdcSimulatorApplication.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/SdcSimulatorApplication.java deleted file mode 100644 index abb183b1..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/SdcSimulatorApplication.java +++ /dev/null @@ -1,36 +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.so.sdc.simulator; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - */ -@SpringBootApplication(scanBasePackages = {"org.onap"}) -public class SdcSimulatorApplication extends SpringBootServletInitializer { - - public static void main(final String[] args) { - SpringApplication.run(SdcSimulatorApplication.class, args); - } -} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/configration/WebSecurityConfigImpl.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/configration/WebSecurityConfigImpl.java deleted file mode 100644 index bf971785..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/configration/WebSecurityConfigImpl.java +++ /dev/null @@ -1,71 +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.so.sdc.simulator.configration; - -import org.onap.so.sdc.simulator.utils.Constants; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; - -/** - * @author waqas.ikram@ericsson.com - * - */ -@Configuration -@EnableWebSecurity -public class WebSecurityConfigImpl extends WebSecurityConfigurerAdapter { - - private final String username; - private final String password; - private final String role; - - public WebSecurityConfigImpl(@Value("${spring.security.username}") final String username, - @Value("${spring.security.password}") final String password, - @Value("${spring.security.role}") final String role) { - this.username = username; - this.password = password; - this.role = role; - } - - - @Override - protected void configure(final HttpSecurity http) throws Exception { - http.csrf().disable().authorizeRequests().antMatchers(Constants.CATALOG_URL + "/**/**").authenticated().and() - .httpBasic(); - } - - @Bean - public BCryptPasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); - } - - @Autowired - public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()).withUser(username).password(password) - .roles(role); - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/controller/CatalogController.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/controller/CatalogController.java deleted file mode 100644 index 01c0b39f..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/controller/CatalogController.java +++ /dev/null @@ -1,64 +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.so.sdc.simulator.controller; - -import static org.onap.so.sdc.simulator.utils.Constants.CATALOG_URL; -import java.util.Optional; -import javax.ws.rs.core.MediaType; -import org.onap.so.sdc.simulator.providers.ResourceProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -@RestController -@RequestMapping(path = CATALOG_URL) -public class CatalogController { - private static final Logger LOGGER = LoggerFactory.getLogger(CatalogController.class); - - private ResourceProvider resourceProvider; - - @Autowired - public CatalogController(final ResourceProvider resourceProvider) { - this.resourceProvider = resourceProvider; - } - - @GetMapping(value = "/resources/{csarId}/toscaModel", produces = MediaType.APPLICATION_OCTET_STREAM) - public ResponseEntity getCsar(@PathVariable("csarId") final String csarId) { - LOGGER.info("Running getCsar for {} ...", csarId); - final Optional resource = resourceProvider.getResource(csarId); - if (resource.isPresent()) { - return new ResponseEntity<>(resource.get(), HttpStatus.OK); - } - LOGGER.error("Unable to find csar: {}", csarId); - - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/controller/SdcSimulatorController.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/controller/SdcSimulatorController.java deleted file mode 100644 index 2baf2038..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/controller/SdcSimulatorController.java +++ /dev/null @@ -1,48 +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.so.sdc.simulator.controller; - -import javax.ws.rs.core.MediaType; -import org.onap.so.sdc.simulator.utils.Constants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - */ -@RestController -@RequestMapping(path = Constants.BASE_URL) -public class SdcSimulatorController { - private static final Logger LOGGER = LoggerFactory.getLogger(SdcSimulatorController.class); - - @GetMapping(value = "/healthcheck", produces = MediaType.APPLICATION_JSON) - @ResponseStatus(code = HttpStatus.OK) - public String healthCheck() { - LOGGER.info("Running health check ..."); - return Constants.HEALTHY; - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/providers/ResourceProvider.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/providers/ResourceProvider.java deleted file mode 100644 index 83994b4b..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/providers/ResourceProvider.java +++ /dev/null @@ -1,36 +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.so.sdc.simulator.providers; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Optional; - -/** - * @author Eoin Hanan (eoin.hanan@est.tech) - */ -public interface ResourceProvider { - - Optional getResource(final String csarId); - - Optional getInputStream(final String csarId) throws IOException; - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/providers/ResourceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/providers/ResourceProviderImpl.java deleted file mode 100644 index efc98de7..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/providers/ResourceProviderImpl.java +++ /dev/null @@ -1,88 +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.so.sdc.simulator.providers; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Optional; -import org.onap.so.sdc.simulator.utils.Constants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.io.ClassPathResource; -import org.springframework.stereotype.Service; -import org.springframework.util.StreamUtils; - -/** - * @author Eoin Hanan (eoin.hanan@est.tech) - */ -@Service -public class ResourceProviderImpl implements ResourceProvider { - - private static final Logger LOGGER = LoggerFactory.getLogger(ResourceProvider.class); - - private final String resourceLocation; - - public ResourceProviderImpl(@Value("${sdc.resource.location:/app/csars/}") final String resourceLocation) { - this.resourceLocation = resourceLocation; - } - - @Override - public Optional getResource(final String csarId) { - try { - final Optional optionalInputStream = getInputStream(csarId); - if (optionalInputStream.isPresent()) { - return Optional.of(StreamUtils.copyToByteArray(optionalInputStream.get())); - } - } catch (final IOException ioException) { - LOGGER.warn("Unable to create file stream ...", ioException); - } - - return Optional.empty(); - } - - @Override - public Optional getInputStream(final String csarId) throws IOException { - final Path filePath = Paths.get(resourceLocation, csarId + ".csar"); - if (Files.exists(filePath)) { - return Optional.of(Files.newInputStream(filePath)); - } - - LOGGER.info("Couldn't find file on file system '{}', will return default csar", filePath); - final ClassPathResource classPathResource = new ClassPathResource(getDefaultCsarPath(), this.getClass()); - if (classPathResource.exists()) { - return Optional.of(classPathResource.getInputStream()); - } - - LOGGER.error("Couldn't find default csar in classpath ...."); - return Optional.empty(); - } - - /* - * Used in test - */ - String getDefaultCsarPath() { - return Constants.DEFAULT_CSAR_PATH; - } -} \ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/utils/Constants.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/utils/Constants.java deleted file mode 100644 index 4fa06881..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdc/simulator/utils/Constants.java +++ /dev/null @@ -1,41 +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.so.sdc.simulator.utils; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - */ -public class Constants { - - public static final String BASE_URL = "/sdc/v1"; - - public static final String CATALOG_URL = BASE_URL + "/catalog"; - - public static final String HEALTHY = "healthy"; - - public static final String DEFAULT_CSAR_NAME = "default_csar_file"; - - public static final String DOT = "."; - - public static final String DOT_CSAR = DOT + "csar"; - - public static final String DEFAULT_CSAR_NAME_WITH_EXT = DEFAULT_CSAR_NAME + DOT_CSAR; - - public static final String DEFAULT_CSAR_PATH = "/csar/" + DEFAULT_CSAR_NAME_WITH_EXT; - - - private Constants() {} -} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/SdcSimulatorApplication.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/SdcSimulatorApplication.java new file mode 100644 index 00000000..25d21e53 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/SdcSimulatorApplication.java @@ -0,0 +1,36 @@ +/*- + * ============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.so.sdcsimulator; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + */ +@SpringBootApplication(scanBasePackages = {"org.onap"}) +public class SdcSimulatorApplication extends SpringBootServletInitializer { + + public static void main(final String[] args) { + SpringApplication.run(SdcSimulatorApplication.class, args); + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/configration/WebSecurityConfigImpl.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/configration/WebSecurityConfigImpl.java new file mode 100644 index 00000000..b2c51369 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/configration/WebSecurityConfigImpl.java @@ -0,0 +1,71 @@ +/*- + * ============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.so.sdcsimulator.configration; + +import org.onap.so.sdcsimulator.utils.Constants; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Configuration +@EnableWebSecurity +public class WebSecurityConfigImpl extends WebSecurityConfigurerAdapter { + + private final String username; + private final String password; + private final String role; + + public WebSecurityConfigImpl(@Value("${spring.security.username}") final String username, + @Value("${spring.security.password}") final String password, + @Value("${spring.security.role}") final String role) { + this.username = username; + this.password = password; + this.role = role; + } + + + @Override + protected void configure(final HttpSecurity http) throws Exception { + http.csrf().disable().authorizeRequests().antMatchers(Constants.CATALOG_URL + "/**/**").authenticated().and() + .httpBasic(); + } + + @Bean + public BCryptPasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + + @Autowired + public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception { + auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()).withUser(username).password(password) + .roles(role); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/CatalogController.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/CatalogController.java new file mode 100644 index 00000000..e9f17762 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/CatalogController.java @@ -0,0 +1,64 @@ +/*- + * ============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.so.sdcsimulator.controller; + +import static org.onap.so.sdcsimulator.utils.Constants.CATALOG_URL; +import java.util.Optional; +import javax.ws.rs.core.MediaType; +import org.onap.so.sdcsimulator.providers.ResourceProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@RestController +@RequestMapping(path = CATALOG_URL) +public class CatalogController { + private static final Logger LOGGER = LoggerFactory.getLogger(CatalogController.class); + + private ResourceProvider resourceProvider; + + @Autowired + public CatalogController(final ResourceProvider resourceProvider) { + this.resourceProvider = resourceProvider; + } + + @GetMapping(value = "/resources/{csarId}/toscaModel", produces = MediaType.APPLICATION_OCTET_STREAM) + public ResponseEntity getCsar(@PathVariable("csarId") final String csarId) { + LOGGER.info("Running getCsar for {} ...", csarId); + final Optional resource = resourceProvider.getResource(csarId); + if (resource.isPresent()) { + return new ResponseEntity<>(resource.get(), HttpStatus.OK); + } + LOGGER.error("Unable to find csar: {}", csarId); + + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/SdcSimulatorController.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/SdcSimulatorController.java new file mode 100644 index 00000000..4cd564d4 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/SdcSimulatorController.java @@ -0,0 +1,48 @@ +/*- + * ============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.so.sdcsimulator.controller; + +import javax.ws.rs.core.MediaType; +import org.onap.so.sdcsimulator.utils.Constants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + */ +@RestController +@RequestMapping(path = Constants.BASE_URL) +public class SdcSimulatorController { + private static final Logger LOGGER = LoggerFactory.getLogger(SdcSimulatorController.class); + + @GetMapping(value = "/healthcheck", produces = MediaType.APPLICATION_JSON) + @ResponseStatus(code = HttpStatus.OK) + public String healthCheck() { + LOGGER.info("Running health check ..."); + return Constants.HEALTHY; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/ResourceProvider.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/ResourceProvider.java new file mode 100644 index 00000000..4d5dcdd0 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/ResourceProvider.java @@ -0,0 +1,36 @@ +/*- + * ============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.so.sdcsimulator.providers; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Optional; + +/** + * @author Eoin Hanan (eoin.hanan@est.tech) + */ +public interface ResourceProvider { + + Optional getResource(final String csarId); + + Optional getInputStream(final String csarId) throws IOException; + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/ResourceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/ResourceProviderImpl.java new file mode 100644 index 00000000..192ac896 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/ResourceProviderImpl.java @@ -0,0 +1,88 @@ +/*- + * ============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.so.sdcsimulator.providers; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Optional; +import org.onap.so.sdcsimulator.utils.Constants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.ClassPathResource; +import org.springframework.stereotype.Service; +import org.springframework.util.StreamUtils; + +/** + * @author Eoin Hanan (eoin.hanan@est.tech) + */ +@Service +public class ResourceProviderImpl implements ResourceProvider { + + private static final Logger LOGGER = LoggerFactory.getLogger(ResourceProvider.class); + + private final String resourceLocation; + + public ResourceProviderImpl(@Value("${sdc.resource.location:/app/csars/}") final String resourceLocation) { + this.resourceLocation = resourceLocation; + } + + @Override + public Optional getResource(final String csarId) { + try { + final Optional optionalInputStream = getInputStream(csarId); + if (optionalInputStream.isPresent()) { + return Optional.of(StreamUtils.copyToByteArray(optionalInputStream.get())); + } + } catch (final IOException ioException) { + LOGGER.warn("Unable to create file stream ...", ioException); + } + + return Optional.empty(); + } + + @Override + public Optional getInputStream(final String csarId) throws IOException { + final Path filePath = Paths.get(resourceLocation, csarId + ".csar"); + if (Files.exists(filePath)) { + return Optional.of(Files.newInputStream(filePath)); + } + + LOGGER.info("Couldn't find file on file system '{}', will return default csar", filePath); + final ClassPathResource classPathResource = new ClassPathResource(getDefaultCsarPath(), this.getClass()); + if (classPathResource.exists()) { + return Optional.of(classPathResource.getInputStream()); + } + + LOGGER.error("Couldn't find default csar in classpath ...."); + return Optional.empty(); + } + + /* + * Used in test + */ + String getDefaultCsarPath() { + return Constants.DEFAULT_CSAR_PATH; + } +} \ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/utils/Constants.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/utils/Constants.java new file mode 100644 index 00000000..e8412574 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/utils/Constants.java @@ -0,0 +1,45 @@ +/*- + * ============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.so.sdcsimulator.utils; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + */ +public class Constants { + + public static final String BASE_URL = "/sdc/v1"; + + public static final String CATALOG_URL = BASE_URL + "/catalog"; + + public static final String HEALTHY = "healthy"; + + public static final String DEFAULT_CSAR_NAME = "default_csar_file"; + + public static final String DOT = "."; + + public static final String DOT_CSAR = DOT + "csar"; + + public static final String DEFAULT_CSAR_NAME_WITH_EXT = DEFAULT_CSAR_NAME + DOT_CSAR; + + public static final String DEFAULT_CSAR_PATH = "/csar/" + DEFAULT_CSAR_NAME_WITH_EXT; + + private Constants() {} +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdc/simulator/controller/CatalogControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdc/simulator/controller/CatalogControllerTest.java deleted file mode 100644 index 98ec448e..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdc/simulator/controller/CatalogControllerTest.java +++ /dev/null @@ -1,110 +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.so.sdc.simulator.controller; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import java.util.Base64; -import java.util.Optional; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.onap.so.sdc.simulator.providers.ResourceProvider; -import org.onap.so.sdc.simulator.utils.Constants; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -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.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -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 class CatalogControllerTest { - - private static final String PASSWORD = "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U"; - - @LocalServerPort - private int port; - - @Autowired - private TestRestTemplate restTemplate; - - @Value("${spring.security.username}") - private String username; - - @Test - public void test_getCsar_validCsarId_matchContent() { - - final String url = getBaseUrl() + "/resources/" + Constants.DEFAULT_CSAR_NAME + "/toscaModel"; - - final ResponseEntity response = - restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), byte[].class); - - assertEquals(HttpStatus.OK, response.getStatusCode()); - assertTrue(response.hasBody()); - assertEquals(3982, response.getBody().length); - - } - - @Test - public void test_getCsar_invalidCsar_internalServerError() { - final ResourceProvider mockedResourceProvider = Mockito.mock(ResourceProvider.class); - Mockito.when(mockedResourceProvider.getResource(Mockito.anyString())).thenReturn(Optional.empty()); - final CatalogController objUnderTest = new CatalogController(mockedResourceProvider); - - final ResponseEntity response = objUnderTest.getCsar(Constants.DEFAULT_CSAR_NAME); - - assertFalse(response.hasBody()); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); - } - - private String getBaseUrl() { - return "http://localhost:" + port + Constants.CATALOG_URL; - } - - private HttpHeaders getHttpHeaders() { - final HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.add("Authorization", getBasicAuth(username)); - requestHeaders.setContentType(MediaType.APPLICATION_JSON); - return requestHeaders; - } - - private String getBasicAuth(final String username) { - return "Basic " + new String(Base64.getEncoder().encodeToString((username + ":" + PASSWORD).getBytes())); - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdc/simulator/controller/SdcSimulatorControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdc/simulator/controller/SdcSimulatorControllerTest.java deleted file mode 100644 index 300b62a8..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdc/simulator/controller/SdcSimulatorControllerTest.java +++ /dev/null @@ -1,61 +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.so.sdc.simulator.controller; - -import static org.junit.Assert.assertEquals; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.so.sdc.simulator.utils.Constants; -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 (waqas.ikram@est.tech) - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ActiveProfiles("test") -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@Configuration -public class SdcSimulatorControllerTest { - - @LocalServerPort - private int port; - - @Autowired - private TestRestTemplate restTemplate; - - @Test - public void test_healthCheck_matchContent() { - final String url = "http://localhost:" + port + Constants.BASE_URL + "/healthcheck"; - final ResponseEntity object = restTemplate.getForEntity(url, String.class); - - assertEquals(Constants.HEALTHY, object.getBody()); - - } - -} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdc/simulator/providers/ResourceProviderImplTest.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdc/simulator/providers/ResourceProviderImplTest.java deleted file mode 100644 index b112c403..00000000 --- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdc/simulator/providers/ResourceProviderImplTest.java +++ /dev/null @@ -1,98 +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.so.sdc.simulator.providers; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertFalse; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.onap.so.sdc.simulator.utils.Constants; -import org.springframework.core.io.ClassPathResource; -import org.springframework.util.StreamUtils; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * @author Eoin Hanan (eoin.hanan@est.tech) - */ -public class ResourceProviderImplTest { - - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - - private static final String DUMMY_CONTENT = "Hell world"; - - @Test - public void test_getResource_withValidPath_matchContent() throws IOException { - final File folder = temporaryFolder.newFolder(); - final Path file = Files.createFile(folder.toPath().resolve("empty.csar")); - - Files.write(file, DUMMY_CONTENT.getBytes()); - - final ResourceProviderImpl objUnderTest = new ResourceProviderImpl(folder.getPath()); - - assertArrayEquals(DUMMY_CONTENT.getBytes(), objUnderTest.getResource("empty").get()); - } - - @Test - public void test_getResource_withoutValidPath_matchContent() throws IOException { - final ClassPathResource classPathResource = new ClassPathResource(Constants.DEFAULT_CSAR_PATH, this.getClass()); - - final byte[] expectedResult = StreamUtils.copyToByteArray(classPathResource.getInputStream()); - - final ResourceProviderImpl objUnderTest = new ResourceProviderImpl(""); - - assertArrayEquals(expectedResult, objUnderTest.getResource(Constants.DEFAULT_CSAR_NAME).get()); - } - - @Test - public void test_getResource_unbleToreadFileFromClasspath_emptyOptional() throws IOException { - - final ResourceProviderImpl objUnderTest = new ResourceProviderImpl("") { - @Override - String getDefaultCsarPath() { - return "/some/dummy/path"; - } - }; - assertFalse(objUnderTest.getResource(Constants.DEFAULT_CSAR_NAME).isPresent()); - - } - - @Test - public void test_getResource_withValidPathAndUnabletoRead_emptyOptional() throws IOException { - final File folder = temporaryFolder.newFolder(); - final Path file = Files.createFile(folder.toPath().resolve("empty.csar")); - - Files.write(file, DUMMY_CONTENT.getBytes()); - file.toFile().setReadable(false); - - final ResourceProviderImpl objUnderTest = new ResourceProviderImpl(folder.getPath()); - - assertFalse(objUnderTest.getResource("empty").isPresent()); - - } - -} \ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java new file mode 100644 index 00000000..ca55f495 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java @@ -0,0 +1,111 @@ +/*- + * ============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.so.sdcsimulator.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import java.util.Base64; +import java.util.Optional; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.so.sdcsimulator.controller.CatalogController; +import org.onap.so.sdcsimulator.providers.ResourceProvider; +import org.onap.so.sdcsimulator.utils.Constants; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +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.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +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 class CatalogControllerTest { + + private static final String PASSWORD = "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U"; + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Value("${spring.security.username}") + private String username; + + @Test + public void test_getCsar_validCsarId_matchContent() { + + final String url = getBaseUrl() + "/resources/" + Constants.DEFAULT_CSAR_NAME + "/toscaModel"; + + final ResponseEntity response = + restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), byte[].class); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertTrue(response.hasBody()); + assertEquals(3982, response.getBody().length); + + } + + @Test + public void test_getCsar_invalidCsar_internalServerError() { + final ResourceProvider mockedResourceProvider = Mockito.mock(ResourceProvider.class); + Mockito.when(mockedResourceProvider.getResource(Mockito.anyString())).thenReturn(Optional.empty()); + final CatalogController objUnderTest = new CatalogController(mockedResourceProvider); + + final ResponseEntity response = objUnderTest.getCsar(Constants.DEFAULT_CSAR_NAME); + + assertFalse(response.hasBody()); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + } + + private String getBaseUrl() { + return "http://localhost:" + port + Constants.CATALOG_URL; + } + + private HttpHeaders getHttpHeaders() { + final HttpHeaders requestHeaders = new HttpHeaders(); + requestHeaders.add("Authorization", getBasicAuth(username)); + requestHeaders.setContentType(MediaType.APPLICATION_JSON); + return requestHeaders; + } + + private String getBasicAuth(final String username) { + return "Basic " + new String(Base64.getEncoder().encodeToString((username + ":" + PASSWORD).getBytes())); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/SdcSimulatorControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/SdcSimulatorControllerTest.java new file mode 100644 index 00000000..9789f812 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/SdcSimulatorControllerTest.java @@ -0,0 +1,61 @@ +/*- + * ============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.so.sdcsimulator.controller; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.sdcsimulator.utils.Constants; +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 (waqas.ikram@est.tech) + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ActiveProfiles("test") +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@Configuration +public class SdcSimulatorControllerTest { + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Test + public void test_healthCheck_matchContent() { + final String url = "http://localhost:" + port + Constants.BASE_URL + "/healthcheck"; + final ResponseEntity object = restTemplate.getForEntity(url, String.class); + + assertEquals(Constants.HEALTHY, object.getBody()); + + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/providers/ResourceProviderImplTest.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/providers/ResourceProviderImplTest.java new file mode 100644 index 00000000..e575f2a5 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/providers/ResourceProviderImplTest.java @@ -0,0 +1,99 @@ +/*- + * ============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.so.sdcsimulator.providers; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertFalse; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.onap.so.sdcsimulator.providers.ResourceProviderImpl; +import org.onap.so.sdcsimulator.utils.Constants; +import org.springframework.core.io.ClassPathResource; +import org.springframework.util.StreamUtils; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * @author Eoin Hanan (eoin.hanan@est.tech) + */ +public class ResourceProviderImplTest { + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + private static final String DUMMY_CONTENT = "Hell world"; + + @Test + public void test_getResource_withValidPath_matchContent() throws IOException { + final File folder = temporaryFolder.newFolder(); + final Path file = Files.createFile(folder.toPath().resolve("empty.csar")); + + Files.write(file, DUMMY_CONTENT.getBytes()); + + final ResourceProviderImpl objUnderTest = new ResourceProviderImpl(folder.getPath()); + + assertArrayEquals(DUMMY_CONTENT.getBytes(), objUnderTest.getResource("empty").get()); + } + + @Test + public void test_getResource_withoutValidPath_matchContent() throws IOException { + final ClassPathResource classPathResource = new ClassPathResource(Constants.DEFAULT_CSAR_PATH, this.getClass()); + + final byte[] expectedResult = StreamUtils.copyToByteArray(classPathResource.getInputStream()); + + final ResourceProviderImpl objUnderTest = new ResourceProviderImpl(""); + + assertArrayEquals(expectedResult, objUnderTest.getResource(Constants.DEFAULT_CSAR_NAME).get()); + } + + @Test + public void test_getResource_unbleToreadFileFromClasspath_emptyOptional() throws IOException { + + final ResourceProviderImpl objUnderTest = new ResourceProviderImpl("") { + @Override + String getDefaultCsarPath() { + return "/some/dummy/path"; + } + }; + assertFalse(objUnderTest.getResource(Constants.DEFAULT_CSAR_NAME).isPresent()); + + } + + @Test + public void test_getResource_withValidPathAndUnabletoRead_emptyOptional() throws IOException { + final File folder = temporaryFolder.newFolder(); + final Path file = Files.createFile(folder.toPath().resolve("empty.csar")); + + Files.write(file, DUMMY_CONTENT.getBytes()); + file.toFile().setReadable(false); + + final ResourceProviderImpl objUnderTest = new ResourceProviderImpl(folder.getPath()); + + assertFalse(objUnderTest.getResource("empty").isPresent()); + + } + +} \ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/pom.xml b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/pom.xml new file mode 100644 index 00000000..8e947e62 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + + org.onap.so.simulators + so-simulators + 1.0-SNAPSHOT + + sdnc-simulator + ${project.artifactId} + + + + org.springframework.boot + spring-boot-maven-plugin + + org.onap.so.sdncsimulator.SdncSimulatorApplication + + + + + repackage + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/SdncSimulatorApplication.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/SdncSimulatorApplication.java new file mode 100644 index 00000000..f6b6938c --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/SdncSimulatorApplication.java @@ -0,0 +1,36 @@ +/*- + * ============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.so.sdncsimulator; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@SpringBootApplication(scanBasePackages = {"org.onap"}) +public class SdncSimulatorApplication extends SpringBootServletInitializer { + + public static void main(final String[] args) { + SpringApplication.run(SdncSimulatorApplication.class, args); + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/SdncSimulatorController.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/SdncSimulatorController.java new file mode 100644 index 00000000..fbe2d281 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/SdncSimulatorController.java @@ -0,0 +1,47 @@ +/*- + * ============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.so.sdncsimulator.controller; + +import javax.ws.rs.core.MediaType; +import org.onap.so.sdncsimulator.utils.Constants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@RestController +@RequestMapping(path = Constants.BASE_URL) +public class SdncSimulatorController { + private static final Logger LOGGER = LoggerFactory.getLogger(SdncSimulatorController.class); + + @GetMapping(value = "/healthcheck", produces = MediaType.APPLICATION_JSON) + @ResponseStatus(code = HttpStatus.OK) + public String healthCheck() { + LOGGER.info("Running health check ..."); + return Constants.HEALTHY; + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/Constants.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/Constants.java new file mode 100644 index 00000000..32f31356 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/Constants.java @@ -0,0 +1,32 @@ +/*- + * ============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.so.sdncsimulator.utils; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class Constants { + public static final String BASE_URL = "/restconf/"; + + public static final String HEALTHY = "healthy"; + + private Constants() {} +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/resources/application.yaml b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/resources/application.yaml new file mode 100644 index 00000000..bcd8d5fc --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/resources/application.yaml @@ -0,0 +1,5 @@ +server: + port: 9994 + tomcat: + max-threads: 4 +ssl-enable: false \ No newline at end of file diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/SdncSimulatorControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/SdncSimulatorControllerTest.java new file mode 100644 index 00000000..b5d6dc0d --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/SdncSimulatorControllerTest.java @@ -0,0 +1,60 @@ +/*- + * ============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.so.sdncsimulator.controller; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.sdncsimulator.utils.Constants; +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 (waqas.ikram@est.tech) + * + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ActiveProfiles("test") +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@Configuration +public class SdncSimulatorControllerTest { + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Test + public void test_healthCheck_matchContent() { + final String url = "http://localhost:" + port + Constants.BASE_URL + "/healthcheck"; + final ResponseEntity object = restTemplate.getForEntity(url, String.class); + + assertEquals(Constants.HEALTHY, object.getBody()); + + } +} -- cgit 1.2.3-korg