diff --git a/tests/features/CAPIF Api Events/capif_events_api.robot b/tests/features/CAPIF Api Events/capif_events_api.robot index c4b60855a19740f15faa28ac5851b5f30d676b1f..c1ea4c79f2bca8d80d895d778484f88baca106e6 100644 --- a/tests/features/CAPIF Api Events/capif_events_api.robot +++ b/tests/features/CAPIF Api Events/capif_events_api.robot @@ -325,47 +325,3 @@ Prueba JMS Log ${event} List Should Contain Value ${notification_events_on_mock_server} ${event} END - - -*** Keywords *** -Create Events From invocationLogs - [Arguments] ${subscription_id} ${invocation_log} - - ${events}= Create List - - # Now we create the expected events received at notification server according to logs sent to loggin service in order to check if all are present. - ${invocation_log_base}= Copy Dictionary ${invocation_log} deepcopy=True - # Store log array because each log will be notified in one Event Notification - ${invocation_log_logs}= Copy List ${invocation_log_base['logs']} - # Remove logs array from invocationLog data - Remove From Dictionary ${invocation_log_base} logs - - FOR ${log} IN @{invocation_log_logs} - Log Dictionary ${log} - ${invocation_logs}= Copy Dictionary ${invocation_log_base} deepcopy=True - - # Get Event Enum for this result - ${event_enum}= Set Variable - IF ${log['result']} >= 200 and ${log['result']} < 300 - ${event_enum}= Set Variable SERVICE_API_INVOCATION_SUCCESS - ELSE - ${event_enum}= Set Variable SERVICE_API_INVOCATION_FAILURE - END - # Create a log array with only one component - ${log_list}= Create List ${log} - # Setup logs array with previously created list - Set To Dictionary ${invocation_logs} logs=${log_list} - # Create event details for each log - ${event_details}= Create dictionary invocationLogs=${invocation_logs} - # Create Event with Event Details from invocationLog and also is appended to events array - ${event}= Create Dictionary - ... subscriptionId=${subscription_id} - ... events=${event_enum} - ... eventDetail=${event_details} - Check Variable ${event} EventNotification - Append To List ${events} ${event} - END - - Log List ${events} - ${events_length}= Get Length ${events} - RETURN ${events} ${events_length} diff --git a/tests/libraries/mock_server/mock_server.py b/tests/libraries/mock_server/mock_server.py index 18d3f92e7078586263e100658844db690f79ad96..e45fae0f241f1801e7ddc9749399f4fa0bc5d796 100644 --- a/tests/libraries/mock_server/mock_server.py +++ b/tests/libraries/mock_server/mock_server.py @@ -1,7 +1,7 @@ from flask import Flask, request import logging from logging.handlers import RotatingFileHandler - +import os app = Flask(__name__) @@ -53,4 +53,4 @@ def requests_list(): configure_logging(app) if __name__ == '__main__': - app.run(host='0.0.0.0',port=9090,debug=True) + app.run(host=os.environ.get("IP",'0.0.0.0'),port=os.environ.get("PORT",9090),debug=True) diff --git a/tests/libraries/mock_server/run_mock_server.sh b/tests/libraries/mock_server/run_mock_server.sh new file mode 100755 index 0000000000000000000000000000000000000000..10c4ba2a7e35b44b23d2353eee017295876fb92b --- /dev/null +++ b/tests/libraries/mock_server/run_mock_server.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +help() { + echo "Usage: $1 " + echo " -i : Setup different host ip for mock server (default 0.0.0.0)" + echo " -p : Setup different port for mock server (default 9090)" + echo " -h : show this help" + exit 1 +} + +IP=0.0.0.0 +PORT=9090 + +# Read params +while getopts ":i:p:h" opt; do + case $opt in + i) + IP="$OPTARG" + ;; + p) + PORT=$OPTARG + ;; + h) + help + ;; + \?) + echo "Not valid option: -$OPTARG" >&2 + help + ;; + :) + echo "The -$OPTARG option requires an argument." >&2 + help + ;; + esac +done + +echo Robot Framework Mock Server will listen on $IP:$PORT +pip install -r requirements.txt + +IP=$IP PORT=$PORT python mock_server.py diff --git a/tests/resources/common/basicRequests.robot b/tests/resources/common/basicRequests.robot index ea3a96ffc432e86aa543ab51c796cbffb61bfc76..5872a57a6a3a92373b93e23940d1de669dc52fff 100644 --- a/tests/resources/common/basicRequests.robot +++ b/tests/resources/common/basicRequests.robot @@ -744,3 +744,46 @@ Create Security Context Between invoker and provider ... username=${register_user_info_invoker['management_cert']} Check Response Variable Type And Values ${resp} 201 ServiceSecurity + + +Create Events From invocationLogs + [Arguments] ${subscription_id} ${invocation_log} + + ${events}= Create List + + # Now we create the expected events received at notification server according to logs sent to loggin service in order to check if all are present. + ${invocation_log_base}= Copy Dictionary ${invocation_log} deepcopy=True + # Store log array because each log will be notified in one Event Notification + ${invocation_log_logs}= Copy List ${invocation_log_base['logs']} + # Remove logs array from invocationLog data + Remove From Dictionary ${invocation_log_base} logs + + FOR ${log} IN @{invocation_log_logs} + Log Dictionary ${log} + ${invocation_logs}= Copy Dictionary ${invocation_log_base} deepcopy=True + + # Get Event Enum for this result + ${event_enum}= Set Variable + IF ${log['result']} >= 200 and ${log['result']} < 300 + ${event_enum}= Set Variable SERVICE_API_INVOCATION_SUCCESS + ELSE + ${event_enum}= Set Variable SERVICE_API_INVOCATION_FAILURE + END + # Create a log array with only one component + ${log_list}= Create List ${log} + # Setup logs array with previously created list + Set To Dictionary ${invocation_logs} logs=${log_list} + # Create event details for each log + ${event_details}= Create dictionary invocationLogs=${invocation_logs} + # Create Event with Event Details from invocationLog and also is appended to events array + ${event}= Create Dictionary + ... subscriptionId=${subscription_id} + ... events=${event_enum} + ... eventDetail=${event_details} + Check Variable ${event} EventNotification + Append To List ${events} ${event} + END + + Log List ${events} + ${events_length}= Get Length ${events} + RETURN ${events} ${events_length}