Skip to content

Instantly share code, notes, and snippets.

@mariofusco
Created January 22, 2025 10:03
Show Gist options
  • Save mariofusco/29f711a1c682845537539896a3c82b3b to your computer and use it in GitHub Desktop.
Save mariofusco/29f711a1c682845537539896a3c82b3b to your computer and use it in GitHub Desktop.
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