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 ==="
65 do_curl PUT /policytypes/ANR/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json
67 echo "=== Get policy status: shall publish and consume for get policy status operation ==="
69 do_curl GET /policytypes/ANR/kafkadispatcher/alpha/status 200 jsonfiles/alpha_policy.json
71 echo "=== Put policy: shall publish and consume for put policy operation for alpha ==="
73 do_curl PUT /policytypes/STD_1/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json
75 echo "=== Delete policy: shall publish and consume for delete policy operation for alpha ==="
77 do_curl DELETE /policytypes/STD_1/kafkadispatcher/alpha 200
79 echo "=== Set force delay 5 sec ==="
80 RESULT="Force delay: 5 sec set for all dispatcher responses until it is resetted"
81 do_curl POST '/dispatcheradmin/forcedelay?delay=5' 200
83 echo "=== Put policy: shall wait at least <delay-time> sec and then respond while publishing and consuming ==="
85 do_elapsetime_curl PUT /policytypes/ANR/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json 5
87 echo "=== Reset force delay ==="
88 RESULT="Force delay has been resetted for all dispatcher responses"
89 do_curl POST /dispatcheradmin/forcedelay 200
91 echo "=== Put policy: shall publish and consume for put policy operation for beta ==="
93 do_curl PUT /policytypes/STD_1/kafkadispatcher/beta 200 jsonfiles/beta_policy.json
95 echo "=== Get policy status: shall publish and consume for get policy status operation ==="
97 do_curl GET /policytypes/ANR/kafkadispatcher/alpha/status 200 jsonfiles/beta_policy.json
99 echo "=== Put policy: shall publish and consume for put policy operation for alpha ==="
101 do_curl PUT /policytypes/STD_2/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json
103 echo "=== Set force response code: 500 ==="
104 RESULT="Force response code: 500 set for all dispatcher response until it is resetted"
105 do_curl POST '/dispatcheradmin/forceresponse?code=500' 200
107 echo "=== Put policy: shall not publish and consume for put policy operation for alpha ==="
108 res=$(cat jsonfiles/forced_response.json)
110 do_curl PUT /policytypes/ANR/kafkadispatcher/alpha 500 jsonfiles/alpha_policy.json
112 echo "=== Reset force response code ==="
113 RESULT="Force response code has been resetted for dispatcher responses"
114 do_curl POST /dispatcheradmin/forceresponse 200
116 echo "=== Get policy status: shall publish and consume for get policy status operation ==="
118 do_curl GET /policytypes/ANR/kafkadispatcher/alpha/status 200 jsonfiles/alpha_policy.json
120 echo "=== Delete policy: shall publish and consume for delete policy operation for alpha ==="
122 do_curl DELETE /policytypes/STD_1/kafkadispatcher/alpha 200
124 echo "********************"
125 echo "*** All tests ok ***"
126 echo "********************"