Commit 59a56fa1 authored by Benoit Orihuela's avatar Benoit Orihuela
Browse files

feat: add tests for JSON properties

parent 3c36c163
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one can retrieve the temporal evolution of an entity with a JSON property

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

Suite Setup         Create Temporal Entity
Suite Teardown      Delete Initial Temporal Entity
Test Template       Retrieve Temporal Entity


*** Variables ***
${vehicle_payload_file}=    vehicle-json-property-temporal-representation.jsonld


*** Test Cases ***    REPRESENTATION    EXPECTATION_FILENAME
020_15_01 Retrieve the normalized temporal representation of an entity with a JSON property
    [Tags]    te-retrieve    5_7_3    4_5_7    since_v1.8.1
    ${EMPTY}    vehicle-json-property-temporal-representation.json
020_15_02 Retrieve the simplified temporal representation of an entity with a JSON property
    [Tags]    te-retrieve    5_7_3    4_5_9    since_v1.8.1
    temporalValues    vehicle-json-property-simplified-temporal-representation.json


*** Keywords ***
Retrieve Temporal Entity
    [Documentation]    Check that you can retrieve the temporal evolution of an entity with a JSON property
    [Arguments]    ${representation}    ${expectation_filename}
    ${response}=    Retrieve Temporal Representation Of Entity
    ...    temporal_entity_representation_id=${temporal_entity_representation_id}
    ...    options=${representation}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    200    ${response.status_code}
    Check Response Body Containing EntityTemporal element
    ...    ${expectation_filename}
    ...    ${temporal_entity_representation_id}
    ...    ${response.json()}

Create Temporal Entity
    ${temporal_entity_representation_id}=    Generate Random Vehicle Entity Id
    Create Temporal Representation Of Entity    ${vehicle_payload_file}    ${temporal_entity_representation_id}
    Set Suite Variable    ${temporal_entity_representation_id}

Delete Initial Temporal Entity
    Delete Temporal Representation Of Entity    ${temporal_entity_representation_id}
+44 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that you can create an entity with a JsonProperty property

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

Test Teardown       Delete Initial Entity
Test Template       Create Entity Scenarios


*** Test Cases ***    FILENAME    CONTENT_TYPE
001_14_01 EntityWithJsonPropertyAsObject
    [Tags]    e-create    5_6_1    4_5_24    since_v1.8.1
    building-json-property-object.jsonld    application/ld+json
001_14_02 EntityWithJsonPropertyAsArray
    [Tags]    e-create    5_6_1    4_5_24    since_v1.8.1
    building-json-property-array.jsonld    application/ld+json


*** Keywords ***
Create Entity Scenarios
    [Documentation]    Check that you can create an entity with a JsonProperty property
    [Arguments]    ${filename}    ${content_type}
    ${entity_id}=    Generate Random Building Entity Id
    Set Test Variable    ${entity_id}
    ${response}=    Create Entity Selecting Content Type
    ...    ${filename}
    ...    ${entity_id}
    ...    ${content_type}
    Check Response Status Code    201    ${response.status_code}
    Check Response Headers Containing URI set to    ${entity_id}    ${response.headers}
    ${created_entity}=    Load Test Sample    entities/${filename}    ${entity_id}
    ${response1}=    Retrieve Entity by Id
    ...    id=${entity_id}
    ...    accept=${content_type}
    ...    context=${ngsild_test_suite_context}
    Check Created Resource Set To
    ...    created_resource=${created_entity}
    ...    response_body=${response1.json()}

Delete Initial Entity
    Delete Entity by Id    ${entity_id}
+49 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that you can append a JsonProperty property to an entity

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

Test Setup          Create Initial Entity
Test Teardown       Delete Initial Entity
Test Template       Append Attributes Without Params


*** Variables ***
${filename}=    vehicle-speed-two-datasetid.jsonld


*** Test Cases ***    STATUS_CODE    FRAGMENT_FILENAME    EXPECTATION_FILENAME
010_10_01 Append a JSON property
    [Tags]    ea-append    5_6_3    4_5_24    since_v1.8.1
    204    vehicle-new-json-property-fragment.jsonld    vehicle-json-property-appended.jsonld


*** Keywords ***
Append Attributes Without Params
    [Documentation]    Check that you can append a JsonProperty property to an entity
    [Arguments]    ${status_code}    ${fragment_filename}    ${expectation_filename}
    ${response}=    Append Entity Attributes    ${entity_id}    ${fragment_filename}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    ${status_code}    ${response.status_code}
    ${entity_expectation_payload}=    Load Test Sample    entities/expectations/${expectation_filename}    ${entity_id}
    ${response1}=    Retrieve Entity by Id
    ...    id=${entity_id}
    ...    context=${ngsild_test_suite_context}
    ...    accept=${CONTENT_TYPE_LD_JSON}
    Check Updated Resource Set To
    ...    updated_resource=${entity_expectation_payload}
    ...    response_body=${response1.json()}

Create Initial Entity
    ${entity_id}=    Generate Random Vehicle Entity Id
    ${response}=    Create Entity Selecting Content Type
    ...    ${filename}
    ...    ${entity_id}
    ...    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${response.status_code}
    Set Suite Variable    ${entity_id}

Delete Initial Entity
    Delete Entity by Id    ${entity_id}
+53 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that you can perform a partial update on a JSON property

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

Test Setup          Initiate Test Case
Test Teardown       Delete Initial Entities
Test Template       Update Attributes


*** Variables ***
${filename}=        building-json-property-object-sub-property.jsonld
${status_code}=     204


*** Test Cases ***    FRAGMENT_FILENAME    ATTRIBUTE_ID    EXPECTATION_FILENAME
012_08_01 Check that you can partially update a JSON property
    [Tags]    ea-partial-update    5_6_4    4_5_24    since_v1.8.1
    building-json-property-fragment.jsonld    jsonProperty    building-json-property-update.jsonld


*** Keywords ***
Update Attributes
    [Documentation]    Check that you can perform a partial update on a JSON property
    [Arguments]    ${fragment_filename}    ${attribute_id}    ${expectation_filename}
    ${response}=    Partial Update Entity Attributes
    ...    entityId=${entity_id}
    ...    attributeId=${attribute_id}
    ...    fragment_filename=${fragment_filename}
    ...    content_type=${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    ${status_code}    ${response.status_code}
    ${entity_expectation_payload}=    Load Test Sample    entities/expectations/${expectation_filename}    ${entity_id}
    ${response1}=    Retrieve Entity by Id
    ...    id=${entity_id}
    ...    context=${ngsild_test_suite_context}
    ...    accept=${CONTENT_TYPE_LD_JSON}
    ${ignored_attributes}=    Create List    @context
    Check Updated Resource Set To    ${entity_expectation_payload}    ${response1.json()}    ${ignored_attributes}

Initiate Test Case
    ${entity_id}=    Generate Random Vehicle Entity Id
    Set Test Variable    ${entity_id}
    ${response}=    Create Entity Selecting Content Type
    ...    ${filename}
    ...    ${entity_id}
    ...    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${response.status_code}

Delete Initial Entities
    Delete Entity by Id    ${entity_id}
+20 −0
Original line number Diff line number Diff line
{
    "id": "urn:ngsi-ld:Building:randomUUID",
    "type": "Building",
    "jsonProperty": {
        "type": "JsonProperty",
        "json": [
            {
                "id": "some-id-1",
                "anythingElse": "anything-else-1"
            },
            {
                "id": "some-id-2",
                "anythingElse": "anything-else-2"
            }
        ]
    },
    "@context": [
        "https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld"
    ]
}
 No newline at end of file
Loading