Enhanced ECS function tests
[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 # Tests if a variable value in the ECS is equal to a target value and and optional timeout.
25 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
26 # equal to the target or not.
27 # Arg: <variable-name> <target-value> <timeout-in-sec>  - This test waits up to the timeout seconds
28 # before setting pass or fail depending on if the variable value becomes equal to the target
29 # value or not.
30 # (Function for test scripts)
31 ecs_equal() {
32         if [ $# -eq 2 ] || [ $# -eq 3 ]; then
33                 __var_test ECS "$LOCALHOST$ECS_EXTERNAL_PORT/" $1 "=" $2 $3
34         else
35                 __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
36         fi
37 }
38
39
40 ##########################################
41 ######### A1-E Enrichment  API ##########
42 ##########################################
43 #Function prefix: ecs_api_a1
44
45 # API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
46 # args: <response-code> <type-id>  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
47 # args (flat uri structure): <response-code> <type-id>|NOTYPE  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
48 # (Function for test scripts)
49 ecs_api_a1_get_job_ids() {
50         __log_test_start $@
51
52         if [ -z "$FLAT_A1_EI" ]; then
53                 # Valid number of parameters 4,5,6 etc
54         if [ $# -lt 3 ]; then
55                         __print_err "<response-code> <type-id>  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
56                         return 1
57                 fi
58         else
59                 echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW
60                 # Valid number of parameters 4,5,6 etc
61         if [ $# -lt 3 ]; then
62                         __print_err "<response-code> <type-id>|NOTYPE  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
63                         return 1
64                 fi
65         fi
66         search=""
67         if [ $3 != "NOWNER" ]; then
68                 search="?owner="$3
69         fi
70
71         if [  -z "$FLAT_A1_EI" ]; then
72                 query="/A1-EI/v1/eitypes/$2/eijobs$search"
73         else
74                 if [ $2 != "NOTYPE" ]; then
75                         if [ -z "$search" ]; then
76                                 search="?eiTypeId="$2
77                         else
78                                 search=$search"&eiTypeId="$2
79                         fi
80                 fi
81                 query="/A1-EI/v1/eijobs$search"
82         fi
83     res="$(__do_curl_to_api ECS GET $query)"
84     status=${res:${#res}-3}
85
86         if [ $status -ne $1 ]; then
87                 __log_test_fail_status_code $1 $status
88                 return 1
89         fi
90
91         if [ $# -gt 3 ]; then
92                 body=${res:0:${#res}-3}
93                 targetJson="["
94
95                 for pid in ${@:4} ; do
96                         if [ "$targetJson" != "[" ]; then
97                                 targetJson=$targetJson","
98                         fi
99                         if [ $pid != "EMPTY" ]; then
100                                 targetJson=$targetJson"\"$pid\""
101                         fi
102                 done
103
104                 targetJson=$targetJson"]"
105                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
106                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
107
108                 if [ $res -ne 0 ]; then
109                         __log_test_fail_body
110                         return 1
111                 fi
112         fi
113
114         __log_test_pass
115         return 0
116 }
117
118 # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}
119 # args: <response-code> <type-id> [<schema-file>]
120 # (Function for test scripts)
121 ecs_api_a1_get_type() {
122         __log_test_start $@
123
124     if [ $# -lt 2 ] || [ $# -gt 3 ]; then
125                 __print_err "<response-code> <type-id> [<schema-file>]" $@
126                 return 1
127         fi
128
129         query="/A1-EI/v1/eitypes/$2"
130     res="$(__do_curl_to_api ECS GET $query)"
131     status=${res:${#res}-3}
132
133         if [ $status -ne $1 ]; then
134                 __log_test_fail_status_code $1 $status
135                 return 1
136         fi
137
138         if [ $# -eq 3 ]; then
139                 body=${res:0:${#res}-3}
140                 if [ -f $3 ]; then
141                         schema=$(cat $3)
142                 else
143                         __log_test_fail_general "Schema file "$3", does not exist"
144                         return 1
145                 fi
146                 if [ -z "$FLAT_A1_EI" ]; then
147                         targetJson="{\"eiJobParametersSchema\":$schema}"
148                 else
149                         targetJson=$schema
150                 fi
151                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
152                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
153
154                 if [ $res -ne 0 ]; then
155                         __log_test_fail_body
156                         return 1
157                 fi
158         fi
159
160         __log_test_pass
161         return 0
162 }
163
164 # API Test function: GET /A1-EI/v1/eitypes
165 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
166 # (Function for test scripts)
167 ecs_api_a1_get_type_ids() {
168         __log_test_start $@
169
170     if [ $# -lt 1 ]; then
171                 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
172                 return 1
173         fi
174
175         query="/A1-EI/v1/eitypes"
176     res="$(__do_curl_to_api ECS GET $query)"
177     status=${res:${#res}-3}
178
179         if [ $status -ne $1 ]; then
180                 __log_test_fail_status_code $1 $status
181                 return 1
182         fi
183         if [ $# -gt 1 ]; then
184                 body=${res:0:${#res}-3}
185                 targetJson="["
186                 if [ $2 != "EMPTY" ]; then
187                         for pid in ${@:2} ; do
188                                 if [ "$targetJson" != "[" ]; then
189                                         targetJson=$targetJson","
190                                 fi
191                                 targetJson=$targetJson"\"$pid\""
192                         done
193                 fi
194                 targetJson=$targetJson"]"
195                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
196                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
197
198                 if [ $res -ne 0 ]; then
199                         __log_test_fail_body
200                         return 1
201                 fi
202         fi
203
204         __log_test_pass
205         return 0
206 }
207
208 # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
209 # args: <response-code> <type-id> <job-id> [<status>]
210 # args (flat uri structure): <response-code> <job-id> [<status>]
211 # (Function for test scripts)
212 ecs_api_a1_get_job_status() {
213         __log_test_start $@
214
215         if [ -z "$FLAT_A1_EI" ]; then
216                 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
217                         __print_err "<response-code> <type-id> <job-id> [<status>]" $@
218                         return 1
219                 fi
220
221                 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
222
223                 res="$(__do_curl_to_api ECS GET $query)"
224                 status=${res:${#res}-3}
225
226                 if [ $status -ne $1 ]; then
227                         __log_test_fail_status_code $1 $status
228                         return 1
229                 fi
230                 if [ $# -eq 4 ]; then
231                         body=${res:0:${#res}-3}
232                         targetJson="{\"operationalState\": \"$4\"}"
233                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
234                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
235
236                         if [ $res -ne 0 ]; then
237                                 __log_test_fail_body
238                                 return 1
239                         fi
240                 fi
241         else
242                 echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW
243                 if [ $# -ne 2 ] && [ $# -ne 3 ]; then
244                         __print_err "<response-code> <job-id> [<status>]" $@
245                         return 1
246                 fi
247
248                 query="/A1-EI/v1/eijobs/$2/status"
249
250                 res="$(__do_curl_to_api ECS GET $query)"
251                 status=${res:${#res}-3}
252
253                 if [ $status -ne $1 ]; then
254                         __log_test_fail_status_code $1 $status
255                         return 1
256                 fi
257                 if [ $# -eq 3 ]; then
258                         body=${res:0:${#res}-3}
259                         targetJson="{\"eiJobStatus\": \"$3\"}"
260                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
261                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
262
263                         if [ $res -ne 0 ]; then
264                                 __log_test_fail_body
265                                 return 1
266                         fi
267                 fi
268         fi
269
270         __log_test_pass
271         return 0
272 }
273
274 # API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
275 # args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
276 # args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
277 # (Function for test scripts)
278 ecs_api_a1_get_job() {
279         __log_test_start $@
280
281         if [  -z "$FLAT_A1_EI" ]; then
282                 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
283                         __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
284                         return 1
285                 fi
286                 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
287         else
288                 echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW
289                 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
290                         __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
291                         return 1
292                 fi
293                 query="/A1-EI/v1/eijobs/$2"
294         fi
295     res="$(__do_curl_to_api ECS GET $query)"
296     status=${res:${#res}-3}
297
298         if [ $status -ne $1 ]; then
299                 __log_test_fail_status_code $1 $status
300                 return 1
301         fi
302
303         if [  -z "$FLAT_A1_EI" ]; then
304                 if [ $# -eq 6 ]; then
305                         body=${res:0:${#res}-3}
306
307                         if [ -f $6 ]; then
308                                 jobfile=$(cat $6)
309                                 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
310                         else
311                                 _log_test_fail_general "Job template file "$6", does not exist"
312                                 return 1
313                         fi
314                         targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
315                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
316                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
317
318                         if [ $res -ne 0 ]; then
319                                 __log_test_fail_body
320                                 return 1
321                         fi
322                 fi
323         else
324                 if [ $# -eq 7 ]; then
325                         body=${res:0:${#res}-3}
326
327                         if [ -f $7 ]; then
328                                 jobfile=$(cat $7)
329                                 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
330                         else
331                                 _log_test_fail_general "Job template file "$6", does not exist"
332                                 return 1
333                         fi
334                         targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
335                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
336                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
337
338                         if [ $res -ne 0 ]; then
339                                 __log_test_fail_body
340                                 return 1
341                         fi
342                 fi
343         fi
344
345         __log_test_pass
346         return 0
347 }
348
349 # API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
350 # args: <response-code> <type-id> <job-id>
351 # args (flat uri structure): <response-code> <job-id>
352 # (Function for test scripts)
353 ecs_api_a1_delete_job() {
354         __log_test_start $@
355
356         if [  -z "$FLAT_A1_EI" ]; then
357                 if [ $# -ne 3 ]; then
358                         __print_err "<response-code> <type-id> <job-id>" $@
359                         return 1
360                 fi
361
362                 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
363         else
364                 echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW
365                 if [ $# -ne 2 ]; then
366                         __print_err "<response-code> <job-id>" $@
367                         return 1
368                 fi
369                 query="/A1-EI/v1/eijobs/$2"
370         fi
371     res="$(__do_curl_to_api ECS DELETE $query)"
372     status=${res:${#res}-3}
373
374         if [ $status -ne $1 ]; then
375                 __log_test_fail_status_code $1 $status
376                 return 1
377         fi
378
379         __log_test_pass
380         return 0
381 }
382
383 # API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
384 # args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
385 # args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
386 # (Function for test scripts)
387 ecs_api_a1_put_job() {
388         __log_test_start $@
389
390         if [  -z "$FLAT_A1_EI" ]; then
391                 if [ $# -lt 6 ]; then
392                         __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
393                         return 1
394                 fi
395                 if [ -f $6 ]; then
396                         jobfile=$(cat $6)
397                         jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
398                 else
399                         _log_test_fail_general "Job template file "$6", does not exist"
400                         return 1
401                 fi
402
403                 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
404                 file="./tmp/.p.json"
405                 echo "$inputJson" > $file
406
407                 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
408         else
409                 echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW
410                 if [ $# -lt 7 ]; then
411                         __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
412                         return 1
413                 fi
414                 if [ -f $7 ]; then
415                         jobfile=$(cat $7)
416                         jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
417                 else
418                         _log_test_fail_general "Job template file "$7", does not exist"
419                         return 1
420                 fi
421
422                 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
423                 file="./tmp/.p.json"
424                 echo "$inputJson" > $file
425
426                 query="/A1-EI/v1/eijobs/$2"
427         fi
428
429     res="$(__do_curl_to_api ECS PUT $query $file)"
430     status=${res:${#res}-3}
431
432         if [ $status -ne $1 ]; then
433                 __log_test_fail_status_code $1 $status
434                 return 1
435         fi
436
437         __log_test_pass
438         return 0
439 }
440
441
442 ##########################################
443 ####   Enrichment Data Producer API   ####
444 ##########################################
445 # Function prefix: ecs_api_edp
446
447 # API Test function: GET /ei-producer/v1/eitypes
448 # args: <response-code> [ EMPTY | <type-id>+]
449 # (Function for test scripts)
450 ecs_api_edp_get_type_ids() {
451         __log_test_start $@
452
453     if [ $# -lt 1 ]; then
454                 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
455                 return 1
456         fi
457
458         query="/ei-producer/v1/eitypes"
459     res="$(__do_curl_to_api ECS GET $query)"
460     status=${res:${#res}-3}
461
462         if [ $status -ne $1 ]; then
463                 __log_test_fail_status_code $1 $status
464                 return 1
465         fi
466
467         if [ $# -gt 1 ]; then
468                 body=${res:0:${#res}-3}
469                 targetJson="["
470                 if [ $2 != "EMPTY" ]; then
471                         for pid in ${@:2} ; do
472                                 if [ "$targetJson" != "[" ]; then
473                                         targetJson=$targetJson","
474                                 fi
475                                 targetJson=$targetJson"\"$pid\""
476                         done
477                 fi
478                 targetJson=$targetJson"]"
479                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
480                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
481
482                 if [ $res -ne 0 ]; then
483                         __log_test_fail_body
484                         return 1
485                 fi
486         fi
487
488         __log_test_pass
489         return 0
490 }
491
492 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
493 # args: <response-code> <producer-id> [<status> [<timeout>]]
494 # (Function for test scripts)
495 ecs_api_edp_get_producer_status() {
496         __log_test_start $@
497
498     if [ $# -lt 2 ] || [ $# -gt 4 ]; then
499                 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
500                 return 1
501         fi
502
503         query="/ei-producer/v1/eiproducers/$2/status"
504         start=$SECONDS
505         for (( ; ; )); do
506                 res="$(__do_curl_to_api ECS GET $query)"
507                 status=${res:${#res}-3}
508
509                 if [ $# -eq 4 ]; then
510                         duration=$((SECONDS-start))
511                         echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
512                         if [ $duration -gt $4 ]; then
513                                 echo ""
514                                 duration=-1  #Last iteration
515                         fi
516                 else
517                         duration=-1 #single test, no wait
518                 fi
519
520                 if [ $status -ne $1 ]; then
521                         if [ $duration -eq -1 ]; then
522                                 __log_test_fail_status_code $1 $status
523                                 return 1
524                         fi
525                 fi
526                 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
527                         body=${res:0:${#res}-3}
528                         targetJson="{\"operational_state\": \"$3\"}"
529                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
530                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
531
532                         if [ $res -ne 0 ]; then
533                                 if [ $duration -eq -1 ]; then
534                                         __log_test_fail_body
535                                         return 1
536                                 fi
537                         else
538                                 duration=-1  #Goto pass
539                         fi
540                 fi
541                 if [ $duration -eq -1 ]; then
542                         if [ $# -eq 4 ]; then
543                                 echo ""
544                         fi
545                         __log_test_pass
546                         return 0
547                 else
548                         sleep 1
549                 fi
550         done
551 }
552
553
554 # API Test function: GET /ei-producer/v1/eiproducers
555 # args: <response-code> [ EMPTY | <producer-id>+]
556 # (Function for test scripts)
557 ecs_api_edp_get_producer_ids() {
558         __log_test_start $@
559
560     if [ $# -lt 1 ]; then
561                 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
562                 return 1
563         fi
564
565         query="/ei-producer/v1/eiproducers"
566     res="$(__do_curl_to_api ECS GET $query)"
567     status=${res:${#res}-3}
568
569         if [ $status -ne $1 ]; then
570                 __log_test_fail_status_code $1 $status
571                 return 1
572         fi
573
574         if [ $# -gt 1 ]; then
575                 body=${res:0:${#res}-3}
576                 targetJson="["
577
578                 for pid in ${@:2} ; do
579                         if [ "$targetJson" != "[" ]; then
580                                 targetJson=$targetJson","
581                         fi
582                         if [ $pid != "EMPTY" ]; then
583                                 targetJson=$targetJson"\"$pid\""
584                         fi
585                 done
586
587                 targetJson=$targetJson"]"
588                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
589                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
590
591                 if [ $res -ne 0 ]; then
592                         __log_test_fail_body
593                         return 1
594                 fi
595         fi
596
597         __log_test_pass
598         return 0
599 }
600
601 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
602 # args: <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
603 # (Function for test scripts)
604 ecs_api_edp_get_type() {
605         __log_test_start $@
606
607         paramError=1
608         if [ $# -eq 2 ]; then
609                 paramError=0
610         fi
611         if [ $# -gt 3 ]; then
612                 paramError=0
613         fi
614     if [ $paramError -ne 0 ]; then
615                 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
616                 return 1
617         fi
618
619         query="/ei-producer/v1/eitypes/$2"
620     res="$(__do_curl_to_api ECS GET $query)"
621     status=${res:${#res}-3}
622
623         if [ $status -ne $1 ]; then
624                 __log_test_fail_status_code $1 $status
625                 return 1
626         fi
627         if [ $# -gt 3 ]; then
628                 body=${res:0:${#res}-3}
629
630                 if [ -f $3 ]; then
631                         schema=$(cat $3)
632                 else
633                         __log_test_fail_general "Job template file "$3", does not exist"
634                         return 1
635                 fi
636
637                 targetJson=""
638                 if [ $4 != "EMPTY" ]; then
639                         for pid in ${@:4} ; do
640                                 if [ "$targetJson" != "" ]; then
641                                         targetJson=$targetJson","
642                                 fi
643                                 targetJson=$targetJson"\"$pid\""
644                         done
645                 fi
646                 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
647
648                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
649                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
650
651                 if [ $res -ne 0 ]; then
652                         __log_test_fail_body
653                         return 1
654                 fi
655         fi
656         __log_test_pass
657         return 0
658 }
659
660 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
661 # args: <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
662 # (Function for test scripts)
663 ecs_api_edp_get_producer() {
664         __log_test_start $@
665
666         #Possible arg count: 2, 5 6, 8, 10 etc
667         paramError=1
668         if [ $# -eq 2 ]; then
669                 paramError=0
670         fi
671         if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
672                 paramError=0
673         fi
674         variablecount=$(($#-4))
675         if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
676                 paramError=0
677         fi
678
679     if [ $paramError -ne 0 ]; then
680                 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
681                 return 1
682         fi
683
684         query="/ei-producer/v1/eiproducers/$2"
685     res="$(__do_curl_to_api ECS GET $query)"
686     status=${res:${#res}-3}
687
688         if [ $status -ne $1 ]; then
689                 __log_test_fail_status_code $1 $status
690                 return 1
691         fi
692
693         if [ $# -gt 2 ]; then
694                 body=${res:0:${#res}-3}
695                 targetJson="["
696                 if [ $# -gt 5 ]; then
697                         arr=(${@:5})
698                         for ((i=0; i<$(($#-5)); i=i+2)); do
699                                 if [ "$targetJson" != "[" ]; then
700                                         targetJson=$targetJson","
701                                 fi
702                                 if [ -f ${arr[$i+1]} ]; then
703                                         schema=$(cat ${arr[$i+1]})
704                                 else
705                                         _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
706                                         return 1
707                                 fi
708
709                                 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
710                         done
711                 fi
712                 targetJson=$targetJson"]"
713                 if [ $# -gt 4 ]; then
714                         targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
715                 fi
716                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
717                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
718
719                 if [ $res -ne 0 ]; then
720                         __log_test_fail_body
721                         return 1
722                 fi
723         fi
724
725         __log_test_pass
726         return 0
727 }
728
729 # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
730 # args: <response-code> <producer-id>
731 # (Function for test scripts)
732 ecs_api_edp_delete_producer() {
733         __log_test_start $@
734
735     if [ $# -lt 2 ]; then
736                 __print_err "<response-code> <producer-id>" $@
737                 return 1
738         fi
739
740         query="/ei-producer/v1/eiproducers/$2"
741     res="$(__do_curl_to_api ECS DELETE $query)"
742     status=${res:${#res}-3}
743
744         if [ $status -ne $1 ]; then
745                 __log_test_fail_status_code $1 $status
746                 return 1
747         fi
748
749         __log_test_pass
750         return 0
751 }
752
753 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
754 # args: <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
755 # (Function for test scripts)
756 ecs_api_edp_put_producer() {
757         __log_test_start $@
758
759         #Valid number of parametrer 5,6,8,10,
760         paramError=1
761         if  [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
762                 paramError=0
763         elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
764                 paramError=0
765         fi
766         if [ $paramError -ne 0 ]; then
767                 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
768                 return 1
769         fi
770
771         inputJson="["
772         if [ $# -gt 5 ]; then
773                 arr=(${@:5})
774                 for ((i=0; i<$(($#-5)); i=i+2)); do
775                         if [ "$inputJson" != "[" ]; then
776                                 inputJson=$inputJson","
777                         fi
778                         if [ -f ${arr[$i+1]} ]; then
779                                 schema=$(cat ${arr[$i+1]})
780                         else
781                                 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
782                                 return 1
783                         fi
784                         inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
785                 done
786         fi
787         inputJson="\"supported_ei_types\":"$inputJson"]"
788
789         inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
790
791         inputJson="{"$inputJson"}"
792
793         file="./tmp/.p.json"
794         echo "$inputJson" > $file
795         query="/ei-producer/v1/eiproducers/$2"
796     res="$(__do_curl_to_api ECS PUT $query $file)"
797     status=${res:${#res}-3}
798
799         if [ $status -ne $1 ]; then
800                 __log_test_fail_status_code $1 $status
801                 return 1
802         fi
803
804         __log_test_pass
805         return 0
806 }
807
808 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
809 # args: <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <template-job-file>]+)
810 # (Function for test scripts)
811 ecs_api_edp_get_producer_jobs() {
812         __log_test_start $@
813
814         #Valid number of parameter 2,3,6,10
815         paramError=1
816         if [ $# -eq 2 ]; then
817                 paramError=0
818         fi
819         if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
820                 paramError=0
821         fi
822         variablecount=$(($#-2))
823         if [ $# -gt 3 ] && [ $(($variablecount%4)) -eq 0 ]; then
824                 paramError=0
825         fi
826         if [ $paramError -eq 1 ]; then
827                 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <template-job-file>]+)" $@
828                 return 1
829         fi
830
831         query="/ei-producer/v1/eiproducers/$2/eijobs"
832     res="$(__do_curl_to_api ECS GET $query)"
833     status=${res:${#res}-3}
834         if [ $status -ne $1 ]; then
835                 __log_test_fail_status_code $1 $status
836                 return 1
837         fi
838         if [ $# -gt 2 ]; then
839                 body=${res:0:${#res}-3}
840                 targetJson="["
841                 if [ $# -gt 3 ]; then
842                         arr=(${@:3})
843                         for ((i=0; i<$(($#-3)); i=i+4)); do
844                                 if [ "$targetJson" != "[" ]; then
845                                         targetJson=$targetJson","
846                                 fi
847                                 if [ -f ${arr[$i+3]} ]; then
848                                         jobfile=$(cat ${arr[$i+3]})
849                                         jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
850                                 else
851                                         _log_test_fail_general "Job template file "${arr[$i+3]}", does not exist"
852                                         return 1
853                                 fi
854                                 targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"ei_job_data\":$jobfile}"
855                         done
856                 fi
857                 targetJson=$targetJson"]"
858
859                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
860                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
861
862                 if [ $res -ne 0 ]; then
863                         __log_test_fail_body
864                         return 1
865                 fi
866         fi
867
868         __log_test_pass
869         return 0
870 }
871
872
873 ##########################################
874 ####          Service status          ####
875 ##########################################
876 # Function prefix: ecs_api_service
877
878 # API Test function: GET ​/status
879 # args: <response-code>
880 # (Function for test scripts)
881 ecs_api_service_status() {
882         __log_test_start $@
883
884     if [ $# -lt 1 ]; then
885                 __print_err "<response-code> [<producer-id>]*|NOID" $@
886                 return 1
887         fi
888         res="$(__do_curl_to_api ECS GET /status)"
889     status=${res:${#res}-3}
890         if [ $status -ne $1 ]; then
891                 __log_test_fail_status_code $1 $status
892                 return 1
893         fi
894         __log_test_pass
895         return 0
896 }