Add CSIT for slice-analysis-ms
[integration/csit.git] / tests / dcaegen2-services-slice-analysis-ms / testcases / slice-analysis-ms-test.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_response.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_payload.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         set to dictionary    ${expected_payload['additionalProperties']['nsiInfo']}   nsiId=${actual_payload['additionalProperties']['nsiInfo']['nsiId']}   
53         Should Be True   """${actual_payload}""".strip() == """${expected_payload}""".strip()
54
55
56 Post pm notification-1 to dmaap
57         ${data}=   Get File      ${TEST_ROBOT_DIR}/data/performance_notification1.json
58         FOR    ${j}    IN RANGE   6
59                 ${response}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_PM_NOTIF_URL}', data=$data)
60                 Sleep   10s
61         END
62         Should Be Equal As Strings  ${response.status_code}  200
63
64
65 Verify pm notification-1 trigger 
66         Create Session  dmaap  ${DMAAP_URL}
67         FOR    ${i}    IN RANGE   20
68                 ${result}=  Get Request  dmaap   ${unauthenticated.DCAE_CL_OUTPUT}
69                 Exit For Loop If    ${result.json()} != @{EMPTY}
70                 Log     Waiting for sliceanalysisms to handle trigger...         console=${True}
71                 Sleep   30s
72         END
73         ${expected_string}=   Get File            ${TEST_ROBOT_DIR}/data/expected_payload_pm1.json
74         ${expected_payload}=    Evaluate     json.loads("""${expected_string}""")     json
75         ${result}=  Convert To String  ${result.content}
76         ${result_string}=    Get Substring    ${result}  2    -2
77         ${actual_data}=      Evaluate     json.loads("""${result_string}""")     json
78         ${actual_payload_str}=    Set Variable     ${actual_data['payload']}
79         ${actual_payload}=       Evaluate     json.loads("""${actual_payload_str}""")     json
80         set to dictionary    ${expected_payload['additionalProperties']['nsiInfo']}   nsiId=${actual_payload['additionalProperties']['nsiInfo']['nsiId']}
81         Should Be True   """${actual_payload}""".strip() == """${expected_payload}""".strip()
82
83
84
85 Post pm notification-2 to dmaap
86         ${data}=   Get File      ${TEST_ROBOT_DIR}/data/performance_notification3.json
87         ${data1}=   Get File      ${TEST_ROBOT_DIR}/data/performance_notification4.json
88         ${data2}=   Get File      ${TEST_ROBOT_DIR}/data/performance_notification5.json
89         ${data3}=   Get File      ${TEST_ROBOT_DIR}/data/performance_notification6.json
90         ${data4}=   Get File      ${TEST_ROBOT_DIR}/data/performance_notification7.json
91         ${data5}=   Get File      ${TEST_ROBOT_DIR}/data/performance_notification8.json
92         FOR    ${i}    IN RANGE   6
93                 ${response}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_PM_NOTIF_URL}', data=$data)
94                 ${response1}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_PM_NOTIF_URL}', data=$data1)
95                 ${response2}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_PM_NOTIF_URL}', data=$data2)
96                 ${response3}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_PM_NOTIF_URL}', data=$data3)
97                 ${response4}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_PM_NOTIF_URL}', data=$data4)
98                 ${response5}=    Evaluate    requests.post('${POST_DMAAP_EVENT_FOR_PM_NOTIF_URL}', data=$data5)
99         END
100         Should Be Equal As Strings  ${response.status_code}  200
101         Should Be Equal As Strings  ${response1.status_code}  200
102         Should Be Equal As Strings  ${response2.status_code}  200
103         Should Be Equal As Strings  ${response3.status_code}  200
104         Should Be Equal As Strings  ${response4.status_code}  200
105         Should Be Equal As Strings  ${response5.status_code}  200
106
107
108 Verify pm notification-2 trigger
109         Create Session  dmaap  ${DMAAP_URL}
110         FOR    ${i}    IN RANGE   20
111                 ${result}=  Get Request  dmaap   ${unauthenticated.DCAE_CL_OUTPUT}
112                 Exit For Loop If    ${result.json()} != @{EMPTY}
113                 Log     Waiting for sliceanalysisms to handle trigger...         console=${True}
114                 Sleep   30s
115         END
116         ${expected_string}=   Get File            ${TEST_ROBOT_DIR}/data/expected_payload_pm2.json
117         ${expected_payload}=    Evaluate     json.loads("""${expected_string}""")     json
118         ${result}=  Convert To String  ${result.content}
119         ${result_string}=    Get Substring    ${result}  2    -2
120         ${actual_data}=      Evaluate     json.loads("""${result_string}""")     json
121         ${actual_payload_str}=    Set Variable     ${actual_data['payload']}
122         ${actual_payload}=       Evaluate     json.loads("""${actual_payload_str}""")     json
123         set to dictionary    ${expected_payload['additionalProperties']['nsiInfo']}   nsiId=${actual_payload['additionalProperties']['nsiInfo']['nsiId']}
124         Should Be True   """${actual_payload}""".strip() == """${expected_payload}""".strip()