Commit eb650098 authored by lopesg's avatar lopesg
Browse files

refactored common behaviors

parent a9520625
Loading
Loading
Loading
Loading
+67 −19
Original line number Diff line number Diff line
@@ -4,33 +4,81 @@ Resource ${EXECDIR}/resources/ApiUtils.resource
Resource    ${EXECDIR}/resources/AssertionUtils.resource
Resource    ${EXECDIR}/resources/JsonUtils.resource

Test Template  Throw 503 LDContextNotAvaliable error 

*** Variable ***
${expected_status_code}=  503

${building_id_prefix}=  urn:ngsi-ld:Building:
${registration_id_prefix}=  urn:ngsi-ld:Registration:
${building_filename}=  building-minimal-without-context-sample.jsonld 

${subscription_id_prefix}=  urn:ngsi-ld:Subscription:
${subscription_filename}=  csourceSubscriptions/subscription-without-context-sample.jsonld

${tea_id_prefix}=  urn:ngsi-ld:Vehicle:
${tea_filename}=  bus-temporal-representation-without-context-sample.jsonld

${registration_id_prefix}=  urn:ngsi-ld:Registration:
${registration_filename}=  csourceRegistrations/context-source-registration-without-context-sample.jsonld   

*** Test Cases ***                          PREFIX                              DELETE_PREFIX             ENDPOINT                                                              FILENAME_PATH                                                                           
043_01_endpoint /entities/                  ${building_id_prefix}               ${EMPTY}                  ${ENTITIES_ENDPOINT_PATH}                                             entities/building-minimal-without-context-sample.jsonld 
043_02_endpoint /csourceRegistrations/      ${registration_id_prefix}           ${EMPTY}                  ${CONTEXT_SOURCE_REGISTRATION_ENDPOINT_PATH}                          csourceRegistrations/context-source-registration-without-context-sample.jsonld                         
043_03_endpoint /subscriptions/             ${subscription_id_prefix}           ${EMPTY}                  ${SUBSCRIPTION_ENDPOINT_PATH}                                         csourceSubscriptions/subscription-without-context-sample.jsonld
043_04_endpoint /csourceSubscriptions/      ${subscription_id_prefix}           /                         ${CONTEXT_SOURCE_REGISTRATION_SUBSCRIPTION_ENDPOINT_PATH}             csourceSubscriptions/subscription-without-context-sample.jsonld
043_05_endpoint /temporal/entities/         ${building_id_prefix}               /                         ${TEMPORAL_ENTITIES_ENDPOINT_PATH}                                    temporalEntities/bus-temporal-representation-without-context-sample.jsonld
*** Test Cases *** 
043_01 Create entity
    [Documentation]  Verify throwing 503 – LDContextNotAvaliable error if remote JSON-LD @context cannot be retrieved (Create entity)

*** Keywords ***                               
Throw 503 LDContextNotAvaliable error 
    [Arguments]  ${prefix}     ${delete_prefix}     ${endpoint}     ${filename_path}
    [Documentation]  Verify throwing 503 – LDContextNotAvaliable error if remote JSON-LD @context cannot be retrieved 
    [Tags]  mandatory
    ${entity_id}=  Generate Random Entity Id    ${building_id_prefix}    
    ${request}    ${response}=    Create Entity Selecting Content Type   ${building_filename}      ${entity_id}     ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code  ${expected_status_code}    ${response['status']}
    Check Response Body Containing ProblemDetails Element Containing Type Element set to      ${response}     ${ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE}
    Check Response Body Containing ProblemDetails Element Containing Title Element    ${response}

    [Teardown]  Delete Entity by Id  ${entity_id}

    ${create_id}=       Generate Random Entity Id    ${prefix}    
    ${delete_id}=       Set Variable    ${delete_prefix}${create_id}  
