3 # ============LICENSE_START===============================================
4 # Copyright (C) 2020 Nordix Foundation. All rights reserved.
5 # ========================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=================================================
20 # This is a script that contains specific test functions for RAPP Catalogue API
22 . ../common/api_curl.sh
24 # Tests if a variable value in the RAPP Catalogue is equal to a target value and and optional timeout.
25 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
26 # equal to the target or not.
27 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
28 # before setting pass or fail depending on if the variable value becomes equal to the target
30 # (Function for test scripts)
32 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
33 __var_test RC "$LOCALHOST$RC_EXTERNAL_PORT/" $1 "=" $2 $3
35 __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
40 ##########################################
41 ######### RAPP Catalogue API ##########
42 ##########################################
43 #Function prefix: rapp_cat_api
45 # API Test function: GET /services
46 # args: <response-code> [(<service-id> <version> <display-name> <description>)+ | EMPTY ]
47 # (Function for test scripts)
48 rapp_cat_api_get_services() {
52 __print_err "<response-code> [(<service-id> <version> <display-name> <description>)+ | EMPTY ]" $@
56 res="$(__do_curl_to_api RC GET $query)"
57 status=${res:${#res}-3}
59 if [ $status -ne $1 ]; then
60 __log_test_fail_status_code $1 $status
65 body=${res:0:${#res}-3}
72 for ((i=0; i<$(($#-1)); i=i+4)); do
73 if [ "$targetJson" != "[" ]; then
74 targetJson=$targetJson","
76 targetJson=$targetJson"{\"name\": \"${arr[$i]}\",\"version\": \"${arr[$i+1]}\",\"display_name\": \"${arr[$i+2]}\",\"description\": \"${arr[$i+3]}\",\"registrationDate\": \"????\"}"
78 targetJson=$targetJson"]"
80 echo " TARGET JSON: $targetJson" >> $HTTPLOG
81 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
83 if [ $res -ne 0 ]; then
93 # API Test function: PUT /services/{service-id}
94 # args: <response-code> <service-id> <version> <display-name> <description>
95 # (Function for test scripts)
96 rapp_cat_api_put_service() {
100 __print_err "<response-code> <service-id> <version> <display-name> <description>" $@
104 inputJson="{\"version\": \"$3\",\"display_name\": \"$4\",\"description\": \"$5\"}"
106 echo "$inputJson" > $file
108 res="$(__do_curl_to_api RC PUT $query $file)"
109 status=${res:${#res}-3}
111 if [ $status -ne $1 ]; then
112 __log_test_fail_status_code $1 $status
120 # API Test function: GET /services/{service-id}
121 # args: <response-code> <service-id>
122 # (Function for test scripts)
123 rapp_cat_api_get_service() {
126 if [ $# -lt 2 ] || [ $# -gt 5 ]; then
127 __print_err "<response-code> <service-id> <version> <display-name> <description>" $@
132 res="$(__do_curl_to_api RC GET $query)"
133 status=${res:${#res}-3}
135 if [ $status -ne $1 ]; then
136 __log_test_fail_status_code $1 $status
140 if [ $# -gt 2 ]; then
141 body=${res:0:${#res}-3}
142 targetJson="{\"name\": \"$2\",\"version\": \"$3\",\"display_name\": \"$4\",\"description\": \"$5\",\"registrationDate\": \"????\"}"
143 echo " TARGET JSON: $targetJson" >> $HTTPLOG
144 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
146 if [ $res -ne 0 ]; then
156 # API Test function: DELETE /services/{service-id}
157 # args: <response-code> <service-id>
158 # (Function for test scripts)
159 rapp_cat_api_delete_service() {
162 if [ $# -ne 2 ]; then
163 __print_err "<response-code> <service-id>" $@
168 res="$(__do_curl_to_api RC DELETE $query)"
169 status=${res:${#res}-3}
171 if [ $status -ne $1 ]; then
172 __log_test_fail_status_code $1 $status