Commit 28c7f299 authored by lopesg's avatar lopesg
Browse files

Added update context source registration suite

parent c5dd3f33
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that you can update a context source registration by id
Resource    ${EXECDIR}/resources/ApiUtils.resource
Resource    ${EXECDIR}/resources/AssertionUtils.resource
Resource    ${EXECDIR}/resources/JsonUtils.resource

Test Template  Update Context Source

*** Variable ***
${registration_id_prefix}=  urn:ngsi-ld:Registration:

*** Test Case ***                                                     FILENAME                                           UPDATE_FILENAME
004_01_Update a context source registration by id                     registration-sample.jsonld                         registration-with-expiration-sample.jsonld  
004_02_Update a context source registration to never expire           registration-with-expiration-sample.jsonld         registration-sample.jsonld

*** Keywords ***
Update Context Source
    [Arguments]  ${filename}    ${update_filename}  
    [Documentation]  Check that you can update a context source registration by id
    [Tags]  mandatory
    ${registration_id}=     Generate Random Entity Id    ${registration_id_prefix}
    ${payload}=    Load Json From File    ${EXECDIR}/data/csourceRegistrations/${filename}
    ${updated_payload}=    Update Value To Json    ${payload}     $..id   ${registration_id}
    ${request}    ${response}=    Create Context Source Registration  ${updated_payload}
    Check Response Status Code  201    ${response['status']}

    ${fragment}=    Load Json From File    ${EXECDIR}/data/csourceRegistrations/${update_filename}
    ${fragment_with_id}=    Update Value To Json    ${fragment}     $..id   ${registration_id}
    ${response}=    Update Context Source Registration  ${registration_id}    ${fragment_with_id}
    Check Response Status Code  204    ${response['status']}

    [Teardown]  Delete Context Source Registration    ${registration_id}
+40 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that you cannot update a context source registration under some conditions
Resource    ${EXECDIR}/resources/ApiUtils.resource
Resource    ${EXECDIR}/resources/AssertionUtils.resource
Resource    ${EXECDIR}/resources/JsonUtils.resource

Suite Setup      Setup Initial Entities
Test Template  Update Context Source

*** Variable ***
${registration_id_prefix}=  urn:ngsi-ld:Registration:
${filename}=  registration-sample.jsonld

*** Test Case ***                                                                                  REGISTRATION_ID                FRAGMENT_FILENAME
005_01_Update a context source registration by id if the Id is not present                         ${EMPTY}                       registration-with-expiration-sample.jsonld  
005_02_Update a context source registration by id if the Id is not a valid URI                     invalidURI                     registration-with-expiration-sample.jsonld  
005_03_Update a context source registration if the request body is not of the same data type       ${valid_registration_id}       registration-different-type-sample.jsonld  
005_04_Update a context source registration if you attempt to remove a mandatory property          ${valid_registration_id}       registration-invalid-structure-sample.jsonld

*** Keywords ***
Update Context Source
    [Arguments]  ${registration_id}    ${fragment_filename}  
    [Documentation]  Check that you cannot update a context source registration under some conditions
    [Tags]  mandatory
    ${payload}=    Load Json From File    ${EXECDIR}/data/csourceRegistrations/${filename}
    ${updated_payload}=    Update Value To Json    ${payload}     $..id   ${valid_registration_id}
    ${request}    ${response}=    Create Context Source Registration  ${updated_payload}
    Check Response Status Code  201    ${response['status']}

    ${fragment}=    Load Json From File    ${EXECDIR}/data/csourceRegistrations/${fragment_filename}
    ${fragment_with_id}=    Update Value To Json    ${fragment}     $..id   ${registration_id}
    ${response}=    Update Context Source Registration  ${registration_id}    ${fragment_with_id}
    Check Response Status Code  400    ${response['status']}
    Check Response Body Containing ProblemDetails Element Containing Title Element     ${response}

    [Teardown]  Delete Context Source Registration    ${valid_registration_id}

