*** Settings ***
Documentation     Test suite for EPC Creation
Suite Setup       Read InputFile
Test Template     Verify EPC Instance Functionality
Library           Collections
Library           String
Library           OperatingSystem
Library           XML
Library           RequestsLibrary
Library           CORDRobot
Library           ImportResource  resources=CORDRobot
Library           MCORD_RestApiProperties.py

*** Variables ***
${USER}           admin
${PASSWORD}       admin
${PATHFILE}       ${CURDIR}/data/EPCInstance.json

*** Test Cases ***    TYPE                 LISTINDEX
Test Create EPC       EPC_CREATE           0

Test Instance Validation
                      INSTANCE_VALIDATE    0

*** Keywords ***
Read InputFile
    ${EPCList} =    CORDRobot.jsonToList    ${PATHFILE}    EPCInfo
    Set Suite Variable    ${elist}    ${EPCList}
    @{vepc_instanceList}=    Create List    mysite_venb    mysite_vspgwc    mysite_vspgwu
    @{instanceList}=    Create List
    Set Suite Variable    @{instanceList}
    Set Suite Variable    @{vepc_instanceList}

Verify EPC Instance functionality
    [Arguments]    ${type}    ${listIndex}
    Run Keyword If    "${type}" == "EPC_CREATE"    Test Post EPC Create    ${listIndex}
    Run Keyword If    "${type}" == "INSTANCE_VALIDATE"    Test Instance Validation    ${listIndex}

Test Post EPC Create
    [Arguments]    ${listIndex}
    ${EPCList} =    Get Variable Value    ${elist}
    ${InputDict}=    CORDRobot.listToDict    ${EPCList}    ${listIndex}
    ${api_result}=    CORDRobot.ApiPost    EPC_INSTANCES    ${InputDict}
    ${site_id}=    CORDRobot.getFieldValueFromDict    ${InputDict}    site_id
    ${json_result}=    CORDRobot.ApiGet    EPC_INSTANCES
    Log    ${json_result}
    ${json_result_list}=    Get From Dictionary    ${json_result}    items
    ${getJsonDict}=    CORDRobot.getDictFromListOfDict    ${json_result_list}    site_id    ${site_id}
    ${result}=    CORDRobot.compare_dict    ${InputDict}    ${getJsonDict}
    Should Be True    ${result}
    Sleep    30s

Test Instance Validation
    [Arguments]    ${listIndex}
    ${get_result}=    CORDRobot.ApiGet    CORE_INSTANCES
    Should Be True    ${get_result}
    ${get_result_List}=    Get From Dictionary    ${get_result}    items
    : FOR    ${Item}    IN    @{get_result_List}
    \    ${instance_name}=    Get From Dictionary    ${Item}    name
    \    Append To List    ${instanceList}    ${instance_name}
    Log    ${instanceList}
    Sort List    ${instanceList}
    Lists Should Be Equal    ${instanceList}    ${vepc_instanceList}
