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