Skip to content

Commit

Permalink
Adding isNotDefined test (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkobayas authored Sep 10, 2024
1 parent 7c80d81 commit 47fc3e7
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.drools.ansible.rulebook.integration.api;

import org.drools.base.reteoo.InitialFactImpl;
import org.junit.Test;
import org.kie.api.prototype.PrototypeFactInstance;
import org.kie.api.runtime.rule.Match;
Expand Down Expand Up @@ -131,4 +132,51 @@ public void testEventShouldProduceMultipleMatchesForSameRule() {

rulesExecutor.dispose();
}

public static final String JSON_IS_NOT_DEFINED =
"""
{
"rules": [
{
"Rule": {
"name": "r1",
"condition": {
"AllCondition": [
{
"IsNotDefinedExpression": {
"Event": "beta.xheaders.age"
}
}
]
},
"actions": [
{
"Action": {
"action": "debug",
"action_args": {}
}
}
],
"enabled": true
}
}
]
}
""";

@Test
public void isNotDefinedExpression() {
RulesExecutor rulesExecutor = RulesExecutorFactory.createFromJson(JSON_IS_NOT_DEFINED);

List<Match> matchedRules = rulesExecutor.processEvents("{\"meta\":{\"headers\":{\"token\":123}}}").join();
assertEquals(1, matchedRules.size());
assertEquals("r1", matchedRules.get(0).getRule().getName());
assertEquals(InitialFactImpl.class, matchedRules.get(0).getObjects().get(0).getClass());

// "isNotDefined" rule matches only once
matchedRules = rulesExecutor.processEvents("{\"beta\":{\"headers\":{\"age\":23}}}").join();
assertEquals(0, matchedRules.size());

rulesExecutor.dispose();
}
}

0 comments on commit 47fc3e7

Please sign in to comment.