diff options
Diffstat (limited to 'plans/so')
84 files changed, 2378 insertions, 297 deletions
diff --git a/plans/so/integration-etsi-testing/config/aai-simulator-populate-data/customer.json b/plans/so/integration-etsi-testing/config/aai-simulator-populate-data/customer.json new file mode 100644 index 00000000..6c53c056 --- /dev/null +++ b/plans/so/integration-etsi-testing/config/aai-simulator-populate-data/customer.json @@ -0,0 +1,73 @@ +{ + "global-customer-id": "DemoCustomer", + "subscriber-name": "DemoCustomer", + "subscriber-type": "INFRA", + "service-subscriptions": { + "service-subscription": [ + { + "service-type": "vLB", + "relationship-list": { + "relationship": [ + { + "related-to": "tenant", + "relationship-label": "org.onap.relationships.inventory.Uses", + "related-link": "/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/xyzcloud/tenants/tenant/693c7729b2364a26a3ca602e6f66187d", + "relationship-data": [ + { + "relationship-key": "cloud-region.cloud-owner", + "relationship-value": "CloudOwner" + }, + { + "relationship-key": "cloud-region.cloud-region-id", + "relationship-value": "xyzcloud" + }, + { + "relationship-key": "tenant.tenant-id", + "relationship-value": "693c7729b2364a26a3ca602e6f66187d" + } + ], + "related-to-property": [ + { + "property-key": "tenant.tenant-name", + "property-value": "admin" + } + ] + } + ] + } + }, + { + "service-type": "vCPE", + "relationship-list": { + "relationship": [ + { + "related-to": "tenant", + "relationship-label": "org.onap.relationships.inventory.Uses", + "related-link": "/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/xyzcloud/tenants/tenant/693c7729b2364a26a3ca602e6f66187d", + "relationship-data": [ + { + "relationship-key": "cloud-region.cloud-owner", + "relationship-value": "CloudOwner" + }, + { + "relationship-key": "cloud-region.cloud-region-id", + "relationship-value": "xyzcloud" + }, + { + "relationship-key": "tenant.tenant-id", + "relationship-value": "693c7729b2364a26a3ca602e6f66187d" + } + ], + "related-to-property": [ + { + "property-key": "tenant.tenant-name", + "property-value": "admin" + } + ] + } + ] + } + } + ] + } +} diff --git a/plans/so/integration-etsi-testing/config/aai-simulator-populate-data/owning-entity.json b/plans/so/integration-etsi-testing/config/aai-simulator-populate-data/owning-entity.json new file mode 100644 index 00000000..7248d41d --- /dev/null +++ b/plans/so/integration-etsi-testing/config/aai-simulator-populate-data/owning-entity.json @@ -0,0 +1,4 @@ +{ + "owning-entity-id": "oe_1", + "owning-entity-name": "oe_2" +} diff --git a/plans/so/integration-etsi-testing/config/aai-simulator-populate-data/project.json b/plans/so/integration-etsi-testing/config/aai-simulator-populate-data/project.json new file mode 100644 index 00000000..146a1e26 --- /dev/null +++ b/plans/so/integration-etsi-testing/config/aai-simulator-populate-data/project.json @@ -0,0 +1,4 @@ +{ + "project-name": "etsiCsitProject" +} + diff --git a/plans/so/integration-etsi-testing/config/apply-workarounds.sh b/plans/so/integration-etsi-testing/config/apply-workarounds.sh index 4200a361..21a3aeb8 100755 --- a/plans/so/integration-etsi-testing/config/apply-workarounds.sh +++ b/plans/so/integration-etsi-testing/config/apply-workarounds.sh @@ -87,6 +87,9 @@ apply_workaround() echo "$SCRIPT_NAME $(current_timestamp): Will insert data into $CATALOG_DB" mysql -h $DB_HOST -uroot -p$MYSQL_ROOT_PASSWORD $CATALOG_DB << EOF BEGIN; + + UPDATE $NORTH_BOUND_TABLE_NAME SET SERVICE_TYPE="*"; + INSERT INTO $BUIDLING_BLOCK_TABLE_NAME (BUILDING_BLOCK_NAME,RESOURCE_TYPE,TARGET_ACTION) values ("EtsiVnfInstantiateBB", "VNF", "ACTIVATE"); INSERT INTO $BUIDLING_BLOCK_TABLE_NAME (BUILDING_BLOCK_NAME,RESOURCE_TYPE,TARGET_ACTION) values ("EtsiVnfDeleteBB", "VNF", "DEACTIVATE"); diff --git a/plans/so/integration-etsi-testing/config/env b/plans/so/integration-etsi-testing/config/env index 9b6dc557..5334c8cb 100644 --- a/plans/so/integration-etsi-testing/config/env +++ b/plans/so/integration-etsi-testing/config/env @@ -1,3 +1,4 @@ NEXUS_DOCKER_REPO_MSO=nexus3.onap.org:10001 TAG=1.4.0-STAGING-latest TIME_OUT_DEFAULT_VALUE_SEC=1200 +PROJECT_NAME=etsiintegrationtesting diff --git a/plans/so/integration-etsi-testing/config/populate-aai-simulator.sh b/plans/so/integration-etsi-testing/config/populate-aai-simulator.sh new file mode 100755 index 00000000..1a00f710 --- /dev/null +++ b/plans/so/integration-etsi-testing/config/populate-aai-simulator.sh @@ -0,0 +1,99 @@ +#!/bin/bash +# +# ============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========================================================= +# + +# @author Gareth Roper (gareth.roper@est.tech) +# @auther Waqas Ikram (waqas.ikram@est.tech) + +SCRIPT_NAME=$(basename $0) +SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +WAIT_FOR_SCRIPT=$SCRIPT_HOME/wait-for.sh + +current_timestamp() +{ + date +"%Y-%m-%d %H:%M:%S" +} + +populate_aai_simulator() +{ + $WAIT_FOR_SCRIPT -t "$TIMEOUT_IN_SECONDS" -h "$AAI_SIMULATOR_HOST" -p "$AAI_SIMULATOR_PORT" + + if [ $? -eq 0 ] + then + echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator is Running." + else + echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator could not be found. Exiting..." + exit 1 + fi + + BASE_URL="https://$AAI_SIMULATOR_HOST:$AAI_SIMULATOR_PORT/aai/v15" + BASIC_AUTHORIZATION_HEADER="Authorization: Basic YWFpOmFhaS5vbmFwLm9yZzpkZW1vMTIzNDU2IQ==" + APPICATION_JSON="application/json" + ACCEPT_HEADER="Accept: $APPICATION_JSON" + CONTENT_TYPE_HEADER="Content-Type: $APPICATION_JSON" + CURL_COMMAND="curl -k -H $BASIC_AUTHORIZATION_HEADER -H $ACCEPT_HEADER -H $CONTENT_TYPE_HEADER" + + AAI_SIMULATOR_DATA_DIR=$SCRIPT_HOME/aai-simulator-populate-data + CUSTOMER_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/customer.json + PROJECT_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/project.json + OWNING_ENTITY_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/owning-entity.json + STATUS_CODE_ACCEPTED="202" + + echo "$SCRIPT_NAME $(current_timestamp): checking health of AAI Simulator" + response=$(curl -k $BASE_URL/healthcheck) + + if [[ "$response" -ne "healthy" ]] ; then + echo "$SCRIPT_NAME $(current_timestamp) ERROR: AAI Simulator health check failed. Response: $response" + exit 1 + fi + + echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator is healthy" + + echo "$SCRIPT_NAME $(current_timestamp): Populating AAI Simulator" + + echo "$SCRIPT_NAME $(current_timestamp): Adding Cloud-Customer Data" + status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/customers/customer/DemoCustomer -X PUT -d @"$CUSTOMER_JSON_FILE") + + if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then + echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put customer data in AAI Simulator. Status code received: $status_code" + exit 1 + fi + + echo "$SCRIPT_NAME $(current_timestamp): Adding Project" + status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/projects/project/etsiCsitProject -X PUT -d @"$PROJECT_JSON_FILE") + + if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then + echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put project data in AAI Simulator. Status code received: $status_code" + exit 1 + fi + + echo "$SCRIPT_NAME $(current_timestamp): Adding Owning-Entity" + status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/owning-entities/owning-entity/oe_1 -X PUT -d @$"$OWNING_ENTITY_JSON_FILE") + + if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then + echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put owning entity data in AAI Simulator. Status code received: $status_code" + exit 1 + fi + + echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator Populated Successfully" +} + +# main body +populate_aai_simulator diff --git a/plans/so/integration-etsi-testing/config/wait-for-aai-config-job.sh b/plans/so/integration-etsi-testing/config/wait-for-aai-config-job.sh new file mode 100755 index 00000000..58a07811 --- /dev/null +++ b/plans/so/integration-etsi-testing/config/wait-for-aai-config-job.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# +# ============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========================================================= +# + +# @author Waqas Ikram (waqas.ikram@est.tech) + +SLEEP_TIME=5 +SUCCESSFUL_TEXT="AAI Simulator Populated Successfully" +FAILURE_TEXT="ERROR:" +TIME_OUT_TEXT="Time out" +CONTAINER_NAME=$(docker ps -aqf "name=populate-aai-config" --format "{{.Names}}") +SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SCRIPT_NAME=$(basename $0) + +current_timestamp() +{ + date +"%Y-%m-%d %H:%M:%S" +} + +# main body +if [ -z $TIME_OUT_DEFAULT_VALUE_SEC ]; then + echo "$SCRIPT_NAME $(current_timestamp): ERROR: Undefined value for TIME_OUT_DEFAULT_VALUE_SEC attribute" + exit 1 +fi + +if [ -z $CONTAINER_NAME ]; then + echo "$SCRIPT_NAME $(current_timestamp): Unable to find docker container id " + exit 1 +fi + +START_TIME_IN_SECONDS=`date +%s` +TIME_OUT_END_TIME_IN_SECONDS=$(($START_TIME_IN_SECONDS+$TIME_OUT_DEFAULT_VALUE_SEC)); + + +echo echo "$SCRIPT_NAME $(current_timestamp): $SCRIPT_NAME script Start Time `date -d @$START_TIME_IN_SECONDS`" +echo echo "$SCRIPT_NAME $(current_timestamp): $SCRIPT_NAME will time out at `date -d @$TIME_OUT_END_TIME_IN_SECONDS`" + +while [ `date +%s` -lt "$TIME_OUT_END_TIME_IN_SECONDS" ]; do + echo "$(current_timestamp): Waiting for $CONTAINER_NAME to finish ..." + + result=$(docker logs $CONTAINER_NAME 2>&1 | grep -E "$SUCCESSFUL_TEXT|$FAILURE_TEXT|$TIME_OUT_TEXT") + if [ ! -z "$result" ]; then + echo "$SCRIPT_NAME $(current_timestamp): Found result: $result" + break; + fi + echo "$(current_timestamp): Sleeping for ${SLEEP_TIME} seconds" + sleep ${SLEEP_TIME} +done + +if [ -z "$result" ]; then + echo "$SCRIPT_NAME $(current_timestamp): ERROR: failed to populate AAI Simulator . . . " + echo "-------------- $CONTAINER_NAME logs -------------" + docker logs $CONTAINER_NAME + echo "------------------------------------------------------------" + exit 1 +fi + +if echo "$result" | grep -E "$FAILURE_TEXT|$TIME_OUT_TEXT"; then + echo "$SCRIPT_NAME $(current_timestamp): populate-aai-simulator.sh failed" + echo "-------------- $CONTAINER_NAME logs -------------" + docker logs $CONTAINER_NAME + echo "------------------------------------------------------------" + exit 1 +fi + +echo "$SCRIPT_NAME $(current_timestamp): Successfully populated AAI Simulator . . ." +exit 0 diff --git a/plans/so/integration-etsi-testing/config/wait-for-container.sh b/plans/so/integration-etsi-testing/config/wait-for-container.sh new file mode 100755 index 00000000..c2cbc262 --- /dev/null +++ b/plans/so/integration-etsi-testing/config/wait-for-container.sh @@ -0,0 +1,146 @@ +#!/bin/bash +# +# ============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========================================================= +# + +# @author Waqas Ikram (waqas.ikram@est.tech) + +SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SCRIPT_NAME=$(basename $0) +WAIT_FOR_SCRIPT=$SCRIPT_HOME/wait-for.sh + +# Process the arguments passed to the script +usage() +{ + _msg_="$@" + cat<<-EOF + Command Arguments: + + -n, --name + Mandatory argument. container name + + -p, --project-name + Mandatory argument. project name + + -t, --timeout + Mandatory argument. time out value in seconds (must be number) + + --help + Optional argument. Display this usage. + +EOF + exit 1 +} + +current_timestamp() +{ + date +"%Y-%m-%d %H:%M:%S" +} + +# Called when script is executed with invalid arguments +invalid_arguments() +{ + echo "Missing or invalid option(s):" + echo "$@" + echo "Try --help for more information" + exit 1 +} + +process_arguments() +{ + SHORT_ARGS="n:p:t:" + LONG_ARGS="help,name:,project-name:,timeout:" + + args=$(getopt -o $SHORT_ARGS -l $LONG_ARGS -n "$0" -- "$@" 2>&1 ) + [[ $? -ne 0 ]] && invalid_arguments $( echo " $args"| head -1 ) + [[ $# -eq 0 ]] && invalid_arguments "No options provided" + + eval set -- "$args" + cmd_arg="$0" + + while true; do + case "$1" in + -n|--name) + NAME=$2 + shift 2 ;; + -p|project-name) + PROJECT_NAME=$2 + shift 2 ;; + -t|--timeout) + TIME_OUT=$2 + shift 2 ;; + --help) + usage + exit 0 + ;; + --) + shift + break ;; + *) + echo BAD ARGUMENTS # perhaps error + break ;; + esac + done + + if [ -z "$NAME" ]; then + echo "$SCRIPT_NAME $(current_timestamp): error: Container name must not be empty! $NAME" >&2; exit 1 + fi + + if [ -z "$PROJECT_NAME" ]; then + echo "$SCRIPT_NAME $(current_timestamp): error: project name must not be empty! $PROJECT_NAME" >&2; exit 1 + fi + + regex='^[0-9]+$' + if ! [[ $TIME_OUT =~ $regex ]] ; then + echo "$SCRIPT_NAME $(current_timestamp): error: TIME_OUT must be number $TIME_OUT" >&2; exit 1 + fi + + CONTAINER_NAME=$(docker ps -aqf "name=$NAME" --format "{{.Names}}") + + if [ $? -ne 0 ]; then + echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to find container using $NAME" + exit 1 + fi + + HOST_IP=$(docker inspect --format '{{ index .NetworkSettings.Networks "'$PROJECT_NAME'" "IPAddress"}}' $CONTAINER_NAME) + + if [ $? -ne 0 ]; then + echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to find HOST IP using project name: $PROJECT_NAME and container name: $CONTAINER_NAME" + exit 1 + fi + + PORT=$(docker port $CONTAINER_NAME | cut -c1-$(docker port $CONTAINER_NAME | grep -aob '/' | grep -oE '[0-9]+')) + + if [ $? -ne 0 ]; then + echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to find PORT using project name: $PROJECT_NAME and container name: $CONTAINER_NAME" + exit 1 + fi + + $WAIT_FOR_SCRIPT -t "$TIME_OUT" -h "$HOST_IP" -p "$PORT" + + if [ $? -ne 0 ]; then + echo "$SCRIPT_NAME $(current_timestamp) ERROR: wait-for.sh failed ..." + exit 1 + fi + + echo "$SCRIPT_NAME $(current_timestamp): finished successfully" +} + +# main body +process_arguments $@ diff --git a/plans/so/integration-etsi-testing/config/wait-for-workaround-job.sh b/plans/so/integration-etsi-testing/config/wait-for-workaround-job.sh index ae6c2f57..035c5e26 100755 --- a/plans/so/integration-etsi-testing/config/wait-for-workaround-job.sh +++ b/plans/so/integration-etsi-testing/config/wait-for-workaround-job.sh @@ -1,4 +1,4 @@ - +#!/bin/bash # # ============LICENSE_START======================================================= # Copyright (C) 2019 Nordix Foundation. diff --git a/plans/so/integration-etsi-testing/docker-compose.yml b/plans/so/integration-etsi-testing/docker-compose.yml index 068349f8..69fb6857 100644 --- a/plans/so/integration-etsi-testing/docker-compose.yml +++ b/plans/so/integration-etsi-testing/docker-compose.yml @@ -343,3 +343,38 @@ 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" +################################################################################ + populate-aai-config: + image: jobs/workaround-job-container:latest + ports: + - "9995:9995" + volumes: + - ${CONFIG_DIR_PATH}/populate-aai-simulator.sh:/config/populate-aai-simulator.sh + - ${CONFIG_DIR_PATH}/wait-for.sh:/config/wait-for.sh + - ${CONFIG_DIR_PATH}/aai-simulator-populate-data:/config/aai-simulator-populate-data/ + environment: + - AAI_SIMULATOR_HOST=aai-simulator + - AAI_SIMULATOR_PORT=9993 + - TIMEOUT_IN_SECONDS=300 #5 mins + depends_on: + - aai-simulator + command: + - "/config/populate-aai-simulator.sh" +################################################################################ diff --git a/plans/so/integration-etsi-testing/setup.sh b/plans/so/integration-etsi-testing/setup.sh index 597bf2ea..a3eb784c 100755 --- a/plans/so/integration-etsi-testing/setup.sh +++ b/plans/so/integration-etsi-testing/setup.sh @@ -40,6 +40,7 @@ MVN_SETTINGS_XML="$SCRIPT_HOME/settings.xml" MVN_CLEAN_INSTALL="$MVN clean install" SIMULATOR_MAVEN_PROJECT_POM="$SCRIPT_HOME/so-simulators/pom.xml" WAIT_FOR_WORKAROUND_SCRIPT=$CONFIG_DIR/"wait-for-workaround-job.sh" +WAIT_FOR_POPULATE_AAI_SCRIPT=$CONFIG_DIR/"wait-for-aai-config-job.sh" echo "Running $SCRIPT_HOME/$SCRIPT_NAME ..." @@ -125,7 +126,7 @@ git clone http://gerrit.onap.org/r/so/docker-config.git $TEST_LAB_DIR_PATH export TEST_LAB_DIR=$TEST_LAB_DIR_PATH export CONFIG_DIR_PATH=$CONFIG_DIR -docker-compose -f $DOCKER_COMPOSE_FILE_PATH up -d +docker-compose -f $DOCKER_COMPOSE_FILE_PATH -p $PROJECT_NAME up -d echo "Sleeping for 3m" sleep 3m @@ -140,6 +141,15 @@ if [ $? -ne 0 ]; then exit 1 fi +echo "Will execute $WAIT_FOR_POPULATE_AAI_SCRIPT script" +$WAIT_FOR_POPULATE_AAI_SCRIPT + +if [ $? -ne 0 ]; then + echo "ERROR: $WAIT_FOR_POPULATE_AAI_SCRIPT failed" + echo "Will stop running docker containers . . ." + docker-compose -f $DOCKER_COMPOSE_FILE_PATH down + exit 1 +fi REPO_IP='127.0.0.1' ROBOT_VARIABLES="-v REPO_IP:${REPO_IP}" 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..428aeb7b 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 @@ -7,13 +7,16 @@ <version>1.0-SNAPSHOT</version> </parent> <artifactId>aai-simulator</artifactId> - <properties> <version.aai.schema>1.0.0</version.aai.schema> </properties> - <dependencies> <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>common</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>org.onap.aai.schema-service</groupId> <artifactId>aai-schema</artifactId> <version>${version.aai.schema}</version> @@ -38,14 +41,13 @@ <scope>test</scope> </dependency> </dependencies> - <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> - <mainClass>org.onap.so.aai.simulator.AaiSimulatorApplication</mainClass> + <mainClass>org.onap.so.aaisimulator.AaiSimulatorApplication</mainClass> </configuration> <executions> <execution> @@ -61,5 +63,4 @@ </plugin> </plugins> </build> - </project>
\ No newline at end of file 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/aaisimulator/AaiSimulatorApplication.java index 26f52e32..bb1b190d 100644 --- 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/aaisimulator/AaiSimulatorApplication.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator; +package org.onap.so.aaisimulator; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; 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/aaisimulator/configration/ApplicationConfigration.java index b1f17796..2a55760b 100644 --- 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/aaisimulator/configration/ApplicationConfigration.java @@ -17,12 +17,12 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.configration; +package org.onap.so.aaisimulator.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 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; 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..1dc483f7 --- /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,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.configration; + +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.simulator.configuration.SimulatorSecurityConfigurer; +import org.onap.so.simulator.model.UserCredentials; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Configuration +@EnableWebSecurity +public class WebSecurityConfigImpl extends SimulatorSecurityConfigurer { + + @Autowired + public WebSecurityConfigImpl(final UserCredentials userCredentials) { + super(userCredentials.getUsers()); + } + + @Override + protected void configure(final HttpSecurity http) throws Exception { + http.csrf().disable().authorizeRequests().antMatchers(Constants.BUSINESS_URL + "/**/**").authenticated().and() + .httpBasic(); + } + +} 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/aaisimulator/controller/AaiSimulatorController.java index af0a0150..f5912908 100644 --- 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/aaisimulator/controller/AaiSimulatorController.java @@ -17,11 +17,11 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.controller; +package org.onap.so.aaisimulator.controller; -import static org.onap.so.aai.simulator.utils.Constants.HEALTHY; +import static org.onap.so.aaisimulator.utils.Constants.HEALTHY; import javax.ws.rs.core.MediaType; -import org.onap.so.aai.simulator.utils.Constants; +import org.onap.so.aaisimulator.utils.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; 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/aaisimulator/controller/BusinessController.java index 0189a427..190d86e6 100644 --- 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/aaisimulator/controller/BusinessController.java @@ -17,13 +17,13 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.controller; +package org.onap.so.aaisimulator.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 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; @@ -31,9 +31,9 @@ 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.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; 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/aaisimulator/controller/NodesController.java index 4fa4d408..9e93cc3b 100644 --- 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/aaisimulator/controller/NodesController.java @@ -17,23 +17,23 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.controller; +package org.onap.so.aaisimulator.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 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.LinkedHashMap; 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.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.NodeServiceInstance; +import org.onap.so.aaisimulator.models.Results; +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; @@ -67,7 +67,6 @@ public class NodesController { } @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) { @@ -85,10 +84,10 @@ public class NodesController { switch (value) { case PATHED: LOGGER.info("found project {} in cache", nodeServiceInstance); - final Map<String, Object> map = new HashMap<>(); + final Map<String, Object> map = new LinkedHashMap<>(); map.put(RESOURCE_TYPE, nodeServiceInstance.getResourceType()); map.put(RESOURCE_LINK, nodeServiceInstance.getResourceLink()); - return ResponseEntity.ok(new Result(map)); + return ResponseEntity.ok(new Results(map)); case RAW: final Optional<ServiceInstance> serviceInstance = customerCacheServiceProvider.getServiceInstance(nodeServiceInstance.getGlobalCustomerId(), @@ -103,8 +102,5 @@ public class NodesController { } 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/aaisimulator/controller/OwningEntityController.java index e3d6b4f7..ec6412c2 100644 --- 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/aaisimulator/controller/OwningEntityController.java @@ -17,12 +17,12 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.controller; +package org.onap.so.aaisimulator.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 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; @@ -30,9 +30,9 @@ 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.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Results; +import org.onap.so.aaisimulator.service.providers.OwnEntityCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -78,8 +78,7 @@ public class OwningEntityController { return ResponseEntity.accepted().build(); } - @GetMapping(value = "{owning-entity-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @GetMapping(value = "{owning-entity-id}", 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, @@ -101,7 +100,7 @@ public class OwningEntityController { case COUNT: final Map<String, Object> map = new HashMap<>(); map.put(OWNING_ENTITY, 1); - return ResponseEntity.ok(new Result(map)); + return ResponseEntity.ok(new Results(map)); default: break; } 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/aaisimulator/controller/ProjectController.java index 0c3b3b7b..8a7c1b8a 100644 --- 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/aaisimulator/controller/ProjectController.java @@ -17,12 +17,12 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.controller; +package org.onap.so.aaisimulator.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 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; @@ -30,9 +30,9 @@ 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.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Results; +import org.onap.so.aaisimulator.service.providers.ProjectCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -76,8 +76,7 @@ public class ProjectController { } - @GetMapping(value = "/{project-name}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @GetMapping(value = "/{project-name}", 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, @@ -99,7 +98,7 @@ public class ProjectController { case COUNT: final Map<String, Object> map = new HashMap<>(); map.put(PROJECT, 1); - return ResponseEntity.ok(new Result(map)); + return ResponseEntity.ok(new Results(map)); default: break; } 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/aaisimulator/models/Format.java index f6ff2403..1c851fc3 100644 --- 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/aaisimulator/models/Format.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.models; +package org.onap.so.aaisimulator.models; /** * @author waqas.ikram@ericsson.com 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/aaisimulator/models/NodeServiceInstance.java index f549850d..4a645915 100644 --- 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/aaisimulator/models/NodeServiceInstance.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.models; +package org.onap.so.aaisimulator.models; import java.io.Serializable; 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/aaisimulator/models/Results.java index 6aa92562..8dc20242 100644 --- 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/aaisimulator/models/Results.java @@ -17,26 +17,29 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.models; +package org.onap.so.aaisimulator.models; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Map; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonRootName; +import com.fasterxml.jackson.annotation.JsonProperty; /** * @author waqas.ikram@ericsson.com * */ -@JsonRootName(value = "result") -public class Result { +public class Results implements Serializable { + private static final long serialVersionUID = 3967660859271162759L; + + @JsonProperty("results") private List<Map<String, Object>> values = new ArrayList<>(); - public Result() {} + public Results() {} - public Result(final Map<String, Object> value) { + public Results(final Map<String, Object> value) { this.values.add(value); } 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/aaisimulator/service/providers/CustomerCacheServiceProvider.java index 713da545..32d5ca0b 100644 --- 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/aaisimulator/service/providers/CustomerCacheServiceProvider.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.service.providers; +package org.onap.so.aaisimulator.service.providers; import java.util.Optional; import org.onap.aai.domain.yang.Customer; 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/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java index c3b5a47d..5c022c95 100644 --- 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/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.service.providers; +package org.onap.so.aaisimulator.service.providers; import java.util.List; import java.util.Optional; @@ -27,7 +27,8 @@ 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.onap.so.aaisimulator.utils.Constants; +import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -100,16 +101,20 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid if (serviceSubscription.isPresent()) { LOGGER.info("Found service subscription ..."); - final List<ServiceInstance> 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); - + final ServiceInstances serviceInstances = serviceSubscription.get().getServiceInstances(); + if (serviceInstances != null) { + final List<ServiceInstance> serviceInstancesList = + serviceInstances.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 result = new ServiceInstances(); + result.getServiceInstance().addAll(serviceInstancesList); + return Optional.of(result); + + } } } } 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/aaisimulator/service/providers/NodesCacheServiceProvider.java index bf444f2f..0dbd45eb 100644 --- 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/aaisimulator/service/providers/NodesCacheServiceProvider.java @@ -17,10 +17,10 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.service.providers; +package org.onap.so.aaisimulator.service.providers; import java.util.Optional; -import org.onap.so.aai.simulator.models.NodeServiceInstance; +import org.onap.so.aaisimulator.models.NodeServiceInstance; /** * @author waqas.ikram@ericsson.com 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/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java index 0f0ac114..156abd24 100644 --- 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/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java @@ -17,12 +17,13 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.service.providers; +package org.onap.so.aaisimulator.service.providers; -import static org.onap.so.aai.simulator.utils.Constants.NODES_CACHE; +import static org.onap.so.aaisimulator.utils.Constants.NODES_CACHE; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; -import org.onap.so.aai.simulator.models.NodeServiceInstance; +import org.onap.so.aaisimulator.models.NodeServiceInstance; +import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; 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/aaisimulator/service/providers/OwnEntityCacheServiceProvider.java index a7b6409c..e34aa70a 100644 --- 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/aaisimulator/service/providers/OwnEntityCacheServiceProvider.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.service.providers; +package org.onap.so.aaisimulator.service.providers; import java.util.Optional; import org.onap.aai.domain.yang.OwningEntity; 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/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java index 6b7af022..58a8b1e6 100644 --- 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/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java @@ -17,14 +17,15 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.service.providers; +package org.onap.so.aaisimulator.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 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.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; 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/aaisimulator/service/providers/ProjectCacheServiceProvider.java index 59060f27..60f763c7 100644 --- 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/aaisimulator/service/providers/ProjectCacheServiceProvider.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.service.providers; +package org.onap.so.aaisimulator.service.providers; import java.util.Optional; import org.onap.aai.domain.yang.Project; 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/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java index 4fca3119..3ddefbe6 100644 --- 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/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java @@ -17,14 +17,15 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.service.providers; +package org.onap.so.aaisimulator.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 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.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; 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/aaisimulator/utils/Constants.java index 3d1f85df..f81d6bd1 100644 --- 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/aaisimulator/utils/Constants.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.utils; +package org.onap.so.aaisimulator.utils; /** * @author waqas.ikram@ericsson.com 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/aaisimulator/utils/RequestError.java index 471e884d..782625f7 100644 --- 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/aaisimulator/utils/RequestError.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.utils; +package org.onap.so.aaisimulator.utils; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; 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/aaisimulator/utils/RequestErrorBuilder.java index 9dbd4a3d..f3742220 100644 --- 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/aaisimulator/utils/RequestErrorBuilder.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.utils; +package org.onap.so.aaisimulator.utils; import java.util.Arrays; import java.util.List; 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/aaisimulator/utils/ServiceException.java index ba2ee782..7ba47fa7 100644 --- 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/aaisimulator/utils/ServiceException.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.utils; +package org.onap.so.aaisimulator.utils; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; 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/aaisimulator/utils/Utils.java index 81deb86b..1963728c 100644 --- 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/aaisimulator/utils/Utils.java @@ -17,10 +17,10 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.utils; +package org.onap.so.aaisimulator.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 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; diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/application.yaml b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/application.yaml index d4f42992..de819447 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/application.yaml +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/application.yaml @@ -3,15 +3,18 @@ server: tomcat: max-threads: 4 ssl: - key-store: classpath:keystore/org.onap.so.p12 - key-store-password: 'u!@JQoYD])@ykq.NKM,O7iA.' - keyStoreType: PKCS12 + key-store: classpath:keystore/org.onap.so.p12 + key-store-password: u!@JQoYD])@ykq.NKM,O7iA. + keyStoreType: PKCS12 ssl-enable: true - spring: security: - username: aai - #password: aai.onap.org:demo123456! - password: $2a$04$crRntT01fAF4kb48mxlvgu68/silcLg.czC1LxQsKTdWuDBPpO3YO - role: VID -
\ No newline at end of file + users: + - username: aai + #password: aai.onap.org:demo123456! + password: $2a$04$crRntT01fAF4kb48mxlvgu68/silcLg.czC1LxQsKTdWuDBPpO3YO + role: VID + - username: aai@aai.onap.org + #password: demo123456! + password: $2a$04$06VCpDvW5ztE7WOvhhvAtOx7JHLghECyZIzOShIbXLWpnshMva8T6 + role: VID
\ No newline at end of file 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/aaisimulator/controller/AaiSimulatorControllerTest.java index 59d3a556..610aaa70 100644 --- 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/aaisimulator/controller/AaiSimulatorControllerTest.java @@ -17,12 +17,12 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.controller; +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.aai.simulator.utils.Constants; +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; 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/aaisimulator/controller/BusinessControllerTest.java index ed9a129d..e7d07859 100644 --- 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/aaisimulator/controller/BusinessControllerTest.java @@ -17,22 +17,22 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.controller; +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.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 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; @@ -43,13 +43,13 @@ 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.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.onap.so.simulator.model.UserCredentials; 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; @@ -83,8 +83,8 @@ public class BusinessControllerTest { @Autowired private TestRestTemplate restTemplate; - @Value("${spring.security.username}") - private String username; + @Autowired + private UserCredentials userCredentials; @Autowired private CustomerCacheServiceProvider cacheServiceProvider; @@ -192,7 +192,7 @@ public class BusinessControllerTest { invokeHttpPut(url, getServiceInstance()); final String serviceInstanceUrl = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCES_URL - + "?service-instance-name=" + SERVICE_NAME; + + "?depth=2&service-instance-name=" + SERVICE_NAME; final ResponseEntity<ServiceInstances> actual = restTemplate.exchange(serviceInstanceUrl, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), ServiceInstances.class); @@ -208,6 +208,28 @@ public class BusinessControllerTest { } @Test + public void test_getSericeInstance_usingServiceInstanceName_returnRequestErrorIfnoServiceInstanceFound() + throws Exception { + + + final ResponseEntity<Void> response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + final String serviceInstanceUrl = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCES_URL + + "?depth=2&service-instance-name=" + SERVICE_NAME; + + final ResponseEntity<RequestError> actual = restTemplate.exchange(serviceInstanceUrl, HttpMethod.GET, + new HttpEntity<>(getHttpHeaders()), RequestError.class); + + assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + assertNotNull(actual.getBody().getServiceException()); + + } + + @Test public void test_getSericeInstance_usingServiceInstanceId_ableToRetrieveServiceInstanceFromCache() throws Exception { @@ -384,7 +406,7 @@ public class BusinessControllerTest { } private HttpHeaders getHttpHeaders() { - return TestUtils.getHttpHeaders(username); + return TestUtils.getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); } private String getServiceInstance() throws Exception, IOException { 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/aaisimulator/controller/NodesControllerTest.java index 5ea6dff0..e67d0987 100644 --- 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/aaisimulator/controller/NodesControllerTest.java @@ -17,35 +17,35 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.controller; +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.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 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.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.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Results; +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.onap.so.simulator.model.UserCredentials; 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; @@ -75,8 +75,8 @@ public class NodesControllerTest { @Autowired private TestRestTemplate restTemplate; - @Value("${spring.security.username}") - private String username; + @Autowired + private UserCredentials userCredentials; @Autowired private NodesCacheServiceProvider nodesCacheServiceProvider; @@ -130,14 +130,14 @@ public class NodesControllerTest { final ResponseEntity<Void> response2 = invokeHttpPut(url, getServiceInstance()); assertEquals(HttpStatus.ACCEPTED, response2.getStatusCode()); - final ResponseEntity<Result> actual = restTemplate.exchange( + final ResponseEntity<Results> actual = restTemplate.exchange( getNodesEndPointUrl() + SERVICE_INSTANCE_URL + "?format=" + Format.PATHED.getValue(), HttpMethod.GET, - new HttpEntity<>(getHttpHeaders()), Result.class); + new HttpEntity<>(getHttpHeaders()), Results.class); assertEquals(HttpStatus.OK, actual.getStatusCode()); assertTrue(actual.hasBody()); - final Result result = actual.getBody(); + final Results result = actual.getBody(); assertNotNull(result.getValues()); assertFalse(result.getValues().isEmpty()); @@ -175,6 +175,6 @@ public class NodesControllerTest { } private HttpHeaders getHttpHeaders() { - return TestUtils.getHttpHeaders(username); + return TestUtils.getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); } } 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/aaisimulator/controller/OwningEntityControllerTest.java index bbb2cad7..7aabc665 100644 --- 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/aaisimulator/controller/OwningEntityControllerTest.java @@ -17,29 +17,29 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.controller; +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.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 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.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.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Results; +import org.onap.so.aaisimulator.service.providers.OwnEntityCacheServiceProvider; +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.onap.so.simulator.model.UserCredentials; 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; @@ -74,8 +74,8 @@ public class OwningEntityControllerTest { @Autowired private TestRestTemplate restTemplate; - @Value("${spring.security.username}") - private String username; + @Autowired + private UserCredentials userCredentials; @Autowired private OwnEntityCacheServiceProvider cacheServiceProvider; @@ -112,12 +112,12 @@ public class OwningEntityControllerTest { assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - final ResponseEntity<Result> actualResponse = - invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Result.class); + final ResponseEntity<Results> actualResponse = + invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class); assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); assertTrue(actualResponse.hasBody()); - final Result result = actualResponse.getBody(); + final Results result = actualResponse.getBody(); assertNotNull(result.getValues()); assertFalse(result.getValues().isEmpty()); assertEquals(1, result.getValues().get(0).get(Constants.OWNING_ENTITY)); @@ -153,7 +153,11 @@ public class OwningEntityControllerTest { } private <T> ResponseEntity<T> invokeHttpGet(final String url, final Class<T> clazz) { - return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(username)), clazz); + return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(getUsername())), clazz); + } + + private String getUsername() { + return userCredentials.getUsers().iterator().next().getUsername(); } private ResponseEntity<Void> invokeHttpPut(final String url, final Object obj) { @@ -162,7 +166,7 @@ public class OwningEntityControllerTest { } private HttpEntity<?> getHttpEntity(final Object obj) { - return new HttpEntity<>(obj, getHttpHeaders(username)); + return new HttpEntity<>(obj, getHttpHeaders(getUsername())); } private String getOwningEntityEndPointUrl() { 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/aaisimulator/controller/ProjectControllerTest.java index ba6ad978..d4f686db 100644 --- 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/aaisimulator/controller/ProjectControllerTest.java @@ -17,27 +17,27 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.controller; +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.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 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.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.onap.so.aaisimulator.models.Results; +import org.onap.so.aaisimulator.service.providers.ProjectCacheServiceProvider; +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.onap.so.simulator.model.UserCredentials; 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; @@ -74,8 +74,8 @@ public class ProjectControllerTest { @Autowired private TestRestTemplate restTemplate; - @Value("${spring.security.username}") - private String username; + @Autowired + private UserCredentials userCredentials; @Autowired private ProjectCacheServiceProvider cacheServiceProvider; @@ -135,19 +135,19 @@ public class ProjectControllerTest { assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - final ResponseEntity<Result> actualResponse = - invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=count", Result.class); + final ResponseEntity<Results> actualResponse = + invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=count", Results.class); assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); assertTrue(actualResponse.hasBody()); - final Result result = actualResponse.getBody(); + final Results result = actualResponse.getBody(); assertNotNull(result.getValues()); assertFalse(result.getValues().isEmpty()); assertEquals(1, result.getValues().get(0).get(Constants.PROJECT)); } private <T> ResponseEntity<T> invokeHttpGet(final String url, final Class<T> clazz) { - return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(username)), clazz); + return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(getUsername())), clazz); } private ResponseEntity<Void> invokeHttpPut(final String url, final Object obj) { @@ -156,7 +156,11 @@ public class ProjectControllerTest { } private HttpEntity<?> getHttpEntity(final Object obj) { - return new HttpEntity<>(obj, getHttpHeaders(username)); + return new HttpEntity<>(obj, getHttpHeaders(getUsername())); + } + + private String getUsername() { + return userCredentials.getUsers().iterator().next().getUsername(); } private String getProjectEndPointUrl() { 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/aaisimulator/controller/configuration/TestRestTemplateConfigration.java index 6e8ccac6..7683721c 100644 --- 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/aaisimulator/controller/configuration/TestRestTemplateConfigration.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.controller.configuration; +package org.onap.so.aaisimulator.controller.configuration; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLSession; 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/aaisimulator/utils/TestConstants.java index f57c946d..f59e8b58 100644 --- 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/aaisimulator/utils/TestConstants.java @@ -17,7 +17,9 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.utils; +package org.onap.so.aaisimulator.utils; + +import org.onap.so.aaisimulator.utils.Constants; /** * @author waqas.ikram@ericsson.com 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/aaisimulator/utils/TestUtils.java index 73e43b10..4dfe9c2c 100644 --- 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/aaisimulator/utils/TestUtils.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.utils; +package org.onap.so.aaisimulator.utils; import java.io.File; import java.io.IOException; @@ -33,7 +33,6 @@ import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; * @author waqas.ikram@ericsson.com * */ - public class TestUtils { private static final String PASSWORD = "aai.onap.org:demo123456!"; diff --git a/plans/so/integration-etsi-testing/so-simulators/common/pom.xml b/plans/so/integration-etsi-testing/so-simulators/common/pom.xml new file mode 100644 index 00000000..497e8213 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/common/pom.xml @@ -0,0 +1,38 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.so.simulators</groupId> + <artifactId>so-simulators</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + <artifactId>common</artifactId> + <properties> + <version.equalsverifier>2.5.1</version.equalsverifier> + <version.openpojo>0.8.6</version.openpojo> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>nl.jqno.equalsverifier</groupId> + <artifactId>equalsverifier</artifactId> + <version>${version.equalsverifier}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.openpojo</groupId> + <artifactId>openpojo</artifactId> + <version>${version.openpojo}</version> + </dependency> + </dependencies> +</project>
\ No newline at end of file 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/common/src/main/java/org/onap/so/simulator/cache/provider/AbstractCacheServiceProvider.java index 4a45e81e..ae31a3ff 100644 --- 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/common/src/main/java/org/onap/so/simulator/cache/provider/AbstractCacheServiceProvider.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.service.providers; +package org.onap.so.simulator.cache.provider; import java.util.concurrent.ConcurrentHashMap; import org.slf4j.Logger; @@ -26,8 +26,7 @@ import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; /** - * @author waqas.ikram@ericsson.com - * + * @author Waqas Ikram (waqas.ikram@ericsson.com) */ public abstract class AbstractCacheServiceProvider { 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/common/src/main/java/org/onap/so/simulator/configuration/SimulatorSecurityConfigurer.java index a4a1fb11..5d59cbbd 100644 --- 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/common/src/main/java/org/onap/so/simulator/configuration/SimulatorSecurityConfigurer.java @@ -17,16 +17,16 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.configration; +package org.onap.so.simulator.configuration; -import org.onap.so.aai.simulator.utils.Constants; +import java.util.List; +import org.onap.so.simulator.model.User; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; 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.authentication.configurers.provisioning.InMemoryUserDetailsManagerConfigurer; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @@ -34,27 +34,14 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; * @author waqas.ikram@ericsson.com * */ -@Configuration -@EnableWebSecurity -public class WebSecurityConfigImpl extends WebSecurityConfigurerAdapter { +public abstract class SimulatorSecurityConfigurer extends WebSecurityConfigurerAdapter { + private static final Logger LOGGER = LoggerFactory.getLogger(SimulatorSecurityConfigurer.class); - 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; - } + private final List<User> users; - @Override - protected void configure(final HttpSecurity http) throws Exception { - http.csrf().disable().authorizeRequests().antMatchers(Constants.BUSINESS_URL + "/**/**").authenticated().and() - .httpBasic(); + public SimulatorSecurityConfigurer(final List<User> users) { + this.users = users; } @Bean @@ -64,8 +51,15 @@ public class WebSecurityConfigImpl extends WebSecurityConfigurerAdapter { @Autowired public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()).withUser(username).password(password) - .roles(role); + final InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder> inMemoryAuthentication = + auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()); + for (int index = 0; index < users.size(); index++) { + final User user = users.get(index); + LOGGER.info("Adding {} to InMemoryUserDetailsManager ...", user); + inMemoryAuthentication.withUser(user.getUsername()).password(user.getPassword()).roles(user.getRole()); + if (index < users.size()) { + inMemoryAuthentication.and(); + } + } } - } diff --git a/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/model/User.java b/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/model/User.java new file mode 100644 index 00000000..48d5622a --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/model/User.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.simulator.model; + +import static org.springframework.util.ObjectUtils.nullSafeEquals; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class User { + private String username; + private String password; + private String role; + + /** + * @return the username + */ + public String getUsername() { + return username; + } + + /** + * @param username the username to set + */ + public void setUsername(final String username) { + this.username = username; + } + + /** + * @return the password + */ + public String getPassword() { + return password; + } + + /** + * @param password the password to set + */ + public void setPassword(final String password) { + this.password = password; + } + + /** + * @return the role + */ + public String getRole() { + return role; + } + + /** + * @param role the role to set + */ + public void setRole(final String role) { + this.role = role; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((password == null) ? 0 : password.hashCode()); + result = prime * result + ((role == null) ? 0 : role.hashCode()); + result = prime * result + ((username == null) ? 0 : username.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof User) { + final User other = (User) obj; + return nullSafeEquals(this.username, other.username) && nullSafeEquals(this.password, other.password) + && nullSafeEquals(this.role, other.role); + } + return false; + } + + @Override + public String toString() { + return "UserCredential [username=" + username + ", password=" + password + ", role=" + role + "]"; + } + + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/model/UserCredentials.java b/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/model/UserCredentials.java new file mode 100644 index 00000000..f12c2475 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/common/src/main/java/org/onap/so/simulator/model/UserCredentials.java @@ -0,0 +1,66 @@ +/*- + * ============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.simulator.model; + +import java.util.ArrayList; +import java.util.List; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; +import org.springframework.util.ObjectUtils; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Component +@ConfigurationProperties(prefix = "spring.security") +public class UserCredentials { + + private final List<User> users = new ArrayList<>(); + + public List<User> getUsers() { + return users; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((users == null) ? 0 : users.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + + if (obj instanceof UserCredentials) { + final UserCredentials other = (UserCredentials) obj; + return ObjectUtils.nullSafeEquals(users, other.users); + } + + return false; + } + + @Override + public String toString() { + return "UserCredentials [userCredentials=" + users + "]"; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/common/src/test/java/org/onap/so/simulator/model/PojoClassesTest.java b/plans/so/integration-etsi-testing/so-simulators/common/src/test/java/org/onap/so/simulator/model/PojoClassesTest.java new file mode 100644 index 00000000..8ae9b8b7 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/common/src/test/java/org/onap/so/simulator/model/PojoClassesTest.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.simulator.model; + +import org.junit.Test; +import org.onap.so.simulator.model.UserCredentials; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; + + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class PojoClassesTest { + + @Test + public void test_UserCredentials_class() throws ClassNotFoundException { + verify(UserCredentials.class); + validate(UserCredentials.class); + } + + @Test + public void test_User_class() throws ClassNotFoundException { + verify(User.class); + validate(User.class); + } + + private void validate(final Class<?> clazz) { + final Validator validator = ValidatorBuilder.create().with(new SetterTester()).with(new GetterTester()).build(); + validator.validate(PojoClassFactory.getPojoClass(clazz)); + } + + private void verify(final Class<?> clazz) { + EqualsVerifier.forClass(clazz).suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS).verify(); + } + +} 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 @@ </assembly> </build> </image> + <image> + <name>simulators/sdnc-simulator</name> + <build> + <cleanup>try</cleanup> + <dockerFileDir>docker-files</dockerFileDir> + <dockerFile>Dockerfile.so-simulator-base-image</dockerFile> + <tags> + <tag>${project.version}</tag> + </tags> + <assembly> + <inline> + <dependencySets> + <dependencySet> + <includes> + <include>org.onap.so.simulators:sdnc-simulator</include> + </includes> + <outputFileNameMapping>app.jar</outputFileNameMapping> + </dependencySet> + </dependencySets> + </inline> + </assembly> + </build> + </image> </images> </configuration> <executions> @@ -110,14 +133,19 @@ </build> <dependencies> <dependency> - <groupId>org.onap.so.simulators</groupId> + <groupId>${project.parent.groupId}</groupId> <artifactId>sdc-simulator</artifactId> <version>${project.version}</version> </dependency> <dependency> - <groupId>org.onap.so.simulators</groupId> + <groupId>${project.parent.groupId}</groupId> <artifactId>aai-simulator</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>sdnc-simulator</artifactId> + <version>${project.version}</version> + </dependency> </dependencies> </project>
\ 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..08d962b7 100644 --- a/plans/so/integration-etsi-testing/so-simulators/pom.xml +++ b/plans/so/integration-etsi-testing/so-simulators/pom.xml @@ -17,8 +17,10 @@ </properties> <modules> + <module>common</module> <module>sdc-simulator</module> <module>aai-simulator</module> + <module>sdnc-simulator</module> <module>package</module> </modules> 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 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> - <mainClass>org.onap.so.sdc.simulator.SdcSimulatorApplication</mainClass> + <mainClass>org.onap.so.sdcsimulator.SdcSimulatorApplication</mainClass> </configuration> <executions> <execution> 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/sdc/simulator/SdcSimulatorApplication.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/SdcSimulatorApplication.java index abb183b1..25d21e53 100644 --- 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/sdcsimulator/SdcSimulatorApplication.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.sdc.simulator; +package org.onap.so.sdcsimulator; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; 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/sdcsimulator/configration/WebSecurityConfigImpl.java index bf971785..b2c51369 100644 --- 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/sdcsimulator/configration/WebSecurityConfigImpl.java @@ -17,9 +17,9 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.sdc.simulator.configration; +package org.onap.so.sdcsimulator.configration; -import org.onap.so.sdc.simulator.utils.Constants; +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; 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/sdcsimulator/controller/CatalogController.java index 01c0b39f..60c1865d 100644 --- 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/sdcsimulator/controller/CatalogController.java @@ -17,27 +17,27 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.sdc.simulator.controller; +package org.onap.so.sdcsimulator.controller; -import static org.onap.so.sdc.simulator.utils.Constants.CATALOG_URL; +import static org.onap.so.sdcsimulator.utils.Constants.CATALOG_URL; import java.util.Optional; import javax.ws.rs.core.MediaType; -import org.onap.so.sdc.simulator.providers.ResourceProvider; +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.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.RestController; /** * @author Waqas Ikram (waqas.ikram@est.tech) * */ -@RestController +@Controller @RequestMapping(path = CATALOG_URL) public class CatalogController { private static final Logger LOGGER = LoggerFactory.getLogger(CatalogController.class); 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/sdcsimulator/controller/SdcSimulatorController.java index 2baf2038..662c0bda 100644 --- 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/sdcsimulator/controller/SdcSimulatorController.java @@ -18,27 +18,29 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.sdc.simulator.controller; +package org.onap.so.sdcsimulator.controller; import javax.ws.rs.core.MediaType; -import org.onap.so.sdc.simulator.utils.Constants; +import org.onap.so.sdcsimulator.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; -import org.springframework.web.bind.annotation.RestController; /** * @author Waqas Ikram (waqas.ikram@est.tech) */ -@RestController +@Controller @RequestMapping(path = Constants.BASE_URL) public class SdcSimulatorController { private static final Logger LOGGER = LoggerFactory.getLogger(SdcSimulatorController.class); - @GetMapping(value = "/healthcheck", produces = MediaType.APPLICATION_JSON) + @ResponseBody + @GetMapping(value = "/healthcheck", produces = MediaType.TEXT_PLAIN) @ResponseStatus(code = HttpStatus.OK) public String healthCheck() { LOGGER.info("Running health check ..."); 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/sdcsimulator/providers/ResourceProvider.java index 83994b4b..4d5dcdd0 100644 --- 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/sdcsimulator/providers/ResourceProvider.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.sdc.simulator.providers; +package org.onap.so.sdcsimulator.providers; import java.io.IOException; import java.io.InputStream; 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/sdcsimulator/providers/ResourceProviderImpl.java index efc98de7..192ac896 100644 --- 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/sdcsimulator/providers/ResourceProviderImpl.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.sdc.simulator.providers; +package org.onap.so.sdcsimulator.providers; import java.io.IOException; import java.io.InputStream; @@ -26,7 +26,7 @@ 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.onap.so.sdcsimulator.utils.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; 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/sdcsimulator/controller/CatalogControllerTest.java index 98ec448e..ca55f495 100644 --- 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/sdcsimulator/controller/CatalogControllerTest.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.sdc.simulator.controller; +package org.onap.so.sdcsimulator.controller; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -27,8 +27,9 @@ 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.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; 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/sdcsimulator/controller/SdcSimulatorControllerTest.java index 300b62a8..9789f812 100644 --- 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/sdcsimulator/controller/SdcSimulatorControllerTest.java @@ -18,12 +18,12 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.sdc.simulator.controller; +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.sdc.simulator.utils.Constants; +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; 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/sdcsimulator/providers/ResourceProviderImplTest.java index b112c403..e575f2a5 100644 --- 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/sdcsimulator/providers/ResourceProviderImplTest.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.sdc.simulator.providers; +package org.onap.so.sdcsimulator.providers; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertFalse; @@ -30,7 +30,8 @@ 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.onap.so.sdcsimulator.providers.ResourceProviderImpl; +import org.onap.so.sdcsimulator.utils.Constants; import org.springframework.core.io.ClassPathResource; import org.springframework.util.StreamUtils; 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..0806d88c --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/pom.xml @@ -0,0 +1,68 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.so.simulators</groupId> + <artifactId>so-simulators</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + <artifactId>sdnc-simulator</artifactId> + <name>${project.artifactId}</name> + <properties> + <version.generic-resource-api-client>1.5.2</version.generic-resource-api-client> + </properties> + <dependencies> + <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>common</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.sdnc.northbound</groupId> + <artifactId>generic-resource-api-client</artifactId> + <version>${version.generic-resource-api-client}</version> + <exclusions> + <exclusion> + <groupId>javax.ws.rs</groupId> + <artifactId>jsr311-api</artifactId> + </exclusion> + <exclusion> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <mainClass>org.onap.so.sdncsimulator.SdncSimulatorApplication</mainClass> + </configuration> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project>
\ 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/configration/ApplicationConfigration.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/configration/ApplicationConfigration.java new file mode 100644 index 00000000..d51bd023 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/configration/ApplicationConfigration.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.sdncsimulator.configration; + +import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_TOPOLOGY_OPERATION_CACHE; +import java.util.Arrays; +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; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Configuration +public class ApplicationConfigration { + + @Bean + public CacheManager cacheManager() { + final SimpleCacheManager manager = new SimpleCacheManager(); + manager.setCaches(Arrays.asList(getCache(SERVICE_TOPOLOGY_OPERATION_CACHE))); + return manager; + } + + private Cache getCache(final String name) { + return new ConcurrentMapCache(name); + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/configration/WebSecurityConfigImpl.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/configration/WebSecurityConfigImpl.java new file mode 100644 index 00000000..261b66d7 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/configration/WebSecurityConfigImpl.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.sdncsimulator.configration; + +import static org.onap.so.sdncsimulator.utils.Constants.OPERATIONS_URL; +import org.onap.so.simulator.configuration.SimulatorSecurityConfigurer; +import org.onap.so.simulator.model.UserCredentials; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Configuration +@EnableWebSecurity +public class WebSecurityConfigImpl extends SimulatorSecurityConfigurer { + + @Autowired + public WebSecurityConfigImpl(final UserCredentials userCredentials) { + super(userCredentials.getUsers()); + } + + @Override + protected void configure(final HttpSecurity http) throws Exception { + http.csrf().disable().authorizeRequests().antMatchers(OPERATIONS_URL + "/**/**").authenticated().and() + .httpBasic(); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java new file mode 100644 index 00000000..00740298 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java @@ -0,0 +1,81 @@ +/*- + * ============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.onap.so.sdncsimulator.utils.Constants.OPERATIONS_URL; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.MediaType; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; +import org.onap.so.sdncsimulator.models.InputRequest; +import org.onap.so.sdncsimulator.models.Output; +import org.onap.so.sdncsimulator.models.OutputRequest; +import org.onap.so.sdncsimulator.providers.ServiceOperationsCacheServiceProvider; +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.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Controller +@RequestMapping(path = OPERATIONS_URL) +public class OperationsController { + + private static final Logger LOGGER = LoggerFactory.getLogger(OperationsController.class); + + private final ServiceOperationsCacheServiceProvider cacheServiceProvider; + + @Autowired + public OperationsController(final ServiceOperationsCacheServiceProvider cacheServiceProvider) { + this.cacheServiceProvider = cacheServiceProvider; + } + + @PostMapping(value = "/GENERIC-RESOURCE-API:service-topology-operation/", + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> postServiceOperationInformation( + @RequestBody final InputRequest<GenericResourceApiServiceOperationInformation> inputRequest, + final HttpServletRequest request) { + LOGGER.info("Request Received {} ...", inputRequest); + + final GenericResourceApiServiceOperationInformation apiServiceOperationInformation = inputRequest.getInput(); + + if (apiServiceOperationInformation == null) { + return ResponseEntity.badRequest().build(); + } + + final Output output = cacheServiceProvider.putServiceOperationInformation(apiServiceOperationInformation); + final OutputRequest outputRequest = new OutputRequest(output); + + if (output.getResponseCode().equals(HttpStatus.OK.toString())) { + return ResponseEntity.ok(outputRequest); + } + + return ResponseEntity.badRequest().body(outputRequest); + + } + +} 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..98655e10 --- /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,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.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.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 (waqas.ikram@est.tech) + * + */ +@Controller +@RequestMapping(path = Constants.BASE_URL) +public class SdncSimulatorController { + private static final Logger LOGGER = LoggerFactory.getLogger(SdncSimulatorController.class); + + @ResponseBody + @GetMapping(value = "/healthcheck", produces = MediaType.TEXT_PLAIN) + @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/models/InputRequest.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/InputRequest.java new file mode 100644 index 00000000..d4e83fce --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/InputRequest.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.sdncsimulator.models; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class InputRequest<T> { + + private T input; + + /** + * @return the input + */ + public T getInput() { + return input; + } + + /** + * @param input the input to set + */ + public void setInput(final T input) { + this.input = input; + } + + @JsonIgnore + @Override + public String toString() { + return "Input [input=" + input + "]"; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/Output.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/Output.java new file mode 100644 index 00000000..554989db --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/Output.java @@ -0,0 +1,153 @@ +/*- + * ============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.models; + +import org.onap.sdnc.northbound.client.model.GenericResourceApiInstanceReference; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class Output { + + @JsonProperty("response-message") + private String responseMessage; + + @JsonProperty("ack-final-indicator") + private String ackFinalIndicator; + + @JsonProperty("svc-request-id") + private String svcRequestId; + + @JsonProperty("response-code") + private String responseCode; + + @JsonProperty("service-response-information") + private GenericResourceApiInstanceReference serviceResponseInformation = null; + + /** + * @return the responseMessage + */ + public String getResponseMessage() { + return responseMessage; + } + + /** + * @param responseMessage the responseMessage to set + */ + public void setResponseMessage(final String responseMessage) { + this.responseMessage = responseMessage; + } + + /** + * @return the ackFinalIndicator + */ + public String getAckFinalIndicator() { + return ackFinalIndicator; + } + + /** + * @param ackFinalIndicator the ackFinalIndicator to set + */ + public void setAckFinalIndicator(final String ackFinalIndicator) { + this.ackFinalIndicator = ackFinalIndicator; + } + + /** + * @return the svcRequestId + */ + public String getSvcRequestId() { + return svcRequestId; + } + + /** + * @param svcRequestId the svcRequestId to set + */ + public void setSvcRequestId(final String svcRequestId) { + this.svcRequestId = svcRequestId; + } + + /** + * @return the responseCode + */ + public String getResponseCode() { + return responseCode; + } + + /** + * @param responseCode the responseCode to set + */ + public void setResponseCode(final String responseCode) { + this.responseCode = responseCode; + } + + /** + * @return the serviceResponseInformation + */ + public GenericResourceApiInstanceReference getServiceResponseInformation() { + return serviceResponseInformation; + } + + /** + * @param serviceResponseInformation the serviceResponseInformation to set + */ + public void setServiceResponseInformation(final GenericResourceApiInstanceReference serviceResponseInformation) { + this.serviceResponseInformation = serviceResponseInformation; + } + + public Output responseMessage(final String responseMessage) { + this.responseMessage = responseMessage; + return this; + } + + public Output ackFinalIndicator(final String ackFinalIndicator) { + this.ackFinalIndicator = ackFinalIndicator; + return this; + } + + public Output svcRequestId(final String svcRequestId) { + this.svcRequestId = svcRequestId; + return this; + } + + public Output responseCode(final String responseCode) { + this.responseCode = responseCode; + return this; + } + + public Output serviceResponseInformation(final GenericResourceApiInstanceReference serviceResponseInformation) { + this.serviceResponseInformation = serviceResponseInformation; + return this; + } + + + @JsonIgnore + @Override + public String toString() { + return "OutputRequest [responseMessage=" + responseMessage + ", ackFinalIndicator=" + ackFinalIndicator + + ", svcRequestId=" + svcRequestId + ", responseCode=" + responseCode + ", serviceResponseInformation=" + + serviceResponseInformation + "]"; + } + + + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/OutputRequest.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/OutputRequest.java new file mode 100644 index 00000000..97d20568 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/OutputRequest.java @@ -0,0 +1,53 @@ +/*- + * ============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.models; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ + +public class OutputRequest { + @JsonProperty("output") + private Output output; + + public OutputRequest() {} + + public OutputRequest(final Output output) { + this.output = output; + } + + + public Output getOutput() { + return output; + } + + public void setOutput(final Output output) { + this.output = output; + } + + @Override + public String toString() { + return "OutputRequest [output=" + output + "]"; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java new file mode 100644 index 00000000..a0116c48 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java @@ -0,0 +1,42 @@ +/*- + * ============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.providers; + +import java.util.Optional; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceModelInfrastructure; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; +import org.onap.so.sdncsimulator.models.Output; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public interface ServiceOperationsCacheServiceProvider { + + Output putServiceOperationInformation( + final GenericResourceApiServiceOperationInformation apiServiceOperationInformation); + + Optional<GenericResourceApiServiceModelInfrastructure> getGenericResourceApiServiceModelInfrastructure( + final String serviceInstanceId); + + void clearAll(); + + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java new file mode 100644 index 00000000..620742ab --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java @@ -0,0 +1,205 @@ +/*- + * ============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.providers; + +import static org.onap.so.sdncsimulator.utils.Constants.RESTCONF_CONFIG_END_POINT; +import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_TOPOLOGY_OPERATION; +import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_TOPOLOGY_OPERATION_CACHE; +import static org.onap.so.sdncsimulator.utils.Constants.YES; +import static org.onap.so.sdncsimulator.utils.ObjectUtils.getString; +import static org.onap.so.sdncsimulator.utils.ObjectUtils.getStringOrNull; +import static org.onap.so.sdncsimulator.utils.ObjectUtils.isValid; +import java.time.LocalDateTime; +import java.util.Optional; +import org.onap.sdnc.northbound.client.model.GenericResourceApiInstanceReference; +import org.onap.sdnc.northbound.client.model.GenericResourceApiLastActionEnumeration; +import org.onap.sdnc.northbound.client.model.GenericResourceApiLastRpcActionEnumeration; +import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiOperStatusData; +import org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration; +import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestStatusEnumeration; +import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestinformationRequestInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiRpcActionEnumeration; +import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceModelInfrastructure; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServiceData; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceinformationServiceInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServicemodelinfrastructureService; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServicestatusServiceStatus; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyServiceTopology; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier; +import org.onap.so.sdncsimulator.models.Output; +import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; +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.http.HttpStatus; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Service +public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServiceProvider + implements ServiceOperationsCacheServiceProvider { + + + private static final Logger LOGGER = LoggerFactory.getLogger(ServiceOperationsCacheServiceProviderimpl.class); + + @Autowired + public ServiceOperationsCacheServiceProviderimpl(final CacheManager cacheManager) { + super(cacheManager); + } + + @Override + public Output putServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) { + + final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader(); + final String svcRequestId = requestHeader != null ? requestHeader.getSvcRequestId() : null; + + final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation(); + if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) { + final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE); + final String serviceInstanceId = serviceInformation.getServiceInstanceId(); + LOGGER.info("Adding GenericResourceApiServiceOperationInformation to cache with key: {}", + serviceInstanceId); + + final GenericResourceApiServiceModelInfrastructure serviceModelInfrastructure = + new GenericResourceApiServiceModelInfrastructure(); + + final GenericResourceApiServicemodelinfrastructureService service = getServiceItem(input); + serviceModelInfrastructure.addServiceItem(service); + cache.put(serviceInstanceId, serviceModelInfrastructure); + + final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus(); + + return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator()) + .responseCode(serviceStatus.getResponseCode()).responseMessage(serviceStatus.getResponseMessage()) + .svcRequestId(svcRequestId).serviceResponseInformation(new GenericResourceApiInstanceReference() + .instanceId(serviceInstanceId).objectPath(RESTCONF_CONFIG_END_POINT + serviceInstanceId)); + + } + return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString()) + .responseMessage("Service instance not found").svcRequestId(svcRequestId); + } + + @Override + public Optional<GenericResourceApiServiceModelInfrastructure> getGenericResourceApiServiceModelInfrastructure( + final String serviceInstanceId) { + final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE); + + final GenericResourceApiServiceModelInfrastructure value = + cache.get(serviceInstanceId, GenericResourceApiServiceModelInfrastructure.class); + if (value != null) { + return Optional.of(value); + } + return Optional.empty(); + } + + @Override + public void clearAll() { + clearCahce(SERVICE_TOPOLOGY_OPERATION_CACHE); + } + + private GenericResourceApiServicemodelinfrastructureService getServiceItem( + final GenericResourceApiServiceOperationInformation input) { + + final GenericResourceApiServicedataServiceData apiServicedataServiceData = + new GenericResourceApiServicedataServiceData(); + + apiServicedataServiceData.requestInformation(input.getRequestInformation()); + apiServicedataServiceData.serviceRequestInput(input.getServiceRequestInput()); + apiServicedataServiceData.serviceInformation(input.getServiceInformation()); + apiServicedataServiceData.serviceTopology(getServiceTopology(input)); + apiServicedataServiceData.sdncRequestHeader(input.getSdncRequestHeader()); + apiServicedataServiceData.serviceLevelOperStatus(getServiceLevelOperStatus(input)); + + final GenericResourceApiServicestatusServiceStatus serviceStatus = + getServiceStatus(getSvcAction(input.getSdncRequestHeader()), getAction(input.getRequestInformation()), + HttpStatus.OK.toString()); + + return new GenericResourceApiServicemodelinfrastructureService().serviceData(apiServicedataServiceData) + .serviceStatus(serviceStatus); + } + + private String getAction(final GenericResourceApiRequestinformationRequestInformation input) { + return getString(input.getRequestAction(), ""); + } + + private String getSvcAction(final GenericResourceApiSdncrequestheaderSdncRequestHeader input) { + return input != null ? getStringOrNull(input.getSvcAction()) : null; + } + + private GenericResourceApiServicestatusServiceStatus getServiceStatus(final String rpcAction, final String action, + final String responseCode) { + return new GenericResourceApiServicestatusServiceStatus().finalIndicator(YES) + .rpcAction(GenericResourceApiRpcActionEnumeration.fromValue(rpcAction)) + .rpcName(SERVICE_TOPOLOGY_OPERATION).responseTimestamp(LocalDateTime.now().toString()) + .responseCode(responseCode).requestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE) + .responseMessage("").action(action); + } + + private GenericResourceApiOperStatusData getServiceLevelOperStatus( + final GenericResourceApiServiceOperationInformation input) { + return new GenericResourceApiOperStatusData().orderStatus(GenericResourceApiOrderStatusEnumeration.CREATED) + .lastAction(GenericResourceApiLastActionEnumeration + .fromValue(getRequestAction(input.getRequestInformation()))) + .lastRpcAction(GenericResourceApiLastRpcActionEnumeration + .fromValue(getSvcAction(input.getSdncRequestHeader()))); + } + + private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input) { + return input != null ? getStringOrNull(input.getRequestAction()) : null; + } + + private GenericResourceApiServicetopologyServiceTopology getServiceTopology( + final GenericResourceApiServiceOperationInformation input) { + final GenericResourceApiOnapmodelinformationOnapModelInformation modelInformation = + input.getServiceInformation() != null ? input.getServiceInformation().getOnapModelInformation() : null; + return new GenericResourceApiServicetopologyServiceTopology().onapModelInformation(modelInformation) + .serviceTopologyIdentifier(getServiceTopologyIdentifier(input)); + } + + private GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier getServiceTopologyIdentifier( + final GenericResourceApiServiceOperationInformation input) { + final GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier identifier = + new GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier(); + + if (input.getServiceInformation() != null) { + final GenericResourceApiServiceinformationServiceInformation serviceInformation = + input.getServiceInformation(); + identifier.globalCustomerId(serviceInformation.getGlobalCustomerId()) + .serviceType(input.getServiceInformation().getSubscriptionServiceType()) + .serviceInstanceId(input.getServiceInformation().getServiceInstanceId());; + } + + if (input.getServiceRequestInput() != null) { + identifier.serviceInstanceName(input.getServiceRequestInput().getServiceInstanceName()); + } + + return identifier; + + } + +} 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..2d774edd --- /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,43 @@ +/*- + * ============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 OPERATIONS_URL = BASE_URL + "/operations"; + + public static final String SERVICE_TOPOLOGY_OPERATION_CACHE = "service-topology-operation-cache"; + + public static final String HEALTHY = "healthy"; + + public static final String YES = "Y"; + + public static final String SERVICE_TOPOLOGY_OPERATION = "service-topology-operation"; + + public static final String RESTCONF_CONFIG_END_POINT = "restconf/config/GENERIC-RESOURCE-API:services/service/"; + + private Constants() {} +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/ObjectUtils.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/ObjectUtils.java new file mode 100644 index 00000000..833da414 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/ObjectUtils.java @@ -0,0 +1,42 @@ +/*- + * ============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 ObjectUtils { + + public static boolean isValid(final String value) { + return value != null && !value.isEmpty(); + } + + public static String getStringOrNull(final Object obj) { + return getString(obj, null); + } + + public static String getString(final Object obj, String defaultValue) { + return obj != null ? obj.toString() : defaultValue; + } + + private ObjectUtils() {} + +} 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..95b28455 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/resources/application.yaml @@ -0,0 +1,16 @@ +server: + port: 9994 + tomcat: + max-threads: 4 +ssl-enable: false +spring: + security: + users: + - username: mso + #password: Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U + password: $2a$04$f8SB6cW/VI26QvYM6z.GXu7hlEmwnFtePenD8zF18mS3Atu3QNqr2 + role: VID + - username: admin + #password: Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U + password: $2a$04$f8SB6cW/VI26QvYM6z.GXu7hlEmwnFtePenD8zF18mS3Atu3QNqr2 + role: VID
\ 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/OperationsControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java new file mode 100644 index 00000000..af46ab40 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java @@ -0,0 +1,186 @@ +/*- + * ============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 static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Base64; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.sdnc.northbound.client.model.GenericResourceApiInstanceReference; +import org.onap.so.sdncsimulator.models.InputRequest; +import org.onap.so.sdncsimulator.models.Output; +import org.onap.so.sdncsimulator.models.OutputRequest; +import org.onap.so.sdncsimulator.providers.ServiceOperationsCacheServiceProvider; +import org.onap.so.sdncsimulator.utils.Constants; +import org.onap.so.simulator.model.UserCredentials; +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.core.io.ClassPathResource; +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 OperationsControllerTest { + + private static final String SVC_REQUEST_ID = "04fc9f50-87b8-430d-a232-ef24bd6c4150"; + + private static final String SERVICE_INSTANCE_ID = "ccece8fe-13da-456a-baf6-41b3a4a2bc2b"; + + private static final String SERVICE_TOPOLOGY_OPERATION_URL = "/GENERIC-RESOURCE-API:service-topology-operation/"; + + private static final String PASSWORD = "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U"; + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Autowired + private ServiceOperationsCacheServiceProvider cacheServiceProvider; + + @Autowired + private UserCredentials userCredentials; + + + @Test + public void test_postServiceOperationInformation_successfullyAddedToCache() throws Exception { + + final HttpEntity<?> httpEntity = new HttpEntity<>(getRequestInput(), getHttpHeaders()); + final ResponseEntity<OutputRequest> responseEntity = + restTemplate.exchange(getUrl(), HttpMethod.POST, httpEntity, OutputRequest.class); + + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertTrue(responseEntity.hasBody()); + + final OutputRequest actualOutputRequest = responseEntity.getBody(); + assertNotNull(actualOutputRequest); + + final Output actualObject = actualOutputRequest.getOutput(); + + assertNotNull(actualObject); + assertEquals(HttpStatus.OK.toString(), actualObject.getResponseCode()); + assertEquals(Constants.YES, actualObject.getAckFinalIndicator()); + assertEquals(SVC_REQUEST_ID, actualObject.getSvcRequestId()); + assertNotNull(actualObject.getServiceResponseInformation()); + + final GenericResourceApiInstanceReference acutalReference = actualObject.getServiceResponseInformation(); + assertEquals(Constants.RESTCONF_CONFIG_END_POINT + SERVICE_INSTANCE_ID, acutalReference.getObjectPath()); + assertEquals(SERVICE_INSTANCE_ID, acutalReference.getInstanceId()); + assertTrue( + cacheServiceProvider.getGenericResourceApiServiceModelInfrastructure(SERVICE_INSTANCE_ID).isPresent()); + } + + @Test + public void test_postServiceOperationInformation_NullInputRequest_badRequest() throws Exception { + + final HttpEntity<?> httpEntity = new HttpEntity<>(new InputRequest<>(), getHttpHeaders()); + final ResponseEntity<OutputRequest> responseEntity = + restTemplate.exchange(getUrl(), HttpMethod.POST, httpEntity, OutputRequest.class); + + assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); + } + + @Test + public void test_postServiceOperationInformation_NullServiceInstanceId_badRequest() throws Exception { + + final HttpEntity<?> httpEntity = new HttpEntity<>(getInvalidRequestInput(), getHttpHeaders()); + final ResponseEntity<OutputRequest> responseEntity = + restTemplate.exchange(getUrl(), HttpMethod.POST, httpEntity, OutputRequest.class); + + assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); + assertTrue(responseEntity.hasBody()); + + final OutputRequest actualOutputRequest = responseEntity.getBody(); + assertNotNull(actualOutputRequest); + + final Output actualObject = actualOutputRequest.getOutput(); + assertNotNull(actualObject); + assertEquals(HttpStatus.BAD_REQUEST.toString(), actualObject.getResponseCode()); + assertEquals(SVC_REQUEST_ID, actualObject.getSvcRequestId()); + assertEquals(Constants.YES, actualObject.getAckFinalIndicator()); + + } + + private HttpHeaders getHttpHeaders() { + return getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); + } + + private String getUrl() { + return "http://localhost:" + port + Constants.OPERATIONS_URL + SERVICE_TOPOLOGY_OPERATION_URL; + } + + private String getRequestInput() throws IOException { + return getFileAsString(getFile("test-data/input.json").toPath()); + } + + private String getInvalidRequestInput() throws IOException { + return getFileAsString(getFile("test-data/InvalidInput.json").toPath()); + } + + private String getFileAsString(final Path path) throws IOException { + return new String(Files.readAllBytes(path)); + } + + private File getFile(final String file) throws IOException { + return new ClassPathResource(file).getFile(); + } + + private HttpHeaders getHttpHeaders(final String username) { + 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())); + } + + @After + public void after() { + cacheServiceProvider.clearAll(); + } + +} 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<String> object = restTemplate.getForEntity(url, String.class); + + assertEquals(Constants.HEALTHY, object.getBody()); + + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/InvalidInput.json b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/InvalidInput.json new file mode 100644 index 00000000..6f2d27d4 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/InvalidInput.json @@ -0,0 +1,27 @@ +{ + "input": { + "request-information": { + "request-action": "CreateServiceInstance", + "source": "MSO", + "request-id": "33ebd358-a189-4664-90f5-cf9e23658e0a" + }, + "sdnc-request-header": { + "svc-request-id": "04fc9f50-87b8-430d-a232-ef24bd6c4150", + "svc-action": "assign" + }, + "service-information": { + "onap-model-information": { + "model-name": "Sol004Zip3Service", + "model-version": "2.0", + "model-uuid": "c112a499-6148-488b-ba82-3f5938cf26d2", + "model-invariant-uuid": "e9acd081-9c89-4b4d-bcb3-e0e2b9715b2a" + }, + "subscription-service-type": "vCPE", + "service-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b", + "global-customer-id": "NordixDemoCustomer" + }, + "service-request-input": { + "service-instance-name": "ServiceTest_24_07_2019" + } + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/input.json b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/input.json new file mode 100644 index 00000000..8d42b620 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/input.json @@ -0,0 +1,28 @@ +{ + "input": { + "request-information": { + "request-action": "CreateServiceInstance", + "source": "MSO", + "request-id": "33ebd358-a189-4664-90f5-cf9e23658e0a" + }, + "sdnc-request-header": { + "svc-request-id": "04fc9f50-87b8-430d-a232-ef24bd6c4150", + "svc-action": "assign" + }, + "service-information": { + "onap-model-information": { + "model-name": "Sol004Zip3Service", + "model-version": "2.0", + "model-uuid": "c112a499-6148-488b-ba82-3f5938cf26d2", + "model-invariant-uuid": "e9acd081-9c89-4b4d-bcb3-e0e2b9715b2a" + }, + "subscription-service-type": "vCPE", + "service-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b", + "global-customer-id": "NordixDemoCustomer", + "service-instance-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b" + }, + "service-request-input": { + "service-instance-name": "ServiceTest_24_07_2019" + } + } +} diff --git a/plans/so/integration-etsi-testing/teardown.sh b/plans/so/integration-etsi-testing/teardown.sh index 6014a0d1..61edc7df 100755 --- a/plans/so/integration-etsi-testing/teardown.sh +++ b/plans/so/integration-etsi-testing/teardown.sh @@ -34,7 +34,6 @@ export $(egrep -v '^#' $ENV_FILE | xargs) export TEST_LAB_DIR=$TEST_LAB_DIR_PATH export CONFIG_DIR_PATH=$CONFIG_DIR - -docker-compose -f $DOCKER_COMPOSE_FILE_PATH down +docker-compose -f $DOCKER_COMPOSE_FILE_PATH -p $PROJECT_NAME down echo "Finished executing $SCRIPT_HOME/$SCRIPT_NAME" |