043_02 Create subscription
    [Documentation]  Verify throwing 503 – LDContextNotAvaliable error if remote JSON-LD @context cannot be retrieved (Create subscription)

    ${response}=    Create Request By Selecting Endpoint    ${create_id}    ${endpoint}    ${filename_path}
    ${subscription_id}=  Generate Random Entity Id    ${subscription_id_prefix}    
    ${response}=    Create Subscription    ${subscription_id}    ${subscription_filename}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code  ${expected_status_code}    ${response['status']}
    Check Response Body Containing ProblemDetails Element Containing Type Element set to      ${response}     ${ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE}
    Check Response Body Containing ProblemDetails Element Containing Title Element    ${response}

    [Teardown]  Delete Request By Selecting Endpoint/Id  ${delete_id}    ${endpoint}
 No newline at end of file
    [Teardown]  Delete Subscription  ${subscription_id}


043_03 Create Temporal Representation of Entities
    [Documentation]  Verify throwing 503 – LDContextNotAvaliable error if remote JSON-LD @context cannot be retrieved (Create Temporal Representation of Entities)

    ${temporal_entity_representation_id}=     Generate Random Entity Id    ${tea_id_prefix}
    ${response}=  Create Or Update Temporal Representation Of Entity Selecting Content Type  ${temporal_entity_representation_id}    ${tea_filename}     ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code  ${expected_status_code}    ${response['status']}
    Check Response Body Containing ProblemDetails Element Containing Type Element set to      ${response}     ${ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE}
    Check Response Body Containing ProblemDetails Element Containing Title Element    ${response}

    [Teardown]  Delete Temporal Representation Of Entity    ${temporal_entity_representation_id}

043_04 Batch entity create
    [Documentation]  Verify throwing 503 – LDContextNotAvaliable error if remote JSON-LD @context cannot be retrieved (Batch entity create)

    ${first_entity_id}=     Generate Random Entity Id    ${building_id_prefix}
    ${second_entity_id}=     Generate Random Entity Id    ${building_id_prefix}
    ${first_entity}=    Load Entity    ${building_filename}      ${first_entity_id}
    ${second_entity}=    Load Entity    ${building_filename}      ${second_entity_id}
    @{entities_to_be_created}=  Create List   ${first_entity}     ${second_entity}

    Batch Create Entities   @{entities_to_be_created}    content_type=${CONTENT_TYPE_LD_JSON}
    Check Response Status Code Set To  ${expected_status_code}
    Check RL Response Body Containing ProblemDetails Element Containing Type Element set to      ${response}     ${ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE}
    Check RL Response Body Containing ProblemDetails Element Containing Title Element    ${response}

    [Teardown]  Batch Delete Entities  @{entities_to_be_created}

043_05 Create context source registration
    [Documentation]  Verify throwing 503 – LDContextNotAvaliable error if remote JSON-LD @context cannot be retrieved (Create context source registration)

    ${registration_id_prefix}=     Generate Random Entity Id    ${registration_id_prefix}

    ${payload}=    Load Json From File    ${EXECDIR}/data/${registration_filename}
    ${updated_payload}=    Update Value To Json    ${payload}     $..id   ${registration_id_prefix}
    ${request}    ${response}=    Create Context Source Registration With Return  ${updated_payload}
    Check Response Status Code  ${expected_status_code}    ${response['status']}
    Check Response Headers Containing URI set to    ${request['path']}/    ${registration_id}    ${response}

    [Teardown]  Delete Context Source Registration    ${registration_id_prefix}
 No newline at end of file
+41 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Verify that PATCH HTTP requests can be done with "application/merge-patch+json" as Content-Type 
Resource    ${EXECDIR}/resources/ApiUtils.resource
Resource    ${EXECDIR}/resources/AssertionUtils.resource
Resource    ${EXECDIR}/resources/JsonUtils.resource

*** Variable ***
${vehicle_id_prefix}=  urn:ngsi-ld:Vehicle:
${vehicle_filename}=  vehicle-simple-attributes-sample.jsonld
${vehicle_fragment}=  vehicle-fragment-brandname-sample.jsonld
${attribute_id}=  brandName

