blob: d0bf25d3168bdf63c2cf27636eef0269e49311a2 [file] [log] [blame]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001#!/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
ecaiyanlinux113bf092020-08-01 14:05:17 +000023# export PORT=8090
24if [ $# -ne 1 ]; then
25 echo "Usage: ./basic_test.sh nonsecure|secure"
26 exit 1
27fi
28if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
29 echo "Usage: ./basic_test.sh nonsecure|secure"
30 exit 1
31fi
32
33if [ $1 == "nonsecure" ]; then
34 #Default http port for the simulator
35 PORT=8090
36 # Set http protocol
37 HTTPX="http"
38else
39 #Default https port for the simulator
40 PORT=8091
41 # Set https protocol
42 HTTPX="https"
43fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +010044
45# source function to do curl and check result
46. ../common/do_curl_function.sh
47
48echo "=== CR hello world ==="
49RESULT="OK"
50do_curl GET / 200
51
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +010052echo "=== Reset ==="
53RESULT="*"
54do_curl POST /reset 200
BjornMagnussonXA80a92002020-03-19 14:31:06 +010055
56echo "=== Get counter - callbacks ==="
57RESULT="0"
58do_curl GET /counter/received_callbacks 200
59
60echo "=== Get counter - fetched events ==="
61RESULT="0"
62do_curl GET /counter/fetched_callbacks 200
63
64echo "=== Get counter - current events ==="
65RESULT="0"
66do_curl GET /counter/current_messages 200
67
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +010068echo "=== Send a request non json ==="
69RESULT="*"
70#create payload
71echo "DATA" > .tmp.json
72do_curl POST '/callbacks/test' 200 .tmp.json
BjornMagnussonXA80a92002020-03-19 14:31:06 +010073
74echo "=== Send a request ==="
75RESULT="*"
76#create payload
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +010077echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json
BjornMagnussonXA80a92002020-03-19 14:31:06 +010078do_curl POST '/callbacks/test' 200 .tmp.json
79
80
81echo "=== Fetch an event, wrong id==="
82RESULT="*"
83do_curl GET '/get-event/wrongid' 204
84
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +010085# Test counters for all ids
BjornMagnussonXA80a92002020-03-19 14:31:06 +010086echo "=== Get counter - callbacks ==="
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +010087RESULT="2"
BjornMagnussonXA80a92002020-03-19 14:31:06 +010088do_curl GET /counter/received_callbacks 200
89
90echo "=== Get counter - fetched events ==="
91RESULT="0"
92do_curl GET /counter/fetched_callbacks 200
93
94echo "=== Get counter - current events ==="
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +010095RESULT="2"
BjornMagnussonXA80a92002020-03-19 14:31:06 +010096do_curl GET /counter/current_messages 200
97
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +010098# Test counter for one id
99echo "=== Get counter - callbacks ==="
100RESULT="2"
101do_curl GET /counter/received_callbacks?id=test 200
102
103echo "=== Get counter - fetched events ==="
104RESULT="0"
105do_curl GET /counter/fetched_callbacks?id=test 200
106
107echo "=== Get counter - current events ==="
108RESULT="2"
109do_curl GET /counter/current_messages?id=test 200
110
111# Test counter for dummy id
112echo "=== Get counter - callbacks ==="
113RESULT="0"
114do_curl GET /counter/received_callbacks?id=dummy 200
115
116echo "=== Get counter - fetched events ==="
117RESULT="0"
118do_curl GET /counter/fetched_callbacks?id=dummy 200
119
120echo "=== Get counter - current events ==="
121RESULT="0"
122do_curl GET /counter/current_messages?id=dummy 200
123
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100124
125echo "=== Fetch an event ==="
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100126RESULT="json:{}"
127do_curl GET '/get-event/test' 200
128
129echo "=== Fetch an event ==="
130RESULT="json:{\"DATA-MSG\":\"msg\"}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100131do_curl GET '/get-event/test' 200
132
133echo "=== Fetch an event again ==="
134RESULT="*"
135do_curl GET '/get-event/test' 204
136
137echo "=== Get counter - callbacks ==="
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100138RESULT="2"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100139do_curl GET /counter/received_callbacks 200
140
141echo "=== Get counter - fetched events ==="
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100142RESULT="2"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100143do_curl GET /counter/fetched_callbacks 200
144
145echo "=== Get counter - current events ==="
146RESULT="0"
147do_curl GET /counter/current_messages 200
148
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100149# Test counter for one id
150echo "=== Get counter - callbacks ==="
151RESULT="2"
152do_curl GET /counter/received_callbacks?id=test 200
153
154echo "=== Get counter - fetched events ==="
155RESULT="2"
156do_curl GET /counter/fetched_callbacks?id=test 200
157
158echo "=== Get counter - current events ==="
159RESULT="0"
160do_curl GET /counter/current_messages?id=test 200
161
162echo "=== Send a request ==="
163RESULT="*"
164#create payload
165echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json
166do_curl POST '/callbacks/test' 200 .tmp.json
167
168echo "=== Send a request ==="
169RESULT="*"
170#create payload
171echo "{\"DATA-MSG2\":\"msg2\"}" > .tmp.json
172do_curl POST '/callbacks/test' 200 .tmp.json
173
174echo "=== Send a request ==="
175RESULT="*"
176#create payload
177echo "{\"DATA-MSG3\":\"msg3\"}" > .tmp.json
178do_curl POST '/callbacks/test1' 200 .tmp.json
179
180echo "=== Get counter - callbacks ==="
181RESULT="5"
182do_curl GET /counter/received_callbacks 200
183
184echo "=== Get counter - fetched events ==="
185RESULT="2"
186do_curl GET /counter/fetched_callbacks 200
187
188echo "=== Get counter - current events ==="
189RESULT="3"
190do_curl GET /counter/current_messages 200
191
192# Test counter for one id, test1
193echo "=== Get counter - callbacks ==="
194RESULT="1"
195do_curl GET /counter/received_callbacks?id=test1 200
196
197echo "=== Get counter - fetched events ==="
198RESULT="0"
199do_curl GET /counter/fetched_callbacks?id=test1 200
200
201echo "=== Get counter - current events ==="
202RESULT="1"
203do_curl GET /counter/current_messages?id=test1 200
204
205echo "=== Fetch all events ==="
206RESULT="json:[{\"DATA-MSG2\":\"msg2\"},{\"DATA-MSG\":\"msg\"}]"
207do_curl GET '/get-all-events/test' 200
208
209echo "=== Get counter - callbacks ==="
210RESULT="5"
211do_curl GET /counter/received_callbacks 200
212
213echo "=== Get counter - fetched events ==="
214RESULT="4"
215do_curl GET /counter/fetched_callbacks 200
216
217echo "=== Get counter - current events ==="
218RESULT="1"
219do_curl GET /counter/current_messages 200
220
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100221echo "=== CR reset ==="
222RESULT="OK"
223do_curl GET /reset 200
224
225echo "=== Get counter - callbacks ==="
226RESULT="0"
227do_curl GET /counter/received_callbacks 200
228
229echo "=== Get counter - fetched events ==="
230RESULT="0"
231do_curl GET /counter/fetched_callbacks 200
232
233echo "=== Get counter - current events ==="
234RESULT="0"
235do_curl GET /counter/current_messages 200
236
237
238echo "********************"
239echo "*** All tests ok ***"
240echo "********************"