Commit a0f70bae authored by lopezaguilar's avatar lopezaguilar
Browse files

Improve the TS 034_02, 034_03, and 034_06

parent 4c177598
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -14,16 +14,15 @@ Test Template Update A Context Source
${registration_id_prefix}=              urn:ngsi-ld:Registration:
${filename}=                            context-source-registration-sample.jsonld
${registration_payload_file_path}=      context-source-registration-invalid-sample.jsonld
${reason_400}=                          Bad Request


*** Test Cases ***
034_02_01 Update a context source registration by id if the Id is not present
    ${EMPTY}    fragments/context-source-registration-different-type-sample.jsonld    405    ${EMPTY}
034_02_02 Update a context source registration by id if the Id is not a valid URI
*** Test Cases ***    REGISTRATION_ID    FRAGMENT_FILENAME    EXPECTED_STATUS_CODE    PROBLEM_TYPE
034_02_01 Update a context source registration by id if the Id is not a valid URI
    invalidURI    fragments/context-source-registration-different-type-sample.jsonld    400    ${ERROR_TYPE_BAD_REQUEST_DATA}
034_02_03 Update a context source registration if the request body is not of the same data type
034_02_02 Update a context source registration if the request body is not of the same data type
    ${valid_registration_id}    fragments/context-source-registration-different-type-sample.jsonld    400    ${ERROR_TYPE_BAD_REQUEST_DATA}
034_02_04 Update a context source registration if you attempt to remove a mandatory property
034_02_03 Update a context source registration if you attempt to remove a mandatory property
    ${valid_registration_id}    context-source-registration-invalid-sample.jsonld    400    ${ERROR_TYPE_BAD_REQUEST_DATA}


@@ -39,9 +38,8 @@ Update A Context Source
    ...    ${fragment_with_id}
    ...    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    ${expected_status_code}    ${response.status_code}
    IF    "${problem_type}"!="${EMPTY}"
        Check Response Body Containing ProblemDetails Element Containing Title Element    ${response.json()}
    END
    Check Response Reason set to    ${response.reason}    ${reason_400}
    Check Response Body Containing ProblemDetails Element    ${response.json()}    ${problem_type}

Create Initial Context Source Registration
    ${valid_registration_id}=    Generate Random Entity Id    ${registration_id_prefix}
+3 −1
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ Resource ${EXECDIR}/resources/JsonUtils.resource
*** Variables ***
${registration_id_prefix}=      urn:ngsi-ld:Registration:
${filename}=                    context-source-registration-sample.jsonld
${reason_404}=                  Not Found


*** Test Cases ***
@@ -24,4 +25,5 @@ ${filename}= context-source-registration-sample.jsonld
    ...    ${fragment_with_id}
    ...    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    404    ${response.status_code}
    Check Response Body Containing ProblemDetails Element Containing Title Element    ${response.json()}
    Check Response Reason set to    ${response.reason}    ${reason_404}
    Check Response Body Containing ProblemDetails Element    ${response.json()}    ${ERROR_TYPE_RESOURCE_NOT_FOUND}
+49 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that you cannot update a context source registration if the Id is not present

Resource            ${EXECDIR}/resources/ApiUtils/ContextSourceRegistration.resource
Resource            ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource

Test Setup          Create Initial Context Source Registration
Test Teardown       Delete Initial Context Source Registration
Test Template       Update A Context Source


*** Variables ***
${registration_id_prefix}=              urn:ngsi-ld:Registration:
${filename}=                            context-source-registration-sample.jsonld
${registration_payload_file_path}=      context-source-registration-invalid-sample.jsonld
${reason_405}=                          Method Not Allowed


*** Test Cases ***    FRAGMENT_FILENAME    EXPECTED_STATUS_CODE    REASON
034_06_01 Update a context source registration by id if the Id is not present
    fragments/context-source-registration-different-type-sample.jsonld    405    ${reason_405}


*** Keywords ***
Update A Context Source
    [Documentation]    Check that you cannot update a context source registration under some conditions
    [Tags]    csr-update    5_9_3
    [Arguments]    ${fragment_filename}    ${expected_status_code}    ${reason}
    ${fragment}=    Load JSON From File    ${EXECDIR}/data/csourceRegistrations/${fragment_filename}
    ${fragment_with_id}=    Update Value To JSON    ${fragment}    $.id    ${EMPTY}
    ${response}=    Update Context Source Registration With Return
    ...    ${EMPTY}
    ...    ${fragment_with_id}
    ...    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    ${expected_status_code}    ${response.status_code}
    Check Response Reason set to    ${response.reason}    ${reason}
    Check Response Does Not Contain Body    ${response}

Create Initial Context Source Registration
    ${valid_registration_id}=    Generate Random Entity Id    ${registration_id_prefix}
    Set Suite Variable    ${valid_registration_id}
    ${payload}=    Load JSON From File    ${EXECDIR}/data/csourceRegistrations/${filename}
    ${updated_payload}=    Update Value To JSON    ${payload}    $.id    ${valid_registration_id}
    ${response}=    Create Context Source Registration With Return    ${updated_payload}
    Check Response Status Code    201    ${response.status_code}

