+ __log_test_pass
+ return 0
+}
+
+# CR API: Check the contents of all current type subscription events for one id from ICS
+# <response-code> <cr-path-id> <id> [ EMPTY | ( <type-id> <schema> <registration-status> )+ ]
+# (Function for test scripts)
+cr_api_check_all_ics_subscription_events() {
+ __log_test_start $@
+
+ #Valid number of parameter 3,4,8,12
+ paramError=1
+ if [ $# -eq 3 ]; then
+ paramError=0
+ fi
+ if [ $# -eq 4 ] && [ "$4" == "EMPTY" ]; then
+ paramError=0
+ fi
+ variablecount=$(($#-3))
+ if [ $# -gt 4 ] && [ $(($variablecount%3)) -eq 0 ]; then
+ paramError=0
+ fi
+ if [ $paramError -eq 1 ]; then
+ __print_err "<response-code> <cr-path-id> <id> [ EMPTY | ( <type-id> <schema> <registration-status> )+ ]" $@
+ return 1
+ fi
+
+ CR_SERVICE_PATH=$(__cr_get_service_path $2)
+ CR_ADAPTER=$CR_SERVICE_PATH
+ if [ $? -ne 0 ]; then
+ __print_err "<cr-path-id> missing or incorrect" $@
+ return 1
+ fi
+
+ query="/get-all-events/"$3
+ res="$(__do_curl_to_api CR GET $query)"
+ status=${res:${#res}-3}
+
+ if [ $status -ne $1 ]; then
+ __log_test_fail_status_code $1 $status
+ return 1
+ fi
+
+ if [ $# -gt 3 ]; then
+ body=${res:0:${#res}-3}
+ targetJson="["
+ if [ $# -gt 4 ]; then
+ arr=(${@:4})
+ for ((i=0; i<$(($#-4)); i=i+3)); do
+ if [ "$targetJson" != "[" ]; then
+ targetJson=$targetJson","
+ fi
+ if [ -f ${arr[$i+1]} ]; then
+ jobfile=$(cat ${arr[$i+1]})
+ else
+ __log_test_fail_general "Job schema file "${arr[$i+1]}", does not exist"
+ return 1
+ fi
+ targetJson=$targetJson"{\"info_type_id\":\"${arr[$i]}\",\"job_data_schema\":$jobfile,\"status\":\"${arr[$i+2]}\"}"
+ done
+ fi
+ targetJson=$targetJson"]"
+
+ echo " TARGET JSON: $targetJson" >> $HTTPLOG
+ res=$(python3 ../common/compare_json.py "$targetJson" "$body")
+
+ if [ $res -ne 0 ]; then
+ __log_test_fail_body
+ return 1
+ fi
+ fi
+
+ __log_test_pass
+ return 0
+}
+
+
+# CR API: Reset all events and counters
+# Arg: <cr-path-id>
+# (Function for test scripts)
+cr_api_reset() {
+ __log_conf_start $@
+
+ if [ $# -ne 1 ]; then
+ __print_err "<cr-path-id>" $@
+ return 1
+ fi
+
+ CR_SERVICE_PATH=$(__cr_get_service_path $1)
+ CR_ADAPTER=$CR_SERVICE_PATH
+ if [ $? -ne 0 ]; then
+ __print_err "<cr-path-id> missing or incorrect" $@
+ return 1
+ fi
+
+ res="$(__do_curl_to_api CR GET /reset)"
+ status=${res:${#res}-3}
+
+ if [ $status -ne 200 ]; then
+ __log_conf_fail_status_code $1 $status
+ return 1
+ fi
+
+ __log_conf_ok
+ return 0
+}
+
+
+# CR API: Check the contents of all json events for path
+# <response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg>+ )
+# (Function for test scripts)
+cr_api_check_all_genric_json_events() {
+ __log_test_start $@
+
+ if [ $# -lt 4 ]; then
+ __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg>+ )" $@
+ return 1
+ fi
+
+ CR_SERVICE_PATH=$(__cr_get_service_path $2)
+ CR_ADAPTER=$CR_SERVICE_PATH
+ if [ $? -ne 0 ]; then
+ __print_err "<cr-path-id> missing or incorrect" $@
+ return 1
+ fi
+
+ query="/get-all-events/"$3
+ res="$(__do_curl_to_api CR GET $query)"
+ status=${res:${#res}-3}
+
+ if [ $status -ne $1 ]; then
+ __log_test_fail_status_code $1 $status
+ return 1
+ fi
+ body=${res:0:${#res}-3}
+ targetJson="["
+
+ if [ $4 != "EMPTY" ]; then
+ shift
+ shift
+ shift
+ while [ $# -gt 0 ]; do
+ if [ "$targetJson" != "[" ]; then
+ targetJson=$targetJson","
+ fi
+ targetJson=$targetJson$1
+ shift
+ done
+ fi
+ targetJson=$targetJson"]"
+
+ echo " TARGET JSON: $targetJson" >> $HTTPLOG
+ res=$(python3 ../common/compare_json.py "$targetJson" "$body")
+
+ if [ $res -ne 0 ]; then
+ __log_test_fail_body
+ return 1
+ fi
+
+ __log_test_pass
+ return 0
+}
+
+
+# CR API: Check a single (oldest) json event (or none if empty) for path
+# <response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg> )
+# (Function for test scripts)
+cr_api_check_single_genric_json_event() {
+ __log_test_start $@
+
+ if [ $# -ne 4 ]; then
+ __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <json-msg> )" $@
+ return 1
+ fi
+
+ CR_SERVICE_PATH=$(__cr_get_service_path $2)
+ CR_ADAPTER=$CR_SERVICE_PATH
+ if [ $? -ne 0 ]; then
+ __print_err "<cr-path-id> missing or incorrect" $@
+ return 1
+ fi
+
+ query="/get-event/"$3
+ res="$(__do_curl_to_api CR GET $query)"
+ status=${res:${#res}-3}
+
+ if [ $status -ne $1 ]; then
+ __log_test_fail_status_code $1 $status
+ return 1
+ fi
+ body=${res:0:${#res}-3}
+ targetJson=$4
+
+ if [ $targetJson == "EMPTY" ] && [ ${#body} -ne 0 ]; then
+ __log_test_fail_body
+ return 1
+ fi
+ echo " TARGET JSON: $targetJson" >> $HTTPLOG
+ res=$(python3 ../common/compare_json.py "$targetJson" "$body")
+
+ if [ $res -ne 0 ]; then
+ __log_test_fail_body
+ return 1
+ fi
+
+ __log_test_pass
+ return 0
+}
+
+# CR API: Check a single (oldest) json in md5 format (or none if empty) for path.
+# Note that if a json message is given, it shall be compact, no ws except inside string.
+# The MD5 will generate different hash if ws is present or not in otherwise equivalent json
+# arg: <response-code> <cr-path-id> <topic-url> (EMPTY | <data-msg> )
+# (Function for test scripts)
+cr_api_check_single_genric_event_md5() {
+ __log_test_start $@
+
+ if [ $# -ne 4 ]; then
+ __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <data-msg> )" $@
+ return 1
+ fi
+
+ CR_SERVICE_PATH=$(__cr_get_service_path $2)
+ CR_ADAPTER=$CR_SERVICE_PATH
+ if [ $? -ne 0 ]; then
+ __print_err "<cr-path-id> missing or incorrect" $@
+ return 1
+ fi
+
+ query="/get-event/"$3
+ res="$(__do_curl_to_api CR GET $query)"
+ status=${res:${#res}-3}
+
+ if [ $status -ne $1 ]; then
+ __log_test_fail_status_code $1 $status
+ return 1
+ fi
+ body=${res:0:${#res}-3}
+ if [ $4 == "EMPTY" ]; then
+ if [ ${#body} -ne 0 ]; then
+ __log_test_fail_body
+ return 1
+ else
+ __log_test_pass
+ return 0
+ fi
+ fi
+ command -v md5 > /dev/null # Mac
+ if [ $? -eq 0 ]; then
+ targetMd5=$(echo -n "$4" | md5)
+ else
+ command -v md5sum > /dev/null # Linux
+ if [ $? -eq 0 ]; then
+ targetMd5=$(echo -n "$4" | md5sum | cut -d' ' -f 1) # Need to cut additional info printed by cmd
+ else
+ __log_test_fail_general "Command md5 nor md5sum is available"
+ return 1
+ fi
+ fi
+ targetMd5="\""$targetMd5"\"" #Quotes needed
+
+ echo " TARGET MD5 hash: $targetMd5" >> $HTTPLOG
+
+ if [ "$body" != "$targetMd5" ]; then
+ __log_test_fail_body
+ return 1
+ fi
+
+ __log_test_pass
+ return 0
+}
+
+# CR API: Check a single (oldest) event in md5 format (or none if empty) for path.
+# Note that if a file with json message is given, the json shall be compact, no ws except inside string and not newlines.
+# The MD5 will generate different hash if ws/newlines is present or not in otherwise equivalent json
+# arg: <response-code> <cr-path-id> <topic-url> (EMPTY | <data-file> )
+# (Function for test scripts)
+cr_api_check_single_genric_event_md5_file() {
+ __log_test_start $@
+
+ if [ $# -ne 4 ]; then
+ __print_err "<response-code> <cr-path-id> <topic-url> (EMPTY | <data-file> )" $@
+ return 1
+ fi
+
+ CR_SERVICE_PATH=$(__cr_get_service_path $2)
+ CR_ADAPTER=$CR_SERVICE_PATH
+ if [ $? -ne 0 ]; then
+ __print_err "<cr-path-id> missing or incorrect" $@
+ return 1
+ fi
+
+ query="/get-event/"$3
+ res="$(__do_curl_to_api CR GET $query)"
+ status=${res:${#res}-3}
+
+ if [ $status -ne $1 ]; then
+ __log_test_fail_status_code $1 $status
+ return 1
+ fi
+ body=${res:0:${#res}-3}
+ if [ $4 == "EMPTY" ]; then
+ if [ ${#body} -ne 0 ]; then
+ __log_test_fail_body
+ return 1
+ else
+ __log_test_pass
+ return 0
+ fi
+ fi
+
+ if [ ! -f $4 ]; then
+ __log_test_fail_general "File $3 does not exist"
+ return 1
+ fi
+
+ filedata=$(cat $4)
+
+ command -v md5 > /dev/null # Mac
+ if [ $? -eq 0 ]; then
+ targetMd5=$(echo -n "$filedata" | md5)
+ else
+ command -v md5sum > /dev/null # Linux
+ if [ $? -eq 0 ]; then
+ targetMd5=$(echo -n "$filedata" | md5sum | cut -d' ' -f 1) # Need to cut additional info printed by cmd
+ else
+ __log_test_fail_general "Command md5 nor md5sum is available"
+ return 1
+ fi
+ fi
+ targetMd5="\""$targetMd5"\"" #Quotes needed
+
+ echo " TARGET MD5 hash: $targetMd5" >> $HTTPLOG
+
+ if [ "$body" != "$targetMd5" ]; then
+ __log_test_fail_body
+ return 1
+ fi
+