44e8526aa48aae7ae3e870b8c7c3905970ac9cdf
[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 echo "=== CR hello world ==="
49 RESULT="OK"
50 do_curl GET / 200
51
52 echo "=== Reset ==="
53 RESULT="*"
54 do_curl POST /reset 200
55
56 echo "=== Get counter - callbacks ==="
57 RESULT="0"
58 do_curl GET /counter/received_callbacks 200
59
60 echo "=== Get counter - fetched events ==="
61 RESULT="0"
62 do_curl GET /counter/fetched_callbacks 200
63
64 echo "=== Get counter - current events ==="
65 RESULT="0"
66 do_curl GET /counter/current_messages 200
67
68 echo "=== Get counter - remote hosts ==="
69 RESULT="*"
70 do_curl GET /counter/remote_hosts 200
71
72 echo "=== Send a request non json ==="
73 RESULT="*"
74 #create payload
75 echo "DATA" > .tmp.json
76 do_curl POST '/callbacks/test' 200 .tmp.json
77
78 echo "=== Send a request ==="
79 RESULT="*"
80 #create payload
81 echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json
82 do_curl POST '/callbacks/test' 200 .tmp.json
83
84
85 echo "=== Fetch an event, wrong id==="
86 RESULT="*"
87 do_curl GET '/get-event/wrongid' 204
88
89 # Test counters for all ids
90 echo "=== Get counter - callbacks ==="
91 RESULT="2"
92 do_curl GET /counter/received_callbacks 200
93
94 echo "=== Get counter - fetched events ==="
95 RESULT="0"
96 do_curl GET /counter/fetched_callbacks 200
97
98 echo "=== Get counter - current events ==="
99 RESULT="2"
100 do_curl GET /counter/current_messages 200
101
102 # Test counter for one id
103 echo "=== Get counter - callbacks ==="
104 RESULT="2"
105 do_curl GET /counter/received_callbacks?id=test 200
106
107 echo "=== Get counter - fetched events ==="
108 RESULT="0"
109 do_curl GET /counter/fetched_callbacks?id=test 200
110
111 echo "=== Get counter - current events ==="
112 RESULT="2"
113 do_curl GET /counter/current_messages?id=test 200
114
115 # Test counter for dummy id
116 echo "=== Get counter - callbacks ==="
117 RESULT="0"
118 do_curl GET /counter/received_callbacks?id=dummy 200
119
120 echo "=== Get counter - fetched events ==="
121 RESULT="0"
122 do_curl GET /counter/fetched_callbacks?id=dummy 200
123
124 echo "=== Get counter - current events ==="
125 RESULT="0"
126 do_curl GET /counter/current_messages?id=dummy 200
127
128
129 echo "=== Fetch an event ==="
130 RESULT="json:{}"
131 do_curl GET '/get-event/test' 200
132
133 echo "=== Fetch an event ==="
134 RESULT="json:{\"DATA-MSG\":\"msg\"}"
135 do_curl GET '/get-event/test' 200
136
137 echo "=== Fetch an event again ==="
138 RESULT="*"
139 do_curl GET '/get-event/test' 204
140
141 echo "=== Get counter - callbacks ==="
142 RESULT="2"
143 do_curl GET /counter/received_callbacks 200
144
145 echo "=== Get counter - fetched events ==="
146 RESULT="2"
147 do_curl GET /counter/fetched_callbacks 200
148
149 echo "=== Get counter - current events ==="
150 RESULT="0"
151 do_curl GET /counter/current_messages 200
152
153 # Test counter for one id
154 echo "=== Get counter - callbacks ==="
155 RESULT="2"
156 do_curl GET /counter/received_callbacks?id=test 200
157
158 echo "=== Get counter - fetched events ==="
159 RESULT="2"
160 do_curl GET /counter/fetched_callbacks?id=test 200
161
162 echo "=== Get counter - current events ==="
163 RESULT="0"
164 do_curl GET /counter/current_messages?id=test 200
165
166 echo "=== Send a request ==="
167 RESULT="*"
168 #create payload
169 echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json
170 do_curl POST '/callbacks/test' 200 .tmp.json
171
172 echo "=== Send a request ==="
173 RESULT="*"
174 #create payload
175 echo "{\"DATA-MSG2\":\"msg2\"}" > .tmp.json
176 do_curl POST '/callbacks/test' 200 .tmp.json
177
178 echo "=== Send a request ==="
179 RESULT="*"
180 #create payload
181 echo "{\"DATA-MSG3\":\"msg3\"}" > .tmp.json
182 do_curl POST '/callbacks/test1' 200 .tmp.json
183
184 echo "=== Get counter - callbacks ==="
185 RESULT="5"
186 do_curl GET /counter/received_callbacks 200
187
188 echo "=== Get counter - fetched events ==="
189 RESULT="2"
190 do_curl GET /counter/fetched_callbacks 200
191
192 echo "=== Get counter - current events ==="
193 RESULT="3"
194 do_curl GET /counter/current_messages 200
195
196 # Test counter for one id, test1
197 echo "=== Get counter - callbacks ==="
198 RESULT="1"
199 do_curl GET /counter/received_callbacks?id=test1 200
200
201 echo "=== Get counter - fetched events ==="
202 RESULT="0"
203 do_curl GET /counter/fetched_callbacks?id=test1 200
204
205 echo "=== Get counter - current events ==="
206 RESULT="1"
207 do_curl GET /counter/current_messages?id=test1 200
208
209 echo "=== Fetch all events ==="
210 RESULT="json:[{\"DATA-MSG2\":\"msg2\"},{\"DATA-MSG\":\"msg\"}]"
211 do_curl GET '/get-all-events/test' 200
212
213 echo "=== Get counter - callbacks ==="
214 RESULT="5"
215 do_curl GET /counter/received_callbacks 200
216
217 echo "=== Get counter - fetched events ==="
218 RESULT="4"
219 do_curl GET /counter/fetched_callbacks 200
220
221 echo "=== Get counter - current events ==="
222 RESULT="1"
223 do_curl GET /counter/current_messages 200
224
225 echo "=== CR reset ==="
226 RESULT="OK"
227 do_curl GET /reset 200
228
229 echo "=== Get counter - callbacks ==="
230 RESULT="0"
231 do_curl GET /counter/received_callbacks 200
232
233 echo "=== Get counter - fetched events ==="
234 RESULT="0"
235 do_curl GET /counter/fetched_callbacks 200
236
237 echo "=== Get counter - current events ==="
238 RESULT="0"
239 do_curl GET /counter/current_messages 200
240
241
242 # Check delay
243
244 echo "=== Set delay 10 sec==="
245 RESULT="*"
246 do_curl POST /forcedelay?delay=10 200
247
248 TSECONDS=$SECONDS
249 echo "=== Send a request, dealyed ==="
250 RESULT="*"
251 #create payload
252 echo "{\"DATA-MSG\":\"msg-del1\"}" > .tmp.json
253 do_curl POST '/callbacks/test' 200 .tmp.json
254
255 if [ $(($SECONDS-$TSECONDS)) -lt 10 ]; then
256     echo "  Delay failed $(($SECONDS-$TSECONDS))"
257     echo "  Exiting...."
258     exit 1
259 else
260     echo "  Delay OK $(($SECONDS-$TSECONDS))"
261 fi
262
263
264 echo "=== Fetch an event ==="
265 RESULT="json:{\"DATA-MSG\":\"msg-del1\"}"
266 do_curl GET '/get-event/test' 200
267
268 echo "********************"
269 echo "*** All tests ok ***"
270 echo "********************"