${subscription_id_prefix}=  urn:ngsi-ld:Subscription:
${subscription_filename}=  csourceSubscriptions/subscription-sample.jsonld
${subscription_fragment}=  csourceSubscriptions/fragments/subscription-update-sample.jsonld

*** Test Cases ***                               
044_01_02_endpoint /entities/{entityId}/attrs/{attrId}
    [Documentation]  Verify that PATCH HTTP requests can be done with "application/merge-patch+json" as Content-Type 
    [Tags]  mandatory
    ${entity_id}=       Generate Random Entity Id    ${vehicle_id_prefix}    
    ${request}    ${response}=    Create Entity Selecting Content Type    ${vehicle_filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}    
    Check Response Status Code  201    ${response['status']}

    ${response}=    Partial Update Entity Attributes    ${entity_id}    ${attribute_id}    ${vehicle_fragment}    ${CONTENT_TYPE_MERGE_PATCH_JSON}
    Check Response Status Code  204    ${response['status']}

    [Teardown]  Delete Entity by Id  ${entity_id}

044_01_03_endpoint /subscriptions/{subscriptionId}       
    [Documentation]  Verify that PATCH HTTP requests can be done with "application/merge-patch+json" as Content-Type 
    [Tags]  mandatory
    ${subscription_id}=       Generate Random Entity Id    ${subscription_id_prefix}    
    ${response}=    Create Subscription    ${subscription_id}    ${subscription_filename}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code  201    ${response['status']}

    ${response}=    Update Subscription    ${subscription_id}     ${subscription_fragment}    ${CONTENT_TYPE_MERGE_PATCH_JSON}
    Check Response Status Code  204    ${response['status']}

    [Teardown]  Delete Subscription  ${subscription_id}
+72 −1
Original line number Diff line number Diff line
@@ -9,6 +9,22 @@ ${vehicle_id_prefix}= urn:ngsi-ld:Vehicle:
${filename}=  vehicle-two-datasetid-attributes-sample.jsonld
${fragment_filename}=  vehicle-two-datasetid-attributes-sample-01.jsonld


${vehicle_id_prefix}=  urn:ngsi-ld:Vehicle:
${filename}=  vehicle-simple-attributes-sample.jsonld
${fragment_filename}=  vehicle-fragment-brandname-sample.jsonld
${attribute_id}=  brandName


${subscription_id_prefix}=  urn:ngsi-ld:Subscription:
${filename_path}=  csourceSubscriptions/subscription-sample.jsonld
${fragment_filename_path}=  csourceSubscriptions/fragments/subscription-update-sample.jsonld

${registration_id_prefix}=  urn:ngsi-ld:Registration:
${registration_payload_file_path}=   registration-sample.jsonld 
${fragment_filename_path}=  context-source-registration-update-sample.jsonld


*** Test Cases ***                               
044_01_01_endpoint /entities/{entityId}/attrs/
    [Documentation]  Verify that PATCH HTTP requests can be done with "application/merge-patch+json" as Content-Type 
@@ -21,3 +37,58 @@ ${fragment_filename}= vehicle-two-datasetid-attributes-sample-01.jsonld
    Check Response Status Code  204    ${response['status']}

    [Teardown]  Delete Entity by Id  ${entity_id}

044_01_02_endpoint /entities/{entityId}/attrs/{attrId}
    [Documentation]  Verify that PATCH HTTP requests can be done with "application/merge-patch+json" as Content-Type 
    [Tags]  mandatory
    ${entity_id}=       Generate Random Entity Id    ${vehicle_id_prefix}    
    ${request}    ${response}=    Create Entity Selecting Content Type    ${filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}    
    Check Response Status Code  201    ${response['status']}

    ${response}=    Partial Update Entity Attributes    ${entity_id}    ${attribute_id}    ${fragment_filename}    ${CONTENT_TYPE_MERGE_PATCH_JSON}
    Check Response Status Code  204    ${response['status']}

    [Teardown]  Delete Entity by Id  ${entity_id}

