3 # ============LICENSE_START===============================================
4 # Copyright (C) 2020 Nordix Foundation. All rights reserved.
5 # ========================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=================================================
20 # This is a script that contains specific test functions for ECS NB/SB API
22 . ../common/api_curl.sh
24 ############### EXPERIMENTAL #############
26 ##########################################
27 ###### Mainly only function skeletons ####
28 ##########################################
30 ##########################################
31 ### A1-E Enrichment Data Consumer API ####
32 ##########################################
33 #Function prefix: ecs_api_a1
35 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs
36 # args: <response-code>
37 # (Function for test scripts)
38 ecs_api_a1_get_job_ids() {
39 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
40 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
44 __print_err "<response-code> [<producer-id>]*|NOID" $@
49 echo -e $GREEN" PASS"$EGREEN
53 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}
54 # args: <response-code>
55 # (Function for test scripts)
56 ecs_api_a1_get_type() {
57 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
58 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
62 __print_err "<response-code> [<producer-id>]*|NOID" $@
67 echo -e $GREEN" PASS"$EGREEN
71 # API Test function: GET /A1-EI/v1/eitypes
72 # args: <response-code>
73 # (Function for test scripts)
74 ecs_api_a1_get_type_ids() {
75 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
76 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
80 __print_err "<response-code> [<producer-id>]*|NOID" $@
85 echo -e $GREEN" PASS"$EGREEN
89 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}/status
90 # args: <response-code>
91 # (Function for test scripts)
92 ecs_api_a1_get_job_status() {
93 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
94 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
98 __print_err "<response-code> [<producer-id>]*|NOID" $@
103 echo -e $GREEN" PASS"$EGREEN
107 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
108 # args: <response-code>
109 # (Function for test scripts)
110 ecs_api_a1_get_job() {
111 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
112 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
115 if [ $# -lt 1 ]; then
116 __print_err "<response-code> [<producer-id>]*|NOID" $@
121 echo -e $GREEN" PASS"$EGREEN
125 # API Test function: DELETE /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
126 # args: <response-code>
127 # (Function for test scripts)
128 ecs_api_a1_delete_job() {
129 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
130 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
133 if [ $# -lt 1 ]; then
134 __print_err "<response-code> [<producer-id>]*|NOID" $@
139 echo -e $GREEN" PASS"$EGREEN
143 # API Test function: PUT /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
144 # args: <response-code>
145 # (Function for test scripts)
146 ecs_api_a1_put_job() {
147 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
148 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
151 if [ $# -lt 1 ]; then
152 __print_err "<response-code> [<producer-id>]*|NOID" $@
157 echo -e $GREEN" PASS"$EGREEN
162 ##########################################
163 #### Enrichment Data Producer API ####
164 ##########################################
165 # Function prefix: ecs_api_edp
167 # API Test function: GET /ei-producer/v1/eitypes
168 # args: <response-code>
169 # (Function for test scripts)
170 ecs_api_edp_get_type_ids() {
171 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
172 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
175 if [ $# -lt 1 ]; then
176 __print_err "<response-code> [<producer-id>]*|NOID" $@
181 echo -e $GREEN" PASS"$EGREEN
185 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
186 # args: <response-code>
187 # (Function for test scripts)
188 ecs_api_edp_get_producer_status() {
189 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
190 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
193 if [ $# -lt 1 ]; then
194 __print_err "<response-code> [<producer-id>]*|NOID" $@
199 echo -e $GREEN" PASS"$EGREEN
204 # API Test function: GET /ei-producer/v1/eiproducers
205 # args: <response-code> [<producer-id>]*|NOID
206 # (Function for test scripts)
207 ecs_api_edp_get_producer_ids() {
208 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
209 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
212 if [ $# -lt 1 ]; then
213 __print_err "<response-code> [<producer-id>]*|NOID" $@
217 query="/ei-producer/v1/eiproducers"
218 res="$(__do_curl_to_api ECS GET $query)"
219 status=${res:${#res}-3}
221 if [ $status -ne $1 ]; then
222 echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
224 __check_stop_at_error
228 if [ $# -gt 1 ]; then
229 body=${res:0:${#res}-3}
232 for pid in ${@:2} ; do
233 if [ "$targetJson" != "[" ]; then
234 targetJson=$targetJson","
236 if [ $pid != "NOID" ]; then
237 targetJson=$targetJson"\"$pid\""
241 targetJson=$targetJson"]"
242 echo "TARGET JSON: $targetJson" >> $HTTPLOG
243 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
245 if [ $res -ne 0 ]; then
246 echo -e $RED" FAIL, returned body not correct"$ERED
248 __check_stop_at_error
254 echo -e $GREEN" PASS"$EGREEN
258 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
259 # args: <response-code>
260 # (Function for test scripts)
261 ecs_api_edp_get_type() {
262 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
263 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
266 if [ $# -lt 1 ]; then
267 __print_err "<response-code> [<producer-id>]*|NOID" $@
272 echo -e $GREEN" PASS"$EGREEN
276 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
277 # args: <response-code>
278 # (Function for test scripts)
279 ecs_api_edp_get_producer() {
280 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
281 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
284 if [ $# -lt 1 ]; then
285 __print_err "<response-code> [<producer-id>]*|NOID" $@
290 echo -e $GREEN" PASS"$EGREEN
294 # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
295 # args: <response-code>
296 # (Function for test scripts)
297 ecs_api_edp_delete_producer() {
298 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
299 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
302 if [ $# -lt 1 ]; then
303 __print_err "<response-code> [<producer-id>]*|NOID" $@
308 echo -e $GREEN" PASS"$EGREEN
312 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
313 # args: <response-code>
314 # (Function for test scripts)
315 ecs_api_edp_put_producer() {
316 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
317 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
320 if [ $# -lt 1 ]; then
321 __print_err "<response-code> [<producer-id>]*|NOID" $@
326 echo -e $GREEN" PASS"$EGREEN
330 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
331 # args: <response-code>
332 # (Function for test scripts)
333 ecs_api_edp_get_producer_jobs() {
334 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
335 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
338 if [ $# -lt 1 ]; then
339 __print_err "<response-code> [<producer-id>]*|NOID" $@
344 echo -e $GREEN" PASS"$EGREEN
349 ##########################################
350 #### Producer Simulator ####
351 ##########################################
352 # Function prefix: ecs_api_sim
354 # API Test function: POST /producer_simulator/job_deleted_error
355 # args: <response-code>
356 # (Function for test scripts)
357 ecs_api_sim_post_job_delete_error() {
358 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
359 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
362 if [ $# -lt 1 ]; then
363 __print_err "<response-code> [<producer-id>]*|NOID" $@
368 echo -e $GREEN" PASS"$EGREEN
372 # API Test function: GET /producer_simulator/supervision
373 # args: <response-code>
374 # (Function for test scripts)
375 ecs_api_sim_get_producer_supervision() {
376 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
377 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
380 if [ $# -lt 1 ]; then
381 __print_err "<response-code> [<producer-id>]*|NOID" $@
386 echo -e $GREEN" PASS"$EGREEN
390 # API Test function: POST /producer_simulator/job_deleted
391 # args: <response-code>
392 # (Function for test scripts)
393 ecs_api_sim_post_job_deleted() {
394 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
395 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
398 if [ $# -lt 1 ]; then
399 __print_err "<response-code> [<producer-id>]*|NOID" $@
404 echo -e $GREEN" PASS"$EGREEN
408 # API Test function: GET /producer_simulator/supervision_error
409 # args: <response-code>
410 # (Function for test scripts)
411 ecs_api_get_producer_supervision_error() {
412 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
413 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
416 if [ $# -lt 1 ]; then
417 __print_err "<response-code> [<producer-id>]*|NOID" $@
422 echo -e $GREEN" PASS"$EGREEN
426 # API Test function: POST /producer_simulator/job_created_error
427 # args: <response-code>
428 # (Function for test scripts)
429 ecs_api_sim_get_job_created_error() {
430 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
431 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
434 if [ $# -lt 1 ]; then
435 __print_err "<response-code> [<producer-id>]*|NOID" $@
440 echo -e $GREEN" PASS"$EGREEN
444 # API Test function: POST /producer_simulator/job_created
445 # args: <response-code>
446 # (Function for test scripts)
447 ecs_api_sim_get_job_created() {
448 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
449 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
452 if [ $# -lt 1 ]; then
453 __print_err "<response-code> [<producer-id>]*|NOID" $@
458 echo -e $GREEN" PASS"$EGREEN
463 ##########################################
464 #### Service status ####
465 ##########################################
466 # Function prefix: ecs_api_service
468 # API Test function: GET /status
469 # args: <response-code>
470 # (Function for test scripts)
471 ecs_api_service_status() {
472 echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
473 echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
476 if [ $# -lt 1 ]; then
477 __print_err "<response-code> [<producer-id>]*|NOID" $@
482 echo -e $GREEN" PASS"$EGREEN