Refactor DMaaP simulator and add tests.
[integration/csit.git] / tests / dcaegen2 / testcases / resources / dcae_keywords.robot
index 89a8786..fb5fc1d 100644 (file)
@@ -1,13 +1,14 @@
 *** Settings ***
 Documentation     The main interface for interacting with DCAE. It handles low level stuff like managing the http request library and DCAE required fields
+Library                  robot_library.DcaeLibrary
+Library           robot_library.DmaapLibrary
+Library           robot_library.CertsLibrary
 Library              RequestsLibrary
-Library                  DcaeLibrary
 Library           OperatingSystem
 Library           Collections
-Library           CertsLibrary
-Variables         ../resources/DcaeVariables.py
+Variables         ./robot_library/DcaeVariables.py
 Resource          ../../../common.robot
-Resource          ../resources/dcae_properties.robot
+Resource          ./dcae_properties.robot
 
 *** Keywords ***
 Create sessions
@@ -18,23 +19,23 @@ Create sessions
     ${wrong_certs}=  Create List  ${VESC_WRONG_CERT}  ${VESC_WRONG_KEY}
     ${outdated_certs}=  Create List  ${VESC_OUTDATED_CERT}  ${VESC_OUTDATED_KEY}
     Create Session    dcae_vesc_url    ${VESC_URL}
-    Set Suite Variable    ${http_session}    dcae_vesc_url
+    Set Global Variable    ${http_session}    dcae_vesc_url
     Create Session    dcae_vesc_url_https    ${VESC_URL_HTTPS}  auth=${auth}  disable_warnings=1
-    Set Suite Variable    ${https_basic_auth_session}    dcae_vesc_url_https
+    Set Global Variable    ${https_basic_auth_session}    dcae_vesc_url_https
     Create Session  dcae_vesc_url_https_wrong_auth  ${VESC_URL_HTTPS}  auth=${wrong_auth}  disable_warnings=1
-    Set Suite Variable  ${https_wrong_auth_session}  dcae_vesc_url_https_wrong_auth
+    Set Global Variable  ${https_wrong_auth_session}  dcae_vesc_url_https_wrong_auth
     Create Client Cert Session  dcae_vesc_url_https_cert  ${VESC_URL_HTTPS}  client_certs=${certs}  disable_warnings=1
-    Set Suite Variable  ${https_valid_cert_session}  dcae_vesc_url_https_cert
+    Set Global Variable  ${https_valid_cert_session}  dcae_vesc_url_https_cert
     Create Client Cert Session  dcae_vesc_url_https_wrong_cert  ${VESC_URL_HTTPS}  client_certs=${wrong_certs}  disable_warnings=1  verify=${False}
-    Set Suite Variable  ${https_invalid_cert_session}  dcae_vesc_url_https_wrong_cert
+    Set Global Variable  ${https_invalid_cert_session}  dcae_vesc_url_https_wrong_cert
     Create Client Cert Session  dcae_vesc_url_https_outdated_cert  ${VESC_URL_HTTPS}  client_certs=${outdated_certs}  disable_warnings=1  verify=${False}
-    Set Suite Variable  ${https_outdated_cert_session}  dcae_vesc_url_https_outdated_cert
+    Set Global Variable  ${https_outdated_cert_session}  dcae_vesc_url_https_outdated_cert
     Create Session  dcae_vesc_url_https_wo_auth  ${VESC_URL_HTTPS}  disable_warnings=1
-    Set Suite Variable  ${https_no_cert_no_auth_session}  dcae_vesc_url_https_wo_auth
+    Set Global Variable  ${https_no_cert_no_auth_session}  dcae_vesc_url_https_wo_auth
 
 Create header
     ${headers}=    Create Dictionary    Content-Type=application/json
-    Set Suite Variable    ${suite_headers}    ${headers}
+    Set Global Variable    ${suite_headers}    ${headers}
 
 Get DCAE Nodes
     [Documentation]    Get DCAE Nodes from Consul Catalog
@@ -139,21 +140,30 @@ Publish Event To VES Collector With Put Method
     ${resp}=   Put Request     ${session}      ${evtpath}     data=${evtdata}   headers=${suite_headers}
     [Return]   ${resp}
 
+Send Request And Validate Response And Error Message
+    [Documentation]  Post singel event to passed url and validate received response code and content
+    [Arguments]  ${keyword}  ${session}  ${evtpath}  ${evtjson}  ${resp_code}  ${msg_content}
+    ${resp}=  Send Request And Validate Response  ${keyword}  ${session}  ${evtpath}  ${evtjson}  ${resp_code}
+    ${error_message}=  Set Variable  ${resp.json()['requestError']['ServiceException']['text']}
+    Should Be Equal As Strings  ${msg_content}  ${error_message}
+
 Send Request And Validate Response
     [Documentation]  Post singel event to passed url with passed data and validate received response
-    [Arguments]  ${keyword}  ${session}  ${evtpath}  ${evtjson}  ${resp_code}  ${msg_code}=None
+    [Arguments]  ${keyword}  ${session}  ${evtpath}  ${evtjson}  ${resp_code}  ${msg_code}=None  ${topic}=None
     ${evtdata}=  Get Data From File  ${evtjson}
     ${resp}=  Run Keyword  ${keyword}  ${session}  ${evtpath}  ${evtdata}
     Log    Receive HTTPS Status code ${resp.status_code}
     Should Be Equal As Strings         ${resp.status_code}     ${resp_code}
     ${isEmpty}=   Is Json Empty    ${resp}
     Run Keyword If   '${isEmpty}' == False   Log  ${resp.json()}
-    Run Keyword If  '${msg_code}' != 'None'  Check Whether Message Received  ${msg_code}
+    Run Keyword If  '${msg_code}' != 'None'  Check Whether Message Received  ${msg_code}  ${topic}
+    [Return]  ${resp}
 
 Check Whether Message Received
     [Documentation]  Validare if message has been received
-    [Arguments]  ${msg_code}
-    ${ret}=  DMaaP Message Receive  ${msg_code}
+    [Arguments]  ${msg_code}  ${topic}
+    ${ret}=  Run Keyword If  '${topic}' != 'None'  DMaaP Message Receive On Topic  ${msg_code}  ${topic}
+    ...  ELSE  DMaaP Message Receive  ${msg_code}
     Should Be Equal As Strings    ${ret}    true
 
 Send Request And Expect Error