X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Frapp_catalogue_api_functions.sh;fp=test%2Fcommon%2Frapp_catalogue_api_functions.sh;h=dce28f3d9cc2ac9f6b742af293e787e490389e50;hb=de4d0f86a327469fb64645c2bcd3aeea7832ad25;hp=0000000000000000000000000000000000000000;hpb=5343c3097bd7ae1c1c8d5f0409803c0c60034805;p=nonrtric.git diff --git a/test/common/rapp_catalogue_api_functions.sh b/test/common/rapp_catalogue_api_functions.sh new file mode 100644 index 00000000..dce28f3d --- /dev/null +++ b/test/common/rapp_catalogue_api_functions.sh @@ -0,0 +1,178 @@ +#!/bin/bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +# This is a script that contains specific test functions for RAPP Catalogue API + +. ../common/api_curl.sh + +# Tests if a variable value in the RAPP Catalogue is equal to a target value and and optional timeout. +# Arg: - This test set pass or fail depending on if the variable is +# equal to the target or not. +# Arg: - This test waits up to the timeout seconds +# before setting pass or fail depending on if the variable value becomes equal to the target +# value or not. +# (Function for test scripts) +rc_equal() { + if [ $# -eq 2 ] || [ $# -eq 3 ]; then + __var_test RC "$LOCALHOST$RC_EXTERNAL_PORT/" $1 "=" $2 $3 + else + __print_err "Wrong args to ecs_equal, needs two or three args: [ timeout ]" $@ + fi +} + + +########################################## +######### RAPP Catalogue API ########## +########################################## +#Function prefix: rapp_cat_api + +# API Test function: GET /services +# args: [( )+ | EMPTY ] +# (Function for test scripts) +rapp_cat_api_get_services() { + __log_test_start $@ + + if [ $# -lt 1 ]; then + __print_err " [( )+ | EMPTY ]" $@ + return 1 + fi + query="/services" + res="$(__do_curl_to_api RC GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + + if [ $# -gt 1 ]; then + body=${res:0:${#res}-3} + targetJson="[" + arr=(${@:2}) + + if [ $# -eq 2 ]; then + targetJson="[]" + else + for ((i=0; i<$(($#-1)); i=i+4)); do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + targetJson=$targetJson"{\"name\": \"${arr[$i]}\",\"version\": \"${arr[$i+1]}\",\"display_name\": \"${arr[$i+2]}\",\"description\": \"${arr[$i+3]}\",\"registrationDate\": \"????\"}" + done + targetJson=$targetJson"]" + fi + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + __log_test_fail_body + return 1 + fi + fi + + __log_test_pass + return 0 +} + +# API Test function: PUT ​/services/{service-id} +# args: +# (Function for test scripts) +rapp_cat_api_put_service() { + __log_test_start $@ + + if [ $# -ne 5 ]; then + __print_err " " $@ + return 1 + fi + + inputJson="{\"version\": \"$3\",\"display_name\": \"$4\",\"description\": \"$5\"}" + file="./tmp/.p.json" + echo "$inputJson" > $file + query="/services/$2" + res="$(__do_curl_to_api RC PUT $query $file)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + + __log_test_pass + return 0 +} + +# API Test function: GET ​/services/{service-id} +# args: +# (Function for test scripts) +rapp_cat_api_get_service() { + __log_test_start $@ + + if [ $# -lt 2 ] || [ $# -gt 5 ]; then + __print_err " " $@ + return 1 + fi + + query="/services/$2" + res="$(__do_curl_to_api RC GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + + if [ $# -gt 2 ]; then + body=${res:0:${#res}-3} + targetJson="{\"name\": \"$2\",\"version\": \"$3\",\"display_name\": \"$4\",\"description\": \"$5\",\"registrationDate\": \"????\"}" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + __log_test_fail_body + return 1 + fi + fi + + __log_test_pass + return 0 +} + +# API Test function: DELETE ​/services/{service-id} +# args: +# (Function for test scripts) +rapp_cat_api_delete_service() { + __log_test_start $@ + + if [ $# -ne 2 ]; then + __print_err " " $@ + return 1 + fi + + query="/services/$2" + res="$(__do_curl_to_api RC DELETE $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + __log_test_fail_status_code $1 $status + return 1 + fi + + __log_test_pass + return 0 +}