044_01_03_endpoint /subscriptions/{subscriptionId}       
    [Documentation]  Verify that PATCH HTTP requests can be done with "application/merge-patch+json" as Content-Type 
    [Tags]  mandatory
    ${subscription_id}=       Generate Random Entity Id    ${subscription_id_prefix}    
    ${response}=    Create Subscription    ${subscription_id}    ${filename_path}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code  201    ${response['status']}

    ${response}=    Update Subscription    ${subscription_id}     ${fragment_filename_path}    ${CONTENT_TYPE_MERGE_PATCH_JSON}
    Check Response Status Code  204    ${response['status']}

    [Teardown]  Delete Subscription  ${subscription_id}

044_01_04_endpoint /csourceRegistrations/{registrationId}  
    [Documentation]  Verify that PATCH HTTP requests can be done with "application/merge-patch+json" as Content-Type 
    [Tags]  mandatory
    ${registration_id}=     Generate Random Entity Id    ${registration_id_prefix}

    ${payload}=    Load Json From File    ${EXECDIR}/data/csourceRegistrations/${registration_payload_file_path}
    ${updated_payload}=    Update Value To Json    ${payload}     $..id   ${registration_id}
    ${request}    ${response}=    Create Context Source Registration With Return  ${updated_payload}
    Check Response Status Code  201    ${response['status']}

    ${fragment}=    Load Json From File    ${EXECDIR}/data/csourceRegistrations/fragments/${fragment_filename_path}
    ${response}=    Update Context Source Registration With Return  ${registration_id}    ${fragment}    ${CONTENT_TYPE_MERGE_PATCH_JSON}
    Check Response Status Code  204    ${response['status']}

    [Teardown]  Delete Context Source Registration    ${registration_id}

*** comment *** 
043_01 Create entity
043_02 Retrieve entity by id
043_03 Partial attribute update

043_04 Create subscription
043_05 Retrieve subscription by id
043_06 Update subscription

043_07 Create Temporal Representation of Entities
043_08 Query temporal entities
043_09 Batch entity create
043_10 Create context source registration
043_11 Query context source registration
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ ${teatype}= Vehicle
    ${request}    ${response}=    Create Entity Selecting Content Type  ${building_filename}     ${id}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code  201    ${response['status']}

    ${response}=    Query Entity    ${id}
    ${request}    ${response}=    Query Entity    ${id}
    Check Response Status Code  200    ${response['status']}
    Check Response Body Containing Entity element    ${building_expectation}    ${id}    ${response['body']}

@@ -82,7 +82,7 @@ ${teatype}= Vehicle
    ${response}=    Create Subscription    ${id}    ${subscription_filename}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code  201    ${response['status']}

    ${response}=  Retrieve Subscription  ${id}
    ${request}    ${response}=  Retrieve Subscription  ${id}
    Check Response Status Code  200    ${response['status']}
    Check Response Body Containing One Subscription element    ${subscription_expectation}    ${response['body']}

+84 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Verify that on a GET HTTP request if nothing is specified on the Accept header, "application/json" is assumed
Resource    ${EXECDIR}/resources/ApiUtils.resource
Resource    ${EXECDIR}/resources/AssertionUtils.resource
Resource    ${EXECDIR}/resources/JsonUtils.resource

*** Variable ***
${building_id_prefix}=  urn:ngsi-ld:Building:
${building_filename}=  building-simple-attributes-sample.jsonld
${building_expectation}=  building-simple-attributes-sample-expectation.json
${entity_type}=  https://ngsi-ld-test-suite/context#Building

${subscription_id_prefix}=  urn:ngsi-ld:Subscription:
${subscription_filename}=  csourceSubscriptions/subscription-sample.jsonld
${subscription_expectation}=  subscription-sample-expectation.json

