3 # ============LICENSE_START===============================================
4 # Copyright (C) 2020 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 # Automated test script for callback receiver container
22 # callbackreciver port
25 echo "Usage: ./basic_test.sh nonsecure|secure"
28 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
29 echo "Usage: ./basic_test.sh nonsecure|secure"
33 if [ $1 == "nonsecure" ]; then
34 #Default http port for the simulator
39 #Default https port for the simulator
45 # source function to do curl and check result
46 . ../common/do_curl_function.sh
48 RESP_CONTENT='*' #Dont check resp content type
50 echo "=== CR hello world ==="
56 do_curl POST /reset 200
58 echo "=== Get counter - callbacks ==="
60 do_curl GET /counter/received_callbacks 200
62 echo "=== Get counter - callback batches ==="
64 do_curl GET /counter/received_callback_batches 200
66 echo "=== Get counter - fetched events ==="
68 do_curl GET /counter/fetched_callbacks 200
70 echo "=== Get counter - current events ==="
72 do_curl GET /counter/current_messages 200
74 echo "=== Get counter - remote hosts ==="
76 do_curl GET /counter/remote_hosts 200
78 echo "=== Send a request non json ==="
81 echo "DATA" > .tmp.json
82 do_curl POST '/callbacks/test' 200 .tmp.json
84 echo "=== Send a request ==="
87 echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json
88 do_curl POST '/callbacks/test' 200 .tmp.json
91 echo "=== Fetch an event, wrong id==="
93 do_curl GET '/get-event/wrongid' 204
95 # Test counters for all ids
96 echo "=== Get counter - callbacks ==="
98 do_curl GET /counter/received_callbacks 200
100 echo "=== Get counter - callback batches ==="
102 do_curl GET /counter/received_callback_batches 200
104 echo "=== Get counter - fetched events ==="
106 do_curl GET /counter/fetched_callbacks 200
108 echo "=== Get counter - current events ==="
110 do_curl GET /counter/current_messages 200
112 # Test counter for one id
113 echo "=== Get counter - callbacks ==="
115 do_curl GET /counter/received_callbacks?id=test 200
117 echo "=== Get counter - callback batches ==="
119 do_curl GET /counter/received_callback_batches?id=test 200
121 echo "=== Get counter - fetched events ==="
123 do_curl GET /counter/fetched_callbacks?id=test 200
125 echo "=== Get counter - current events ==="
127 do_curl GET /counter/current_messages?id=test 200
129 # Test counter for dummy id
130 echo "=== Get counter - callbacks ==="
132 do_curl GET /counter/received_callbacks?id=dummy 200
134 echo "=== Get counter - callback batches ==="
136 do_curl GET /counter/received_callback_batches?id=dummy 200
138 echo "=== Get counter - fetched events ==="
140 do_curl GET /counter/fetched_callbacks?id=dummy 200
142 echo "=== Get counter - current events ==="
144 do_curl GET /counter/current_messages?id=dummy 200
147 echo "=== Fetch an event ==="
149 do_curl GET '/get-event/test' 200
151 echo "=== Fetch an event ==="
152 RESULT="json:{\"DATA-MSG\":\"msg\"}"
153 do_curl GET '/get-event/test' 200
155 echo "=== Fetch an event again ==="
157 do_curl GET '/get-event/test' 204
159 echo "=== Get counter - callbacks ==="
161 do_curl GET /counter/received_callbacks 200
163 echo "=== Get counter - callback batches ==="
165 do_curl GET /counter/received_callback_batches 200
167 echo "=== Get counter - fetched events ==="
169 do_curl GET /counter/fetched_callbacks 200
171 echo "=== Get counter - current events ==="
173 do_curl GET /counter/current_messages 200
175 # Test counter for one id
176 echo "=== Get counter - callbacks ==="
178 do_curl GET /counter/received_callbacks?id=test 200
180 echo "=== Get counter - callback batches ==="
182 do_curl GET /counter/received_callback_batches?id=test 200
184 echo "=== Get counter - fetched events ==="
186 do_curl GET /counter/fetched_callbacks?id=test 200
188 echo "=== Get counter - current events ==="
190 do_curl GET /counter/current_messages?id=test 200
192 echo "=== Send a request ==="
195 echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json
196 do_curl POST '/callbacks/test' 200 .tmp.json
198 echo "=== Send a request ==="
201 echo "{\"DATA-MSG2\":\"msg2\"}" > .tmp.json
202 do_curl POST '/callbacks/test' 200 .tmp.json
204 echo "=== Send a request ==="
207 echo "{\"DATA-MSG3\":\"msg3\"}" > .tmp.json
208 do_curl POST '/callbacks/test1' 200 .tmp.json
210 echo "=== Get counter - callbacks ==="
212 do_curl GET /counter/received_callbacks 200
214 echo "=== Get counter - callback batches ==="
216 do_curl GET /counter/received_callback_batches 200
218 echo "=== Get counter - fetched events ==="
220 do_curl GET /counter/fetched_callbacks 200
222 echo "=== Get counter - current events ==="
224 do_curl GET /counter/current_messages 200
226 # Test counter for one id, test1
227 echo "=== Get counter - callbacks ==="
229 do_curl GET /counter/received_callbacks?id=test1 200
231 echo "=== Get counter - callback batches ==="
233 do_curl GET /counter/received_callback_batches?id=test1 200
235 echo "=== Get counter - fetched events ==="
237 do_curl GET /counter/fetched_callbacks?id=test1 200
239 echo "=== Get counter - current events ==="
241 do_curl GET /counter/current_messages?id=test1 200
243 echo "=== Fetch all events ==="
244 RESULT="json:[{\"DATA-MSG2\":\"msg2\"},{\"DATA-MSG\":\"msg\"}]"
245 do_curl GET '/get-all-events/test' 200
247 echo "=== Get counter - callbacks ==="
249 do_curl GET /counter/received_callbacks 200
251 echo "=== Get counter - callback batches ==="
253 do_curl GET /counter/received_callback_batches 200
255 echo "=== Get counter - fetched events ==="
257 do_curl GET /counter/fetched_callbacks 200
259 echo "=== Get counter - current events ==="
261 do_curl GET /counter/current_messages 200
263 echo "=== Send a request ==="
266 echo "[{\"DATA-MSG\":\"msg\"},{\"DATA-MSG\":\"msg\"}]" > .tmp.json
267 do_curl POST '/callbacks-text/test' 200 .tmp.json
269 echo "=== Get counter - callbacks ==="
271 do_curl GET /counter/received_callbacks 200
273 echo "=== Get counter - callback batches ==="
275 do_curl GET /counter/received_callback_batches 200
277 echo "=== Get counter - fetched events ==="
279 do_curl GET /counter/fetched_callbacks 200
281 echo "=== Get counter - current events ==="
283 do_curl GET /counter/current_messages 200
286 echo "=== CR reset ==="
288 do_curl GET /reset 200
290 echo "=== Get counter - callbacks ==="
292 do_curl GET /counter/received_callbacks 200
294 echo "=== Get counter - callback batches ==="
296 do_curl GET /counter/received_callback_batches 200
298 echo "=== Get counter - fetched events ==="
300 do_curl GET /counter/fetched_callbacks 200
302 echo "=== Get counter - current events ==="
304 do_curl GET /counter/current_messages 200
309 echo "=== Set delay 10 sec==="
311 do_curl POST /forcedelay?delay=10 200
314 echo "=== Send a request, dealyed ==="
317 echo "{\"DATA-MSG\":\"msg-del1\"}" > .tmp.json
318 do_curl POST '/callbacks/test' 200 .tmp.json
320 if [ $(($SECONDS-$TSECONDS)) -lt 10 ]; then
321 echo " Delay failed $(($SECONDS-$TSECONDS))"
325 echo " Delay OK $(($SECONDS-$TSECONDS))"
329 echo "=== Fetch an event ==="
330 RESULT="json:{\"DATA-MSG\":\"msg-del1\"}"
331 do_curl GET '/get-event/test' 200
333 echo "********************"
334 echo "*** All tests ok ***"
335 echo "********************"