Setup Initial Entities
    ${valid_registration_id}=     Generate Random Entity Id    ${registration_id_prefix}
    Set Suite Variable  ${valid_registration_id}
 No newline at end of file
+27 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that you cannot update a context source registration if the request body is invalid
Resource    ${EXECDIR}/resources/ApiUtils.resource
Resource    ${EXECDIR}/resources/AssertionUtils.resource
Resource    ${EXECDIR}/resources/JsonUtils.resource

*** Variable ***
${registration_id_prefix}=  urn:ngsi-ld:Registration:
${filename}=  registration-sample.jsonld
${registration_payload_file_path}=  registration-invalid-sample.jsonld

*** Test Case ***
005_04_Update a context source registration if the request body is invalid 
    [Documentation]  Check that you cannot update a context source registration if the request body is invalid
    [Tags]  mandatory
    ${registration_id}=     Generate Random Entity Id    ${registration_id_prefix}
    ${payload}=    Load Json From File    ${EXECDIR}/data/csourceRegistrations/${filename}
    ${updated_payload}=    Update Value To Json    ${payload}     $..id   ${registration_id}
    ${request}    ${response}=    Create Context Source Registration  ${updated_payload}
    Check Response Status Code  201    ${response['status']}

    ${response}=    Update Context Source Registration Using Session  ${registration_id}    ${registration_payload_file_path}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code  <Response [400]>    ${response}
    Check Response Body Type When Using Session Request      ${response.json()}     ${ERROR_TYPE_BAD_REQUEST_DATA}
    Check Response Body Title When Using Session Request    ${response.json()}

    [Teardown]  Delete Context Source Registration    ${registration_id}
+23 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that you cannot update a context source registration by id if the id is not known to the system
Resource    ${EXECDIR}/resources/ApiUtils.resource
Resource    ${EXECDIR}/resources/AssertionUtils.resource
Resource    ${EXECDIR}/resources/JsonUtils.resource

*** Variable ***
${registration_id_prefix}=  urn:ngsi-ld:Registration:
${filename}=  registration-sample.jsonld
${registration_payload_file_path}=  registration-invalid-sample.jsonld

*** Test Case ***
006_Update a context source registration by id if the id is not known to the system
    [Documentation]  Check that you cannot update a context source registration by id if the id is not known to the system
    [Tags]  mandatory
    ${registration_id}=     Generate Random Entity Id    ${registration_id_prefix}
    ${fragment}=    Load Json From File    ${EXECDIR}/data/csourceRegistrations/${filename}
    ${fragment_with_id}=    Update Value To Json    ${fragment}     $..id   ${registration_id}
    ${response}=    Update Context Source Registration  ${registration_id}    ${fragment_with_id}
    Check Response Status Code  400    ${response['status']}
    Check Response Body Containing ProblemDetails Element Containing Title Element     ${response}

    [Teardown]  Delete Context Source Registration    ${registration_id}
+43 −0
Original line number Diff line number Diff line
{
    "id": "urn:ngsi-ld:ContextSourceRegistration:randomUUID",
    "type": "building",
    "information": [
        {
        "entities": [
            {
            "id": "urn:ngsi-ld:Vehicle:A456",
            "type": "Vehicle"
            }
        ],
        "propertyNames": ["brandName","speed"],
        "relationshipNames": ["isParked"]
        },
        {
        "entities": [
            {
                "idPattern": ".*downtown$",
                "type": "OffStreetParking"
            },
            {
                "idPattern": ".*47$",
                "type": "OffStreetParking"
            }
        ],
        "propertyNames": ["availableSpotNumber","totalSpotNumber"],
        "relationshipNames": ["isNextToBuilding"]
        }
    ],
    "endpoint": "http://my.csource.org:1026", 
    "location": {
        "type": "Polygon",
        "coordinates": [
            [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
            [100.0, 1.0], [100.0, 0.0]] ]
    },
    "timestamp": {
        "startAt": " 2017-11-29T14:53:15Z"
    },
    "@context": [
        "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.3.jsonld"
    ]
}
 No newline at end of file
Loading