Shorten vnf and vf names
[testsuite.git] / robot / resources / mr_interface.robot
1 *** Settings ***
2 Documentation     The main interface for interacting with Message router. It handles low level stuff like managing the http request library and message router required fields
3 Library           RequestsClientCert
4 Library               RequestsLibrary
5 Library           UUID
6
7 Resource          global_properties.robot
8
9 *** Variables ***
10 ${MR_HEALTH_CHECK_PATH}        /topics
11 ${MR_PUB_HEALTH_CHECK_PATH}        /events/TEST_TOPIC
12 ${MR_SUB_HEALTH_CHECK_PATH}        /events/TEST_TOPIC/g1/c4?timeout=5000
13 ${MR_ENDPOINT}     ${GLOBAL_MR_SERVER_PROTOCOL}://${GLOBAL_INJECTED_MR_IP_ADDR}:${GLOBAL_MR_SERVER_PORT}
14 ${MR_PUBLISH_TEMPLATE}     robot/assets/templates/mr_publish.template
15
16
17 *** Keywords ***
18 Run MR Health Check
19      [Documentation]    Runs MR Health check
20      ${resp}=    Run MR Get Request    ${MR_HEALTH_CHECK_PATH}
21      Should Be Equal As Strings        ${resp.status_code}     200
22      Should Contain    ${resp.json()}    topics
23
24 Run MR PubSub Health Check
25      [Documentation]    Runs MR PubSub Health check
26      #${resp}=    Run MR Get Request    ${MR_SUB_HEALTH_CHECK_PATH}
27      # topic may not be created which is a 400 error
28
29      ${resp}=    Run MR Post Request    ${MR_PUB_HEALTH_CHECK_PATH}
30      Should Be Equal As Strings         ${resp.status_code}     200
31      Should Contain    ${resp.json()}    serverTimeMs    Failed to Write Data
32      ${resp}=    Run MR Get Request    ${MR_SUB_HEALTH_CHECK_PATH}
33      # Always Write twice to catch lost first message
34      ${resp}=    Run MR Post Request    ${MR_PUB_HEALTH_CHECK_PATH}
35      ${resp}=    Run MR Get Request    ${MR_SUB_HEALTH_CHECK_PATH}
36      # ${resp} is an array
37      Should Be Equal As Strings         ${resp.status_code}     200
38      Should Contain    ${resp.json()[0]}    timestamp    Failed to Read Data
39
40 Run MR Get Request
41      [Documentation]    Runs MR Get request
42      [Arguments]    ${data_path}
43      ${session}=    Create Session      mr      ${MR_ENDPOINT}
44      ${uuid}=    Generate UUID
45      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
46      ${resp}=   Get Request     mr      ${data_path}     headers=${headers}
47      Log    Received response from message router ${resp.text}
48      [Return]    ${resp}
49
50 Run MR Post Request
51      [Documentation]    Runs MR Post request
52      [Arguments]    ${data_path}
53      ${session}=    Create Session      mr      ${MR_ENDPOINT}
54      ${timestamp}=   Get Current Date
55      ${dict}=    Create Dictionary    timestamp=${timestamp}
56      ${data}=   Fill JSON Template File    ${MR_PUBLISH_TEMPLATE}    ${dict}
57      ${uuid}=    Generate UUID
58      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
59      ${resp}=   Post Request    mr      ${data_path}     data=${data}    headers=${headers}
60      Log    Received response from message router ${resp.text}
61      [Return]    ${resp}
62