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 basic test of the Kafka message dispatcher.
21 # Run the build_and_start with the same arg, except arg 'nonsecure|secure', as this script
24 echo "Usage: ./basic_test.sh nonsecure|secure "
31 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
35 if [ $1 == "nonsecure" ]; then
36 #Default http port for the simulator
41 #Default https port for the simulator
47 . ../common/test_common.sh
48 . ../common/elapse_time_curl.sh
50 echo "=== Kafka message dispatcher hello world ==="
54 echo "=== Reset force delay ==="
55 RESULT="Force delay has been resetted for all dispatcher responses"
56 do_curl POST /dispatcheradmin/forcedelay 200
58 echo "=== API: Get policy type to topic mapping of type: ANR ==="
59 res=$(cat jsonfiles/ANR_to_topic_map.json)
61 do_curl GET /policytypetotopicmapping/ANR 200
63 echo "=== Put policy: shall publish and consume for put policy operation ==="
64 req_id=$(get_random_number)
66 do_curl PUT /policytypes/ANR/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json $req_id &
68 publish_response_event $req_id kafkatopicres
71 echo "=== Get policy status: shall publish and consume for get policy status operation ==="
72 req_id=$(get_random_number)
74 do_curl GET /policytypes/ANR/kafkadispatcher/alpha/status 200 jsonfiles/alpha_policy.json $req_id &
76 publish_response_event $req_id kafkatopicres
79 echo "=== Put policy: shall publish and consume for put policy operation for alpha ==="
80 req_id=$(get_random_number)
82 do_curl PUT /policytypes/STD_1/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json $req_id &
84 publish_response_event $req_id kafkatopicres2
87 echo "=== Delete policy: shall publish and consume for delete policy operation for alpha ==="
88 req_id=$(get_random_number)
90 do_curl DELETE /policytypes/STD_1/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json $req_id &
92 publish_response_event $req_id kafkatopicres2
95 echo "=== Set force delay 5 sec ==="
96 RESULT="Force delay: 5 sec set for all dispatcher responses until it is resetted"
97 do_curl POST '/dispatcheradmin/forcedelay?delay=5' 200
99 echo "=== Hello world: shall wait at least <delay-time> sec and then respond while hello world ==="
101 do_elapsetime_curl GET / 200 jsonfiles/alpha_policy.json 5
103 echo "=== Reset force delay ==="
104 RESULT="Force delay has been resetted for all dispatcher responses"
105 do_curl POST /dispatcheradmin/forcedelay 200
107 echo "=== Put policy: shall publish and consume for put policy operation for beta ==="
108 req_id=$(get_random_number)
110 do_curl PUT /policytypes/STD_1/kafkadispatcher/beta 200 jsonfiles/beta_policy.json $req_id &
112 publish_response_event $req_id kafkatopicres2
115 echo "=== Get policy status: shall publish and consume for get policy status operation ==="
116 req_id=$(get_random_number)
118 do_curl GET /policytypes/ANR/kafkadispatcher/alpha/status 200 jsonfiles/beta_policy.json $req_id &
120 publish_response_event $req_id kafkatopicres
123 echo "=== Put policy: shall publish and consume for put policy operation for alpha ==="
124 req_id=$(get_random_number)
126 do_curl PUT /policytypes/STD_2/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json $req_id &
128 publish_response_event $req_id kafkatopicres3
131 echo "=== Set force response code: 500 ==="
132 RESULT="Force response code: 500 set for all dispatcher response until it is resetted"
133 do_curl POST '/dispatcheradmin/forceresponse?code=500' 200
135 echo "=== Put policy: shall not publish and consume for put policy operation for alpha ==="
136 req_id=$(get_random_number)
137 res=$(cat jsonfiles/forced_response.json)
139 do_curl PUT /policytypes/ANR/kafkadispatcher/alpha 500 jsonfiles/alpha_policy.json $req_id &
141 publish_response_event $req_id kafkatopicres
144 echo "=== Reset force response code ==="
145 RESULT="Force response code has been resetted for dispatcher responses"
146 do_curl POST /dispatcheradmin/forceresponse 200
148 echo "=== Get policy status: shall publish and consume for get policy status operation ==="
149 req_id=$(get_random_number)
151 do_curl GET /policytypes/ANR/kafkadispatcher/alpha/status 200 jsonfiles/alpha_policy.json $req_id &
153 publish_response_event $req_id kafkatopicres
156 echo "=== Delete policy: shall publish and consume for delete policy operation for alpha ==="
157 req_id=$(get_random_number)
159 do_curl DELETE /policytypes/STD_1/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json $req_id &
161 publish_response_event $req_id kafkatopicres2
164 echo "********************"
165 echo "*** All tests ok ***"
166 echo "********************"