Move CSIT to integration/csit repo
[integration/csit.git] / tests / holmes / testcase / RuleMgt / Rule-Keywords.robot
1 *** Settings ***
2 Library           RequestsLibrary
3 Library           Collections
4 Resource          RuleAddr.robot
5 Resource          ../CommonKeywords/HttpRequest.robot
6
7 *** Keywords ***
8 prepareRules
9     ${rule1}    create dictionary    rulename=ying001    content=package rule0001    enabled=1    description=this is first description
10     ${rule2}    create dictionary    rulename=ying002    content=package rule0002    enabled=0    description=this is seconddescription
11     ${rule3}    create dictionary    rulename=ying003    content=package rule0003    enabled=1    description=this is third description
12     @{rulesList}    create list    ${rule1}    ${rule2}    ${rule3}
13     : FOR    ${row}    IN    @{rulesList}
14     \    ${rulejson}    encode    ${row}
15     \    log    ${rulejson}
16     \    createRule    ${rulejson}
17
18 ruleMgtSuiteVariable
19     ${RULEDIC}    create dictionary    rulename=gy2017001    description=create a new rule!    content=package rule2017001    enabled=1
20     set suite variable    ${RULEDIC}
21
22 queryConditionRule
23     [Arguments]    ${queryParam}    ${codeFlag}=1
24     [Documentation]    ${queryParam} : The data type is Json .
25     create session    microservices    ${ruleMgtHost}
26     Comment    ${param}    set variable    queryrequest\=${queryParam}
27     ${getResponse}    get request    microservices    ${ruleMgtUrl}?queryrequest\=${queryParam}
28     log    ${getResponse.content}
29     run keyword if    ${codeFlag}==1    Should be equal as strings    ${getResponse.status_code}    200
30     run keyword if    ${codeFlag}!=1    Should be equal as strings    ${getResponse.status_code}    499
31     [Return]    ${getResponse}
32
33 traversalRuleAttribute
34     [Arguments]    ${responseJsonData}    ${expectAttrDic}
35     [Documentation]    ${expectAttrDic} : The data type is dictionary;
36     ...    key is the name of the attribute, value is the expected value of the attribute.
37     @{responseRules}    Get From Dictionary    ${responseJsonData}    correlationRules
38     : FOR    ${rule}    IN    @{responseRules}
39     \    log    ${rule}
40     \    verifyRuleAttribute    ${rule}    ${expectAttrDic}
41
42 verifyRuleAttribute
43     [Arguments]    ${singleRule}    ${expectAttrDic}
44     [Documentation]    ${expectAttrDic} : The data type is dictionary; key is the name of the attributes to be traversaled, value is the expected value of the attributes.
45     log    ${singleRule}
46     log    ${expectAttrDic}
47     @{attrsKeys}    get dictionary keys    ${expectAttrDic}
48     : FOR    ${attr}    IN    @{attrsKeys}
49     \    log    ${attr}
50     \    ${actualResponse}    get from dictionary    ${singleRule}    ${attr}
51     \    ${expectResponse}    get from dictionary    ${expectAttrDic}    ${attr}
52     \    Comment    log    ${actualResponse}
53     \    Comment    log    ${expectResponse}
54     Should be equal as strings    ${actualResponse}    ${expectResponse}
55
56 createRule
57     [Arguments]    ${jsonParams}    ${codeFlag}=1
58     [Documentation]    ${codeFlag} : The data type is string, defult value is 1, indicating that the case need to assert thatthe statues code is 200.
59     ...    Then other values indicating that the case need to assert that the statues code is 499.
60     ${response}    httpPut    ${ruleMgtHost}    ${ruleMgtUrl}    ${jsonParams}
61     log    ${response.content}
62     run keyword if    ${codeFlag}==1    Should be equal as strings    ${response.status_code}    200
63     run keyword if    ${codeFlag}!=1    Should be equal as strings    ${response.status_code}    499
64     [Return]    ${response}
65
66 modifyRule
67     [Arguments]    ${jsonParams}    ${codeFlag}=1
68     ${response}    httpPost    ${ruleMgtHost}    ${ruleMgtUrl}    ${jsonParams}
69     log    ${response.content}
70     run keyword if    ${codeFlag}==1    Should be equal as strings    ${response.status_code}    200
71     run keyword if    ${codeFlag}!=1    Should be equal as strings    ${response.status_code}    499
72     [Return]    ${response}
73
74 deleteRule
75     [Arguments]    ${ruleId}    ${codeFlag}=1
76     ${response}    httpDelete    ${ruleMgtHost}    ${ruleMgtUrl}/${ruleId}
77     log    ${response.content}
78     run keyword if    ${codeFlag}==1    Should be equal as strings    ${response.status_code}    200
79     run keyword if    ${codeFlag}!=1    Should be equal as strings    ${response.status_code}    499
80     [Return]    ${response}