Commit 2ad92d1e authored by Marco Cavalli's avatar Marco Cavalli
Browse files

feat: adds expectation files for test 003 01 01, also fix test logic and...

feat: adds expectation files for test 003 01 01, also fix test logic and remove redundant query operations
parent 1c5ac09a
Loading
Loading
Loading
Loading
+18 −38
Original line number Diff line number Diff line
@@ -11,8 +11,10 @@ Test Teardown Delete Entities and Delete Registrations
${first_entity_payload_filename}               interoperability/offstreet-parking1-full.jsonld
${second_entity_payload_filename}              interoperability/offstreet-parking2-full.jsonld
${third_entity_payload_filename}               interoperability/offstreet-parking2-no-location-and-totalspotsnumber.jsonld
${inclusive_registration_payload_file_path}    csourceRegistrations/interoperability/context-source-registration-inclusive-2.jsonld
${exclusive_registration_payload_file_path}    csourceRegistrations/interoperability/context-source-registration-exclusive-2.jsonld
${inclusive_registration_payload_file_path}    csourceRegistrations/interoperability/context-source-registration-inclusive-1.jsonld
${exclusive_registration_payload_file_path}    csourceRegistrations/interoperability/context-source-registration-exclusive-1.jsonld
${first_expected_payload_file_path}            interoperability/query-entity-IOP-003-01-01-first.json
${second_expected_payload_file_path}           interoperability/query-entity-IOP-003-01-01-second.json
${broker_A_url}
${broker_B_url}
${broker_C_url}
@@ -24,38 +26,24 @@ IOP_003_01_01 Query Entities Of Type OffstreetParking Via GET
    [Tags]    since_v1.6.1    iop    cnf_01    4_3_3    additive-inclusive    proxy-exclusive    4_3_6    5_7_2    6_4_3_1

    #Agent queries all entities with type OffStreetParking in A and checks for a successful response that contains the attributes of both entities in B and C.
    ${response}=    Query Entities    entity_types=OffStreetParking    broker_url=${broker_A_url}    context=${ngsild_test_suite_context}
    Check Response Status Code    200    ${response.status_code}
    Should Contain    ${response.json()}    availableSpotsNumber
    Should Contain    ${response.json()}    totalSpotsNumber
    Should Contain    ${response.json()}    availableSpotsNumber
    Should Contain    ${response.json()}    location
    ${response_a}=    Query Entities    entity_types=OffStreetParking    broker_url=${broker_A_url}    context=${ngsild_test_suite_context}
    Check Response Status Code    200    ${response_a.status_code}

    #Agent queries all entities with type OffStreetParking in B and C
    ${response}=    Query Entities    entity_types=OffStreetParking    broker_url=${broker_B_url}    context=${ngsild_test_suite_context}
    @{first_expected_payload}=    Set Variable    ${response.json()}
    ${entity_ids}=    Create List    ${entity_id}    ${second_entity_id}
    Check Response Body Containing Entities URIS set to    ${entity_ids}    ${response.json()}

    ${response}=    Query Entities    entity_types=OffStreetParking    broker_url=${broker_C_url}    context=${ngsild_test_suite_context}
    @{second_expected_payload}=    Set Variable    ${response.json()}
    Check Response Body Containing Entities URIS set to    ${entity_id}    ${response.json()}
    ${entity_ids}=    Create List    ${first_entity_id}    ${second_entity_id}
    Check Response Body Containing Entities URIS set to    ${entity_ids}    ${response_a.json()}

    #Agent checks that OffStreetParking:1 in A is the same as the one in B and that OffStreetParking:2 in A contains the attributes of both OffStreetParking:2 in B and C.
    Should Be Equal    ${response.json()}    ${first_expected_payload}
    Should Contain    ${response.json()}    ${second_expected_payload}
    Check Response Body Containing Entity element by id    ${first_expected_payload_file_path}    ${first_entity_id}    ${response_a.json()}
    Check Response Body Containing Entity element by id    ${second_expected_payload_file_path}    ${second_entity_id}    ${response_a.json()}

*** Keywords ***
Setup Initial Context Source Registrations

    ${entity_id}=    Generate Random Parking Entity Id
    Set Suite Variable    ${entity_id}
    ${second_entity_id}=    Generate Random Parking Entity Id
    Set Suite Variable    ${second_entity_id}
    Set Test Variable    ${first_entity_id}    urn:ngsi-ld:OffStreetParking:1
    Set Test Variable    ${second_entity_id}    urn:ngsi-ld:OffStreetParking:2

    ${response}=    Create Entity
    ...    ${first_entity_payload_filename}
    ...    ${entity_id}
    ...    ${first_entity_id}
    ...    broker_url=${broker_B_url}
    Check Response Status Code    201    ${response.status_code}

