Commit ef6dd4d1 authored by lopezaguilar's avatar lopezaguilar
Browse files

Check the increase of numberOfHits with Cached @contexts

parent 79046d69
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that you can get an increase numberOfHits after creation of a @context and using it
Documentation       Check that you can get an increase numberOfHits after creation of a Hosted @context and using it

Resource            ${EXECDIR}/resources/ApiUtils/JSON-LD@ContextServer.resource
Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource
@@ -16,17 +16,10 @@ ${entity_context_id}= urn:ngsi-ld:Building:randomUUID


*** Test Cases ***
053_04_01 Check that the numberOfHits is increased after using a context
    [Documentation]    Check that you can delete a hosted @context
053_04_01 Check that the numberOfHits is increased after using a Hosted context
    [Documentation]    Check that the numberOfHits is increased after using a Hosted context
    [Tags]    ctx-serve    5_13_5

    ${response}=    Serve a @context
    ...    contextId=${uri}
    ...    details=true

    Check Response Status Code    200    ${response.status_code}
    Check Context Response Body Containing numberOfHits value    ${response.json()}    1

    Create Entity selecting @context    ${entityfile}    ${uri}

    ${response}=    Serve a @context
@@ -44,6 +37,13 @@ Create Initial @context condition
    ${uri}=    Fetch Id From Response Location Header    ${response.headers}
    Set Suite Variable    ${uri}

    ${response}=    Serve a @context
    ...    contextId=${uri}
    ...    details=true

    Check Response Status Code    200    ${response.status_code}
    Check Context Response Body Containing numberOfHits value    ${response.json()}    1

Delete Initial @context condition
    Delete Entity by Id    ${entity_context_id}
    Delete a @context    ${uri}
+76 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that the context served by a context server is still in the broker after a ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE with details=true

Resource            ${EXECDIR}/resources/ApiUtils/JSON-LD@ContextServer.resource
Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource
Resource            ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource
Resource            ${EXECDIR}/resources/HttpUtils.resource
Resource            ${EXECDIR}/resources/ContextServerUtils.resource
Library             Collections
Library             String
Variables           ${EXECDIR}/resources/variables.py
Library             HttpCtrl.Client
Library             HttpCtrl.Server

Test Setup          Create Initial @context condition
Test Teardown       Delete Initial @context condition


*** Variables ***
${filename}=                @context-minimal-valid.json
${entityfile}=              minimal-entity-using-@context.jsonld
${entity_context_id}=       urn:ngsi-ld:Testing:randomUUID
${uri}                      /api/v1/context.jsonld
${reason_200}=              OK


*** Test Cases ***
053_05_01 Check that the context served by a context server is still in the broker after a ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE with details=true
    [Documentation]    Check that the context served by a context server is still in the broker after a ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE with details=true
    [Tags]    ctx-serve    5_13_5

    ${response}=    Serve a @context
    ...    contextId=${uri}
    ...    details=true

    Check Response Status Code    200    ${response.status_code}
    Check Response Reason set to    ${response.reason}    ${reason_200}
    Check Response Headers Containing Content-Type set to    ${CONTENT_TYPE_JSON}    ${response.headers}

    # Check mandatory keys in the response (URL, localId, kind, timestamp) and their possible values
    Check Context Response Body Containing Detailed Information    ${response.json()}    Cached

    # Check optional keys in the response (lastUsage, numberOfHits, extraInfo) and their possible values
    Check Dictionary Might Contain Additional Members    ${response.json()}    lastUsage
    Check Dictionary Might Contain Additional Members    ${response.json()}    numberOfHits

    # Check that there is no other keys
    Check Context Detailed Information Keys    ${response.json()}


*** Keywords ***
Create Initial @context condition
    Start @context Local Server

    ${uri}=    Catenate    http://${context_source_host}:${context_source_port}${uri}
    Set Global Variable    ${uri}

    Create Entity selecting @context    ${entityfile}    ${uri}

    Log    Waiting 3 seconds to continue...
    Sleep    3s

    ${response}=    Serve a @context    ${uri}    true
    Check Response Status Code    200    ${response.status_code}
    Check Context Response Kind    ${response.json()}    Cached

    Stop @context Local Server

    ${response}=    Delete a @context    ${uri}    true
    Check Response Status Code    503    ${response.status_code}

Delete Initial @context condition
    Log    Delete initial contidions
    Delete Entity by Id    ${entity_context_id}
    Delete a @context    ${uri}
+69 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that the context served by a context server is still in the broker after a ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE with details=true

Resource            ${EXECDIR}/resources/ApiUtils/JSON-LD@ContextServer.resource
Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource
Resource            ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource
Resource            ${EXECDIR}/resources/HttpUtils.resource
Resource            ${EXECDIR}/resources/ContextServerUtils.resource
Library             Collections
Library             String
Variables           ${EXECDIR}/resources/variables.py
Library             HttpCtrl.Client
Library             HttpCtrl.Server

Test Setup          Create Initial @context condition
Test Teardown       Delete Initial @context condition


*** Variables ***
${filename}=                @context-minimal-valid.json
${entityfile}=              minimal-entity-using-@context.jsonld
${uri}                      /api/v1/context.jsonld
${reason_200}=              OK
${testing_id_prefix}=       urn:ngsi-ld:Testing:


*** Test Cases ***
053_06_01 Check that the numberOfHits is increased after using a Cached context
    [Documentation]    Check that the numberOfHits is increased after using a Cached context
    [Tags]    ctx-serve    5_13_5

    ${second_existing_entity_id}=    Generate Random Entity Id    ${testing_id_prefix}
    Set Global Variable    ${first_existing_entity_id}

    Create Entity selecting @context    ${entityfile}    ${uri}    ${second_existing_entity_id}

    ${response}=    Serve a @context
    ...    contextId=${uri}
    ...    details=true

    Check Response Status Code    200    ${response.status_code}
    Check Context Response Body Containing numberOfHits value    ${response.json()}    2


*** Keywords ***
Create Initial @context condition
    Start @context Local Server

    ${first_existing_entity_id}=    Generate Random Entity Id    ${testing_id_prefix}
    Set Global Variable    ${first_existing_entity_id}

    ${uri}=    Catenate    http://${context_source_host}:${context_source_port}${uri}
    Set Global Variable    ${uri}

    Create Entity selecting @context    ${entityfile}    ${uri}    ${first_existing_entity_id}

    ${response}=    Serve a @context
    ...    contextId=${uri}
    ...    details=true

    Check Response Status Code    200    ${response.status_code}
    Check Context Response Body Containing numberOfHits value    ${response.json()}    1

Delete Initial @context condition
    Log    Delete initial contidions
    Delete Entity by Id    ${first_existing_entity_id}
    Delete a @context    ${uri}
    Stop @context Local Server
+6 −1
Original line number Diff line number Diff line
@@ -147,9 +147,14 @@ Create Entity
    RETURN    ${response}

Create Entity selecting @context
    [Arguments]    ${filename}    ${context}
    [Arguments]    ${filename}    ${context}    ${entity_id}=${EMPTY}
    ${entity_payload}=    Load JSON From File    ${EXECDIR}/data/jsonldContext/${filename}
    ${entity}=    Update Value To JSON    ${entity_payload}    $..@context    ${context}

    IF    '${entity_id}'!=''
        ${entity}=    Update Value To JSON    ${entity}    $..id    ${entity_id}
    END

    &{headers}=    Create Dictionary    Content-Type=application/ld+json
    ${response}=    POST
    ...    url=${url}/${ENTITIES_ENDPOINT_PATH}