Delete Initial Context Source Registration
    Delete Context Source Registration    ${valid_registration_id}
+38 −1
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ class Checks:
                Checks.check_response_body_title_when_using_session_request,
            'Check Response Body Containing ProblemDetails Element Containing Title Element':
                Checks.check_response_body_containing_problemdetails_element_containing_title_element,
            'Check Response Body Containing ProblemDetails Element':
                Checks.check_response_body_containing_problemdetails_element,
            'Check RL Response Body Containing ProblemDetails Element Containing Type Element set to':
                Checks.check_rl_response_body_containing_problemdetails_element_containing_type_element_set_to,
            'Check RL Response Body Containing ProblemDetails Element Containing Title Element':
@@ -99,7 +101,11 @@ class Checks:
            'Check Retrieving Context Source Registration':
                Checks.check_retrieving_context_source_registration,
            'Check JSON Value Not In Response Body':
                Checks.check_json_value_not_in_response_body
                Checks.check_json_value_not_in_response_body,
            'Check Response Reason set to':
                Checks.check_response_reason_set_to,
            'Check Response Does Not Contain Body':
                Checks.check_response_does_not_contain_body
        }

        self.args = {
@@ -115,6 +121,10 @@ class Checks:
                'params': ['type'],
                'position': [1]
            },
            'Check Response Body Containing ProblemDetails Element': {
                'params': ['problem_type'],
                'position': [1]
            },
            'Check Response Headers Containing Content-Type set to': {
                'params': ['content_type'],
                'position': [0]
@@ -284,6 +294,14 @@ class Checks:
            'Check JSON Value Not In Response Body': {
                'params': ['json_path_expr'],
                'position': [0]
            },
            'Check Response Reason set to': {
                'params': ['reason'],
                'position': [1]
            },
            'Check Response Does Not Contain Body': {
                'params': ['response'],
                'position': [0]
            }
        }

@@ -364,6 +382,14 @@ class Checks:

        return response

    @staticmethod
    def check_response_reason_set_to(kwargs: list) -> str:
        return f"Response reason set to '{kwargs['reason']}'"

    @staticmethod
    def check_response_does_not_contain_body(kwargs: list) -> str:
        return f"Response does not contain a body"

    @staticmethod
    def check_response_body_containing_array_of_uris_set_to(kwargs: list) -> str:
        return 'Response Body set to an array of created entities ids'
@@ -645,6 +671,17 @@ class Checks:
        else:
            raise Exception(f"ERROR, expected type attribute, but received: {kwargs}")

    @staticmethod
    def check_response_body_containing_problemdetails_element(kwargs: list) -> str:
        if 'problem_type' in kwargs:
            problem_type = kwargs['problem_type']
            return (f"Response Body containing the type '{problem_type}' and "
                    f"Response Body Title is a string and is not ${{EMPTY}} and "
                    f"Response Body Detail is a string and is not ${{EMPTY}} and "
                    f"Response Boty Title is not equal to Response Body Detail")
        else:
            raise Exception(f"ERROR, expected type attribute, but received: {kwargs}")

    @staticmethod
    def check_response_body_title_when_using_session_request(kwargs: list) -> str:
        return "Response body containing 'title' element"
