Updated image tags for tests
[nonrtric.git] / test / prodstub / 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 producer stub container
21
22 if [ $# -ne 1 ]; then
23     echo "Usage: ./basic_test.sh nonsecure|secure"
24     exit 1
25 fi
26 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
27     echo "Usage: ./basic_test.sh nonsecure|secure"
28     exit 1
29 fi
30
31 if [ $1 == "nonsecure" ]; then
32     #Default http port for the simulator
33     PORT=8992
34     # Set http protocol
35     HTTPX="http"
36 else
37     #Default https port for the simulator
38     PORT=8993
39     # Set https protocol
40     HTTPX="https"
41 fi
42
43 # source function to do curl and check result
44 . ../common/do_curl_function.sh
45 RESP_CONTENT="*"
46
47 echo "=== hello world ==="
48 RESULT="OK"
49 do_curl GET / 200
50
51 echo "=== reset ==="
52 RESULT=""
53 do_curl GET /reset 200
54
55 echo "=== status ==="
56 RESULT="json:{}"
57 do_curl GET /status 200
58
59 # Basic admin
60
61 echo "===  check supervision counter ==="
62 RESULT="-1"
63 do_curl GET /counter/supervision/prod-x 200
64
65 echo "===  check create counter ==="
66 RESULT="-1"
67 do_curl GET /counter/create/prod-x/job-x 200
68
69 echo "===  check delete counter ==="
70 RESULT="-1"
71 do_curl GET /counter/delete/prod-x/job-x 200
72
73 ## Create/update a producer
74
75 echo "===  create producer ==="
76 RESULT="Unknown query parameter(s)"
77 do_curl PUT /arm/supervision/prod-x?test=201 400
78
79 echo "===  create producer ==="
80 RESULT=""
81 do_curl PUT /arm/supervision/prod-x?response=201 200
82
83 echo "===  update producer ==="
84 RESULT=""
85 do_curl PUT /arm/supervision/prod-x?response=400 200
86
87 echo "===  update producer ==="
88 RESULT=""
89 do_curl PUT /arm/supervision/prod-x 200
90
91 ## Add types to a producere
92
93 echo "===  add type 10 ==="
94 RESULT=""
95 do_curl PUT /arm/type/prod-x/10 200
96
97 echo "===  add type 15 ==="
98 RESULT=""
99 do_curl PUT /arm/type/prod-x/15 200
100
101 ## check the db
102
103 echo "=== status ==="
104 RESULT="json:{\"prod-x\": {\"supervision_response\": 200, \"supervision_counter\": 0, \"types\": [\"10\", \"15\"]}}"
105 do_curl GET /status 200
106
107 ## Add type
108 echo "===  add type 20 ==="
109 RESULT=""
110 do_curl PUT /arm/type/prod-x/20 200
111
112 echo "=== status ==="
113 RESULT="json:{\"prod-x\": {\"supervision_response\": 200, \"supervision_counter\": 0, \"types\": [\"10\", \"15\", \"20\"]}}"
114 do_curl GET /status 200
115
116 ## remove type
117 echo "===  remove type 20 ==="
118 RESULT=""
119 do_curl DELETE /arm/type/prod-x/20 200
120
121 echo "=== status ==="
122 RESULT="json:{\"prod-x\": {\"supervision_response\": 200, \"supervision_counter\": 0, \"types\": [\"10\", \"15\"]}}"
123 do_curl GET /status 200
124
125 ## producer supervision
126 echo "===  check supervision counter ==="
127 RESULT="0"
128 do_curl GET /counter/supervision/prod-x 200
129
130 echo "===  supervision producer ==="
131 RESULT=""
132 do_curl GET /callbacks/supervision/prod-x 200
133
134 echo "===  update producer ==="
135 RESULT=""
136 do_curl PUT /arm/supervision/prod-x?response=400 200
137
138 echo "===  callback supervision producer ==="
139 RESULT="returning configured response code"
140 do_curl GET /callbacks/supervision/prod-x 400
141
142 ## check the db
143
144 echo "=== status ==="
145 RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"]}}"
146 do_curl GET /status 200
147
148 ## create/update job
149
150 echo "===  add job ==="
151 RESULT=""
152 do_curl PUT /arm/create/prod-x/job-y 200
153
154 echo "===  update job ==="
155 RESULT=""
156 do_curl PUT /arm/create/prod-x/job-y?response=405 200
157
158 ## check the db
159
160 echo "=== status ==="
161 RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 404, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": \"stopped\", \"delivery_attempts\": 0}}}"
162 do_curl GET /status 200
163
164 ## add delete response for job
165
166 echo "===  update job ==="
167 RESULT=""
168 do_curl PUT /arm/delete/prod-x/job-y?response=407 200
169
170 ## check the db
171
172 echo "=== status ==="
173 RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 407, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": \"stopped\", \"delivery_attempts\": 0}}}"
174 do_curl GET /status 200
175
176 ## Get jobdata
177 echo "=== job data ==="
178 RESULT=""
179 do_curl GET /jobdata/prod-x/job-y 204
180
181 ##  callback create
182
183 echo "===  add job ==="
184 RESULT=""
185 do_curl PUT /arm/create/prod-x/job-1 200
186 RESULT=""
187 do_curl PUT /arm/delete/prod-x/job-1 200
188
189 echo "===  callback create job ==="
190 RESULT=""
191 echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
192 do_curl POST /callbacks/job/prod-x 201 .p.json
193
194 echo "===  callback create job -update ==="
195 RESULT=""
196 echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
197 do_curl POST /callbacks/job/prod-x 200 .p.json
198
199 ## Get jobdata
200 echo "=== job data ==="
201 RESULT="json:{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\", \"ei_type_identity\": \"10\"}"
202 do_curl GET /jobdata/prod-x/job-1 200
203
204 ## check the db
205
206 echo "=== status ==="
207 RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 407, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": \"stopped\", \"delivery_attempts\": 0}, \"job-1\": {\"create_response\": 200, \"delete_response\": 204, \"json\": {\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\", \"ei_type_identity\": \"10\"}, \"create_counter\": 2, \"delete_counter\": 0, \"delivering\": \"delivering\", \"delivery_attempts\": 0}}}"
208 do_curl GET /status 200
209
210 # create and delete job tests
211 echo "===  set job create response ==="
212 RESULT=""
213 do_curl PUT /arm/create/prod-x/job-1?response=404 200
214
215 echo "===  callback create job -update ==="
216 RESULT="returning configured response code"
217 echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
218 do_curl POST /callbacks/job/prod-x 404 .p.json
219
220 echo "===  set job delete response ==="
221 RESULT=""
222 do_curl PUT /arm/delete/prod-x/job-1?response=404 200
223
224 echo "===  callback delete job==="
225 RESULT="returning configured response code"
226 echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
227 do_curl DELETE /callbacks/job/prod-x/job-1 404 .p.json
228
229 echo "===  set job delete response ==="
230 RESULT=""
231 do_curl PUT /arm/delete/prod-x/job-1 200
232
233 echo "===  callback delete job==="
234 RESULT=""
235 echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
236 do_curl DELETE /callbacks/job/prod-x/job-1 204 .p.json
237
238 ## check the db
239
240 echo "=== status ==="
241 RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"], \"job-y\": {\"create_response\": 405, \"delete_response\": 407, \"json\": null, \"create_counter\": 0, \"delete_counter\": 0, \"delivering\": \"stopped\", \"delivery_attempts\": 0}, \"job-1\": {\"create_response\": 404, \"delete_response\": 404, \"json\": null, \"create_counter\": 3, \"delete_counter\": 2, \"delivering\": \"stopped\", \"delivery_attempts\": 0}}}"
242 do_curl GET /status 200
243
244
245 ##  data delivery
246
247 echo "===  update producer ==="
248 RESULT=""
249 do_curl PUT /arm/create/prod-x/job-1 200
250
251 echo "===  callback create job ==="
252 RESULT=""
253 echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
254 do_curl POST /callbacks/job/prod-x 201 .p.json
255
256 echo "=== data delivery start ==="
257 RESULT="job not found"
258 do_curl POST /jobdata/prod-x/job-x?action=START 404
259
260 echo "=== data delivery start ==="
261 RESULT=""
262 do_curl POST /jobdata/prod-x/job-1?action=START 200
263
264 echo "sleep 5"
265 sleep 5
266
267 echo "=== data delivery stop ==="
268 RESULT=""
269 do_curl POST /jobdata/prod-x/job-1?action=STOP 200
270
271 echo "********************"
272 echo "*** All tests ok ***"
273 echo "********************"