8c4d8e23ed1568cfddcb782b29a97f1557e67360
[integration/csit.git] / tests / dcaegen2-services-slice-analysis-ms / testcases / slice-analysis-ms-test-cps-aai.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 ${SLICE_ANALYSIS_MS_BASE_URL}             http://${SLICE_ANALYSIS_MS_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_ML_NOTIF_URL}      http://${DMAAP_IP}:3904/events/unauthenticated.ML_RESPONSE_TOPIC
16 ${POST_DMAAP_EVENT_FOR_PM_NOTIF_URL}      http://${DMAAP_IP}:3904/events/unauthenticated.PERFORMANCE_MEASUREMENTS
17
18
19 *** Test Cases ***
20
21 HealthCheck
22
23         Create Session  sliceanalysisms  ${SLICE_ANALYSIS_MS_BASE_URL}
24         ${resp}=  Get Request   sliceanalysisms   ${HEALTHCHECK_ENDPOINT}
25         Should Be Equal As Strings  ${resp.status_code}  200
26
27
28 Post ml notification to dmaap
29         Create Session  dmaap  ${DMAAP_URL}
30         ${headers}=    Create Dictionary    Content-Type    application/json
31         ${data}=   Get File      ${TEST_ROBOT_DIR}/data/ml_response0.json
32         ${response}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_ML_NOTIF_URL}', data=$data)
33         Should Be Equal As Strings  ${response.status_code}  200
34
35
36 Verify ml notification trigger
37         Create Session  dmaap  ${DMAAP_URL}
38         FOR    ${i}    IN RANGE   30
39                 ${result}=  Get Request  dmaap   ${unauthenticated.DCAE_CL_OUTPUT}
40                 Exit For Loop If    ${result.json()} != @{EMPTY}
41                 Log     Waiting for slice-analysis-ms to handle trigger...         console=${True}
42                 Sleep   5s
43         END
44
45         ${expected_string}=   Get File            ${TEST_ROBOT_DIR}/data/expected_ml_payload0.json
46         ${expected_payload}=    Evaluate     json.loads("""${expected_string}""")     json
47         ${result}=  Convert To String  ${result.content}
48         ${result_string}=    Get Substring    ${result}  2    -2
49         ${actual_data}=      Evaluate     json.loads("""${result_string}""")     json
50         ${actual_payload_str}=    Set Variable     ${actual_data['payload']}
51         ${actual_payload}=       Evaluate     json.loads("""${actual_payload_str}""")     json
52
53 Post pm notification-1 to dmaap
54         ${data}=   Get File      ${TEST_ROBOT_DIR}/data/performance_notification0.json
55         FOR    ${j}    IN RANGE   6
56                 ${response}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_PM_NOTIF_URL}', data=$data)
57                 Sleep   10s
58         END
59         Should Be Equal As Strings  ${response.status_code}  200
60
61
62 Verify pm notification-1 trigger
63         Create Session  dmaap  ${DMAAP_URL}
64         FOR    ${i}    IN RANGE   20
65                 ${result}=  Get Request  dmaap   ${unauthenticated.DCAE_CL_OUTPUT}
66                 Exit For Loop If    ${result.json()} != @{EMPTY}
67                 Log     Waiting for sliceanalysisms to handle trigger...         console=${True}
68                 Sleep   30s
69         END
70         ${expected_string}=   Get File            ${TEST_ROBOT_DIR}/data/expected_payload_pm0.json
71         ${expected_payload}=    Evaluate     json.loads("""${expected_string}""")     json
72         ${result}=  Convert To String  ${result.content}
73         ${result_string}=    Get Substring    ${result}  2    -2
74         ${actual_data}=      Evaluate     json.loads("""${result_string}""")     json
75         ${actual_payload_str}=    Set Variable     ${actual_data['payload']}
76         ${actual_payload}=       Evaluate     json.loads("""${actual_payload_str}""")     json
77         set to dictionary    ${expected_payload['additionalProperties']['nsiInfo']}   nsiId=${actual_payload['additionalProperties']['nsiInfo']['nsiId']}
78         Should Be True   """${actual_payload}""".strip() == """${expected_payload}""".strip()