blob: 3ce4be4855a6461d2d90c588464db073de0e6fad [file] [log] [blame]
Gary Wu9abb61c2018-09-27 10:38:50 -07001*** Settings ***
2Library RequestsLibrary
3Library Collections
4Resource RuleAddr.robot
5Resource ../CommonKeywords/HttpRequest.robot
6
7*** Keywords ***
8prepareRules
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
18ruleMgtSuiteVariable
19 ${RULEDIC} create dictionary rulename=gy2017001 description=create a new rule! content=package rule2017001 enabled=1
20 set suite variable ${RULEDIC}
21
22queryConditionRule
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
33traversalRuleAttribute
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
42verifyRuleAttribute
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
56createRule
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
66modifyRule
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
74deleteRule
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}