Update version number in container-tag for F Maintenance Release
[sim/a1-interface.git] / near-rt-ric-simulator / test / KAFKA_DISPATCHER_TEST / basic_test.sh
1 #!/bin/bash
2
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
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
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=================================================
18 #
19
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
22
23 print_usage() {
24     echo "Usage: ./basic_test.sh nonsecure|secure "
25     exit 1
26 }
27
28 if [ $# -ne 1 ]; then
29     print_usage
30 fi
31 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
32     print_usage
33 fi
34
35 if [ $1 == "nonsecure" ]; then
36     #Default http port for the simulator
37     PORT=7075
38     # Set http protocol
39     HTTPX="http"
40 else
41     #Default https port for the simulator
42     PORT=7175
43     # Set https protocol
44     HTTPX="https"
45 fi
46
47 . ../common/test_common.sh
48 . ../common/elapse_time_curl.sh
49
50 echo "=== Kafka message dispatcher hello world ==="
51 RESULT="OK"
52 do_curl GET / 200
53
54 echo "=== Reset force delay ==="
55 RESULT="Force delay has been resetted for all dispatcher responses"
56 do_curl POST /dispatcheradmin/forcedelay 200
57
58 echo "=== API: Get policy type to topic mapping of type: ANR ==="
59 res=$(cat jsonfiles/ANR_to_topic_map.json)
60 RESULT="json:$res"
61 do_curl GET /policytypetotopicmapping/ANR 200
62
63 echo "=== Put policy: shall publish and consume for put policy operation ==="
64 req_id=$(get_random_number)
65 RESULT=""
66 do_curl PUT  /policytypes/ANR/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json $req_id &
67 proc_id=$!
68 publish_response_event $req_id kafkatopicres
69 wait $proc_id
70
71 echo "=== Get policy status: shall publish and consume for get policy status operation ==="
72 req_id=$(get_random_number)
73 RESULT=""
74 do_curl GET  /policytypes/ANR/kafkadispatcher/alpha/status 200 jsonfiles/alpha_policy.json $req_id &
75 proc_id=$!
76 publish_response_event $req_id kafkatopicres
77 wait $proc_id
78
79 echo "=== Put policy: shall publish and consume for put policy operation for alpha ==="
80 req_id=$(get_random_number)
81 RESULT=""
82 do_curl PUT  /policytypes/STD_1/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json $req_id &
83 proc_id=$!
84 publish_response_event $req_id kafkatopicres2
85 wait $proc_id
86
87 echo "=== Delete policy: shall publish and consume for delete policy operation for alpha ==="
88 req_id=$(get_random_number)
89 RESULT=""
90 do_curl DELETE  /policytypes/STD_1/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json $req_id &
91 proc_id=$!
92 publish_response_event $req_id kafkatopicres2
93 wait $proc_id
94
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
98
99 echo "=== Hello world: shall wait at least <delay-time> sec and then respond while hello world ==="
100 RESULT="OK"
101 do_elapsetime_curl GET / 200 jsonfiles/alpha_policy.json 5
102
103 echo "=== Reset force delay ==="
104 RESULT="Force delay has been resetted for all dispatcher responses"
105 do_curl POST /dispatcheradmin/forcedelay 200
106
107 echo "=== Put policy: shall publish and consume for put policy operation for beta ==="
108 req_id=$(get_random_number)
109 RESULT=""
110 do_curl PUT  /policytypes/STD_1/kafkadispatcher/beta 200 jsonfiles/beta_policy.json $req_id &
111 proc_id=$!
112 publish_response_event $req_id kafkatopicres2
113 wait $proc_id
114
115 echo "=== Get policy status: shall publish and consume for get policy status operation ==="
116 req_id=$(get_random_number)
117 RESULT=""
118 do_curl GET  /policytypes/ANR/kafkadispatcher/alpha/status 200 jsonfiles/beta_policy.json $req_id &
119 proc_id=$!
120 publish_response_event $req_id kafkatopicres
121 wait $proc_id
122
123 echo "=== Put policy: shall publish and consume for put policy operation for alpha ==="
124 req_id=$(get_random_number)
125 RESULT=""
126 do_curl PUT  /policytypes/STD_2/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json $req_id &
127 proc_id=$!
128 publish_response_event $req_id kafkatopicres3
129 wait $proc_id
130
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
134
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)
138 RESULT="json:$res"
139 do_curl PUT  /policytypes/ANR/kafkadispatcher/alpha 500 jsonfiles/alpha_policy.json $req_id &
140 proc_id=$!
141 publish_response_event $req_id kafkatopicres
142 wait $proc_id
143
144 echo "=== Reset force response code ==="
145 RESULT="Force response code has been resetted for dispatcher responses"
146 do_curl POST  /dispatcheradmin/forceresponse 200
147
148 echo "=== Get policy status: shall publish and consume for get policy status operation ==="
149 req_id=$(get_random_number)
150 RESULT=""
151 do_curl GET  /policytypes/ANR/kafkadispatcher/alpha/status 200 jsonfiles/alpha_policy.json $req_id &
152 proc_id=$!
153 publish_response_event $req_id kafkatopicres
154 wait $proc_id
155
156 echo "=== Delete policy: shall publish and consume for delete policy operation for alpha ==="
157 req_id=$(get_random_number)
158 RESULT=""
159 do_curl DELETE  /policytypes/STD_1/kafkadispatcher/alpha 200 jsonfiles/alpha_policy.json $req_id &
160 proc_id=$!
161 publish_response_event $req_id kafkatopicres2
162 wait $proc_id
163
164 echo "********************"
165 echo "*** All tests ok ***"
166 echo "********************"