3 # ============LICENSE_START===============================================
4 # Copyright (C) 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 # Script for error testing of the Kafka message dispatcher
21 # The timeout value should be equal to TIME_OUT param that exist in the start script
22 # Run the script with the args: nonsecure|secure timeout=30
25 echo "Usage: ./basic_test.sh nonsecure|secure timeout=30"
32 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
36 timeout=$(echo "$2" | cut -d'=' -f2)
37 regexp_for_number='^[0-9]+$'
39 if ! [[ $timeout =~ $regexp_for_number ]] ; then
40 echo "error:"$timeout" Not a number"
43 if [ $timeout -le 0 ]; then
44 echo "Timeout value must be greater than zero"
49 if [ $1 == "nonsecure" ]; then
50 # Default http port for the simulator
55 #Default https port for the simulator
61 . ../common/test_common.sh
63 echo "=== Kafka message dispatcher hello world ==="
67 echo "=== Reset force delay ==="
68 RESULT="Force delay has been resetted for all dispatcher responses"
69 do_curl POST /dispatcheradmin/forcedelay 200
71 # asynch error test case
72 echo "=== Put policy: shall publish and consume time-out ==="
73 req_id=$(get_random_number)
74 res=$(cat jsonfiles/timeout_response.json)
77 do_curl PUT /policytypes/ANR/kafkadispatcher/alpha 408 jsonfiles/alpha_policy.json $req_id &
80 # after time out duration, publish the event
81 publish_response_event $req_id kafkatopicres
82 # wait until the main process to be completed
85 # asynch success test case after 10s
86 echo "=== Put policy: shall publish and consume success at least 10 secs later ==="
87 req_id=$(get_random_number)
90 do_curl PUT /policytypes/STD_1/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json $req_id &
93 # after 10s, publish the event
94 publish_response_event $req_id kafkatopicres2
95 # wait until the main process to be completed
98 # asynch error test case
99 echo "=== Get policy status: shall publish and consume time-out ==="
100 req_id=$(get_random_number)
101 res=$(cat jsonfiles/timeout_response.json)
104 do_curl GET /policytypes/STD_2/kafkadispatcher/alpha/status 408 jsonfiles/alpha_policy.json $req_id &
107 # after time out duration, publish the event
108 publish_response_event $req_id kafkatopicres3
109 # wait until the main process to be completed
112 # asynch success test case after 10s
113 echo "=== Get policy status: shall publish and consume success at least 15 secs later ==="
114 req_id=$(get_random_number)
117 do_curl GET /policytypes/ANR/kafkadispatcher/alpha/status 200 jsonfiles/alpha_policy.json $req_id &
120 # after 15s, publish the event
121 publish_response_event $req_id kafkatopicres
122 # wait until the main process to be completed
125 # asynch success test case without any delay
126 echo "=== Delete policy: shall publish and consume success ==="
127 req_id=$(get_random_number)
130 do_curl DELETE /policytypes/STD_1/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json $req_id &
132 publish_response_event $req_id kafkatopicres2
133 # wait until the main process to be completed
137 echo "********************"
138 echo "*** All tests ok ***"
139 echo "********************"