blob: 6c4317342b471231ec588e91871cfc78223115d9 [file] [log] [blame]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001#!/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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +010024# 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)
31ecs_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
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020039
40##########################################
BjornMagnussonXA7b36db62020-11-23 10:57:57 +010041######### A1-E Enrichment API ##########
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020042##########################################
43#Function prefix: ecs_api_a1
44
45# API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +020046# args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXA4207b832020-11-03 09:52:49 +010047# args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020048# (Function for test scripts)
49ecs_api_a1_get_job_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +010050 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020051
BjornMagnussonXA4207b832020-11-03 09:52:49 +010052 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
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020065 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +010066 search=""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +020067 if [ $3 != "NOWNER" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +010068 search="?owner="$3
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +020069 fi
70
BjornMagnussonXA4207b832020-11-03 09:52:49 +010071 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
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +020083 res="$(__do_curl_to_api ECS GET $query)"
84 status=${res:${#res}-3}
85
86 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +010087 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +020088 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100109 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200110 return 1
111 fi
112 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200113
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100114 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200115 return 0
116}
117
118# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200119# args: <response-code> <type-id> [<schema-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200120# (Function for test scripts)
121ecs_api_a1_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100122 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200123
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200124 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
125 __print_err "<response-code> <type-id> [<schema-file>]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200126 return 1
127 fi
128
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200129 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100134 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200135 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100143 __log_test_fail_general "Schema file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200144 return 1
145 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100146 if [ -z "$FLAT_A1_EI" ]; then
147 targetJson="{\"eiJobParametersSchema\":$schema}"
148 else
149 targetJson=$schema
150 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200151 echo " TARGET JSON: $targetJson" >> $HTTPLOG
152 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
153
154 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100155 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200156 return 1
157 fi
158 fi
159
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100160 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200161 return 0
162}
163
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200164# API Test function: GET /A1-EI/v1/eitypes
165# args: <response-code> [ (EMPTY | [<type-id>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200166# (Function for test scripts)
167ecs_api_a1_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100168 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200169
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200170 if [ $# -lt 1 ]; then
171 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200172 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100180 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200181 return 1
182 fi
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200183 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")
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200197
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200198 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100199 __log_test_fail_body
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200200 return 1
201 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200202 fi
203
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100204 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200205 return 0
206}
207
208# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200209# args: <response-code> <type-id> <job-id> [<status>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100210# args (flat uri structure): <response-code> <job-id> [<status>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200211# (Function for test scripts)
212ecs_api_a1_get_job_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100213 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200214
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100215 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
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200220
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100221 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200222
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100223 res="$(__do_curl_to_api ECS GET $query)"
224 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200225
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100226 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100227 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200228 return 1
229 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100230 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100237 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100238 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100254 __log_test_fail_status_code $1 $status
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100255 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100264 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100265 return 1
266 fi
267 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200268 fi
269
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100270 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200271 return 0
272}
273
274# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200275# args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100276# args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200277# (Function for test scripts)
278ecs_api_a1_get_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100279 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200280
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100281 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"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200294 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200295 res="$(__do_curl_to_api ECS GET $query)"
296 status=${res:${#res}-3}
297
298 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100299 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200300 return 1
301 fi
302
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100303 if [ -z "$FLAT_A1_EI" ]; then
304 if [ $# -eq 6 ]; then
305 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200306
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100307 if [ -f $6 ]; then
308 jobfile=$(cat $6)
309 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
310 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100311 _log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100312 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100319 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100320 return 1
321 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200322 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100323 else
324 if [ $# -eq 7 ]; then
325 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200326
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100327 if [ -f $7 ]; then
328 jobfile=$(cat $7)
329 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
330 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100331 _log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100332 return 1
333 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100334 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100335 echo " TARGET JSON: $targetJson" >> $HTTPLOG
336 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
337
338 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100339 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100340 return 1
341 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200342 fi
343 fi
344
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100345 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200346 return 0
347}
348
349# API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200350# args: <response-code> <type-id> <job-id>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100351# args (flat uri structure): <response-code> <job-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200352# (Function for test scripts)
353ecs_api_a1_delete_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100354 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200355
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100356 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
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200361
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100362 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
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200371 res="$(__do_curl_to_api ECS DELETE $query)"
372 status=${res:${#res}-3}
373
374 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100375 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200376 return 1
377 fi
378
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100379 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200380 return 0
381}
382
383# API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200384# args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100385# args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200386# (Function for test scripts)
387ecs_api_a1_put_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100388 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200389
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100390 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100399 _log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100400 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"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200408 else
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100409 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100418 _log_test_fail_general "Job template file "$7", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100419 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"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200427 fi
428
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200429 res="$(__do_curl_to_api ECS PUT $query $file)"
430 status=${res:${#res}-3}
431
432 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100433 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200434 return 1
435 fi
436
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100437 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200438 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
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200448# args: <response-code> [ EMPTY | <type-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200449# (Function for test scripts)
450ecs_api_edp_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100451 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200452
453 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200454 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200455 return 1
456 fi
457
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200458 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100463 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200464 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100483 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200484 return 1
485 fi
486 fi
487
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100488 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200489 return 0
490}
491
492# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100493# args: <response-code> <producer-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200494# (Function for test scripts)
495ecs_api_edp_get_producer_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100496 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200497
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100498 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
499 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200500 return 1
501 fi
502
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200503 query="/ei-producer/v1/eiproducers/$2/status"
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100504 start=$SECONDS
505 for (( ; ; )); do
506 res="$(__do_curl_to_api ECS GET $query)"
507 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200508
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100509 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
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200518 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200519
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100520 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
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200551}
552
553
554# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200555# args: <response-code> [ EMPTY | <producer-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200556# (Function for test scripts)
557ecs_api_edp_get_producer_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100558 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200559
560 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200561 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200562 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100570 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200571 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
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200582 if [ $pid != "EMPTY" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200583 targetJson=$targetJson"\"$pid\""
584 fi
585 done
586
587 targetJson=$targetJson"]"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200588 echo " TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200589 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
590
591 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100592 __log_test_fail_body
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200593 return 1
594 fi
595 fi
596
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100597 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200598 return 0
599}
600
601# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200602# args: <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200603# (Function for test scripts)
604ecs_api_edp_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100605 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200606
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200607 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
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200615 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200616 return 1
617 fi
618
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200619 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100624 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200625 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100633 __log_test_fail_general "Job template file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200634 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100652 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200653 return 1
654 fi
655 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100656 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200657 return 0
658}
659
660# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100661# args: <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200662# (Function for test scripts)
663ecs_api_edp_get_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100664 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200665
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100666 #Possible arg count: 2, 5 6, 8, 10 etc
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200667 paramError=1
668 if [ $# -eq 2 ]; then
669 paramError=0
670 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100671 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200672 paramError=0
673 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100674 variablecount=$(($#-4))
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200675 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
676 paramError=0
677 fi
678
679 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100680 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200681 return 1
682 fi
683
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200684 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100689 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200690 return 1
691 fi
692
693 if [ $# -gt 2 ]; then
694 body=${res:0:${#res}-3}
695 targetJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100696 if [ $# -gt 5 ]; then
697 arr=(${@:5})
698 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200699 if [ "$targetJson" != "[" ]; then
700 targetJson=$targetJson","
701 fi
702 if [ -f ${arr[$i+1]} ]; then
703 schema=$(cat ${arr[$i+1]})
704 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100705 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200706 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100714 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200715 fi
716 echo " TARGET JSON: $targetJson" >> $HTTPLOG
717 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
718
719 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100720 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200721 return 1
722 fi
723 fi
724
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100725 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200726 return 0
727}
728
729# API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200730# args: <response-code> <producer-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200731# (Function for test scripts)
732ecs_api_edp_delete_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100733 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200734
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200735 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100745 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200746 return 1
747 fi
748
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100749 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200750 return 0
751}
752
753# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100754# args: <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200755# (Function for test scripts)
756ecs_api_edp_put_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100757 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200758
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100759 #Valid number of parametrer 5,6,8,10,
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200760 paramError=1
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100761 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200762 paramError=0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100763 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200764 paramError=0
765 fi
766 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100767 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200768 return 1
769 fi
770
771 inputJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100772 if [ $# -gt 5 ]; then
773 arr=(${@:5})
774 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200775 if [ "$inputJson" != "[" ]; then
776 inputJson=$inputJson","
777 fi
778 if [ -f ${arr[$i+1]} ]; then
779 schema=$(cat ${arr[$i+1]})
780 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100781 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200782 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100789 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200790
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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100800 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200801 return 1
802 fi
803
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100804 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200805 return 0
806}
807
808# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXA2138b632020-11-30 21:17:32 +0100809# args: <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200810# (Function for test scripts)
811ecs_api_edp_get_producer_jobs() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100812 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200813
BjornMagnussonXA2138b632020-11-30 21:17:32 +0100814 #Valid number of parameter 2,3,7,11
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200815 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))
BjornMagnussonXA2138b632020-11-30 21:17:32 +0100823 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200824 paramError=0
825 fi
826 if [ $paramError -eq 1 ]; then
BjornMagnussonXA2138b632020-11-30 21:17:32 +0100827 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200828 return 1
829 fi
830
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200831 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
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100835 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200836 return 1
837 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200838 if [ $# -gt 2 ]; then
839 body=${res:0:${#res}-3}
840 targetJson="["
841 if [ $# -gt 3 ]; then
842 arr=(${@:3})
BjornMagnussonXA2138b632020-11-30 21:17:32 +0100843 for ((i=0; i<$(($#-3)); i=i+5)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200844 if [ "$targetJson" != "[" ]; then
845 targetJson=$targetJson","
846 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +0100847 if [ -f ${arr[$i+4]} ]; then
848 jobfile=$(cat ${arr[$i+4]})
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200849 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
850 else
BjornMagnussonXA2138b632020-11-30 21:17:32 +0100851 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200852 return 1
853 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +0100854 targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200855 done
856 fi
857 targetJson=$targetJson"]"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200858
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200859 echo " TARGET JSON: $targetJson" >> $HTTPLOG
860 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200861
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200862 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100863 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200864 return 1
865 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200866 fi
867
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100868 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200869 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)
881ecs_api_service_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100882 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200883
884 if [ $# -lt 1 ]; then
885 __print_err "<response-code> [<producer-id>]*|NOID" $@
886 return 1
887 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100888 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
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200895 return 0
896}