[DCAEGEN2] Update son-handler CSIT with CPS
[integration/csit.git] / tests / dcaegen2-services-son-handler / testcases / son-handler-test-cps.robot
1 *** Settings ***
2 Library           Collections
3 Library           Process
4 Library           RequestsLibrary
5 Library           String
6 Library           OperatingSystem
7
8 Suite Teardown  Delete All Sessions
9
10 *** Variables ***
11 ${SON_HANDLER_BASE_URL}                   http://${SONHMS_IP}:8080
12 ${HEALTHCHECK_ENDPOINT}                   /healthcheck
13 ${DMAAP_URL}                              http://${DMAAP_IP}:3904/events
14 ${unauthenticated.DCAE_CL_OUTPUT}         /unauthenticated.DCAE_CL_OUTPUT/23/23
15 ${POST_DMAAP_EVENT_FOR_FM_NOTIF_URL}      http://${DMAAP_IP}:3904/events/unauthenticated.SEC_FAULT_OUTPUT
16 ${POST_DMAAP_EVENT_FOR_PM_NOTIF_URL}      http://${DMAAP_IP}:3904/events/unauthenticated.VES_MEASUREMENT_OUTPUT
17 ${POST_DMAAP_EVENT_FOR_POLICY_RESPONSE}   http://${DMAAP_IP}:3904/events/DCAE_CL_RSP
18
19
20 *** Test Cases ***
21
22 HealthCheck
23
24         Create Session  sonhms  ${SON_HANDLER_BASE_URL}
25         ${resp}=  Get Request   sonhms  ${HEALTHCHECK_ENDPOINT}
26         Should Be Equal As Strings  ${resp.status_code}  200
27
28
29 Post fm notification to dmaap
30         Create Session  dmaap  ${DMAAP_URL}
31         ${headers}=    Create Dictionary    Content-Type    application/json
32         ${data}=   Get File      ${TEST_ROBOT_DIR}/data/cps_fault_notification.json
33         ${response}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_FM_NOTIF_URL}', data=$data)
34         Should Be Equal As Strings  ${response.status_code}  200
35
36
37 Verify fm notification trigger in sonhms
38         Create Session  dmaap  ${DMAAP_URL}
39         FOR    ${i}    IN RANGE   10
40                 ${result}=  Get Request  dmaap   ${unauthenticated.DCAE_CL_OUTPUT}
41                 Exit For Loop If    ${result.json()} != @{EMPTY}
42                 Log     Waiting for sonhms to handle trigger...         console=${True}
43                 Sleep   30s
44         END
45         ${expected_payload}=   Get File            ${TEST_ROBOT_DIR}/data/cps_expected_payload_fm.json
46         ${result}=  Convert To String  ${result.content}
47         ${result_string}=    Get Substring    ${result}    2    -2
48         ${actual_data}=    Evaluate     json.loads("""${result_string}""")    json
49         ${actual_payload}=    Set Variable     ${actual_data['payload']}
50         Should Be True   """${actual_payload}""".strip() == """${expected_payload}""".strip()
51
52
53 Post pm notification to dmaap
54         ${data}=   Get File      ${TEST_ROBOT_DIR}/data/performance_notification.json
55         ${response}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_PM_NOTIF_URL}', data=$data)
56         Should Be Equal As Strings  ${response.status_code}  200
57
58
59 Verify pm notification trigger in sonhms
60         Create Session  dmaap  ${DMAAP_URL}
61         FOR    ${i}    IN RANGE   5
62                 ${result}=  Get Request  dmaap   ${unauthenticated.DCAE_CL_OUTPUT}
63                 Exit For Loop If    ${result.json()} != @{EMPTY}
64                 Log     Waiting for sonhms to handle trigger...         console=${True}
65                 Sleep   30s
66         END
67         ${expected_payload}=   Get File            ${TEST_ROBOT_DIR}/data/cps_expected_payload_pm.json
68         ${result}=  Convert To String  ${result.content}
69         ${result_string}=    Get Substring    ${result}    2    -2
70         ${actual_data}=    Evaluate     json.loads("""${result_string}""")    json
71         ${actual_payload}=    Set Variable     ${actual_data['payload']}
72         Should Be True   """${actual_payload}""".strip() == """${expected_payload}""".strip()
73
74
75 Post policy negative acknowledgement to dmaap
76         ${data}=   Get File      ${TEST_ROBOT_DIR}/data/negative_ack_from_policy.json
77         FOR    ${i}    IN RANGE   3
78            ${response}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_POLICY_RESPONSE}', data=$data)
79         END
80         Should Be Equal As Strings  ${response.status_code}  200
81
82
83 Oof trigger for fixed Pci cells
84
85         Create Session  dmaap  ${DMAAP_URL}
86         ${headers}=    Create Dictionary    Content-Type    application/json
87         ${data}=   Get File      ${TEST_ROBOT_DIR}/data/cps_fault_notification.json
88         ${response}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_FM_NOTIF_URL}', data=$data)
89
90         Create Session  dmaap  ${DMAAP_URL}
91         FOR    ${i}    IN RANGE   15
92                 ${result}=  Get Request  dmaap   ${unauthenticated.DCAE_CL_OUTPUT}
93                 Exit For Loop If    ${result.json()} != @{EMPTY}
94                 Log     Waiting for sonhms to handle trigger...         console=${True}
95                 Sleep   30s
96         END
97         ${expected_payload}=   Get File    ${TEST_ROBOT_DIR}/data/cps_expected_payload_fm.json
98         ${result}=  Convert To String  ${result.content}
99         ${result_string}=    Get Substring    ${result}    2    -2
100         ${actual_data}=    Evaluate     json.loads("""${result_string}""")    json
101         ${actual_payload}=    Set Variable     ${actual_data['payload']}
102         Should Be True   """${actual_payload}""".strip() == """${expected_payload}""".strip()