@@ -67,12 +55,12 @@ Setup Initial Context Source Registrations

    ${response}=    Create Entity
    ...    ${second_entity_payload_filename}
    ...    ${entity_id}
    ...    ${second_entity_id}
    ...    broker_url=${broker_C_url}
    Check Response Status Code    201    ${response.status_code}

    @{first_set}=    Create List
    ...    ${entity_id}
    ...    ${EMPTY}
    ...    ${inclusive_registration_payload_file_path}
    ...    inclusive
    ...    ${broker_B_url}
@@ -80,25 +68,17 @@ Setup Initial Context Source Registrations

    @{second_set}=    Create List
    ...    ${second_entity_id}
    ...    ${inclusive_registration_payload_file_path}
    ...    inclusive
    ...    ${broker_B_url}
    ...    ${broker_A_url}

    @{third_set}=    Create List
    ...    ${entity_id}
    ...    ${exclusive_registration_payload_file_path}
    ...    exclusive
    ...    ${broker_C_url}
    ...    ${broker_A_url}

    @{first_configuration}=    Create List    ${first_set}    ${second_set}    ${third_set}
    @{first_configuration}=    Create List    ${first_set}    ${second_set}
    Compose IOP Configuration    ${first_configuration}

Delete Entities And Delete Registrations
    Delete Context Source Registration With Return    ${registration_id1}    broker_url=${broker_A_url}
    Delete Context Source Registration With Return    ${registration_id2}    broker_url=${broker_A_url}
    Delete Context Source Registration With Return    ${registration_id3}    broker_url=${broker_A_url}
    Delete Entity    ${entity_id}    broker_url=${broker_B_url}
    Delete Entity    ${first_entity_id}    broker_url=${broker_B_url}
    Delete Entity    ${second_entity_id}    broker_url=${broker_B_url}
    Delete Entity    ${entity_id}    broker_url=${broker_C_url}
 No newline at end of file
    Delete Entity    ${second_entity_id}    broker_url=${broker_C_url}
 No newline at end of file
+4 −2
Original line number Diff line number Diff line
@@ -5,11 +5,13 @@
    {
      "entities": [
        {
          "id": "urn:ngsi-ld:OffStreetParking:2"
          "id": "urn:ngsi-ld:OffStreetParking:2",
          "type": "OffStreetParking"
        }
      ],
      "propertyNames": [
        "totalSpotsNumber"		
        "totalSpotsNumber",
        "availableSpotsNumber"	
      ]
    }
  ],
+28 −0
Original line number Diff line number Diff line
{
  "id": "urn:ngsi-ld:OffStreetParking:1",
  "type": "OffStreetParking",
  "name": {
    "type": "Property",
    "value": "Downtown One"
  },
  "availableSpotsNumber": {
    "type": "Property",
    "value": 121,
    "observedAt": "2017-07-29T12:05:02Z",
    "reliability": {
      "type": "Property",
      "value": 0.7
    }
  },
  "totalSpotsNumber": {
    "type": "Property",
    "value": 200
  },
  "location": {
    "type": "GeoProperty",
    "value": {
      "type": "Point",
      "coordinates": [-8.5, 41.2]
    }
  }
}
+21 −0
Original line number Diff line number Diff line
{
  "id": "urn:ngsi-ld:OffStreetParking:2",
  "type": "OffStreetParking",
  "name": {
    "type": "Property",
    "value": "Downtown Two"
  },
  "availableSpotsNumber": {
    "type": "Property",
    "value": 92,
    "observedAt": "2017-07-30T12:10:02Z",
    "reliability": {
      "type": "Property",
      "value": 0.56
    }
  },
  "totalSpotsNumber": {
    "type": "Property",
    "value": 150
  }
}
+19 −0
Original line number Diff line number Diff line
@@ -173,6 +173,25 @@ Check Response Body Containing Entity element
    ...    ${ignore_core_context_version}
    Should Be Empty    ${comparison_result}    msg=${comparison_result.pretty()}

Check Response Body Containing Entity element by id
    [Arguments]    ${expectation_filename}    ${entity_id}    ${response_body}    ${ignore_core_context_version}=False
    ${entity_payload}=    Load JSON From File    ${EXECDIR}/data/entities/expectations/${expectation_filename}
    IF    isinstance($response_body, list)
        ${filtered_response_body}=    Evaluate    next((entity for entity in $response_body if entity["id"] == "${entity_id}"), None)
        IF    $filtered_response_body is None
            Fail    Entity with id ${entity_id} not found in response body
        END
    ELSE
        Should Be Equal    ${response_body}[id]    ${entity_id}
        ${filtered_response_body}=    Set Variable    ${response_body}
    END

    Check Response Body Containing Entity element
    ...    ${expectation_filename}
    ...    ${entity_id}
    ...    ${filtered_response_body}
    ...    ${ignore_core_context_version}

Check Response Body Containing List Containing Entity Elements
    [Arguments]
    ...    ${expectation_filename}