Skip to content

Commit

Permalink
[DROOLS-7639] ansible-rulebook : support event path for collecting el…
Browse files Browse the repository at this point in the history
…ements in array in array

- WIP: test case only
  • Loading branch information
tkobayas committed Oct 25, 2024
1 parent a840c07 commit f8d7c85
Showing 1 changed file with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,98 @@ public void testSelectAttrWithScientificNotation() {

rulesExecutor.dispose();
}

@Test
public void testSelectAttrForArrayInArray() {

String JSON_ARRAY_IN_ARRAY =
"""
{
"rules":[
{
"Rule":{
"name":"r1",
"condition":{
"AllCondition":[
{
"SelectAttrExpression":{
"lhs":{
"Event":"incident.alerts.tags"
},
"rhs":{
"key":{
"String":"value"
},
"operator":{
"String":"=="
},
"value":{
"String":"DiskUsage"
}
}
}
}
]
},
"actions":[
{
"Action":{
"action":"debug",
"action_args":{
"msg":"Found a match with alerts"
}
}
}
],
"enabled":true
}
}
]
}
""";

RulesExecutor rulesExecutor = RulesExecutorFactory.createFromJson(JSON_ARRAY_IN_ARRAY);

List<Match> matchedRules = rulesExecutor.processFacts( """
{
"incident":{
"id":"aaa",
"active":false,
"alerts":[
{
"id":"bbb",
"tags":[
{
"name":"alertname",
"value":"MariadbDown"
},
{
"name":"severity",
"value":"critical"
}
],
"status":"Ok"
},
{
"id":"ccc",
"tags":[
{
"name":"severity",
"value":"critical"
},
{
"name":"alertname",
"value":"DiskUsage"
}
],
"status":"Ok"
}
]
}
}
""" ).join();
assertEquals( 1, matchedRules.size() );

rulesExecutor.dispose();
}
}

0 comments on commit f8d7c85

Please sign in to comment.