${registration_id_prefix}=  urn:ngsi-ld:Registration:
${registration_filename}=   csourceRegistrations/registration-with-expiration-sample.jsonld
${registration_expectation}=  registration-with-expiration-expectation-sample.json
${registration_type}=  Vehicle

${tea_id_prefix}=  urn:ngsi-ld:Vehicle:
${tea_filename}=  vehicle-temporal-representation-sample.jsonld
${tea_expectation}=  vehicle-temporal-representation-expectation.json
${teatype}=  Vehicle

*** Test Cases ***
044_02_01_endpoint /entities/{entityId}
    [Documentation]  Verify that on a GET HTTP request if nothing is specified on the Accept header, "application/json" is assumed (/entities/{entityId})
    ${id}=     Generate Random Entity Id    ${building_id_prefix}
    ${request}    ${response}=    Create Entity Selecting Content Type  ${building_filename}     ${id}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code  201    ${response['status']}

    ${request}    ${response}=    Query Entity    ${id}
    Check Response Status Code  200    ${response['status']}
    Check Response Body Containing Entity element    ${building_expectation}    ${id}    ${response['body']}
    Check Request Containing Accept Header Set To  ${request}    application/json, */* 

    [Teardown]  Delete Entity by Id Returning Response   ${id}
    

044_02_02_endpoint /subscriptions/{subscriptionId}
    [Documentation]  Verify that on a GET HTTP request if nothing is specified on the Accept header, "application/json" is assumed (/subscriptions/{subscriptionId})

    ${id}=  Generate Random Entity Id    ${subscription_id_prefix}    
    ${response}=    Create Subscription    ${id}    ${subscription_filename}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code  201    ${response['status']}

    ${request}    ${response}=  Retrieve Subscription  ${id}
    Check Response Status Code  200    ${response['status']}
    Check Response Body Containing One Subscription element    ${subscription_expectation}    ${response['body']}
    Check Request Containing Accept Header Set To  ${request}    application/json, */* 

    [Teardown]  Delete Subscription  ${id}

044_02_03_endpoint /csourceRegistrations/
    [Documentation]  Verify that on a GET HTTP request if nothing is specified on the Accept header, "application/json" is assumed (/csourceRegistrations/)

    ${registration_id}=     Generate Random Entity Id    ${registration_id_prefix}
    ${payload}=    Load Json From File    ${EXECDIR}/data/${registration_filename}
    ${updated_payload}=    Update Value To Json    ${payload}     $..id   ${registration_id}
    ${request}    ${response}=    Create Context Source Registration With Return  ${updated_payload}
    Check Response Status Code  201    ${response['status']}

    ${request}    ${response}=  Query Context Source Registrations With Return      id=${registration_id}    type=${registration_type}
    Check Response Status Code  200    ${response['status']}
    Check Response Body Containing One Registration element  ${registration_expectation}    ${response['body']}
    Check Request Containing Accept Header Set To  ${request}    application/json, */* 

    [Teardown]  Delete Context Source Registration    ${registration_id}

044_02_04_endpoint /temporal/entities
    [Documentation]  Verify that on a GET HTTP request if nothing is specified on the Accept header, "application/json" is assumed (/temporal/entities)

    ${temporal_entity_representation_id}=     Generate Random Entity Id    ${tea_id_prefix}
    Create Temporal Representation Of Entity  ${tea_filename}     ${temporal_entity_representation_id}

    ${request}    ${response}=  Query Temporal Representation Of Entities With Return   entity_types=${teatype}    timerel=after    timeAt=2020-08-01T12:05:00Z
    Check Response Status Code  200    ${response['status']}
    Set Test Variable  ${response}
    Check Response Body Containing EntityTemporal element      ${tea_expectation}    ${temporal_entity_representation_id}
    Check Request Containing Accept Header Set To  ${request}    application/json, */* 

    [Teardown]  Delete Temporal Representation Of Entity    ${temporal_entity_representation_id}
 No newline at end of file
Loading