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 "=== Send a request non json ==="
71 echo "DATA" > .tmp.json
72 do_curl POST '/callbacks/test' 200 .tmp.json
74 echo "=== Send a request ==="
77 echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json
78 do_curl POST '/callbacks/test' 200 .tmp.json
81 echo "=== Fetch an event, wrong id==="
83 do_curl GET '/get-event/wrongid' 204
85 # Test counters for all ids
86 echo "=== Get counter - callbacks ==="
88 do_curl GET /counter/received_callbacks 200
90 echo "=== Get counter - fetched events ==="
92 do_curl GET /counter/fetched_callbacks 200
94 echo "=== Get counter - current events ==="
96 do_curl GET /counter/current_messages 200
98 # Test counter for one id
99 echo "=== Get counter - callbacks ==="
101 do_curl GET /counter/received_callbacks?id=test 200
103 echo "=== Get counter - fetched events ==="
105 do_curl GET /counter/fetched_callbacks?id=test 200
107 echo "=== Get counter - current events ==="
109 do_curl GET /counter/current_messages?id=test 200
111 # Test counter for dummy id
112 echo "=== Get counter - callbacks ==="
114 do_curl GET /counter/received_callbacks?id=dummy 200
116 echo "=== Get counter - fetched events ==="
118 do_curl GET /counter/fetched_callbacks?id=dummy 200
120 echo "=== Get counter - current events ==="
122 do_curl GET /counter/current_messages?id=dummy 200
125 echo "=== Fetch an event ==="
127 do_curl GET '/get-event/test' 200
129 echo "=== Fetch an event ==="
130 RESULT="json:{\"DATA-MSG\":\"msg\"}"
131 do_curl GET '/get-event/test' 200
133 echo "=== Fetch an event again ==="
135 do_curl GET '/get-event/test' 204
137 echo "=== Get counter - callbacks ==="
139 do_curl GET /counter/received_callbacks 200
141 echo "=== Get counter - fetched events ==="
143 do_curl GET /counter/fetched_callbacks 200
145 echo "=== Get counter - current events ==="
147 do_curl GET /counter/current_messages 200
149 # Test counter for one id
150 echo "=== Get counter - callbacks ==="
152 do_curl GET /counter/received_callbacks?id=test 200
154 echo "=== Get counter - fetched events ==="
156 do_curl GET /counter/fetched_callbacks?id=test 200
158 echo "=== Get counter - current events ==="
160 do_curl GET /counter/current_messages?id=test 200
162 echo "=== Send a request ==="
165 echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json
166 do_curl POST '/callbacks/test' 200 .tmp.json
168 echo "=== Send a request ==="
171 echo "{\"DATA-MSG2\":\"msg2\"}" > .tmp.json
172 do_curl POST '/callbacks/test' 200 .tmp.json
174 echo "=== Send a request ==="
177 echo "{\"DATA-MSG3\":\"msg3\"}" > .tmp.json
178 do_curl POST '/callbacks/test1' 200 .tmp.json
180 echo "=== Get counter - callbacks ==="
182 do_curl GET /counter/received_callbacks 200
184 echo "=== Get counter - fetched events ==="
186 do_curl GET /counter/fetched_callbacks 200
188 echo "=== Get counter - current events ==="
190 do_curl GET /counter/current_messages 200
192 # Test counter for one id, test1
193 echo "=== Get counter - callbacks ==="
195 do_curl GET /counter/received_callbacks?id=test1 200
197 echo "=== Get counter - fetched events ==="
199 do_curl GET /counter/fetched_callbacks?id=test1 200
201 echo "=== Get counter - current events ==="
203 do_curl GET /counter/current_messages?id=test1 200
205 echo "=== Fetch all events ==="
206 RESULT="json:[{\"DATA-MSG2\":\"msg2\"},{\"DATA-MSG\":\"msg\"}]"
207 do_curl GET '/get-all-events/test' 200
209 echo "=== Get counter - callbacks ==="
211 do_curl GET /counter/received_callbacks 200
213 echo "=== Get counter - fetched events ==="
215 do_curl GET /counter/fetched_callbacks 200
217 echo "=== Get counter - current events ==="
219 do_curl GET /counter/current_messages 200
221 echo "=== CR reset ==="
223 do_curl GET /reset 200
225 echo "=== Get counter - callbacks ==="
227 do_curl GET /counter/received_callbacks 200
229 echo "=== Get counter - fetched events ==="
231 do_curl GET /counter/fetched_callbacks 200
233 echo "=== Get counter - current events ==="
235 do_curl GET /counter/current_messages 200
238 echo "********************"
239 echo "*** All tests ok ***"
240 echo "********************"