Created
January 22, 2025 10:03
-
-
Save mariofusco/29f711a1c682845537539896a3c82b3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.drools.ansible.rulebook.integration.api; | |
import org.drools.base.util.index.ConstraintTypeOperator; | |
import org.drools.core.reteoo.Rete; | |
import org.drools.kiesession.rulebase.InternalKnowledgeBase; | |
import org.junit.Test; | |
import org.kie.api.runtime.rule.Match; | |
import java.util.List; | |
import static org.junit.Assert.assertEquals; | |
public class JoinTest { | |
@Test | |
public void testJoin() { | |
String json = | |
""" | |
{ | |
"rules": [ | |
{ | |
"Rule": { | |
"condition": { | |
"AllCondition": [ | |
{ | |
"EqualsExpression": { | |
"lhs": { | |
"Event": "i" | |
}, | |
"rhs": { | |
"Integer": "3" | |
} | |
} | |
}, | |
{ | |
"EqualsExpression": { | |
"lhs": { | |
"Event": "j" | |
}, | |
"rhs": { | |
"Integer": "3" | |
} | |
} | |
} | |
] | |
}, | |
"enabled": true, | |
"name": "R1" | |
} | |
} | |
] | |
} | |
"""; | |
RulesExecutor rulesExecutor = RulesExecutorFactory.createFromJson(json); | |
List<Match> matchedRules = rulesExecutor.processEvents("{ \"i\": 3 }").join(); | |
assertEquals(0, matchedRules.size()); | |
matchedRules = rulesExecutor.processEvents("{ \"i\": 3 }").join(); | |
assertEquals(0, matchedRules.size()); | |
matchedRules = rulesExecutor.processEvents("{ \"j\": 3 }").join(); | |
assertEquals(2, matchedRules.size()); | |
assertEquals("R1", matchedRules.get(0).getRule().getName()); | |
assertEquals("R1", matchedRules.get(1).getRule().getName()); | |
rulesExecutor.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment