Commit c251b3cd authored by root's avatar root
Browse files

added Consumption/Entity/001_02.robot

parent 074a5505
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -6,17 +6,20 @@ Resource ${EXECDIR}/resources/JsonUtils.resource

*** Variable ***
${building_id_prefix}=  urn:ngsi-ld:Building:
${filename}=  building-simple-attributes-sample.jsonld
${expectation_filename}=  building-simple-attributes-sample-expectation.jsonld

*** Test Cases ***                               
001_01_Check that you can get an entity by id
001_01_Get an entity by id
    [Documentation]  Check that you can get an entity by id
    [Tags]  mandatory

    ${entity_id}=     Generate Random Entity Id    ${building_id_prefix}
    ${request}    ${response}=    Create Entity Selecting Content Type  building-simple-attributes-sample.jsonld     ${entity_id}    application/ld+json
    ${request}    ${response}=    Create Entity Selecting Content Type  ${filename}     ${entity_id}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code  201    ${response['status']}

    ${response}=    Retrieve Entity by Id Returning Response    ${entity_id}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code  200    ${response['status']}
    Check Response Body Containing Entity element    ${expectation_filename}    ${entity_id}    ${response}

    [Teardown]  Delete Entity by Id Returning Response   ${entity_id}
 No newline at end of file
+28 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that you can query some attributes from entity
Resource    ${EXECDIR}/resources/ApiUtils.resource
Resource    ${EXECDIR}/resources/AssertionUtils.resource
Resource    ${EXECDIR}/resources/JsonUtils.resource

*** Variable ***
${building_id_prefix}=  urn:ngsi-ld:Building:
${filename}=  building-simple-attributes-sample.jsonld
${expectation_filename}=  building-simple-attributes-sample-expectation-query-attributes.jsonld
${attribute_airqualitylevel}=  https://uri.fiware.org/ns/data-models#airQualityLevel
${attribute_subcategory}=  https://uri.fiware.org/ns/data-models#subCategory

*** Test Cases ***                               
001_02_Query some attributes from an entity
    [Documentation]  Check that you can query some attributes from entity
    [Tags]  mandatory

    ${entity_id}=     Generate Random Entity Id    ${building_id_prefix}
    ${request}    ${response}=    Create Entity Selecting Content Type  ${filename}     ${entity_id}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code  201    ${response['status']}

    ${attributes_to_be_retrieved}=  Create List      ${attribute_airqualitylevel}  ${attribute_subcategory}
    ${response}=    Query Entity    ${entity_id}    ${CONTENT_TYPE_LD_JSON}    attrs=${attributes_to_be_retrieved}
    Check Response Status Code  200    ${response['status']}
    Check Response Body Containing Entity element    ${expectation_filename}    ${entity_id}    ${response}

    [Teardown]  Delete Entity by Id Returning Response   ${entity_id}
 No newline at end of file
+17 −0
Original line number Diff line number Diff line
{
    "id": "urn:ngsi-ld:Building:7123416795055774",
    "type": "https://uri.fiware.org/ns/data-models#Building",
    "https://uri.fiware.org/ns/data-models#airQualityLevel": {
        "type": "Property",
        "value": 4,
        "observedAt": "2020-09-09T16:40:00.000Z",
        "unitCode": "C62"
    },
    "https://uri.fiware.org/ns/data-models#subCategory": {
        "type": "Property",
        "value": "tourism"
    },
    "@context": [
        "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld"
    ]
}
 No newline at end of file
+25 −0
Original line number Diff line number Diff line
{
    "id": "urn:ngsi-ld:Building:6539860708584325",
        "type": "https://uri.fiware.org/ns/data-models#Building",
        "name": {
            "type": "Property",
            "value": "Eiffel Tower"
    },
    "https://uri.fiware.org/ns/data-models#airQualityLevel": {
        "type": "Property",
        "value": 4,
        "observedAt": "2020-09-09T16:40:00.000Z",
        "unitCode": "C62"
    },
    "https://uri.fiware.org/ns/data-models#almostFull": {
        "type": "Property",
        "value": false
    },
    "https://uri.fiware.org/ns/data-models#subCategory": {
        "type": "Property",
        "value": "tourism"
    },
    "@context": [
        "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld"
    ]
}
 No newline at end of file
+16 −4
Original line number Diff line number Diff line
@@ -68,12 +68,26 @@ Retrieve Entity by Id Returning Response
    [Arguments]  ${id}      ${accept}     ${context}=${EMPTY}
    ${headers}=  Create Dictionary
    Set To Dictionary   ${headers}   Accept    ${accept}
    Run Keyword If     '${context}'!=''       Set To Dictionary   ${headers}   Link=<${context}>; rel="http://www.w3.org/ns/json-ld#context";type="application/ld+json"
    Run Keyword If     '${context}'!=''       Set To Dictionary   ${headers}   Link=<${context}>; rel="http://www.w3.org/ns/json-ld#context";type=${accept}
    ${response}=  GET  ${ENTITIES_ENDPOINT_PATH}${id}  headers=${headers}
    Output  request
    Output  response
    [return]    ${response}

Query Entity
    [Arguments]  ${id}     ${accept}    ${attrs}=${EMPTY}      ${context}=${EMPTY}
    ${attrs_length} =  Get Length  ${attrs}
    &{headers}=  Create Dictionary
    &{params}=  Create Dictionary
    Set To Dictionary   ${headers}   Accept    ${accept}
    Run Keyword If     '${context}'!=''       Set To Dictionary   ${headers}    Link=<${context}>; rel="http://www.w3.org/ns/json-ld#context";type=${accept}
    Run Keyword If     ${attrs_length}>0       Set To Dictionary   ${params}       attrs=${attrs}

    ${response}=  GET  ${ENTITIES_ENDPOINT_PATH}${id}      headers=${headers}      query=${params}
    Output  request
    Output  response
    [return]    ${response}

Retrieve Entity by Id
    [Arguments]  ${id}      ${accept}=${CONTENT_TYPE_LD_JSON}     ${context}=${EMPTY}
    ${headers}=  Create Dictionary
@@ -88,12 +102,10 @@ Create Entity Selecting Content Type
    [Arguments]  ${filename}    ${entity_id}    ${content_type}
    ${entity_payload}=    Load Json From File    ${EXECDIR}/data/entities/${filename}
    ${entity}=    Update Value To Json    ${entity_payload}     $..id   ${entity_id}

    &{headers}=  Create Dictionary  Content-Type=${content_type}
    ${response}=  POST  ${ENTITIES_ENDPOINT_PATH}  body=${entity}  headers=${headers}
    Output  request
    Output  response
    ${request}=    Output  request
    Output  response
    [return]    ${request}    ${response}

Create Entity
Loading