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 echo "=== CR hello world ==="
54 do_curl POST /reset 200
56 echo "=== Get counter - callbacks ==="
58 do_curl GET /counter/received_callbacks 200
60 echo "=== Get counter - fetched events ==="
62 do_curl GET /counter/fetched_callbacks 200
64 echo "=== Get counter - current events ==="
66 do_curl GET /counter/current_messages 200
68 echo "=== Get counter - remote hosts ==="
70 do_curl GET /counter/remote_hosts 200
72 echo "=== Send a request non json ==="
75 echo "DATA" > .tmp.json
76 do_curl POST '/callbacks/test' 200 .tmp.json
78 echo "=== Send a request ==="
81 echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json
82 do_curl POST '/callbacks/test' 200 .tmp.json
85 echo "=== Fetch an event, wrong id==="
87 do_curl GET '/get-event/wrongid' 204
89 # Test counters for all ids
90 echo "=== Get counter - callbacks ==="
92 do_curl GET /counter/received_callbacks 200
94 echo "=== Get counter - fetched events ==="
96 do_curl GET /counter/fetched_callbacks 200
98 echo "=== Get counter - current events ==="
100 do_curl GET /counter/current_messages 200
102 # Test counter for one id
103 echo "=== Get counter - callbacks ==="
105 do_curl GET /counter/received_callbacks?id=test 200
107 echo "=== Get counter - fetched events ==="
109 do_curl GET /counter/fetched_callbacks?id=test 200
111 echo "=== Get counter - current events ==="
113 do_curl GET /counter/current_messages?id=test 200
115 # Test counter for dummy id
116 echo "=== Get counter - callbacks ==="
118 do_curl GET /counter/received_callbacks?id=dummy 200
120 echo "=== Get counter - fetched events ==="
122 do_curl GET /counter/fetched_callbacks?id=dummy 200
124 echo "=== Get counter - current events ==="
126 do_curl GET /counter/current_messages?id=dummy 200
129 echo "=== Fetch an event ==="
131 do_curl GET '/get-event/test' 200
133 echo "=== Fetch an event ==="
134 RESULT="json:{\"DATA-MSG\":\"msg\"}"
135 do_curl GET '/get-event/test' 200
137 echo "=== Fetch an event again ==="
139 do_curl GET '/get-event/test' 204
141 echo "=== Get counter - callbacks ==="
143 do_curl GET /counter/received_callbacks 200
145 echo "=== Get counter - fetched events ==="
147 do_curl GET /counter/fetched_callbacks 200
149 echo "=== Get counter - current events ==="
151 do_curl GET /counter/current_messages 200
153 # Test counter for one id
154 echo "=== Get counter - callbacks ==="
156 do_curl GET /counter/received_callbacks?id=test 200
158 echo "=== Get counter - fetched events ==="
160 do_curl GET /counter/fetched_callbacks?id=test 200
162 echo "=== Get counter - current events ==="
164 do_curl GET /counter/current_messages?id=test 200
166 echo "=== Send a request ==="
169 echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json
170 do_curl POST '/callbacks/test' 200 .tmp.json
172 echo "=== Send a request ==="
175 echo "{\"DATA-MSG2\":\"msg2\"}" > .tmp.json
176 do_curl POST '/callbacks/test' 200 .tmp.json
178 echo "=== Send a request ==="
181 echo "{\"DATA-MSG3\":\"msg3\"}" > .tmp.json
182 do_curl POST '/callbacks/test1' 200 .tmp.json
184 echo "=== Get counter - callbacks ==="
186 do_curl GET /counter/received_callbacks 200
188 echo "=== Get counter - fetched events ==="
190 do_curl GET /counter/fetched_callbacks 200
192 echo "=== Get counter - current events ==="
194 do_curl GET /counter/current_messages 200
196 # Test counter for one id, test1
197 echo "=== Get counter - callbacks ==="
199 do_curl GET /counter/received_callbacks?id=test1 200
201 echo "=== Get counter - fetched events ==="
203 do_curl GET /counter/fetched_callbacks?id=test1 200
205 echo "=== Get counter - current events ==="
207 do_curl GET /counter/current_messages?id=test1 200
209 echo "=== Fetch all events ==="
210 RESULT="json:[{\"DATA-MSG2\":\"msg2\"},{\"DATA-MSG\":\"msg\"}]"
211 do_curl GET '/get-all-events/test' 200
213 echo "=== Get counter - callbacks ==="
215 do_curl GET /counter/received_callbacks 200
217 echo "=== Get counter - fetched events ==="
219 do_curl GET /counter/fetched_callbacks 200
221 echo "=== Get counter - current events ==="
223 do_curl GET /counter/current_messages 200
225 echo "=== CR reset ==="
227 do_curl GET /reset 200
229 echo "=== Get counter - callbacks ==="
231 do_curl GET /counter/received_callbacks 200
233 echo "=== Get counter - fetched events ==="
235 do_curl GET /counter/fetched_callbacks 200
237 echo "=== Get counter - current events ==="
239 do_curl GET /counter/current_messages 200
244 echo "=== Set delay 10 sec==="
246 do_curl POST /forcedelay?delay=10 200
249 echo "=== Send a request, dealyed ==="
252 echo "{\"DATA-MSG\":\"msg-del1\"}" > .tmp.json
253 do_curl POST '/callbacks/test' 200 .tmp.json
255 if [ $(($SECONDS-$TSECONDS)) -lt 10 ]; then
256 echo " Delay failed $(($SECONDS-$TSECONDS))"
260 echo " Delay OK $(($SECONDS-$TSECONDS))"
264 echo "=== Fetch an event ==="
265 RESULT="json:{\"DATA-MSG\":\"msg-del1\"}"
266 do_curl GET '/get-event/test' 200
268 echo "********************"
269 echo "*** All tests ok ***"
270 echo "********************"