Skip to content

Commit

Permalink
- replace agenda-group with ruleflow-group
Browse files Browse the repository at this point in the history
- adjust unit tests
  • Loading branch information
tkobayas committed Jan 29, 2025
1 parent 6a683f9 commit a5d3341
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void typeFieldDescr() {
void attributeDescr() {
final String source = "rule R1\n" +
" salience 42\n" +
" agenda-group \"my_group\"\n" +
" ruleflow-group \"my_group\"\n" +
" when\n" +
" then\n" +
"end";
Expand All @@ -257,10 +257,10 @@ void attributeDescr() {
// Backward compatibility doesn't seem to be required in this case. (If do it, the code would be unnecessarily complicated.)
if (DrlParser.ANTLR4_PARSER_ENABLED) {
assertProperties(rule.getAttributes().get("salience"), 10, 21, 2, 2, 2, 12);
assertProperties(rule.getAttributes().get("agenda-group"), 24, 47, 3, 2, 3, 24);
assertProperties(rule.getAttributes().get("ruleflow-group"), 24, 49, 3, 2, 3, 26);
} else {
assertProperties(rule.getAttributes().get("salience"), 19, 21, 2, 11, 2, 12);
assertProperties(rule.getAttributes().get("agenda-group"), 37, 47, 3, 15, 3, 24);
assertProperties(rule.getAttributes().get("ruleflow-group"), 39, 49, 3, 17, 3, 26);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1765,8 +1765,8 @@ void attributes() {
assertThat(at.getName()).isEqualTo("salience");
assertThat(at.getValue()).isEqualTo("42");

at = (AttributeDescr) attrs.get("agenda-group");
assertThat(at.getName()).isEqualTo("agenda-group");
at = (AttributeDescr) attrs.get("ruleflow-group");
assertThat(at.getName()).isEqualTo("ruleflow-group");
assertThat(at.getValue()).isEqualTo("my_group");

at = (AttributeDescr) attrs.get("no-loop");
Expand Down Expand Up @@ -1801,8 +1801,8 @@ void attributes2() {
AttributeDescr at = (AttributeDescr) attrs.get("salience");
assertThat(at.getName()).isEqualTo("salience");
assertThat(at.getValue()).isEqualTo("(42)");
at = (AttributeDescr) attrs.get("agenda-group");
assertThat(at.getName()).isEqualTo("agenda-group");
at = (AttributeDescr) attrs.get("ruleflow-group");
assertThat(at.getName()).isEqualTo("ruleflow-group");
assertThat(at.getValue()).isEqualTo("my_group");

rule = rules.get(1);
Expand Down Expand Up @@ -1957,8 +1957,8 @@ void attributes_alternateSyntax() {
assertThat(at.getName()).isEqualTo("salience");
assertThat(at.getValue()).isEqualTo("42");

at = attrs.get("agenda-group");
assertThat(at.getName()).isEqualTo("agenda-group");
at = attrs.get("ruleflow-group");
assertThat(at.getName()).isEqualTo("ruleflow-group");
assertThat(at.getValue()).isEqualTo("my_group");

at = attrs.get("no-loop");
Expand Down Expand Up @@ -2015,7 +2015,7 @@ void packageAttributes() {
"package_attributes.drl");

AttributeDescr at = (AttributeDescr) pkg.getAttributes().get(0);
assertThat(at.getName()).isEqualTo("agenda-group");
assertThat(at.getName()).isEqualTo("ruleflow-group");
assertThat(at.getValue()).isEqualTo("x");
at = (AttributeDescr) pkg.getAttributes().get(1);
assertThat(at.getName()).isEqualTo("dialect");
Expand All @@ -2027,8 +2027,8 @@ void packageAttributes() {

RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertThat(rule.getName()).isEqualTo("bar");
at = (AttributeDescr) rule.getAttributes().get("agenda-group");
assertThat(at.getName()).isEqualTo("agenda-group");
at = (AttributeDescr) rule.getAttributes().get("ruleflow-group");
assertThat(at.getName()).isEqualTo("ruleflow-group");
assertThat(at.getValue()).isEqualTo("x");
at = (AttributeDescr) rule.getAttributes().get("dialect");
assertThat(at.getName()).isEqualTo("dialect");
Expand All @@ -2039,8 +2039,8 @@ void packageAttributes() {
at = (AttributeDescr) rule.getAttributes().get("dialect");
assertThat(at.getName()).isEqualTo("dialect");
assertThat(at.getValue()).isEqualTo("mvel");
at = (AttributeDescr) rule.getAttributes().get("agenda-group");
assertThat(at.getName()).isEqualTo("agenda-group");
at = (AttributeDescr) rule.getAttributes().get("ruleflow-group");
assertThat(at.getName()).isEqualTo("ruleflow-group");
assertThat(at.getValue()).isEqualTo("x");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package com.foo;

agenda-group "x"
ruleflow-group "x"

import goo.ber
import wee.waa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
rule simple_rule
// attributes keywork (and colon) is totally optional
salience 42
agenda-group "my_group"
ruleflow-group "my_group"
no-loop
duration 42
activation-group "my_activation_group"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package foo.bar

rule rule1
salience (42)
agenda-group "my_group"
ruleflow-group "my_group"
when
Foo()
then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

rule simple_rule
attributes:
salience 42, agenda-group "my_group", no-loop, lock-on-active, duration 42, activation-group "my_activation_group"
salience 42, ruleflow-group "my_group", no-loop, lock-on-active, duration 42, activation-group "my_activation_group"
when
Foo()
then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ drlKeywords returns [Token token]
| DRL_LOCK_ON_ACTIVE
| DRL_REFRACT
| DRL_DIRECT
| DRL_AGENDA_GROUP
| DRL_ACTIVATION_GROUP
| DRL_RULEFLOW_GROUP
| DRL_DATE_EFFECTIVE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ DRL_AUTO_FOCUS : 'auto-focus';
DRL_LOCK_ON_ACTIVE : 'lock-on-active';
DRL_REFRACT : 'refract';
DRL_DIRECT : 'direct';
DRL_AGENDA_GROUP : 'agenda-group';
DRL_ACTIVATION_GROUP : 'activation-group';
DRL_RULEFLOW_GROUP : 'ruleflow-group';
DRL_DATE_EFFECTIVE : 'date-effective';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ drlAnnotation
attributes : (DRL_ATTRIBUTES COLON?)? attribute ( COMMA? attribute )* ;
attribute : name=( DRL_SALIENCE | DRL_ENABLED ) conditionalAttributeValue #expressionAttribute
| name=( DRL_NO_LOOP | DRL_AUTO_FOCUS | DRL_LOCK_ON_ACTIVE | DRL_REFRACT | DRL_DIRECT ) BOOL_LITERAL? #booleanAttribute
| name=( DRL_AGENDA_GROUP | DRL_ACTIVATION_GROUP | DRL_RULEFLOW_GROUP | DRL_DATE_EFFECTIVE | DRL_DATE_EXPIRES | DRL_DIALECT ) DRL_STRING_LITERAL #stringAttribute
| name=( DRL_ACTIVATION_GROUP | DRL_RULEFLOW_GROUP | DRL_DATE_EFFECTIVE | DRL_DATE_EXPIRES | DRL_DIALECT ) DRL_STRING_LITERAL #stringAttribute
| name=DRL_CALENDARS DRL_STRING_LITERAL ( COMMA DRL_STRING_LITERAL )* #stringListAttribute
| name=DRL_TIMER ( DECIMAL_LITERAL | LPAREN chunk RPAREN ) #intOrChunkAttribute
| name=DRL_DURATION ( DECIMAL_LITERAL | LPAREN chunk RPAREN ) #intOrChunkAttribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.drools.core.common.InternalAgenda;
import org.drools.core.impl.RuleBaseFactory;
import org.drools.core.integrationtests.SerializationHelper;
import org.drools.drl.parser.DrlParser;
import org.drools.kiesession.rulebase.InternalKnowledgeBase;
import org.drools.kiesession.rulebase.KnowledgeBaseFactory;
import org.kie.api.KieBase;
Expand Down Expand Up @@ -126,6 +127,7 @@ protected KieBase loadKnowledgeBaseFromString(
protected KieBase loadKnowledgeBaseFromString( KnowledgeBuilderConfiguration config, KieBaseConfiguration kBaseConfig, String... drlContentStrings) {
KnowledgeBuilder kbuilder = config == null ? KnowledgeBuilderFactory.newKnowledgeBuilder() : KnowledgeBuilderFactory.newKnowledgeBuilder(config);
for (String drlContentString : drlContentStrings) {
drlContentString = replaceAgendaGroupIfRequired(drlContentString);
kbuilder.add(ResourceFactory.newByteArrayResource(drlContentString
.getBytes()), ResourceType.DRL);
}
Expand All @@ -141,6 +143,14 @@ protected KieBase loadKnowledgeBaseFromString( KnowledgeBuilderConfiguration con
return kbase;
}

public static String replaceAgendaGroupIfRequired(String drl) {
if (DrlParser.ANTLR4_PARSER_ENABLED) {
// new parser (DRL10) supports only ruleflow-group, dropping agenda-group
return drl.replaceAll("agenda-group", "ruleflow-group");
}
return drl;
}

protected KieBase loadKnowledgeBase(KnowledgeBuilderConfiguration kbuilderConf, KieBaseConfiguration kbaseConf, String... classPathResources) {
Collection<KiePackage> knowledgePackages = loadKnowledgePackages(kbuilderConf, classPathResources);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.drools.compiler.kie.builder.impl.InternalKieModule;
import org.drools.core.reteoo.EntryPointNode;
import org.drools.core.reteoo.ObjectTypeNode;
import org.drools.drl.parser.DrlParser;
import org.drools.kiesession.rulebase.InternalKnowledgeBase;
import org.drools.model.codegen.ExecutableModelProject;
import org.kie.api.KieServices;
Expand Down Expand Up @@ -185,7 +186,15 @@ public KieFile( int index, String content ) {

public KieFile( String path, String content ) {
this.path = path;
this.content = content;
this.content = replaceAgendaGroupIfRequired(content);
}

public static String replaceAgendaGroupIfRequired(String drl) {
if (DrlParser.ANTLR4_PARSER_ENABLED) {
// new parser (DRL10) supports only ruleflow-group, dropping agenda-group
return drl.replaceAll("agenda-group", "ruleflow-group");
}
return drl;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.drools.commands.impl.CommandBasedStatefulKnowledgeSessionImpl;
import org.drools.commands.impl.FireAllRulesInterceptor;
import org.drools.commands.impl.LoggingInterceptor;
import org.drools.mvel.CommonTestMethodBase;
import org.drools.mvel.compiler.Person;
import org.drools.persistence.PersistableRunner;
import org.drools.persistence.util.DroolsPersistenceUtil;
Expand Down Expand Up @@ -329,6 +330,8 @@ public void testSetFocus(String locking) {
str += "end\n";
str += "\n";

str = CommonTestMethodBase.replaceAgendaGroupIfRequired(str);

KieServices ks = KieServices.Factory.get();

KieFileSystem kfs = ks.newKieFileSystem().write( "src/main/resources/r1.drl", str );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.drools.persistence.util.DroolsPersistenceUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.drools.io.ClassPathResource;
Expand Down Expand Up @@ -98,7 +99,8 @@ public void testRuleFlowGroupOnly(boolean locking) throws Exception {
assertThat(groups[0].getName()).isEqualTo("MAIN");
assertThat(groups[1].getName()).isEqualTo("ruleflow-group");
}


@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@ParameterizedTest
@MethodSource("parameters")
public void testAgendaGroupOnly(boolean locking) throws Exception {
Expand Down Expand Up @@ -126,7 +128,8 @@ public void testAgendaGroupOnly(boolean locking) throws Exception {
assertThat(groups[1].getName()).isEqualTo("agenda-group");

}


@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@ParameterizedTest
@MethodSource("parameters")
public void testAgendaGroupAndRuleFlowGroup(boolean locking) throws Exception {
Expand Down Expand Up @@ -234,6 +237,7 @@ public Void execute(Context context) {

}

@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@ParameterizedTest
@MethodSource("parameters")
public void testConflictingAgendaAndRuleflowGroups() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.drools.core.FlowSessionConfiguration;
import org.drools.core.SessionConfiguration;
import org.drools.core.impl.RuleBaseFactory;
import org.drools.mvel.CommonTestMethodBase;
import org.drools.mvel.compiler.Address;
import org.drools.mvel.compiler.Person;
import org.drools.persistence.PersistableRunner;
Expand Down Expand Up @@ -361,7 +362,7 @@ public void testSetFocusWithOOPath() {
}

private void testFocus(final boolean withOOPath) {
final String str = "package org.kie.test\n" +
String str = "package org.kie.test\n" +
"global java.util.List list\n" +
"rule rule1\n" +
"agenda-group \"badfocus\"" +
Expand All @@ -372,6 +373,8 @@ private void testFocus(final boolean withOOPath) {
"end\n" +
"\n";

str = CommonTestMethodBase.replaceAgendaGroupIfRequired(str);

final KieBase kbase = new KieHelper().addContent(str, ResourceType.DRL).build();

final KieSession ksession = KieServices.get().getStoreServices().newKieSession(kbase, null, env);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.kie.api.KieBase;
import org.kie.api.KieBaseConfiguration;
import org.kie.api.KieServices;
Expand Down Expand Up @@ -1560,6 +1561,7 @@ public void testActivationGroups() throws Exception {
assertThat(list.get(1)).isEqualTo("rule4");
}

@DisabledIfSystemProperty(named = "drools.drl.antlr4.parser.enabled", matches = "true")
@Test
public void testAgendaGroups() throws Exception {
String rule1 = "package org.drools.compiler.test;\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ end


rule "match Person 2"
agenda-group "xxx"
ruleflow-group "xxx"
salience ($age2 - $age1)
when
$person : Person(name=="mark", $age1 : age )
Expand All @@ -53,7 +53,7 @@ rule "match Person 2"
end

rule "match Person 3"
agenda-group "xxx"
ruleflow-group "xxx"
dialect "mvel"
when
not Person( name == "mark" )
Expand All @@ -62,7 +62,7 @@ rule "match Person 3"
end

rule "match Integer"
agenda-group "yyy"
ruleflow-group "yyy"
auto-focus true
when
Person( name == "bob" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,6 @@ public void testFiredRuleDoNotRefireAfterUnblock(KieBaseTestConfiguration kieBas
"end\n";

final KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmodule = ks.newKieModuleModel();

KieBaseModel baseModel = kmodule.newKieBaseModel("defaultKBase")
Expand All @@ -928,10 +927,7 @@ public void testFiredRuleDoNotRefireAfterUnblock(KieBaseTestConfiguration kieBas
baseModel.newKieSessionModel("defaultKSession")
.setDefault(true);

kfs.writeKModuleXML(kmodule.toXML());
kfs.write("src/main/resources/block_rule.drl", drl);
final KieBuilder kieBuilder = KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
assertThat(kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size()).isEqualTo(0);
KieUtil.getKieBuilderFromDrls(kieBaseTestConfiguration, kmodule, true, drl);

KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();

Expand Down
Loading

0 comments on commit a5d3341

Please sign in to comment.