+12 −26
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@
  "initial_condition": "with {\n    the SUT being in the \"initial state\" and\n    the SUT contains a Context Source Registration \n        with id equal to ${context_source_registration_id}\n        and payload set to ${context_source_registration_payload_file_path}\n}",
  "test_cases": [
    {
      "name": "034_02_01 Update a context source registration by id if the Id is not present",
      "name": "034_02_01 Update a context source registration by id if the Id is not a valid URI",
      "permutation_tp_id": "TP/NGSI-LD/CS/REG/034_02_01",
      "doc": "Check that you cannot update a context source registration under some conditions",
      "tags": [
@@ -20,13 +20,13 @@
      "setup": "Create Initial Context Source Registration",
      "teardown": "Delete Initial Context Source Registration",
      "template": "Update A Context Source",
      "then": "then {\n    the SUT sends a valid Response for the operations:\n        Update Context Source Registration With Return with Response Status Code set to 400     and\n        Update Context Source Registration With Return with Response body containing 'title' element\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/csourceRegistrations/{registration_id}'\n        method set to 'PATCH'\n        Update Context Source Registration with id set to '${registration_id}' and registration update fragment set to '${fragment_with_id}' and content-type set to 'application/ld+json'\n}",
      "then": "then {\n    the SUT sends a valid Response for the operations:\n        Update Context Source Registration With Return with Response Status Code set to 400     and\n        Update Context Source Registration With Return with Response reason set to 'Bad Request'     and\n        Update Context Source Registration With Return with Response Body containing the type 'https://uri.etsi.org/ngsi-ld/errors/BadRequestData' and Response Body Title is a string and is not ${EMPTY} and Response Body Detail is a string and is not ${EMPTY} and Response Boty Title is not equal to Response Body Detail\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/csourceRegistrations/{registration_id}'\n        method set to 'PATCH'\n        Update Context Source Registration with id set to 'invalidURI' and registration update fragment set to '${fragment_with_id}' and content-type set to 'application/ld+json'\n}",
      "http_verb": "PATCH",
      "endpoint": "csourceRegistrations/{registration_id}"
    },
    {
      "name": "034_02_02 Update a context source registration by id if the Id is not a valid URI",
      "name": "034_02_02 Update a context source registration if the request body is not of the same data type",
      "permutation_tp_id": "TP/NGSI-LD/CS/REG/034_02_02",
      "doc": "Check that you cannot update a context source registration under some conditions",
      "tags": [
@@ -36,13 +36,13 @@
      "setup": "Create Initial Context Source Registration",
      "teardown": "Delete Initial Context Source Registration",
      "template": "Update A Context Source",
      "then": "then {\n    the SUT sends a valid Response for the operations:\n        Update Context Source Registration With Return with Response Status Code set to 400     and\n        Update Context Source Registration With Return with Response body containing 'title' element\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/csourceRegistrations/{registration_id}'\n        method set to 'PATCH'\n        Update Context Source Registration with id set to '${registration_id}' and registration update fragment set to '${fragment_with_id}' and content-type set to 'application/ld+json'\n}",
      "then": "then {\n    the SUT sends a valid Response for the operations:\n        Update Context Source Registration With Return with Response Status Code set to 400     and\n        Update Context Source Registration With Return with Response reason set to 'Bad Request'     and\n        Update Context Source Registration With Return with Response Body containing the type 'https://uri.etsi.org/ngsi-ld/errors/BadRequestData' and Response Body Title is a string and is not ${EMPTY} and Response Body Detail is a string and is not ${EMPTY} and Response Boty Title is not equal to Response Body Detail\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/csourceRegistrations/{registration_id}'\n        method set to 'PATCH'\n        Update Context Source Registration with id set to '${valid_registration_id}' and registration update fragment set to '${fragment_with_id}' and content-type set to 'application/ld+json'\n}",
      "http_verb": "PATCH",
      "endpoint": "csourceRegistrations/{registration_id}"
    },
    {
      "name": "034_02_03 Update a context source registration if the request body is not of the same data type",
      "name": "034_02_03 Update a context source registration if you attempt to remove a mandatory property",
      "permutation_tp_id": "TP/NGSI-LD/CS/REG/034_02_03",
      "doc": "Check that you cannot update a context source registration under some conditions",
      "tags": [
@@ -52,29 +52,15 @@
      "setup": "Create Initial Context Source Registration",
      "teardown": "Delete Initial Context Source Registration",
      "template": "Update A Context Source",
      "then": "then {\n    the SUT sends a valid Response for the operations:\n        Update Context Source Registration With Return with Response Status Code set to 400     and\n        Update Context Source Registration With Return with Response body containing 'title' element\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/csourceRegistrations/{registration_id}'\n        method set to 'PATCH'\n        Update Context Source Registration with id set to '${registration_id}' and registration update fragment set to '${fragment_with_id}' and content-type set to 'application/ld+json'\n}",
      "http_verb": "PATCH",
      "endpoint": "csourceRegistrations/{registration_id}"
    },
    {
      "name": "034_02_04 Update a context source registration if you attempt to remove a mandatory property",
      "permutation_tp_id": "TP/NGSI-LD/CS/REG/034_02_04",
      "doc": "Check that you cannot update a context source registration under some conditions",
      "tags": [
        "csr-update",
        "5_9_3"
      ],
      "setup": "Create Initial Context Source Registration",
      "teardown": "Delete Initial Context Source Registration",
      "template": "Update A Context Source",
      "then": "then {\n    the SUT sends a valid Response for the operations:\n        Update Context Source Registration With Return with Response Status Code set to 400     and\n        Update Context Source Registration With Return with Response body containing 'title' element\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/csourceRegistrations/{registration_id}'\n        method set to 'PATCH'\n        Update Context Source Registration with id set to '${registration_id}' and registration update fragment set to '${fragment_with_id}' and content-type set to 'application/ld+json'\n}",
      "then": "then {\n    the SUT sends a valid Response for the operations:\n        Update Context Source Registration With Return with Response Status Code set to 400     and\n        Update Context Source Registration With Return with Response reason set to 'Bad Request'     and\n        Update Context Source Registration With Return with Response Body containing the type 'https://uri.etsi.org/ngsi-ld/errors/BadRequestData' and Response Body Title is a string and is not ${EMPTY} and Response Body Detail is a string and is not ${EMPTY} and Response Boty Title is not equal to Response Body Detail\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/csourceRegistrations/{registration_id}'\n        method set to 'PATCH'\n        Update Context Source Registration with id set to '${valid_registration_id}' and registration update fragment set to '${fragment_with_id}' and content-type set to 'application/ld+json'\n}",
      "http_verb": "PATCH",
      "endpoint": "csourceRegistrations/{registration_id}"
    }
  ],
  "permutations": [],
  "permutations": [
    "when"
  ],
  "robotpath": "ContextSource/Registration/UpdateContextSourceRegistration",
  "robotfile": "034_02"
}
 No newline at end of file
Loading