3 # ============LICENSE_START===============================================
4 # Copyright (C) 2020-2022 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 # Function to execute curl and compare + print result
22 # Note: Env var PORT must be set to the intended port number
23 # Notre Env var HTTPX must be set to either 'http' or 'https'
25 #args: <http-operation> <url> <response-code> [file]
26 #Expects the env $RESULT to contain the expected RESULT.
27 #If json, the RESULT shall begin with 'json:'.
28 #Any json parameter with unknown value shall be given as "????" to skip checking the value.
29 #The requestid parameter is being introduced in the fifth order.
32 echo "Need 3 or more parameters, <http-operation> <url> <response-code> [file]: "$@
33 echo "Exiting test script....."
36 curlstr="curl -X "$1" -skw %{http_code} $HTTPX://localhost:"${PORT}${2}" -H accept:*/*"
38 curlstr=$curlstr" -H Content-Type:application/json --data-binary @"$4
41 curlstr=$curlstr" -H Content-Type:application/json --data-binary @"$4" -H requestid:"$5
43 echo " CMD (${BASH_LINENO[0]}):"$curlstr
45 status=${res:${#res}-3}
46 body=${res:0:${#res}-3}
47 if [ $status -ne $3 ]; then
48 echo " Error status :"$status" Expected status: "$3
50 echo "Exiting test script....."
53 echo " OK, code :"$status" (Expected)"
55 if [ "$RESULT" == "*" ]; then
56 echo " Body contents not checked"
57 elif [[ "$RESULT" == "json:"* ]]; then
58 result=${RESULT:5:${#RESULT}} #Remove 'json:' from the result string
59 res=$(python ../common/compare_json.py "$result" "$body")
60 if [ $res -eq 0 ]; then
61 echo " Expected json body :"$result
62 echo " Body as expected"
64 echo " Expected json body :"$result
69 body="$(echo $body | tr -d '\n' )"
70 if [ "$RESULT" == "$body" ]; then
71 echo " Expected body :"$RESULT
72 echo " Body as expected"
74 echo " Expected body :"$RESULT
82 # Triggers publish_event_to_kafka_bus.py script to send msg to Kafka broker
83 # The aim of this function is to realize error related test cases only
84 # The request_id for the Kafka msg, should be passed here as a function parameter
85 publish_response_event() {
87 echo "Need 2 parameter, <request_id> <target_topic>"
88 echo "Exiting test script....."
91 res=$(python ../common/publish_response_event_to_kafka_bus.py "$1" "$2")
92 if [ $res -eq 0 ]; then
93 echo " Result as expected "
95 echo " Result not expected "
101 # Creates 16 digits random number using letters and numbers only
102 get_random_number() {
103 r_num=$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 16)
107 # It is being used to cross-test-cases in between A1 sim and external server
108 # The parameter it holds all with regards to External Server relates e.g. HTTPX_EXT_SRV and PORT_EXT_SRV
110 if [ $# -lt 3 ]; then
111 echo "Need 3 or more parameters, <http-operation> <url> <response-code> [file]: "$@
112 echo "Exiting test script....."
115 curlstr="curl -X "$1" -skw %{http_code} $HTTPX_EXT_SRV://localhost:"${PORT_EXT_SRV}${2}" -H accept:*/*"
116 if [ $# -gt 3 ]; then
117 curlstr=$curlstr" -H Content-Type:application/json --data-binary @"$4
119 echo " CMD (${BASH_LINENO[0]}):"$curlstr
121 status=${res:${#res}-3}
122 body=${res:0:${#res}-3}
123 if [ $status -ne $3 ]; then
124 echo " Error status :"$status" Expected status: "$3
126 echo "Exiting test script....."
129 echo " OK, code :"$status" (Expected)"
131 if [ "$RESULT" == "*" ]; then
132 echo " Body contents not checked"
133 elif [[ "$RESULT" == "json:"* ]]; then
134 result=${RESULT:5:${#RESULT}} #Remove 'json:' from the result string
135 res=$(python ../common/compare_json.py "$result" "$body")
136 if [ $res -eq 0 ]; then
137 echo " Expected json body :"$result
138 echo " Body as expected"
140 echo " Expected json body :"$result
145 body="$(echo $body | tr -d '\n' )"
146 if [ "$RESULT" == "$body" ]; then
147 echo " Expected body :"$RESULT
148 echo " Body as expected"
150 echo " Expected body :"$RESULT