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 producer stub container
23 echo "Usage: ./basic_test.sh nonsecure|secure"
26 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
27 echo "Usage: ./basic_test.sh nonsecure|secure"
31 if [ $1 == "nonsecure" ]; then
32 #Default http port for the simulator
37 #Default https port for the simulator
43 # source function to do curl and check result
44 . ../common/do_curl_function.sh
46 echo "=== hello world ==="
52 do_curl GET /reset 200
56 do_curl GET /status 200
60 echo "=== check supervision counter ==="
62 do_curl GET /counter/supervision/prod-x 200
64 echo "=== check create counter ==="
66 do_curl GET /counter/create/prod-x/job-x 200
68 echo "=== check delete counter ==="
70 do_curl GET /counter/delete/prod-x/job-x 200
72 ## Create/update a producer
74 echo "=== create producer ==="
75 RESULT="Unknown query parameter(s)"
76 do_curl PUT /arm/supervision/prod-x?test=201 400
78 echo "=== create producer ==="
80 do_curl PUT /arm/supervision/prod-x?response=201 200
82 echo "=== update producer ==="
84 do_curl PUT /arm/supervision/prod-x?response=400 200
86 echo "=== update producer ==="
88 do_curl PUT /arm/supervision/prod-x 200
90 ## Add types to a producere
92 echo "=== add type 10 ==="
94 do_curl PUT /arm/type/prod-x/10 200
96 echo "=== add type 15 ==="
98 do_curl PUT /arm/type/prod-x/15 200
102 echo "=== status ==="
103 RESULT="json:{\"prod-x\": {\"supervision_response\": 200, \"supervision_counter\": 0, \"types\": [\"10\", \"15\"]}}"
104 do_curl GET /status 200
107 echo "=== add type 20 ==="
109 do_curl PUT /arm/type/prod-x/20 200
111 echo "=== status ==="
112 RESULT="json:{\"prod-x\": {\"supervision_response\": 200, \"supervision_counter\": 0, \"types\": [\"10\", \"15\", \"20\"]}}"
113 do_curl GET /status 200
116 echo "=== remove type 20 ==="
118 do_curl DELETE /arm/type/prod-x/20 200
120 echo "=== status ==="
121 RESULT="json:{\"prod-x\": {\"supervision_response\": 200, \"supervision_counter\": 0, \"types\": [\"10\", \"15\"]}}"
122 do_curl GET /status 200
124 ## producer supervision
125 echo "=== check supervision counter ==="
127 do_curl GET /counter/supervision/prod-x 200
129 echo "=== supervision producer ==="
131 do_curl GET /callbacks/supervision/prod-x 200
133 echo "=== update producer ==="
135 do_curl PUT /arm/supervision/prod-x?response=400 200
137 echo "=== callback supervision producer ==="
138 RESULT="returning configured response code"
139 do_curl GET /callbacks/supervision/prod-x 400
143 echo "=== status ==="
144 RESULT="json:{\"prod-x\": {\"supervision_response\": 400, \"supervision_counter\": 2, \"types\": [\"10\", \"15\"]}}"
145 do_curl GET /status 200
149 echo "=== add job ==="
151 do_curl PUT /arm/create/prod-x/job-y 200
153 echo "=== update job ==="
155 do_curl PUT /arm/create/prod-x/job-y?response=405 200
159 echo "=== status ==="
160 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}}}"
161 do_curl GET /status 200
163 ## add delete response for job
165 echo "=== update job ==="
167 do_curl PUT /arm/delete/prod-x/job-y?response=407 200
171 echo "=== status ==="
172 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}}}"
173 do_curl GET /status 200
176 echo "=== job data ==="
178 do_curl GET /jobdata/prod-x/job-y 204
182 echo "=== add job ==="
184 do_curl PUT /arm/create/prod-x/job-1 200
186 do_curl PUT /arm/delete/prod-x/job-1 200
188 echo "=== callback create job ==="
190 echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
191 do_curl POST /callbacks/job/prod-x 201 .p.json
193 echo "=== callback create job -update ==="
195 echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
196 do_curl POST /callbacks/job/prod-x 200 .p.json
199 echo "=== job data ==="
200 RESULT="json:{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\", \"ei_type_identity\": \"10\"}"
201 do_curl GET /jobdata/prod-x/job-1 200
205 echo "=== status ==="
206 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}}}"
207 do_curl GET /status 200
209 # create and delete job tests
210 echo "=== set job create response ==="
212 do_curl PUT /arm/create/prod-x/job-1?response=404 200
214 echo "=== callback create job -update ==="
215 RESULT="returning configured response code"
216 echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
217 do_curl POST /callbacks/job/prod-x 404 .p.json
219 echo "=== set job delete response ==="
221 do_curl PUT /arm/delete/prod-x/job-1?response=404 200
223 echo "=== callback delete job==="
224 RESULT="returning configured response code"
225 echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
226 do_curl DELETE /callbacks/job/prod-x/job-1 404 .p.json
228 echo "=== set job delete response ==="
230 do_curl PUT /arm/delete/prod-x/job-1 200
232 echo "=== callback delete job==="
234 echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
235 do_curl DELETE /callbacks/job/prod-x/job-1 204 .p.json
239 echo "=== status ==="
240 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}}}"
241 do_curl GET /status 200
246 echo "=== update producer ==="
248 do_curl PUT /arm/create/prod-x/job-1 200
250 echo "=== callback create job ==="
252 echo "{\"ei_job_identity\": \"job-1\", \"ei_job_data\": {}, \"target_uri\": \"http://localhost:80\",\"ei_type_identity\": \"10\"}" > .p.json
253 do_curl POST /callbacks/job/prod-x 201 .p.json
255 echo "=== data delivery start ==="
256 RESULT="job not found"
257 do_curl POST /jobdata/prod-x/job-x?action=START 404
259 echo "=== data delivery start ==="
261 do_curl POST /jobdata/prod-x/job-1?action=START 200
266 echo "=== data delivery stop ==="
268 do_curl POST /jobdata/prod-x/job-1?action=STOP 200
270 echo "********************"
271 echo "*** All tests ok ***"
272 echo "********************"