From ea1dc5fdeea3150885ea0bbbc8e02f9563799530 Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Wed, 18 Dec 2024 12:56:32 +0100 Subject: [PATCH 1/3] New api status tests --- tests/features/Api Status/api_status.robot | 106 ++++++++++++++++++ .../api_publish_service/bodyRequests.py | 17 ++- tests/libraries/common/types.json | 9 +- tests/resources/common/basicRequests.robot | 2 + tests/resources/common/expectedMessages.robot | 54 ++++----- 5 files changed, 161 insertions(+), 27 deletions(-) diff --git a/tests/features/Api Status/api_status.robot b/tests/features/Api Status/api_status.robot index 2b76a5e..bf21c5f 100644 --- a/tests/features/Api Status/api_status.robot +++ b/tests/features/Api Status/api_status.robot @@ -256,6 +256,112 @@ Publish without apiStatus feature receive eventDetails without eventDetails (api +### ---------------------- + +Update published API without apiStatus and apiStatusMonitoring inactive + [Tags] api_status-12 mockserver + + # Initialize Mock server + Init Mock Server + + # Default Invoker Registration and Onboarding + ${register_user_info_invoker} ${url} ${request_body}= Invoker Default Onboarding + + # Register APF + ${register_user_info_provider}= Provider Default Registration total_aef_roles=2 + + ${aef_id_1}= Set Variable ${register_user_info_provider['aef_roles']['${AEF_PROVIDER_USERNAME}']['aef_id']} + ${aef_id_2}= Set Variable ${register_user_info_provider['aef_roles']['${AEF_PROVIDER_USERNAME}_1']['aef_id']} + ${aef_ids}= Create List ${aef_id_1} ${aef_id_2} + + # Subscribe to events + ${events_list}= Create List SERVICE_API_AVAILABLE SERVICE_API_UNAVAILABLE SERVICE_API_UPDATE + + ${request_body}= Create Events Subscription + ... events=@{events_list} + ... notification_destination=${NOTIFICATION_DESTINATION_URL}/testing + ... supported_features=C + ${resp}= Post Request Capif + ... /capif-events/v1/${register_user_info_invoker['api_invoker_id']}/subscriptions + ... json=${request_body} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${INVOKER_USERNAME} + + # Check Results + Check Response Variable Type And Values ${resp} 201 EventSubscription + ${subscriber_id} ${subscription_id}= Check Event Location Header ${resp} + + # Publish api with 2 aefIds + ${service_api_description_published} ${resource_url} ${request_body}= Publish Service Api + ... ${register_user_info_provider} + ... service_1 + ... aef_id=${aef_ids} + ... api_status=${aef_id_1} + ... supported_features=020 + + # Discover APIs by invoker + ${resp}= Get Request Capif + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&aef-id=${aef_id_1} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${INVOKER_USERNAME} + + Check Response Variable Type And Values ${resp} 200 DiscoveredAPIs + + # # Check Results + Dictionary Should Contain Key ${resp.json()} serviceAPIDescriptions + Should Not Be Empty ${resp.json()['serviceAPIDescriptions']} + Length Should Be ${resp.json()['serviceAPIDescriptions']} 1 + List Should Contain Value ${resp.json()['serviceAPIDescriptions']} ${service_api_description_published} + + # Update Request to published API + ${service_api_description_modified}= Create Service Api Description + ... service_1 + ... aef_id=${aef_ids} + ... supported_features=020 + ... api_status=${NONE} + ${resp}= Put Request Capif + ... ${resource_url.path} + ... json=${service_api_description_modified} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${APF_PROVIDER_USERNAME} + + Check Response Variable Type And Values ${resp} 200 ServiceAPIDescription + ... apiName=service_1 + Dictionary Should Not Contain Key ${resp.json()} apiStatus + + # Provider Remove service_1 published API + # ${resp}= Delete Request Capif + # ... ${resource_url.path} + # ... server=${CAPIF_HTTPS_URL} + # ... verify=ca.crt + # ... username=${APF_PROVIDER_USERNAME} + + # Status Should Be 204 ${resp} + + # Check Event Notifications + ## Create check Events to ensure all notifications were received + ${service_api_available_resources}= Create List ${resource_url} + ${events_expected}= Create Expected Events For Service API Notifications + ... subscription_id=${subscription_id} + ... service_api_available_resources=${service_api_available_resources} + ... event_detail_expected=${TRUE} + ... service_api_description_expected=${TRUE} + ... service_api_description=${service_api_description_published} + + Log List ${events_expected} + ${events_expected}= Create Expected Service Update Event + ... subscription_id=${subscription_id} + ... service_api_resource=${resource_url} + ... service_api_descriptions=${service_api_description_modified} + ... events_expected=${events_expected} + Log List ${events_expected} + ## Check Events Expected towards received notifications at mock server + Wait Until Keyword Succeeds 5x 5s Check Mock Server Notification Events ${events_expected} + + ###--- # Invoker receives Service API Invocation events diff --git a/tests/libraries/api_publish_service/bodyRequests.py b/tests/libraries/api_publish_service/bodyRequests.py index b693457..6ca699d 100644 --- a/tests/libraries/api_publish_service/bodyRequests.py +++ b/tests/libraries/api_publish_service/bodyRequests.py @@ -1,4 +1,9 @@ -def create_service_api_description(api_name="service_1", aef_id="aef_id", supported_features="0", vendor_specific_service_api_description=None, vendor_specific_aef_profile=None): +def create_service_api_description(api_name="service_1", + aef_id="aef_id", + supported_features="0", + vendor_specific_service_api_description=None, + vendor_specific_aef_profile=None, + api_status=None): aef_ids = list() if isinstance(aef_id, list): aef_ids = aef_id @@ -39,6 +44,16 @@ def create_service_api_description(api_name="service_1", aef_id="aef_id", suppor body["aefProfiles"][0][key] = value if supported_features is not None: body['supportedFeatures'] = supported_features + if api_status is not None: + aef_ids_active = list() + if isinstance(api_status, list): + aef_ids_active = api_status + print("api_status parameter is a list") + elif isinstance(api_status, str): + print("api_status parameter is a string") + aef_ids_active.append(api_status) + body['apiStatus'] = dict() + body['apiStatus']['aefIds'] = aef_ids_active return body diff --git a/tests/libraries/common/types.json b/tests/libraries/common/types.json index f2f0ff8..9f3aecd 100644 --- a/tests/libraries/common/types.json +++ b/tests/libraries/common/types.json @@ -82,12 +82,19 @@ "serviceAPICategory": "string", "apiSuppFeats": "SupportedFeatures", "pubApiPath": "PublishedApiPath", - "ccfId": "string" + "ccfId": "string", + "apiStatus": "ApiStatus" }, "regex_attributes": { "^vendorSpecific-(.*)": "VendorSpecificObject" } }, + "ApiStatus": { + "mandatory_attributes": { + "aefIds": "string" + }, + "optional_attributes": {} + }, "VendorSpecificObject": { "Check": false }, diff --git a/tests/resources/common/basicRequests.robot b/tests/resources/common/basicRequests.robot index 03518dd..3cde89d 100644 --- a/tests/resources/common/basicRequests.robot +++ b/tests/resources/common/basicRequests.robot @@ -795,6 +795,7 @@ Publish Service Api ... ${vendor_specific_service_api_description}=${None} ... ${vendor_specific_aef_profile}=${None} ... ${aef_id}=${NONE} + ... ${api_status}=${NONE} ${aef_ids}= Create List IF "${aef_id}" == "${NONE}" @@ -824,6 +825,7 @@ Publish Service Api ... ${supported_features} ... ${vendor_specific_service_api_description} ... ${vendor_specific_aef_profile} + ... ${api_status} ${resp}= Post Request Capif ... /published-apis/v1/${apf_id_to_use}/service-apis ... json=${request_body} diff --git a/tests/resources/common/expectedMessages.robot b/tests/resources/common/expectedMessages.robot index c246324..128f983 100644 --- a/tests/resources/common/expectedMessages.robot +++ b/tests/resources/common/expectedMessages.robot @@ -74,34 +74,38 @@ Create Expected Events For Service API Notifications END END - FOR ${service_api_available_resource} IN @{service_api_available_resources} - Log ${service_api_available_resource} - ${api_id}= Fetch From Right ${service_api_available_resource.path} / - - IF "${event_detail_expected}" != "${TRUE}" - ${api_id}= Set Variable ${NONE} + IF "${service_api_available_resources}" != "${NONE}" + FOR ${service_api_available_resource} IN @{service_api_available_resources} + Log ${service_api_available_resource} + ${api_id}= Fetch From Right ${service_api_available_resource.path} / + + IF "${event_detail_expected}" != "${TRUE}" + ${api_id}= Set Variable ${NONE} + END + + ${event_expected}= Create Notification Event + ... ${subscription_id} + ... SERVICE_API_AVAILABLE + ... apiIds=${api_id} + ... serviceAPIDescriptions=${service_api_description_to_use} + Append To List ${events_expected} ${event_expected} END - - ${event_expected}= Create Notification Event - ... ${subscription_id} - ... SERVICE_API_AVAILABLE - ... apiIds=${api_id} - ... serviceAPIDescriptions=${service_api_description_to_use} - Append To List ${events_expected} ${event_expected} END - FOR ${service_api_unavailable_resource} IN @{service_api_unavailable_resources} - Log ${service_api_unavailable_resource} - ${api_id}= Fetch From Right ${service_api_unavailable_resource.path} / - IF "${event_detail_expected}" != "${TRUE}" - ${api_id}= Set Variable ${NONE} + IF "${service_api_unavailable_resources}" != "${NONE}" + FOR ${service_api_unavailable_resource} IN @{service_api_unavailable_resources} + Log ${service_api_unavailable_resource} + ${api_id}= Fetch From Right ${service_api_unavailable_resource.path} / + IF "${event_detail_expected}" != "${TRUE}" + ${api_id}= Set Variable ${NONE} + END + ${event_expected}= Create Notification Event + ... ${subscription_id} + ... SERVICE_API_UNAVAILABLE + ... apiIds=${api_id} + ... serviceAPIDescriptions=${service_api_description_to_use} + Append To List ${events_expected} ${event_expected} END - ${event_expected}= Create Notification Event - ... ${subscription_id} - ... SERVICE_API_UNAVAILABLE - ... apiIds=${api_id} - ... serviceAPIDescriptions=${service_api_description_to_use} - Append To List ${events_expected} ${event_expected} END RETURN ${events_expected} @@ -213,7 +217,7 @@ Create Expected Service Update Event IF "${event_detail_expected}" != "${TRUE}" ${service_api_descriptions}= Set Variable ${NONE} END - ${events_expected}= Create List + ${event_expected}= Create Notification Event ... ${subscription_id} ... SERVICE_API_UPDATE -- GitLab From c9be4cce1b7316e2103982af79b0869c80750c7b Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Wed, 18 Dec 2024 16:42:03 +0100 Subject: [PATCH 2/3] New patch tests in api status test suite --- tests/features/Api Status/api_status.robot | 320 +++++++++++++++++- .../api_publish_service/bodyRequests.py | 70 +++- tests/libraries/common/types.json | 13 + 3 files changed, 391 insertions(+), 12 deletions(-) diff --git a/tests/features/Api Status/api_status.robot b/tests/features/Api Status/api_status.robot index bf21c5f..aa0b22c 100644 --- a/tests/features/Api Status/api_status.robot +++ b/tests/features/Api Status/api_status.robot @@ -319,7 +319,7 @@ Update published API without apiStatus and apiStatusMonitoring inactive ${service_api_description_modified}= Create Service Api Description ... service_1 ... aef_id=${aef_ids} - ... supported_features=020 + ... supported_features=000 ... api_status=${NONE} ${resp}= Put Request Capif ... ${resource_url.path} @@ -332,14 +332,101 @@ Update published API without apiStatus and apiStatusMonitoring inactive ... apiName=service_1 Dictionary Should Not Contain Key ${resp.json()} apiStatus - # Provider Remove service_1 published API - # ${resp}= Delete Request Capif - # ... ${resource_url.path} - # ... server=${CAPIF_HTTPS_URL} - # ... verify=ca.crt - # ... username=${APF_PROVIDER_USERNAME} + # Check Event Notifications + ## Create check Events to ensure all notifications were received + ${service_api_available_resources}= Create List ${resource_url} + ${events_expected}= Create Expected Events For Service API Notifications + ... subscription_id=${subscription_id} + ... service_api_available_resources=${service_api_available_resources} + ... event_detail_expected=${TRUE} + ... service_api_description_expected=${TRUE} + ... service_api_description=${service_api_description_published} + + Log List ${events_expected} + ${events_expected}= Create Expected Service Update Event + ... subscription_id=${subscription_id} + ... service_api_resource=${resource_url} + ... service_api_descriptions=${service_api_description_modified} + ... events_expected=${events_expected} + Log List ${events_expected} + ## Check Events Expected towards received notifications at mock server + Wait Until Keyword Succeeds 5x 5s Check Mock Server Notification Events ${events_expected} + + +Update published API with apiStatus empty and apiStatusMonitoring inactive + [Tags] api_status-13 mockserver + + # Initialize Mock server + Init Mock Server + + # Default Invoker Registration and Onboarding + ${register_user_info_invoker} ${url} ${request_body}= Invoker Default Onboarding + + # Register APF + ${register_user_info_provider}= Provider Default Registration total_aef_roles=2 + + ${aef_id_1}= Set Variable ${register_user_info_provider['aef_roles']['${AEF_PROVIDER_USERNAME}']['aef_id']} + ${aef_id_2}= Set Variable ${register_user_info_provider['aef_roles']['${AEF_PROVIDER_USERNAME}_1']['aef_id']} + ${aef_ids}= Create List ${aef_id_1} ${aef_id_2} + + # Subscribe to events + ${events_list}= Create List SERVICE_API_AVAILABLE SERVICE_API_UNAVAILABLE SERVICE_API_UPDATE + + ${request_body}= Create Events Subscription + ... events=@{events_list} + ... notification_destination=${NOTIFICATION_DESTINATION_URL}/testing + ... supported_features=C + ${resp}= Post Request Capif + ... /capif-events/v1/${register_user_info_invoker['api_invoker_id']}/subscriptions + ... json=${request_body} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${INVOKER_USERNAME} + + # Check Results + Check Response Variable Type And Values ${resp} 201 EventSubscription + ${subscriber_id} ${subscription_id}= Check Event Location Header ${resp} + + # Publish api with 2 aefIds + ${service_api_description_published} ${resource_url} ${request_body}= Publish Service Api + ... ${register_user_info_provider} + ... service_1 + ... aef_id=${aef_ids} + ... api_status=${aef_id_1} + ... supported_features=020 + + # Discover APIs by invoker + ${resp}= Get Request Capif + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&aef-id=${aef_id_1} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${INVOKER_USERNAME} + + Check Response Variable Type And Values ${resp} 200 DiscoveredAPIs + + # # Check Results + Dictionary Should Contain Key ${resp.json()} serviceAPIDescriptions + Should Not Be Empty ${resp.json()['serviceAPIDescriptions']} + Length Should Be ${resp.json()['serviceAPIDescriptions']} 1 + List Should Contain Value ${resp.json()['serviceAPIDescriptions']} ${service_api_description_published} + + # Update Request to published API + ${aef_empty_list}= Create List + ${service_api_description_modified}= Create Service Api Description + ... service_1 + ... aef_id=${aef_ids} + ... supported_features=000 + ... api_status=${aef_empty_list} + ${resp}= Put Request Capif + ... ${resource_url.path} + ... json=${service_api_description_modified} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${APF_PROVIDER_USERNAME} - # Status Should Be 204 ${resp} + Check Response Variable Type And Values ${resp} 200 ServiceAPIDescription + ... apiName=service_1 + Dictionary Should Not Contain Key ${resp.json()} apiStatus # Check Event Notifications ## Create check Events to ensure all notifications were received @@ -357,10 +444,227 @@ Update published API without apiStatus and apiStatusMonitoring inactive ... service_api_resource=${resource_url} ... service_api_descriptions=${service_api_description_modified} ... events_expected=${events_expected} + + ${service_api_unavailable_resources}= Create List ${resource_url} + ${events_expected}= Create Expected Events For Service API Notifications + ... subscription_id=${subscription_id} + ... service_api_unavailable_resources=${service_api_unavailable_resources} + ... event_detail_expected=${TRUE} + ... service_api_description_expected=${TRUE} + ... service_api_description=${service_api_description_modified} + Log List ${events_expected} + ## Check Events Expected towards received notifications at mock server + Wait Until Keyword Succeeds 5x 5s Check Mock Server Notification Events ${events_expected} + + +## ---------------------------------- +Patch published (apiStatusMonitoring active) API with apiStatus only aefId2 + [Tags] api_status-17 mockserver + + # Initialize Mock server + Init Mock Server + + # Default Invoker Registration and Onboarding + ${register_user_info_invoker} ${url} ${request_body}= Invoker Default Onboarding + + # Register APF + ${register_user_info_provider}= Provider Default Registration total_aef_roles=2 + + ${aef_id_1}= Set Variable ${register_user_info_provider['aef_roles']['${AEF_PROVIDER_USERNAME}']['aef_id']} + ${aef_id_2}= Set Variable ${register_user_info_provider['aef_roles']['${AEF_PROVIDER_USERNAME}_1']['aef_id']} + ${aef_ids}= Create List ${aef_id_1} ${aef_id_2} + + # Subscribe to events + ${events_list}= Create List SERVICE_API_AVAILABLE SERVICE_API_UNAVAILABLE SERVICE_API_UPDATE + + ${request_body}= Create Events Subscription + ... events=@{events_list} + ... notification_destination=${NOTIFICATION_DESTINATION_URL}/testing + ... supported_features=C + ${resp}= Post Request Capif + ... /capif-events/v1/${register_user_info_invoker['api_invoker_id']}/subscriptions + ... json=${request_body} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${INVOKER_USERNAME} + + # Check Results + Check Response Variable Type And Values ${resp} 201 EventSubscription + ${subscriber_id} ${subscription_id}= Check Event Location Header ${resp} + + # Publish api with 2 aefIds + ${service_api_description_published} ${resource_url} ${request_body}= Publish Service Api + ... ${register_user_info_provider} + ... service_1 + ... aef_id=${aef_ids} + ... api_status=${aef_id_1} + ... supported_features=020 + + # Discover APIs by invoker + ${resp}= Get Request Capif + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&aef-id=${aef_id_1} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${INVOKER_USERNAME} + + Check Response Variable Type And Values ${resp} 200 DiscoveredAPIs + + # # Check Results + Dictionary Should Contain Key ${resp.json()} serviceAPIDescriptions + Should Not Be Empty ${resp.json()['serviceAPIDescriptions']} + Length Should Be ${resp.json()['serviceAPIDescriptions']} 1 + List Should Contain Value ${resp.json()['serviceAPIDescriptions']} ${service_api_description_published} + + # Update Request to published API + ${aef_empty_list}= Create List + ${service_api_description_patch}= Create Service Api Description Patch + ... api_status=${aef_id_2} + Check Variable ${service_api_description_patch} ServiceAPIDescriptionPatch + ${resp}= Patch Request Capif + ... ${resource_url.path} + ... json=${service_api_description_patch} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${APF_PROVIDER_USERNAME} + + ${service_api_to_check}= Copy Dictionary ${service_api_description_published} deepcopy=${True} + ${aef_ids_expected}= Create List ${aef_id_2} + ${api_status_expected}= Create dictionary aefIds=${aef_ids_expected} + Set To Dictionary ${service_api_to_check} apiStatus=${api_status_expected} + + Check Response Variable Type And Values ${resp} 200 ServiceAPIDescription + ... apiName=service_1 + + Dictionary Should Contain Key ${resp.json()} apiStatus + + Dictionaries Should Be Equal ${resp.json()['apiStatus']} ${service_api_description_patch['apiStatus']} + + + # Check Event Notifications + ## Create check Events to ensure all notifications were received + ${service_api_available_resources}= Create List ${resource_url} + ${events_expected}= Create Expected Events For Service API Notifications + ... subscription_id=${subscription_id} + ... service_api_available_resources=${service_api_available_resources} + ... event_detail_expected=${TRUE} + ... service_api_description_expected=${TRUE} + ... service_api_description=${service_api_description_published} + + Log List ${events_expected} + ${events_expected}= Create Expected Service Update Event + ... subscription_id=${subscription_id} + ... service_api_resource=${resource_url} + ... service_api_descriptions=${service_api_to_check} + ... events_expected=${events_expected} + + Log List ${events_expected} + ## Check Events Expected towards received notifications at mock server + Wait Until Keyword Succeeds 5x 5s Check Mock Server Notification Events ${events_expected} + + +## ----------------------------- +Patch published (apiStatusMonitoring active) API with apiStatus aef1 and aef2 + [Tags] api_status-18 mockserver + + # Initialize Mock server + Init Mock Server + + # Default Invoker Registration and Onboarding + ${register_user_info_invoker} ${url} ${request_body}= Invoker Default Onboarding + + # Register APF + ${register_user_info_provider}= Provider Default Registration total_aef_roles=2 + + ${aef_id_1}= Set Variable ${register_user_info_provider['aef_roles']['${AEF_PROVIDER_USERNAME}']['aef_id']} + ${aef_id_2}= Set Variable ${register_user_info_provider['aef_roles']['${AEF_PROVIDER_USERNAME}_1']['aef_id']} + ${aef_ids}= Create List ${aef_id_1} ${aef_id_2} + + # Subscribe to events + ${events_list}= Create List SERVICE_API_AVAILABLE SERVICE_API_UNAVAILABLE SERVICE_API_UPDATE + + ${request_body}= Create Events Subscription + ... events=@{events_list} + ... notification_destination=${NOTIFICATION_DESTINATION_URL}/testing + ... supported_features=C + ${resp}= Post Request Capif + ... /capif-events/v1/${register_user_info_invoker['api_invoker_id']}/subscriptions + ... json=${request_body} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${INVOKER_USERNAME} + + # Check Results + Check Response Variable Type And Values ${resp} 201 EventSubscription + ${subscriber_id} ${subscription_id}= Check Event Location Header ${resp} + + # Publish api with 2 aefIds + ${service_api_description_published} ${resource_url} ${request_body}= Publish Service Api + ... ${register_user_info_provider} + ... service_1 + ... aef_id=${aef_ids} + ... api_status=${aef_id_1} + ... supported_features=020 + + # Discover APIs by invoker + ${resp}= Get Request Capif + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&aef-id=${aef_id_1} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${INVOKER_USERNAME} + + Check Response Variable Type And Values ${resp} 200 DiscoveredAPIs + + # # Check Results + Dictionary Should Contain Key ${resp.json()} serviceAPIDescriptions + Should Not Be Empty ${resp.json()['serviceAPIDescriptions']} + Length Should Be ${resp.json()['serviceAPIDescriptions']} 1 + List Should Contain Value ${resp.json()['serviceAPIDescriptions']} ${service_api_description_published} + + # Update Request to published API + ${aef_empty_list}= Create List + ${service_api_description_patch}= Create Service Api Description Patch + ... api_status=${aef_ids} + ${resp}= Patch Request Capif + ... ${resource_url.path} + ... json=${service_api_description_patch} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${APF_PROVIDER_USERNAME} + + ${service_api_to_check}= Copy Dictionary ${service_api_description_published} deepcopy=${True} + ${api_status_expected}= Create dictionary aefIds=${aef_ids} + Set To Dictionary ${service_api_to_check} apiStatus=${api_status_expected} + + Check Response Variable Type And Values ${resp} 200 ServiceAPIDescription + ... apiName=service_1 + + Dictionary Should Contain Key ${resp.json()} apiStatus + + Dictionaries Should Be Equal ${resp.json()['apiStatus']} ${service_api_description_patch['apiStatus']} + + + # Check Event Notifications + ## Create check Events to ensure all notifications were received + ${service_api_available_resources}= Create List ${resource_url} + ${events_expected}= Create Expected Events For Service API Notifications + ... subscription_id=${subscription_id} + ... service_api_available_resources=${service_api_available_resources} + ... event_detail_expected=${TRUE} + ... service_api_description_expected=${TRUE} + ... service_api_description=${service_api_description_published} + + Log List ${events_expected} + ${events_expected}= Create Expected Service Update Event + ... subscription_id=${subscription_id} + ... service_api_resource=${resource_url} + ... service_api_descriptions=${service_api_to_check} + ... events_expected=${events_expected} + Log List ${events_expected} ## Check Events Expected towards received notifications at mock server Wait Until Keyword Succeeds 5x 5s Check Mock Server Notification Events ${events_expected} + ###--- diff --git a/tests/libraries/api_publish_service/bodyRequests.py b/tests/libraries/api_publish_service/bodyRequests.py index 6ca699d..f76fe9d 100644 --- a/tests/libraries/api_publish_service/bodyRequests.py +++ b/tests/libraries/api_publish_service/bodyRequests.py @@ -60,14 +60,13 @@ def create_service_api_description(api_name="service_1", def create_aef_profiles(aef_ids): profiles = list() - index=1 + index = 1 for aef_id in aef_ids: - profiles.append(create_aef_profile(aef_id,"resource_" + str(index))) - index=index+1 + profiles.append(create_aef_profile(aef_id, "resource_" + str(index))) + index = index+1 return profiles - def create_aef_profile(aef_id, resource_name): data = { "aefId": aef_id, @@ -101,3 +100,66 @@ def create_aef_profile(aef_id, resource_name): ] } return data + + +def create_service_api_description_patch(aef_id=None, + description=None, + shareable_info=None, + api_status=None, + service_api_category=None, + api_supp_feats=None, + pub_api_path=None, + ccf_id=None): + body = dict() + + # aef profiles + aef_ids = list() + if aef_id is None: + aef_ids = None + elif isinstance(aef_id, list): + aef_ids = aef_id + print("aef_id parameter is a list") + elif isinstance(aef_id, str): + print("aef_id parameter is a string") + aef_ids.append(aef_id) + if aef_ids is not None: + profiles = create_aef_profiles(aef_ids) + body['aefProfiles'] = profiles + + # description + if description is not None: + body['description'] = description + + # shareable info + if shareable_info is not None: + body['shareableInfo'] = shareable_info + + # service API Category + if service_api_category is not None: + body['serviceAPICategory'] = service_api_category + + # api Supp Feats + if api_supp_feats is not None: + body['apiSuppFeats'] = api_supp_feats + + # pub Api Path + if pub_api_path is not None: + body['pubApiPath'] = pub_api_path + + # ccf id + if ccf_id is not None: + body['ccfId'] = ccf_id + + # api Status + if api_status is not None: + aef_ids_active = list() + if isinstance(api_status, list): + aef_ids_active = api_status + print("api_status parameter is a list") + elif isinstance(api_status, str): + print("api_status parameter is a string") + aef_ids_active.append(api_status) + body['apiStatus'] = dict() + body['apiStatus']['aefIds'] = aef_ids_active + + return body diff --git a/tests/libraries/common/types.json b/tests/libraries/common/types.json index 9f3aecd..5d67162 100644 --- a/tests/libraries/common/types.json +++ b/tests/libraries/common/types.json @@ -89,6 +89,19 @@ "^vendorSpecific-(.*)": "VendorSpecificObject" } }, + "ServiceAPIDescriptionPatch": { + "mandatory_attributes": {}, + "optional_attributes": { + "apiStatus": "ApiStatus", + "aefProfiles": "AefProfile", + "description": "string", + "shareableInfo": "ShareableInformation", + "serviceAPICategory": "string", + "apiSuppFeats": "SupportedFeatures", + "pubApiPath": "PublishedApiPath", + "ccfId": "string" + } + }, "ApiStatus": { "mandatory_attributes": { "aefIds": "string" -- GitLab From 408d7d6e1fbe9ca523fa99f8109563190f075498 Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Wed, 18 Dec 2024 17:26:39 +0100 Subject: [PATCH 3/3] New apiStatus tests --- tests/features/Api Status/api_status.robot | 203 +++++++++++++++++++++ 1 file changed, 203 insertions(+) diff --git a/tests/features/Api Status/api_status.robot b/tests/features/Api Status/api_status.robot index aa0b22c..ca779ad 100644 --- a/tests/features/Api Status/api_status.robot +++ b/tests/features/Api Status/api_status.robot @@ -664,7 +664,210 @@ Patch published (apiStatusMonitoring active) API with apiStatus aef1 and aef2 ## Check Events Expected towards received notifications at mock server Wait Until Keyword Succeeds 5x 5s Check Mock Server Notification Events ${events_expected} + +Patch published (apiStatusMonitoring inactive) API with apiStatus aefId1 and aefId2 + [Tags] api_status-19 mockserver + + # Initialize Mock server + Init Mock Server + + # Default Invoker Registration and Onboarding + ${register_user_info_invoker} ${url} ${request_body}= Invoker Default Onboarding + + # Register APF + ${register_user_info_provider}= Provider Default Registration total_aef_roles=2 + + ${aef_id_1}= Set Variable ${register_user_info_provider['aef_roles']['${AEF_PROVIDER_USERNAME}']['aef_id']} + ${aef_id_2}= Set Variable ${register_user_info_provider['aef_roles']['${AEF_PROVIDER_USERNAME}_1']['aef_id']} + ${aef_ids}= Create List ${aef_id_1} ${aef_id_2} + + # Subscribe to events + ${events_list}= Create List SERVICE_API_AVAILABLE SERVICE_API_UNAVAILABLE SERVICE_API_UPDATE + + ${request_body}= Create Events Subscription + ... events=@{events_list} + ... notification_destination=${NOTIFICATION_DESTINATION_URL}/testing + ... supported_features=C + ${resp}= Post Request Capif + ... /capif-events/v1/${register_user_info_invoker['api_invoker_id']}/subscriptions + ... json=${request_body} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${INVOKER_USERNAME} + + # Check Results + Check Response Variable Type And Values ${resp} 201 EventSubscription + ${subscriber_id} ${subscription_id}= Check Event Location Header ${resp} + + # Publish api with 2 aefIds + ${service_api_description_published} ${resource_url} ${request_body}= Publish Service Api + ... ${register_user_info_provider} + ... service_1 + ... aef_id=${aef_ids} + ... api_status=${aef_id_1} + ... supported_features=000 + + # Discover APIs by invoker + ${resp}= Get Request Capif + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&aef-id=${aef_id_1} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${INVOKER_USERNAME} + + Check Response Variable Type And Values ${resp} 200 DiscoveredAPIs + + # # Check Results + Dictionary Should Contain Key ${resp.json()} serviceAPIDescriptions + Should Not Be Empty ${resp.json()['serviceAPIDescriptions']} + Length Should Be ${resp.json()['serviceAPIDescriptions']} 1 + List Should Contain Value ${resp.json()['serviceAPIDescriptions']} ${service_api_description_published} + Dictionary Should Not Contain Key ${resp.json()} apiStatus + + # Update Request to published API + ${aef_empty_list}= Create List + ${service_api_description_patch}= Create Service Api Description Patch + ... api_status=${aef_ids} + ${resp}= Patch Request Capif + ... ${resource_url.path} + ... json=${service_api_description_patch} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${APF_PROVIDER_USERNAME} + + ${service_api_to_check}= Copy Dictionary ${service_api_description_published} deepcopy=${True} + ${api_status_expected}= Create dictionary aefIds=${aef_ids} + Set To Dictionary ${service_api_to_check} apiStatus=${api_status_expected} + + Check Response Variable Type And Values ${resp} 200 ServiceAPIDescription + ... apiName=service_1 + + Dictionary Should Not Contain Key ${resp.json()} apiStatus + + Dictionaries Should Be Equal ${resp.json()['apiStatus']} ${service_api_description_patch['apiStatus']} + + # Check Event Notifications + ## Create check Events to ensure all notifications were received + ${service_api_available_resources}= Create List ${resource_url} + ${events_expected}= Create Expected Events For Service API Notifications + ... subscription_id=${subscription_id} + ... service_api_available_resources=${service_api_available_resources} + ... event_detail_expected=${TRUE} + ... service_api_description_expected=${TRUE} + ... service_api_description=${service_api_description_published} + + Log List ${events_expected} + ## Check Events Expected towards received notifications at mock server + Wait Until Keyword Succeeds 5x 5s Check Mock Server Notification Events ${events_expected} + +Patch published without aefs available API with apiStatus only aef2 + [Tags] api_status-20 mockserver + + # Initialize Mock server + Init Mock Server + + # Default Invoker Registration and Onboarding + ${register_user_info_invoker} ${url} ${request_body}= Invoker Default Onboarding + + # Register APF + ${register_user_info_provider}= Provider Default Registration total_aef_roles=2 + + ${aef_id_1}= Set Variable ${register_user_info_provider['aef_roles']['${AEF_PROVIDER_USERNAME}']['aef_id']} + ${aef_id_2}= Set Variable ${register_user_info_provider['aef_roles']['${AEF_PROVIDER_USERNAME}_1']['aef_id']} + ${aef_ids}= Create List ${aef_id_1} ${aef_id_2} + ${aef_ids_empty_array}= Create List + + # Subscribe to events + ${events_list}= Create List SERVICE_API_AVAILABLE SERVICE_API_UNAVAILABLE SERVICE_API_UPDATE + + ${request_body}= Create Events Subscription + ... events=@{events_list} + ... notification_destination=${NOTIFICATION_DESTINATION_URL}/testing + ... supported_features=C + ${resp}= Post Request Capif + ... /capif-events/v1/${register_user_info_invoker['api_invoker_id']}/subscriptions + ... json=${request_body} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${INVOKER_USERNAME} + + # Check Results + Check Response Variable Type And Values ${resp} 201 EventSubscription + ${subscriber_id} ${subscription_id}= Check Event Location Header ${resp} + + # Publish api with 2 aefIds + ${service_api_description_published} ${resource_url} ${request_body}= Publish Service Api + ... ${register_user_info_provider} + ... service_1 + ... aef_id=${aef_ids} + ... api_status=${aef_ids_empty_array} + ... supported_features=020 + + # Discover APIs by invoker + ${resp}= Get Request Capif + ... ${DISCOVER_URL}${register_user_info_invoker['api_invoker_id']}&aef-id=${aef_id_1} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${INVOKER_USERNAME} + + Check Response Variable Type And Values ${resp} 200 DiscoveredAPIs + + # # Check Results + Dictionary Should Contain Key ${resp.json()} serviceAPIDescriptions + Should Not Be Empty ${resp.json()['serviceAPIDescriptions']} + Length Should Be ${resp.json()['serviceAPIDescriptions']} 1 + List Should Contain Value ${resp.json()['serviceAPIDescriptions']} ${service_api_description_published} + Dictionary Should Not Contain Key ${resp.json()} apiStatus + + # Update Request to published API + ${service_api_description_patch}= Create Service Api Description Patch + ... api_status=${aef_ids} + ${resp}= Patch Request Capif + ... ${resource_url.path} + ... json=${service_api_description_patch} + ... server=${CAPIF_HTTPS_URL} + ... verify=ca.crt + ... username=${APF_PROVIDER_USERNAME} + + ${service_api_to_check}= Copy Dictionary ${service_api_description_published} deepcopy=${True} + ${api_status_expected}= Create dictionary aefIds=${aef_ids} + Set To Dictionary ${service_api_to_check} apiStatus=${api_status_expected} + + Check Response Variable Type And Values ${resp} 200 ServiceAPIDescription + ... apiName=service_1 + + Dictionary Should Contain Key ${resp.json()} apiStatus + Dictionaries Should Be Equal ${resp.json()['apiStatus']} ${service_api_description_patch['apiStatus']} + + # Check Event Notifications + ## Create check Events to ensure all notifications were received + ${service_api_available_resources}= Create List ${resource_url} + ${service_api_unavailable_resources}= Create List ${resource_url} + ${events_expected}= Create Expected Events For Service API Notifications + ... subscription_id=${subscription_id} + ... service_api_unavailable_resources=${service_api_unavailable_resources} + ... event_detail_expected=${TRUE} + ... service_api_description_expected=${TRUE} + ... service_api_description=${service_api_description_published} + Log List ${events_expected} + + ${events_expected}= Create Expected Service Update Event + ... subscription_id=${subscription_id} + ... service_api_resource=${resource_url} + ... service_api_descriptions=${service_api_to_check} + ... events_expected=${events_expected} + Log List ${events_expected} + + ${events_expected}= Create Expected Events For Service API Notifications + ... subscription_id=${subscription_id} + ... service_api_available_resources=${service_api_available_resources} + ... event_detail_expected=${TRUE} + ... service_api_description_expected=${TRUE} + ... service_api_description=${service_api_to_check} + Log List ${events_expected} + ## Check Events Expected towards received notifications at mock server + Wait Until Keyword Succeeds 5x 5s Check Mock Server Notification Events ${events_expected} + ###--- -- GitLab