Test FTC100 fails since A1-SIM update
[nonrtric.git] / test / cr / basic_test.sh
1 #!/bin/bash
2
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
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 # Automated test script for callback receiver container
21
22 # callbackreciver port
23 # export PORT=8090
24 if [ $# -ne 1 ]; then
25     echo "Usage: ./basic_test.sh nonsecure|secure"
26     exit 1
27 fi
28 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
29     echo "Usage: ./basic_test.sh nonsecure|secure"
30     exit 1
31 fi
32
33 if [ $1 == "nonsecure" ]; then
34     #Default http port for the simulator
35     PORT=8090
36     # Set http protocol
37     HTTPX="http"
38 else
39     #Default https port for the simulator
40     PORT=8091
41     # Set https protocol
42     HTTPX="https"
43 fi
44
45 # source function to do curl and check result
46 . ../common/do_curl_function.sh
47
48 RESP_CONTENT='*' #Dont check resp content type
49
50 echo "=== CR hello world ==="
51 RESULT="OK"
52 do_curl GET / 200
53
54 echo "=== Reset ==="
55 RESULT="*"
56 do_curl POST /reset 200
57
58 echo "=== Get counter - callbacks ==="
59 RESULT="0"
60 do_curl GET /counter/received_callbacks 200
61
62 echo "=== Get counter - callback batches ==="
63 RESULT="0"
64 do_curl GET /counter/received_callback_batches 200
65
66 echo "=== Get counter - fetched events ==="
67 RESULT="0"
68 do_curl GET /counter/fetched_callbacks 200
69
70 echo "=== Get counter - current events ==="
71 RESULT="0"
72 do_curl GET /counter/current_messages 200
73
74 echo "=== Get counter - remote hosts ==="
75 RESULT="*"
76 do_curl GET /counter/remote_hosts 200
77
78 echo "=== Send a request non json ==="
79 RESULT="*"
80 #create payload
81 echo "DATA" > .tmp.json
82 do_curl POST '/callbacks/test' 200 .tmp.json
83
84 echo "=== Send a request ==="
85 RESULT="*"
86 #create payload
87 echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json
88 do_curl POST '/callbacks/test' 200 .tmp.json
89
90
91 echo "=== Fetch an event, wrong id==="
92 RESULT="*"
93 do_curl GET '/get-event/wrongid' 204
94
95 # Test counters for all ids
96 echo "=== Get counter - callbacks ==="
97 RESULT="2"
98 do_curl GET /counter/received_callbacks 200
99
100 echo "=== Get counter - callback batches ==="
101 RESULT="0"
102 do_curl GET /counter/received_callback_batches 200
103
104 echo "=== Get counter - fetched events ==="
105 RESULT="0"
106 do_curl GET /counter/fetched_callbacks 200
107
108 echo "=== Get counter - current events ==="
109 RESULT="2"
110 do_curl GET /counter/current_messages 200
111
112 # Test counter for one id
113 echo "=== Get counter - callbacks ==="
114 RESULT="2"
115 do_curl GET /counter/received_callbacks?id=test 200
116
117 echo "=== Get counter - callback batches ==="
118 RESULT="1"
119 do_curl GET /counter/received_callback_batches?id=test 200
120
121 echo "=== Get counter - fetched events ==="
122 RESULT="0"
123 do_curl GET /counter/fetched_callbacks?id=test 200
124
125 echo "=== Get counter - current events ==="
126 RESULT="2"
127 do_curl GET /counter/current_messages?id=test 200
128
129 # Test counter for dummy id
130 echo "=== Get counter - callbacks ==="
131 RESULT="0"
132 do_curl GET /counter/received_callbacks?id=dummy 200
133
134 echo "=== Get counter - callback batches ==="
135 RESULT="0"
136 do_curl GET /counter/received_callback_batches?id=dummy 200
137
138 echo "=== Get counter - fetched events ==="
139 RESULT="0"
140 do_curl GET /counter/fetched_callbacks?id=dummy 200
141
142 echo "=== Get counter - current events ==="
143 RESULT="0"
144 do_curl GET /counter/current_messages?id=dummy 200
145
146
147 echo "=== Fetch an event ==="
148 RESULT="json:{}"
149 do_curl GET '/get-event/test' 200
150
151 echo "=== Fetch an event ==="
152 RESULT="json:{\"DATA-MSG\":\"msg\"}"
153 do_curl GET '/get-event/test' 200
154
155 echo "=== Fetch an event again ==="
156 RESULT="*"
157 do_curl GET '/get-event/test' 204
158
159 echo "=== Get counter - callbacks ==="
160 RESULT="2"
161 do_curl GET /counter/received_callbacks 200
162
163 echo "=== Get counter - callback batches ==="
164 RESULT="0"
165 do_curl GET /counter/received_callback_batches 200
166
167 echo "=== Get counter - fetched events ==="
168 RESULT="2"
169 do_curl GET /counter/fetched_callbacks 200
170
171 echo "=== Get counter - current events ==="
172 RESULT="0"
173 do_curl GET /counter/current_messages 200
174
175 # Test counter for one id
176 echo "=== Get counter - callbacks ==="
177 RESULT="2"
178 do_curl GET /counter/received_callbacks?id=test 200
179
180 echo "=== Get counter - callback batches ==="
181 RESULT="1"
182 do_curl GET /counter/received_callback_batches?id=test 200
183
184 echo "=== Get counter - fetched events ==="
185 RESULT="2"
186 do_curl GET /counter/fetched_callbacks?id=test 200
187
188 echo "=== Get counter - current events ==="
189 RESULT="0"
190 do_curl GET /counter/current_messages?id=test 200
191
192 echo "=== Send a request ==="
193 RESULT="*"
194 #create payload
195 echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json
196 do_curl POST '/callbacks/test' 200 .tmp.json
197
198 echo "=== Send a request ==="
199 RESULT="*"
200 #create payload
201 echo "{\"DATA-MSG2\":\"msg2\"}" > .tmp.json
202 do_curl POST '/callbacks/test' 200 .tmp.json
203
204 echo "=== Send a request ==="
205 RESULT="*"
206 #create payload
207 echo "{\"DATA-MSG3\":\"msg3\"}" > .tmp.json
208 do_curl POST '/callbacks/test1' 200 .tmp.json
209
210 echo "=== Get counter - callbacks ==="
211 RESULT="5"
212 do_curl GET /counter/received_callbacks 200
213
214 echo "=== Get counter - callback batches ==="
215 RESULT="0"
216 do_curl GET /counter/received_callback_batches 200
217
218 echo "=== Get counter - fetched events ==="
219 RESULT="2"
220 do_curl GET /counter/fetched_callbacks 200
221
222 echo "=== Get counter - current events ==="
223 RESULT="3"
224 do_curl GET /counter/current_messages 200
225
226 # Test counter for one id, test1
227 echo "=== Get counter - callbacks ==="
228 RESULT="1"
229 do_curl GET /counter/received_callbacks?id=test1 200
230
231 echo "=== Get counter - callback batches ==="
232 RESULT="0"
233 do_curl GET /counter/received_callback_batches?id=test1 200
234
235 echo "=== Get counter - fetched events ==="
236 RESULT="0"
237 do_curl GET /counter/fetched_callbacks?id=test1 200
238
239 echo "=== Get counter - current events ==="
240 RESULT="1"
241 do_curl GET /counter/current_messages?id=test1 200
242
243 echo "=== Fetch all events ==="
244 RESULT="json:[{\"DATA-MSG2\":\"msg2\"},{\"DATA-MSG\":\"msg\"}]"
245 do_curl GET '/get-all-events/test' 200
246
247 echo "=== Get counter - callbacks ==="
248 RESULT="5"
249 do_curl GET /counter/received_callbacks 200
250
251 echo "=== Get counter - callback batches ==="
252 RESULT="0"
253 do_curl GET /counter/received_callback_batches 200
254
255 echo "=== Get counter - fetched events ==="
256 RESULT="4"
257 do_curl GET /counter/fetched_callbacks 200
258
259 echo "=== Get counter - current events ==="
260 RESULT="1"
261 do_curl GET /counter/current_messages 200
262
263 echo "=== Send a request ==="
264 RESULT="*"
265 #create payload
266 echo "[{\"DATA-MSG\":\"msg\"},{\"DATA-MSG\":\"msg\"}]" > .tmp.json
267 do_curl POST '/callbacks-text/test' 200 .tmp.json
268
269 echo "=== Get counter - callbacks ==="
270 RESULT="7"
271 do_curl GET /counter/received_callbacks 200
272
273 echo "=== Get counter - callback batches ==="
274 RESULT="1"
275 do_curl GET /counter/received_callback_batches 200
276
277 echo "=== Get counter - fetched events ==="
278 RESULT="4"
279 do_curl GET /counter/fetched_callbacks 200
280
281 echo "=== Get counter - current events ==="
282 RESULT="3"
283 do_curl GET /counter/current_messages 200
284
285
286 echo "=== CR reset ==="
287 RESULT="OK"
288 do_curl GET /reset 200
289
290 echo "=== Get counter - callbacks ==="
291 RESULT="0"
292 do_curl GET /counter/received_callbacks 200
293
294 echo "=== Get counter - callback batches ==="
295 RESULT="0"
296 do_curl GET /counter/received_callback_batches 200
297
298 echo "=== Get counter - fetched events ==="
299 RESULT="0"
300 do_curl GET /counter/fetched_callbacks 200
301
302 echo "=== Get counter - current events ==="
303 RESULT="0"
304 do_curl GET /counter/current_messages 200
305
306
307 # Check delay
308
309 echo "=== Set delay 10 sec==="
310 RESULT="*"
311 do_curl POST /forcedelay?delay=10 200
312
313 TSECONDS=$SECONDS
314 echo "=== Send a request, dealyed ==="
315 RESULT="*"
316 #create payload
317 echo "{\"DATA-MSG\":\"msg-del1\"}" > .tmp.json
318 do_curl POST '/callbacks/test' 200 .tmp.json
319
320 if [ $(($SECONDS-$TSECONDS)) -lt 10 ]; then
321     echo "  Delay failed $(($SECONDS-$TSECONDS))"
322     echo "  Exiting...."
323     exit 1
324 else
325     echo "  Delay OK $(($SECONDS-$TSECONDS))"
326 fi
327
328
329 echo "=== Fetch an event ==="
330 RESULT="json:{\"DATA-MSG\":\"msg-del1\"}"
331 do_curl GET '/get-event/test' 200
332
333 echo "********************"
334 echo "*** All tests ok ***"
335 echo "********************"