Restructure test cases and upgraded test environment
[nonrtric.git] / test / common / ecs_api_functions.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 # This is a script that contains specific test functions for ECS NB/SB API
21
22 . ../common/api_curl.sh
23
24 ############### EXPERIMENTAL #############
25
26 ##########################################
27 ###### Mainly only function skeletons ####
28 ##########################################
29
30 ##########################################
31 ### A1-E Enrichment Data Consumer API ####
32 ##########################################
33 #Function prefix: ecs_api_a1
34
35 # API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
36 # args: <response-code>
37 # (Function for test scripts)
38 ecs_api_a1_get_job_ids() {
39         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
40     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
41         ((RES_TEST++))
42
43     if [ $# -lt 1 ]; then
44                 __print_err "<response-code> [<producer-id>]*|NOID" $@
45                 return 1
46         fi
47
48         ((RES_PASS++))
49         echo -e $GREEN" PASS"$EGREEN
50         return 0
51 }
52
53 # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}
54 # args: <response-code>
55 # (Function for test scripts)
56 ecs_api_a1_get_type() {
57         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
58     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
59         ((RES_TEST++))
60
61     if [ $# -lt 1 ]; then
62                 __print_err "<response-code> [<producer-id>]*|NOID" $@
63                 return 1
64         fi
65
66         ((RES_PASS++))
67         echo -e $GREEN" PASS"$EGREEN
68         return 0
69 }
70
71 # API Test function: GET ​/A1-EI​/v1​/eitypes
72 # args: <response-code>
73 # (Function for test scripts)
74 ecs_api_a1_get_type_ids() {
75         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
76     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
77         ((RES_TEST++))
78
79     if [ $# -lt 1 ]; then
80                 __print_err "<response-code> [<producer-id>]*|NOID" $@
81                 return 1
82         fi
83
84         ((RES_PASS++))
85         echo -e $GREEN" PASS"$EGREEN
86         return 0
87 }
88
89 # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
90 # args: <response-code>
91 # (Function for test scripts)
92 ecs_api_a1_get_job_status() {
93         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
94     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
95         ((RES_TEST++))
96
97     if [ $# -lt 1 ]; then
98                 __print_err "<response-code> [<producer-id>]*|NOID" $@
99                 return 1
100         fi
101
102         ((RES_PASS++))
103         echo -e $GREEN" PASS"$EGREEN
104         return 0
105 }
106
107 # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
108 # args: <response-code>
109 # (Function for test scripts)
110 ecs_api_a1_get_job() {
111         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
112     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
113         ((RES_TEST++))
114
115     if [ $# -lt 1 ]; then
116                 __print_err "<response-code> [<producer-id>]*|NOID" $@
117                 return 1
118         fi
119
120         ((RES_PASS++))
121         echo -e $GREEN" PASS"$EGREEN
122         return 0
123 }
124
125 # API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
126 # args: <response-code>
127 # (Function for test scripts)
128 ecs_api_a1_delete_job() {
129         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
130     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
131         ((RES_TEST++))
132
133     if [ $# -lt 1 ]; then
134                 __print_err "<response-code> [<producer-id>]*|NOID" $@
135                 return 1
136         fi
137
138         ((RES_PASS++))
139         echo -e $GREEN" PASS"$EGREEN
140         return 0
141 }
142
143 # API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
144 # args: <response-code>
145 # (Function for test scripts)
146 ecs_api_a1_put_job() {
147         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
148     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
149         ((RES_TEST++))
150
151     if [ $# -lt 1 ]; then
152                 __print_err "<response-code> [<producer-id>]*|NOID" $@
153                 return 1
154         fi
155
156         ((RES_PASS++))
157         echo -e $GREEN" PASS"$EGREEN
158         return 0
159 }
160
161
162 ##########################################
163 ####   Enrichment Data Producer API   ####
164 ##########################################
165 # Function prefix: ecs_api_edp
166
167 # API Test function: GET /ei-producer/v1/eitypes
168 # args: <response-code>
169 # (Function for test scripts)
170 ecs_api_edp_get_type_ids() {
171         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
172     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
173         ((RES_TEST++))
174
175     if [ $# -lt 1 ]; then
176                 __print_err "<response-code> [<producer-id>]*|NOID" $@
177                 return 1
178         fi
179
180         ((RES_PASS++))
181         echo -e $GREEN" PASS"$EGREEN
182         return 0
183 }
184
185 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
186 # args: <response-code>
187 # (Function for test scripts)
188 ecs_api_edp_get_producer_status() {
189         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
190     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
191         ((RES_TEST++))
192
193     if [ $# -lt 1 ]; then
194                 __print_err "<response-code> [<producer-id>]*|NOID" $@
195                 return 1
196         fi
197
198         ((RES_PASS++))
199         echo -e $GREEN" PASS"$EGREEN
200         return 0
201 }
202
203
204 # API Test function: GET /ei-producer/v1/eiproducers
205 # args: <response-code> [<producer-id>]*|NOID
206 # (Function for test scripts)
207 ecs_api_edp_get_producer_ids() {
208         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
209     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
210         ((RES_TEST++))
211
212     if [ $# -lt 1 ]; then
213                 __print_err "<response-code> [<producer-id>]*|NOID" $@
214                 return 1
215         fi
216
217         query="/ei-producer/v1/eiproducers"
218     res="$(__do_curl_to_api ECS GET $query)"
219     status=${res:${#res}-3}
220
221         if [ $status -ne $1 ]; then
222                 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
223                 ((RES_FAIL++))
224                 __check_stop_at_error
225                 return 1
226         fi
227
228         if [ $# -gt 1 ]; then
229                 body=${res:0:${#res}-3}
230                 targetJson="["
231
232                 for pid in ${@:2} ; do
233                         if [ "$targetJson" != "[" ]; then
234                                 targetJson=$targetJson","
235                         fi
236                         if [ $pid != "NOID" ]; then
237                                 targetJson=$targetJson"\"$pid\""
238                         fi
239                 done
240
241                 targetJson=$targetJson"]"
242                 echo "TARGET JSON: $targetJson" >> $HTTPLOG
243                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
244
245                 if [ $res -ne 0 ]; then
246                         echo -e $RED" FAIL, returned body not correct"$ERED
247                         ((RES_FAIL++))
248                         __check_stop_at_error
249                         return 1
250                 fi
251         fi
252
253         ((RES_PASS++))
254         echo -e $GREEN" PASS"$EGREEN
255         return 0
256 }
257
258 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
259 # args: <response-code>
260 # (Function for test scripts)
261 ecs_api_edp_get_type() {
262         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
263     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
264         ((RES_TEST++))
265
266     if [ $# -lt 1 ]; then
267                 __print_err "<response-code> [<producer-id>]*|NOID" $@
268                 return 1
269         fi
270
271         ((RES_PASS++))
272         echo -e $GREEN" PASS"$EGREEN
273         return 0
274 }
275
276 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
277 # args: <response-code>
278 # (Function for test scripts)
279 ecs_api_edp_get_producer() {
280         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
281     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
282         ((RES_TEST++))
283
284     if [ $# -lt 1 ]; then
285                 __print_err "<response-code> [<producer-id>]*|NOID" $@
286                 return 1
287         fi
288
289         ((RES_PASS++))
290         echo -e $GREEN" PASS"$EGREEN
291         return 0
292 }
293
294 # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
295 # args: <response-code>
296 # (Function for test scripts)
297 ecs_api_edp_delete_producer() {
298         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
299     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
300         ((RES_TEST++))
301
302     if [ $# -lt 1 ]; then
303                 __print_err "<response-code> [<producer-id>]*|NOID" $@
304                 return 1
305         fi
306
307         ((RES_PASS++))
308         echo -e $GREEN" PASS"$EGREEN
309         return 0
310 }
311
312 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
313 # args: <response-code>
314 # (Function for test scripts)
315 ecs_api_edp_put_producer() {
316         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
317     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
318         ((RES_TEST++))
319
320     if [ $# -lt 1 ]; then
321                 __print_err "<response-code> [<producer-id>]*|NOID" $@
322                 return 1
323         fi
324
325         ((RES_PASS++))
326         echo -e $GREEN" PASS"$EGREEN
327         return 0
328 }
329
330 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
331 # args: <response-code>
332 # (Function for test scripts)
333 ecs_api_edp_get_producer_jobs() {
334         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
335     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
336         ((RES_TEST++))
337
338     if [ $# -lt 1 ]; then
339                 __print_err "<response-code> [<producer-id>]*|NOID" $@
340                 return 1
341         fi
342
343         ((RES_PASS++))
344         echo -e $GREEN" PASS"$EGREEN
345         return 0
346 }
347
348
349 ##########################################
350 ####        Producer Simulator        ####
351 ##########################################
352 # Function prefix: ecs_api_sim
353
354 # API Test function: POST ​/producer_simulator​/job_deleted_error
355 # args: <response-code>
356 # (Function for test scripts)
357 ecs_api_sim_post_job_delete_error() {
358         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
359     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
360         ((RES_TEST++))
361
362     if [ $# -lt 1 ]; then
363                 __print_err "<response-code> [<producer-id>]*|NOID" $@
364                 return 1
365         fi
366
367         ((RES_PASS++))
368         echo -e $GREEN" PASS"$EGREEN
369         return 0
370 }
371
372 # API Test function: GET /producer_simulator​/supervision
373 # args: <response-code>
374 # (Function for test scripts)
375 ecs_api_sim_get_producer_supervision() {
376         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
377     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
378         ((RES_TEST++))
379
380     if [ $# -lt 1 ]; then
381                 __print_err "<response-code> [<producer-id>]*|NOID" $@
382                 return 1
383         fi
384
385         ((RES_PASS++))
386         echo -e $GREEN" PASS"$EGREEN
387         return 0
388 }
389
390 # API Test function: POST /producer_simulator​/job_deleted
391 # args: <response-code>
392 # (Function for test scripts)
393 ecs_api_sim_post_job_deleted() {
394         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
395     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
396         ((RES_TEST++))
397
398     if [ $# -lt 1 ]; then
399                 __print_err "<response-code> [<producer-id>]*|NOID" $@
400                 return 1
401         fi
402
403         ((RES_PASS++))
404         echo -e $GREEN" PASS"$EGREEN
405         return 0
406 }
407
408 # API Test function: GET ​/producer_simulator​/supervision_error
409 # args: <response-code>
410 # (Function for test scripts)
411 ecs_api_get_producer_supervision_error() {
412         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
413     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
414         ((RES_TEST++))
415
416     if [ $# -lt 1 ]; then
417                 __print_err "<response-code> [<producer-id>]*|NOID" $@
418                 return 1
419         fi
420
421         ((RES_PASS++))
422         echo -e $GREEN" PASS"$EGREEN
423         return 0
424 }
425
426 # API Test function: POST /producer_simulator​/job_created_error
427 # args: <response-code>
428 # (Function for test scripts)
429 ecs_api_sim_get_job_created_error() {
430         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
431     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
432         ((RES_TEST++))
433
434     if [ $# -lt 1 ]; then
435                 __print_err "<response-code> [<producer-id>]*|NOID" $@
436                 return 1
437         fi
438
439         ((RES_PASS++))
440         echo -e $GREEN" PASS"$EGREEN
441         return 0
442 }
443
444 # API Test function: POST ​/producer_simulator​/job_created
445 # args: <response-code>
446 # (Function for test scripts)
447 ecs_api_sim_get_job_created() {
448         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
449     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
450         ((RES_TEST++))
451
452     if [ $# -lt 1 ]; then
453                 __print_err "<response-code> [<producer-id>]*|NOID" $@
454                 return 1
455         fi
456
457         ((RES_PASS++))
458         echo -e $GREEN" PASS"$EGREEN
459         return 0
460 }
461
462
463 ##########################################
464 ####          Service status          ####
465 ##########################################
466 # Function prefix: ecs_api_service
467
468 # API Test function: GET ​/status
469 # args: <response-code>
470 # (Function for test scripts)
471 ecs_api_service_status() {
472         echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
473     echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
474         ((RES_TEST++))
475
476     if [ $# -lt 1 ]; then
477                 __print_err "<response-code> [<producer-id>]*|NOID" $@
478                 return 1
479         fi
480
481         ((RES_PASS++))
482         echo -e $GREEN" PASS"$EGREEN
483         return 0
484 }