diff --git a/drools-model/drools-canonical-model/pom.xml b/drools-model/drools-canonical-model/pom.xml index 58d14809398..0b11dd11640 100644 --- a/drools-model/drools-canonical-model/pom.xml +++ b/drools-model/drools-canonical-model/pom.xml @@ -43,11 +43,10 @@ logback-classic test - - junit - junit - test + org.junit.jupiter + junit-jupiter + test org.assertj diff --git a/drools-model/drools-canonical-model/src/test/java/org/drools/model/operators/MatchesOperatorTest.java b/drools-model/drools-canonical-model/src/test/java/org/drools/model/operators/MatchesOperatorTest.java index 4520828c4ea..85904614f4d 100644 --- a/drools-model/drools-canonical-model/src/test/java/org/drools/model/operators/MatchesOperatorTest.java +++ b/drools-model/drools-canonical-model/src/test/java/org/drools/model/operators/MatchesOperatorTest.java @@ -18,11 +18,11 @@ */ package org.drools.model.operators; -import org.junit.After; -import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; public class MatchesOperatorTest { @@ -60,7 +60,7 @@ public void testMatchesOperatorNoCache() { assertThat(instance.mapSize()).isEqualTo(0); } - @After + @AfterEach public void resetCache() { MatchesOperator instance = MatchesOperator.INSTANCE; instance.reInitialize(); diff --git a/drools-model/drools-canonical-model/src/test/java/org/drools/model/util/OperatorUtilsTest.java b/drools-model/drools-canonical-model/src/test/java/org/drools/model/util/OperatorUtilsTest.java index 9a42b767312..0b2b2797720 100644 --- a/drools-model/drools-canonical-model/src/test/java/org/drools/model/util/OperatorUtilsTest.java +++ b/drools-model/drools-canonical-model/src/test/java/org/drools/model/util/OperatorUtilsTest.java @@ -20,7 +20,7 @@ import java.math.BigDecimal; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-model/drools-model-codegen/pom.xml b/drools-model/drools-model-codegen/pom.xml index b8df4eda918..174224e2c04 100644 --- a/drools-model/drools-model-codegen/pom.xml +++ b/drools-model/drools-model-codegen/pom.xml @@ -127,36 +127,16 @@ test - - junit - junit - test - - + + org.junit.jupiter + junit-jupiter + test + + org.assertj assertj-core test - - org.junit.vintage - junit-vintage-engine - test - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.junit.jupiter - junit-jupiter-params - test - org.drools drools-decisiontables diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/AccumulateTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/AccumulateTest.java index f46c7f77084..95d368192c9 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/AccumulateTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/AccumulateTest.java @@ -50,6 +50,8 @@ import org.drools.core.base.accumulators.IntegerMaxAccumulateFunction; import org.drools.core.rule.consequence.InternalMatch; import org.drools.model.functions.accumulate.GroupKey; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.drools.model.codegen.execmodel.domain.Adult; import org.drools.model.codegen.execmodel.domain.Child; import org.drools.model.codegen.execmodel.domain.Customer; @@ -59,7 +61,6 @@ import org.drools.model.codegen.execmodel.domain.StockTick; import org.drools.model.codegen.execmodel.domain.TargetPolicy; import org.drools.model.codegen.execmodel.oopathdtables.InternationalAddress; -import org.junit.Test; import org.kie.api.builder.Message; import org.kie.api.builder.Results; import org.kie.api.definition.type.FactType; @@ -68,16 +69,14 @@ import org.kie.api.runtime.rule.FactHandle; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.fail; public class AccumulateTest extends BaseModelTest { - public AccumulateTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testAccumulate1() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulate1(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -89,7 +88,7 @@ public void testAccumulate1() { " insert(new Result($sum));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -102,8 +101,9 @@ public void testAccumulate1() { assertThat(results.iterator().next().getValue()).isEqualTo(77); } - @Test - public void testFromOnAccumulatedValue() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromOnAccumulatedValue(RUN_TYPE runType) { // DROOLS-5635 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -117,7 +117,7 @@ public void testFromOnAccumulatedValue() { " insert(new Result($s));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert("test"); ksession.insert(new Person("Mark", 37)); @@ -131,8 +131,9 @@ public void testFromOnAccumulatedValue() { assertThat(results.iterator().next().getValue()).isEqualTo("77"); } - @Test - public void testFromOnAccumulatedValueUsingExists() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromOnAccumulatedValueUsingExists(RUN_TYPE runType) { // DROOLS-5635 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -146,7 +147,7 @@ public void testFromOnAccumulatedValueUsingExists() { " insert(new Result($s));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert("test"); ksession.insert(new Person("Mark", 37)); @@ -160,8 +161,9 @@ public void testFromOnAccumulatedValueUsingExists() { assertThat(results.iterator().next().getValue()).isEqualTo("77"); } - @Test - public void testAccumulateWithoutParameters() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithoutParameters(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -173,7 +175,7 @@ public void testAccumulateWithoutParameters() { " insert(new Result($count));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -186,8 +188,9 @@ public void testAccumulateWithoutParameters() { assertThat(results.iterator().next().getValue()).isEqualTo(2l); } - @Test - public void testAccumulateWithLessParameter() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithLessParameter(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -199,7 +202,7 @@ public void testAccumulateWithLessParameter() { " insert(new Result(\"fired\"));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -214,8 +217,9 @@ public void testAccumulateWithLessParameter() { assertThat(results.iterator().next().getValue()).isEqualTo("fired"); } - @Test - public void testAccumulateOverConstant() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateOverConstant(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -227,7 +231,7 @@ public void testAccumulateOverConstant() { " insert(new Result($sum));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -240,8 +244,9 @@ public void testAccumulateOverConstant() { assertThat(results.iterator().next().getValue()).isEqualTo(2); } - @Test - public void testAccumulateConstrainingValue() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateConstrainingValue(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -253,7 +258,7 @@ public void testAccumulateConstrainingValue() { " insert(new Result($sum));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -266,8 +271,9 @@ public void testAccumulateConstrainingValue() { assertThat(results.iterator().next().getValue()).isEqualTo(77); } - @Test - public void testAccumulateConstrainingValue2() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateConstrainingValue2(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -279,7 +285,7 @@ public void testAccumulateConstrainingValue2() { " insert(new Result($sum));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -291,8 +297,9 @@ public void testAccumulateConstrainingValue2() { assertThat(results.size()).isEqualTo(0); } - @Test - public void testAccumulateConstrainingValueInPattern() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateConstrainingValueInPattern(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -304,7 +311,7 @@ public void testAccumulateConstrainingValueInPattern() { " insert(new Result($sum));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -317,8 +324,9 @@ public void testAccumulateConstrainingValueInPattern() { assertThat(results.iterator().next().getValue()).isEqualTo(77); } - @Test - public void testAccumulateWithProperty() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithProperty(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -330,7 +338,7 @@ public void testAccumulateWithProperty() { " insert(new Result($sum));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -343,8 +351,9 @@ public void testAccumulateWithProperty() { assertThat(results.iterator().next().getValue()).isEqualTo(77); } - @Test - public void testAccumulate2() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulate2(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -358,7 +367,7 @@ public void testAccumulate2() { " insert(new Result($average));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -371,8 +380,9 @@ public void testAccumulate2() { assertThat(results).contains(new Result(77)); } - @Test - public void testAccumulateMultipleFunctions() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateMultipleFunctions(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -386,7 +396,7 @@ public void testAccumulateMultipleFunctions() { " insert(new Result($average));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -399,8 +409,9 @@ public void testAccumulateMultipleFunctions() { assertThat(results).contains(new Result(77)); } - @Test - public void testAccumulateMultipleFunctionsConstrainingValues() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateMultipleFunctionsConstrainingValues(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -415,7 +426,7 @@ public void testAccumulateMultipleFunctionsConstrainingValues() { " insert(new Result($min));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -428,8 +439,9 @@ public void testAccumulateMultipleFunctionsConstrainingValues() { assertThat(results).contains(new Result(77)); } - @Test - public void testAccumulateWithAnd() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithAnd(RUN_TYPE runType) { String str = "import " + Adult.class.getCanonicalName() + ";\n" + "import " + Child.class.getCanonicalName() + ";\n" + @@ -440,7 +452,7 @@ public void testAccumulateWithAnd() { " insert(new Result($parentAge));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Adult a = new Adult( "Mario", 43 ); Child c = new Child( "Sofia", 6, "Mario" ); @@ -453,8 +465,9 @@ public void testAccumulateWithAnd() { assertThat(results).contains(new Result(43)); } - @Test - public void testAccumulateWithAnd2() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithAnd2(RUN_TYPE runType) { String str = "import " + Adult.class.getCanonicalName() + ";\n" + "import " + Child.class.getCanonicalName() + ";\n" + @@ -465,7 +478,7 @@ public void testAccumulateWithAnd2() { " insert(new Result($parentAge));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Adult a = new Adult( "Mario", 43 ); Child c = new Child( "Sofia", 6, "Mario" ); @@ -479,8 +492,9 @@ public void testAccumulateWithAnd2() { assertThat(((Number) results.iterator().next().getValue()).intValue()).isEqualTo(49); } - @Test - public void testAccumulateWithAnd3() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithAnd3(RUN_TYPE runType) { String str = "import " + Adult.class.getCanonicalName() + ";\n" + "import " + Child.class.getCanonicalName() + ";\n" + @@ -491,7 +505,7 @@ public void testAccumulateWithAnd3() { " insert(new Result($parentAge));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Adult a = new Adult( "Mario", 43 ); Child c = new Child( "Sofia", 6, "Mario" ); @@ -505,8 +519,9 @@ public void testAccumulateWithAnd3() { assertThat(((Number) results.iterator().next().getValue()).intValue()).isEqualTo(49); } - @Test - public void testAccumulateWithAnd3Binds() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithAnd3Binds(RUN_TYPE runType) { String str = "import " + Adult.class.getCanonicalName() + ";\n" + "import " + Child.class.getCanonicalName() + ";\n" + @@ -518,7 +533,7 @@ public void testAccumulateWithAnd3Binds() { " insert(new Result($parentAge));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Adult a = new Adult( "Mario", 43 ); Child c = new Child( "Sofia", 6, "Mario" ); @@ -533,8 +548,9 @@ public void testAccumulateWithAnd3Binds() { assertThat(((Number) results.iterator().next().getValue()).intValue()).isEqualTo(54); } - @Test - public void testAccumulateWithAnd4Binds() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithAnd4Binds(RUN_TYPE runType) { String str = "import " + Adult.class.getCanonicalName() + ";\n" + "import " + Child.class.getCanonicalName() + ";\n" + @@ -546,7 +562,7 @@ public void testAccumulateWithAnd4Binds() { " insert(new Result($parentAge));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Adult a = new Adult( "Mario", 43 ); Child c = new Child( "Sofia", 6, "Mario" ); @@ -562,8 +578,9 @@ public void testAccumulateWithAnd4Binds() { assertThat(((Number) results.iterator().next().getValue()).intValue()).isEqualTo(59); } - @Test - public void testAccumulateWithCustomImport() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithCustomImport(RUN_TYPE runType) { String str = "import accumulate " + TestFunction.class.getCanonicalName() + " f;\n" + "import " + Adult.class.getCanonicalName() + ";\n" + @@ -575,7 +592,7 @@ public void testAccumulateWithCustomImport() { " insert(new Result($parentAge));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Adult a = new Adult( "Mario", 43 ); Child c = new Child( "Sofia", 6, "Mario" ); @@ -630,8 +647,9 @@ public Class getResultType() { } } - @Test - public void testFromAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromAccumulate(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -643,7 +661,7 @@ public void testFromAccumulate() { " insert(new Result($sum));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -656,8 +674,9 @@ public void testFromAccumulate() { assertThat(results.iterator().next().getValue()).isEqualTo(77); } - @Test - public void testFromCollect() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromCollect(RUN_TYPE runType) { String str = "import " + Customer.class.getCanonicalName() + ";\n" + "import " + TargetPolicy.class.getCanonicalName() + ";\n" + @@ -671,11 +690,12 @@ public void testFromCollect() { " update($target);\n" + "end"; - checkCollect( str ); + checkCollect(runType, str); } - @Test - public void testFromCollectWithAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromCollectWithAccumulate(RUN_TYPE runType) { String str = "import " + Customer.class.getCanonicalName() + ";\n" + "import " + TargetPolicy.class.getCanonicalName() + ";\n" + @@ -689,11 +709,12 @@ public void testFromCollectWithAccumulate() { " update($target);\n" + "end"; - checkCollect( str ); + checkCollect(runType, str); } - @Test - public void testFromCollectWithExpandedAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromCollectWithExpandedAccumulate(RUN_TYPE runType) { String str = "import " + Customer.class.getCanonicalName() + ";\n" + "import " + TargetPolicy.class.getCanonicalName() + ";\n" + @@ -712,11 +733,11 @@ public void testFromCollectWithExpandedAccumulate() { " update($target);\n" + "end"; - checkCollect( str ); + checkCollect(runType, str); } - private void checkCollect( String str ) { - KieSession ksession = getKieSession(str); + private void checkCollect(RUN_TYPE runType, String str ) { + KieSession ksession = getKieSession(runType, str); Customer customer = new Customer(); customer.setCode("code1"); @@ -744,17 +765,19 @@ private void checkCollect( String str ) { assertThat(filtered).isEqualTo(1); } - @Test - public void testFromCollectWithExpandedAccumulate2() { - testFromCollectWithExpandedAccumulate2(false); + @ParameterizedTest + @MethodSource("parameters") + public void testFromCollectWithExpandedAccumulate2(RUN_TYPE runType) { + testFromCollectWithExpandedAccumulate2(runType, false); } - @Test - public void testFromCollectWithExpandedAccumulate2WithReverse() { - testFromCollectWithExpandedAccumulate2(true); + @ParameterizedTest + @MethodSource("parameters") + public void testFromCollectWithExpandedAccumulate2WithReverse(RUN_TYPE runType) { + testFromCollectWithExpandedAccumulate2(runType, true); } - public void testFromCollectWithExpandedAccumulate2(boolean performReverse) { + public void testFromCollectWithExpandedAccumulate2(RUN_TYPE runType, boolean performReverse) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "rule R when\n" + " $sum : Integer() from accumulate (\n" + @@ -764,7 +787,7 @@ public void testFromCollectWithExpandedAccumulate2(boolean performReverse) { " insert($sum);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); FactHandle fh_Mark = ksession.insert(new Person("Mark", 37)); FactHandle fh_Edson = ksession.insert(new Person("Edson", 35)); @@ -785,8 +808,9 @@ public void testFromCollectWithExpandedAccumulate2(boolean performReverse) { } } - @Test - public void testExpandedAccumulateWith2Args() { + @ParameterizedTest + @MethodSource("parameters") + public void testExpandedAccumulateWith2Args(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "rule R when\n" + " $avg : Integer() from accumulate (\n" + @@ -799,7 +823,7 @@ public void testExpandedAccumulateWith2Args() { " insert($avg);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); FactHandle fh_Mark = ksession.insert(new Person("Mark", 37)); FactHandle fh_Edson = ksession.insert(new Person("Edson", 35)); @@ -818,8 +842,9 @@ public void testExpandedAccumulateWith2Args() { assertThat(results).contains(36); } - @Test - public void testExpandedAccumulateWith2Args2Bindings() { + @ParameterizedTest + @MethodSource("parameters") + public void testExpandedAccumulateWith2Args2Bindings(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "rule R when\n" + " $avg : Integer() from accumulate (\n" + @@ -833,7 +858,7 @@ public void testExpandedAccumulateWith2Args2Bindings() { " insert($avg);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); FactHandle fh_Mark = ksession.insert(new Person("Mark", 37)); FactHandle fh_Edson = ksession.insert(new Person("Edson", 35)); @@ -853,8 +878,9 @@ public void testExpandedAccumulateWith2Args2Bindings() { } - @Test - public void testExpandedAccumulateWith3Args() { + @ParameterizedTest + @MethodSource("parameters") + public void testExpandedAccumulateWith3Args(RUN_TYPE runType) { String str = "rule \"TestAccumulate2\" when\n" + " $dx : Number () from accumulate ( $d : Double (),\n" + @@ -866,7 +892,7 @@ public void testExpandedAccumulateWith3Args() { " insert($dx.intValue());\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(1.0); ksession.insert(2.0); @@ -878,8 +904,9 @@ public void testExpandedAccumulateWith3Args() { assertThat(results).contains(8); } - @Test - public void testAccumulateFromWithConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateFromWithConstraint(RUN_TYPE runType) { String str = "import " + java.util.List.class.getCanonicalName() + ";" + "import " + org.drools.model.codegen.execmodel.oopathdtables.Person.class.getCanonicalName() + ";" + @@ -892,7 +919,7 @@ public void testAccumulateFromWithConstraint() { " insert($cities.get(0));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new InternationalAddress("", 1, "Milan", "Safecountry")); ksession.fireAllRules(); @@ -902,8 +929,9 @@ public void testAccumulateFromWithConstraint() { assertThat(results).contains("Milan"); } - @Test - public void testAccumulateWithThis() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithThis(RUN_TYPE runType) { final String drl1 = "import java.util.*;\n" + "rule B\n" + @@ -916,7 +944,7 @@ public void testAccumulateWithThis() { "then\n" + " insert($eventCodeDistinctMois);\n" + "end"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert("1"); ksession.insert("3"); @@ -930,8 +958,9 @@ public void testAccumulateWithThis() { assertThat(results).contains(4); } - @Test - public void testAccumulateWithExternalBind() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithExternalBind(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -944,7 +973,7 @@ public void testAccumulateWithExternalBind() { " insert(new Result($sum));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert("x"); ksession.insert(new Person("Mark", 37)); @@ -958,8 +987,9 @@ public void testAccumulateWithExternalBind() { assertThat(((Number) results.iterator().next().getValue()).intValue()).isEqualTo(77); } - @Test - public void testFromCollectWithExpandedAccumulateExternalBindInInit() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromCollectWithExpandedAccumulateExternalBindInInit(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "rule R when\n" + " String( $l : length )\n" + @@ -970,7 +1000,7 @@ public void testFromCollectWithExpandedAccumulateExternalBindInInit() { " insert($sum);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert("x"); FactHandle fh_Mark = ksession.insert(new Person("Mark", 37)); @@ -984,8 +1014,9 @@ public void testFromCollectWithExpandedAccumulateExternalBindInInit() { } - @Test - public void testFromCollectWithExpandedAccumulateExternalBindInAction() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromCollectWithExpandedAccumulateExternalBindInAction(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "rule R when\n" + " String( $l : length )" + @@ -996,7 +1027,7 @@ public void testFromCollectWithExpandedAccumulateExternalBindInAction() { " insert($sum);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert("x"); FactHandle fh_Mark = ksession.insert(new Person("Mark", 37)); @@ -1010,8 +1041,9 @@ public void testFromCollectWithExpandedAccumulateExternalBindInAction() { } - @Test - public void testUseAccumulateFunctionWithOperationInBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testUseAccumulateFunctionWithOperationInBinding(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "rule R when\n" + @@ -1022,7 +1054,7 @@ public void testUseAccumulateFunctionWithOperationInBinding() { " insert($result);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert("x"); FactHandle fh_Mark = ksession.insert(new Person("Mark", 37)); @@ -1036,8 +1068,9 @@ public void testUseAccumulateFunctionWithOperationInBinding() { } - @Test - public void testUseAccumulateFunctionWithArrayAccessOperation() { + @ParameterizedTest + @MethodSource("parameters") + public void testUseAccumulateFunctionWithArrayAccessOperation(RUN_TYPE runType) { String str = "import " + Adult.class.getCanonicalName() + ";\n" + "rule R when\n" + @@ -1048,7 +1081,7 @@ public void testUseAccumulateFunctionWithArrayAccessOperation() { " insert($result);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert("x"); Adult luca = new Adult("Luca", 33); @@ -1065,8 +1098,9 @@ public void testUseAccumulateFunctionWithArrayAccessOperation() { assertThat(results.get(0).intValue()).isEqualTo(11); } - @Test - public void testUseAccumulateFunctionWithListMvelDialectWithoutBias() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testUseAccumulateFunctionWithListMvelDialectWithoutBias(RUN_TYPE runType) throws Exception { String str = "package org.test;" + "import java.util.*; " + "declare Data " + @@ -1081,7 +1115,7 @@ public void testUseAccumulateFunctionWithListMvelDialectWithoutBias() throws Exc " insert($tot);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); FactType dataType = ksession.getKieBase().getFactType("org.test", "Data"); Object data1 = dataType.newInstance(); @@ -1095,8 +1129,9 @@ public void testUseAccumulateFunctionWithListMvelDialectWithoutBias() throws Exc assertThat(results.get(0).intValue()).isEqualTo(2); } - @Test - public void testUseAccumulateFunctionWithListMvelDialect() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testUseAccumulateFunctionWithListMvelDialect(RUN_TYPE runType) throws Exception { String str = "package org.test;" + "import java.util.*; " + "declare Data " + @@ -1112,7 +1147,7 @@ public void testUseAccumulateFunctionWithListMvelDialect() throws Exception { " insert($tot);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); FactType dataType = ksession.getKieBase().getFactType("org.test", "Data"); Object data1 = dataType.newInstance(); @@ -1132,8 +1167,9 @@ public void testUseAccumulateFunctionWithListMvelDialect() throws Exception { assertThat(results.get(0).intValue()).isEqualTo(212); } - @Test - public void testTypedResultOnAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testTypedResultOnAccumulate(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -1145,7 +1181,7 @@ public void testTypedResultOnAccumulate() { " insert(new Person(\"test\", $max));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert("xyz"); @@ -1156,8 +1192,9 @@ public void testTypedResultOnAccumulate() { assertThat(results.iterator().next().getAge()).isEqualTo(3); } - @Test - public void testExtractorInPattern() { + @ParameterizedTest + @MethodSource("parameters") + public void testExtractorInPattern(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -1169,7 +1206,7 @@ public void testExtractorInPattern() { " insert(new Result($max));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("a", 23)); @@ -1181,8 +1218,9 @@ public void testExtractorInPattern() { } - @Test - public void testThisInPattern() { + @ParameterizedTest + @MethodSource("parameters") + public void testThisInPattern(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -1194,7 +1232,7 @@ public void testThisInPattern() { " insert(new Result($max));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(2); ksession.insert(10); @@ -1208,8 +1246,9 @@ public void testThisInPattern() { - @Test - public void testExtractorInFunction() { + @ParameterizedTest + @MethodSource("parameters") + public void testExtractorInFunction(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -1221,7 +1260,7 @@ public void testExtractorInFunction() { " insert(new Result($max));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("a", 23)); @@ -1232,8 +1271,9 @@ public void testExtractorInFunction() { assertThat(results.iterator().next().getValue()).isEqualTo(23); } - @Test - public void testBigDecimalOperationsInAccumulateConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalOperationsInAccumulateConstraint(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "import " + BigDecimal.class.getCanonicalName() + ";\n" + "global java.util.List results;\n" + @@ -1246,7 +1286,7 @@ public void testBigDecimalOperationsInAccumulateConstraint() { " results.add($moneySummed);\n" + "end\n"; - KieSession ksession1 = getKieSession(str); + KieSession ksession1 = getKieSession(runType, str); ArrayList results = new ArrayList<>(); ksession1.setGlobal("results", results); @@ -1266,8 +1306,9 @@ public void testBigDecimalOperationsInAccumulateConstraint() { // do also the test with two functions - @Test - public void testAccumulateWithMax() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithMax(RUN_TYPE runType) { String str = "import " + StockTick.class.getCanonicalName() + ";" + "import " + StockTick.class.getCanonicalName() + ";" + @@ -1279,7 +1320,7 @@ public void testAccumulateWithMax() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); StockTick st = new StockTick("RHT"); st.setTimeField(new Date().getTime()); @@ -1287,8 +1328,9 @@ public void testAccumulateWithMax() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAccumulateWithMaxCalendar() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithMaxCalendar(RUN_TYPE runType) { String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "rule AccumulateMaxDate\n" + @@ -1300,7 +1342,7 @@ public void testAccumulateWithMaxCalendar() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); StockTick st = new StockTick("RHT"); st.setDueDate(Calendar.getInstance()); @@ -1308,8 +1350,9 @@ public void testAccumulateWithMaxCalendar() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAccumulateWithMaxCalendarAndConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithMaxCalendarAndConstraint(RUN_TYPE runType) { String str = "import " + Customer.class.getCanonicalName() + ";\n" + "import " + StockTick.class.getCanonicalName() + ";\n" + @@ -1324,7 +1367,7 @@ public void testAccumulateWithMaxCalendarAndConstraint() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); StockTick st = new StockTick("RHT"); st.setDueDate(Calendar.getInstance()); @@ -1335,8 +1378,9 @@ public void testAccumulateWithMaxCalendarAndConstraint() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNoBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testNoBinding(RUN_TYPE runType) { final String str = "rule foo\n" + "when\n" + @@ -1347,7 +1391,7 @@ public void testNoBinding() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert("xyz"); ksession.fireAllRules(); } @@ -1358,8 +1402,9 @@ public Short getValue() { } } - @Test - public void testImplicitCastInAccumulateFunction() { + @ParameterizedTest + @MethodSource("parameters") + public void testImplicitCastInAccumulateFunction(RUN_TYPE runType) { String str = "import " + ShortValue.class.getCanonicalName() + ";" + "rule X when\n" + @@ -1367,15 +1412,16 @@ public void testImplicitCastInAccumulateFunction() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new ShortValue()); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAccumulateWithFunctionWithExternalBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithFunctionWithExternalBinding(RUN_TYPE runType) { final String drl = "import " + Converter.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + @@ -1387,7 +1433,7 @@ public void testAccumulateWithFunctionWithExternalBinding() { " list.add($result);\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -1408,8 +1454,9 @@ public static int convert(final int i) { } } - @Test - public void testAccumulateWithFunctionWithExternalBindingAndOR() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithFunctionWithExternalBindingAndOR(RUN_TYPE runType) { final String drl = "import " + Converter.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + @@ -1424,7 +1471,7 @@ public void testAccumulateWithFunctionWithExternalBindingAndOR() { " list.add($result);\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -1438,8 +1485,9 @@ public void testAccumulateWithFunctionWithExternalBindingAndOR() { assertThat(list.get(0).intValue()).isEqualTo(5); } - @Test - public void testAccumulateWithOR() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithOR(RUN_TYPE runType) { final String drl = "import " + Converter.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + @@ -1453,7 +1501,7 @@ public void testAccumulateWithOR() { " list.add($result);\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -1466,8 +1514,9 @@ public void testAccumulateWithOR() { assertThat(list.get(0).intValue()).isEqualTo(5); } - @Test - public void testPatternMatchingOverNumberWhileAccumulatingShort() { + @ParameterizedTest + @MethodSource("parameters") + public void testPatternMatchingOverNumberWhileAccumulatingShort(RUN_TYPE runType) { String drl= "import " + AccumulateResult.class.getCanonicalName() + "\n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -1486,7 +1535,7 @@ public void testPatternMatchingOverNumberWhileAccumulatingShort() { " update($accumulateResult);\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); AccumulateResult result = new AccumulateResult(false); @@ -1538,8 +1587,9 @@ public void setBigDecimalValue(BigDecimal bigDecimalValue) { } - @Test - public void testAccumulateOverField() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateOverField(RUN_TYPE runType) { String str = "import java.lang.Number;\n" + "import java.math.BigDecimal;\n" + @@ -1558,7 +1608,7 @@ public void testAccumulateOverField() { " }\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mario", BigDecimal.valueOf(1000))); ksession.insert(new Person("Luca", BigDecimal.valueOf(2000))); @@ -1572,8 +1622,9 @@ public void testAccumulateOverField() { assertThat(result.getBigDecimalValue()).isEqualTo(BigDecimal.valueOf(3000)); } - @Test - public void testFromAccumulateBigDecimalMvel() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromAccumulateBigDecimalMvel(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "import " + BigDecimal.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + @@ -1590,7 +1641,7 @@ public void testFromAccumulateBigDecimalMvel() { " list.add($b);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -1607,8 +1658,9 @@ public void testFromAccumulateBigDecimalMvel() { } - @Test - public void testSemicolonMissingInInit() { + @ParameterizedTest + @MethodSource("parameters") + public void testSemicolonMissingInInit(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "import " + BigDecimal.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + @@ -1624,7 +1676,7 @@ public void testSemicolonMissingInInit() { " list.add($sum);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -1643,8 +1695,9 @@ public void testSemicolonMissingInInit() { } - @Test(expected = AssertionError.class) - public void testSemicolonMissingInAction() { + @ParameterizedTest + @MethodSource("parameters") + public void testSemicolonMissingInAction(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "import " + BigDecimal.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + @@ -1660,11 +1713,13 @@ public void testSemicolonMissingInAction() { " list.add($sum);\n" + "end"; - getKieSession(str); + + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> getKieSession(runType, str)); } - @Test(expected = AssertionError.class) - public void testSemicolonMissingInReverse() { + @ParameterizedTest + @MethodSource("parameters") + public void testSemicolonMissingInReverse(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "import " + BigDecimal.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + @@ -1680,11 +1735,12 @@ public void testSemicolonMissingInReverse() { " list.add($sum);\n" + "end"; - getKieSession(str); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> getKieSession(runType, str)); } - @Test - public void testGroupBy() { + @ParameterizedTest + @MethodSource("parameters") + public void testGroupBy(RUN_TYPE runType) { // DROOLS-4737 String str = "import java.util.*;\n" + @@ -1704,7 +1760,7 @@ public void testGroupBy() { " System.out.println(\"Sum of ages of person with initial '\" + $initial + \"' is \" + $sumOfAges);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 42)); ksession.insert(new Person("Edson", 38)); @@ -1765,8 +1821,9 @@ public V getValue() { } } - @Test - public void testGroupBy2() { + @ParameterizedTest + @MethodSource("parameters") + public void testGroupBy2(RUN_TYPE runType) { // DROOLS-4737 String str = "import java.util.*;\n" + @@ -1787,7 +1844,7 @@ public void testGroupBy2() { " results.put($initial, $sumOfAges);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Map results = new HashMap(); ksession.setGlobal( "results", results ); @@ -1822,8 +1879,9 @@ public void testGroupBy2() { assertThat(results.get("M")).isEqualTo(119); } - @Test - public void testGroupBy3() { + @ParameterizedTest + @MethodSource("parameters") + public void testGroupBy3(RUN_TYPE runType) { // DROOLS-4737 String str = "import java.util.*;\n" + @@ -1854,7 +1912,7 @@ public void testGroupBy3() { " results.put($initial, $sumOfAges);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Map results = new HashMap(); ksession.setGlobal( "results", results ); @@ -1889,8 +1947,9 @@ public void testGroupBy3() { assertThat(results.get("M")).isEqualTo(119); } - @Test - public void testGroupBy3WithExists() { + @ParameterizedTest + @MethodSource("parameters") + public void testGroupBy3WithExists(RUN_TYPE runType) { String str = "import java.util.*;\n" + "import " + GroupKey.class.getCanonicalName() + ";\n" + @@ -1921,7 +1980,7 @@ public void testGroupBy3WithExists() { " results.put($initial, $sumOfAges);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Map results = new HashMap(); ksession.setGlobal( "results", results ); @@ -1961,8 +2020,9 @@ public void testGroupBy3WithExists() { assertThat(results.get("M")).isEqualTo(119); } - @Test - public void testGroupBy3WithExists2() { + @ParameterizedTest + @MethodSource("parameters") + public void testGroupBy3WithExists2(RUN_TYPE runType) { String str = "import java.util.*;\n" + "import " + GroupKey.class.getCanonicalName() + ";\n" + @@ -1994,7 +2054,7 @@ public void testGroupBy3WithExists2() { " results.add(java.util.Arrays.asList($k, $count));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList(); ksession.setGlobal( "results", results ); @@ -2022,8 +2082,9 @@ public void testGroupBy3WithExists2() { .containsOnly(Arrays.asList(child2, 1L)); } - @Test - public void testGroupBy3With2VarsKey() { + @ParameterizedTest + @MethodSource("parameters") + public void testGroupBy3With2VarsKey(RUN_TYPE runType) { String str = "import java.util.*;\n" + "import " + GroupKey.class.getCanonicalName() + ";\n" + @@ -2057,7 +2118,7 @@ public void testGroupBy3With2VarsKey() { " results.put($k, $sumOfAges);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Map results = new HashMap(); ksession.setGlobal( "results", results ); @@ -2100,8 +2161,9 @@ public void testGroupBy3With2VarsKey() { assertThat(results.get("M5")).isEqualTo(119); } - @Test - public void testFromAfterAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromAfterAccumulate(RUN_TYPE runType) { // DROOLS-4737 String str = "import " + List.class.getCanonicalName() + ";\n" + @@ -2113,7 +2175,7 @@ public void testFromAfterAccumulate() { " System.out.println($name + \"' is \" + $age);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 42)); ksession.insert(new Person("Edson", 38)); @@ -2121,8 +2183,9 @@ public void testFromAfterAccumulate() { ksession.fireAllRules(); } - @Test - public void testCoercionInAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testCoercionInAccumulate(RUN_TYPE runType) { String str = "global java.util.List result;\n" + "rule \"Row 1 moveToBiggerCities\"\n" + @@ -2136,7 +2199,7 @@ public void testCoercionInAccumulate() { List result = new ArrayList<>(); - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal("result", result); IntStream.range(1, 7).forEach(ksession::insert); @@ -2147,8 +2210,9 @@ public void testCoercionInAccumulate() { } - @Test - public void testCoercionInAccumulate2() { + @ParameterizedTest +@MethodSource("parameters") + public void testCoercionInAccumulate2(RUN_TYPE runType) { final String drl = "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List result; \n" + @@ -2165,7 +2229,7 @@ public void testCoercionInAccumulate2() { List result = new ArrayList<>(); - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); ksession.setGlobal("result", result); ksession.insert(new Person("Luca", 35)); @@ -2210,8 +2274,9 @@ public long between(LocalDateTime start, LocalDateTime end) { } } - @Test - public void testAccumulateOnStaticMethod() { + @ParameterizedTest +@MethodSource("parameters") + public void testAccumulateOnStaticMethod(RUN_TYPE runType) { // DROOLS-4979 final String drl = "import java.time.Duration\n" + @@ -2230,7 +2295,7 @@ public void testAccumulateOnStaticMethod() { List result = new ArrayList<>(); - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); ksession.setGlobal("result", result); ksession.insert(new Interval( @@ -2244,8 +2309,9 @@ public void testAccumulateOnStaticMethod() { } - @Test - public void testAccumulateOfDurationBetweenDateTime() { + @ParameterizedTest +@MethodSource("parameters") + public void testAccumulateOfDurationBetweenDateTime(RUN_TYPE runType) { // DROOLS-4979 final String drl = "import java.time.Duration\n" + @@ -2264,7 +2330,7 @@ public void testAccumulateOfDurationBetweenDateTime() { List result = new ArrayList<>(); - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); ksession.setGlobal("result", result); ksession.insert(new Interval( @@ -2278,8 +2344,9 @@ public void testAccumulateOfDurationBetweenDateTime() { } - @Test - public void testGroupByRegrouped() { + @ParameterizedTest + @MethodSource("parameters") + public void testGroupByRegrouped(RUN_TYPE runType) { // DROOLS-5283 String str = "import java.util.*;\n" + @@ -2305,7 +2372,7 @@ public void testGroupByRegrouped() { "then\n" + " System.out.println($p.toString());\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 42)); ksession.insert(new Person("Edson", 38)); @@ -2327,8 +2394,9 @@ public void testGroupByRegrouped() { ksession.fireAllRules(); } - @Test - public void testAccumulateStaticMethodWithPatternBindVar() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateStaticMethodWithPatternBindVar(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "import " + MyUtil.class.getCanonicalName() + ";\n" + "rule R when\n" + @@ -2339,7 +2407,7 @@ public void testAccumulateStaticMethodWithPatternBindVar() { " insert($result);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert("x"); ksession.insert(new Person("Mark", 37)); @@ -2358,8 +2426,9 @@ public static int add(int a, int b) { } } - @Test - public void testModifyAccumulatedFactWithNonIndexableConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testModifyAccumulatedFactWithNonIndexableConstraint(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "rule R when\n" + @@ -2370,7 +2439,7 @@ public void testModifyAccumulatedFactWithNonIndexableConstraint() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( "a" ); ksession.insert( "b" ); @@ -2411,8 +2480,9 @@ public void testModifyAccumulatedFactWithNonIndexableConstraint() { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testAccumulateWithManyBindings() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithManyBindings(RUN_TYPE runType) { // DROOLS-5546 String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -2424,7 +2494,7 @@ public void testAccumulateWithManyBindings() { " insert($max);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 40 ) ); ksession.insert( new Person( "Mark", 40 ) ); @@ -2437,8 +2507,9 @@ public void testAccumulateWithManyBindings() { assertThat(results.get(0).intValue()).isEqualTo(5); } - @Test - public void testFalseNodeSharing() { + @ParameterizedTest + @MethodSource("parameters") + public void testFalseNodeSharing(RUN_TYPE runType) { // DROOLS-5686 String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -2457,7 +2528,7 @@ public void testFalseNodeSharing() { " insert(\"\" + $sum);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 46 ) ); ksession.insert( new Person( "Mark", 44 ) ); @@ -2474,8 +2545,9 @@ public void testFalseNodeSharing() { assertThat(resultsString.get(0)).isEqualTo("13"); } - @Test - public void testAccumulateWithTwoFunctions1() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithTwoFunctions1(RUN_TYPE runType) { // DROOLS-5752 String str = "import java.time.Duration;\n" + "import " + Shift.class.getCanonicalName() + ";\n" + @@ -2492,15 +2564,16 @@ public void testAccumulateWithTwoFunctions1() { " System.out.println($shiftCount + \" \" + $totalMinutes);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Shift( OffsetDateTime.now()) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAccumulateWithTwoFunctions2() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithTwoFunctions2(RUN_TYPE runType) { // DROOLS-5752 String str = "import java.time.Duration;\n" + "import " + Shift.class.getCanonicalName() + ";\n" + @@ -2517,7 +2590,7 @@ public void testAccumulateWithTwoFunctions2() { " System.out.println($shiftCount + \" \" + $totalMinutes);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Shift( OffsetDateTime.now()) ); @@ -2577,8 +2650,9 @@ public static Duration between(OffsetDateTime start, OffsetDateTime end) { return Duration.between(start, end); } - @Test - public void testAccumulateNumberFromSum() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateNumberFromSum(RUN_TYPE runType) { String str = "import " + Shift.class.getCanonicalName() + ";" + "import " + AccumulateTest.class.getCanonicalName() + ";" @@ -2600,7 +2674,7 @@ public void testAccumulateNumberFromSum() { - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Shift shift = new Shift(OffsetDateTime.now()); @@ -2625,8 +2699,9 @@ private static int switchMachinesInAssignments(KieSession session, MrProcessAssi return session.fireAllRules(); } - @Test - public void testDoubleAccumulateNPE() { + @ParameterizedTest + @MethodSource("parameters") + public void testDoubleAccumulateNPE(RUN_TYPE runType) { // Prepare reproducing data. MrMachine machine2 = new MrMachine(); MrMachine machine3 = new MrMachine(); @@ -2651,7 +2726,7 @@ public void testDoubleAccumulateNPE() { "then\n" + " result.add($count);\n" + "end;"; - KieSession kieSession = getKieSession(rule); + KieSession kieSession = getKieSession(runType, rule); List result = new ArrayList<>(); kieSession.setGlobal("result", result); @@ -2731,8 +2806,9 @@ public static class MrMachine { } - @Test - public void testInlineAccumulateWithAnd() { + @ParameterizedTest + @MethodSource("parameters") + public void testInlineAccumulateWithAnd(RUN_TYPE runType) { // RHDM-1549 String str = "import " + Car.class.getCanonicalName() + ";" + @@ -2749,7 +2825,7 @@ public void testInlineAccumulateWithAnd() { " result.add($total);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -2780,8 +2856,9 @@ public void testInlineAccumulateWithAnd() { ksession.dispose(); } - @Test - public void testInlineMvelAccumulateWithAnd() { + @ParameterizedTest + @MethodSource("parameters") + public void testInlineMvelAccumulateWithAnd(RUN_TYPE runType) { // RHDM-1549 String str = "import " + Car.class.getCanonicalName() + ";" + @@ -2799,7 +2876,7 @@ public void testInlineMvelAccumulateWithAnd() { " result.add($total);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -2912,8 +2989,9 @@ public void setPrice(BigDecimal price) { } } - @Test - public void testAccumulateOnPartiallyReversibleFunction() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateOnPartiallyReversibleFunction(RUN_TYPE runType) { // DROOLS-5930 String str = "import accumulate " + CountingIntegerMaxAccumulateFunction.class.getCanonicalName() + " countingMax;\n" + @@ -2925,7 +3003,7 @@ public void testAccumulateOnPartiallyReversibleFunction() { " result.add($max);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); CountingIntegerMaxAccumulateFunction accFunction = CountingIntegerMaxAccumulateFunction.INSTANCE; @@ -2990,8 +3068,9 @@ public void resetAccumulateCount() { } } - @Test - public void testOneAccumulateOnPattern() { + @ParameterizedTest + @MethodSource("parameters") + public void testOneAccumulateOnPattern(RUN_TYPE runType) { // DROOLS-5938 String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -3004,7 +3083,7 @@ public void testOneAccumulateOnPattern() { " result.add($acc1.iterator().next());" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -3019,8 +3098,9 @@ public void testOneAccumulateOnPattern() { assertThat(result.get(0)).isEqualTo(lukas); } - @Test - public void testOneAccumulateOnPatternWithVarBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testOneAccumulateOnPatternWithVarBinding(RUN_TYPE runType) { // DROOLS-5938 String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -3033,7 +3113,7 @@ public void testOneAccumulateOnPatternWithVarBinding() { " result.add($acc1.iterator().next());" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -3047,8 +3127,9 @@ public void testOneAccumulateOnPatternWithVarBinding() { assertThat(result.get(0)).isEqualTo(lukas); } - @Test - public void testTwoAccumulatesOnPattern() { + @ParameterizedTest + @MethodSource("parameters") + public void testTwoAccumulatesOnPattern(RUN_TYPE runType) { // DROOLS-5938 String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -3064,7 +3145,7 @@ public void testTwoAccumulatesOnPattern() { " result.add($acc2.iterator().next());" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -3076,8 +3157,9 @@ public void testTwoAccumulatesOnPattern() { assertThat(result.get(0)).isEqualTo(Pair.create("Lukas", 35)); } - @Test - public void testTwoAccumulatesOnPatternWithVarBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testTwoAccumulatesOnPatternWithVarBinding(RUN_TYPE runType) { // DROOLS-5938 String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -3093,7 +3175,7 @@ public void testTwoAccumulatesOnPatternWithVarBinding() { " result.add($acc2.iterator().next());" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -3105,8 +3187,9 @@ public void testTwoAccumulatesOnPatternWithVarBinding() { assertThat(result.get(0)).isEqualTo(Pair.create("Lukas", 35)); } - @Test - public void testBindingOrderWithInlineAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindingOrderWithInlineAccumulate(RUN_TYPE runType) { // RHDM-1551 String str = "import " + Aclass.class.getCanonicalName() + ";\n" + @@ -3134,7 +3217,7 @@ public void testBindingOrderWithInlineAccumulate() { " result.add($eSet.iterator().next());" + "end"; - KieSession kSession = getKieSession( str ); + KieSession kSession = getKieSession(runType, str); List result = new ArrayList<>(); kSession.setGlobal("result", result); @@ -3151,8 +3234,9 @@ public void testBindingOrderWithInlineAccumulate() { kSession.dispose(); } - @Test - public void testBindingOrderWithInlineAccumulateAndLists() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindingOrderWithInlineAccumulateAndLists(RUN_TYPE runType) { // RHDM-1551 String str = "import " + Aclass.class.getCanonicalName() + ";\n" + @@ -3180,7 +3264,7 @@ public void testBindingOrderWithInlineAccumulateAndLists() { " result.add($eSet.iterator().next());" + "end"; - KieSession kSession = getKieSession( str ); + KieSession kSession = getKieSession(runType, str); List result = new ArrayList<>(); kSession.setGlobal("result", result); @@ -3197,8 +3281,9 @@ public void testBindingOrderWithInlineAccumulateAndLists() { kSession.dispose(); } - @Test - public void testBindingOrderWithInlineAccumulateAndListsAndFrom() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindingOrderWithInlineAccumulateAndListsAndFrom(RUN_TYPE runType) { // RHDM-1551 String str = "import " + Aclass.class.getCanonicalName() + ";\n" + @@ -3227,7 +3312,7 @@ public void testBindingOrderWithInlineAccumulateAndListsAndFrom() { " result.add($eSet.iterator().next());" + "end"; - KieSession kSession = getKieSession( str ); + KieSession kSession = getKieSession(runType, str); List result = new ArrayList<>(); kSession.setGlobal("result", result); @@ -3324,8 +3409,9 @@ public void setName(String name) { } } - @Test - public void testMultiAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultiAccumulate(RUN_TYPE runType) { // RHDM-1572 String str = "global java.util.List result;\n" + @@ -3340,7 +3426,7 @@ public void testMultiAccumulate() { " result.addAll($list);\n" + "end"; - KieSession kSession = getKieSession( str ); + KieSession kSession = getKieSession(runType, str); List result = new ArrayList<>(); kSession.setGlobal( "result", result ); @@ -3360,8 +3446,9 @@ public void testMultiAccumulate() { kSession.dispose(); } - @Test - public void testAccumulateWithExists() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithExists(RUN_TYPE runType) { // RHDM-1571 String str = "import " + Car.class.getCanonicalName() + ";" + @@ -3375,7 +3462,7 @@ public void testAccumulateWithExists() { " result.addAll($list);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal( "result", result ); @@ -3392,8 +3479,9 @@ public void testAccumulateWithExists() { ksession.dispose(); } - @Test - public void testAccumulateWithForAll() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithForAll(RUN_TYPE runType) { // DROOLS-6025 String str = "import " + GrandChild.class.getCanonicalName() + ";\n" + @@ -3408,7 +3496,7 @@ public void testAccumulateWithForAll() { " System.out.println(\"exec \" + $count);\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); GrandParent grandParent = new GrandParent(); GrandChild grandChild = new GrandChild(); @@ -3444,8 +3532,9 @@ public void setGrandChild(List grandChild) { } } - @Test - public void testAccumulateSubnetworkEval() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateSubnetworkEval(RUN_TYPE runType) { // DROOLS-6228 String str = "import java.time.Duration;\n" + @@ -3462,7 +3551,7 @@ public void testAccumulateSubnetworkEval() { " holder.set((int)holder.get() + $sum);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); AtomicReference holder = new AtomicReference<>(0); ksession.setGlobal("holder", holder); @@ -3475,8 +3564,9 @@ public void testAccumulateSubnetworkEval() { assertThat((int) holder.get()).isEqualTo(0); } - @Test - public void testInnerClassInAccumulatingFunction() { + @ParameterizedTest + @MethodSource("parameters") + public void testInnerClassInAccumulatingFunction(RUN_TYPE runType) { // DROOLS-6238 String str = "import java.util.*;\n" + @@ -3501,7 +3591,7 @@ public void testInnerClassInAccumulatingFunction() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 42)); ksession.insert(new Person("Edson", 38)); @@ -3553,8 +3643,9 @@ public List result() { } } - @Test - public void testAccumulateWithSameBindingVariable() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithSameBindingVariable(RUN_TYPE runType) { // DROOLS-6102 String str = "import java.util.*;\n" + @@ -3568,7 +3659,7 @@ public void testAccumulateWithSameBindingVariable() { " list.add( $tot2.intValue() ); \n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -3583,8 +3674,9 @@ public void testAccumulateWithSameBindingVariable() { assertThat((int) list.get(1)).isEqualTo(2); } - @Test - public void testAccumulateWithMaxCalendarNullDate() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithMaxCalendarNullDate(RUN_TYPE runType) { //DROOLS-4990 String str = "import " + StockTick.class.getCanonicalName() + ";\n" + @@ -3597,7 +3689,7 @@ public void testAccumulateWithMaxCalendarNullDate() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); StockTick st = new StockTick("RHT"); ksession.insert(st); @@ -3607,8 +3699,9 @@ public void testAccumulateWithMaxCalendarNullDate() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testSubnetworkTuple() { + @ParameterizedTest + @MethodSource("parameters") + public void testSubnetworkTuple(RUN_TYPE runType) { final String drl = "import java.math.*; " + "import " + InputDataTypes.class.getCanonicalName() + "; " + @@ -3624,7 +3717,7 @@ public void testSubnetworkTuple() { " result.add($min); " + "end"; - final KieSession ksession = getKieSession(drl); + final KieSession ksession = getKieSession(runType, drl); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -3685,8 +3778,9 @@ private GregorianCalendar calendarFromString(String inputString) { return GregorianCalendar.from( ZonedDateTime.from( DateTimeFormatter.ISO_DATE_TIME.parse(inputString))); } - @Test - public void testAccumulateCountWithExists() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateCountWithExists(RUN_TYPE runType) { // The following rule uses an accumulate to count all the name Strings for which at least one Person // of that name exists. Expected behavior: // - A name should be counted exactly once no matter how many Persons with that name exists. @@ -3704,7 +3798,7 @@ public void testAccumulateCountWithExists() { + " insert( new Result($count));\n" + " System.out.println(kcontext.getMatch().getObjects());\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ReteDumper.dumpRete(ksession); @@ -3725,8 +3819,9 @@ public void testAccumulateCountWithExists() { assertThat(results.iterator().next().getValue()).isEqualTo(2L); } - @Test - public void testAccumulateWithIndirectArgument() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithIndirectArgument(RUN_TYPE runType) { String str = "global java.util.List resultTotal; \n" + "global java.util.List resultPair; \n" + @@ -3745,7 +3840,7 @@ public void testAccumulateWithIndirectArgument() { " resultPair.add($pair);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List resultTotal = new ArrayList<>(); ksession.setGlobal("resultTotal", resultTotal); @@ -3766,8 +3861,9 @@ public void testAccumulateWithIndirectArgument() { assertThat(firstPair.getSecond()).isEqualTo("Mario"); } - @Test - public void testVariableWithMethodCallInAccFunc() { + @ParameterizedTest + @MethodSource("parameters") + public void testVariableWithMethodCallInAccFunc(RUN_TYPE runType) { final String str = "package org.drools.mvel.compiler\n" + "import " + ControlFact.class.getCanonicalName() + ";" + "import " + Payment.class.getCanonicalName() + ";" + @@ -3785,7 +3881,7 @@ public void testVariableWithMethodCallInAccFunc() { System.out.println(str); - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); final Payment payment = new Payment(); payment.setDueDate(Calendar.getInstance()); @@ -3799,8 +3895,9 @@ public void testVariableWithMethodCallInAccFunc() { assertThat(rules).isEqualTo(1); } - @Test - public void testVariableWithMethodCallInAccFuncSimple() { + @ParameterizedTest + @MethodSource("parameters") + public void testVariableWithMethodCallInAccFuncSimple(RUN_TYPE runType) { final String str = "package org.drools.mvel.compiler\n" + "import " + FactA.class.getCanonicalName() + ";" + "rule r1\n" + @@ -3814,7 +3911,7 @@ public void testVariableWithMethodCallInAccFuncSimple() { System.out.println(str); - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); final FactA factA = new FactA(); factA.setValue(1); @@ -3863,8 +3960,9 @@ public void setValue(Integer value) { } } - @Test - public void testAccumulateOnTwoPatterns() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateOnTwoPatterns(RUN_TYPE runType) { // DROOLS-5738 String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -3876,7 +3974,7 @@ public void testAccumulateOnTwoPatterns() { " insert($sum);\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 46 ) ); ksession.insert( new Person( "Mark", 44 ) ); @@ -3888,8 +3986,9 @@ public void testAccumulateOnTwoPatterns() { assertThat(results.get(0)).isEqualTo(90); } - @Test - public void testPositionalAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testPositionalAccumulate(RUN_TYPE runType) { // DROOLS-6128 String str = "import " + Result.class.getCanonicalName() + ";" + @@ -3912,7 +4011,7 @@ public void testPositionalAccumulate() { " insert(new Result($sum));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.fireAllRules(); @@ -3921,8 +4020,9 @@ public void testPositionalAccumulate() { assertThat(results.iterator().next().getValue()).isEqualTo(112); } - @Test - public void testAccumulateOnSet() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateOnSet(RUN_TYPE runType) { String str = "import java.util.*;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -3933,7 +4033,7 @@ public void testAccumulateOnSet() { " holder.set($size); \n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); AtomicReference holder = new AtomicReference<>(0); ksession.setGlobal("holder", holder); @@ -3954,8 +4054,9 @@ public void testAccumulateOnSet() { assertThat((int) holder.get()).isEqualTo(4); } - @Test - public void testNestedAccumulates() { + @ParameterizedTest + @MethodSource("parameters") + public void testNestedAccumulates(RUN_TYPE runType) { // DROOLS-6202 String str = "import java.util.*;\n" + @@ -3970,7 +4071,7 @@ public void testNestedAccumulates() { " holder.set($max); \n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); AtomicReference holder = new AtomicReference<>(0); ksession.setGlobal("holder", holder); @@ -3991,8 +4092,9 @@ public void testNestedAccumulates() { assertThat((int) holder.get()).isEqualTo(4); } - @Test - public void testIfInInlineAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testIfInInlineAccumulate(RUN_TYPE runType) { // DROOLS-6429 String str = "import " + Person.class.getCanonicalName() + ";\n" + "rule R when\n" + @@ -4006,7 +4108,7 @@ public void testIfInInlineAccumulate() { " insert($avg);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Sofia", 10)); FactHandle fh_Mark = ksession.insert(new Person("Mark", 37)); @@ -4026,8 +4128,9 @@ public void testIfInInlineAccumulate() { assertThat(results).contains(36); } - @Test - public void testBindVariableUsedInSubsequentAccumulateString() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindVariableUsedInSubsequentAccumulateString(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List result;\n" + @@ -4044,7 +4147,7 @@ public void testBindVariableUsedInSubsequentAccumulateString() { " result.add($maxAge);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -4058,8 +4161,9 @@ public void testBindVariableUsedInSubsequentAccumulateString() { assertThat(result).containsExactly(50); } - @Test - public void testBindVariableUsedInSubsequentAccumulateBigDecimal() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindVariableUsedInSubsequentAccumulateBigDecimal(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List result;\n" + @@ -4076,7 +4180,7 @@ public void testBindVariableUsedInSubsequentAccumulateBigDecimal() { " result.add($maxAge);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -4090,8 +4194,9 @@ public void testBindVariableUsedInSubsequentAccumulateBigDecimal() { assertThat(result).containsExactly(50); } - @Test - public void testCollectAfterAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testCollectAfterAccumulate(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "import " + BigDecimal.class.getCanonicalName() + ";\n" + "import " + ArrayList.class.getCanonicalName() + ";\n" + @@ -4109,7 +4214,7 @@ public void testCollectAfterAccumulate() { " result.addAll($list)\n" + "end"; try { - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -4130,8 +4235,9 @@ public void testCollectAfterAccumulate() { } } - @Test - public void testExistsFromAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testExistsFromAccumulate(RUN_TYPE runType) { // DROOLS-6959 String str = "import " + Set.class.getCanonicalName() + ";\n" + @@ -4140,15 +4246,16 @@ public void testExistsFromAccumulate() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert("String1"); ksession.insert("String2"); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAccumulateWithBetaConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithBetaConstraint(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -4161,7 +4268,7 @@ public void testAccumulateWithBetaConstraint() { " insert(new Result($sum + \":\" + $i));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(5); ksession.insert(new Person("Mark", 37)); @@ -4175,8 +4282,9 @@ public void testAccumulateWithBetaConstraint() { assertThat(results).containsExactly(new Result("75:5")); } - @Test - public void testJoinInAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinInAccumulate(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -4188,7 +4296,7 @@ public void testJoinInAccumulate() { " insert(new Result($sum));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -4207,8 +4315,9 @@ public void testJoinInAccumulate() { assertThat(results).containsExactlyInAnyOrder(new Result(0), new Result(75)); } - @Test - public void testAccumulateSumMultipleParametersExpression() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateSumMultipleParametersExpression(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -4220,8 +4329,8 @@ public void testAccumulateSumMultipleParametersExpression() { " insert(new Result($sum));\n" + "end"; - Results results = createKieBuilder(str).getResults(); - if (testRunType.isExecutableModel()) { + Results results = createKieBuilder(runType, str).getResults(); + if (runType.isExecutableModel()) { assertThat(results.getMessages(Message.Level.ERROR).get(0).getText().contains( "Function \"sum\" cannot have more than 1 parameter")).isTrue(); } else { @@ -4230,8 +4339,9 @@ public void testAccumulateSumMultipleParametersExpression() { } } - @Test - public void testAccumulateSumUnaryExpression() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateSumUnaryExpression(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -4243,7 +4353,7 @@ public void testAccumulateSumUnaryExpression() { " insert(new Result($sum));\n" + "end"; - KieSession kieSession = getKieSession( str ); + KieSession kieSession = getKieSession(runType, str); kieSession.insert(new Person("Mark", 37)); kieSession.insert(new Person("Edson", 35)); @@ -4256,8 +4366,9 @@ public void testAccumulateSumUnaryExpression() { assertThat(results.iterator().next().getValue()).isEqualTo(-77); } - @Test - public void testAccumulateSumBinaryExpWithNestedUnaryExpression() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateSumBinaryExpWithNestedUnaryExpression(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -4269,7 +4380,7 @@ public void testAccumulateSumBinaryExpWithNestedUnaryExpression() { " insert(new Result($sum));\n" + "end"; - KieSession kieSession = getKieSession( str ); + KieSession kieSession = getKieSession(runType, str); kieSession.insert(new Person("Mark", 37)); kieSession.insert(new Person("Edson", 35)); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BaseModelTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BaseModelTest.java index 5d99cc628fe..20e3bfe6141 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BaseModelTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BaseModelTest.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.UUID; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.drools.compiler.kie.builder.impl.DrlProject; import org.drools.compiler.kie.builder.impl.InternalKieModule; @@ -28,9 +29,6 @@ import org.drools.core.reteoo.ObjectTypeNode; import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.model.codegen.ExecutableModelProject; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.KieFileSystem; @@ -47,7 +45,6 @@ import static org.drools.model.codegen.execmodel.BaseModelTest.RUN_TYPE.PATTERN_WITH_ALPHA_NETWORK; import static org.drools.model.codegen.execmodel.BaseModelTest.RUN_TYPE.STANDARD_WITH_ALPHA_NETWORK; -@RunWith(Parameterized.class) public abstract class BaseModelTest { public enum RUN_TYPE { PATTERN_DSL( true, false ), @@ -72,66 +69,55 @@ public boolean isExecutableModel() { } } - final static Object[] PLAIN = { - RUN_TYPE.STANDARD_FROM_DRL, - PATTERN_DSL, - }; - - final static Object[] WITH_ALPHA_NETWORK = { - RUN_TYPE.STANDARD_FROM_DRL, - PATTERN_DSL, - STANDARD_WITH_ALPHA_NETWORK, - PATTERN_WITH_ALPHA_NETWORK, - }; - - - @Parameters(name = "{0}") - public static Object[] params() { + + public static Stream parameters() { if(Boolean.valueOf(System.getProperty("alphanetworkCompilerEnabled"))) { - return WITH_ALPHA_NETWORK; + return Stream.of(RUN_TYPE.STANDARD_FROM_DRL, + PATTERN_DSL, + STANDARD_WITH_ALPHA_NETWORK, + PATTERN_WITH_ALPHA_NETWORK); } else { - return PLAIN; + return Stream.of(RUN_TYPE.STANDARD_FROM_DRL, + PATTERN_DSL); } } - protected final CompilerTest.RUN_TYPE testRunType; - - public BaseModelTest( CompilerTest.RUN_TYPE testRunType ) { - this.testRunType = testRunType; + public BaseModelTest() { } - protected KieSession getKieSession(String... rules) { + protected KieSession getKieSession(BaseModelTest.RUN_TYPE testRunType, String... rules) { KieModuleModel model = testRunType.isAlphaNetworkCompiler() ? getKieModuleModelWithAlphaNetworkCompiler() : null; - return getKieSession(model, rules); + return getKieSession(testRunType, model, rules); } + - protected KieSession getKieSession(KieModuleModel model, String... stringRules) { - return getKieContainer( model, stringRules ).newKieSession(); + protected KieSession getKieSession(BaseModelTest.RUN_TYPE testRunType, KieModuleModel model, String... stringRules) { + return getKieContainer(testRunType, model, stringRules ).newKieSession(); } - protected KieContainer getKieContainer( KieModuleModel model, String... stringRules ) { - return getKieContainer( model, toKieFiles( stringRules ) ); + protected KieContainer getKieContainer(BaseModelTest.RUN_TYPE testRunType, KieModuleModel model, String... stringRules ) { + return getKieContainer(testRunType, model, toKieFiles( stringRules ) ); } - protected KieContainer getKieContainer( KieModuleModel model, KieFile... stringRules ) { + protected KieContainer getKieContainer(BaseModelTest.RUN_TYPE testRunType, KieModuleModel model, KieFile... stringRules ) { KieServices ks = KieServices.get(); ReleaseId releaseId = ks.newReleaseId( "org.kie", "kjar-test-" + UUID.randomUUID(), "1.0" ); - KieBuilder kieBuilder = createKieBuilder( ks, model, releaseId, stringRules ); + KieBuilder kieBuilder = createKieBuilder(testRunType, ks, model, releaseId, stringRules ); return ks.newKieContainer( releaseId ); } - protected KieBuilder createKieBuilder( String... stringRules ) { + protected KieBuilder createKieBuilder(BaseModelTest.RUN_TYPE testRunType, String... stringRules ) { KieServices ks = KieServices.get(); ReleaseId releaseId = ks.newReleaseId( "org.kie", "kjar-test-" + UUID.randomUUID(), "1.0" ); - return createKieBuilder( ks, null, releaseId, false, toKieFiles( stringRules ) ); + return createKieBuilder(testRunType, ks, null, releaseId, false, toKieFiles( stringRules ) ); } - protected KieBuilder createKieBuilder( KieServices ks, KieModuleModel model, ReleaseId releaseId, KieFile... stringRules ) { - return createKieBuilder( ks, model, releaseId, true, stringRules ); + protected KieBuilder createKieBuilder(BaseModelTest.RUN_TYPE testRunType, KieServices ks, KieModuleModel model, ReleaseId releaseId, KieFile... stringRules ) { + return createKieBuilder(testRunType, ks, model, releaseId, true, stringRules ); } - protected KieBuilder createKieBuilder( KieServices ks, KieModuleModel model, ReleaseId releaseId, boolean failIfBuildError, KieFile... stringRules ) { + protected KieBuilder createKieBuilder(BaseModelTest.RUN_TYPE testRunType, KieServices ks, KieModuleModel model, ReleaseId releaseId, boolean failIfBuildError, KieFile... stringRules ) { ks.getRepository().removeKieModule( releaseId ); KieFileSystem kfs = ks.newKieFileSystem(); @@ -170,20 +156,20 @@ public static List getObjectsIntoList(KieSession ksession, Class clazz return ksession.getInstancesOf(clazz).stream().collect(Collectors.toList()); } - protected void createAndDeployJar( KieServices ks, ReleaseId releaseId, String... drls ) { - createAndDeployJar( ks, null, releaseId, drls ); + protected void createAndDeployJar(BaseModelTest.RUN_TYPE testRunType, KieServices ks, ReleaseId releaseId, String... drls ) { + createAndDeployJar(testRunType, ks, null, releaseId, drls ); } - protected void createAndDeployJar( KieServices ks, ReleaseId releaseId, KieFile... ruleFiles ) { - createAndDeployJar( ks, null, releaseId, ruleFiles ); + protected void createAndDeployJar(BaseModelTest.RUN_TYPE testRunType, KieServices ks, ReleaseId releaseId, KieFile... ruleFiles ) { + createAndDeployJar(testRunType, ks, null, releaseId, ruleFiles ); } - protected void createAndDeployJar( KieServices ks, KieModuleModel model, ReleaseId releaseId, String... drls ) { - createAndDeployJar( ks, model, releaseId, toKieFiles( drls ) ); + protected void createAndDeployJar(BaseModelTest.RUN_TYPE testRunType, KieServices ks, KieModuleModel model, ReleaseId releaseId, String... drls ) { + createAndDeployJar(testRunType, ks, model, releaseId, toKieFiles( drls ) ); } - protected void createAndDeployJar( KieServices ks, KieModuleModel model, ReleaseId releaseId, KieFile... ruleFiles ) { - KieBuilder kieBuilder = createKieBuilder( ks, model, releaseId, ruleFiles ); + protected void createAndDeployJar(BaseModelTest.RUN_TYPE testRunType, KieServices ks, KieModuleModel model, ReleaseId releaseId, KieFile... ruleFiles ) { + KieBuilder kieBuilder = createKieBuilder(testRunType, ks, model, releaseId, ruleFiles ); InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModule(); ks.getRepository().addKieModule( kieModule ); } diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BetaConditionTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BetaConditionTest.java index 03ba9de14c8..2c0eb97cdf5 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BetaConditionTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BetaConditionTest.java @@ -22,7 +22,8 @@ import java.util.List; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; @@ -30,12 +31,10 @@ // DROOLS-5852 public class BetaConditionTest extends BaseModelTest { - public BetaConditionTest(RUN_TYPE testRunType ) { - super( testRunType ); - } - @Test - public void betaCheckTwoConditionsExplicit() { + @ParameterizedTest + @MethodSource("parameters") + public void betaCheckTwoConditionsExplicit(RUN_TYPE runType) { final String drl = "global java.util.List list\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -46,11 +45,12 @@ public void betaCheckTwoConditionsExplicit() { " list.add($p2);" + "end\n"; - verify(drl, 2); + verify(runType, drl, 2); } - @Test - public void betaCheckTwoConditionsImplicit() { + @ParameterizedTest + @MethodSource("parameters") + public void betaCheckTwoConditionsImplicit(RUN_TYPE runType) { final String drl = "global java.util.List list\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -61,11 +61,12 @@ public void betaCheckTwoConditionsImplicit() { " list.add($p2);" + "end\n"; - verify(drl, 2); + verify(runType, drl, 2); } - @Test - public void betaCheckORExplicit() { + @ParameterizedTest + @MethodSource("parameters") + public void betaCheckORExplicit(RUN_TYPE runType) { final String drl = "global java.util.List list\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -76,11 +77,12 @@ public void betaCheckORExplicit() { " list.add($p2);" + "end\n"; - verify(drl, 3); + verify(runType, drl, 3); } - @Test - public void betaCheckORImplicit() { + @ParameterizedTest + @MethodSource("parameters") + public void betaCheckORImplicit(RUN_TYPE runType) { final String str = "global java.util.List list\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -91,11 +93,12 @@ public void betaCheckORImplicit() { " list.add($p2);" + "end\n"; - verify(str, 3); + verify(runType, str, 3); } - @Test - public void betaCheckExplicit() { + @ParameterizedTest + @MethodSource("parameters") + public void betaCheckExplicit(RUN_TYPE runType) { final String drl = "global java.util.List list\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -106,12 +109,13 @@ public void betaCheckExplicit() { " list.add($p2);" + "end\n"; - verify(drl, 2); + verify(runType, drl, 2); } - @Test - public void betaCheckImplicit() { + @ParameterizedTest + @MethodSource("parameters") + public void betaCheckImplicit(RUN_TYPE runType) { final String drl = "global java.util.List list\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -122,11 +126,12 @@ public void betaCheckImplicit() { " list.add($p2);" + "end\n"; - verify(drl, 2); + verify(runType, drl, 2); } - @Test - public void checkBooleanExplicit() { + @ParameterizedTest + @MethodSource("parameters") + public void checkBooleanExplicit(RUN_TYPE runType) { final String str = "global java.util.List list\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -136,12 +141,13 @@ public void checkBooleanExplicit() { " list.add($p2);" + "end\n"; - verify(str, 1); + verify(runType, str, 1); } - @Test - public void checkBooleanImplicit() { + @ParameterizedTest + @MethodSource("parameters") + public void checkBooleanImplicit(RUN_TYPE runType) { final String drl = "global java.util.List list\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -151,11 +157,11 @@ public void checkBooleanImplicit() { " list.add($p2);" + "end\n"; - verify(drl, 1); + verify(runType, drl, 1); } - private void verify(String str, int numberOfResults) { - KieSession ksession = getKieSession(str); + private void verify(RUN_TYPE runType, String str, int numberOfResults) { + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("list", results); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BigPojoExecModelGenerationTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BigPojoExecModelGenerationTest.java index 2611f306c22..776e0e7b23b 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BigPojoExecModelGenerationTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BigPojoExecModelGenerationTest.java @@ -21,7 +21,7 @@ import java.util.UUID; import org.drools.model.codegen.ExecutableModelProject; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.KieFileSystem; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BindingTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BindingTest.java index 9512691161f..93546bc13a9 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BindingTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BindingTest.java @@ -22,19 +22,17 @@ import java.util.List; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class BindingTest extends BaseModelTest { - public BindingTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testBindUnaryBooleanExpression() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindUnaryBooleanExpression(RUN_TYPE runType) { // RHDM-1612 final String str = "global java.util.List result;\n" + @@ -80,7 +78,7 @@ public void testBindUnaryBooleanExpression() { " result.add(\"R8\");\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal( "result", result ); @@ -105,8 +103,9 @@ public void testBindUnaryBooleanExpression() { assertThat(result.contains("R8")).isFalse(); } - @Test - public void testBindMethodCall() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindMethodCall(RUN_TYPE runType) { // DROOLS-6521 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -118,7 +117,7 @@ public void testBindMethodCall() { " result.add($value);\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal( "result", result ); @@ -130,8 +129,9 @@ public void testBindMethodCall() { assertThat((char) result.get(0)).isEqualTo('r'); } - @Test - public void testEnclosedBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testEnclosedBinding(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List result;\n" + @@ -141,7 +141,7 @@ public void testEnclosedBinding() { " result.add($n);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -152,8 +152,9 @@ public void testEnclosedBinding() { assertThat(result).containsExactly("Mario"); } - @Test - public void testComplexEnclosedBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexEnclosedBinding(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List result;\n" + @@ -163,7 +164,7 @@ public void testComplexEnclosedBinding() { " result.add($n);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -174,8 +175,9 @@ public void testComplexEnclosedBinding() { assertThat(result).containsExactly("Mario"); } - @Test - public void testComplexEnclosedDoubleBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexEnclosedDoubleBinding(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List result;\n" + @@ -185,7 +187,7 @@ public void testComplexEnclosedDoubleBinding() { " result.add($n);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -196,8 +198,9 @@ public void testComplexEnclosedDoubleBinding() { assertThat(result).containsExactly("Mario"); } - @Test - public void testBindingOnRight() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindingOnRight(RUN_TYPE runType) { // DROOLS-6611 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -208,7 +211,7 @@ public void testBindingOnRight() { " result.add($a);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -219,8 +222,9 @@ public void testBindingOnRight() { assertThat(result).containsExactly(40); } - @Test - public void testBindingOnBoth() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindingOnBoth(RUN_TYPE runType) { // DROOLS-6611 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -232,7 +236,7 @@ public void testBindingOnBoth() { " result.add($a);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -243,8 +247,9 @@ public void testBindingOnBoth() { assertThat(result).containsExactlyInAnyOrder("Mario", 40); } - @Test - public void test3BindingOn3Conditions() { + @ParameterizedTest + @MethodSource("parameters") + public void test3BindingOn3Conditions(RUN_TYPE runType) { // DROOLS-6611 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -257,7 +262,7 @@ public void test3BindingOn3Conditions() { " result.add($l);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -269,8 +274,9 @@ public void test3BindingOn3Conditions() { assertThat(result).containsExactlyInAnyOrder("Mario", 40, "Cheddar"); } - @Test - public void test2BindingOn3Conditions() { + @ParameterizedTest + @MethodSource("parameters") + public void test2BindingOn3Conditions(RUN_TYPE runType) { // DROOLS-6611 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -282,7 +288,7 @@ public void test2BindingOn3Conditions() { " result.add($l);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -294,8 +300,9 @@ public void test2BindingOn3Conditions() { assertThat(result).containsExactlyInAnyOrder(40, "Cheddar"); } - @Test - public void testBindingOnRightWithOr() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindingOnRightWithOr(RUN_TYPE runType) { // DROOLS-6920 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -306,7 +313,7 @@ public void testBindingOnRightWithOr() { " result.add($a);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -317,8 +324,9 @@ public void testBindingOnRightWithOr() { assertThat(result).containsExactly(40); } - @Test - public void testBindingOnBothWithOr() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindingOnBothWithOr(RUN_TYPE runType) { // DROOLS-6920 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -330,7 +338,7 @@ public void testBindingOnBothWithOr() { " result.add($a);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -341,8 +349,9 @@ public void testBindingOnBothWithOr() { assertThat(result).containsExactlyInAnyOrder("Toshiya", 40); } - @Test - public void test3BindingOn3ConditionsWithOr() { + @ParameterizedTest + @MethodSource("parameters") + public void test3BindingOn3ConditionsWithOr(RUN_TYPE runType) { // DROOLS-6920 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -355,7 +364,7 @@ public void test3BindingOn3ConditionsWithOr() { " result.add($l);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -367,8 +376,9 @@ public void test3BindingOn3ConditionsWithOr() { assertThat(result).containsExactlyInAnyOrder("Toshiya", 10, "Cheddar"); } - @Test - public void test2BindingOn3ConditionsWithOr() { + @ParameterizedTest + @MethodSource("parameters") + public void test2BindingOn3ConditionsWithOr(RUN_TYPE runType) { // DROOLS-6920 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -380,7 +390,7 @@ public void test2BindingOn3ConditionsWithOr() { " result.add($l);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -392,8 +402,9 @@ public void test2BindingOn3ConditionsWithOr() { assertThat(result).containsExactlyInAnyOrder(10, "Cheddar"); } - @Test - public void test3BindingOn3ConditionsWithAndOr() { + @ParameterizedTest + @MethodSource("parameters") + public void test3BindingOn3ConditionsWithAndOr(RUN_TYPE runType) { // DROOLS-6920 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -406,7 +417,7 @@ public void test3BindingOn3ConditionsWithAndOr() { " result.add($l);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -434,8 +445,9 @@ public void test3BindingOn3ConditionsWithAndOr() { assertThat(result).isEmpty(); } - @Test - public void test3BindingOn3ConditionsWithOrAnd() { + @ParameterizedTest + @MethodSource("parameters") + public void test3BindingOn3ConditionsWithOrAnd(RUN_TYPE runType) { // DROOLS-6920 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -448,7 +460,7 @@ public void test3BindingOn3ConditionsWithOrAnd() { " result.add($l);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -476,8 +488,9 @@ public void test3BindingOn3ConditionsWithOrAnd() { assertThat(result).isEmpty(); } - @Test - public void testConstraintExpression() { + @ParameterizedTest + @MethodSource("parameters") + public void testConstraintExpression(RUN_TYPE runType) { String str = "package constraintexpression\n" + "\n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -492,7 +505,7 @@ public void testConstraintExpression() { " booleanListGlobal.add($booleanVariable); \n " + "end \n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); try { final List booleanListGlobal = new ArrayList<>(); ksession.setGlobal("booleanListGlobal", booleanListGlobal); @@ -511,8 +524,9 @@ public void testConstraintExpression() { * enclosed in parentheses. This is intentional behaviour, agreed in discussions, * which may be revised in the future. */ - @Test - public void testIgnoreConstraintInParentheses() { + @ParameterizedTest + @MethodSource("parameters") + public void testIgnoreConstraintInParentheses(RUN_TYPE runType) { String str = "package constraintexpression\n" + "\n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -527,7 +541,7 @@ public void testIgnoreConstraintInParentheses() { " booleanListGlobal.add($booleanVariable); \n " + "end \n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); try { final List booleanListGlobal = new ArrayList<>(); ksession.setGlobal("booleanListGlobal", booleanListGlobal); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BuildFromDescrTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BuildFromDescrTest.java index 2a1f216cf96..44f176c2251 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BuildFromDescrTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BuildFromDescrTest.java @@ -25,7 +25,7 @@ import org.drools.model.codegen.ExecutableModelProject; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.runtime.KieSession; import org.kie.internal.utils.KieHelper; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BuildFromKJarTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BuildFromKJarTest.java index 865a9384474..f0fe20d1cb0 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BuildFromKJarTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/BuildFromKJarTest.java @@ -21,10 +21,9 @@ import java.util.List; import org.drools.compiler.kie.builder.impl.InternalKieModule; -import org.drools.compiler.kie.builder.impl.KieBuilderImpl; import org.drools.model.codegen.ExecutableModelProject; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.KieFileSystem; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CepTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CepTest.java index f1a4080f8b5..c44597ea046 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CepTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CepTest.java @@ -37,7 +37,8 @@ import org.drools.model.codegen.execmodel.domain.StockFact; import org.drools.model.codegen.execmodel.domain.StockTick; import org.drools.model.codegen.execmodel.domain.StockTickEx; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieServices; import org.kie.api.builder.model.KieModuleModel; import org.kie.api.conf.EventProcessingOption; @@ -53,9 +54,6 @@ public class CepTest extends BaseModelTest { - public CepTest( RUN_TYPE testRunType ) { - super( testRunType ); - } public static KieModuleModel getCepKieModuleModel() { KieModuleModel kproj = KieServices.get().newKieModuleModel(); @@ -67,8 +65,9 @@ public static KieModuleModel getCepKieModuleModel() { return kproj; } - @Test - public void testAfter() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testAfter(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + @@ -78,7 +77,7 @@ public void testAfter() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( new StockTick( "DROO" ) ); @@ -93,8 +92,9 @@ public void testAfter() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testNegatedAfter() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testNegatedAfter(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + @@ -104,7 +104,7 @@ public void testNegatedAfter() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( new StockTick( "DROO" ) ); @@ -119,8 +119,9 @@ public void testNegatedAfter() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAfterWithEntryPoints() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testAfterWithEntryPoints(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + @@ -130,7 +131,7 @@ public void testAfterWithEntryPoints() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.getEntryPoint( "ep1" ).insert( new StockTick( "DROO" ) ); @@ -148,8 +149,9 @@ public void testAfterWithEntryPoints() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testSlidingWindow() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testSlidingWindow(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "rule R when\n" + @@ -158,7 +160,7 @@ public void testSlidingWindow() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); clock.advanceTime( 1, TimeUnit.SECONDS ); @@ -173,8 +175,9 @@ public void testSlidingWindow() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testNotAfter() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testNotAfter(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + @@ -184,7 +187,7 @@ public void testNotAfter() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( new StockTick("DROO") ); @@ -202,8 +205,9 @@ public void testNotAfter() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testDeclaredSlidingWindow() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testDeclaredSlidingWindow(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "declare window DeclaredWindow\n" + @@ -215,7 +219,7 @@ public void testDeclaredSlidingWindow() throws Exception { " System.out.println($a.getCompany());\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); clock.advanceTime( 2, TimeUnit.SECONDS ); @@ -230,8 +234,9 @@ public void testDeclaredSlidingWindow() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testDeclaredSlidingWindowWithEntryPoint() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testDeclaredSlidingWindowWithEntryPoint(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "declare window DeclaredWindow\n" + @@ -243,7 +248,7 @@ public void testDeclaredSlidingWindowWithEntryPoint() throws Exception { " System.out.println($a.getCompany());\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); EntryPoint ep = ksession.getEntryPoint("ticks"); @@ -260,8 +265,9 @@ public void testDeclaredSlidingWindowWithEntryPoint() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testDeclaredSlidingWindowOnEventInTypeDeclaration() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testDeclaredSlidingWindowOnEventInTypeDeclaration(RUN_TYPE runType) throws Exception { String str = "declare String\n" + " @role( event )\n" + @@ -275,7 +281,7 @@ public void testDeclaredSlidingWindowOnEventInTypeDeclaration() throws Exception " System.out.println($a);\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( "ACME" ); @@ -284,8 +290,9 @@ public void testDeclaredSlidingWindowOnEventInTypeDeclaration() throws Exception assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testDeclaredSlidingWindowOnDeclaredType() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testDeclaredSlidingWindowOnDeclaredType(RUN_TYPE runType) throws Exception { String str = "declare MyEvent\n" + " @role( event )\n" + @@ -303,13 +310,14 @@ public void testDeclaredSlidingWindowOnDeclaredType() throws Exception { " System.out.println($a);\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testDeclaredSlidingWindowWith2Arguments() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testDeclaredSlidingWindowWith2Arguments(RUN_TYPE runType) throws Exception { String str = "declare String\n" + " @role( event )\n" + @@ -323,7 +331,7 @@ public void testDeclaredSlidingWindowWith2Arguments() throws Exception { " System.out.println($a);\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( "ACME" ); @@ -332,8 +340,9 @@ public void testDeclaredSlidingWindowWith2Arguments() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testWithDeclaredEvent() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testWithDeclaredEvent(RUN_TYPE runType) throws Exception { String str = "import " + StockFact.class.getCanonicalName() + ";\n" + "declare StockFact @role( event ) end;\n" + @@ -344,7 +353,7 @@ public void testWithDeclaredEvent() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( new StockFact( "DROO" ) ); @@ -359,8 +368,9 @@ public void testWithDeclaredEvent() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testExpireEventOnEndTimestamp() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testExpireEventOnEndTimestamp(RUN_TYPE runType) throws Exception { String str = "package org.drools.compiler;\n" + "import " + StockTick.class.getCanonicalName() + ";\n" + @@ -374,7 +384,7 @@ public void testExpireEventOnEndTimestamp() throws Exception { " resultsAfter.add( $b );\n" + "end"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); List resultsAfter = new ArrayList(); @@ -393,8 +403,9 @@ public void testExpireEventOnEndTimestamp() throws Exception { assertThat(resultsAfter.size()).isEqualTo(1); } - @Test - public void testExpireEventOnEndTimestampWithDeclaredEvent() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testExpireEventOnEndTimestampWithDeclaredEvent(RUN_TYPE runType) throws Exception { String str = "package org.drools.compiler;\n" + "import " + StockFact.class.getCanonicalName() + ";\n" + @@ -413,7 +424,7 @@ public void testExpireEventOnEndTimestampWithDeclaredEvent() throws Exception { " resultsAfter.add( $b );\n" + "end"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); List resultsAfter = new ArrayList(); @@ -432,8 +443,9 @@ public void testExpireEventOnEndTimestampWithDeclaredEvent() throws Exception { assertThat(resultsAfter.size()).isEqualTo(1); } - @Test - public void testExpires() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testExpires(RUN_TYPE runType) throws Exception { String str = "package org.drools.compiler;\n" + "import " + StockFact.class.getCanonicalName() + ";\n" + @@ -449,7 +461,7 @@ public void testExpires() throws Exception { "then\n" + "end"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert(new StockFact("DROO")); @@ -463,8 +475,9 @@ public void testExpires() throws Exception { assertThat(ksession.getObjects().size()).isEqualTo(0); } - @Test - public void testDeclareAndExpires() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testDeclareAndExpires(RUN_TYPE runType) throws Exception { String str = "package org.drools.compiler;\n" + "declare StockFact\n" + @@ -480,7 +493,7 @@ public void testDeclareAndExpires() throws Exception { "then\n" + "end"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); FactType stockFactType = ksession.getKieBase().getFactType("org.drools.compiler", "StockFact"); @@ -498,8 +511,9 @@ public void testDeclareAndExpires() throws Exception { assertThat(ksession.getObjects().size()).isEqualTo(0); } - @Test - public void testNoEvent() { + @ParameterizedTest + @MethodSource("parameters") + public void testNoEvent(RUN_TYPE runType) { String str = "declare BaseEvent\n" + " @role(event)\n" + @@ -526,12 +540,13 @@ public void testNoEvent() { "\n" + "end"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testIntervalTimer() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testIntervalTimer(RUN_TYPE runType) throws Exception { String str = ""; str += "package org.simple \n"; str += "global java.util.List list \n"; @@ -542,7 +557,7 @@ public void testIntervalTimer() throws Exception { str += " list.add(\"fired\"); \n"; str += "end \n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); List list = new ArrayList(); @@ -576,8 +591,9 @@ public void testIntervalTimer() throws Exception { assertThat(list.size()).isEqualTo(3); } - @Test - public void testAfterWithAnd() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testAfterWithAnd(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + @@ -587,7 +603,7 @@ public void testAfterWithAnd() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( new StockTick( "DROO" ) ); @@ -602,8 +618,9 @@ public void testAfterWithAnd() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testAfterOnLongFields() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testAfterOnLongFields(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + @@ -613,7 +630,7 @@ public void testAfterOnLongFields() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( new StockTick( "DROO" ).setTimeField( 0 ) ); @@ -626,8 +643,9 @@ public void testAfterOnLongFields() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testAfterOnDateFields() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testAfterOnDateFields(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + @@ -637,7 +655,7 @@ public void testAfterOnDateFields() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( new StockTick( "DROO" ).setTimeField( 0 ) ); @@ -650,8 +668,9 @@ public void testAfterOnDateFields() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testAfterOnDateFieldsWithBinding() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testAfterOnDateFieldsWithBinding(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + @@ -661,7 +680,7 @@ public void testAfterOnDateFieldsWithBinding() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); clock.advanceTime( 100, TimeUnit.MILLISECONDS ); @@ -675,8 +694,9 @@ public void testAfterOnDateFieldsWithBinding() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testAfterOnFactAndField() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testAfterOnFactAndField(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + @@ -686,7 +706,7 @@ public void testAfterOnFactAndField() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( new StockTick( "DROO" ).setTimeField( 0 ) ); @@ -701,8 +721,9 @@ public void testAfterOnFactAndField() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testComplexTimestamp() { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexTimestamp(RUN_TYPE runType) { final String str = "import " + Message.class.getCanonicalName() + "\n" + "declare " + Message.class.getCanonicalName() + "\n" + @@ -711,7 +732,7 @@ public void testComplexTimestamp() { " @duration( getProperties().get( 'duration' ) + 1 ) \n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); try { final Message msg = new Message(); @@ -759,8 +780,9 @@ public void setDuration(final Long duration) { } } - @Test - public void testTimerWithMillisPrecision() { + @ParameterizedTest + @MethodSource("parameters") + public void testTimerWithMillisPrecision(RUN_TYPE runType) { final String drl = "import " + MyEvent.class.getCanonicalName() + "\n" + "import " + AtomicInteger.class.getCanonicalName() + "\n" + "declare MyEvent\n" + @@ -781,7 +803,7 @@ public void testTimerWithMillisPrecision() { " }\n" + "end"; - KieSession ksession = getKieSession(getCepKieModuleModel(), drl); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), drl); try { final long now = 1000; @@ -911,8 +933,9 @@ public void setPrice( Double price ) { } } - @Test - public void testCollectWithDeclaredWindow() { + @ParameterizedTest + @MethodSource("parameters") + public void testCollectWithDeclaredWindow(RUN_TYPE runType) { // DROOLS-4492 final String drl = "import " + Quote.class.getCanonicalName() + "\n" + @@ -942,7 +965,7 @@ public void testCollectWithDeclaredWindow() { " }\n" + "end"; - KieSession ksession = getKieSession( getCepKieModuleModel(), drl ); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), drl ); try { ksession.insert( new Quote("RHT", 10.0) ); @@ -957,8 +980,9 @@ public void testCollectWithDeclaredWindow() { } } - @Test - public void testAfterBindingFirst() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testAfterBindingFirst(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + @@ -968,7 +992,7 @@ public void testAfterBindingFirst() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( new StockTick( "ACME" ) ); @@ -983,8 +1007,9 @@ public void testAfterBindingFirst() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testAfterOnLongFieldsBindingFirst() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testAfterOnLongFieldsBindingFirst(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "declare StockTick @timestamp(timeFieldAsLong) end\n" + @@ -995,7 +1020,7 @@ public void testAfterOnLongFieldsBindingFirst() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert(new StockTick("ACME").setTimeField(0)); @@ -1008,8 +1033,9 @@ public void testAfterOnLongFieldsBindingFirst() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testBefore() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testBefore(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + @@ -1019,7 +1045,7 @@ public void testBefore() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( new StockTick( "ACME" ) ); @@ -1034,8 +1060,9 @@ public void testBefore() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testBeforeBindingFirst() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testBeforeBindingFirst(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + @@ -1045,7 +1072,7 @@ public void testBeforeBindingFirst() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( new StockTick( "DROO" ) ); @@ -1060,8 +1087,9 @@ public void testBeforeBindingFirst() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testBeforeOnLongFields() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testBeforeOnLongFields(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "declare StockTick @timestamp(timeFieldAsLong) end\n" + @@ -1072,7 +1100,7 @@ public void testBeforeOnLongFields() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert(new StockTick("ACME").setTimeField(0)); @@ -1085,8 +1113,9 @@ public void testBeforeOnLongFields() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testBeforeOnLongFieldsBindingFirst() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testBeforeOnLongFieldsBindingFirst(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "declare StockTick @timestamp(timeFieldAsLong) end\n" + @@ -1097,7 +1126,7 @@ public void testBeforeOnLongFieldsBindingFirst() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert(new StockTick("DROO").setTimeField(0)); @@ -1110,8 +1139,9 @@ public void testBeforeOnLongFieldsBindingFirst() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testBeforeOnLongFieldsWithDifferentMethod() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testBeforeOnLongFieldsWithDifferentMethod(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "import " + StockTickEx.class.getCanonicalName() + ";\n" + @@ -1124,7 +1154,7 @@ public void testBeforeOnLongFieldsWithDifferentMethod() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert(new StockTick("ACME").setTimeField(0)); @@ -1137,8 +1167,9 @@ public void testBeforeOnLongFieldsWithDifferentMethod() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testAfterOnLongFieldsBindingFirstWithDifferentMethod() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testAfterOnLongFieldsBindingFirstWithDifferentMethod(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "import " + StockTickEx.class.getCanonicalName() + ";\n" + @@ -1151,7 +1182,7 @@ public void testAfterOnLongFieldsBindingFirstWithDifferentMethod() throws Except " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert(new StockTick("ACME").setTimeField(0)); @@ -1164,8 +1195,9 @@ public void testAfterOnLongFieldsBindingFirstWithDifferentMethod() throws Except assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testLiteral() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testLiteral(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "declare StockTick @timestamp(timeFieldAsLong) end\n" + @@ -1175,7 +1207,7 @@ public void testLiteral() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); long time = LocalDateTime.of(2020, 1, 1, 0, 0, 0).atZone(ZoneId.of("UTC")).toInstant().getEpochSecond() * 1000; ksession.insert(new StockTick("DROO").setTimeField(time)); @@ -1183,8 +1215,9 @@ public void testLiteral() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testZonedDateTime() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testZonedDateTime(RUN_TYPE runType) throws Exception { String str = "import " + DateTimeHolder.class.getCanonicalName() + ";" + "rule R when\n" + @@ -1193,7 +1226,7 @@ public void testZonedDateTime() throws Exception { "then\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( new DateTimeHolder( ZonedDateTime.now() ) ); @@ -1202,8 +1235,9 @@ public void testZonedDateTime() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testCalendarsWithCronAndStartAndEnd() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testCalendarsWithCronAndStartAndEnd(RUN_TYPE runType) throws Exception { final Locale defaultLoc = Locale.getDefault(); try { Locale.setDefault(Locale.UK); // Because of the date strings in the DRL, fixable with JBRULES-3444 @@ -1220,7 +1254,7 @@ public void testCalendarsWithCronAndStartAndEnd() throws Exception { " list.add(\"fired\"); \n" + "end \n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); try { final List list = new ArrayList(); final PseudoClockScheduler timeService = ksession.getSessionClock(); @@ -1263,8 +1297,9 @@ public void testCalendarsWithCronAndStartAndEnd() throws Exception { } } - @Test - public void testNegate() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testNegate(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + @@ -1274,7 +1309,7 @@ public void testNegate() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( new StockTick( "DROO" ) ); @@ -1289,8 +1324,9 @@ public void testNegate() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNegateFromCollect() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testNegateFromCollect(RUN_TYPE runType) throws Exception { String str = "import " + StockTick.class.getCanonicalName() + ";" + "import " + List.class.getCanonicalName() + ";" + @@ -1301,7 +1337,7 @@ public void testNegateFromCollect() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert( new StockTick( "DROO" ) ); @@ -1316,8 +1352,9 @@ public void testNegateFromCollect() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNegateFromCollectWithDeclaredTimestamp() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testNegateFromCollectWithDeclaredTimestamp(RUN_TYPE runType) throws Exception { String str = "import " + TransactionHistory.class.getCanonicalName() + ";" + "import " + List.class.getCanonicalName() + ";" + @@ -1332,7 +1369,7 @@ public void testNegateFromCollectWithDeclaredTimestamp() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); ksession.insert(new TransactionHistory(10, toEpochMilliYMD(2022, 5, 12))); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ChannelTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ChannelTest.java index a14a545717d..d9dd067d4a2 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ChannelTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ChannelTest.java @@ -22,7 +22,8 @@ import java.util.List; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.Channel; import org.kie.api.runtime.KieSession; @@ -31,11 +32,7 @@ public class ChannelTest extends BaseModelTest { - public ChannelTest(RUN_TYPE testRunType) { - super(testRunType); - } - - public void testChannel(boolean isMvel) { + public void testChannel(RUN_TYPE runType, boolean isMvel) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R \n" + @@ -46,7 +43,7 @@ public void testChannel(boolean isMvel) { " channels[\"testChannel\"].send(\"Test Message\");\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); TestChannel testChannel = new TestChannel(); ksession.registerChannel("testChannel", testChannel); @@ -58,14 +55,16 @@ public void testChannel(boolean isMvel) { assertThat(testChannel.getChannelMessages()).contains("Test Message"); } - @Test - public void testChannelWithJava() { - testChannel(false); + @ParameterizedTest + @MethodSource("parameters") + public void testChannelWithJava(RUN_TYPE runType) { + testChannel(runType, false); } - @Test - public void testChannelWithMvel() { - testChannel(true); + @ParameterizedTest + @MethodSource("parameters") + public void testChannelWithMvel(RUN_TYPE runType) { + testChannel(runType, true); } public static class TestChannel implements Channel { diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CompilationFailuresTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CompilationFailuresTest.java index 398ff751800..8dce6906c13 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CompilationFailuresTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CompilationFailuresTest.java @@ -22,7 +22,8 @@ import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.builder.Message; import org.kie.api.builder.Results; @@ -30,12 +31,10 @@ public class CompilationFailuresTest extends BaseModelTest { - public CompilationFailuresTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - @Test - public void testNonQuotedStringComapre() { + @ParameterizedTest + @MethodSource("parameters") + public void testNonQuotedStringComapre(RUN_TYPE runType) { String drl = "declare Fact\n" + " field : String\n" + @@ -45,15 +44,16 @@ public void testNonQuotedStringComapre() { "then\n" + "end\n"; - Results results = getCompilationResults(drl); + Results results = getCompilationResults(runType, drl); assertThat(results.getMessages(Message.Level.ERROR).isEmpty()).isFalse(); // line = -1 even with STANDARD_FROM_DRL (PredicateDescr) assertThat(results.getMessages().get(0).getLine()).isEqualTo(-1); } - @Test - public void testUseNotExistingEnum() { + @ParameterizedTest + @MethodSource("parameters") + public void testUseNotExistingEnum(RUN_TYPE runType) { String drl = "import " + NumberRestriction.class.getCanonicalName() + "\n" + "rule R when\n" + @@ -61,14 +61,14 @@ public void testUseNotExistingEnum() { "then\n" + "end\n"; - Results results = getCompilationResults(drl); + Results results = getCompilationResults(runType, drl); assertThat(results.getMessages(Message.Level.ERROR).isEmpty()).isFalse(); assertThat(results.getMessages().get(0).getLine()).isEqualTo(3); } - private Results getCompilationResults( String drl ) { - return createKieBuilder( drl ).getResults(); + private Results getCompilationResults(RUN_TYPE runType, String drl ) { + return createKieBuilder(runType, drl).getResults(); } public static class NumberRestriction { @@ -96,27 +96,31 @@ public String getValueType() { } } - @Test - public void testMaxIntegerResultOnDoublePatternShouldntCompile() { - checkCompilationFailureOnMismatchingAccumulate("Integer", "max"); + @ParameterizedTest + @MethodSource("parameters") + public void testMaxIntegerResultOnDoublePatternShouldntCompile(RUN_TYPE runType) { + checkCompilationFailureOnMismatchingAccumulate(runType, "Integer", "max"); } - @Test - public void testMinIntegerResultOnDoublePatternShouldntCompile() { - checkCompilationFailureOnMismatchingAccumulate("Integer", "min"); + @ParameterizedTest + @MethodSource("parameters") + public void testMinIntegerResultOnDoublePatternShouldntCompile(RUN_TYPE runType) { + checkCompilationFailureOnMismatchingAccumulate(runType, "Integer", "min"); } - @Test - public void testMaxLongResultOnDoublePatternShouldntCompile() { - checkCompilationFailureOnMismatchingAccumulate("Long", "max"); + @ParameterizedTest + @MethodSource("parameters") + public void testMaxLongResultOnDoublePatternShouldntCompile(RUN_TYPE runType) { + checkCompilationFailureOnMismatchingAccumulate(runType, "Long", "max"); } - @Test - public void testMinLongResultOnDoublePatternShouldntCompile() { - checkCompilationFailureOnMismatchingAccumulate("Long", "min"); + @ParameterizedTest + @MethodSource("parameters") + public void testMinLongResultOnDoublePatternShouldntCompile(RUN_TYPE runType) { + checkCompilationFailureOnMismatchingAccumulate(runType, "Long", "min"); } - private void checkCompilationFailureOnMismatchingAccumulate(String type, String accFunc) { + private void checkCompilationFailureOnMismatchingAccumulate(RUN_TYPE runType, String type, String accFunc) { String drl = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -128,7 +132,7 @@ private void checkCompilationFailureOnMismatchingAccumulate(String type, String " System.out.println($max);\n" + "end"; - Results results = getCompilationResults(drl); + Results results = getCompilationResults(runType, drl); assertThat(results.getMessages(Message.Level.ERROR).isEmpty()).isFalse(); // line = 1 with STANDARD_FROM_DRL (RuleDescr) @@ -136,8 +140,9 @@ private void checkCompilationFailureOnMismatchingAccumulate(String type, String } - @Test - public void modify_factInScope_java() { + @ParameterizedTest + @MethodSource("parameters") + public void modify_factInScope_java(RUN_TYPE runType) { // DROOLS-5242, DROOLS-7195 String drl = "import " + Person.class.getCanonicalName() + ";" + @@ -148,12 +153,13 @@ public void modify_factInScope_java() { " modify($p) { $p.setName(\"Mark\") }\n" + "end"; - Results results = getCompilationResults(drl); + Results results = getCompilationResults(runType, drl); assertThat(results.getMessages(Message.Level.ERROR).isEmpty()).isFalse(); } - @Test - public void modify_factInScope_mvel() { + @ParameterizedTest + @MethodSource("parameters") + public void modify_factInScope_mvel(RUN_TYPE runType) { // DROOLS-5242, DROOLS-7195 String drl = "import " + Person.class.getCanonicalName() + ";" + @@ -165,12 +171,13 @@ public void modify_factInScope_mvel() { " modify($p) { $p.setName(\"Mark\") }\n" + "end"; - Results results = getCompilationResults(drl); + Results results = getCompilationResults(runType, drl); assertThat(results.getMessages(Message.Level.ERROR).isEmpty()).isFalse(); } - @Test - public void modify_factInScope_nestedPropertySetter_java() { + @ParameterizedTest + @MethodSource("parameters") + public void modify_factInScope_nestedPropertySetter_java(RUN_TYPE runType) { // DROOLS-5242, DROOLS-7195 String drl = "import " + Person.class.getCanonicalName() + ";" + @@ -181,12 +188,13 @@ public void modify_factInScope_nestedPropertySetter_java() { " modify($p) { $p.address.setCity(\"London\") }\n" + "end"; - Results results = getCompilationResults(drl); + Results results = getCompilationResults(runType, drl); assertThat(results.getMessages(Message.Level.ERROR).isEmpty()).isFalse(); } - @Test - public void modify_factInScope_nestedPropertySetter_mvel() { + @ParameterizedTest + @MethodSource("parameters") + public void modify_factInScope_nestedPropertySetter_mvel(RUN_TYPE runType) { // DROOLS-5242, DROOLS-7195 String drl = "import " + Person.class.getCanonicalName() + ";" + @@ -198,12 +206,13 @@ public void modify_factInScope_nestedPropertySetter_mvel() { " modify($p) { $p.address.setCity(\"London\") }\n" + "end"; - Results results = getCompilationResults(drl); + Results results = getCompilationResults(runType, drl); assertThat(results.getMessages(Message.Level.ERROR).isEmpty()).isFalse(); } - @Test - public void modify_factInScope_nestedPropertyAssign_java() { + @ParameterizedTest + @MethodSource("parameters") + public void modify_factInScope_nestedPropertyAssign_java(RUN_TYPE runType) { // DROOLS-5242, DROOLS-7195 String drl = "import " + Person.class.getCanonicalName() + ";" + @@ -214,12 +223,13 @@ public void modify_factInScope_nestedPropertyAssign_java() { " modify($p) { $p.address.city = \"London\" }\n" + "end"; - Results results = getCompilationResults(drl); + Results results = getCompilationResults(runType, drl); assertThat(results.getMessages(Message.Level.ERROR).isEmpty()).isFalse(); } - @Test - public void modify_factInScope_nestedPropertyAssign_mvel() { + @ParameterizedTest + @MethodSource("parameters") + public void modify_factInScope_nestedPropertyAssign_mvel(RUN_TYPE runType) { // DROOLS-5242, DROOLS-7195 String drl = "import " + Person.class.getCanonicalName() + ";" + @@ -231,12 +241,13 @@ public void modify_factInScope_nestedPropertyAssign_mvel() { " modify($p) { $p.address.city = \"London\" }\n" + "end"; - Results results = getCompilationResults(drl); + Results results = getCompilationResults(runType, drl); assertThat(results.getMessages(Message.Level.ERROR).isEmpty()).isFalse(); } - @Test - public void testVariableInsideBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testVariableInsideBinding(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + NameLengthCount.class.getCanonicalName() + ";" + @@ -246,13 +257,14 @@ public void testVariableInsideBinding() { "then\n" + "end"; - Results results = createKieBuilder(str ).getResults(); + Results results = createKieBuilder(runType, str).getResults(); assertThat(results.getMessages(Message.Level.ERROR).stream().map(Message::getText)) .contains("Variables can not be used inside bindings. Variable [$nlc] is being used in binding '$nlc.self.getNameLength(name)'"); } - @Test - public void testVariableInsideBindingInParameter() { + @ParameterizedTest + @MethodSource("parameters") + public void testVariableInsideBindingInParameter(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + NameLengthCount.class.getCanonicalName() + ";" + @@ -262,7 +274,7 @@ public void testVariableInsideBindingInParameter() { "then\n" + "end"; - Results results = createKieBuilder(str ).getResults(); + Results results = createKieBuilder(runType, str ).getResults(); assertThat(results.getMessages(Message.Level.ERROR).stream().map(Message::getText)) .contains("Variables can not be used inside bindings. Variable [$nlc] is being used in binding 'identityBigDecimal($nlc.fortyTwo)'"); } @@ -282,8 +294,9 @@ public BigDecimal getFortyTwo() { } } - @Test - public void testTypeSafe() { + @ParameterizedTest + @MethodSource("parameters") + public void testTypeSafe(RUN_TYPE runType) { String str = "import " + Parent.class.getCanonicalName() + ";" + "declare\n" + @@ -295,8 +308,8 @@ public void testTypeSafe() { "then\n" + "end\n"; - Results results = createKieBuilder(str).getResults(); - if (testRunType.isExecutableModel()) { + Results results = createKieBuilder(runType, str).getResults(); + if (runType.isExecutableModel()) { assertThat(results.getMessages(Message.Level.ERROR).get(0).getText().contains("@typesafe(false) is not supported in executable model")); } else { assertThat(results.getMessages(Message.Level.ERROR).isEmpty()).isTrue(); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CompilerTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CompilerTest.java index 702020fb7e5..abe40ca412c 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CompilerTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CompilerTest.java @@ -43,10 +43,10 @@ import org.drools.model.codegen.execmodel.domain.StockTick; import org.drools.model.codegen.execmodel.domain.Toy; import org.drools.model.codegen.execmodel.domain.Woman; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.definition.type.FactType; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.process.ProcessContext; @@ -57,12 +57,10 @@ public class CompilerTest extends BaseModelTest { - public CompilerTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test(timeout = 5000) - public void testPropertyReactivity() { + @ParameterizedTest + @MethodSource("parameters") + @Timeout(5000) + public void testPropertyReactivity(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -71,7 +69,7 @@ public void testPropertyReactivity() { " modify($p) { setAge($p.getAge()+1) }\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person me = new Person( "Mario", 40 ); ksession.insert( me ); @@ -80,8 +78,9 @@ public void testPropertyReactivity() { assertThat(me.getAge()).isEqualTo(41); } - @Test - public void testPropertyReactivityWithArguments() { + @ParameterizedTest + @MethodSource("parameters") + public void testPropertyReactivityWithArguments(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R \n" + @@ -91,7 +90,7 @@ public void testPropertyReactivityWithArguments() { " modify($p) { setLikes( String.valueOf(($p.getAddress().getStreet() + $p.getAddress().getCity()))) };\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person me = new Person( "Mario", 40 ); me.setAddress(new Address("street1", 2, "city1")); @@ -101,8 +100,9 @@ public void testPropertyReactivityWithArguments() { assertThat(me.getLikes()).isEqualTo("street1city1"); } - @Test - public void testPropertyReactvityOnFinalField() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testPropertyReactvityOnFinalField(RUN_TYPE runType) throws Exception { String str = "rule R when\n" + " $a : String( length > 3 )\n" + @@ -110,7 +110,7 @@ public void testPropertyReactvityOnFinalField() throws Exception { " System.out.println($a);\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert( "abcd" ); ksession.insert( "xy" ); @@ -118,8 +118,9 @@ public void testPropertyReactvityOnFinalField() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testEqualityCheckOnNull() { + @ParameterizedTest + @MethodSource("parameters") + public void testEqualityCheckOnNull(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -129,7 +130,7 @@ public void testEqualityCheckOnNull() { " insert(new Result($name));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final Person mario = new Person("Mario", 40); final Person luca = new Person(null, 33); @@ -144,8 +145,9 @@ public void testEqualityCheckOnNull() { assertThat(results.iterator().next().getValue()).isEqualTo("Mario"); } - @Test - public void testOrWithFixedLeftOperand() { + @ParameterizedTest + @MethodSource("parameters") + public void testOrWithFixedLeftOperand(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -155,7 +157,7 @@ public void testOrWithFixedLeftOperand() { " insert(new Result($p));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final Person mario = new Person("Mario", 40); final Person luca = new Person("Luca", 33); @@ -174,8 +176,9 @@ public void testOrWithFixedLeftOperand() { assertThat(results.stream().map(r -> r.getValue())).containsExactlyInAnyOrder(mario, luca, edoardo); } - @Test - public void testCapitalLetterProperty() { + @ParameterizedTest + @MethodSource("parameters") + public void testCapitalLetterProperty(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -185,7 +188,7 @@ public void testCapitalLetterProperty() { " insert(new Result($p));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final Person luca = new Person("Luca", 35); final Person leonardo = new Person("Leonardo", 2).setParentP(luca); @@ -202,8 +205,9 @@ public void testCapitalLetterProperty() { assertThat(results.stream().map(Result::getValue)).containsExactlyInAnyOrder(leonardo); } - @Test - public void testBeta() { + @ParameterizedTest + @MethodSource("parameters") + public void testBeta(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -215,7 +219,7 @@ public void testBeta() { " $r.setValue($olderV.getName() + \" is older than \" + $markV.getName());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -244,8 +248,9 @@ public void testBeta() { } - @Test - public void testBetaMap() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaMap(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + @@ -258,7 +263,7 @@ public void testBetaMap() { " $r.setValue($olderV.get(\"name\") + \" is older than \" + $markV.get(\"name\"));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -287,8 +292,9 @@ public void testBetaMap() { assertThat(result.getValue()).isEqualTo("Edson is older than Mark"); } - @Test - public void testBetaMapComparisonWithLiteral() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaMapComparisonWithLiteral(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Map.class.getCanonicalName() + ";" + @@ -299,7 +305,7 @@ public void testBetaMapComparisonWithLiteral() { " $r.setValue($olderV.get(\"name\") + \" is older than Mark\"\n);" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -328,8 +334,9 @@ private Map mapPerson(String name, int age) { return person; } - @Test - public void testRuleExtends() { + @ParameterizedTest + @MethodSource("parameters") + public void testRuleExtends(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -347,7 +354,7 @@ public void testRuleExtends() { " $r.setValue($p2.getName() + \" is older than \" + $p1.getName());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -363,8 +370,9 @@ public void testRuleExtends() { assertThat(result.getValue()).isEqualTo("Mario is older than Mark"); } - @Test - public void testBetaWithDeclaration() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaWithDeclaration(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -376,7 +384,7 @@ public void testBetaWithDeclaration() { " $r.setValue($p2.getName() + \" is older than \" + $p1.getName());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -404,8 +412,9 @@ public void testBetaWithDeclaration() { assertThat(result.getValue()).isEqualTo("Edson is older than Mark"); } - @Test - public void test3Patterns() { + @ParameterizedTest + @MethodSource("parameters") + public void test3Patterns(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -416,7 +425,7 @@ public void test3Patterns() { " System.out.println(\"Found: \" + $s);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( "Mario" ); ksession.insert( new Person( "Mark", 37 ) ); @@ -425,8 +434,9 @@ public void test3Patterns() { ksession.fireAllRules(); } - @Test - public void testSimpleInsert() { + @ParameterizedTest + @MethodSource("parameters") + public void testSimpleInsert(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -437,7 +447,7 @@ public void testSimpleInsert() { " insert(r);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mark", 37 ) ); ksession.insert( new Person( "Mario", 40 ) ); @@ -448,8 +458,9 @@ public void testSimpleInsert() { assertThat(results.iterator().next().getValue()).isEqualTo("Mark"); } - @Test - public void testSimpleInsertWithProperties() { + @ParameterizedTest + @MethodSource("parameters") + public void testSimpleInsertWithProperties(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -460,7 +471,7 @@ public void testSimpleInsertWithProperties() { " insert(r);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mark", 37, new Address("London")) ); ksession.insert( new Person( "Luca", 32 , new Address("Milan")) ); @@ -471,8 +482,9 @@ public void testSimpleInsertWithProperties() { assertThat(results.iterator().next().getValue()).isEqualTo("Luca"); } - @Test - public void testSimpleDelete() { + @ParameterizedTest + @MethodSource("parameters") + public void testSimpleDelete(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -484,7 +496,7 @@ public void testSimpleDelete() { " delete($p);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mark", 37 ) ); ksession.insert( new Person( "Mario", 40 ) ); @@ -496,8 +508,9 @@ public void testSimpleDelete() { assertThat(getObjectsIntoList(ksession, Person.class).size()).isEqualTo(1); } - @Test - public void testSimpleInsertDeleteExplicitScope() { + @ParameterizedTest + @MethodSource("parameters") + public void testSimpleInsertDeleteExplicitScope(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -509,7 +522,7 @@ public void testSimpleInsertDeleteExplicitScope() { " drools.delete($p);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mark", 37 ) ); ksession.insert( new Person( "Mario", 40 ) ); @@ -521,8 +534,9 @@ public void testSimpleInsertDeleteExplicitScope() { assertThat(getObjectsIntoList(ksession, Person.class).size()).isEqualTo(1); } - @Test - public void testSimpleUpdate() { + @ParameterizedTest + @MethodSource("parameters") + public void testSimpleUpdate(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -532,7 +546,7 @@ public void testSimpleUpdate() { " update($p);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person mark = new Person( "Mark", 37 ); Person mario = new Person( "Mario", 40 ); @@ -545,8 +559,9 @@ public void testSimpleUpdate() { assertThat(mario.getAge()).isEqualTo(40); } - @Test - public void testSimpleModify() { + @ParameterizedTest + @MethodSource("parameters") + public void testSimpleModify(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -555,7 +570,7 @@ public void testSimpleModify() { " modify($p) { setAge($p.getAge()+1) }\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person mark = new Person( "Mark", 37 ); Person mario = new Person( "Mario", 40 ); @@ -568,8 +583,9 @@ public void testSimpleModify() { assertThat(mario.getAge()).isEqualTo(40); } - @Test - public void testEmptyPattern() { + @ParameterizedTest + @MethodSource("parameters") + public void testEmptyPattern(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -579,7 +595,7 @@ public void testEmptyPattern() { " insert(new Result(\"ok\"));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person mario = new Person( "Mario", 40 ); @@ -591,8 +607,9 @@ public void testEmptyPattern() { assertThat(results.iterator().next().getValue()).isEqualTo("ok"); } - @Test - public void testEmptyPatternWithBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testEmptyPatternWithBinding(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -602,7 +619,7 @@ public void testEmptyPatternWithBinding() { " insert(new Result($p.getName()));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person mario = new Person( "Mario", 40 ); @@ -614,8 +631,9 @@ public void testEmptyPatternWithBinding() { assertThat(results.iterator().next().getValue()).isEqualTo("Mario"); } - @Test - public void testFrom() { + @ParameterizedTest + @MethodSource("parameters") + public void testFrom(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";\n" + "import " + Adult.class.getCanonicalName() + ";\n" + @@ -628,7 +646,7 @@ public void testFrom() { " $r.setValue($c.getName());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -642,17 +660,19 @@ public void testFrom() { assertThat(result.getValue()).isEqualTo("Alan"); } - @Test - public void testConcatenatedFrom() { - checkConcatenatedFrom(true); + @ParameterizedTest + @MethodSource("parameters") + public void testConcatenatedFrom(RUN_TYPE runType) { + checkConcatenatedFrom(runType, true); } - @Test - public void testConcatenatedFromWithCondition() { - checkConcatenatedFrom(false); + @ParameterizedTest + @MethodSource("parameters") + public void testConcatenatedFromWithCondition(RUN_TYPE runType) { + checkConcatenatedFrom(runType, false); } - private void checkConcatenatedFrom(boolean withCondition) { + private void checkConcatenatedFrom(RUN_TYPE runType, boolean withCondition) { String str = "import " + Result.class.getCanonicalName() + ";\n" + "import " + Man.class.getCanonicalName() + ";\n" + @@ -669,7 +689,7 @@ private void checkConcatenatedFrom(boolean withCondition) { " list.add($t.getName());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -696,8 +716,9 @@ private void checkConcatenatedFrom(boolean withCondition) { assertThat(list).containsExactlyInAnyOrder("car", "ball"); } - @Test - public void testAgeWithSum() { + @ParameterizedTest + @MethodSource("parameters") + public void testAgeWithSum(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -708,7 +729,7 @@ public void testAgeWithSum() { " insert(new Result($plusTwo.getName()));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 40 ) ); ksession.insert( new Person( "Mark", 37 ) ); @@ -720,8 +741,9 @@ public void testAgeWithSum() { assertThat(results.iterator().next().getValue()).isEqualTo("Mark"); } - @Test - public void testAgeWithSumUsing2DeclarationInBeta() { + @ParameterizedTest + @MethodSource("parameters") + public void testAgeWithSumUsing2DeclarationInBeta(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -732,7 +754,7 @@ public void testAgeWithSumUsing2DeclarationInBeta() { " insert(new Result($plusTwo.getName()));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mario", 40)); ksession.insert(new Person("Mark", 37)); @@ -745,8 +767,9 @@ public void testAgeWithSumUsing2DeclarationInBeta() { assertThat(results.iterator().next().getValue()).isEqualTo("Mark"); } - @Test - public void testFunction3() { + @ParameterizedTest + @MethodSource("parameters") + public void testFunction3(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -759,7 +782,7 @@ public void testFunction3() { " insert(new Result($p.getName()));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 40 ) ); ksession.insert( new Person( "Mark", 37 ) ); @@ -771,15 +794,16 @@ public void testFunction3() { assertThat(results.iterator().next().getValue()).isEqualTo("Mario"); } - @Test - public void testInsertLogical() { + @ParameterizedTest + @MethodSource("parameters") + public void testInsertLogical(RUN_TYPE runType) { String str = "rule R when\n" + " Integer()" + "then\n" + " insertLogical(\"Hello World\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); FactHandle fh_47 = ksession.insert(47); ksession.fireAllRules(); @@ -794,8 +818,9 @@ public void testInsertLogical() { assertThat(results.contains("Hello World")).isFalse(); } - @Test - public void testModifyRewriteAvoidTwiceThePreceeding() { + @ParameterizedTest + @MethodSource("parameters") + public void testModifyRewriteAvoidTwiceThePreceeding(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List globalA \n" + "global java.util.List globalB \n" + @@ -808,7 +833,7 @@ public void testModifyRewriteAvoidTwiceThePreceeding() { " globalB.add(\"B\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List globalA = new ArrayList<>(); List globalB = new ArrayList<>(); @@ -822,8 +847,9 @@ public void testModifyRewriteAvoidTwiceThePreceeding() { assertThat(globalB.size()).isEqualTo(1); } - @Test - public void testEmptyModifyRewrite() { + @ParameterizedTest + @MethodSource("parameters") + public void testEmptyModifyRewrite(RUN_TYPE runType) { String str = "rule R \n" + "no-loop \n" + "when\n" + @@ -833,7 +859,7 @@ public void testEmptyModifyRewrite() { " modify( $s ) { }\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert("Hello World"); int fired = ksession.fireAllRules(); @@ -841,8 +867,9 @@ public void testEmptyModifyRewrite() { assertThat(fired).isEqualTo(1); } - @Test() - public void testModifyRewriteWithComments() { + @ParameterizedTest + @MethodSource("parameters") + public void testModifyRewriteWithComments(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List globalA \n" + "global java.util.List globalB \n" + @@ -861,7 +888,7 @@ public void testModifyRewriteWithComments() { " /* modify ; something */\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List globalA = new ArrayList<>(); List globalB = new ArrayList<>(); @@ -877,9 +904,10 @@ public void testModifyRewriteWithComments() { assertThat(person1.getAge()).isEqualTo(47); } - @Test() - @Ignore("fails for exec model, is not recognizing properly start/ends of modify block") - public void testModifyRewriteWithCommentsAbsurd() { + @ParameterizedTest + @MethodSource("parameters") + @Disabled("fails for exec model, is not recognizing properly start/ends of modify block") + public void testModifyRewriteWithCommentsAbsurd(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List globalA \n" + "global java.util.List globalB \n" + @@ -898,7 +926,7 @@ public void testModifyRewriteWithCommentsAbsurd() { " /* modify( $p ) { setAge(2) } */\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List globalA = new ArrayList<>(); List globalB = new ArrayList<>(); @@ -914,8 +942,9 @@ public void testModifyRewriteWithCommentsAbsurd() { assertThat(person1.getAge()).isEqualTo(47); } - @Test - public void testConstraintContainingAMethodCallWithParams() { + @ParameterizedTest + @MethodSource("parameters") + public void testConstraintContainingAMethodCallWithParams(RUN_TYPE runType) { String str = "import " + Overloaded.class.getCanonicalName() + ";" + "rule OverloadedMethods\n" + "when\n" + @@ -924,7 +953,7 @@ public void testConstraintContainingAMethodCallWithParams() { " insert(\"matched\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Overloaded()); ksession.fireAllRules(); @@ -933,8 +962,9 @@ public void testConstraintContainingAMethodCallWithParams() { assertThat(results.size()).isEqualTo(1); } - @Test - public void testSimpleModifyUsingNameRefFollowedByMethodCall() { + @ParameterizedTest + @MethodSource("parameters") + public void testSimpleModifyUsingNameRefFollowedByMethodCall(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -943,7 +973,7 @@ public void testSimpleModifyUsingNameRefFollowedByMethodCall() { " modify($p) { setAge($p.getAge()+1) }\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person mark = new Person("Mark", 37); Person mario = new Person("Mario", 40); @@ -956,8 +986,9 @@ public void testSimpleModifyUsingNameRefFollowedByMethodCall() { assertThat(mario.getAge()).isEqualTo(40); } - @Test - public void testChainOfMethodCallInConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testChainOfMethodCallInConstraint(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + " $p : Person( getAddress().getCity().length() == 5 )\n" + @@ -965,7 +996,7 @@ public void testChainOfMethodCallInConstraint() { " insert(\"matched\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person john = new Person("John", 47); Address a = new Address("Italy"); @@ -978,8 +1009,9 @@ public void testChainOfMethodCallInConstraint() { assertThat(results.size()).isEqualTo(1); } - @Test - public void testChainOfMethodCallInConstraintSub() { + @ParameterizedTest + @MethodSource("parameters") + public void testChainOfMethodCallInConstraintSub(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + " $p : Person( address.(city.startsWith(\"I\") && city.length() == 5 ) )\n" + // DRL feature "Grouped accessors for nested objects" is addressed by the RuleDescr directly. @@ -987,7 +1019,7 @@ public void testChainOfMethodCallInConstraintSub() { " insert(\"matched\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person john = new Person("John", 47); Address a = new Address("Italy"); @@ -1000,8 +1032,9 @@ public void testChainOfMethodCallInConstraintSub() { assertThat(results.size()).isEqualTo(1); } - @Test - public void testChainFieldAccessorsAndMethodCall() { + @ParameterizedTest + @MethodSource("parameters") + public void testChainFieldAccessorsAndMethodCall(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + " $p : Person( address.getCity().length == 5 )\n" + @@ -1009,7 +1042,7 @@ public void testChainFieldAccessorsAndMethodCall() { " insert(\"matched\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person john = new Person("John", 47); Address a = new Address("Italy"); @@ -1022,8 +1055,9 @@ public void testChainFieldAccessorsAndMethodCall() { assertThat(results.size()).isEqualTo(1); } - @Test - public void testInnerBindingWithOr() { + @ParameterizedTest + @MethodSource("parameters") + public void testInnerBindingWithOr(RUN_TYPE runType) { String str = "global java.util.List list\n" + "\n" + @@ -1033,7 +1067,7 @@ public void testInnerBindingWithOr() { " list.add(s);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList(); ksession.setGlobal("list", list); @@ -1045,8 +1079,9 @@ public void testInnerBindingWithOr() { assertThat(list.get(0)).isEqualTo("y"); } - @Test - public void testRHS() { + @ParameterizedTest + @MethodSource("parameters") + public void testRHS(RUN_TYPE runType) { String str = "rule R when\n" + " //conditions\n" + @@ -1060,11 +1095,12 @@ public void testRHS() { " kcontext.getKnowledgeRuntime();\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); } - @Test - public void testBindWith2Arguments() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindWith2Arguments(RUN_TYPE runType) { String str = "import " + Adult.class.getCanonicalName() + ";\n" + "import " + Child.class.getCanonicalName() + ";\n" + @@ -1075,7 +1111,7 @@ public void testBindWith2Arguments() { " insert(new Result($sum));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Adult a = new Adult( "Mario", 43 ); ksession.insert( a ); @@ -1085,8 +1121,9 @@ public void testBindWith2Arguments() { assertThat(((Number) results.iterator().next().getValue()).intValue()).isEqualTo(48); } - @Test - public void testLockOnActiveWithModify() { + @ParameterizedTest + @MethodSource("parameters") + public void testLockOnActiveWithModify(RUN_TYPE runType) { String str = "package org.drools.test; \n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -1112,7 +1149,7 @@ public void testLockOnActiveWithModify() { " modify ( $p ) { setName( \"john\" ); } \n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.fireAllRules(); @@ -1124,8 +1161,9 @@ public void testLockOnActiveWithModify() { assertThat(p.getName()).isEqualTo("john"); } - @Test - public void testAlphaConstraintOn2Properties() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaConstraintOn2Properties(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -1133,15 +1171,16 @@ public void testAlphaConstraintOn2Properties() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person me = new Person( "Mario", 40 ); ksession.insert( me ); ksession.fireAllRules(); } - @Test - public void testAlphaNull() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaNull(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -1162,7 +1201,7 @@ public void testAlphaNull() { " insert(new Result($p.getName()));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person first = new Person(null, 40); Person second = new Person("Luca", 40); @@ -1179,8 +1218,9 @@ public void testAlphaNull() { assertThat(results).containsExactlyInAnyOrder("Luca", null); } - @Test - public void testAlphaNullBoolean() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaNullBoolean(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -1190,7 +1230,7 @@ public void testAlphaNullBoolean() { " insert(new Result($p.getName()));\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person first = new Person("First", 40); first.setEmployed(null); @@ -1207,8 +1247,9 @@ public void testAlphaNullBoolean() { assertThat(results).containsExactlyInAnyOrder("Second"); } - @Test - public void testStringValueOf() { + @ParameterizedTest + @MethodSource("parameters") + public void testStringValueOf(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "import " + Result.class.getCanonicalName() + ";\n" + @@ -1219,7 +1260,7 @@ public void testStringValueOf() { " insert(new Result($i));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( 44 ); ksession.insert( new Person( "44", 44 ) ); @@ -1229,8 +1270,9 @@ public void testStringValueOf() { assertThat(((Number) results.iterator().next().getValue()).intValue()).isEqualTo(44); } - @Test - public void testBigDecimalBigIntegerCoercion() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalBigIntegerCoercion(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "import " + BigInteger.class.getCanonicalName() + ";\n" + "rule \"rule1\"\n" + @@ -1250,7 +1292,7 @@ public void testBigDecimalBigIntegerCoercion() { "end\n"; - KieSession ksession1 = getKieSession(str); + KieSession ksession1 = getKieSession(runType, str); Person p1 = new Person(); p1.setMoney( new BigDecimal(1 ) ); @@ -1259,8 +1301,9 @@ public void testBigDecimalBigIntegerCoercion() { } - @Test - public void testBigDecimalOperationsInConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalOperationsInConstraint(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "import " + BigDecimal.class.getCanonicalName() + ";\n" + "global java.util.List results;\n" + @@ -1271,7 +1314,7 @@ public void testBigDecimalOperationsInConstraint() { " results.add($moneyDoubled);\n" + "end\n"; - KieSession ksession1 = getKieSession(str); + KieSession ksession1 = getKieSession(runType, str); ArrayList results = new ArrayList<>(); ksession1.setGlobal("results", results); @@ -1285,8 +1328,9 @@ public void testBigDecimalOperationsInConstraint() { } - @Test - public void testSingleQuoteString() { + @ParameterizedTest + @MethodSource("parameters") + public void testSingleQuoteString(RUN_TYPE runType) { String str = "rule R1 when\n" + " String( this == 'x' )\n" + @@ -1297,15 +1341,16 @@ public void testSingleQuoteString() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( "x" ); ksession.insert( "xx" ); assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testIntToLongComparison() { + @ParameterizedTest + @MethodSource("parameters") + public void testIntToLongComparison(RUN_TYPE runType) { String str = "rule R when\n" + " $i : Integer()\n" + @@ -1313,7 +1358,7 @@ public void testIntToLongComparison() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( 1 ); ksession.insert( 2L ); @@ -1321,8 +1366,9 @@ public void testIntToLongComparison() { } - @Test - public void testUseGlobalInLHS() { + @ParameterizedTest + @MethodSource("parameters") + public void testUseGlobalInLHS(RUN_TYPE runType) { // DROOLS-1025 final String drl1 = "import " + Result.class.getCanonicalName() + ";\n" + @@ -1333,7 +1379,7 @@ public void testUseGlobalInLHS() { " insert(new Result(\"match\"));\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.setGlobal("globalInt", new AtomicInteger(0)); @@ -1343,8 +1389,9 @@ public void testUseGlobalInLHS() { assertThat(results.iterator().next().getValue().toString()).isEqualTo("match"); } - @Test - public void testMapAccess() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapAccess(RUN_TYPE runType) { final String drl1 = "import java.util.Map;\n" + "rule R1 when\n" + @@ -1352,7 +1399,7 @@ public void testMapAccess() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); final Map map = new HashMap<>(); map.put("type", "Goods"); @@ -1361,8 +1408,9 @@ public void testMapAccess() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testMapAccessBindingConstant() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapAccessBindingConstant(RUN_TYPE runType) { final String drl1 = "import java.util.Map;\n" + "rule R1 when\n" + @@ -1370,7 +1418,7 @@ public void testMapAccessBindingConstant() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); final Map map = new HashMap<>(); map.put("type", "Goods"); @@ -1379,8 +1427,9 @@ public void testMapAccessBindingConstant() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testMapAccessBindingConstantJoin() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapAccessBindingConstantJoin(RUN_TYPE runType) { final String drl1 = "import java.util.Map;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -1394,7 +1443,7 @@ public void testMapAccessBindingConstantJoin() { " results.add($p.getName());\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ArrayList results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1413,8 +1462,9 @@ public void testMapAccessBindingConstantJoin() { assertThat(results).containsExactlyInAnyOrder("Andrea", "Luca"); } - @Test - public void testMapAccessBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapAccessBinding(RUN_TYPE runType) { final String drl1 = "import java.util.Map;\n" + "rule R1 when\n" + @@ -1423,7 +1473,7 @@ public void testMapAccessBinding() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); final Map map = new HashMap<>(); map.put("type", "Goods"); @@ -1433,8 +1483,9 @@ public void testMapAccessBinding() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testStringBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testStringBinding(RUN_TYPE runType) { final String drl1 = "import " + Result.class.getCanonicalName() + ";\n" + "rule R1 when\n" + @@ -1443,7 +1494,7 @@ public void testStringBinding() { " insert(new Result($t));\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert( "whatever" ); assertThat(ksession.fireAllRules()).isEqualTo(1); @@ -1452,8 +1503,9 @@ public void testStringBinding() { assertThat(results.iterator().next().getValue().toString()).isEqualTo("type"); } - @Test - public void testMapAccessProperty() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapAccessProperty(RUN_TYPE runType) { final String drl1 = "import " + Person.class.getCanonicalName() + ";\n" + "import java.util.Map;\n" + @@ -1462,7 +1514,7 @@ public void testMapAccessProperty() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); final Map map = new HashMap<>(); map.put(1, 2000); @@ -1478,8 +1530,9 @@ public void testMapAccessProperty() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testMapInitialization() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapInitialization(RUN_TYPE runType) { final String drl1 = "import " + Person.class.getCanonicalName() + ";\n" + "import java.util.Map;\n" + @@ -1489,7 +1542,7 @@ public void testMapInitialization() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); final Person luca = new Person("Luca"); luca.setNumberOfItems(2); @@ -1502,8 +1555,9 @@ public void testMapInitialization() { } - @Test - public void testErrorTwoPatterns() { + @ParameterizedTest + @MethodSource("parameters") + public void testErrorTwoPatterns(RUN_TYPE runType) { // DROOLS-3850 final String drl1 = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1515,7 +1569,7 @@ public void testErrorTwoPatterns() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); final Person luca = new Person("Luca"); luca.setNumberOfItems(2); @@ -1528,8 +1582,9 @@ public void testErrorTwoPatterns() { } - @Test - public void testMapWithBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapWithBinding(RUN_TYPE runType) { // DROOLS-3558 final String drl1 = "package org.drools.compiler\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -1541,7 +1596,7 @@ public void testMapWithBinding() { " then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); final Person john = new Person("John"); HashMap items = new HashMap(); @@ -1557,8 +1612,9 @@ public void testMapWithBinding() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testMapAccessPropertyWithCast() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapAccessPropertyWithCast(RUN_TYPE runType) { final String drl1 = "import " + Person.class.getCanonicalName() + ";\n" + "import java.util.Map;\n" + @@ -1567,7 +1623,7 @@ public void testMapAccessPropertyWithCast() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); final Map map = new HashMap<>(); map.put(1, 2000); @@ -1583,8 +1639,9 @@ public void testMapAccessPropertyWithCast() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testArrayAccess() { + @ParameterizedTest + @MethodSource("parameters") + public void testArrayAccess(RUN_TYPE runType) { final String drl = "package org.drools.compiler.test\n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -1596,13 +1653,14 @@ public void testArrayAccess() { "then\n" + "end\n"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testInOperators() { + @ParameterizedTest + @MethodSource("parameters") + public void testInOperators(RUN_TYPE runType) { final String drl1 = "package org.drools.compiler\n" + "import " + Person.class.getCanonicalName() + ";\n" + "rule \"eval rewrite with 'in'\"\n" + @@ -1611,7 +1669,7 @@ public void testInOperators() { " then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); final Person luca = new Person("Luca"); luca.setAge(2); @@ -1640,8 +1698,9 @@ public void setaBcde(String aBcde) { } } - @Test - public void testGetterSetterCase() { + @ParameterizedTest + @MethodSource("parameters") + public void testGetterSetterCase(RUN_TYPE runType) { // DROOLS-2724 final String drl = "import " + TestFact.class.getCanonicalName() + ";\n" + @@ -1650,13 +1709,14 @@ public void testGetterSetterCase() { "when \n" + " TestFact(aBcde == \"test\")\n" + "then end"; - KieSession kieSession = getKieSession(drl); + KieSession kieSession = getKieSession(runType, drl); kieSession.insert(new TestFact("test")); assertThat(kieSession.fireAllRules()).isEqualTo(1); } - @Test - public void testCommaInModify() { + @ParameterizedTest + @MethodSource("parameters") + public void testCommaInModify(RUN_TYPE runType) { // DROOLS-3505 final String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -1667,7 +1727,7 @@ public void testCommaInModify() { "then\n" + " modify($p) { setAge(1), setLikes(\"bread\"); }\n" + "end\n"; - KieSession kieSession = getKieSession(drl); + KieSession kieSession = getKieSession(runType, drl); Person john = new Person("John", 24); kieSession.insert(john); assertThat(kieSession.fireAllRules()).isEqualTo(1); @@ -1701,8 +1761,9 @@ public void setStatus( int status ) { } } - @Test - public void testStaticFieldClashingWithClassName() { + @ParameterizedTest + @MethodSource("parameters") + public void testStaticFieldClashingWithClassName(RUN_TYPE runType) { // DROOLS-3560 final String drl = "import " + Message.class.getCanonicalName() + "\n" + @@ -1723,7 +1784,7 @@ public void testStaticFieldClashingWithClassName() { " System.out.println( myMessage );\n" + "end\n"; - KieSession kieSession = getKieSession(drl); + KieSession kieSession = getKieSession(runType, drl); Message message = new Message(); message.setMessage( "Hi" ); message.setStatus( Message.HELLO ); @@ -1731,8 +1792,9 @@ public void testStaticFieldClashingWithClassName() { assertThat(kieSession.fireAllRules()).isEqualTo(2); } - @Test - public void testDoubleModify() { + @ParameterizedTest + @MethodSource("parameters") + public void testDoubleModify(RUN_TYPE runType) { // DROOLS-3560 final String drl = "import " + Message.class.getCanonicalName() + "\n" + @@ -1754,7 +1816,7 @@ public void testDoubleModify() { " System.out.println( myMessage );\n" + "end\n"; - KieSession kieSession = getKieSession(drl); + KieSession kieSession = getKieSession(runType, drl); Message message = new Message(); message.setMessage( "Hi" ); message.setStatus( Message.HELLO ); @@ -1762,8 +1824,9 @@ public void testDoubleModify() { assertThat(kieSession.fireAllRules()).isEqualTo(2); } - @Test - public void testPrettyPrinterCrashing() { + @ParameterizedTest + @MethodSource("parameters") + public void testPrettyPrinterCrashing(RUN_TYPE runType) { final String drl = "" + "package org.drools.compiler.test \n" + @@ -1801,7 +1864,7 @@ public void testPrettyPrinterCrashing() { "end\n" + "\n"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); try { final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -1816,8 +1879,9 @@ public void testPrettyPrinterCrashing() { } } - @Test - public void testBetaJoinBigInteger() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaJoinBigInteger(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -1829,7 +1893,7 @@ public void testBetaJoinBigInteger() { " $r.setValue($olderV.getName() + \" is older than \" + $markV.getName());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -1846,8 +1910,9 @@ public void testBetaJoinBigInteger() { assertThat(result.getValue()).isEqualTo("Mario is older than Mark"); } - @Test - public void testBetaJoinBigDecimal() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaJoinBigDecimal(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -1859,7 +1924,7 @@ public void testBetaJoinBigDecimal() { " $r.setValue($richerV.getName() + \" is richer than \" + $markV.getName());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -1876,8 +1941,9 @@ public void testBetaJoinBigDecimal() { assertThat(result.getValue()).isEqualTo("Mario is richer than Mark"); } - @Test - public void testBetaCast() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaCast(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -1890,7 +1956,7 @@ public void testBetaCast() { " $r.setValue($a.getCity() + \" number has the same value of \" + $p.getName() + \" age\");\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -1916,8 +1982,9 @@ public void testBetaCast() { assertThat(result.getValue()).isEqualTo("Milan number has the same value of Mark age"); } - @Test - public void testNumericLimitsLiteral() { + @ParameterizedTest + @MethodSource("parameters") + public void testNumericLimitsLiteral(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -1928,7 +1995,7 @@ public void testNumericLimitsLiteral() { " $r.setValue($p.getName() + \" is very old\");\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -1949,8 +2016,9 @@ public void testNumericLimitsLiteral() { - @Test - public void testBetaCastGreaterThan() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaCastGreaterThan(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -1963,7 +2031,7 @@ public void testBetaCastGreaterThan() { " $r.setValue($a.getCity() + \" number is greater than \" + $p.getName() + \" age\");\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -1995,8 +2063,9 @@ public void testBetaCastGreaterThan() { } - @Test - public void testNumericLimits() { + @ParameterizedTest + @MethodSource("parameters") + public void testNumericLimits(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -2007,7 +2076,7 @@ public void testNumericLimits() { " $r.setValue($p.getName() + \" is very old\");\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -2026,8 +2095,9 @@ public void testNumericLimits() { } - @Test - public void testMapAbbreviatedComparison() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapAbbreviatedComparison(RUN_TYPE runType) { final String drl1 = "import java.util.Map;\n" + "rule R1 when\n" + @@ -2035,7 +2105,7 @@ public void testMapAbbreviatedComparison() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); final Map map = new HashMap<>(); map.put("money", new BigDecimal(70)); @@ -2044,8 +2114,9 @@ public void testMapAbbreviatedComparison() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testMapPrimitiveComparison() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapPrimitiveComparison(RUN_TYPE runType) { final String drl1 = "import java.util.Map;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -2055,7 +2126,7 @@ public void testMapPrimitiveComparison() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); final Map map = new HashMap<>(); map.put("age", 20); @@ -2068,8 +2139,9 @@ public void testMapPrimitiveComparison() { public static final int CONSTANT = 1; - @Test - public void testMapCheckForExistence() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapCheckForExistence(RUN_TYPE runType) { final String drl1 = "import " + Person.class.getCanonicalName() + ";\n" + "import " + Result.class.getCanonicalName() + ";" + @@ -2079,7 +2151,7 @@ public void testMapCheckForExistence() { " insert(new Result($p.getName()));\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); final Map items = new HashMap<>(); items.put(CONSTANT, 2000); @@ -2098,8 +2170,9 @@ public void testMapCheckForExistence() { assertThat(results.iterator().next().getValue()).isEqualTo("Mario"); } - @Test - public void testBigDecimalIntCoercion() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalIntCoercion(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";\n" + "rule \"rule1\"\n" + "when\n" + @@ -2107,7 +2180,7 @@ public void testBigDecimalIntCoercion() { "then\n" + "end\n"; - KieSession ksession1 = getKieSession(str); + KieSession ksession1 = getKieSession(runType, str); Result fact = new Result(); fact.setValue( new BigDecimal(10) ); @@ -2115,8 +2188,9 @@ public void testBigDecimalIntCoercion() { assertThat(ksession1.fireAllRules()).isEqualTo(1); } - @Test - public void testBooleanCoercion() { + @ParameterizedTest + @MethodSource("parameters") + public void testBooleanCoercion(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -2125,7 +2199,7 @@ public void testBooleanCoercion() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person first = new Person("First", 40); first.setEmployed(true); @@ -2133,8 +2207,9 @@ public void testBooleanCoercion() { assertThat(ksession.fireAllRules()).isEqualTo(1);; } - @Test - public void testUseMatch() { + @ParameterizedTest + @MethodSource("parameters") + public void testUseMatch(RUN_TYPE runType) { // DROOLS-4579 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -2144,15 +2219,16 @@ public void testUseMatch() { " if ($p != drools.getMatch().getObjects().get(0)) throw new RuntimeException();\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person me = new Person( "Mario", 40 ); ksession.insert( me ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testMultilinePattern() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultilinePattern(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + @@ -2161,7 +2237,7 @@ public void testMultilinePattern() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person first = new Person("John", 40); first.setEmployed(true); @@ -2169,8 +2245,9 @@ public void testMultilinePattern() { assertThat(ksession.fireAllRules()).isEqualTo(1);; } - @Test - public void testAccumulateWithMax() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithMax(RUN_TYPE runType) { String str = "import " + StockTick.class.getCanonicalName() + ";" + "import " + StockTick.class.getCanonicalName() + ";" + @@ -2181,7 +2258,7 @@ public void testAccumulateWithMax() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); StockTick st = new StockTick("RHT"); st.setTimeField(new Date().getTime()); @@ -2189,8 +2266,9 @@ public void testAccumulateWithMax() { assertThat(ksession.fireAllRules()).isEqualTo(1);; } - @Test() - public void testMultipleModify() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleModify(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -2201,7 +2279,7 @@ public void testMultipleModify() { " modify($p2) { setAge($p2.getAge()+5) }\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p1 = new Person( "John", 40 ); Person p2 = new Person( "Paul", 38 ); @@ -2214,8 +2292,9 @@ public void testMultipleModify() { assertThat(p2.getAge()).isEqualTo(43); } - @Test() - public void testMultipleModifyWithDifferentFacts() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleModifyWithDifferentFacts(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Pet.class.getCanonicalName() + ";" + @@ -2233,7 +2312,7 @@ public void testMultipleModifyWithDifferentFacts() { " modify($pet) { setAge($pet.getAge()+1) }\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person person = new Person( "John", 40 ); Pet pet = new Pet( Pet.PetType.dog, 3 ); @@ -2341,8 +2420,10 @@ public String getValue(Object o) { } } - @Test // DROOLS-5007 - public void testIntToShortCast() { + // DROOLS-5007 + @ParameterizedTest + @MethodSource("parameters") + public void testIntToShortCast(RUN_TYPE runType) { String str = "import " + Address.class.getCanonicalName() + ";\n" + "rule \"rule1\"\n" + "when\n" + @@ -2353,7 +2434,7 @@ public void testIntToShortCast() { " update($address);\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Address address = new Address(); address.setNumber(1); @@ -2362,8 +2443,10 @@ public void testIntToShortCast() { } - @Test // DROOLS-5709 // DROOLS-5768 - public void testCastingIntegerToShort() { + // DROOLS-5709 // DROOLS-5768 + @ParameterizedTest + @MethodSource("parameters") + public void testCastingIntegerToShort(RUN_TYPE runType) { String str = "import " + IntegerToShort.class.getCanonicalName() + ";\n " + "rule \"test_rule\"\n" + @@ -2381,7 +2464,7 @@ public void testCastingIntegerToShort() { " update($integerToShort);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); IntegerToShort integerToShort = new IntegerToShort(false, Short.MAX_VALUE, (short)0, (double)0); ksession.insert(integerToShort); @@ -2391,8 +2474,10 @@ public void testCastingIntegerToShort() { assertThat(integerToShort).isEqualTo(new IntegerToShort(true, Short.MAX_VALUE, Short.MAX_VALUE, (double)0)); } - @Test // DROOLS-5998 - public void testCastingIntegerToShortWithNegativeNumbers() { + // DROOLS-5998 + @ParameterizedTest + @MethodSource("parameters") + public void testCastingIntegerToShortWithNegativeNumbers(RUN_TYPE runType) { String str = "import " + IntegerToShort.class.getCanonicalName() + ";\n " + "rule \"test_rule\"\n" + @@ -2409,7 +2494,7 @@ public void testCastingIntegerToShortWithNegativeNumbers() { " update($integerToShort);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); IntegerToShort integerToShort = new IntegerToShort(false, Short.MAX_VALUE, (short)0, (double)0); ksession.insert(integerToShort); @@ -2419,8 +2504,10 @@ public void testCastingIntegerToShortWithNegativeNumbers() { assertThat(integerToShort).isEqualTo(new IntegerToShort(true, Short.MAX_VALUE, (short)-12, (double)0)); } - @Test // RHDM-1644 // DROOLS-6196 - public void testCastingIntegerToShortWithDoubleVar() { + // RHDM-1644 // DROOLS-6196 + @ParameterizedTest + @MethodSource("parameters") + public void testCastingIntegerToShortWithDoubleVar(RUN_TYPE runType) { String str = "import " + IntegerToShort.class.getCanonicalName() + ";\n " + "rule \"test_rule\"\n" + @@ -2438,7 +2525,7 @@ public void testCastingIntegerToShortWithDoubleVar() { " update($integerToShort);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); IntegerToShort integerToShort = new IntegerToShort(false, Short.MAX_VALUE, (short)0, (double)1); ksession.insert(integerToShort); @@ -2448,8 +2535,10 @@ public void testCastingIntegerToShortWithDoubleVar() { assertThat(integerToShort).isEqualTo(new IntegerToShort(true, Short.MAX_VALUE, (short)17, (double)1)); } - @Test // RHDM-1644 // DROOLS-6196 - public void testUseOfVarCreatedAsInputArgInGlobalFuntionAsA_Var() { + // RHDM-1644 // DROOLS-6196 + @ParameterizedTest + @MethodSource("parameters") + public void testUseOfVarCreatedAsInputArgInGlobalFuntionAsA_Var(RUN_TYPE runType) { String str = "import " + IntegerToShort.class.getCanonicalName() + ";\n " + "global " + GlobalFunctions.class.getCanonicalName() + " functions;\n " + @@ -2468,7 +2557,7 @@ public void testUseOfVarCreatedAsInputArgInGlobalFuntionAsA_Var() { " update($integerToShort);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); IntegerToShort integerToShort = new IntegerToShort(false, Short.MAX_VALUE, (short)0); ksession.insert(integerToShort); @@ -2479,8 +2568,9 @@ public void testUseOfVarCreatedAsInputArgInGlobalFuntionAsA_Var() { assertThat(integerToShort).isEqualTo(new IntegerToShort(true, 1, (short)0)); } - @Test - public void testConsequenceGetContext() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testConsequenceGetContext(RUN_TYPE runType) throws Exception { String str = "import " + ProcessContext.class.getCanonicalName() + ";" + "rule R when\n" + @@ -2489,12 +2579,14 @@ public void testConsequenceGetContext() throws Exception { " ProcessContext clazz = drools.getContext(ProcessContext.class);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ksession).isNotNull(); } - @Test // DROOLS-6034 - public void testConsequenceInsertThenUpdate() throws Exception { + // DROOLS-6034 + @ParameterizedTest + @MethodSource("parameters") + public void testConsequenceInsertThenUpdate(RUN_TYPE runType) throws Exception { String str = "global java.util.List children;\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -2508,7 +2600,7 @@ public void testConsequenceInsertThenUpdate() throws Exception { " children.add(andrea.getName());\n" + "end"; - KieSession kSession = getKieSession( str ); + KieSession kSession = getKieSession(runType, str); ArrayList children = new ArrayList<>(); kSession.setGlobal("children", children); @@ -2521,8 +2613,10 @@ public void testConsequenceInsertThenUpdate() throws Exception { assertThat(children).containsOnly("Andrea"); } - @Test // DROOLS-6034 - public void testConsequenceInsertThenModify() throws Exception { + // DROOLS-6034 + @ParameterizedTest + @MethodSource("parameters") + public void testConsequenceInsertThenModify(RUN_TYPE runType) throws Exception { String str = "global java.util.List children;\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -2538,7 +2632,7 @@ public void testConsequenceInsertThenModify() throws Exception { " children.add(andrea.getName());\n" + "end"; - KieSession kSession = getKieSession( str ); + KieSession kSession = getKieSession(runType, str); ArrayList children = new ArrayList<>(); kSession.setGlobal("children", children); @@ -2551,8 +2645,10 @@ public void testConsequenceInsertThenModify() throws Exception { assertThat(children).containsOnly("Andrea"); } - @Test // DROOLS-6034 - public void testConsequenceInsertThenUpdateWithPatternInitializer() throws Exception { + // DROOLS-6034 + @ParameterizedTest + @MethodSource("parameters") + public void testConsequenceInsertThenUpdateWithPatternInitializer(RUN_TYPE runType) throws Exception { String str = "global java.util.List result;\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -2569,7 +2665,7 @@ public void testConsequenceInsertThenUpdateWithPatternInitializer() throws Excep " result.add(fromNameExprTwice.getName());\n" + "end"; - KieSession kSession = getKieSession( str ); + KieSession kSession = getKieSession(runType, str); ArrayList children = new ArrayList<>(); kSession.setGlobal("result", children); @@ -2582,8 +2678,9 @@ public void testConsequenceInsertThenUpdateWithPatternInitializer() throws Excep assertThat(children).containsOnly("Luca"); } - @Test - public void testExtraParenthes() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testExtraParenthes(RUN_TYPE runType) throws Exception { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -2591,7 +2688,7 @@ public void testExtraParenthes() throws Exception { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person person = new Person( "John", 20 ); @@ -2599,8 +2696,9 @@ public void testExtraParenthes() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testNegateBigDecimal() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testNegateBigDecimal(RUN_TYPE runType) throws Exception { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List list;\n" + @@ -2610,7 +2708,7 @@ public void testNegateBigDecimal() throws Exception { " list.add($p.getName());" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -2626,8 +2724,9 @@ public void testNegateBigDecimal() throws Exception { assertThat(list).containsExactly("John"); } - @Test - public void testNegateJoin() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testNegateJoin(RUN_TYPE runType) throws Exception { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + @@ -2637,7 +2736,7 @@ public void testNegateJoin() throws Exception { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Address a = new Address("Milan"); Person p = new Person("Toshiya"); @@ -2649,8 +2748,9 @@ public void testNegateJoin() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNegateComplex() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testNegateComplex(RUN_TYPE runType) throws Exception { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List list;\n" + @@ -2660,7 +2760,7 @@ public void testNegateComplex() throws Exception { " list.add($p.getName());" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -2679,8 +2779,9 @@ public void testNegateComplex() throws Exception { assertThat(list).containsExactlyInAnyOrder("John", "George"); } - @Test - public void testMapStringProp() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testMapStringProp(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -2689,7 +2790,7 @@ public void testMapStringProp() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); final Person p = new Person("Toshiya"); p.getItemsString().put("AAA", "XXX"); @@ -2698,8 +2799,9 @@ public void testMapStringProp() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testMapString() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testMapString(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + "import " + Map.class.getCanonicalName() + ";\n" + @@ -2708,7 +2810,7 @@ public void testMapString() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); Map map = new HashMap<>(); map.put("AAA", "XXX"); @@ -2717,8 +2819,9 @@ public void testMapString() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testHashSet() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testHashSet(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + "import " + HashSet.class.getCanonicalName() + ";\n" + @@ -2739,7 +2842,7 @@ public void testHashSet() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); FactType appType = ksession.getKieBase().getFactType("org.drools.test", "Application"); Object appObj = appType.newInstance(); @@ -2750,8 +2853,9 @@ public void testHashSet() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test() - public void testRhsOrderWithModify() { + @ParameterizedTest + @MethodSource("parameters") + public void testRhsOrderWithModify(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List list;\n" + @@ -2769,7 +2873,7 @@ public void testRhsOrderWithModify() { " list.add($p2.getAge());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -2783,8 +2887,9 @@ public void testRhsOrderWithModify() { assertThat(list).containsExactlyInAnyOrder(40, 38, 41, 38, 41, 43); } - @Test() - public void testStringRelationalComparison() { + @ParameterizedTest + @MethodSource("parameters") + public void testStringRelationalComparison(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List list;\n" + @@ -2794,7 +2899,7 @@ public void testStringRelationalComparison() { " list.add($p.getName());" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -2805,11 +2910,9 @@ public void testStringRelationalComparison() { assertThat(list).containsExactly("John"); } - @Rule - public ExpectedException exceptionRule = ExpectedException.none(); - - @Test - public void testNPEOnConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testNPEOnConstraint(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -2817,7 +2920,7 @@ public void testNPEOnConstraint() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person me = new Person( "Luca"); me.setMoney(null); @@ -2826,8 +2929,9 @@ public void testNPEOnConstraint() { .isThrownBy(() -> ksession.fireAllRules()) .withMessage("Error evaluating constraint 'money < salary * 20' in [Rule \"R\" in r0.drl]"); } - @Test - public void testSharedPredicateInformation() { + @ParameterizedTest + @MethodSource("parameters") + public void testSharedPredicateInformation(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + @@ -2839,7 +2943,7 @@ public void testSharedPredicateInformation() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person me = new Person("Luca"); me.setSalary(null); @@ -2851,8 +2955,9 @@ public void testSharedPredicateInformation() { .withMessage("Error evaluating constraint 'money < salary * 20' in [Rule \"R1\", \"R2\" in r0.drl]"); } - @Test - public void testSharedPredicateInformationWithNonSharedRule() { + @ParameterizedTest + @MethodSource("parameters") + public void testSharedPredicateInformationWithNonSharedRule(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + @@ -2869,7 +2974,7 @@ public void testSharedPredicateInformationWithNonSharedRule() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person me = new Person("Luca"); me.setSalary(null); @@ -2882,8 +2987,9 @@ public void testSharedPredicateInformationWithNonSharedRule() { } - @Test - public void testSharedPredicateInformationWithMultipleFiles() { + @ParameterizedTest + @MethodSource("parameters") + public void testSharedPredicateInformationWithMultipleFiles(RUN_TYPE runType) { String str1 = "import " + Person.class.getCanonicalName() + ";" + @@ -2906,7 +3012,7 @@ public void testSharedPredicateInformationWithMultipleFiles() { "then\n" + "end"; - KieSession ksession = getKieSession(str1, str2); + KieSession ksession = getKieSession(runType, str1, str2); Person me = new Person("Luca"); me.setSalary(null); @@ -2919,8 +3025,9 @@ public void testSharedPredicateInformationWithMultipleFiles() { } - @Test - public void testSharedBetaPredicateInformationWithMultipleFiles() { + @ParameterizedTest + @MethodSource("parameters") + public void testSharedBetaPredicateInformationWithMultipleFiles(RUN_TYPE runType) { String str1 = "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + @@ -2946,7 +3053,7 @@ public void testSharedBetaPredicateInformationWithMultipleFiles() { "then\n" + "end"; - KieSession ksession = getKieSession(str1, str2); + KieSession ksession = getKieSession(runType, str1, str2); Person me = new Person("Luca"); me.setSalary(null); @@ -2959,8 +3066,9 @@ public void testSharedBetaPredicateInformationWithMultipleFiles() { .withMessage("Error evaluating constraint '$i < salary * 20' in [Rule \"R1\", \"R2\" in r0.drl] [Rule \"R3\", \"R4\" in r1.drl]"); } - @Test - public void testSharedPredicateInformationExceedMaxRuleDefs() { + @ParameterizedTest + @MethodSource("parameters") + public void testSharedPredicateInformationExceedMaxRuleDefs(RUN_TYPE runType) { // shared by 11 rules String str1 = "import " + Person.class.getCanonicalName() + ";" + @@ -3024,7 +3132,7 @@ public void testSharedPredicateInformationExceedMaxRuleDefs() { "then\n" + "end"; - KieSession ksession = getKieSession(str1, str2, str3); + KieSession ksession = getKieSession(runType, str1, str2, str3); Person me = new Person("Luca"); me.setSalary(null); @@ -3039,8 +3147,9 @@ public void testSharedPredicateInformationExceedMaxRuleDefs() { } - @Test - public void testWithQuotedStringConcatenationOnConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testWithQuotedStringConcatenationOnConstraint(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -3048,7 +3157,7 @@ public void testWithQuotedStringConcatenationOnConstraint() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person me = new Person( "Luca II"); me.setMoney(null); @@ -3057,8 +3166,9 @@ public void testWithQuotedStringConcatenationOnConstraint() { assertThat(rulesFired).isEqualTo(1); } - @Test - public void testNegatedConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testNegatedConstraint(RUN_TYPE runType) { // DROOLS-5791 String str = "rule R when\n" + @@ -3067,15 +3177,16 @@ public void testNegatedConstraint() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( 5 ); ksession.insert( "test" ); assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testMethodCallWithClass() { + @ParameterizedTest + @MethodSource("parameters") + public void testMethodCallWithClass(RUN_TYPE runType) { final String str = "package org.drools.mvel.compiler\n" + "import " + FactWithMethod.class.getCanonicalName() + ";" + "rule r1\n" + @@ -3084,7 +3195,7 @@ public void testMethodCallWithClass() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final FactWithMethod fact = new FactWithMethod(); ksession.insert(fact); final int rules = ksession.fireAllRules(); @@ -3108,8 +3219,9 @@ default String getDefaultString() { public static class MyClass implements MyInterface { } - @Test - public void testUseDefaultMethod() { + @ParameterizedTest + @MethodSource("parameters") + public void testUseDefaultMethod(RUN_TYPE runType) { // DROOLS-6358 final String str = "package org.drools.mvel.compiler\n" + @@ -3122,7 +3234,7 @@ public void testUseDefaultMethod() { " list.add(val);" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -3133,8 +3245,9 @@ public void testUseDefaultMethod() { assertThat(list.get(0)).isEqualTo("DEFAULT"); } - @Test - public void testSharedConstraintWithExtraParenthesis() { + @ParameterizedTest + @MethodSource("parameters") + public void testSharedConstraintWithExtraParenthesis(RUN_TYPE runType) { // DROOLS-6548 final String str = "package org.drools.mvel.compiler\n" + @@ -3152,7 +3265,7 @@ public void testSharedConstraintWithExtraParenthesis() { " list.add(\"r2\");" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -3162,8 +3275,9 @@ public void testSharedConstraintWithExtraParenthesis() { assertThat(list.get(0)).isEqualTo("r1"); } - @Test - public void orWithMethodCall() { + @ParameterizedTest + @MethodSource("parameters") + public void orWithMethodCall(RUN_TYPE runType) { final String str = "package org.example\n" + "import " + MyFact.class.getCanonicalName() + ";" + @@ -3172,15 +3286,16 @@ public void orWithMethodCall() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new MyFact(5)); int fired = ksession.fireAllRules(); assertThat(fired).isEqualTo(1); } - @Test - public void orWithMethodCallWithArg() { + @ParameterizedTest + @MethodSource("parameters") + public void orWithMethodCallWithArg(RUN_TYPE runType) { final String str = "package org.example\n" + "import " + MyFact.class.getCanonicalName() + ";" + @@ -3189,7 +3304,7 @@ public void orWithMethodCallWithArg() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new MyFact(5)); int fired = ksession.fireAllRules(); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ComplexRulesTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ComplexRulesTest.java index 7853acecf99..adce0b0f321 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ComplexRulesTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ComplexRulesTest.java @@ -20,7 +20,6 @@ import java.time.LocalDateTime; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -41,19 +40,17 @@ import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.RootFact; import org.drools.model.codegen.execmodel.domain.SubFact; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class ComplexRulesTest extends BaseModelTest { - public ComplexRulesTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void test1() { + @ParameterizedTest + @MethodSource("parameters") + public void test1(RUN_TYPE runType) { String str = "import " + EnumFact1.class.getCanonicalName() + ";\n" + "import " + EnumFact2.class.getCanonicalName() + ";\n" + @@ -100,11 +97,12 @@ public void test1() { " list.add($result);\n" + "end\n"; - testComplexRule(str); + testComplexRule(runType, str); } - @Test - public void testNotWithEval() { + @ParameterizedTest + @MethodSource("parameters") + public void testNotWithEval(RUN_TYPE runType) { String str = "import " + EnumFact1.class.getCanonicalName() + ";\n" + "import " + EnumFact2.class.getCanonicalName() + ";\n" + @@ -151,11 +149,11 @@ public void testNotWithEval() { " list.add($result);\n" + "end\n"; - testComplexRule(str); + testComplexRule(runType, str); } - private void testComplexRule(final String rule) { - KieSession ksession = getKieSession( rule ); + private void testComplexRule(RUN_TYPE runType, String rule) { + KieSession ksession = getKieSession(runType, rule); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -176,8 +174,9 @@ private void testComplexRule(final String rule) { assertThat((int) list.get(0)).isEqualTo(1); } - @Test - public void test2() { + @ParameterizedTest + @MethodSource("parameters") + public void test2(RUN_TYPE runType) { final String drl = " import org.drools.model.codegen.execmodel.domain.*;\n" + " rule \"R1\"\n" + @@ -200,7 +199,7 @@ public void test2() { " update($childFact4);\n" + " end\n"; - KieSession ksession = getKieSession( drl ); + KieSession ksession = getKieSession(runType, drl ); int initialId = 1; final RootFact rootFact = new RootFact(initialId); @@ -220,8 +219,9 @@ public void test2() { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void test3() { + @ParameterizedTest + @MethodSource("parameters") + public void test3(RUN_TYPE runType) { String str = "import " + RootFact.class.getCanonicalName() + ";\n" + "import " + ChildFactWithObject.class.getCanonicalName() + ";\n" + @@ -243,7 +243,7 @@ public void test3() { " list.add($result);\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -258,8 +258,9 @@ public void test3() { assertThat((int) list.get(0)).isEqualTo(1); } - @Test - public void test4() { + @ParameterizedTest + @MethodSource("parameters") + public void test4(RUN_TYPE runType) { String str = "import " + RootFact.class.getCanonicalName() + ";\n" + "import " + ChildFactWithObject.class.getCanonicalName() + ";\n" + @@ -280,7 +281,7 @@ public void test4() { " list.add($result);\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -294,8 +295,9 @@ public void test4() { assertThat((int) list.get(0)).isEqualTo(1); } - @Test - public void testEnum() { + @ParameterizedTest + @MethodSource("parameters") + public void testEnum(RUN_TYPE runType) { String str = "import " + EnumFact1.class.getCanonicalName() + ";\n" + "import " + ChildFactWithEnum1.class.getCanonicalName() + ";\n" + @@ -305,13 +307,14 @@ public void testEnum() { " then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ChildFactWithEnum1(1, 3, EnumFact1.FIRST) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNotInEnum() { + @ParameterizedTest + @MethodSource("parameters") + public void testNotInEnum(RUN_TYPE runType) { String str = "import " + EnumFact1.class.getCanonicalName() + ";\n" + "import " + ChildFactWithEnum1.class.getCanonicalName() + ";\n" + @@ -321,13 +324,14 @@ public void testNotInEnum() { " then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ChildFactWithEnum1(1, 3, EnumFact1.SECOND) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNotInInterfaceAsEnum() { + @ParameterizedTest + @MethodSource("parameters") + public void testNotInInterfaceAsEnum(RUN_TYPE runType) { String str = "import " + InterfaceAsEnum.class.getCanonicalName() + ";\n" + "import " + ChildFactWithEnum1.class.getCanonicalName() + ";\n" + @@ -337,13 +341,14 @@ public void testNotInInterfaceAsEnum() { " then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ChildFactWithEnum1(1, 3, EnumFact1.SECOND) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testConstraintWithFunctionUsingThis() { + @ParameterizedTest + @MethodSource("parameters") + public void testConstraintWithFunctionUsingThis(RUN_TYPE runType) { String str = "import " + ChildFactWithObject.class.getCanonicalName() + ";\n" + "import " + BusinessFunctions.class.getCanonicalName() + ";\n" + @@ -356,14 +361,15 @@ public void testConstraintWithFunctionUsingThis() { " then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal( "functions", new BusinessFunctions() ); ksession.insert( new ChildFactWithObject(5, 1, new Object[0]) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testConstraintWithTernaryOperator() { + @ParameterizedTest + @MethodSource("parameters") + public void testConstraintWithTernaryOperator(RUN_TYPE runType) { String str = "import " + ChildFactWithObject.class.getCanonicalName() + ";\n" + "import " + BusinessFunctions.class.getCanonicalName() + ";\n" + @@ -377,15 +383,16 @@ public void testConstraintWithTernaryOperator() { " then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal( "functions", new BusinessFunctions() ); ksession.insert( "test" ); ksession.insert( new ChildFactWithObject(5, 1, new Object[0]) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testCastInConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testCastInConstraint(RUN_TYPE runType) { String str = "import " + ChildFactWithObject.class.getCanonicalName() + ";\n" + "import " + BusinessFunctions.class.getCanonicalName() + ";\n" + @@ -395,14 +402,15 @@ public void testCastInConstraint() { " then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal( "functions", new BusinessFunctions() ); ksession.insert( new ChildFactWithObject(5, 1, new Object[0]) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testConstraintWithFunctionAndStringConcatenation() { + @ParameterizedTest + @MethodSource("parameters") + public void testConstraintWithFunctionAndStringConcatenation(RUN_TYPE runType) { String str = "import " + ChildFactWithObject.class.getCanonicalName() + ";\n" + "import " + BusinessFunctions.class.getCanonicalName() + ";\n" + @@ -416,14 +424,15 @@ public void testConstraintWithFunctionAndStringConcatenation() { " then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal( "functions", new BusinessFunctions() ); ksession.insert( new ChildFactWithObject(5, 1, new Object[0]) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testEvalWithFunction() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalWithFunction(RUN_TYPE runType) { String str = "import " + ChildFactWithObject.class.getCanonicalName() + ";\n" + "import " + BusinessFunctions.class.getCanonicalName() + ";\n" + @@ -437,14 +446,15 @@ public void testEvalWithFunction() { " then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal( "functions", new BusinessFunctions() ); ksession.insert( new ChildFactWithObject(5, 1, new Object[0]) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testEqualOnShortField() { + @ParameterizedTest + @MethodSource("parameters") + public void testEqualOnShortField(RUN_TYPE runType) { String str = "import " + ChildFactWithObject.class.getCanonicalName() + ";\n" + "rule R when\n" + @@ -453,13 +463,14 @@ public void testEqualOnShortField() { " then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ChildFactWithObject(5, 1, new Object[0]) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testGreaterOnShortField() { + @ParameterizedTest + @MethodSource("parameters") + public void testGreaterOnShortField(RUN_TYPE runType) { String str = "import " + ChildFactWithObject.class.getCanonicalName() + ";\n" + "rule R when\n" + @@ -468,13 +479,14 @@ public void testGreaterOnShortField() { " then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ChildFactWithObject(5, 1, new Object[0]) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testBooleanField() { + @ParameterizedTest + @MethodSource("parameters") + public void testBooleanField(RUN_TYPE runType) { String str = "import " + ChildFactWithObject.class.getCanonicalName() + ";\n" + "rule R when\n" + @@ -483,13 +495,14 @@ public void testBooleanField() { " then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ChildFactWithObject(5, 1, new Object[0]) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testConsequenceThrowingException() { + @ParameterizedTest + @MethodSource("parameters") + public void testConsequenceThrowingException(RUN_TYPE runType) { String str = "import " + ChildFactWithObject.class.getCanonicalName() + ";\n" + "import " + BusinessFunctions.class.getCanonicalName() + ";\n" + @@ -501,14 +514,15 @@ public void testConsequenceThrowingException() { " functions.doSomethingRisky($c);" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal( "functions", new BusinessFunctions() ); ksession.insert( new ChildFactWithObject(5, 1, new Object[0]) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testCompareDate() { + @ParameterizedTest + @MethodSource("parameters") + public void testCompareDate(RUN_TYPE runType) { String str = "import " + ChildFactWithObject.class.getCanonicalName() + ";\n" + "rule R when\n" + @@ -518,14 +532,15 @@ public void testCompareDate() { " then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ChildFactWithObject(5, 1, new Object[0]) ); ksession.insert( new ChildFactWithObject(6, 1, new Object[0]) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testCompareDateWithString() { + @ParameterizedTest + @MethodSource("parameters") + public void testCompareDateWithString(RUN_TYPE runType) { String str = "import " + ChildFactWithObject.class.getCanonicalName() + ";\n" + "rule R when\n" + @@ -534,13 +549,14 @@ public void testCompareDateWithString() { " then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ChildFactWithObject(5, 1, new Object[0]) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void test2UpperCaseProp() { + @ParameterizedTest + @MethodSource("parameters") + public void test2UpperCaseProp(RUN_TYPE runType) { String str = "import " + ChildFactWithObject.class.getCanonicalName() + ";\n" + "rule R when\n" + @@ -550,7 +566,7 @@ public void test2UpperCaseProp() { " then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ChildFactWithObject(5, 1, new Object[0]) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } @@ -571,8 +587,9 @@ public List getList() { } } - @Test - public void testNameClashBetweenAttributeAndGlobal() { + @ParameterizedTest + @MethodSource("parameters") + public void testNameClashBetweenAttributeAndGlobal(RUN_TYPE runType) { String str = "import " + ListContainer.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + @@ -582,7 +599,7 @@ public void testNameClashBetweenAttributeAndGlobal() { " list.add($l);" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList(); ksession.setGlobal( "list", list ); @@ -598,8 +615,9 @@ public char[] getCharArray() { } } - @Test - public void testPrimitiveArray() { + @ParameterizedTest + @MethodSource("parameters") + public void testPrimitiveArray(RUN_TYPE runType) { String str = "import " + Primitives.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + @@ -609,7 +627,7 @@ public void testPrimitiveArray() { " list.add($c);" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList(); ksession.setGlobal( "list", list ); @@ -619,8 +637,9 @@ public void testPrimitiveArray() { assertThat(list.size()).isEqualTo(1); } - @Test - public void testUseConstructorInConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testUseConstructorInConstraint(RUN_TYPE runType) { // DROOLS-2990 String str = "rule R when\n" + @@ -629,15 +648,16 @@ public void testUseConstructorInConstraint() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( (short) 1 ); ksession.insert( 2.0 ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testManyPropFactWithNot() { + @ParameterizedTest + @MethodSource("parameters") + public void testManyPropFactWithNot(RUN_TYPE runType) { // DROOLS-4572 try { System.setProperty("drools.propertySpecific", "ALLOWED"); @@ -660,7 +680,7 @@ public void testManyPropFactWithNot() { " update($subFact);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ManyPropFact fact = new ManyPropFact(); fact.setId(1); @@ -698,8 +718,9 @@ public CaseData getMe() { } } - @Test - public void testGetOnMapField() { + @ParameterizedTest + @MethodSource("parameters") + public void testGetOnMapField(RUN_TYPE runType) { // DROOLS-4999 String str = "import " + CaseData.class.getCanonicalName() + ";\n" + @@ -708,15 +729,16 @@ public void testGetOnMapField() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new CaseData( 5 ) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testEqualsOnMapField() { + @ParameterizedTest + @MethodSource("parameters") + public void testEqualsOnMapField(RUN_TYPE runType) { // DROOLS-4999 String str = "import " + CaseData.class.getCanonicalName() + ";\n" + @@ -725,15 +747,16 @@ public void testEqualsOnMapField() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new CaseData( "OK" ) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testDoubleNegation() { + @ParameterizedTest + @MethodSource("parameters") + public void testDoubleNegation(RUN_TYPE runType) { // DROOLS-5545 String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -742,13 +765,14 @@ public void testDoubleNegation() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 45 ) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testGlobalAsFunctionArgument() { + @ParameterizedTest + @MethodSource("parameters") + public void testGlobalAsFunctionArgument(RUN_TYPE runType) { // DROOLS-5999 String str = "import java.util.*;\n"+ @@ -773,7 +797,7 @@ public void testGlobalAsFunctionArgument() { " result.add(Integer.valueOf(42));\n"+ "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConditionalExprTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConditionalExprTest.java index a8d5908248c..5b08b24674c 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConditionalExprTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConditionalExprTest.java @@ -22,8 +22,10 @@ import java.util.List; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; @@ -47,41 +49,40 @@ public class ConditionalExprTest extends BaseModelTest { private KieSession ksession; private List booleanListGlobal; - public ConditionalExprTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Before + @BeforeEach public void setup() { - ksession = getKieSession(RULE_STRING); booleanListGlobal = new ArrayList<>(); - ksession.setGlobal("booleanListGlobal", booleanListGlobal); + } + + @AfterEach + public void tearDown() { + if (ksession != null) { + ksession.dispose(); + } } - @Test - public void testConditionalExpressionWithNamedPerson() { - try { - Person person = new Person("someName"); - ksession.insert(person); - int rulesFired = ksession.fireAllRules(); - assertThat(rulesFired).isEqualTo(1); - assertThat(booleanListGlobal).isNotEmpty().containsExactly(Boolean.TRUE); - } finally { - ksession.dispose(); - } + @ParameterizedTest + @MethodSource("parameters") + public void testConditionalExpressionWithNamedPerson(RUN_TYPE runType) { + ksession = getKieSession(runType, RULE_STRING); + ksession.setGlobal("booleanListGlobal", booleanListGlobal); + Person person = new Person("someName"); + ksession.insert(person); + int rulesFired = ksession.fireAllRules(); + assertThat(rulesFired).isEqualTo(1); + assertThat(booleanListGlobal).isNotEmpty().containsExactly(Boolean.TRUE); } - @Test - public void testConditionalExpressionWithUnnamedPerson() { - try { - Person person = new Person(); - ksession.insert(person); - int rulesFired = ksession.fireAllRules(); - assertThat(rulesFired).isEqualTo(1); - assertThat(booleanListGlobal).isNotEmpty().containsExactly(Boolean.FALSE); - } finally { - ksession.dispose(); - } + @ParameterizedTest + @MethodSource("parameters") + public void testConditionalExpressionWithUnnamedPerson(RUN_TYPE runType) { + ksession = getKieSession(runType, RULE_STRING); + ksession.setGlobal("booleanListGlobal", booleanListGlobal); + Person person = new Person(); + ksession.insert(person); + int rulesFired = ksession.fireAllRules(); + assertThat(rulesFired).isEqualTo(1); + assertThat(booleanListGlobal).isNotEmpty().containsExactly(Boolean.FALSE); } } \ No newline at end of file diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConstraintNormalizationTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConstraintNormalizationTest.java index 939722b9bee..058242c8cc5 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConstraintNormalizationTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConstraintNormalizationTest.java @@ -32,7 +32,8 @@ import org.drools.model.codegen.execmodel.domain.Address; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Toy; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.definition.type.FactType; import org.kie.api.runtime.KieSession; @@ -40,12 +41,9 @@ public class ConstraintNormalizationTest extends BaseModelTest { - public ConstraintNormalizationTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Test - public void testNormalizationForPropertyReactivity() { + @ParameterizedTest + @MethodSource("parameters") + public void testNormalizationForPropertyReactivity(RUN_TYPE runType) { final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -62,7 +60,7 @@ public void testNormalizationForPropertyReactivity() { "then\n" + "end\n"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); final Toy t = new Toy("Ball"); t.setOwner("Toshiya"); @@ -72,8 +70,9 @@ public void testNormalizationForPropertyReactivity() { assertThat(ksession.fireAllRules(10)).isEqualTo(2); // no infinite loop } - @Test - public void testNormalizationForPropertyReactivity2() { + @ParameterizedTest + @MethodSource("parameters") + public void testNormalizationForPropertyReactivity2(RUN_TYPE runType) { final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -89,7 +88,7 @@ public void testNormalizationForPropertyReactivity2() { "then\n" + "end\n"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); final Person p = new Person("Toshiya", 45); ksession.insert(new Integer(30)); @@ -97,8 +96,9 @@ public void testNormalizationForPropertyReactivity2() { assertThat(ksession.fireAllRules(10)).isEqualTo(2); // no infinite loop } - @Test - public void testNormalizationForAlphaIndexing() { + @ParameterizedTest + @MethodSource("parameters") + public void testNormalizationForAlphaIndexing(RUN_TYPE runType) { final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -115,7 +115,7 @@ public void testNormalizationForAlphaIndexing() { "then\n" + "end\n"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); ObjectTypeNode otn = ((NamedEntryPoint) ksession.getEntryPoint("DEFAULT")).getEntryPointNode().getObjectTypeNodes().entrySet() .stream() @@ -134,8 +134,9 @@ public void testNormalizationForAlphaIndexing() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNormalizationForNodeSharing() { + @ParameterizedTest + @MethodSource("parameters") + public void testNormalizationForNodeSharing(RUN_TYPE runType) { final String str = "package org.drools.test;\n" + @@ -149,7 +150,7 @@ public void testNormalizationForNodeSharing() { "then\n" + "end\n"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); @@ -158,8 +159,9 @@ public void testNormalizationForNodeSharing() { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testOperators() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testOperators(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + @@ -176,7 +178,7 @@ public void testOperators() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(4); @@ -189,8 +191,9 @@ public void testOperators() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testNestedProperty() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testNestedProperty(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -204,7 +207,7 @@ public void testNestedProperty() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); @@ -216,8 +219,9 @@ public void testNestedProperty() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testComplexMethod() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexMethod(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -232,7 +236,7 @@ public void testComplexMethod() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); @@ -244,8 +248,9 @@ public void testComplexMethod() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testPropsOnBothSide() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testPropsOnBothSide(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -259,7 +264,7 @@ public void testPropsOnBothSide() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); @@ -271,8 +276,9 @@ public void testPropsOnBothSide() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testExtraParentheses() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testExtraParentheses(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -286,7 +292,7 @@ public void testExtraParentheses() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); @@ -297,8 +303,9 @@ public void testExtraParentheses() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testAnd() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testAnd(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -312,10 +319,10 @@ public void testAnd() throws Exception { "then\n" + "end\n"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly - if (testRunType == RUN_TYPE.STANDARD_FROM_DRL || testRunType == RUN_TYPE.STANDARD_WITH_ALPHA_NETWORK) { + if (runType == RUN_TYPE.STANDARD_FROM_DRL || runType == RUN_TYPE.STANDARD_WITH_ALPHA_NETWORK) { assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(2); } else { // && is not split in case of executable-model @@ -329,8 +336,9 @@ public void testAnd() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testOr() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testOr(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -344,7 +352,7 @@ public void testOr() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); @@ -356,8 +364,9 @@ public void testOr() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testNegate() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testNegate(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -371,7 +380,7 @@ public void testNegate() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); @@ -382,8 +391,9 @@ public void testNegate() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testBigDecimal() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimal(RUN_TYPE runType) throws Exception { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + @@ -396,7 +406,7 @@ public void testBigDecimal() throws Exception { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); @@ -409,8 +419,9 @@ public void testBigDecimal() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testNegateComplex() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testNegateComplex(RUN_TYPE runType) throws Exception { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List list;\n" + @@ -426,7 +437,7 @@ public void testNegateComplex() throws Exception { " list.add($p.getName());" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); @@ -449,8 +460,9 @@ public void testNegateComplex() throws Exception { assertThat(list).containsExactlyInAnyOrder("John", "George", "John", "George"); } - @Test - public void testNegateComplex2() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testNegateComplex2(RUN_TYPE runType) throws Exception { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List list;\n" + @@ -466,7 +478,7 @@ public void testNegateComplex2() throws Exception { " list.add($p.getName());" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); @@ -489,8 +501,9 @@ public void testNegateComplex2() throws Exception { assertThat(list).containsExactlyInAnyOrder("John", "George", "John", "George"); } - @Test - public void testDeclaredType() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testDeclaredType(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + "declare Person\n" + @@ -507,7 +520,7 @@ public void testDeclaredType() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(2); @@ -520,8 +533,9 @@ public void testDeclaredType() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testMapProp() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testMapProp(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -535,7 +549,7 @@ public void testMapProp() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); @@ -547,8 +561,9 @@ public void testMapProp() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testMapStringProp() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testMapStringProp(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -562,7 +577,7 @@ public void testMapStringProp() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); @@ -574,8 +589,9 @@ public void testMapStringProp() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testMapStringThis() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testMapStringThis(RUN_TYPE runType) throws Exception { final String str = "package org.drools.test;\n" + "import " + Map.class.getCanonicalName() + ";\n" + @@ -589,7 +605,7 @@ public void testMapStringThis() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); // Check NodeSharing to verify if normalization works expectedly assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConstraintTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConstraintTest.java index b3475e58c2d..5eced33ee03 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConstraintTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ConstraintTest.java @@ -23,8 +23,10 @@ import java.util.List; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; @@ -50,41 +52,40 @@ public class ConstraintTest extends BaseModelTest { private List bigDecimalListGlobal; - public ConstraintTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Before + @BeforeEach public void setup() { - ksession = getKieSession(RULE_STRING); bigDecimalListGlobal = new ArrayList<>(); - ksession.setGlobal("bigDecimalListGlobal", bigDecimalListGlobal); + } + + @AfterEach + public void tearDown() { + if (ksession != null) { + ksession.dispose(); + } } - @Test - public void testConstraintWithMoney() { - try { - BigDecimal money = BigDecimal.valueOf(34.45); - Person person = new Person("", money); - ksession.insert(person); - int rulesFired = ksession.fireAllRules(); - assertThat(rulesFired).isEqualTo(1); - assertThat(bigDecimalListGlobal).isNotEmpty().containsExactly(money); - } finally { - ksession.dispose(); - } + @ParameterizedTest + @MethodSource("parameters") + public void testConstraintWithMoney(RUN_TYPE runType) { + ksession = getKieSession(runType, RULE_STRING); + ksession.setGlobal("bigDecimalListGlobal", bigDecimalListGlobal); + BigDecimal money = BigDecimal.valueOf(34.45); + Person person = new Person("", money); + ksession.insert(person); + int rulesFired = ksession.fireAllRules(); + assertThat(rulesFired).isEqualTo(1); + assertThat(bigDecimalListGlobal).isNotEmpty().containsExactly(money); } - @Test - public void testConstraintWithoutMoney() { - try { - Person person = new Person(); - ksession.insert(person); - int rulesFired = ksession.fireAllRules(); - assertThat(rulesFired).isEqualTo(1); - assertThat(bigDecimalListGlobal).isNotEmpty().containsExactly(BigDecimal.valueOf(100.0)); - } finally { - ksession.dispose(); - } + @ParameterizedTest + @MethodSource("parameters") + public void testConstraintWithoutMoney(RUN_TYPE runType) { + ksession = getKieSession(runType, RULE_STRING); + ksession.setGlobal("bigDecimalListGlobal", bigDecimalListGlobal); + Person person = new Person(); + ksession.insert(person); + int rulesFired = ksession.fireAllRules(); + assertThat(rulesFired).isEqualTo(1); + assertThat(bigDecimalListGlobal).isNotEmpty().containsExactly(BigDecimal.valueOf(100.0)); } } diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CustomConstraintOperatorTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CustomConstraintOperatorTest.java index d1b5c6f7768..4a5ad46f851 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CustomConstraintOperatorTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/CustomConstraintOperatorTest.java @@ -37,7 +37,7 @@ import org.drools.model.prototype.PrototypeVariable; import org.drools.modelcompiler.KieBaseBuilder; import org.drools.modelcompiler.constraints.LambdaConstraint; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieBase; import org.kie.api.prototype.PrototypeFact; import org.kie.api.prototype.PrototypeFactInstance; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DeclaredTypeDifferentKJarIncludesTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DeclaredTypeDifferentKJarIncludesTest.java index a51146f0c5b..26d837003a5 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DeclaredTypeDifferentKJarIncludesTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DeclaredTypeDifferentKJarIncludesTest.java @@ -20,8 +20,9 @@ import org.drools.compiler.kie.builder.impl.DrlProject; import org.drools.model.codegen.ExecutableModelProject; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.drools.io.ByteArrayResource; -import org.junit.Test; import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; @@ -49,9 +50,6 @@ public class DeclaredTypeDifferentKJarIncludesTest extends BaseModelTest { private final String SUPER_KBASE_PACKAGE = "org.superkbase"; private final ReleaseIdImpl SUPER_RELEASE_ID = new ReleaseIdImpl(SUPER_KBASE_PACKAGE, "superkbase", "1.0.0"); - public DeclaredTypeDifferentKJarIncludesTest(RUN_TYPE testRunType) { - super(testRunType); - } private static final String SUPER_RULE = "package org.superkbase;\n" + "\n" + @@ -80,9 +78,10 @@ public DeclaredTypeDifferentKJarIncludesTest(RUN_TYPE testRunType) { " delete($s);\n" + "end\n"; - @Test - public void testChildIncludingSuper() { - KieBase kBase = createKieBase(); + @ParameterizedTest + @MethodSource("parameters") + public void testChildIncludingSuper(RUN_TYPE runType) { + KieBase kBase = createKieBase(runType); KieSession newSuperKieBase = kBase.newKieSession(); newSuperKieBase.insert(10); @@ -92,16 +91,16 @@ public void testChildIncludingSuper() { assertThat(newSuperKieBase.getObjects().size()).isEqualTo(0); } - private KieBase createKieBase() { + private KieBase createKieBase(RUN_TYPE runType) { KieServices kieServices = KieServices.Factory.get(); - superKieBase(kieServices); - childKieBase(kieServices); + superKieBase(kieServices, runType); + childKieBase(kieServices, runType); return kieServices.newKieContainer(CHILD_RELEASE_ID).getKieBase(CHILD_KBASE_NAME); } - private void superKieBase(KieServices kieServices) { + private void superKieBase(KieServices kieServices, RUN_TYPE runType) { KieModuleModel superKModule = kieServices.newKieModuleModel(); KieBaseModel superKieBase = superKModule.newKieBaseModel(SUPER_KBASE_NAME); @@ -116,10 +115,10 @@ private void superKieBase(KieServices kieServices) { superFileSystem.writeKModuleXML(superKModule.toXML()); superFileSystem.write("pom.xml", generatePomXmlWithDependencies(SUPER_RELEASE_ID)); - kieServices.newKieBuilder(superFileSystem).buildAll(buildProjectClass()); + kieServices.newKieBuilder(superFileSystem).buildAll(buildProjectClass(runType)); } - private void childKieBase(KieServices kieServices) { + private void childKieBase(KieServices kieServices, RUN_TYPE runType) { KieModuleModel childKModule = kieServices.newKieModuleModel(); KieBaseModel childKbase = childKModule.newKieBaseModel(CHILD_KBASE_NAME) .setDefault(true) @@ -135,7 +134,7 @@ private void childKieBase(KieServices kieServices) { childFileSystem.writeKModuleXML(childKModule.toXML()); childFileSystem.write("pom.xml", generatePomXmlWithDependencies(CHILD_RELEASE_ID, SUPER_RELEASE_ID)); - kieServices.newKieBuilder(childFileSystem).buildAll(buildProjectClass()); + kieServices.newKieBuilder(childFileSystem).buildAll(buildProjectClass(runType)); } private static String generatePomXmlWithDependencies(ReleaseId releaseId, ReleaseId... dependencies) { @@ -176,8 +175,8 @@ private static void toGAV(ReleaseId releaseId, StringBuilder sBuilder) { sBuilder.append(" \n"); } - private Class buildProjectClass() { - if (asList(PATTERN_DSL, PATTERN_WITH_ALPHA_NETWORK).contains(testRunType)) { + private Class buildProjectClass(RUN_TYPE runType) { + if (asList(PATTERN_DSL, PATTERN_WITH_ALPHA_NETWORK).contains(runType)) { return ExecutableModelProject.class; } else { return DrlProject.class; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DeclaredTypesTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DeclaredTypesTest.java index 664ae7534ed..a6d4ba52f95 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DeclaredTypesTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DeclaredTypesTest.java @@ -35,7 +35,8 @@ import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.definition.type.FactType; import org.kie.api.runtime.KieSession; @@ -44,12 +45,9 @@ public class DeclaredTypesTest extends BaseModelTest { - public DeclaredTypesTest(RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testPojo() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testPojo(RUN_TYPE runType) throws Exception { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -67,7 +65,7 @@ public void testPojo() throws Exception { " insert(new Result(p));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mario", 40)); ksession.insert(new Person("Mark", 37)); @@ -98,8 +96,9 @@ public void testPojo() throws Exception { assertThat(luca.toString()).isEqualTo("POJOPerson( name=Luca, surname=null, age=32 )"); } - @Test - public void testPojoInDifferentPackages() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testPojoInDifferentPackages(RUN_TYPE runType) throws Exception { String ruleWithPojo = "package org.drools.pojo.model;" + "\n" + @@ -128,7 +127,7 @@ public void testPojoInDifferentPackages() throws Exception { " insert(new Result($p));\n" + "end\n"; - KieSession ksession = getKieSession(rule, ruleWithPojo); + KieSession ksession = getKieSession(runType, rule, ruleWithPojo); ksession.insert(new Person("Mario", 40)); ksession.insert(new Person("Mark", 37)); @@ -159,8 +158,9 @@ public void testPojoInDifferentPackages() throws Exception { assertThat(luca.toString()).isEqualTo("POJOPerson( name=Luca, surname=null, age=32 )"); } - @Test - public void testPojoReferencingEachOthers() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testPojoReferencingEachOthers(RUN_TYPE runType) throws Exception { String factA = "package org.kie.test;" + "\n" + @@ -183,13 +183,14 @@ public void testPojoReferencingEachOthers() throws Exception { "then\n" + "end"; - KieSession ksession = getKieSession(rule, factA, factB); + KieSession ksession = getKieSession(runType, rule, factA, factB); ksession.fireAllRules(); } - @Test - public void testDeclaredTypeInLhs() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testDeclaredTypeInLhs(RUN_TYPE runType) throws Exception { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -212,7 +213,7 @@ public void testDeclaredTypeInLhs() throws Exception { " insert(new Result($p));\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mario", 40)); ksession.insert(new Person("Mark", 37)); @@ -265,8 +266,9 @@ public String toString() { } } - @Test - public void testPojoPredicateIsUsedAsConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testPojoPredicateIsUsedAsConstraint(RUN_TYPE runType) { String str = "import " + MyNumber.class.getCanonicalName() + ";" + "rule R when\n" + " MyNumber(even, $value : value)" + @@ -274,7 +276,7 @@ public void testPojoPredicateIsUsedAsConstraint() { " insert($value);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new MyNumber(2)); ksession.fireAllRules(); @@ -290,8 +292,9 @@ public void testPojoPredicateIsUsedAsConstraint() { assertThat(results.contains(1)).isFalse(); // This is because MyNumber(1) would fail for "even" predicate/getter used here in pattern as a constraint. } - @Test - public void testPojoPredicateIsUsedAsConstraintOK() { + @ParameterizedTest + @MethodSource("parameters") + public void testPojoPredicateIsUsedAsConstraintOK(RUN_TYPE runType) { String str = "import " + MyNumber.class.getCanonicalName() + ";" + "rule R when\n" + " $n : MyNumber(even, $value : value)" + @@ -299,7 +302,7 @@ public void testPojoPredicateIsUsedAsConstraintOK() { " insert($value);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new MyNumber(2)); ksession.fireAllRules(); @@ -315,8 +318,9 @@ public void testPojoPredicateIsUsedAsConstraintOK() { assertThat(results.contains(1)).isFalse(); // This is because MyNumber(1) would fail for "even" predicate/getter used here in pattern as a constraint. } - @Test - public void testBindingOfPredicateIsNotUsedAsConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindingOfPredicateIsNotUsedAsConstraint(RUN_TYPE runType) { String str = "import " + MyNumber.class.getCanonicalName() + ";" + "rule R when\n" + " MyNumber($even : even, $value : value)" + @@ -324,7 +328,7 @@ public void testBindingOfPredicateIsNotUsedAsConstraint() { " insert($value);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new MyNumber(2)); ksession.fireAllRules(); @@ -340,8 +344,9 @@ public void testBindingOfPredicateIsNotUsedAsConstraint() { assertThat(results.contains(1)).isTrue(); // This is because MyNumber(1) would simply bind for "even" predicate/getter to $even variable, and not used as a constraint. } - @Test - public void testDeclaredWithAllPrimitives() { + @ParameterizedTest + @MethodSource("parameters") + public void testDeclaredWithAllPrimitives(RUN_TYPE runType) { String str = "declare DeclaredAllPrimitives\n" + " my_byte : byte \n" + " my_short : short \n" + @@ -358,7 +363,7 @@ public void testDeclaredWithAllPrimitives() { " insert(new DeclaredAllPrimitives((byte) 1, (short) 1, 1, 1L, 1f, 1d, 'x', true));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.fireAllRules(); @@ -366,8 +371,9 @@ public void testDeclaredWithAllPrimitives() { assertThat(results.size()).isEqualTo(1); } - @Test - public void testFactType() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testFactType(RUN_TYPE runType) throws Exception { // DROOLS-4784 String str = "package org.test;\n" + @@ -381,7 +387,7 @@ public void testFactType() throws Exception { " insert($v);" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); FactType nameType = ksession.getKieBase().getFactType("org.test", "Name"); Object name = nameType.newInstance(); @@ -408,8 +414,9 @@ public void testFactType() throws Exception { assertThat(index >= 0).isTrue(); } - @Test - public void testFactTypeNotUsedInRule() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testFactTypeNotUsedInRule(RUN_TYPE runType) throws Exception { String str = "package org.test;\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -424,7 +431,7 @@ public void testFactTypeNotUsedInRule() throws Exception { " insert($v);" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); FactType nameType = ksession.getKieBase().getFactType("org.test", "ExtendedName"); Object name = nameType.newInstance(); @@ -440,8 +447,9 @@ public void testFactTypeNotUsedInRule() throws Exception { assertThat(results.iterator().next()).isEqualTo("Mario"); } - @Test - public void testTypeDeclarationsInheritance() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testTypeDeclarationsInheritance(RUN_TYPE runType) throws Exception { String str = "declare Person\n" + " id : int @key\n" + @@ -463,11 +471,12 @@ public void testTypeDeclarationsInheritance() throws Exception { " Person pe = new Employee();\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); } - @Test - public void testEnum() { + @ParameterizedTest + @MethodSource("parameters") + public void testEnum(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -485,7 +494,7 @@ public void testEnum() { " insert(new Result($p));\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mario")); ksession.fireAllRules(); @@ -496,8 +505,9 @@ public void testEnum() { assertThat(p.getAge()).isEqualTo(11); } - @Test - public void testDeclaredSlidingWindowOnEventInTypeDeclaration() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testDeclaredSlidingWindowOnEventInTypeDeclaration(RUN_TYPE runType) throws Exception { String str = "package org.test;\n" + "declare MyPojo\n" + @@ -505,7 +515,7 @@ public void testDeclaredSlidingWindowOnEventInTypeDeclaration() throws Exception "end\n" + "rule R when then insert(new MyPojo()); end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.fireAllRules(); Object pojo = getObjectsIntoList(ksession, Object.class).iterator().next(); @@ -514,8 +524,9 @@ public void testDeclaredSlidingWindowOnEventInTypeDeclaration() throws Exception assertThat((long) f.get(pojo)).isEqualTo(42L); } - @Test - public void testNestedDateConstraint() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testNestedDateConstraint(RUN_TYPE runType) throws Exception { String str = "package org.test;\n" + "declare Fact\n" + @@ -530,7 +541,7 @@ public void testNestedDateConstraint() throws Exception { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); KieBase kbase = ksession.getKieBase(); FactType factType = kbase.getFactType("org.test", "Fact"); @@ -548,8 +559,9 @@ public void testNestedDateConstraint() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testExtendPojo() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testExtendPojo(RUN_TYPE runType) throws Exception { String str = "package org.test;\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -562,7 +574,7 @@ public void testExtendPojo() throws Exception { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); KieBase kbase = ksession.getKieBase(); FactType factType = kbase.getFactType("org.test", "MyPerson"); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DowncastTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DowncastTest.java index 477e120af45..981768ef1ca 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DowncastTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DowncastTest.java @@ -20,19 +20,17 @@ import java.math.BigDecimal; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class DowncastTest extends BaseModelTest { - public DowncastTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testDowncast() { + @ParameterizedTest + @MethodSource("parameters") + public void testDowncast(RUN_TYPE runType) { // DROOLS-6520 String str = "import " + Product.class.getCanonicalName() + ";" + @@ -48,7 +46,7 @@ public void testDowncast() { " update($lp);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Proposal cashProposal = new Proposal(new CashProduct(new BigDecimal(2))); Proposal loanProposal = new Proposal(new LoanProduct(new BigDecimal(12))); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DroolsContextTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DroolsContextTest.java index 7a29973489d..9e6e502cf61 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DroolsContextTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/DroolsContextTest.java @@ -21,19 +21,17 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class DroolsContextTest extends BaseModelTest { - public DroolsContextTest(final RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testDroolsContext() { + @ParameterizedTest + @MethodSource("parameters") + public void testDroolsContext(RUN_TYPE runType) { final String str = "global java.util.List list\n" + "global java.util.List list2\n" + @@ -43,7 +41,7 @@ public void testDroolsContext() { " list.add(list2.add(kcontext));\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -56,8 +54,9 @@ public void testDroolsContext() { assertThat(list.size()).isEqualTo(1); } - @Test - public void testDroolsContextInString() { + @ParameterizedTest + @MethodSource("parameters") + public void testDroolsContextInString(RUN_TYPE runType) { final String str = "global java.util.List list\n" + "global java.util.List list2\n" + @@ -67,7 +66,7 @@ public void testDroolsContextInString() { " list.add(list2.add(\"something\" + kcontext));\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -80,8 +79,9 @@ public void testDroolsContextInString() { assertThat(list.size()).isEqualTo(1); } - @Test - public void testDroolsContextWithoutReplacingStrings() { + @ParameterizedTest + @MethodSource("parameters") + public void testDroolsContextWithoutReplacingStrings(RUN_TYPE runType) { final String str = "global java.util.List list\n" + "\n" + @@ -90,7 +90,7 @@ public void testDroolsContextWithoutReplacingStrings() { " list.add(\"this kcontext shoudln't be replaced\");\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -100,8 +100,9 @@ public void testDroolsContextWithoutReplacingStrings() { assertThat(list.get(0)).isEqualTo("this kcontext shoudln't be replaced"); } - @Test - public void testRuleContext() { + @ParameterizedTest + @MethodSource("parameters") + public void testRuleContext(RUN_TYPE runType) { final String str = "import " + FactWithRuleContext.class.getCanonicalName() + ";\n" + "global java.util.List list\n" + @@ -112,7 +113,7 @@ public void testRuleContext() { " list.add($factWithRuleContext.getRuleName(kcontext));\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/EnumTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/EnumTest.java index 12be270f641..e95e6146fd0 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/EnumTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/EnumTest.java @@ -18,19 +18,18 @@ */ package org.drools.model.codegen.execmodel; -import org.junit.Test; import org.kie.api.runtime.KieSession; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + import static org.assertj.core.api.Assertions.assertThat; public class EnumTest extends BaseModelTest { - public EnumTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testMatchEnum() { + @ParameterizedTest + @MethodSource("parameters") + public void testMatchEnum(RUN_TYPE runType) { String str = "import " + Bus.class.getCanonicalName() + ";" + "rule bus2 when\n" + @@ -39,7 +38,7 @@ public void testMatchEnum() { " System.out.println(\"bus=\" + $bus + \", maker=\" + $maker);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str ); Bus a = new Bus("blue", 25, Bus.Maker.HINO); ksession.insert(a); @@ -49,8 +48,9 @@ public void testMatchEnum() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testBindEnum() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindEnum(RUN_TYPE runType) { // DROOLS-5851 String str = "import " + Bus.class.getCanonicalName() + ";" + @@ -60,7 +60,7 @@ public void testBindEnum() { " System.out.println(\"bus=\" + $bus + \", maker=\" + $maker);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Bus a = new Bus("blue", 25, Bus.Maker.HINO); ksession.insert(a); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/EvalTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/EvalTest.java index 95562316462..6e307f092c0 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/EvalTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/EvalTest.java @@ -24,19 +24,18 @@ import org.drools.model.codegen.execmodel.domain.Overloaded; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class EvalTest extends BaseModelTest { - public EvalTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - @Test - public void testEval() { + @ParameterizedTest + @MethodSource("parameters") + public void testEval(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -47,7 +46,7 @@ public void testEval() { " insert(new Result($p.getName()));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 40 ) ); ksession.insert( new Person( "Mark", 37 ) ); @@ -59,8 +58,9 @@ public void testEval() { assertThat(results.iterator().next().getValue()).isEqualTo("Mario"); } - @Test - public void testEvalWithMethodInvocation() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalWithMethodInvocation(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -71,7 +71,7 @@ public void testEvalWithMethodInvocation() { " insert(new Result($p.getName()));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 40 ) ); ksession.insert( new Person( "Mark", 37 ) ); @@ -83,56 +83,61 @@ public void testEvalWithMethodInvocation() { assertThat(results.iterator().next().getValue()).isEqualTo("Edson"); } - @Test - public void testEvalTrue() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalTrue(RUN_TYPE runType) { String str = "rule R when\n" + " eval( true )\n" + "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testEvalFalse() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalFalse(RUN_TYPE runType) { String str = "rule R when\n" + " eval( false )\n" + "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testEvalOr() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalOr(RUN_TYPE runType) { String str = "rule R when\n" + " eval( true ) or eval( false )\n" + "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testEvalIdentity() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalIdentity(RUN_TYPE runType) { String str = "rule R when\n" + " eval( 1 == 1 )\n" + "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testFunction() { + @ParameterizedTest + @MethodSource("parameters") + public void testFunction(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -146,7 +151,7 @@ public void testFunction() { " insert(new Result(hello($p.getName())));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 40 ) ); ksession.insert( new Person( "Mark", 37 ) ); @@ -158,8 +163,9 @@ public void testFunction() { assertThat(results.iterator().next().getValue()).isEqualTo("Hello Mario!"); } - @Test - public void testFunction2() { + @ParameterizedTest + @MethodSource("parameters") + public void testFunction2(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -173,7 +179,7 @@ public void testFunction2() { " insert(new Result($p.getName()));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 40 ) ); ksession.insert( new Person( "Mark", 37 ) ); @@ -185,8 +191,9 @@ public void testFunction2() { assertThat(results.iterator().next().getValue()).isEqualTo("Mario"); } - @Test - public void testEvalWith2Bindings() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalWith2Bindings(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -198,7 +205,7 @@ public void testEvalWith2Bindings() { " insert(new Result($p1.getName()));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 40 ) ); ksession.insert( new Person( "Mark", 38 ) ); @@ -210,8 +217,9 @@ public void testEvalWith2Bindings() { assertThat(results.iterator().next().getValue()).isEqualTo("Mario"); } - @Test - public void testEvalWith2BindingsInvokingMethod() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalWith2BindingsInvokingMethod(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -223,7 +231,7 @@ public void testEvalWith2BindingsInvokingMethod() { " insert(new Result($p1.getName()));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 40 ) ); ksession.insert( new Person( "Mario", 38 ) ); @@ -235,8 +243,9 @@ public void testEvalWith2BindingsInvokingMethod() { assertThat(results.iterator().next().getValue()).isEqualTo("Mario"); } - @Test - public void testEvalWithDeclaration() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalWithDeclaration(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -247,7 +256,7 @@ public void testEvalWithDeclaration() { " insert(new Result($p1.getName()));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 40 ) ); ksession.insert( new Person( "Mark", 38 ) ); @@ -259,8 +268,9 @@ public void testEvalWithDeclaration() { assertThat(results.iterator().next().getValue()).isEqualTo("Mario"); } - @Test - public void testEvalWith2Declarations() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalWith2Declarations(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -272,7 +282,7 @@ public void testEvalWith2Declarations() { " insert(new Result($p1.getName()));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 40 ) ); ksession.insert( new Person( "Mark", 38 ) ); @@ -284,8 +294,9 @@ public void testEvalWith2Declarations() { assertThat(results.iterator().next().getValue()).isEqualTo("Mario"); } - @Test - public void testEvalWithBinary() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalWithBinary(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -295,7 +306,7 @@ public void testEvalWithBinary() { " insert(new Result($p.getName()));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mario", 40)); ksession.insert(new Person("Mark", 37)); @@ -307,8 +318,9 @@ public void testEvalWithBinary() { assertThat(results.iterator().next().getValue()).isEqualTo("Mario"); } - @Test - public void testEvalInvokingMethod() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalInvokingMethod(RUN_TYPE runType) { String str = "import " + Overloaded.class.getCanonicalName() + ";" + "rule OverloadedMethods\n" + "when\n" + @@ -318,7 +330,7 @@ public void testEvalInvokingMethod() { " insert(\"matched\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Overloaded()); ksession.fireAllRules(); @@ -327,8 +339,9 @@ public void testEvalInvokingMethod() { assertThat(results.size()).isEqualTo(1); } - @Test - public void testEvalInvokingMethod2() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalInvokingMethod2(RUN_TYPE runType) { String str = "import " + Overloaded.class.getCanonicalName() + ";" + "rule OverloadedMethods\n" + "when\n" + @@ -338,7 +351,7 @@ public void testEvalInvokingMethod2() { " insert(\"matched\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Overloaded()); ksession.fireAllRules(); @@ -348,8 +361,9 @@ public void testEvalInvokingMethod2() { } - @Test - public void testEvalInvokingFunction() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalInvokingFunction(RUN_TYPE runType) { String str = "function boolean isPositive(int i){\n" + " return i > 0;\n" + @@ -361,7 +375,7 @@ public void testEvalInvokingFunction() { " insert(\"matched\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(42); ksession.fireAllRules(); @@ -370,8 +384,9 @@ public void testEvalInvokingFunction() { assertThat(results.size()).isEqualTo(1); } - @Test - public void testEvalWithGlobal() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalWithGlobal(RUN_TYPE runType) { final String drl1 = "import " + Result.class.getCanonicalName() + ";\n" + "global java.lang.Integer globalInt\n" + @@ -381,7 +396,7 @@ public void testEvalWithGlobal() { " insert(new Result(\"match\"));\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.setGlobal("globalInt", 1); ksession.insert(1); @@ -394,8 +409,9 @@ public void testEvalWithGlobal() { assertThat(results.iterator().next().getValue().toString()).isEqualTo("match"); } - @Test - public void testEvalWithGlobal2() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalWithGlobal2(RUN_TYPE runType) { final String drl1 = "import " + Result.class.getCanonicalName() + ";\n" + "global java.lang.Integer globalInt\n" + @@ -405,7 +421,7 @@ public void testEvalWithGlobal2() { " insert(new Result(\"match\"));\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.setGlobal("globalInt", 1); ksession.insert(1); @@ -419,8 +435,9 @@ public void testEvalWithGlobal2() { } - @Test - public void testEvalExprWithFunctionCall() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalExprWithFunctionCall(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global " + GlobalFunctions.class.getCanonicalName() + " functions;" + @@ -430,7 +447,7 @@ public void testEvalExprWithFunctionCall() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); GlobalFunctions gf = new GlobalFunctions(); ksession.setGlobal("functions", gf); @@ -445,8 +462,9 @@ public Integer add(int a, int b) { } } - @Test - public void testEvalCalculationWithParenthesis() { + @ParameterizedTest + @MethodSource("parameters") + public void testEvalCalculationWithParenthesis(RUN_TYPE runType) { String str = "import " + CalcFact.class.getCanonicalName() + ";" + "rule R when\n" + @@ -455,7 +473,7 @@ public void testEvalCalculationWithParenthesis() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new CalcFact(1.0d, 1.0d)); // (1.0 / (1.0 * 10) * 10) is 1. So this rule should not fire @@ -464,8 +482,9 @@ public void testEvalCalculationWithParenthesis() { assertThat(fired).isEqualTo(0); } - @Test - public void testParseIntStringConcatenation() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testParseIntStringConcatenation(RUN_TYPE runType) throws Exception { String str = "rule R when\n" + " $s : String()\n" + @@ -473,7 +492,7 @@ public void testParseIntStringConcatenation() throws Exception { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert("5"); assertThat(ksession.fireAllRules()).isEqualTo(1); } @@ -502,8 +521,9 @@ public void setT(String t) { } } - @Test - public void testModifyEvalAfterJoin() { + @ParameterizedTest + @MethodSource("parameters") + public void testModifyEvalAfterJoin(RUN_TYPE runType) { // DROOLS-7255 String str = "import " + Dt1.class.getCanonicalName() + ";" + @@ -534,7 +554,7 @@ public void testModifyEvalAfterJoin() { " }\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Dt1 dt1 = new Dt1(); dt1.setA(1); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ExisistentialTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ExisistentialTest.java index 38cc55ca3fa..f5de60b45ac 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ExisistentialTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ExisistentialTest.java @@ -25,7 +25,8 @@ import org.assertj.core.api.Assertions; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; import org.kie.api.runtime.rule.Match; @@ -38,12 +39,9 @@ public class ExisistentialTest extends BaseModelTest { - public ExisistentialTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testNot() { + @ParameterizedTest + @MethodSource("parameters") + public void testNot(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -53,7 +51,7 @@ public void testNot() { " insert(new Result(\"ok\"));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person mario = new Person( "Mario", 40 ); @@ -65,8 +63,9 @@ public void testNot() { assertThat(results.iterator().next().getValue()).isEqualTo("ok"); } - @Test - public void testNotEmptyPredicate() { + @ParameterizedTest + @MethodSource("parameters") + public void testNotEmptyPredicate(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -76,7 +75,7 @@ public void testNotEmptyPredicate() { " insert(new Result(\"ok\"));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person mario = new Person( "Mario", 40 ); @@ -87,8 +86,9 @@ public void testNotEmptyPredicate() { assertThat(results.size()).isEqualTo(0); } - @Test - public void testExists() { + @ParameterizedTest + @MethodSource("parameters") + public void testExists(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -98,7 +98,7 @@ public void testExists() { " insert(new Result(\"ok\"));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person mario = new Person( "Mario", 40 ); @@ -110,8 +110,9 @@ public void testExists() { assertThat(results.iterator().next().getValue()).isEqualTo("ok"); } - @Test - public void testForall() { + @ParameterizedTest + @MethodSource("parameters") + public void testForall(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -122,7 +123,7 @@ public void testForall() { " insert(new Result(\"ok\"));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 41 ) ); ksession.insert( new Person( "Mark", 39 ) ); @@ -134,8 +135,9 @@ public void testForall() { assertThat(results.iterator().next().getValue()).isEqualTo("ok"); } - @Test - public void testForallInQuery() { + @ParameterizedTest + @MethodSource("parameters") + public void testForallInQuery(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "query ifAllPersonsAreOlderReturnThem (int pAge)\n" + @@ -143,7 +145,7 @@ public void testForallInQuery() { " $person : Person()\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mario", 41 ) ); ksession.insert( new Person( "Mark", 39 ) ); @@ -155,8 +157,9 @@ public void testForallInQuery() { assertThat(results.size()).isEqualTo(3); } - @Test - public void testForallSingleConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testForallSingleConstraint(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -166,7 +169,7 @@ public void testForallSingleConstraint() { " insert(new Result(\"ok\"));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mario")); ksession.insert(new Person("Edson")); @@ -177,8 +180,9 @@ public void testForallSingleConstraint() { assertThat(results.iterator().next().getValue()).isEqualTo("ok"); } - @Test - public void testForallEmptyConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testForallEmptyConstraint(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -188,7 +192,7 @@ public void testForallEmptyConstraint() { " insert(new Result(\"ok\"));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mario")); ksession.insert(new Person("Mark")); @@ -200,8 +204,9 @@ public void testForallEmptyConstraint() { assertThat(results.iterator().next().getValue()).isEqualTo("ok"); } - @Test - public void testExistsEmptyPredicate() { + @ParameterizedTest + @MethodSource("parameters") + public void testExistsEmptyPredicate(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -211,7 +216,7 @@ public void testExistsEmptyPredicate() { " insert(new Result(\"ok\"));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person mark = new Person( "Mark", 37 ); Person mario = new Person( "Mario", 40 ); @@ -225,8 +230,9 @@ public void testExistsEmptyPredicate() { assertThat(results.iterator().next().getValue()).isEqualTo("ok"); } - @Test - public void testComplexNots() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexNots(RUN_TYPE runType) throws Exception { String str = "package org.drools.testcoverage.regression;\n" + "\n" + @@ -270,13 +276,14 @@ public void testComplexNots() throws Exception { "end\n" + ""; - KieSession ksession = getKieSession( getCepKieModuleModel(), str ); + KieSession ksession = getKieSession(runType, getCepKieModuleModel(), str ); assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testDuplicateBindingNameInDifferentScope() { + @ParameterizedTest + @MethodSource("parameters") + public void testDuplicateBindingNameInDifferentScope(RUN_TYPE runType) { final String drl1 = "package org.drools.compiler\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -286,15 +293,16 @@ public void testDuplicateBindingNameInDifferentScope() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert( "test" ); ksession.insert( new Person("test", 18) ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNotWithDereferencingConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testNotWithDereferencingConstraint(RUN_TYPE runType) { final String drl1 = "package org.drools.compiler\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -304,14 +312,15 @@ public void testNotWithDereferencingConstraint() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert( new Person("test", 18) ); assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void test2NotsWithAnd() { + @ParameterizedTest + @MethodSource("parameters") + public void test2NotsWithAnd(RUN_TYPE runType) { final String drl1 = "package org.drools.compiler\n" + "rule R when\n" + @@ -326,13 +335,14 @@ public void test2NotsWithAnd() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testExistsWithAJoin() { + @ParameterizedTest + @MethodSource("parameters") + public void testExistsWithAJoin(RUN_TYPE runType) { // DROOLS-7065 final String drl1 = "package org.drools.compiler\n" + @@ -344,7 +354,7 @@ public void testExistsWithAJoin() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); AtomicInteger matchCount = new AtomicInteger(0); // Atomic only so that I get an effectively-final int. ((RuleEventManager) ksession).addEventListener(new RuleEventListener() { diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ExternalisedLambdaTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ExternalisedLambdaTest.java index b0a31db75dc..a97c79568b2 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ExternalisedLambdaTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ExternalisedLambdaTest.java @@ -30,9 +30,10 @@ import org.drools.model.codegen.execmodel.domain.StockTick; import org.drools.model.codegen.execmodel.domain.Woman; import org.drools.model.codegen.execmodel.util.lambdareplace.NonExternalisedLambdaFoundException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieServices; import org.kie.api.builder.model.KieModuleModel; import org.kie.api.conf.EventProcessingOption; @@ -53,23 +54,20 @@ public class ExternalisedLambdaTest extends BaseModelTest { private boolean checkNonExternalisedLambdaOrig; - public ExternalisedLambdaTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Before + @BeforeEach public void init() { checkNonExternalisedLambdaOrig = RuleWriter.isCheckNonExternalisedLambda(); RuleWriter.setCheckNonExternalisedLambda(true); } - @After + @AfterEach public void clear() { RuleWriter.setCheckNonExternalisedLambda(checkNonExternalisedLambdaOrig); } - @Test - public void testConsequenceNoVariable() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testConsequenceNoVariable(RUN_TYPE runType) { // DROOLS-4924 String str = "package defaultpkg;\n" + @@ -82,7 +80,7 @@ public void testConsequenceNoVariable() throws Exception { KieSession ksession = null; try { - ksession = getKieSession(str); + ksession = getKieSession(runType, str); } catch (NonExternalisedLambdaFoundException e) { fail(e.getMessage()); } @@ -93,8 +91,9 @@ public void testConsequenceNoVariable() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testExternalizeBindingVariableLambda() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testExternalizeBindingVariableLambda(RUN_TYPE runType) { String str = "package defaultpkg;\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -107,7 +106,7 @@ public void testExternalizeBindingVariableLambda() throws Exception { KieSession ksession = null; try { - ksession = getKieSession(str); + ksession = getKieSession(runType, str); } catch (NonExternalisedLambdaFoundException e) { fail(e.getMessage()); } @@ -122,8 +121,9 @@ public void testExternalizeBindingVariableLambda() throws Exception { assertThat(list).containsExactlyInAnyOrder("Mario"); } - @Test - public void testExternalizeLambdaPredicate() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testExternalizeLambdaPredicate(RUN_TYPE runType) { String str = "package defaultpkg;\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -136,7 +136,7 @@ public void testExternalizeLambdaPredicate() throws Exception { KieSession ksession = null; try { - ksession = getKieSession(str); + ksession = getKieSession(runType, str); } catch (NonExternalisedLambdaFoundException e) { fail(e.getMessage()); } @@ -151,8 +151,9 @@ public void testExternalizeLambdaPredicate() throws Exception { assertThat(list).containsExactlyInAnyOrder("Mario"); } - @Test - public void testExternalizeLambdaUsingVariable() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testExternalizeLambdaUsingVariable(RUN_TYPE runType) { String str = "package defaultpkg;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -166,7 +167,7 @@ public void testExternalizeLambdaUsingVariable() throws Exception { KieSession ksession = null; try { - ksession = getKieSession(str); + ksession = getKieSession(runType, str); } catch (NonExternalisedLambdaFoundException e) { fail(e.getMessage()); } @@ -181,8 +182,9 @@ public void testExternalizeLambdaUsingVariable() throws Exception { assertThat(list).containsExactlyInAnyOrder(43); } - @Test - public void testEval() { + @ParameterizedTest + @MethodSource("parameters") + public void testEval(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -195,7 +197,7 @@ public void testEval() { KieSession ksession = null; try { - ksession = getKieSession(str); + ksession = getKieSession(runType, str); } catch (NonExternalisedLambdaFoundException e) { fail(e.getMessage()); } @@ -210,8 +212,9 @@ public void testEval() { assertThat(results.iterator().next().getValue()).isEqualTo("Mario"); } - @Test - public void testFromExpression() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromExpression(RUN_TYPE runType) { final String str = "import org.drools.model.codegen.execmodel.domain.*;\n" + "global java.util.List list\n" + @@ -225,7 +228,7 @@ public void testFromExpression() { KieSession ksession = null; try { - ksession = getKieSession(str); + ksession = getKieSession(runType, str); } catch (NonExternalisedLambdaFoundException e) { fail(e.getMessage()); } @@ -248,8 +251,9 @@ public void testFromExpression() { assertThat(list).containsExactlyInAnyOrder("Charles"); } - @Test - public void testAccumulateWithBinaryExpr() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccumulateWithBinaryExpr(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -264,7 +268,7 @@ public void testAccumulateWithBinaryExpr() { KieSession ksession = null; try { - ksession = getKieSession(str); + ksession = getKieSession(runType, str); } catch (NonExternalisedLambdaFoundException e) { fail(e.getMessage()); } @@ -281,8 +285,9 @@ public void testAccumulateWithBinaryExpr() { assertThat(((Number) results.iterator().next().getValue()).intValue()).isEqualTo(77); } - @Test - public void testOOPath() { + @ParameterizedTest + @MethodSource("parameters") + public void testOOPath(RUN_TYPE runType) { final String str = "import org.drools.model.codegen.execmodel.domain.*;\n" + "global java.util.List list\n" + @@ -295,7 +300,7 @@ public void testOOPath() { KieSession ksession = null; try { - ksession = getKieSession(str); + ksession = getKieSession(runType, str); } catch (NonExternalisedLambdaFoundException e) { fail(e.getMessage()); } @@ -320,8 +325,9 @@ public void testOOPath() { assertThat(list).containsExactlyInAnyOrder("Bob"); } - @Test - public void testCep() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testCep(RUN_TYPE runType) { String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + @@ -339,7 +345,7 @@ public void testCep() throws Exception { .setDefault( true ).setClockType( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) ); KieSession ksession = null; try { - ksession = getKieSession(kmodel, str); + ksession = getKieSession(runType, kmodel, str); } catch (NonExternalisedLambdaFoundException e) { fail(e.getMessage()); } diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/FromTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/FromTest.java index afbcfe18403..770896c5e90 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/FromTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/FromTest.java @@ -29,7 +29,9 @@ import org.drools.model.codegen.execmodel.domain.Toy; import org.drools.model.codegen.execmodel.domain.ToysStore; import org.drools.model.codegen.execmodel.domain.Woman; -import org.junit.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieServices; import org.kie.api.builder.model.KieModuleModel; import org.kie.api.runtime.KieSession; @@ -54,12 +56,9 @@ public class FromTest extends BaseModelTest { - public FromTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testFromGlobal() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testFromGlobal(RUN_TYPE runType) throws Exception { String str = "global java.util.List list \n" + "rule R when \n" + " $o : String(length > 3) from list\n" + @@ -67,7 +66,7 @@ public void testFromGlobal() throws Exception { " insert($o); \n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List strings = Arrays.asList("a", "Hello World!", "xyz"); @@ -81,8 +80,9 @@ public void testFromGlobal() throws Exception { assertThat(results.contains("xyz")).isFalse(); } - @Test - public void testFromVariable() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromVariable(RUN_TYPE runType) { final String str = "import org.drools.model.codegen.execmodel.domain.*;\n" + "global java.util.List list\n" + @@ -94,7 +94,7 @@ public void testFromVariable() { " list.add( $child.getName() );\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -114,8 +114,9 @@ public void testFromVariable() { assertThat(list).containsExactlyInAnyOrder("Charles"); } - @Test - public void testFromExpression() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromExpression(RUN_TYPE runType) { final String str = "import org.drools.model.codegen.execmodel.domain.*;\n" + "global java.util.List list\n" + @@ -127,7 +128,7 @@ public void testFromExpression() { " list.add( $child.getName() );\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -147,8 +148,9 @@ public void testFromExpression() { assertThat(list).containsExactlyInAnyOrder("Charles"); } - @Test - public void testModifyWithFrom() { + @ParameterizedTest + @MethodSource("parameters") + public void testModifyWithFrom(RUN_TYPE runType) { // DROOLS-6486 final String str = "import org.drools.model.codegen.execmodel.domain.*;\n" + @@ -160,7 +162,7 @@ public void testModifyWithFrom() { " modify( $child ) { setName($child.getName() + \"x\") };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final Woman alice = new Woman( "Alice", 38 ); final Man bob = new Man( "Bob", 40 ); @@ -178,8 +180,9 @@ public void testModifyWithFrom() { assertThat(charlie.getName()).isEqualTo("Charlesx"); } - @Test - public void testModifyWithFromAndReevaluate() { + @ParameterizedTest + @MethodSource("parameters") + public void testModifyWithFromAndReevaluate(RUN_TYPE runType) { // DROOLS-7203 final String str = "import org.drools.model.codegen.execmodel.domain.*;\n" + @@ -208,7 +211,7 @@ public void testModifyWithFromAndReevaluate() { " delete($s);\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -241,8 +244,10 @@ public void testModifyWithFromAndReevaluate() { assertThat(results).containsExactly("executed"); // R1 should not be executed twice because age is modified to 13 } - @Test(timeout = 20000) - public void testModifyWithFromSudoku() { + @ParameterizedTest + @MethodSource("parameters") + @Timeout(20000) + public void testModifyWithFromSudoku(RUN_TYPE runType) { // DROOLS-7203 : Slimmed down Sudoku final String str = "import " + Setting.class.getCanonicalName() + ";\n" + @@ -297,7 +302,7 @@ public void testModifyWithFromSudoku() { " insert( new Setting( $rn, $cn, i ) );\n" + "end\n"; - KieSession ksession = getKieSession(getDisablePropertyReactivityKieModuleModel(), str); + KieSession ksession = getKieSession(runType, getDisablePropertyReactivityKieModuleModel(), str); Cell c1 = new Cell(0, 0, null); c1.setFree(new HashSet<>(Arrays.asList(1, 2, 3))); @@ -496,8 +501,9 @@ public static Integer getLength(String ignoredParameter, String s, Integer offse return s.length() + offset; } - @Test - public void testFromExternalFunction() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromExternalFunction(RUN_TYPE runType) { final String str = "import " + FromTest.class.getCanonicalName() + ";\n" + "global java.util.List list\n" + @@ -509,7 +515,7 @@ public void testFromExternalFunction() { " list.add( \"received long message: \" + $s);\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -520,8 +526,9 @@ public void testFromExternalFunction() { assertThat(list).containsExactlyInAnyOrder("received long message: Hello World!"); } - @Test - public void testFromExternalFunctionMultipleBindingArguments() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromExternalFunctionMultipleBindingArguments(RUN_TYPE runType) { final String str = "import " + FromTest.class.getCanonicalName() + ";\n" + "global java.util.List list\n" + @@ -534,7 +541,7 @@ public void testFromExternalFunctionMultipleBindingArguments() { " list.add( \"received long message: \" + $s);\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -546,8 +553,9 @@ public void testFromExternalFunctionMultipleBindingArguments() { assertThat(list).containsExactlyInAnyOrder("received long message: Hello!"); } - @Test - public void testFromConstant() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromConstant(RUN_TYPE runType) { String str = "package org.drools.compiler.test \n" + "global java.util.List list\n" + @@ -558,7 +566,7 @@ public void testFromConstant() { " list.add( $s );\n" + "end \n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -568,8 +576,9 @@ public void testFromConstant() { assertThat(list.get(0)).isEqualTo("test"); } - @Test - public void testFromConstructor() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromConstructor(RUN_TYPE runType) { String str = "package org.drools.compiler.test \n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -583,7 +592,7 @@ public void testFromConstructor() { " list.add( $p );\n" + "end \n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -597,8 +606,9 @@ public void testFromConstructor() { assertThat(list.get(0)).isEqualTo(new Person("Mario", 44)); } - @Test - public void testFromMapValues() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromMapValues(RUN_TYPE runType) { // DROOLS-3661 String str = "package org.drools.compiler.test \n" + @@ -611,7 +621,7 @@ public void testFromMapValues() { "then\n" + "end \n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); PetPerson petPerson = new PetPerson( "me" ); Map petMap = new HashMap<>(); @@ -623,8 +633,9 @@ public void testFromMapValues() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testGlobalInFromExpression() { + @ParameterizedTest + @MethodSource("parameters") + public void testGlobalInFromExpression(RUN_TYPE runType) { // DROOLS-4999 String str = "package org.drools.compiler.test \n" + @@ -638,7 +649,7 @@ public void testGlobalInFromExpression() { "then\n" + "end \n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal( "petName", "Dog" ); @@ -652,8 +663,9 @@ public void testGlobalInFromExpression() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testLiteralFrom() { + @ParameterizedTest + @MethodSource("parameters") + public void testLiteralFrom(RUN_TYPE runType) { // DROOLS-5217 String str = "package com.sample\n" + @@ -665,15 +677,16 @@ public void testLiteralFrom() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Pojo( Arrays.asList(1,2,3) ) ); int rulesFired = ksession.fireAllRules(); assertThat(rulesFired).isEqualTo(2); } - @Test - public void testLiteralFrom2() { + @ParameterizedTest + @MethodSource("parameters") + public void testLiteralFrom2(RUN_TYPE runType) { // DROOLS-5217 String str = "package com.sample\n" + @@ -685,15 +698,16 @@ public void testLiteralFrom2() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Pojo( Arrays.asList(1,2,3) ) ); int rulesFired = ksession.fireAllRules(); assertThat(rulesFired).isEqualTo(1); } - @Test - public void testFromCollect() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromCollect(RUN_TYPE runType) { String str = "package org.drools.compiler.test \n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -704,7 +718,7 @@ public void testFromCollect() { "then\n" + "end \n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p1 = new Person("John", 32); Person p2 = new Person("Paul", 30); @@ -717,8 +731,9 @@ public void testFromCollect() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testFromCollectCustomSet() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromCollectCustomSet(RUN_TYPE runType) { // DROOLS-7534 String str = "package org.drools.compiler.test \n" + @@ -732,7 +747,7 @@ public void testFromCollectCustomSet() { " FromTest.printPersons($set);" + "end \n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p1 = new Person("John", 32); Person p1a = new Person("John", 32); @@ -758,8 +773,9 @@ public MyHashSet() { } } - @Test - public void testThisArray() { + @ParameterizedTest + @MethodSource("parameters") + public void testThisArray(RUN_TYPE runType) { // This test verifies the behavior when ArrayType is used as "_this" (which $childrenA is converted to) in from clause. String str = "package org.drools.compiler.test \n" + @@ -773,7 +789,7 @@ public void testThisArray() { " list.add($i);\n" + "end \n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -786,8 +802,9 @@ public void testThisArray() { assertThat(list).containsExactlyInAnyOrder(2); } - @Test - public void testFromArray() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromArray(RUN_TYPE runType) { // This test verifies the behavior when the return type is ArrayType String str = "package org.drools.compiler.test \n" + @@ -802,7 +819,7 @@ public void testFromArray() { " list.add($p.getName());\n" + "end \n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -815,8 +832,9 @@ public void testFromArray() { assertThat(list).containsExactlyInAnyOrder("Julian", "Sean"); } - @Test - public void testInnerClassCollection() { + @ParameterizedTest + @MethodSource("parameters") + public void testInnerClassCollection(RUN_TYPE runType) { String str = "package org.drools.compiler.test \n" + "import " + MyPerson.class.getCanonicalName() + "\n" + @@ -827,7 +845,7 @@ public void testInnerClassCollection() { "then\n" + "end \n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); MyPerson john = new MyPerson("John"); Collection kids = new ArrayList<>(); @@ -840,8 +858,9 @@ public void testInnerClassCollection() { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testInnerClassWithInstanceMethod() { + @ParameterizedTest + @MethodSource("parameters") + public void testInnerClassWithInstanceMethod(RUN_TYPE runType) { String str = "package org.drools.compiler.test \n" + "import " + MyPerson.class.getCanonicalName() + "\n" + @@ -854,7 +873,7 @@ public void testInnerClassWithInstanceMethod() { " list.add($d.getName());" + "end \n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -865,8 +884,9 @@ public void testInnerClassWithInstanceMethod() { assertThat(list).containsExactlyInAnyOrder("Dummy"); } - @Test - public void testInnerClassWithStaticMethod() { + @ParameterizedTest + @MethodSource("parameters") + public void testInnerClassWithStaticMethod(RUN_TYPE runType) { String str = "package org.drools.compiler.test \n" + "import " + MyPerson.class.getCanonicalName() + "\n" + @@ -878,7 +898,7 @@ public void testInnerClassWithStaticMethod() { " list.add($d.getName());" + "end \n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -886,8 +906,9 @@ public void testInnerClassWithStaticMethod() { assertThat(list).containsExactlyInAnyOrder("Dummy"); } - @Test - public void testInnerClassWithStaticMethodWithArg() { + @ParameterizedTest + @MethodSource("parameters") + public void testInnerClassWithStaticMethodWithArg(RUN_TYPE runType) { String str = "package org.drools.compiler.test \n" + "import " + MyPerson.class.getCanonicalName() + "\n" + @@ -900,7 +921,7 @@ public void testInnerClassWithStaticMethodWithArg() { " list.add($d.getName());" + "end \n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -965,8 +986,9 @@ public static MyPerson getDummyPersonStatic(String name) { } } - @Test - public void testNew() { + @ParameterizedTest + @MethodSource("parameters") + public void testNew(RUN_TYPE runType) { String str = "package org.drools.compiler.test \n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -978,7 +1000,7 @@ public void testNew() { " list.add($p);\n" + "end \n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -987,8 +1009,9 @@ public void testNew() { assertThat(list.size()).isEqualTo(1); } - @Test - public void testFromOr() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromOr(RUN_TYPE runType) { String str = "package org.drools.compiler.test \n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -1008,7 +1031,7 @@ public void testFromOr() { " list.add($store.getStoreName());\n" + "end \n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -1066,8 +1089,9 @@ public Object getSomethingBy(Object o) { } } - @Test - public void testFromFunctionCall() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromFunctionCall(RUN_TYPE runType) { // DROOLS-5548 String str = "package com.sample;" + @@ -1101,7 +1125,7 @@ public void testFromFunctionCall() { " controlSet.add($colorVal);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); HashSet hashSet = new HashSet<>(); ksession.setGlobal("controlSet", hashSet); @@ -1114,8 +1138,9 @@ public void testFromFunctionCall() { assertThat(hashSet.iterator().next()).isEqualTo("red"); } - @Test - public void testFromMap() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromMap(RUN_TYPE runType) { // DROOLS-5549 String str = "package com.sample;" + @@ -1137,7 +1162,7 @@ public void testFromMap() { " controlSet.add($colorVal);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); HashSet hashSet = new HashSet<>(); ksession.setGlobal("controlSet", hashSet); @@ -1150,8 +1175,9 @@ public void testFromMap() { assertThat(hashSet.iterator().next()).isEqualTo("red"); } - @Test - public void testFromChainedCall() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromChainedCall(RUN_TYPE runType) { // DROOLS-5608 String str = "package com.sample;" + @@ -1170,7 +1196,7 @@ public void testFromChainedCall() { " controlSet.add($colorVal);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); HashSet hashSet = new HashSet<>(); ksession.setGlobal("controlSet", hashSet); @@ -1200,8 +1226,9 @@ public static Map.Entry mapEntry(K key, V value) { } } - @Test - public void testNestedService() { + @ParameterizedTest + @MethodSource("parameters") + public void testNestedService(RUN_TYPE runType) { // DROOLS-5609 String str = "package com.sample;" + @@ -1218,7 +1245,7 @@ public void testNestedService() { " controlSet.add($colorVal);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); HashSet hashSet = new HashSet<>(); ksession.setGlobal("controlSet", hashSet); @@ -1233,8 +1260,9 @@ public void testNestedService() { } - @Test - public void testMultipleFrom() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleFrom(RUN_TYPE runType) { // DROOLS-5542 String str = "package com.sample;" + @@ -1254,7 +1282,7 @@ public void testMultipleFrom() { " controlSet.add($colorVal);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); HashSet hashSet = new HashSet<>(); ksession.setGlobal("controlSet", hashSet); @@ -1268,8 +1296,9 @@ public void testMultipleFrom() { assertThat(hashSet.iterator().next()).isEqualTo("red"); } - @Test - public void testMultipleFromFromBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleFromFromBinding(RUN_TYPE runType) { // DROOLS-5591 String str = "package com.sample;" + @@ -1286,7 +1315,7 @@ public void testMultipleFromFromBinding() { " controlSet.add($colorVal);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); HashSet hashSet = new HashSet<>(); ksession.setGlobal("controlSet", hashSet); @@ -1300,8 +1329,9 @@ public void testMultipleFromFromBinding() { assertThat(hashSet.iterator().next()).isEqualTo("red"); } - @Test - public void testMultipleFromList() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleFromList(RUN_TYPE runType) { // DROOLS-5590 String str = "package com.sample;" + @@ -1324,7 +1354,7 @@ public void testMultipleFromList() { " controlSet.add($colorVal);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); HashSet hashSet = new HashSet<>(); ksession.setGlobal("controlSet", hashSet); @@ -1338,8 +1368,9 @@ public void testMultipleFromList() { assertThat(hashSet.iterator().next()).isEqualTo("red"); } - @Test - public void tesFromMethodCall() { + @ParameterizedTest + @MethodSource("parameters") + public void tesFromMethodCall(RUN_TYPE runType) { // DROOLS-5641 String str = "package com.sample;" + @@ -1361,7 +1392,7 @@ public void tesFromMethodCall() { " controlSet.add($colorVal);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); HashSet hashSet = new HashSet<>(); ksession.setGlobal("controlSet", hashSet); @@ -1376,8 +1407,9 @@ public void tesFromMethodCall() { assertThat(hashSet.iterator().next()).isEqualTo("red"); } - @Test - public void testFromStringConcatenation() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromStringConcatenation(RUN_TYPE runType) { // DROOLS-5640 String str = "global java.util.List list;\n" + @@ -1389,7 +1421,7 @@ public void testFromStringConcatenation() { " list.add($c);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -1400,8 +1432,9 @@ public void testFromStringConcatenation() { assertThat(list).containsExactlyInAnyOrder("AA", "AB", "BA", "BB"); } - @Test - public void testFromBoolean() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromBoolean(RUN_TYPE runType) { // DROOLS-5830 String str = "rule R when\n" + @@ -1411,14 +1444,15 @@ public void testFromBoolean() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( "A" ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testFromCollectWithOr() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromCollectWithOr(RUN_TYPE runType) { // DROOLS-6531 String str = "import java.util.List;\n" + @@ -1432,7 +1466,7 @@ public void testFromCollectWithOr() { " $list.addAll($values);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.insert(list); @@ -1444,8 +1478,9 @@ public void testFromCollectWithOr() { assertThat(list.size()).isEqualTo(2); } - @Test - public void fromWithTernaryExpressionBoolean() { + @ParameterizedTest + @MethodSource("parameters") + public void fromWithTernaryExpressionBoolean(RUN_TYPE runType) { // DROOLS-7236 String str = "global java.util.List results;\n" + @@ -1457,7 +1492,7 @@ public void fromWithTernaryExpressionBoolean() { " results.add($bar);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1467,8 +1502,9 @@ public void fromWithTernaryExpressionBoolean() { assertThat(results).containsExactly(true); } - @Test - public void fromWithTernaryExpressionBooleanWithMethodCall() { + @ParameterizedTest + @MethodSource("parameters") + public void fromWithTernaryExpressionBooleanWithMethodCall(RUN_TYPE runType) { // DROOLS-7236 String str = "import " + MyFact.class.getCanonicalName() + ";\n" + @@ -1481,7 +1517,7 @@ public void fromWithTernaryExpressionBooleanWithMethodCall() { " results.add($bar);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1491,8 +1527,9 @@ public void fromWithTernaryExpressionBooleanWithMethodCall() { assertThat(results).containsExactly(true); } - @Test - public void fromWithTernaryExpressionStringWithMethodCall() { + @ParameterizedTest + @MethodSource("parameters") + public void fromWithTernaryExpressionStringWithMethodCall(RUN_TYPE runType) { // DROOLS-7236 String str = "import " + MyFact.class.getCanonicalName() + ";\n" + @@ -1505,7 +1542,7 @@ public void fromWithTernaryExpressionStringWithMethodCall() { " results.add($bar);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1544,8 +1581,9 @@ public void setStrValue(String strValue) { } - @Test - public void testFromGlobalWithDuplicates() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromGlobalWithDuplicates(RUN_TYPE runType) { String str = "import java.util.concurrent.atomic.AtomicInteger;\n" + "import " + NamedPerson.class.getCanonicalName() + ";\n" + @@ -1557,7 +1595,7 @@ public void testFromGlobalWithDuplicates() { " insert($o); \n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List strings = Arrays.asList(new NamedPerson("Mario", 1), new NamedPerson("Mario", 2)); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/FunctionsTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/FunctionsTest.java index 04af90eab76..6fb44fa32dd 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/FunctionsTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/FunctionsTest.java @@ -24,19 +24,17 @@ import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class FunctionsTest extends BaseModelTest { - public FunctionsTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testFunctionWithEquals() { + @ParameterizedTest + @MethodSource("parameters") + public void testFunctionWithEquals(RUN_TYPE runType) { // DROOLS-3653 String str = "package com.sample\n" + "import " + Person.class.getName() + ";\n" + @@ -58,15 +56,16 @@ public void testFunctionWithEquals() { " then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("John", 10)); int rulesFired = ksession.fireAllRules(); assertThat(rulesFired).isEqualTo(1); // only R1 should fire } - @Test - public void testConstraintCallingStaticFunctionInsideEnum() { + @ParameterizedTest + @MethodSource("parameters") + public void testConstraintCallingStaticFunctionInsideEnum(RUN_TYPE runType) { String str = "import " + Person.class.getName() + ";\n" + "import " + FunctionEnum.class.getCanonicalName() + ";\n" + @@ -76,7 +75,7 @@ public void testConstraintCallingStaticFunctionInsideEnum() { " then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person john = new Person("John", 10); @@ -88,8 +87,9 @@ public void testConstraintCallingStaticFunctionInsideEnum() { assertThat(rulesFired).isEqualTo(1); } - @Test - public void testConstraintCallingImportedStaticFunction() { + @ParameterizedTest + @MethodSource("parameters") + public void testConstraintCallingImportedStaticFunction(RUN_TYPE runType) { String str = "import " + Person.class.getName() + ";\n" + "import " + FunctionEnum.class.getCanonicalName() + ";\n" + @@ -100,7 +100,7 @@ public void testConstraintCallingImportedStaticFunction() { " then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person john = new Person("John", 10); @@ -121,8 +121,9 @@ public static FunctionEnum constantEnumValue(String input) { } - @Test - public void testStaticMethodCall1() { + @ParameterizedTest + @MethodSource("parameters") + public void testStaticMethodCall1(RUN_TYPE runType) { // DROOLS-5214 String str = "package com.sample\n" + @@ -134,15 +135,16 @@ public void testStaticMethodCall1() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Pojo( Arrays.asList(1,3) ) ); int rulesFired = ksession.fireAllRules(); assertThat(rulesFired).isEqualTo(1); } - @Test - public void testStaticMethodCall2() { + @ParameterizedTest + @MethodSource("parameters") + public void testStaticMethodCall2(RUN_TYPE runType) { // DROOLS-5214 String str = "package com.sample\n" + @@ -154,15 +156,16 @@ public void testStaticMethodCall2() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Pojo( Arrays.asList(1,2,3) ) ); int rulesFired = ksession.fireAllRules(); assertThat(rulesFired).isEqualTo(1); } - @Test - public void testFQNStaticMethodCall1() { + @ParameterizedTest + @MethodSource("parameters") + public void testFQNStaticMethodCall1(RUN_TYPE runType) { // DROOLS-5214 String str = "package com.sample\n" + @@ -173,15 +176,16 @@ public void testFQNStaticMethodCall1() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Pojo( Arrays.asList(1,3) ) ); int rulesFired = ksession.fireAllRules(); assertThat(rulesFired).isEqualTo(1); } - @Test - public void testFQNStaticMethodCall2() { + @ParameterizedTest + @MethodSource("parameters") + public void testFQNStaticMethodCall2(RUN_TYPE runType) { // DROOLS-5214 String str = "package com.sample\n" + @@ -192,7 +196,7 @@ public void testFQNStaticMethodCall2() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Pojo( Arrays.asList(1,2,3) ) ); int rulesFired = ksession.fireAllRules(); @@ -211,8 +215,9 @@ public List getIntList() { } } - @Test - public void testInvokeFunctionWithDroolsKeyword() { + @ParameterizedTest + @MethodSource("parameters") + public void testInvokeFunctionWithDroolsKeyword(RUN_TYPE runType) { // DROOLS-5215 String str = "package com.sample\n" + @@ -226,14 +231,15 @@ public void testInvokeFunctionWithDroolsKeyword() { " printRuleName(drools.getRule().getName());\n" + " end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); int rulesFired = ksession.fireAllRules(); assertThat(rulesFired).isEqualTo(1); } - @Test - public void testBindingFieldsIndexedWithSquareBrackets() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindingFieldsIndexedWithSquareBrackets(RUN_TYPE runType) { // DROOLS-5216 String str = "package com.sample\n" + @@ -245,7 +251,7 @@ public void testBindingFieldsIndexedWithSquareBrackets() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Pojo( Arrays.asList(1,3) ) ); int rulesFired = ksession.fireAllRules(); @@ -256,8 +262,9 @@ public static String constantValue(String input) { return "whatever"; } - @Test - public void testExternalFunctionJoin() { + @ParameterizedTest + @MethodSource("parameters") + public void testExternalFunctionJoin(RUN_TYPE runType) { // DROOLS-5288 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -273,7 +280,7 @@ public void testExternalFunctionJoin() { " insert(new Result($p2.getName()));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Luca")); ksession.insert(new Person("whatever")); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GeneratedClassNamesTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GeneratedClassNamesTest.java index 97e765af554..4453582a29f 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GeneratedClassNamesTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GeneratedClassNamesTest.java @@ -20,6 +20,7 @@ import java.util.Set; import java.util.UUID; +import java.util.stream.Stream; import org.drools.compiler.compiler.io.memory.MemoryFileSystem; import org.drools.compiler.kie.builder.impl.InternalKieModule; @@ -30,10 +31,10 @@ import org.drools.modelcompiler.CanonicalKieModule; import org.drools.wiring.api.classloader.ProjectClassLoader; import org.drools.wiring.api.classloader.ProjectClassLoaderTestUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; @@ -54,28 +55,24 @@ public class GeneratedClassNamesTest extends BaseModelTest { private boolean enableStoreFirstOrig; - public GeneratedClassNamesTest(RUN_TYPE testRunType) { - super(testRunType); + public static Stream parameters() { + return Stream.of(RUN_TYPE.PATTERN_DSL); } - @Parameters(name = "{0}") - public static Object[] params() { - return new Object[]{RUN_TYPE.PATTERN_DSL}; - } - - @Before - public void init() { + @BeforeEach + public void setUp() { enableStoreFirstOrig = ProjectClassLoader.isEnableStoreFirst(); ProjectClassLoaderTestUtil.setEnableStoreFirst(true); } - @After - public void clear() { + @AfterEach + public void tearDown() { ProjectClassLoaderTestUtil.setEnableStoreFirst(enableStoreFirstOrig); } - @Test - public void testGeneratedClassNames() { + @ParameterizedTest + @MethodSource("parameters") + public void testGeneratedClassNames(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -87,7 +84,7 @@ public void testGeneratedClassNames() { KieServices ks = KieServices.get(); ReleaseId releaseId = ks.newReleaseId("org.kie", "kjar-test-" + UUID.randomUUID(), "1.0"); - createKieBuilder(ks, getDefaultKieModuleModel( ks ), releaseId, toKieFiles(new String[]{str})); + createKieBuilder(runType, ks, getDefaultKieModuleModel( ks ), releaseId, toKieFiles(new String[]{str})); KieContainer kcontainer = ks.newKieContainer(releaseId); KieModule kieModule = ((KieContainerImpl) kcontainer).getKieModuleForKBase("kbase"); @@ -123,12 +120,14 @@ private void assertGeneratedClassNames(Set generatedClassNames) { } } - @Test + @ParameterizedTest + @MethodSource("parameters") public void testModuleWithDepWithoutClassLoader() throws Exception { testModuleWithDep(null); } - @Test + @ParameterizedTest + @MethodSource("parameters") public void testModuleWithDepWithClassLoader() throws Exception { ProjectClassLoader projectClassLoader = ProjectClassLoader.createProjectClassLoader(Thread.currentThread().getContextClassLoader()); testModuleWithDep(projectClassLoader); @@ -266,8 +265,9 @@ private void assertGeneratedClassNamesWithDep(Set generatedClassNames) { } } - @Test - public void testKjarWithoutGeneratedClassNames() { + @ParameterizedTest + @MethodSource("parameters") + public void testKjarWithoutGeneratedClassNames(RUN_TYPE runType) { // Build a kjar without generated-class-names file (= simulating a build by old drools version) ProjectClassLoaderTestUtil.setEnableStoreFirst(false); @@ -283,7 +283,7 @@ public void testKjarWithoutGeneratedClassNames() { KieServices ks = KieServices.get(); ReleaseId releaseId = ks.newReleaseId("org.kie", "kjar-test-" + UUID.randomUUID(), "1.0"); - KieBuilder kieBuilder = createKieBuilder(ks, getDefaultKieModuleModel( ks ), releaseId, toKieFiles(new String[]{str})); + KieBuilder kieBuilder = createKieBuilder(runType, ks, getDefaultKieModuleModel( ks ), releaseId, toKieFiles(new String[]{str})); final InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModule(); byte[] kjar = kieModule.getBytes(); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GenericsTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GenericsTest.java index c08544f01e9..a2bccfaaece 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GenericsTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GenericsTest.java @@ -24,19 +24,17 @@ import org.drools.model.codegen.execmodel.domain.Address; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class GenericsTest extends BaseModelTest { - public GenericsTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Test - public void testGenericsAccumulateInlineCode() { + @ParameterizedTest + @MethodSource("parameters") + public void testGenericsAccumulateInlineCode(RUN_TYPE runType) { // accumulate inline code supports generics String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -55,7 +53,7 @@ public void testGenericsAccumulateInlineCode() { " results.add($l);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List> results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -94,8 +92,9 @@ public void setExtendedAddress(final P extendedAddress) { } } - @Test - public void testClassWithGenericField() { + @ParameterizedTest + @MethodSource("parameters") + public void testClassWithGenericField(RUN_TYPE runType) { // KIE-1077 String str = "import " + ClassWithGenericField.class.getCanonicalName() + ";\n " + @@ -107,7 +106,7 @@ public void testClassWithGenericField() { " results.add($addressStreet);\n " + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -118,8 +117,9 @@ public void testClassWithGenericField() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testGenericsOnSuperclass() { + @ParameterizedTest + @MethodSource("parameters") + public void testGenericsOnSuperclass(RUN_TYPE runType) { // KIE-DROOLS-5925 String str = "import " + DieselCar.class.getCanonicalName() + ";\n " + @@ -143,11 +143,12 @@ public void testGenericsOnSuperclass() { " update($v);\n" + "end"; - runTestWithGenerics(str); + runTestWithGenerics(runType, str); } - @Test - public void testGenericsOnSuperclassWithRedundantVariableDeclaration() { + @ParameterizedTest + @MethodSource("parameters") + public void testGenericsOnSuperclassWithRedundantVariableDeclaration(RUN_TYPE runType) { // KIE-DROOLS-5925 String str = "import " + DieselCar.class.getCanonicalName() + ";\n " + @@ -171,11 +172,11 @@ public void testGenericsOnSuperclassWithRedundantVariableDeclaration() { " update($v);\n" + "end"; - runTestWithGenerics(str); + runTestWithGenerics(runType, str); } - private void runTestWithGenerics(String str) { - KieSession ksession = getKieSession(str); + private void runTestWithGenerics(RUN_TYPE runType, String str) { + KieSession ksession = getKieSession(runType, str); DieselCar vehicle1 = new DieselCar("Volkswagen", "Passat", 100); vehicle1.setFrameMaxTorque(500); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GetterOverloadingTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GetterOverloadingTest.java index 5c72aa7700a..d4408ce55e3 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GetterOverloadingTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GetterOverloadingTest.java @@ -20,7 +20,8 @@ import java.util.List; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.Message.Level; @@ -31,10 +32,6 @@ public class GetterOverloadingTest extends BaseModelTest { - public GetterOverloadingTest(RUN_TYPE testRunType) { - super(testRunType); - } - // NOTE: Drools/Mvel accepts 5 kinds of getters // e.g. for "resource" property, // @@ -46,8 +43,9 @@ public GetterOverloadingTest(RUN_TYPE testRunType) { // // If a class has multiple getters of those 5, one getter has to be chosen based on the above priority order - @Test - public void testDuplicateDifferentPropertyInClassHierarchy() { + @ParameterizedTest + @MethodSource("parameters") + public void testDuplicateDifferentPropertyInClassHierarchy(RUN_TYPE runType) { // ClassA.resource is boolean : isResource() // ClassB.resource is String : getResource() // Mvel picks a method from getResource or isResoure depending on the order of Class.getMethods() -> unreliable. So let's make this ERROR @@ -59,7 +57,7 @@ public void testDuplicateDifferentPropertyInClassHierarchy() { "then\n" + "end\n"; - KieBuilder kieBuilder = createKieBuilder(str); + KieBuilder kieBuilder = createKieBuilder(runType, str); List messages = kieBuilder.getResults().getMessages(Level.ERROR); assertThat(messages.get(0).getText()).contains("Incompatible Getter overloading detected"); } @@ -90,8 +88,9 @@ public void setResource(String resource) { } } - @Test - public void testBooleanAccessorOverload() { + @ParameterizedTest + @MethodSource("parameters") + public void testBooleanAccessorOverload(RUN_TYPE runType) { // ClassC implements both isResource() and getResource() for boolean (This is acceptable according to Javabeans spec) // isResource() has to be prioritized per Javabeans spec. // No Warning @@ -103,7 +102,7 @@ public void testBooleanAccessorOverload() { "then\n" + "end\n"; - KieBuilder kieBuilder = createKieBuilder(str); + KieBuilder kieBuilder = createKieBuilder(runType, str); List messages = kieBuilder.getResults().getMessages(); assertThat(messages).isEmpty(); @@ -135,8 +134,9 @@ public void setResource(boolean resource) { } } - @Test - public void testAccessorInMultipleInterfaces() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccessorInMultipleInterfaces(RUN_TYPE runType) { // 2 super interfaces have the same abstract method // Valid overriding. No warning. final String str = @@ -147,7 +147,7 @@ public void testAccessorInMultipleInterfaces() { "then\n" + "end\n"; - KieBuilder kieBuilder = createKieBuilder(str); + KieBuilder kieBuilder = createKieBuilder(runType, str); List messages = kieBuilder.getResults().getMessages(); assertThat(messages).isEmpty(); @@ -189,8 +189,9 @@ public String getName() { } } - @Test - public void testAccessorInSuperClassAndInterface() { + @ParameterizedTest + @MethodSource("parameters") + public void testAccessorInSuperClassAndInterface(RUN_TYPE runType) { // Valid overriding from super class and interface. No Warning final String str = "import " + ClassF.class.getCanonicalName() + ";" + @@ -200,7 +201,7 @@ public void testAccessorInSuperClassAndInterface() { "then\n" + "end\n"; - KieBuilder kieBuilder = createKieBuilder(str); + KieBuilder kieBuilder = createKieBuilder(runType, str); List messages = kieBuilder.getResults().getMessages(); assertThat(messages).isEmpty(); @@ -240,8 +241,9 @@ public String getName() { } } - @Test - public void testAcceptableStringAccessorOverload() { + @ParameterizedTest + @MethodSource("parameters") + public void testAcceptableStringAccessorOverload(RUN_TYPE runType) { // ClassG implements getName(), getname() and name() for String // This is acceptable overloading and getName() has to be prioritized. No Warning. final String str = @@ -252,7 +254,7 @@ public void testAcceptableStringAccessorOverload() { "then\n" + "end\n"; - KieBuilder kieBuilder = createKieBuilder(str); + KieBuilder kieBuilder = createKieBuilder(runType, str); List messages = kieBuilder.getResults().getMessages(); assertThat(messages).isEmpty(); @@ -287,8 +289,9 @@ public String name() { } } - @Test - public void testCovariantOverload() { + @ParameterizedTest + @MethodSource("parameters") + public void testCovariantOverload(RUN_TYPE runType) { // ClassH : getValue() returns Number // ClassI : getValue() returns Integer // a more specialized getter (covariant overload) is preferred. @@ -300,7 +303,7 @@ public void testCovariantOverload() { "then\n" + "end\n"; - KieBuilder kieBuilder = createKieBuilder(str); + KieBuilder kieBuilder = createKieBuilder(runType, str); List messages = kieBuilder.getResults().getMessages(); assertThat(messages).isEmpty(); @@ -339,8 +342,9 @@ public Integer getValue() { } } - @Test - public void testContravariantOverload() { + @ParameterizedTest + @MethodSource("parameters") + public void testContravariantOverload(RUN_TYPE runType) { // ClassJ : getValue() returns Integer // ClassK : getvalue() returns Number // a more specialized getter (covariant overload) is preferred regardless of class hierarchy. @@ -352,7 +356,7 @@ public void testContravariantOverload() { "then\n" + "end\n"; - KieBuilder kieBuilder = createKieBuilder(str); + KieBuilder kieBuilder = createKieBuilder(runType, str); List messages = kieBuilder.getResults().getMessages(); assertThat(messages).isEmpty(); @@ -390,8 +394,9 @@ public Number getvalue() { // cannot define Number getValue() } } - @Test - public void testPossibleBooleanAccessorOverload() { + @ParameterizedTest + @MethodSource("parameters") + public void testPossibleBooleanAccessorOverload(RUN_TYPE runType) { // ClassL implements 5 possible getters // This is acceptable overloading and isResource() has to be prioritized. No Warning. final String str = @@ -402,7 +407,7 @@ public void testPossibleBooleanAccessorOverload() { "then\n" + "end\n"; - KieBuilder kieBuilder = createKieBuilder(str); + KieBuilder kieBuilder = createKieBuilder(runType, str); List messages = kieBuilder.getResults().getMessages(); assertThat(messages).isEmpty(); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GlobalTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GlobalTest.java index 190a6bc792a..b3bf58b9c81 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GlobalTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GlobalTest.java @@ -25,7 +25,8 @@ import org.drools.model.codegen.execmodel.domain.InputDataTypes; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.builder.Message; import org.kie.api.builder.Results; @@ -36,12 +37,9 @@ public class GlobalTest extends BaseModelTest { - public GlobalTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testGlobalInConsequence() { + @ParameterizedTest + @MethodSource("parameters") + public void testGlobalInConsequence(RUN_TYPE runType) { String str = "package org.mypkg;" + "import " + Person.class.getCanonicalName() + ";" + @@ -53,7 +51,7 @@ public void testGlobalInConsequence() { " globalResult.setValue($p1.getName() + \" is \" + $p1.getAge());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.setGlobal("globalResult", result); @@ -67,8 +65,9 @@ public void testGlobalInConsequence() { assertThat(result.getValue()).isEqualTo("Mark is 37"); } - @Test - public void testGlobalInConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testGlobalInConstraint(RUN_TYPE runType) { String str = "package org.mypkg;" + "import " + Person.class.getCanonicalName() + ";" + @@ -81,7 +80,7 @@ public void testGlobalInConstraint() { " resultG.setValue($p1.getName() + \" is \" + $p1.getAge());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal("nameG", "Mark"); @@ -164,8 +163,9 @@ public Double sumOf(Object[] objects) { } - @Test - public void testGlobalBooleanFunction() { + @ParameterizedTest + @MethodSource("parameters") + public void testGlobalBooleanFunction(RUN_TYPE runType) { String str = "package org.mypkg;" + "import " + Person.class.getCanonicalName() + ";" + @@ -179,7 +179,7 @@ public void testGlobalBooleanFunction() { " resultG.setValue($p1.getName() + \" is \" + $p1.getAge());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal("functions", new Functions()); @@ -195,8 +195,9 @@ public void testGlobalBooleanFunction() { assertThat(result.getValue()).isEqualTo("Mark is 37"); } - @Test - public void testGlobalFunctionOnLeft() { + @ParameterizedTest + @MethodSource("parameters") + public void testGlobalFunctionOnLeft(RUN_TYPE runType) { String str = "package org.mypkg;" + "import " + Person.class.getCanonicalName() + ";" + @@ -210,7 +211,7 @@ public void testGlobalFunctionOnLeft() { " resultG.setValue($p1.getName() + \" is \" + $p1.getAge());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal("functions", new Functions()); @@ -226,8 +227,9 @@ public void testGlobalFunctionOnLeft() { assertThat(result.getValue()).isEqualTo("Mark is 37"); } - @Test - public void testGlobalFunctionOnRight() { + @ParameterizedTest + @MethodSource("parameters") + public void testGlobalFunctionOnRight(RUN_TYPE runType) { String str = "package org.mypkg;" + "import " + Person.class.getCanonicalName() + ";" + @@ -241,7 +243,7 @@ public void testGlobalFunctionOnRight() { " resultG.setValue($p1.getName() + \" is \" + $p1.getAge());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal("functions", new Functions()); @@ -263,8 +265,9 @@ public Object getPersons() { } } - @Test - public void testComplexGlobalFunction() { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexGlobalFunction(RUN_TYPE runType) { String str = "package org.mypkg;" + "import " + Family.class.getCanonicalName() + ";" + @@ -277,15 +280,16 @@ public void testComplexGlobalFunction() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal("functions", new Functions()); ksession.insert(new Family()); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testComplexGlobalFunctionWithShort() { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexGlobalFunctionWithShort(RUN_TYPE runType) { String str = "package org.mypkg;" + "import " + Family.class.getCanonicalName() + ";" + @@ -298,15 +302,16 @@ public void testComplexGlobalFunctionWithShort() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal("functions", new Functions()); ksession.insert(new Family()); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testComplexGlobalFunctionWithShortEvalOnJoin() { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexGlobalFunctionWithShortEvalOnJoin(RUN_TYPE runType) { String str = "package org.mypkg;" + "import " + Family.class.getCanonicalName() + ";" + @@ -320,7 +325,7 @@ public void testComplexGlobalFunctionWithShortEvalOnJoin() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal("functions", new Functions()); ksession.insert(new Family()); ksession.insert("test"); @@ -328,8 +333,9 @@ public void testComplexGlobalFunctionWithShortEvalOnJoin() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testComplexGlobalFunctionWithShortNotFiring() { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexGlobalFunctionWithShortNotFiring(RUN_TYPE runType) { String str = "package org.mypkg;" + "import " + Family.class.getCanonicalName() + ";" + @@ -342,7 +348,7 @@ public void testComplexGlobalFunctionWithShortNotFiring() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal("functions", new Functions()); ksession.insert(new Family()); @@ -350,17 +356,19 @@ public void testComplexGlobalFunctionWithShortNotFiring() { } - @Test - public void testGlobalOnTypeDeclaration() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testGlobalOnTypeDeclaration(RUN_TYPE runType) throws Exception { String str = "declare MyObject end\n" + "global MyObject event;"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); } - @Test - public void testGlobalFunctionWithArrayInput() { + @ParameterizedTest + @MethodSource("parameters") + public void testGlobalFunctionWithArrayInput(RUN_TYPE runType) { String str = "package org.mypkg;" + "import " + InputDataTypes.class.getCanonicalName() + ";" + @@ -384,15 +392,16 @@ public void testGlobalFunctionWithArrayInput() { " update($input);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal("functions", new Functions()); ksession.insert(new InputDataTypes()); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testGlobalFunctionWithLargeArrayInput() { + @ParameterizedTest + @MethodSource("parameters") + public void testGlobalFunctionWithLargeArrayInput(RUN_TYPE runType) { String str = "package org.mypkg;" + "import " + InputDataTypes.class.getCanonicalName() + ";" + @@ -453,15 +462,16 @@ public void testGlobalFunctionWithLargeArrayInput() { " update($input);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal("functions", new Functions()); ksession.insert(new InputDataTypes()); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testGlobalInDifferentPackage() throws InstantiationException, IllegalAccessException { + @ParameterizedTest + @MethodSource("parameters") + public void testGlobalInDifferentPackage(RUN_TYPE runType) throws InstantiationException, IllegalAccessException { // DROOLS-6657 String def = "package org.drools.reproducer.definitions\n" + @@ -482,7 +492,7 @@ public void testGlobalInDifferentPackage() throws InstantiationException, Illega " globalList.add(\"FOO matched\");\n" + "end\n"; - KieSession ksession = getKieSession( rule, def ); + KieSession ksession = getKieSession(runType, rule, def); KieBase kb = ksession.getKieBase(); assertThat(ksession.fireAllRules()).isEqualTo(0); @@ -502,8 +512,9 @@ public void testGlobalInDifferentPackage() throws InstantiationException, Illega assertThat(globalList.get(0)).isEqualTo("FOO matched"); } - @Test - public void testGenericOnGlobal() { + @ParameterizedTest + @MethodSource("parameters") + public void testGenericOnGlobal(RUN_TYPE runType) { // DROOLS-7155 String def = "package org.drools.reproducer\n" + @@ -513,14 +524,15 @@ public void testGenericOnGlobal() { " globalList.add(\"test\");\n" + "end\n"; - KieSession ksession = getKieSession( def ); + KieSession ksession = getKieSession(runType, def); ksession.setGlobal("globalList", new ArrayList()); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testWrongGenericOnGlobal() { + @ParameterizedTest + @MethodSource("parameters") + public void testWrongGenericOnGlobal(RUN_TYPE runType) { // DROOLS-7155 String def = "package org.drools.reproducer\n" + @@ -530,7 +542,7 @@ public void testWrongGenericOnGlobal() { " globalList.add(\"test\");\n" + "end\n"; - Results results = createKieBuilder(def).getResults(); + Results results = createKieBuilder(runType, def).getResults(); assertThat(results.getMessages(Message.Level.ERROR)).isNotEmpty(); assertThat(results.getMessages(Message.Level.ERROR).stream().map(Message::getText) .anyMatch(s -> s.contains("The method add(Integer) in the type List is not applicable for the arguments (String)"))).isTrue(); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GroupByTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GroupByTest.java index 020cbce685e..1adc41e23d6 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GroupByTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/GroupByTest.java @@ -25,7 +25,8 @@ import org.drools.model.codegen.execmodel.domain.Parent; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.functions.accumulate.GroupKey; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; import org.kie.api.runtime.rule.Match; @@ -49,28 +50,25 @@ public class GroupByTest extends BaseModelTest { - public GroupByTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - public void assertSessionHasProperties(String ruleString, Consumer kieSessionConsumer) { + public void assertSessionHasProperties(RUN_TYPE testRunType, String ruleString, Consumer kieSessionConsumer) { if (testRunType.isExecutableModel()) { - KieSession ksession = getKieSession( ruleString ); + KieSession ksession = getKieSession(testRunType, ruleString); kieSessionConsumer.accept(ksession); } else { assertAll(() -> { - KieSession ksession = getKieSession( "dialect \"java\";\n" + ruleString); + KieSession ksession = getKieSession(testRunType, "dialect \"java\";\n" + ruleString); kieSessionConsumer.accept(ksession); }, () -> { - KieSession ksession = getKieSession( "dialect \"mvel\";\n" + ruleString); + KieSession ksession = getKieSession(testRunType, "dialect \"mvel\";\n" + ruleString); kieSessionConsumer.accept(ksession); }); } } - @Test - public void providedInstance() { + @ParameterizedTest + @MethodSource("parameters") + public void providedInstance(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "import " + Map.class.getCanonicalName() + ";\n" + "global Map results;\n" + @@ -83,7 +81,7 @@ public void providedInstance() { " results.put($key, $sumOfAges);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { Map results = new HashMap(); ksession.setGlobal( "results", results ); @@ -117,8 +115,9 @@ public void providedInstance() { }); } - @Test - public void testSumPersonAgeGroupByInitialWithAcc() { + @ParameterizedTest + @MethodSource("parameters") + public void testSumPersonAgeGroupByInitialWithAcc(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + GroupKey.class.getCanonicalName() + ";" + @@ -146,7 +145,7 @@ public void testSumPersonAgeGroupByInitialWithAcc() { " results.put($key, $sumOfAges);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { Map results = new HashMap(); ksession.setGlobal( "results", results ); @@ -181,8 +180,9 @@ public void testSumPersonAgeGroupByInitialWithAcc() { }); } - @Test - public void testGroupPersonsInitial() { + @ParameterizedTest + @MethodSource("parameters") + public void testGroupPersonsInitial(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + List.class.getCanonicalName() + ";" + @@ -194,7 +194,7 @@ public void testGroupPersonsInitial() { " results.add($key);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { List results = new ArrayList<>(); ksession.setGlobal( "results", results ); @@ -229,8 +229,9 @@ public void testGroupPersonsInitial() { }); } - @Test - public void testSumPersonAgeGroupByInitial() { + @ParameterizedTest + @MethodSource("parameters") + public void testSumPersonAgeGroupByInitial(RUN_TYPE runType) { // Note: this appears to be a duplicate of providedInstance String str = "import " + Person.class.getCanonicalName() + ";" + @@ -244,7 +245,7 @@ public void testSumPersonAgeGroupByInitial() { "then\n" + " results.put($key, $sumOfAges);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { Map results = new HashMap(); ksession.setGlobal( "results", results ); @@ -279,8 +280,9 @@ public void testSumPersonAgeGroupByInitial() { }); } - @Test - public void testSumPersonAgeGroupByInitialWithBetaFilter() { + @ParameterizedTest + @MethodSource("parameters") + public void testSumPersonAgeGroupByInitialWithBetaFilter(RUN_TYPE runType) { // TODO: For some reason, the compiled class expression thinks $p should be an integer? String str = "import " + Person.class.getCanonicalName() + ";" + @@ -295,7 +297,7 @@ public void testSumPersonAgeGroupByInitialWithBetaFilter() { " results.put($key, $sum);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { Map results = new HashMap(); ksession.setGlobal("results", results); @@ -331,8 +333,9 @@ public void testSumPersonAgeGroupByInitialWithBetaFilter() { }); } - @Test - public void testSumPersonAgeGroupByInitialWithExists() { + @ParameterizedTest + @MethodSource("parameters") + public void testSumPersonAgeGroupByInitialWithExists(RUN_TYPE runType) { // TODO: For some reason, the compiled class expression thinks $p should be an integer? String str = "import " + Person.class.getCanonicalName() + ";" + @@ -348,7 +351,7 @@ public void testSumPersonAgeGroupByInitialWithExists() { " results.put($key, $sum);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { Map results = new HashMap(); ksession.setGlobal("results", results); @@ -405,8 +408,9 @@ public MyType getNested() { } } - @Test - public void testWithNull() { + @ParameterizedTest + @MethodSource("parameters") + public void testWithNull(RUN_TYPE runType) { String str = "import " + MyType.class.getCanonicalName() + ";" + "import " + List.class.getCanonicalName() + ";" + @@ -421,7 +425,7 @@ public void testWithNull() { " result.add($key);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { AtomicInteger mappingFunctionCallCounter = new AtomicInteger(); List result = new ArrayList<>(); ksession.setGlobal("mappingFunctionCallCounter", mappingFunctionCallCounter); @@ -440,8 +444,9 @@ public void testWithNull() { }); } - @Test - public void testWithGroupByAfterExists() { + @ParameterizedTest + @MethodSource("parameters") + public void testWithGroupByAfterExists(RUN_TYPE runType) { String str = "import " + Map.class.getCanonicalName() + ";" + "import " + Math.class.getCanonicalName() + ";" + @@ -454,7 +459,7 @@ public void testWithGroupByAfterExists() { " glob.put($key, $count.intValue());\n" + "end"; - assertSessionHasProperties(str, session -> { + assertSessionHasProperties(runType, str, session -> { Map global = new HashMap<>(); session.setGlobal("glob", global); @@ -470,8 +475,9 @@ public void testWithGroupByAfterExists() { }); } - @Test - public void testWithGroupByAfterExistsWithFrom() { + @ParameterizedTest + @MethodSource("parameters") + public void testWithGroupByAfterExistsWithFrom(RUN_TYPE runType) { // Note: this looks exactly the same as testWithGroupByAfterExists String str = "import " + Map.class.getCanonicalName() + ";" + @@ -485,7 +491,7 @@ public void testWithGroupByAfterExistsWithFrom() { " glob.put($key, $count.intValue());\n" + "end"; - assertSessionHasProperties(str, session -> { + assertSessionHasProperties(runType, str, session -> { Map global = new HashMap<>(); session.setGlobal("glob", global); @@ -501,8 +507,9 @@ public void testWithGroupByAfterExistsWithFrom() { }); } - @Test - public void testGroupBy2Vars() { + @ParameterizedTest + @MethodSource("parameters") + public void testGroupBy2Vars(RUN_TYPE runType) { // TODO: For some reason, the compiled class expression thinks $p should be an integer? String str = "import " + Person.class.getCanonicalName() + ";" + @@ -516,7 +523,7 @@ public void testGroupBy2Vars() { " results.put($key, $sum);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { Map results = new HashMap(); ksession.setGlobal("results", results); @@ -560,8 +567,9 @@ public void testGroupBy2Vars() { }); } - @Test - public void testUnexpectedRuleMatch() { + @ParameterizedTest + @MethodSource("parameters") + public void testUnexpectedRuleMatch(RUN_TYPE runType) { String str = "import " + Parent.class.getCanonicalName() + ";" + "import " + Child.class.getCanonicalName() + ";" + @@ -578,7 +586,7 @@ public void testUnexpectedRuleMatch() { " results.add(Arrays.asList($child, $count));\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { List results = new ArrayList(); ksession.setGlobal("results", results); @@ -603,8 +611,9 @@ public void testUnexpectedRuleMatch() { }); } - @Test - public void testCompositeKey() { + @ParameterizedTest + @MethodSource("parameters") + public void testCompositeKey(RUN_TYPE runType) { // TODO: For some reason, the compiled class expression thinks $p should be an integer? String str = "import " + Person.class.getCanonicalName() + ";" + @@ -623,7 +632,7 @@ public void testCompositeKey() { " results.put($key1, $sum);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { Map results = new HashMap(); ksession.setGlobal("results", results); @@ -698,8 +707,9 @@ public String toString() { } } - @Test - public void testTwoExpressionsOnSecondPattern() { + @ParameterizedTest + @MethodSource("parameters") + public void testTwoExpressionsOnSecondPattern(RUN_TYPE runType) { // DROOLS-5704 // TODO: For some reason, the compiled class expression thinks $p should be an integer? String str = @@ -716,7 +726,7 @@ public void testTwoExpressionsOnSecondPattern() { " results.add($key);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { Set results = new LinkedHashSet<>(); ksession.setGlobal("results", results); @@ -730,8 +740,9 @@ public void testTwoExpressionsOnSecondPattern() { }); } - @Test - public void testFromAfterGroupBy() { + @ParameterizedTest + @MethodSource("parameters") + public void testFromAfterGroupBy(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Set.class.getCanonicalName() + ";" + @@ -750,7 +761,7 @@ public void testFromAfterGroupBy() { " typeChecker.accept($remappedKey);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { Set results = new LinkedHashSet<>(); ksession.setGlobal("results", results); @@ -768,8 +779,9 @@ public void testFromAfterGroupBy() { }); } - @Test - public void testBindingRemappedAfterGroupBy() { + @ParameterizedTest + @MethodSource("parameters") + public void testBindingRemappedAfterGroupBy(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Set.class.getCanonicalName() + ";" + @@ -788,7 +800,7 @@ public void testBindingRemappedAfterGroupBy() { " typeChecker.accept($remappedKey);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { Set results = new LinkedHashSet<>(); ksession.setGlobal("results", results); @@ -806,8 +818,9 @@ public void testBindingRemappedAfterGroupBy() { }); } - @Test - public void testGroupByUpdatingKey() { + @ParameterizedTest + @MethodSource("parameters") + public void testGroupByUpdatingKey(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Map.class.getCanonicalName() + ";" + @@ -823,7 +836,7 @@ public void testGroupByUpdatingKey() { " results.put($key, $sumOfAges + $countOfPersons.intValue());" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { Map results = new HashMap(); ksession.setGlobal("results", results); @@ -851,8 +864,9 @@ public void testGroupByUpdatingKey() { }); } - @Test - public void doesNotRemoveProperly() { + @ParameterizedTest + @MethodSource("parameters") + public void doesNotRemoveProperly(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Set.class.getCanonicalName() + ";" + @@ -867,7 +881,7 @@ public void doesNotRemoveProperly() { " results.add($key);" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { Set results = new LinkedHashSet<>(); @@ -911,8 +925,9 @@ public void onUpdateMatch(Match match) { }); } - @Test - public void testTwoGroupBy() { + @ParameterizedTest + @MethodSource("parameters") + public void testTwoGroupBy(RUN_TYPE runType) { // DROOLS-5697 // TODO: For some reason, the compiled class expression thinks $p should be an integer? String str = @@ -936,7 +951,7 @@ public void testTwoGroupBy() { " results.put($key, $maxOfValues);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { Map results = new HashMap(); ksession.setGlobal("results", results); @@ -991,8 +1006,9 @@ public void testTwoGroupBy() { }); } - @Test - public void testTwoGroupByUsingBindings() { + @ParameterizedTest + @MethodSource("parameters") + public void testTwoGroupByUsingBindings(RUN_TYPE runType) { // DROOLS-5697 // TODO: For some reason, the compiled class expression thinks $p should be an integer? String str = @@ -1016,7 +1032,7 @@ public void testTwoGroupByUsingBindings() { " results.put($key, $maxOfValues);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { Map results = new HashMap(); ksession.setGlobal("results", results); @@ -1089,8 +1105,9 @@ public Object getValue() { } } - @Test - public void testEmptyPatternOnGroupByKey() { + @ParameterizedTest + @MethodSource("parameters") + public void testEmptyPatternOnGroupByKey(RUN_TYPE runType) { // DROOLS-6031 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -1107,7 +1124,7 @@ public void testEmptyPatternOnGroupByKey() { " results.add($key);" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { List results = new ArrayList(); ksession.setGlobal("results", results); @@ -1122,8 +1139,9 @@ public void testEmptyPatternOnGroupByKey() { }); } - @Test - public void testFilterOnGroupByKey() { + @ParameterizedTest + @MethodSource("parameters") + public void testFilterOnGroupByKey(RUN_TYPE runType) { // DROOLS-6031 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -1141,7 +1159,7 @@ public void testFilterOnGroupByKey() { " results.add($key);" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { List results = new ArrayList(); ksession.setGlobal("results", results); @@ -1156,8 +1174,9 @@ public void testFilterOnGroupByKey() { }); } - @Test - public void testDecomposedGroupByKey() { + @ParameterizedTest + @MethodSource("parameters") + public void testDecomposedGroupByKey(RUN_TYPE runType) { // DROOLS-6031 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -1177,7 +1196,7 @@ public void testDecomposedGroupByKey() { " results.add($subkeyB);" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { final List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1192,8 +1211,9 @@ public void testDecomposedGroupByKey() { }); } - @Test - public void testDecomposedGroupByKeyAndAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testDecomposedGroupByKeyAndAccumulate(RUN_TYPE runType) { // DROOLS-6031 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -1215,7 +1235,7 @@ public void testDecomposedGroupByKeyAndAccumulate() { " results.add($accresult);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { final List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1231,8 +1251,9 @@ public void testDecomposedGroupByKeyAndAccumulate() { }); } - @Test - public void testDecomposedGroupByKeyAnd2Accumulates() { + @ParameterizedTest + @MethodSource("parameters") + public void testDecomposedGroupByKeyAnd2Accumulates(RUN_TYPE runType) { // DROOLS-6031 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -1254,7 +1275,7 @@ public void testDecomposedGroupByKeyAnd2Accumulates() { " results.add($accresult);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { final List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1269,8 +1290,9 @@ public void testDecomposedGroupByKeyAnd2Accumulates() { }); } - @Test - public void testDecomposedGroupByKeyAnd2AccumulatesInConsequence() { + @ParameterizedTest + @MethodSource("parameters") + public void testDecomposedGroupByKeyAnd2AccumulatesInConsequence(RUN_TYPE runType) { // DROOLS-6031 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -1288,7 +1310,7 @@ public void testDecomposedGroupByKeyAnd2AccumulatesInConsequence() { " results.add($key);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { final List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1301,8 +1323,9 @@ public void testDecomposedGroupByKeyAnd2AccumulatesInConsequence() { }); } - @Test - public void testNestedGroupBy1a() { + @ParameterizedTest + @MethodSource("parameters") + public void testNestedGroupBy1a(RUN_TYPE runType) { // DROOLS-6045 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -1317,7 +1340,7 @@ public void testNestedGroupBy1a() { " results.add($accresult);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { final List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1329,8 +1352,9 @@ public void testNestedGroupBy1a() { }); } - @Test - public void testNestedGroupBy1b() { + @ParameterizedTest + @MethodSource("parameters") + public void testNestedGroupBy1b(RUN_TYPE runType) { // DROOLS-6045 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -1345,7 +1369,7 @@ public void testNestedGroupBy1b() { " results.add($accresult);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { final List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1356,8 +1380,9 @@ public void testNestedGroupBy1b() { }); } - @Test - public void testNestedGroupBy2() { + @ParameterizedTest + @MethodSource("parameters") + public void testNestedGroupBy2(RUN_TYPE runType) { // DROOLS-6045 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -1374,7 +1399,7 @@ public void testNestedGroupBy2() { "then\n" + " results.add($accresult);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { final List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1386,8 +1411,9 @@ public void testNestedGroupBy2() { }); } - @Test - public void testNestedGroupBy3() { + @ParameterizedTest + @MethodSource("parameters") + public void testNestedGroupBy3(RUN_TYPE runType) { // DROOLS-6045 // TODO: For some reason, the compiled class expression thinks $p should be an integer? String str = @@ -1404,7 +1430,7 @@ public void testNestedGroupBy3() { "then\n" + " results.add($keyOuter);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { final List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1417,8 +1443,9 @@ public void testNestedGroupBy3() { }); } - @Test - public void testFilterOnAccumulateResultWithDecomposedGroupByKey() { + @ParameterizedTest + @MethodSource("parameters") + public void testFilterOnAccumulateResultWithDecomposedGroupByKey(RUN_TYPE runType) { // DROOLS-6045 // TODO: For some reason, the compiled class expression thinks $p should be an integer? String str = @@ -1441,7 +1468,7 @@ public void testFilterOnAccumulateResultWithDecomposedGroupByKey() { " results.add($accresult);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { final List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1524,8 +1551,9 @@ public void testFilterOnAccumulateResultWithDecomposedGroupByKey() { // } // } - @Test - public void testNestedRewrite() { + @ParameterizedTest + @MethodSource("parameters") + public void testNestedRewrite(RUN_TYPE runType) { // DROOLS-5697 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -1544,7 +1572,7 @@ public void testNestedRewrite() { " results.add($maxOfValues);\n" + "end"; - assertSessionHasProperties(str, ksession -> { + assertSessionHasProperties(runType, str, ksession -> { List results = new ArrayList(); ksession.setGlobal("results", results); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/HalfBinaryTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/HalfBinaryTest.java index f4514a36bde..df52b350958 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/HalfBinaryTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/HalfBinaryTest.java @@ -23,26 +23,24 @@ import org.drools.model.codegen.execmodel.domain.Address; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class HalfBinaryTest extends BaseModelTest { - public HalfBinaryTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testHalfBinary() { + @ParameterizedTest + @MethodSource("parameters") + public void testHalfBinary(RUN_TYPE runType) { final String drl1 = "rule R1 when\n" + " Integer(this > 2 && < 5)\n" + "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert( 3 ); ksession.insert( 4 ); @@ -50,8 +48,9 @@ public void testHalfBinary() { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testHalfBinaryWithParenthesis() { + @ParameterizedTest + @MethodSource("parameters") + public void testHalfBinaryWithParenthesis(RUN_TYPE runType) { // DROOLS-6006 final String drl1 = "rule R1 when\n" + @@ -59,7 +58,7 @@ public void testHalfBinaryWithParenthesis() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert( 3 ); ksession.insert( 4 ); @@ -67,8 +66,9 @@ public void testHalfBinaryWithParenthesis() { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testHalfBinaryOrWithParenthesis() { + @ParameterizedTest + @MethodSource("parameters") + public void testHalfBinaryOrWithParenthesis(RUN_TYPE runType) { // DROOLS-6006 final String drl1 = "rule R1 when\n" + @@ -76,7 +76,7 @@ public void testHalfBinaryOrWithParenthesis() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert( 3 ); ksession.insert( 4 ); @@ -84,8 +84,9 @@ public void testHalfBinaryOrWithParenthesis() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testComplexHalfBinary() { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexHalfBinary(RUN_TYPE runType) { // DROOLS-6006 final String drl1 = "rule R1 when\n" + @@ -93,7 +94,7 @@ public void testComplexHalfBinary() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert( 3 ); ksession.insert( 4 ); @@ -101,8 +102,9 @@ public void testComplexHalfBinary() { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testHalfBinaryOnComparable() { + @ParameterizedTest + @MethodSource("parameters") + public void testHalfBinaryOnComparable(RUN_TYPE runType) { // DROOLS-6421 final String drl1 = "rule R1 when\n" + @@ -110,7 +112,7 @@ public void testHalfBinaryOnComparable() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert( "B" ); ksession.insert( "D" ); @@ -119,8 +121,9 @@ public void testHalfBinaryOnComparable() { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testHalfBinaryOrOnComparable() { + @ParameterizedTest + @MethodSource("parameters") + public void testHalfBinaryOrOnComparable(RUN_TYPE runType) { // DROOLS-6421 final String drl1 = "rule R1 when\n" + @@ -128,7 +131,7 @@ public void testHalfBinaryOrOnComparable() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert( "B" ); ksession.insert( "D" ); @@ -137,8 +140,9 @@ public void testHalfBinaryOrOnComparable() { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testComplexHalfBinaryOnComparable() { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexHalfBinaryOnComparable(RUN_TYPE runType) { // DROOLS-6421 final String drl1 = "rule R1 when\n" + @@ -146,7 +150,7 @@ public void testComplexHalfBinaryOnComparable() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert( "B" ); ksession.insert( "D" ); @@ -155,8 +159,9 @@ public void testComplexHalfBinaryOnComparable() { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testComplexHalfBinaryOnComparableField() { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexHalfBinaryOnComparableField(RUN_TYPE runType) { // DROOLS-6421 final String drl1 = "import " + Person.class.getCanonicalName() + ";\n" + @@ -165,7 +170,7 @@ public void testComplexHalfBinaryOnComparableField() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert( new Person("B") ); ksession.insert( new Person("D") ); @@ -174,8 +179,9 @@ public void testComplexHalfBinaryOnComparableField() { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testComplexHalfBinaryOnComparableInternalField() { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexHalfBinaryOnComparableInternalField(RUN_TYPE runType) { // DROOLS-6421 final String drl1 = "import " + Person.class.getCanonicalName() + ";\n" + @@ -184,7 +190,7 @@ public void testComplexHalfBinaryOnComparableInternalField() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); Person b = new Person("B"); b.setAddress(new Address("B")); @@ -202,8 +208,9 @@ public void testComplexHalfBinaryOnComparableInternalField() { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testComplexHalfBinaryOnComparableInternalNullSafeField() { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexHalfBinaryOnComparableInternalNullSafeField(RUN_TYPE runType) { // DROOLS-6421 final String drl1 = "import " + Person.class.getCanonicalName() + ";\n" + @@ -212,7 +219,7 @@ public void testComplexHalfBinaryOnComparableInternalNullSafeField() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); Person a = new Person("A"); a.setAddress(new Address(null)); @@ -233,8 +240,9 @@ public void testComplexHalfBinaryOnComparableInternalNullSafeField() { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testHalfBinaryOrAndAmpersand() { + @ParameterizedTest + @MethodSource("parameters") + public void testHalfBinaryOrAndAmpersand(RUN_TYPE runType) { final String drl = "import " + Person.class.getCanonicalName() + ";\n" + "global java.util.List result;\n" + @@ -244,7 +252,7 @@ public void testHalfBinaryOrAndAmpersand() { " result.add($p.getName());\n" + "end\n"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -257,8 +265,9 @@ public void testHalfBinaryOrAndAmpersand() { assertThat(result).containsExactlyInAnyOrder("A", "C"); } - @Test - public void testNestedHalfBinaryOrAndAmpersand() { + @ParameterizedTest + @MethodSource("parameters") + public void testNestedHalfBinaryOrAndAmpersand(RUN_TYPE runType) { final String drl = "import " + Person.class.getCanonicalName() + ";\n" + "global java.util.List result;\n" + @@ -268,7 +277,7 @@ public void testNestedHalfBinaryOrAndAmpersand() { " result.add($p.getName());\n" + "end\n"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); List result = new ArrayList<>(); ksession.setGlobal("result", result); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/HierarchyRulesTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/HierarchyRulesTest.java index 173f3c1fdbf..5ff5d6627a1 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/HierarchyRulesTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/HierarchyRulesTest.java @@ -18,19 +18,18 @@ */ package org.drools.model.codegen.execmodel; -import org.junit.Test; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; -public class HierarchyRulesTest extends BaseModelTest { +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; - public HierarchyRulesTest(RUN_TYPE testRunType ) { - super( testRunType ); - } +public class HierarchyRulesTest extends BaseModelTest { - @Test - public void test() { + @ParameterizedTest + @MethodSource("parameters") + public void test(RUN_TYPE runType) { // DROOLS-7470 String str = "rule R1 when \n" + @@ -105,7 +104,7 @@ public void test() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat( ksession.fireAllRules() ).isEqualTo(4); } } diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/InTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/InTest.java index 04cf9c53038..dafc5be0272 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/InTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/InTest.java @@ -24,45 +24,45 @@ import org.drools.model.codegen.execmodel.domain.Address; import org.drools.model.codegen.execmodel.domain.Child; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class InTest extends BaseModelTest { - public InTest(RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testInWithNullFire() { + @ParameterizedTest + @MethodSource("parameters") + public void testInWithNullFire(RUN_TYPE runType) { String str = "import " + Child.class.getCanonicalName() + "; \n" + "rule R when \n" + " $c : Child(parent in (\"Gustav\", \"Alice\", null))\n" + "then \n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Child("Ben", 10)); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testInWithNullNoFire() { + @ParameterizedTest + @MethodSource("parameters") + public void testInWithNullNoFire(RUN_TYPE runType) { String str = "import " + Child.class.getCanonicalName() + "; \n" + "rule R when \n" + " $c : Child(parent in (\"Gustav\", \"Alice\"))\n" + "then \n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Child("Ben", 10)); assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testInWithNullComments() { + @ParameterizedTest + @MethodSource("parameters") + public void testInWithNullComments(RUN_TYPE runType) { String str = "import " + Child.class.getCanonicalName() + "; \n" + "global java.util.List results; \n" + "global java.util.List results; \n" + @@ -75,7 +75,7 @@ public void testInWithNullComments() { " results.add($c);\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -88,16 +88,17 @@ public void testInWithNullComments() { assertThat(results).containsExactly(ben); } - @Test - public void testInWithJoin() { + @ParameterizedTest + @MethodSource("parameters") + public void testInWithJoin(RUN_TYPE runType) { String str = "import " + Address.class.getCanonicalName() + "; \n" + "rule R when \n" + " $a1: Address($street: street, city in (\"Brno\", \"Milan\", \"Bratislava\")) \n" + " $a2: Address(city in (\"Krakow\", \"Paris\", $a1.city)) \n" + "then \n" + - "end\n"; + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Address("Brno")); ksession.insert(new Address("Milan")); assertThat(ksession.fireAllRules()).isEqualTo(2); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/IncrementalCompilationTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/IncrementalCompilationTest.java index 0908ce636fa..a060f4eef7b 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/IncrementalCompilationTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/IncrementalCompilationTest.java @@ -24,7 +24,8 @@ import org.drools.model.codegen.execmodel.domain.Address; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieServices; import org.kie.api.builder.ReleaseId; import org.kie.api.builder.model.KieModuleModel; @@ -36,9 +37,6 @@ public class IncrementalCompilationTest extends BaseModelTest { - public IncrementalCompilationTest( RUN_TYPE testRunType ) { - super( testRunType ); - } public class Message implements Serializable { private final String value; @@ -52,8 +50,9 @@ public String getValue() { } } - @Test - public void testKJarUpgradeSameAndDifferentSessions() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testKJarUpgradeSameAndDifferentSessions(RUN_TYPE runType) throws Exception { String drl1 = "package org.drools.incremental\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R1 when\n" + @@ -80,7 +79,7 @@ public void testKJarUpgradeSameAndDifferentSessions() throws Exception { // Create an in-memory jar for version 1.0.0 ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-upgrade", "1.0.0" ); - createAndDeployJar( ks, releaseId1, drl1, drl2_1 ); + createAndDeployJar(runType, ks, releaseId1, drl1, drl2_1 ); // Create a session and fire rules KieContainer kc = ks.newKieContainer( releaseId1 ); @@ -90,7 +89,7 @@ public void testKJarUpgradeSameAndDifferentSessions() throws Exception { // Create a new jar for version 1.1.0 ReleaseId releaseId2 = ks.newReleaseId( "org.kie", "test-upgrade", "1.1.0" ); - createAndDeployJar( ks, releaseId2, drl1, drl2_2 ); + createAndDeployJar(runType, ks, releaseId2, drl1, drl2_2 ); // try to update the container to version 1.1.0 kc.updateToVersion( releaseId2 ); @@ -105,8 +104,9 @@ public void testKJarUpgradeSameAndDifferentSessions() throws Exception { assertThat(ksession2.fireAllRules()).isEqualTo(2); } - @Test - public void testKJarUpgradeWithDeclaredType() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testKJarUpgradeWithDeclaredType(RUN_TYPE runType) throws Exception { String drl1 = "package org.drools.incremental\n" + "declare Message value : String end\n" + "rule Init when then insert(new Message( \"Hello World\" )); end\n" + @@ -141,10 +141,10 @@ public void testKJarUpgradeWithDeclaredType() throws Exception { ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-upgrade", "1.0.0" ); KieModuleModel kieModuleModel = ks.newKieModuleModel(); - if(this.testRunType.isAlphaNetworkCompiler()) { + if(runType.isAlphaNetworkCompiler()) { kieModuleModel.setConfigurationProperty("drools.alphaNetworkCompiler", AlphaNetworkCompilerOption.INMEMORY.toString()); } - createAndDeployJar( ks, kieModuleModel, releaseId1, drl1, drl2_1 ); + createAndDeployJar(runType, ks, kieModuleModel, releaseId1, drl1, drl2_1 ); KieContainer kc = ks.newKieContainer( releaseId1 ); @@ -154,7 +154,7 @@ public void testKJarUpgradeWithDeclaredType() throws Exception { // Create a new jar for version 1.1.0 ReleaseId releaseId2 = ks.newReleaseId( "org.kie", "test-upgrade", "1.1.0" ); - createAndDeployJar( ks, kieModuleModel, releaseId2, drl1, drl2_2 ); + createAndDeployJar(runType, ks, kieModuleModel, releaseId2, drl1, drl2_2 ); // try to update the container to version 1.1.0 kc.updateToVersion( releaseId2 ); @@ -165,7 +165,7 @@ public void testKJarUpgradeWithDeclaredType() throws Exception { // Create a new jar for version 1.2.0 ReleaseId releaseId3 = ks.newReleaseId( "org.kie", "test-upgrade", "1.2.0" ); - createAndDeployJar( ks, kieModuleModel, releaseId3, drl1, drl2_3 ); + createAndDeployJar(runType, ks, kieModuleModel, releaseId3, drl1, drl2_3 ); // try to update the container to version 1.2.0 kc.updateToVersion( releaseId3 ); @@ -178,8 +178,9 @@ public void testKJarUpgradeWithDeclaredType() throws Exception { assertThat(list.get(0)).isEqualTo("Hello World"); } - @Test - public void testKJarUpgradeWithChangedDeclaredType() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testKJarUpgradeWithChangedDeclaredType(RUN_TYPE runType) throws Exception { String drl1a = "package org.drools.incremental\n" + "declare Message value : String end\n" + "rule Init when then insert(new Message( \"Hello World\" )); end\n" + @@ -202,7 +203,7 @@ public void testKJarUpgradeWithChangedDeclaredType() throws Exception { // Create an in-memory jar for version 1.0.0 ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-upgrade", "1.0.0" ); - createAndDeployJar( ks, releaseId1, drl1a ); + createAndDeployJar(runType, ks, releaseId1, drl1a ); // Create a session and fire rules KieContainer kc = ks.newKieContainer( releaseId1 ); @@ -211,7 +212,7 @@ public void testKJarUpgradeWithChangedDeclaredType() throws Exception { // Create a new jar for version 1.1.0 ReleaseId releaseId2 = ks.newReleaseId( "org.kie", "test-upgrade", "1.1.0" ); - createAndDeployJar( ks, releaseId2, drl1b ); + createAndDeployJar(runType, ks, releaseId2, drl1b ); // try to update the container to version 1.1.0 kc.updateToVersion( releaseId2 ); @@ -224,8 +225,9 @@ public void testKJarUpgradeWithChangedDeclaredType() throws Exception { assertThat(ksession2.fireAllRules()).isEqualTo(2); } - @Test - public void testIdenticalConsequenceButImportChange() { + @ParameterizedTest + @MethodSource("parameters") + public void testIdenticalConsequenceButImportChange(RUN_TYPE runType) { final String drl1 = "package org.drools.test\n" + "import " + Person.class.getCanonicalName() + "\n" + "rule R\n" + @@ -249,7 +251,7 @@ public void testIdenticalConsequenceButImportChange() { final KieServices ks = KieServices.Factory.get(); final ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0"); - createAndDeployJar(ks, releaseId1, drl1); + createAndDeployJar(runType, ks, releaseId1, drl1); final KieContainer kc = ks.newKieContainer(releaseId1); final KieSession kieSession = kc.newKieSession(); @@ -259,7 +261,7 @@ public void testIdenticalConsequenceButImportChange() { assertThat(kieSession.fireAllRules()).isEqualTo(1); final ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "2.0.0"); - createAndDeployJar(ks, releaseId2, drl2); + createAndDeployJar(runType, ks, releaseId2, drl2); kc.updateToVersion(releaseId2); @@ -270,8 +272,9 @@ public void testIdenticalConsequenceButImportChange() { assertThat(kieSession.fireAllRules()).isEqualTo(1); } - @Test - public void testIdenticalPredicateButImportChange() { + @ParameterizedTest + @MethodSource("parameters") + public void testIdenticalPredicateButImportChange(RUN_TYPE runType) { // This test also verifies LambdaExtractor final String drl1 = "package org.drools.test\n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -296,7 +299,7 @@ public void testIdenticalPredicateButImportChange() { final KieServices ks = KieServices.Factory.get(); final ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0"); - createAndDeployJar(ks, releaseId1, drl1); + createAndDeployJar(runType, ks, releaseId1, drl1); final KieContainer kc = ks.newKieContainer(releaseId1); final KieSession kieSession = kc.newKieSession(); @@ -306,7 +309,7 @@ public void testIdenticalPredicateButImportChange() { assertThat(kieSession.fireAllRules()).isEqualTo(0); final ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "2.0.0"); - createAndDeployJar(ks, releaseId2, drl2); + createAndDeployJar(runType, ks, releaseId2, drl2); kc.updateToVersion(releaseId2); @@ -317,8 +320,9 @@ public void testIdenticalPredicateButImportChange() { assertThat(kieSession.fireAllRules()).isEqualTo(1); } - @Test - public void testKJarUpgradeWithChangedFunctionForRHSWithoutExternalizeLambda() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testKJarUpgradeWithChangedFunctionForRHSWithoutExternalizeLambda(RUN_TYPE runType) throws Exception { String drl1a = "package org.drools.incremental\n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -346,7 +350,7 @@ public void testKJarUpgradeWithChangedFunctionForRHSWithoutExternalizeLambda() t ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0"); KieModuleModel model1 = ks.newKieModuleModel(); model1.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.FALSE.toString()); - createAndDeployJar(ks, model1, releaseId1, drl1a); + createAndDeployJar(runType, ks, model1, releaseId1, drl1a); // Create a session and fire rules KieContainer kc = ks.newKieContainer(releaseId1); @@ -362,7 +366,7 @@ public void testKJarUpgradeWithChangedFunctionForRHSWithoutExternalizeLambda() t ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0"); KieModuleModel model2 = ks.newKieModuleModel(); model2.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.FALSE.toString()); - createAndDeployJar(ks, model2, releaseId2, drl1b); + createAndDeployJar(runType, ks, model2, releaseId2, drl1b); // try to update the container to version 1.1.0 kc.updateToVersion(releaseId2); @@ -382,8 +386,9 @@ public void testKJarUpgradeWithChangedFunctionForRHSWithoutExternalizeLambda() t assertThat(list2).containsExactlyInAnyOrder("Good bye George"); } - @Test - public void testKJarUpgradeWithChangedFunctionForRHSWithExternalizeLambda() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testKJarUpgradeWithChangedFunctionForRHSWithExternalizeLambda(RUN_TYPE runType) throws Exception { String drl1a = "package org.drools.incremental\n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -411,7 +416,7 @@ public void testKJarUpgradeWithChangedFunctionForRHSWithExternalizeLambda() thro ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0"); KieModuleModel model1 = ks.newKieModuleModel(); model1.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.TRUE.toString()); - createAndDeployJar(ks, model1, releaseId1, drl1a); + createAndDeployJar(runType, ks, model1, releaseId1, drl1a); // Create a session and fire rules KieContainer kc = ks.newKieContainer(releaseId1); @@ -427,7 +432,7 @@ public void testKJarUpgradeWithChangedFunctionForRHSWithExternalizeLambda() thro ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0"); KieModuleModel model2 = ks.newKieModuleModel(); model2.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.TRUE.toString()); - createAndDeployJar(ks, model2, releaseId2, drl1b); + createAndDeployJar(runType, ks, model2, releaseId2, drl1b); // try to update the container to version 1.1.0 kc.updateToVersion(releaseId2); @@ -447,8 +452,9 @@ public void testKJarUpgradeWithChangedFunctionForRHSWithExternalizeLambda() thro assertThat(list2).containsExactlyInAnyOrder("Good bye George"); } - @Test - public void testKJarUpgradeWithChangedJavaFunctionForRHSWithoutExternalizeLambda() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testKJarUpgradeWithChangedJavaFunctionForRHSWithoutExternalizeLambda(RUN_TYPE runType) throws Exception { String java1 = "package org.drools.test;\n" + "public class MyFunction {\n" + @@ -480,7 +486,7 @@ public void testKJarUpgradeWithChangedJavaFunctionForRHSWithoutExternalizeLambda ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0"); KieModuleModel model1 = ks.newKieModuleModel(); model1.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.FALSE.toString()); - createAndDeployJar(ks, model1, releaseId1, + createAndDeployJar(runType, ks, model1, releaseId1, new KieFile("src/main/java/org/drools/test/MyFunction.java", java1), new KieFile("src/main/resources/org/drools/incremental/r1.drl", drl)); @@ -498,7 +504,7 @@ public void testKJarUpgradeWithChangedJavaFunctionForRHSWithoutExternalizeLambda ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0"); KieModuleModel model2 = ks.newKieModuleModel(); model2.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.FALSE.toString()); - createAndDeployJar(ks, model2, releaseId2, + createAndDeployJar(runType, ks, model2, releaseId2, new KieFile("src/main/java/org/drools/test/MyFunction.java", java2), new KieFile("src/main/resources/org/drools/incremental/r1.drl", drl)); // try to update the container to version 1.1.0 @@ -519,8 +525,9 @@ public void testKJarUpgradeWithChangedJavaFunctionForRHSWithoutExternalizeLambda assertThat(list2).containsExactlyInAnyOrder("Good bye George"); } - @Test - public void testKJarUpgradeWithChangedJavaFunctionForRHSWithExternalizeLambda() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testKJarUpgradeWithChangedJavaFunctionForRHSWithExternalizeLambda(RUN_TYPE runType) throws Exception { String java1 = "package org.drools.test;\n" + "public class MyFunction {\n" + @@ -552,7 +559,7 @@ public void testKJarUpgradeWithChangedJavaFunctionForRHSWithExternalizeLambda() ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0"); KieModuleModel model1 = ks.newKieModuleModel(); model1.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.TRUE.toString()); - createAndDeployJar(ks, model1, releaseId1, + createAndDeployJar(runType, ks, model1, releaseId1, new KieFile("src/main/java/org/drools/test/MyFunction.java", java1), new KieFile("src/main/resources/org/drools/incremental/r1.drl", drl)); @@ -570,7 +577,7 @@ public void testKJarUpgradeWithChangedJavaFunctionForRHSWithExternalizeLambda() ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0"); KieModuleModel model2 = ks.newKieModuleModel(); model2.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.TRUE.toString()); - createAndDeployJar(ks, model2, releaseId2, + createAndDeployJar(runType, ks, model2, releaseId2, new KieFile("src/main/java/org/drools/test/MyFunction.java", java2), new KieFile("src/main/resources/org/drools/incremental/r1.drl", drl)); @@ -592,8 +599,9 @@ public void testKJarUpgradeWithChangedJavaFunctionForRHSWithExternalizeLambda() assertThat(list2).containsExactlyInAnyOrder("Good bye George"); } - @Test - public void testKJarUpgradeWithChangedFunctionForLHSWithoutExternalizeLambda() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testKJarUpgradeWithChangedFunctionForLHSWithoutExternalizeLambda(RUN_TYPE runType) throws Exception { String drl1a = "package org.drools.incremental\n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -621,7 +629,7 @@ public void testKJarUpgradeWithChangedFunctionForLHSWithoutExternalizeLambda() t ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0"); KieModuleModel model1 = ks.newKieModuleModel(); model1.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.FALSE.toString()); - createAndDeployJar(ks, model1, releaseId1, drl1a); + createAndDeployJar(runType, ks, model1, releaseId1, drl1a); // Create a session and fire rules KieContainer kc = ks.newKieContainer(releaseId1); @@ -638,7 +646,7 @@ public void testKJarUpgradeWithChangedFunctionForLHSWithoutExternalizeLambda() t ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0"); KieModuleModel model2 = ks.newKieModuleModel(); model2.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.FALSE.toString()); - createAndDeployJar(ks, model2, releaseId2, drl1b); + createAndDeployJar(runType, ks, model2, releaseId2, drl1b); // try to update the container to version 1.1.0 System.out.println("=== updateToVersion ==="); @@ -660,8 +668,9 @@ public void testKJarUpgradeWithChangedFunctionForLHSWithoutExternalizeLambda() t assertThat(list2).containsExactlyInAnyOrder("John"); } - @Test - public void testKJarUpgradeWithChangedFunctionForLHSWithExternalizeLambda() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testKJarUpgradeWithChangedFunctionForLHSWithExternalizeLambda(RUN_TYPE runType) throws Exception { String drl1a = "package org.drools.incremental\n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -689,7 +698,7 @@ public void testKJarUpgradeWithChangedFunctionForLHSWithExternalizeLambda() thro ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0"); KieModuleModel model1 = ks.newKieModuleModel(); model1.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.TRUE.toString()); - createAndDeployJar(ks, model1, releaseId1, drl1a); + createAndDeployJar(runType, ks, model1, releaseId1, drl1a); // Create a session and fire rules KieContainer kc = ks.newKieContainer(releaseId1); @@ -706,7 +715,7 @@ public void testKJarUpgradeWithChangedFunctionForLHSWithExternalizeLambda() thro ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0"); KieModuleModel model2 = ks.newKieModuleModel(); model2.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.TRUE.toString()); - createAndDeployJar(ks, model2, releaseId2, drl1b); + createAndDeployJar(runType, ks, model2, releaseId2, drl1b); // try to update the container to version 1.1.0 System.out.println("=== updateToVersion ==="); @@ -728,8 +737,9 @@ public void testKJarUpgradeWithChangedFunctionForLHSWithExternalizeLambda() thro assertThat(list2).containsExactlyInAnyOrder("John"); } - @Test - public void testKJarUpgradeWithChangedJavaFunctionForLHSWithoutExternalizeLambda() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testKJarUpgradeWithChangedJavaFunctionForLHSWithoutExternalizeLambda(RUN_TYPE runType) throws Exception { String java1 = "package org.drools.test;\n" + "public class MyFunction {\n" + @@ -763,7 +773,7 @@ public void testKJarUpgradeWithChangedJavaFunctionForLHSWithoutExternalizeLambda ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0"); KieModuleModel model1 = ks.newKieModuleModel(); model1.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.FALSE.toString()); - createAndDeployJar(ks, model1, releaseId1, + createAndDeployJar(runType, ks, model1, releaseId1, new KieFile("src/main/java/org/drools/test/MyFunction.java", java1), new KieFile("src/main/resources/org/drools/incremental/r1.drl", drl)); @@ -782,7 +792,7 @@ public void testKJarUpgradeWithChangedJavaFunctionForLHSWithoutExternalizeLambda ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0"); KieModuleModel model2 = ks.newKieModuleModel(); model2.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.FALSE.toString()); - createAndDeployJar(ks, model2, releaseId2, + createAndDeployJar(runType, ks, model2, releaseId2, new KieFile("src/main/java/org/drools/test/MyFunction.java", java2), new KieFile("src/main/resources/org/drools/incremental/r1.drl", drl)); @@ -806,8 +816,9 @@ public void testKJarUpgradeWithChangedJavaFunctionForLHSWithoutExternalizeLambda assertThat(list2).containsExactlyInAnyOrder("John"); } - @Test - public void testKJarUpgradeWithChangedJavaFunctionForLHSWithExternalizeLambda() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testKJarUpgradeWithChangedJavaFunctionForLHSWithExternalizeLambda(RUN_TYPE runType) throws Exception { String java1 = "package org.drools.test;\n" + "public class MyFunction {\n" + @@ -841,7 +852,7 @@ public void testKJarUpgradeWithChangedJavaFunctionForLHSWithExternalizeLambda() ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0"); KieModuleModel model1 = ks.newKieModuleModel(); model1.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.TRUE.toString()); - createAndDeployJar(ks, model1, releaseId1, + createAndDeployJar(runType, ks, model1, releaseId1, new KieFile("src/main/java/org/drools/test/MyFunction.java", java1), new KieFile("src/main/resources/org/drools/incremental/r1.drl", drl)); @@ -860,7 +871,7 @@ public void testKJarUpgradeWithChangedJavaFunctionForLHSWithExternalizeLambda() ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0"); KieModuleModel model2 = ks.newKieModuleModel(); model2.setConfigurationProperty("drools.externaliseCanonicalModelLambda", Boolean.TRUE.toString()); - createAndDeployJar(ks, model2, releaseId2, + createAndDeployJar(runType, ks, model2, releaseId2, new KieFile("src/main/java/org/drools/test/MyFunction.java", java2), new KieFile("src/main/resources/org/drools/incremental/r1.drl", drl)); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/IndexTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/IndexTest.java index 67b8177bd58..fb7e1e4edd3 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/IndexTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/IndexTest.java @@ -32,7 +32,8 @@ import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.util.DateUtils; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.definition.rule.Rule; import org.kie.api.runtime.KieSession; @@ -41,12 +42,9 @@ public class IndexTest extends BaseModelTest { - public IndexTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testBetaIndexOnDeclaration() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaIndexOnDeclaration(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + @@ -55,7 +53,7 @@ public void testBetaIndexOnDeclaration() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ObjectTypeNode otn = getObjectTypeNodeForClass( ksession, Person.class ); BetaNode beta = (BetaNode) otn.getObjectSinkPropagator().getSinks()[0]; @@ -68,8 +66,9 @@ public void testBetaIndexOnDeclaration() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testBetaIndexWithAccessor() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaIndexWithAccessor(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + @@ -78,7 +77,7 @@ public void testBetaIndexWithAccessor() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( "test" ); ksession.insert( new Person("Sofia", 4) ); @@ -110,8 +109,9 @@ public Integer getInteger() { } } - @Test - public void testBetaIndexWithImplicitDowncast() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaIndexWithImplicitDowncast(RUN_TYPE runType) { // DROOLS-5614 String str = "import " + ObjectWrapper.class.getCanonicalName() + ";" + @@ -122,7 +122,7 @@ public void testBetaIndexWithImplicitDowncast() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ObjectWrapper( 42 ) ); ksession.insert( new IntegerWrapper( 42 ) ); @@ -130,8 +130,9 @@ public void testBetaIndexWithImplicitDowncast() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAlphaIndexWithDateEqual() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaIndexWithDateEqual(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + @@ -147,7 +148,7 @@ public void testAlphaIndexWithDateEqual() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); assertConstraintType(ksession.getKieBase(), Person.class, "R1", ConstraintTypeOperator.EQUAL); assertConstraintType(ksession.getKieBase(), Person.class, "R2", ConstraintTypeOperator.EQUAL); @@ -160,8 +161,9 @@ public void testAlphaIndexWithDateEqual() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAlphaIndexWithDateRelation() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaIndexWithDateRelation(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + @@ -177,7 +179,7 @@ public void testAlphaIndexWithDateRelation() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); assertConstraintType(ksession.getKieBase(), Person.class, "R1", ConstraintTypeOperator.GREATER_THAN); assertConstraintType(ksession.getKieBase(), Person.class, "R2", ConstraintTypeOperator.LESS_OR_EQUAL); @@ -207,8 +209,9 @@ private void assertConstraintType(KieBase kbase, Class factClass, String rule assertThat(asserted).isTrue(); } - @Test - public void testBetaIndexOn2ValuesOnLeftTuple() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaIndexOn2ValuesOnLeftTuple(RUN_TYPE runType) { // DROOLS-5995 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -219,12 +222,12 @@ public void testBetaIndexOn2ValuesOnLeftTuple() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ObjectTypeNode otn = getObjectTypeNodeForClass( ksession, Person.class ); BetaNode beta = (BetaNode) otn.getObjectSinkPropagator().getSinks()[0]; // this beta index is only supported by executable model - assertThat(beta.getRawConstraints().isIndexed()).isEqualTo(this.testRunType.isExecutableModel()); + assertThat(beta.getRawConstraints().isIndexed()).isEqualTo(runType.isExecutableModel()); ksession.insert( 5 ); ksession.insert( "test" ); @@ -233,8 +236,9 @@ public void testBetaIndexOn2ValuesOnLeftTuple() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNoBetaIndexWithThisPropertyOnRight() { + @ParameterizedTest + @MethodSource("parameters") + public void testNoBetaIndexWithThisPropertyOnRight(RUN_TYPE runType) { // DROOLS-5995 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -245,7 +249,7 @@ public void testNoBetaIndexWithThisPropertyOnRight() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( 5 ); ksession.insert( "test" ); @@ -254,8 +258,9 @@ public void testNoBetaIndexWithThisPropertyOnRight() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNoBetaIndexWithThisOperationOnLeft() { + @ParameterizedTest + @MethodSource("parameters") + public void testNoBetaIndexWithThisOperationOnLeft(RUN_TYPE runType) { // DROOLS-5995 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -266,7 +271,7 @@ public void testNoBetaIndexWithThisOperationOnLeft() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( 5 ); ksession.insert( "test" ); @@ -275,8 +280,9 @@ public void testNoBetaIndexWithThisOperationOnLeft() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNoBetaIndexWithThisOperationOnLeft2() { + @ParameterizedTest + @MethodSource("parameters") + public void testNoBetaIndexWithThisOperationOnLeft2(RUN_TYPE runType) { // DROOLS-5995 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -287,7 +293,7 @@ public void testNoBetaIndexWithThisOperationOnLeft2() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( 5 ); ksession.insert( "test" ); @@ -296,8 +302,9 @@ public void testNoBetaIndexWithThisOperationOnLeft2() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNoBetaIndexWithThisMethodInvocationOnLeft() { + @ParameterizedTest + @MethodSource("parameters") + public void testNoBetaIndexWithThisMethodInvocationOnLeft(RUN_TYPE runType) { // DROOLS-5995 String str = "import " + List.class.getCanonicalName() + ";" + @@ -307,12 +314,13 @@ public void testNoBetaIndexWithThisMethodInvocationOnLeft() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testBetaIndexOn3ValuesOnLeftTuple() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaIndexOn3ValuesOnLeftTuple(RUN_TYPE runType) { // DROOLS-5995 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -324,12 +332,12 @@ public void testBetaIndexOn3ValuesOnLeftTuple() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ObjectTypeNode otn = getObjectTypeNodeForClass( ksession, Person.class ); BetaNode beta = (BetaNode) otn.getObjectSinkPropagator().getSinks()[0]; // this beta index is only supported by executable model - assertThat(beta.getRawConstraints().isIndexed()).isEqualTo(this.testRunType.isExecutableModel()); + assertThat(beta.getRawConstraints().isIndexed()).isEqualTo(runType.isExecutableModel()); ksession.insert( 2L ); ksession.insert( 3 ); @@ -339,8 +347,9 @@ public void testBetaIndexOn3ValuesOnLeftTuple() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testBetaIndexOn4ValuesOnLeftTuple() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaIndexOn4ValuesOnLeftTuple(RUN_TYPE runType) { // DROOLS-5995 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -353,12 +362,12 @@ public void testBetaIndexOn4ValuesOnLeftTuple() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ObjectTypeNode otn = getObjectTypeNodeForClass( ksession, Person.class ); BetaNode beta = (BetaNode) otn.getObjectSinkPropagator().getSinks()[0]; // this beta index is only supported by executable model - assertThat(beta.getRawConstraints().isIndexed()).isEqualTo(this.testRunType.isExecutableModel()); + assertThat(beta.getRawConstraints().isIndexed()).isEqualTo(runType.isExecutableModel()); ksession.insert( (short)1 ); ksession.insert( 1L ); @@ -369,8 +378,9 @@ public void testBetaIndexOn4ValuesOnLeftTuple() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAlphaIndexHashed() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaIndexHashed(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + @@ -386,13 +396,14 @@ public void testAlphaIndexHashed() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); assertHashIndex(ksession, Person.class, 3); } - @Test - public void testAlphaIndexHashedNonGetter() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaIndexHashedNonGetter(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + @@ -408,7 +419,7 @@ public void testAlphaIndexHashedNonGetter() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); assertHashIndex(ksession, Person.class, 3); } @@ -422,8 +433,9 @@ private void assertHashIndex(KieSession ksession, Class factClass, int expect assertThat(compositeObjectSinkAdapter.getHashedSinkMap().size()).isEqualTo(expectedHashedSinkMapSize); } - @Test - public void testAlphaIndexHashedPrimitiveWrapper() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaIndexHashedPrimitiveWrapper(RUN_TYPE runType) { String str = "import " + Integer.class.getCanonicalName() + ";\n" + "rule R1 when\n" + @@ -439,13 +451,14 @@ public void testAlphaIndexHashedPrimitiveWrapper() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); assertHashIndex(ksession, Integer.class, 3); } - @Test - public void testAlphaIndexHashedNumberInterface() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaIndexHashedNumberInterface(RUN_TYPE runType) { String str = "import " + Integer.class.getCanonicalName() + ";\n" + "rule R1 when\n" + @@ -461,7 +474,7 @@ public void testAlphaIndexHashedNumberInterface() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); assertHashIndex(ksession, Number.class, 3); @@ -470,8 +483,9 @@ public void testAlphaIndexHashedNumberInterface() { assertThat(fired).isEqualTo(1); } - @Test - public void testAlphaIndexWithDeclarationInPattern() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaIndexWithDeclarationInPattern(RUN_TYPE runType) { final String str = "package org.drools.mvel.compiler\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -481,7 +495,7 @@ public void testAlphaIndexWithDeclarationInPattern() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ObjectTypeNode otn = getObjectTypeNodeForClass(ksession, Person.class); ObjectSink sink = otn.getObjectSinkPropagator().getSinks()[0]; @@ -494,8 +508,9 @@ public void testAlphaIndexWithDeclarationInPattern() { assertThat(fired).isEqualTo(1); } - @Test - public void testAlphaIndexWithDeclarationInPatternWithSameNameProp() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaIndexWithDeclarationInPatternWithSameNameProp(RUN_TYPE runType) { final String str = "package org.drools.mvel.compiler\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -506,7 +521,7 @@ public void testAlphaIndexWithDeclarationInPatternWithSameNameProp() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ObjectTypeNode otn = getObjectTypeNodeForClass(ksession, Person.class); ObjectSink sink = otn.getObjectSinkPropagator().getSinks()[0]; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/InternalMatchGroupTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/InternalMatchGroupTest.java index 01e88262e71..defa110bc45 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/InternalMatchGroupTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/InternalMatchGroupTest.java @@ -22,7 +22,8 @@ import java.util.List; import org.drools.commands.runtime.rule.ClearActivationGroupCommand; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieServices; import org.kie.api.command.BatchExecutionCommand; import org.kie.api.command.Command; @@ -39,12 +40,10 @@ public class InternalMatchGroupTest extends OnlyPatternTest { private static final String KIE_SESSION = "ksession1"; private static final String ACTIVATION_GROUP = "first-group"; - public InternalMatchGroupTest(RUN_TYPE testRunType) { - super(testRunType); - } - @Test - public void testClearActivationGroup() { + @ParameterizedTest + @MethodSource("parameters") + public void testClearActivationGroup(RUN_TYPE runType) { // DROOLS-5685 ClearActivationGroup command changed its behaviour String str = "import java.util.List;\n" + "\n" + @@ -75,7 +74,7 @@ public void testClearActivationGroup() { List> commands = new ArrayList>(); - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); KieCommands commandsFactory = KieServices.get().getCommands(); BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands, KIE_SESSION); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/KieBaseBuilderTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/KieBaseBuilderTest.java index eaea5f9930b..fe231cdac2a 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/KieBaseBuilderTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/KieBaseBuilderTest.java @@ -22,14 +22,15 @@ import java.util.List; import java.util.UUID; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.drools.compiler.compiler.io.memory.MemoryFileSystem; import org.drools.compiler.kie.builder.impl.KieBuilderImpl; import org.drools.model.Model; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.modelcompiler.KieBaseBuilder; -import org.junit.Test; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.KieBaseConfiguration; import org.kie.api.KieServices; @@ -46,17 +47,13 @@ public class KieBaseBuilderTest extends BaseModelTest { // Only exec-model test - @Parameters(name = "{0}") - public static Object[] params() { - return new Object[]{RUN_TYPE.PATTERN_DSL}; + public static Stream parameters() { + return Stream.of(RUN_TYPE.PATTERN_DSL); } - public KieBaseBuilderTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Test - public void createKieBaseWithKnowledgeBuilderConfiguration() { + @ParameterizedTest + @MethodSource("parameters") + public void createKieBaseWithKnowledgeBuilderConfiguration(RUN_TYPE runType) { // DROOLS-7239 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -73,7 +70,7 @@ public void createKieBaseWithKnowledgeBuilderConfiguration() { ReleaseId releaseId = ks.newReleaseId("org.kie", "kjar-test-" + UUID.randomUUID(), "1.0"); KieModuleModel model = ks.newKieModuleModel(); model.setConfigurationProperty(option.getPropertyName(), option.name()); - KieBuilder kieBuilder = createKieBuilder(ks, model, releaseId, toKieFiles(new String[]{str})); + KieBuilder kieBuilder = createKieBuilder(runType, ks, model, releaseId, toKieFiles(new String[]{str})); // 2nd round: Create a kbase with generated classes and PropertySpecificOption.DISABLED KnowledgeBuilderConfiguration knowledgeBuilderConf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/KieBuilderTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/KieBuilderTest.java index 6d766f53f52..e36dd7e6db9 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/KieBuilderTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/KieBuilderTest.java @@ -26,7 +26,7 @@ import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.model.codegen.ExecutableModelProject; import org.drools.modelcompiler.constraints.LambdaConstraint; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.KieFileSystem; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/KjarBuildTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/KjarBuildTest.java index 4d663ec33ff..49baf35bde9 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/KjarBuildTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/KjarBuildTest.java @@ -19,7 +19,7 @@ package org.drools.model.codegen.execmodel; import org.drools.model.codegen.ExecutableModelProject; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.KieFileSystem; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ListenersTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ListenersTest.java index 3c893c3deb9..6d87f35295c 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ListenersTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ListenersTest.java @@ -21,7 +21,8 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.event.rule.ObjectDeletedEvent; import org.kie.api.event.rule.ObjectInsertedEvent; import org.kie.api.event.rule.ObjectUpdatedEvent; @@ -32,12 +33,9 @@ public class ListenersTest extends BaseModelTest { - public ListenersTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testInsert() { + @ParameterizedTest + @MethodSource("parameters") + public void testInsert(RUN_TYPE runType) { String str = "rule R\n" + "when\n" + @@ -46,7 +44,7 @@ public void testInsert() { " insert(\"\" + $i);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MapInitializationDrools3800Test.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MapInitializationDrools3800Test.java index d760d2fd8b0..672dc20e7cf 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MapInitializationDrools3800Test.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MapInitializationDrools3800Test.java @@ -21,17 +21,14 @@ import java.util.Map; import java.util.Objects; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class MapInitializationDrools3800Test extends BaseModelTest { - public MapInitializationDrools3800Test(BaseModelTest.RUN_TYPE testRunType) { - super(testRunType); - } - public static boolean calc(Map params) { return Objects.equals(params.get("src"), params.get("target")); } @@ -57,8 +54,9 @@ public void setResult(String result) { } } - @Test - public void testMapInitialization() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapInitialization(RUN_TYPE runType) { StringBuilder r = new StringBuilder(); r.append("package ").append(getClass().getPackage().getName()).append("\n"); r.append("\n"); @@ -76,7 +74,7 @@ public void testMapInitialization() { r.append(" }").append("\n"); r.append("end").append("\n"); - KieSession ksession = getKieSession(r.toString() ); + KieSession ksession = getKieSession(runType, r.toString()); Fact fact = new Fact(); @@ -88,8 +86,9 @@ public void testMapInitialization() { assertThat(fact.getResult()).isEqualTo("OK"); } - @Test - public void testPropertyReactivityHanging() { + @ParameterizedTest + @MethodSource("parameters") + public void testPropertyReactivityHanging(RUN_TYPE runType) { // DROOLS-3849 String rule = "package " + getClass().getPackage().getName() + "\n" + @@ -107,7 +106,7 @@ public void testPropertyReactivityHanging() { " }\n" + "end"; - KieSession ksession = getKieSession(rule); + KieSession ksession = getKieSession(runType, rule); Fact fact = new Fact(); fact.setName("TEST"); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MaterializedLambdaTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MaterializedLambdaTest.java index eb807e427e5..eb756552f5a 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MaterializedLambdaTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MaterializedLambdaTest.java @@ -22,19 +22,17 @@ import java.util.Date; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class MaterializedLambdaTest extends BaseModelTest { - public MaterializedLambdaTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Test - public void testMaterializeLambda() { + @ParameterizedTest + @MethodSource("parameters") + public void testMaterializeLambda(RUN_TYPE runType) { String str = "import " + DataType.class.getCanonicalName() + ";\n" + @@ -57,7 +55,7 @@ public void testMaterializeLambda() { " result.setValue(0);\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); DataType st = new DataType("FF", "BBB"); DataType st2 = new DataType("FF", "CCC"); @@ -81,8 +79,9 @@ public static void execute(Runnable r) { } // DROOLS-4858 - @Test - public void testMaterializeLambdaWithNested() { + @ParameterizedTest + @MethodSource("parameters") + public void testMaterializeLambdaWithNested(RUN_TYPE runType) { String str = "import " + Executor.class.getCanonicalName() + ";\n" + "import " + Result.class.getCanonicalName() + ";\n" + @@ -97,7 +96,7 @@ public void testMaterializeLambdaWithNested() { " });" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(42); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ModelBuilderImplTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ModelBuilderImplTest.java index 76adb83215a..90d4bb047e4 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ModelBuilderImplTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ModelBuilderImplTest.java @@ -24,8 +24,8 @@ import org.drools.core.reteoo.CoreComponentFactory; import org.drools.drl.ast.descr.GlobalDescr; import org.drools.drl.ast.descr.PackageDescr; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.kie.api.builder.ReleaseId; import org.kie.internal.builder.KnowledgeBuilderFactory; import org.kie.util.maven.support.ReleaseIdImpl; @@ -42,7 +42,7 @@ public class ModelBuilderImplTest { private PackageRegistry packageRegistry; private ModelBuilderImpl modelBuilder; - @Before + @BeforeEach public void setup() { internalKnowledgePackage = CoreComponentFactory.get().createKnowledgePackage("apackage"); modelBuilder = new ModelBuilderImpl<>(PackageSources::dumpSources, CONFIGURATION, RELEASE_ID, false); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ModelSourceClassTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ModelSourceClassTest.java index 82189b9a4ce..e3438136f67 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ModelSourceClassTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ModelSourceClassTest.java @@ -24,15 +24,15 @@ import java.util.Map; import org.drools.compiler.kproject.models.KieBaseModelImpl; - -import static org.assertj.core.api.Assertions.assertThat; import org.drools.compiler.kproject.models.KieModuleModelImpl; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.builder.ReleaseId; import org.kie.api.builder.model.KieBaseModel; import org.kie.api.builder.model.KieModuleModel; import org.kie.util.maven.support.ReleaseIdImpl; +import static org.assertj.core.api.Assertions.assertThat; + public class ModelSourceClassTest { diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MultiKieBaseTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MultiKieBaseTest.java index a59086ab697..4f02e0c197f 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MultiKieBaseTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MultiKieBaseTest.java @@ -18,7 +18,6 @@ */ package org.drools.model.codegen.execmodel; -import org.junit.Test; import org.kie.api.KieServices; import org.kie.api.builder.ReleaseId; import org.kie.api.builder.model.KieModuleModel; @@ -27,14 +26,14 @@ import static org.assertj.core.api.Assertions.assertThat; -public class MultiKieBaseTest extends BaseModelTest { +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; - public MultiKieBaseTest( RUN_TYPE testRunType ) { - super( testRunType ); - } +public class MultiKieBaseTest extends BaseModelTest { - @Test - public void testHelloWorldWithPackagesAnd2KieBases() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testHelloWorldWithPackagesAnd2KieBases(RUN_TYPE runType) throws Exception { String drl1a = "package org.pkg1\n" + "rule R1 when\n" + " $m : String( this == \"Hello World\" )\n" + @@ -69,7 +68,7 @@ public void testHelloWorldWithPackagesAnd2KieBases() throws Exception { // Create an in-memory jar for version 1.0.0 ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-upgrade", "1.0.0" ); - createAndDeployJar( ks, createKieProjectWithPackagesAnd2KieBases(), releaseId1, + createAndDeployJar(runType, ks, createKieProjectWithPackagesAnd2KieBases(), releaseId1, new KieFile( "src/main/resources/org/pkg1/r1.drl", drl1a ), new KieFile( "src/main/resources/org/pkg2/r2.drl", drl2a ) ); @@ -97,7 +96,7 @@ public void testHelloWorldWithPackagesAnd2KieBases() throws Exception { assertThat(ksession2.fireAllRules()).isEqualTo(1); ReleaseId releaseId2 = ks.newReleaseId( "org.kie", "test-upgrade", "1.1.0" ); - createAndDeployJar( ks, createKieProjectWithPackagesAnd2KieBases(), releaseId2, + createAndDeployJar(runType, ks, createKieProjectWithPackagesAnd2KieBases(), releaseId2, new KieFile( "src/main/resources/org/pkg1/r1.drl", drl1a ), new KieFile( "src/main/resources/org/pkg2/r2.drl", drl2b ) ); @@ -122,8 +121,9 @@ private KieModuleModel createKieProjectWithPackagesAnd2KieBases() { return kproj; } - @Test - public void testFoldersVsPackages() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testFoldersVsPackages(RUN_TYPE runType) throws Exception { String drl1 = "//package org.commented1\n" + "package org.pkg1\n" + @@ -166,7 +166,7 @@ public void testFoldersVsPackages() throws Exception { .newKieSessionModel("KSession4"); ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-pkgs", "1.0.0" ); - createAndDeployJar( ks, kproj, releaseId1, + createAndDeployJar(runType, ks, kproj, releaseId1, new KieFile( "src/main/resources/org/pkg1/r1.drl", drl1 ), new KieFile( "src/main/resources/rules/r2.drl", drl2 ) ); @@ -190,8 +190,9 @@ public void testFoldersVsPackages() throws Exception { assertThat(ks4.fireAllRules()).isEqualTo(0); // there is no "rules" package and folder is not relevant } - @Test - public void testDotInKieBaseName() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testDotInKieBaseName(RUN_TYPE runType) throws Exception { // DROOLS-5845 String drl1 = "package org.pkg1\n" + @@ -209,7 +210,7 @@ public void testDotInKieBaseName() throws Exception { .newKieSessionModel("Kie.Session"); ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-dor", "1.0.0" ); - createAndDeployJar( ks, kproj, releaseId1, + createAndDeployJar(runType, ks, kproj, releaseId1, new KieFile( "src/main/resources/org/pkg1/r1.drl", drl1 ) ); // Create a session and fire rules @@ -220,8 +221,9 @@ public void testDotInKieBaseName() throws Exception { assertThat(ks2.fireAllRules()).isEqualTo(1); // only rule in org.pkg1 should fire } - @Test - public void testHelloMultiKieBasesWithSharedDeclaredType() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testHelloMultiKieBasesWithSharedDeclaredType(RUN_TYPE runType) throws Exception { // DROOLS-6331 String drlType = "package org.pkg.type\n" + @@ -270,7 +272,7 @@ public void testHelloMultiKieBasesWithSharedDeclaredType() throws Exception { // Create an in-memory jar for version 1.0.0 ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-types", "1.0.0" ); - createAndDeployJar( ks, kproj, releaseId1, + createAndDeployJar(runType, ks, kproj, releaseId1, new KieFile( "src/main/resources/org/pkg/type/r0.drl", drlType ), new KieFile( "src/main/resources/org/pkg1/r1.drl", drl1 ), new KieFile( "src/main/resources/org/pkg2/r2.drl", drl2 ), diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MvelDialectMapTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MvelDialectMapTest.java index b96dce0a1a4..fdcb919b12a 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MvelDialectMapTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MvelDialectMapTest.java @@ -22,20 +22,17 @@ import java.util.List; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class MvelDialectMapTest extends BaseModelTest { - public MvelDialectMapTest(RUN_TYPE testRunType ) { - super( testRunType ); - } - - - @Test - public void testMapAccessorWithBind() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapAccessorWithBind(RUN_TYPE runType) { final String drl = "" + "import java.util.*;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -51,7 +48,7 @@ public void testMapAccessorWithBind() { " results.add($i.length());" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -67,8 +64,9 @@ public void testMapAccessorWithBind() { assertThat(results).containsExactly(5); // item1.length() } - @Test - public void testMapAccessorWithBindFieldAccessor() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapAccessorWithBindFieldAccessor(RUN_TYPE runType) { final String drl = "" + "import java.util.*;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -84,7 +82,7 @@ public void testMapAccessorWithBindFieldAccessor() { " results.add($childName.length());" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); List results = new ArrayList<>(); ksession.setGlobal("results", results); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MvelDialectTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MvelDialectTest.java index 087dece997d..90308ac94a0 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MvelDialectTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MvelDialectTest.java @@ -36,7 +36,8 @@ import org.drools.model.codegen.execmodel.domain.InternationalAddress; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.ValueHolder; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.builder.Message; import org.kie.api.builder.Results; import org.kie.api.definition.rule.Rule; @@ -51,12 +52,9 @@ public class MvelDialectTest extends BaseModelTest { - public MvelDialectTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testMVELinsert() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVELinsert(RUN_TYPE runType) { String str = "rule R\n" + "dialect \"mvel\"\n" + "when\n" + @@ -66,7 +64,7 @@ public void testMVELinsert() { " insert(\"Hello World\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); FactHandle fh_47 = ksession.insert(47); ksession.fireAllRules(); @@ -75,8 +73,9 @@ public void testMVELinsert() { assertThat(results.contains("Hello World")).isTrue(); } - @Test - public void testMVELMapSyntax() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVELMapSyntax(RUN_TYPE runType) { final String drl = "" + "import java.util.*;\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -102,7 +101,7 @@ public void testMVELMapSyntax() { " update(m);\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); Person p = new Person("Luca"); @@ -115,8 +114,9 @@ public void testMVELMapSyntax() { assertThat(itemsString.keySet().size()).isEqualTo(4); } - @Test - public void testMVELmodify() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVELmodify(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "rule R\n" + "dialect \"mvel\"\n" + @@ -126,7 +126,7 @@ public void testMVELmodify() { " modify($p) { setAge(1); }\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Matteo", 47)); ksession.fireAllRules(); @@ -136,8 +136,9 @@ public void testMVELmodify() { results.forEach(System.out::println); } - @Test - public void testMVELmultiple() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVELmultiple(RUN_TYPE runType) { String str = "package mypackage;" + "dialect \"mvel\"\n" + // MVEL dialect defined at package level. "import " + Person.class.getCanonicalName() + ";\n" + @@ -164,7 +165,7 @@ public void testMVELmultiple() { " retract($s)" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); FactHandle fh_47 = ksession.insert(47); ksession.fireAllRules(); @@ -175,8 +176,9 @@ public void testMVELmultiple() { assertThat(results.contains("Modified person age to 1 for: Matteo")).isTrue(); } - @Test - public void testMVELmultipleStatements() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVELmultipleStatements(RUN_TYPE runType) { String str = "import " + Person.class.getPackage().getName() + ".*;\n" + // keep the package.* in order for Address to be resolvable in the RHS. "rule R\n" + @@ -188,7 +190,7 @@ public void testMVELmultipleStatements() { " insert(a);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Matteo", 47)); ksession.fireAllRules(); @@ -208,8 +210,9 @@ public static class TempDecl8 {} public static class TempDecl9 {} public static class TempDecl10 {} - @Test - public void testMVEL10declarations() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVEL10declarations(RUN_TYPE runType) { String str = "\n" + "import " + TempDecl1.class.getCanonicalName() + ";\n" + "import " + TempDecl2.class.getCanonicalName() + ";\n" + @@ -238,7 +241,7 @@ public void testMVEL10declarations() { " insert(\"matched\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new TempDecl1()); ksession.insert(new TempDecl2()); @@ -256,8 +259,9 @@ public void testMVEL10declarations() { assertThat(results.size()).isEqualTo(1); } - @Test - public void testMVEL10declarationsBis() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVEL10declarationsBis(RUN_TYPE runType) { String str = "\n" + "import " + TempDecl1.class.getCanonicalName() + ";\n" + "import " + TempDecl2.class.getCanonicalName() + ";\n" + @@ -301,7 +305,7 @@ public void testMVEL10declarationsBis() { " insert(\"matched\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.fireAllRules(); @@ -309,8 +313,9 @@ public void testMVEL10declarationsBis() { assertThat(results.size()).isEqualTo(1); } - @Test - public void testMvelFunctionWithClassArg() { + @ParameterizedTest + @MethodSource("parameters") + public void testMvelFunctionWithClassArg(RUN_TYPE runType) { final String drl = "package org.drools.compiler.integrationtests.drl; \n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -333,7 +338,7 @@ public void testMvelFunctionWithClassArg() { " value.append( getFieldValue($bean) ); \n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); try { final StringBuilder sb = new StringBuilder(); @@ -346,8 +351,9 @@ public void testMvelFunctionWithClassArg() { } } - @Test - public void testMvelFunctionWithDeclaredTypeArg() { + @ParameterizedTest + @MethodSource("parameters") + public void testMvelFunctionWithDeclaredTypeArg(RUN_TYPE runType) { final String drl = "package org.drools.compiler.integrationtests.drl; \n" + "dialect \"mvel\"\n" + @@ -372,7 +378,7 @@ public void testMvelFunctionWithDeclaredTypeArg() { " value.append( getFieldValue($bean) ); \n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); try { final StringBuilder sb = new StringBuilder(); @@ -385,8 +391,9 @@ public void testMvelFunctionWithDeclaredTypeArg() { } } - @Test - public void testMultiDrlWithSamePackageMvel() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testMultiDrlWithSamePackageMvel(RUN_TYPE runType) throws Exception { // DROOLS-3508 String drl1 = "package org.pkg\n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -402,7 +409,7 @@ public void testMultiDrlWithSamePackageMvel() throws Exception { " update($p);\n" + "end\n"; - KieSession ksession = getKieSession(drl1, drl2); + KieSession ksession = getKieSession(runType, drl1, drl2); Person john = new Person("John", 24); ksession.insert(john); @@ -410,8 +417,9 @@ public void testMultiDrlWithSamePackageMvel() throws Exception { assertThat(john.getAge()).isEqualTo(1); } - @Test - public void testMVELNonExistingMethod() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVELNonExistingMethod(RUN_TYPE runType) { // DROOLS-3559 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -423,12 +431,13 @@ public void testMVELNonExistingMethod() { " modify($p) {likes = nonExistingMethod()};\n" + "end"; - Results results = createKieBuilder( drl ).getResults(); + Results results = createKieBuilder(runType, drl).getResults(); assertThat(results.getMessages(Message.Level.ERROR).isEmpty()).isFalse(); } - @Test - public void testBinaryOperationOnBigDecimal() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testBinaryOperationOnBigDecimal(RUN_TYPE runType) throws Exception { // RHDM-1421 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -440,7 +449,7 @@ public void testBinaryOperationOnBigDecimal() throws Exception { " $p.money = $p.money + 50000;\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); Person john = new Person("John", 30); john.setMoney( new BigDecimal( 70000 ) ); @@ -450,8 +459,9 @@ public void testBinaryOperationOnBigDecimal() throws Exception { assertThat(john.getMoney()).isEqualTo(new BigDecimal( 120000 )); } - @Test - public void testAdditionMultiplication() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testAdditionMultiplication(RUN_TYPE runType) throws Exception { // DROOLS-6089 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -466,7 +476,7 @@ public void testAdditionMultiplication() throws Exception { " $p.money = $p.money + (bd1.multiply(bd2));" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); Person john = new Person("John", 30); john.setMoney( new BigDecimal( 70000 ) ); @@ -476,8 +486,9 @@ public void testAdditionMultiplication() throws Exception { assertThat(john.getMoney()).isEqualTo(new BigDecimal( 70200 )); } - @Test - public void testBigDecimalModuloConsequence() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalModuloConsequence(RUN_TYPE runType) { // DROOLS-5959 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -493,7 +504,7 @@ public void testBigDecimalModuloConsequence() { " results.add(moduloPromotedToBigDecimal);\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -507,8 +518,9 @@ public void testBigDecimalModuloConsequence() { assertThat(results).containsExactly(valueOf(1), valueOf(2)); } - @Test - public void testBigDecimalModulo() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalModulo(RUN_TYPE runType) { // DROOLS-5959 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -521,7 +533,7 @@ public void testBigDecimalModulo() { " results.add($m);\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -539,8 +551,9 @@ public void testBigDecimalModulo() { assertThat(results.iterator().next()).isEqualTo(new BigDecimal( 70000 )); } - @Test - public void testBigDecimalModuloBetweenFields() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalModuloBetweenFields(RUN_TYPE runType) { // DROOLS-5959 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -553,7 +566,7 @@ public void testBigDecimalModuloBetweenFields() { " results.add($m);\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -571,8 +584,9 @@ public void testBigDecimalModuloBetweenFields() { assertThat(results.iterator().next()).isEqualTo(new BigDecimal( 80 )); } - @Test - public void testBigDecimalPatternWithString() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalPatternWithString(RUN_TYPE runType) { // DROOLS-6356 // DROOLS-6361 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -593,7 +607,7 @@ public void testBigDecimalPatternWithString() { " $p.name = 144B;\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -612,8 +626,9 @@ public void testBigDecimalPatternWithString() { assertThat(results.iterator().next().getName()).isEqualTo("144"); } - @Test - public void testBigDecimalAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalAccumulate(RUN_TYPE runType) { // DROOLS-6366 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -628,7 +643,7 @@ public void testBigDecimalAccumulate() { " results.add($john);\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -646,8 +661,9 @@ public void testBigDecimalAccumulate() { assertThat(results).containsExactly(john); } - @Test - public void testBigDecimalAccumulateWithFrom() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalAccumulateWithFrom(RUN_TYPE runType) { // DROOLS-6366 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -662,7 +678,7 @@ public void testBigDecimalAccumulateWithFrom() { " results.add($john);\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -680,8 +696,9 @@ public void testBigDecimalAccumulateWithFrom() { assertThat(results).containsExactly(john); } - @Test - public void testCompoundOperatorBigDecimalConstant() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testCompoundOperatorBigDecimalConstant(RUN_TYPE runType) throws Exception { // DROOLS-5894 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -700,7 +717,7 @@ public void testCompoundOperatorBigDecimalConstant() throws Exception { " $p.money = result;" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); Person john = new Person("John", 30); john.setMoney( new BigDecimal( 70000 ) ); @@ -710,8 +727,9 @@ public void testCompoundOperatorBigDecimalConstant() throws Exception { assertThat(john.getMoney()).isEqualTo(new BigDecimal( 400000 )); } - @Test - public void testCompoundOperatorBigDecimalConstantWithoutLiterals() { + @ParameterizedTest + @MethodSource("parameters") + public void testCompoundOperatorBigDecimalConstantWithoutLiterals(RUN_TYPE runType) { // DROOLS-5894 // DROOLS-5901 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -738,7 +756,7 @@ public void testCompoundOperatorBigDecimalConstantWithoutLiterals() { " $p.money = result;" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); Person john = new Person("John", 30); john.setMoney( new BigDecimal( 70000 ) ); @@ -748,8 +766,9 @@ public void testCompoundOperatorBigDecimalConstantWithoutLiterals() { assertThat(john.getMoney()).isEqualTo(new BigDecimal( 0 )); } - @Test - public void testArithmeticOperationsOnBigDecimal() { + @ParameterizedTest + @MethodSource("parameters") + public void testArithmeticOperationsOnBigDecimal(RUN_TYPE runType) { String drl = "import " + Person.class.getCanonicalName() + "\n" + "import " + BigDecimal.class.getCanonicalName() + "\n" + @@ -762,7 +781,7 @@ public void testArithmeticOperationsOnBigDecimal() { " $p.money = operation;\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); Person john = new Person("John", 30); john.setMoney( new BigDecimal( 70000 ) ); @@ -773,8 +792,9 @@ public void testArithmeticOperationsOnBigDecimal() { assertThat(john.getMoney()).isEqualTo(new BigDecimal( 7002 )); } - @Test - public void testCompoundOperatorOnfield() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testCompoundOperatorOnfield(RUN_TYPE runType) throws Exception { // DROOLS-5895 String drl = @@ -787,7 +807,7 @@ public void testCompoundOperatorOnfield() throws Exception { " $p.money += $p.money;\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); Person john = new Person("John", 30); john.setMoney( new BigDecimal( 70000 ) ); @@ -797,8 +817,9 @@ public void testCompoundOperatorOnfield() throws Exception { assertThat(john.getMoney()).isEqualTo(new BigDecimal( 140000 )); } - @Test - public void testModifyOnBigDecimal() { + @ParameterizedTest + @MethodSource("parameters") + public void testModifyOnBigDecimal(RUN_TYPE runType) { // DROOLS-5889 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -815,7 +836,7 @@ public void testModifyOnBigDecimal() { " list.add(\"after \" + $p + \", money = \" + $p.money);" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); ArrayList logMessages = new ArrayList<>(); ksession.setGlobal("list", logMessages); @@ -831,8 +852,9 @@ public void testModifyOnBigDecimal() { "after John, money = 30000"); } - @Test - public void testModifyOnBigDecimalWithLiteral() { + @ParameterizedTest + @MethodSource("parameters") + public void testModifyOnBigDecimalWithLiteral(RUN_TYPE runType) { // DROOLS-5891 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -846,7 +868,7 @@ public void testModifyOnBigDecimalWithLiteral() { " } " + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); Person john = new Person("John", 30); john.setMoney( new BigDecimal( 70000 ) ); @@ -860,8 +882,9 @@ public void testModifyOnBigDecimalWithLiteral() { assertThat(leonardo.getMoney()).isEqualTo(new BigDecimal( 500 )); } - @Test - public void testBinaryOperationOnInteger() { + @ParameterizedTest + @MethodSource("parameters") + public void testBinaryOperationOnInteger(RUN_TYPE runType) { // RHDM-1421 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -873,7 +896,7 @@ public void testBinaryOperationOnInteger() { " $p.salary = $p.salary + 50000;\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); Person john = new Person("John", 30); john.setSalary( 70000 ); @@ -883,8 +906,9 @@ public void testBinaryOperationOnInteger() { assertThat((int) john.getSalary()).isEqualTo(120000); } - @Test - public void testSetOnInteger() { + @ParameterizedTest + @MethodSource("parameters") + public void testSetOnInteger(RUN_TYPE runType) { // RHDM-1421 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -896,7 +920,7 @@ public void testSetOnInteger() { " $p.salary = 50000;\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); Person john = new Person("John", 30); john.setSalary( 70000 ); @@ -906,8 +930,9 @@ public void testSetOnInteger() { assertThat((int) john.getSalary()).isEqualTo(50000); } - @Test - public void testCollectSubtypeInConsequence() { + @ParameterizedTest + @MethodSource("parameters") + public void testCollectSubtypeInConsequence(RUN_TYPE runType) { // DROOLS-5887 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -923,7 +948,7 @@ public void testCollectSubtypeInConsequence() { " }\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); List names = new ArrayList<>(); ksession.setGlobal("names", names); @@ -938,8 +963,9 @@ public void testCollectSubtypeInConsequence() { assertThat(names).containsExactlyInAnyOrder("Mario", "Luca", "Leonardo"); } - @Test - public void testCollectSubtypeInConsequenceNested() { + @ParameterizedTest + @MethodSource("parameters") + public void testCollectSubtypeInConsequenceNested(RUN_TYPE runType) { // DROOLS-5887 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -961,7 +987,7 @@ public void testCollectSubtypeInConsequenceNested() { " }\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); List names = new ArrayList<>(); ksession.setGlobal("names", names); @@ -984,8 +1010,9 @@ public void testCollectSubtypeInConsequenceNested() { assertThat(addresses).contains("Milan"); } - @Test - public void testSetOnMvel() { + @ParameterizedTest + @MethodSource("parameters") + public void testSetOnMvel(RUN_TYPE runType) { // RHDM-1550 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -998,7 +1025,7 @@ public void testSetOnMvel() { ");\n" + "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); Person mario = new Person(); ksession.insert( mario ); @@ -1008,8 +1035,9 @@ public void testSetOnMvel() { assertThat(mario.getAge()).isEqualTo(46); } - @Test - public void testCompoundOperator() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testCompoundOperator(RUN_TYPE runType) throws Exception { // DROOLS-5894 // DROOLS-5901 // DROOLS-5897 String drl = "import " + Person.class.getCanonicalName() + "\n" + @@ -1040,7 +1068,7 @@ public void testCompoundOperator() throws Exception { " $p.money -= intVar;\n" + // 0 "end"; - KieSession ksession = getKieSession(drl); + KieSession ksession = getKieSession(runType, drl); Person john = new Person("John", 30); john.setMoney( new BigDecimal( 70000 ) ); @@ -1050,8 +1078,9 @@ public void testCompoundOperator() throws Exception { assertThat(john.getMoney()).isEqualTo(new BigDecimal( 0 )); } - @Test - public void testKcontext() { + @ParameterizedTest + @MethodSource("parameters") + public void testKcontext(RUN_TYPE runType) { String str = "global java.util.List result;" + "rule R\n" + @@ -1062,7 +1091,7 @@ public void testKcontext() { " result.add(kcontext.getRule().getName());\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -1072,8 +1101,9 @@ public void testKcontext() { assertThat(result.contains("R")).isTrue(); } - @Test - public void testLineBreakAtTheEndOfStatementWithoutSemicolon() { + @ParameterizedTest + @MethodSource("parameters") + public void testLineBreakAtTheEndOfStatementWithoutSemicolon(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -1087,7 +1117,7 @@ public void testLineBreakAtTheEndOfStatementWithoutSemicolon() { " insert(p2);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert(p); @@ -1096,8 +1126,9 @@ public void testLineBreakAtTheEndOfStatementWithoutSemicolon() { assertThat(fired).isEqualTo(1); } - @Test - public void testSetNullInModify() { + @ParameterizedTest + @MethodSource("parameters") + public void testSetNullInModify(RUN_TYPE runType) { // RHDM-1713 String str = "dialect \"mvel\"\n" + @@ -1112,15 +1143,16 @@ public void testSetNullInModify() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person me = new Person( "Mario", 47 ); ksession.insert( me ); assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testSetSubclassInModify() { + @ParameterizedTest + @MethodSource("parameters") + public void testSetSubclassInModify(RUN_TYPE runType) { // RHDM-1713 String str = "dialect \"mvel\"\n" + @@ -1136,15 +1168,16 @@ public void testSetSubclassInModify() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person me = new Person( "Mario", 47 ); ksession.insert( me ); assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testForEachAccessor() { + @ParameterizedTest + @MethodSource("parameters") + public void testForEachAccessor(RUN_TYPE runType) { // DROOLS-6298 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -1160,7 +1193,7 @@ public void testForEachAccessor() { "}\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ArrayList results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1175,8 +1208,9 @@ public void testForEachAccessor() { assertThat(results).containsOnly("Address"); } - @Test - public void testBigDecimalPromotionUsedAsArgument() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalPromotionUsedAsArgument(RUN_TYPE runType) { // DROOLS-6362 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -1219,7 +1253,7 @@ public void testBigDecimalPromotionUsedAsArgument() { "}\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ArrayList results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1243,8 +1277,9 @@ public static BigDecimal bigDecimalFunc( BigDecimal bd){ return new BigDecimal(bd.toString()); } - @Test - public void testBigDecimalPromotionWithExternalFunction() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalPromotionWithExternalFunction(RUN_TYPE runType) { // DROOLS-6410 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -1266,7 +1301,7 @@ public void testBigDecimalPromotionWithExternalFunction() { "results.add(bigDecimalFunc($bd) * 100 + 12);\n" + // 101212 "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ArrayList results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1281,8 +1316,9 @@ public void testBigDecimalPromotionWithExternalFunction() { assertThat(results).containsExactly(valueOf(1012), valueOf(1012), valueOf(1012), valueOf(101212)); } - @Test - public void testBigDecimalPromotionUsingDefinedFunctionAndDeclaredType() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalPromotionUsingDefinedFunctionAndDeclaredType(RUN_TYPE runType) { // DROOLS-6362 String str = "package com.sample\n" + "import " + Person.class.getName() + ";\n" + @@ -1316,7 +1352,7 @@ public void testBigDecimalPromotionUsingDefinedFunctionAndDeclaredType() { "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ArrayList results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1332,8 +1368,9 @@ public void testBigDecimalPromotionUsingDefinedFunctionAndDeclaredType() { assertThat(results).containsExactly("John"); } - @Test - public void testMVELMapRHSGetAndAssign() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVELMapRHSGetAndAssign(RUN_TYPE runType) { String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + "dialect \"mvel\"\n" + @@ -1346,7 +1383,7 @@ public void testMVELMapRHSGetAndAssign() { " result.add(i);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -1357,8 +1394,9 @@ public void testMVELMapRHSGetAndAssign() { assertThat(result).containsExactly(100); } - @Test - public void testRHSMapGetAsParam() { + @ParameterizedTest + @MethodSource("parameters") + public void testRHSMapGetAsParam(RUN_TYPE runType) { String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + "dialect \"mvel\"\n" + @@ -1370,7 +1408,7 @@ public void testRHSMapGetAsParam() { " result.add($p.itemsString[$name]);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -1381,8 +1419,9 @@ public void testRHSMapGetAsParam() { assertThat(result).containsExactly("OK"); } - @Test - public void testRHSMapNestedProperty() { + @ParameterizedTest + @MethodSource("parameters") + public void testRHSMapNestedProperty(RUN_TYPE runType) { String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + "dialect \"mvel\"\n" + @@ -1394,7 +1433,7 @@ public void testRHSMapNestedProperty() { " result.add($p.childrenMap[$name].age);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -1407,8 +1446,9 @@ public void testRHSMapNestedProperty() { assertThat(result).containsExactly(5); } - @Test - public void testRHSListNestedProperty() { + @ParameterizedTest + @MethodSource("parameters") + public void testRHSListNestedProperty(RUN_TYPE runType) { String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + "dialect \"mvel\"\n" + @@ -1420,7 +1460,7 @@ public void testRHSListNestedProperty() { " result.add($p.addresses[$age].city);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -1433,8 +1473,9 @@ public void testRHSListNestedProperty() { assertThat(result).containsExactly("London"); } - @Test - public void testRHSMapMethod() { + @ParameterizedTest + @MethodSource("parameters") + public void testRHSMapMethod(RUN_TYPE runType) { String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + "dialect \"mvel\"\n" + @@ -1446,7 +1487,7 @@ public void testRHSMapMethod() { " result.add($p.itemsString.size);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -1457,8 +1498,9 @@ public void testRHSMapMethod() { assertThat(result).containsExactly(1); } - @Test - public void testMVELBigIntegerLiteralRHS() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVELBigIntegerLiteralRHS(RUN_TYPE runType) { String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + "rule R\n" + @@ -1469,7 +1511,7 @@ public void testMVELBigIntegerLiteralRHS() { " $p.setAgeInSeconds(10000I);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person(); ksession.insert(p); @@ -1478,8 +1520,9 @@ public void testMVELBigIntegerLiteralRHS() { assertThat(p.getAgeInSeconds().equals(new BigInteger("10000"))).isTrue(); } - @Test - public void testMVELBigDecimalLiteralRHS() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVELBigDecimalLiteralRHS(RUN_TYPE runType) { String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + "rule R\n" + @@ -1490,7 +1533,7 @@ public void testMVELBigDecimalLiteralRHS() { " $p.setMoney(10000B);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person(); ksession.insert(p); @@ -1499,8 +1542,9 @@ public void testMVELBigDecimalLiteralRHS() { assertThat(p.getMoney().equals(new BigDecimal("10000"))).isTrue(); } - @Test - public void testMVELBigIntegerLiteralLHS() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVELBigIntegerLiteralLHS(RUN_TYPE runType) { String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + "rule R\n" + @@ -1510,7 +1554,7 @@ public void testMVELBigIntegerLiteralLHS() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person(); p.setAgeInSeconds(new BigInteger("10000")); @@ -1520,8 +1564,9 @@ public void testMVELBigIntegerLiteralLHS() { assertThat(fired).isEqualTo(1); } - @Test - public void testMVELModifyPropMethodCall() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVELModifyPropMethodCall(RUN_TYPE runType) { String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + "rule R\n" + @@ -1535,7 +1580,7 @@ public void testMVELModifyPropMethodCall() { " }\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person("John"); List
addresses = new ArrayList<>(); @@ -1549,8 +1594,9 @@ public void testMVELModifyPropMethodCall() { assertThat(fired).isEqualTo(1); } - @Test - public void assign_primitiveBooleanProperty() { + @ParameterizedTest + @MethodSource("parameters") + public void assign_primitiveBooleanProperty(RUN_TYPE runType) { // DROOLS-7250 String str = "package com.example.reproducer\n" + "import " + ValueHolder.class.getCanonicalName() + ";\n" + @@ -1562,7 +1608,7 @@ public void assign_primitiveBooleanProperty() { " $holder.primitiveBooleanValue = true;\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ValueHolder holder = new ValueHolder(); holder.setPrimitiveBooleanValue(false); @@ -1572,8 +1618,9 @@ public void assign_primitiveBooleanProperty() { assertThat(holder.isPrimitiveBooleanValue()).isTrue(); } - @Test - public void assign_wrapperBooleanProperty() { + @ParameterizedTest + @MethodSource("parameters") + public void assign_wrapperBooleanProperty(RUN_TYPE runType) { // DROOLS-7250 String str = "package com.example.reproducer\n" + "import " + ValueHolder.class.getCanonicalName() + ";\n" + @@ -1585,7 +1632,7 @@ public void assign_wrapperBooleanProperty() { " $holder.wrapperBooleanValue = true;\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ValueHolder holder = new ValueHolder(); holder.setWrapperBooleanValue(false); @@ -1595,7 +1642,7 @@ public void assign_wrapperBooleanProperty() { assertThat(holder.getWrapperBooleanValue()).isTrue(); } - public void assign_nestedProperty() { + public void assign_nestedProperty(RUN_TYPE runType) { // DROOLS-7195 String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -1607,7 +1654,7 @@ public void assign_nestedProperty() { " $p.address.city = \"Tokyo\";\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person("John"); p.setAddress(new Address("London")); @@ -1617,8 +1664,9 @@ public void assign_nestedProperty() { assertThat(p.getAddress().getCity()).isEqualTo("Tokyo"); } - @Test - public void assign_nestedPropertyInModify() { + @ParameterizedTest + @MethodSource("parameters") + public void assign_nestedPropertyInModify(RUN_TYPE runType) { // DROOLS-7195 String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -1632,7 +1680,7 @@ public void assign_nestedPropertyInModify() { " }\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person("John"); p.setAddress(new Address("London")); @@ -1642,8 +1690,9 @@ public void assign_nestedPropertyInModify() { assertThat(p.getAddress().getCity()).isEqualTo("Tokyo"); } - @Test - public void setter_nestedPropertyInModify() { + @ParameterizedTest + @MethodSource("parameters") + public void setter_nestedPropertyInModify(RUN_TYPE runType) { // DROOLS-7195 String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -1657,7 +1706,7 @@ public void setter_nestedPropertyInModify() { " }\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person("John"); p.setAddress(new Address("London")); @@ -1667,8 +1716,9 @@ public void setter_nestedPropertyInModify() { assertThat(p.getAddress().getCity()).isEqualTo("Tokyo"); } - @Test - public void assign_deepNestedPropertyInModify() { + @ParameterizedTest + @MethodSource("parameters") + public void assign_deepNestedPropertyInModify(RUN_TYPE runType) { // DROOLS-7195 String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -1682,7 +1732,7 @@ public void assign_deepNestedPropertyInModify() { " }\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person person = new Person("John"); Address address = new Address("London"); @@ -1696,8 +1746,9 @@ public void assign_deepNestedPropertyInModify() { assertThat(person.getAddress().getVisitorCounter().getValue()).isEqualTo(1); } - @Test - public void setter_deepNestedPropertyInModify() { + @ParameterizedTest + @MethodSource("parameters") + public void setter_deepNestedPropertyInModify(RUN_TYPE runType) { // DROOLS-7195 String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -1711,7 +1762,7 @@ public void setter_deepNestedPropertyInModify() { " }\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person person = new Person("John"); Address address = new Address("London"); @@ -1725,8 +1776,9 @@ public void setter_deepNestedPropertyInModify() { assertThat(person.getAddress().getVisitorCounter().getValue()).isEqualTo(1); } - @Test - public void drools_workingMemory_setGlobal() { + @ParameterizedTest + @MethodSource("parameters") + public void drools_workingMemory_setGlobal(RUN_TYPE runType) { // DROOLS-7338 String str = "package com.example.reproducer\n" + "import " + Logger.class.getCanonicalName() + ";\n" + @@ -1738,7 +1790,7 @@ public void drools_workingMemory_setGlobal() { " drools.workingMemory.setGlobal(\"logger\", org.slf4j.LoggerFactory.getLogger(getClass()));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.fireAllRules(); @@ -1746,8 +1798,9 @@ public void drools_workingMemory_setGlobal() { assertThat(logger).isInstanceOf(Logger.class); } - @Test - public void drools_fieldAccess() { + @ParameterizedTest + @MethodSource("parameters") + public void drools_fieldAccess(RUN_TYPE runType) { String str = "package com.example.reproducer\n" + "global java.util.Map results;\n" + "rule R\n" + @@ -1762,7 +1815,7 @@ public void drools_fieldAccess() { " results.put(\"kieRuntime\", drools.kieRuntime);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Map results = new HashMap<>(); ksession.setGlobal("results", results); @@ -1776,8 +1829,9 @@ public void drools_fieldAccess() { assertThat(results.get("kieRuntime")).isInstanceOf(KieRuntime.class); } - @Test - public void integerToBigDecimalBindVariableCoercion_shouldNotCoerceToInteger() { + @ParameterizedTest + @MethodSource("parameters") + public void integerToBigDecimalBindVariableCoercion_shouldNotCoerceToInteger(RUN_TYPE runType) { // DROOLS-7540 String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -1791,7 +1845,7 @@ public void integerToBigDecimalBindVariableCoercion_shouldNotCoerceToInteger() { " results.add($money);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1804,8 +1858,9 @@ public void integerToBigDecimalBindVariableCoercion_shouldNotCoerceToInteger() { assertThat(results).contains(new BigDecimal("5")); } - @Test - public void integerToBigDecimalVariableCoercionTwice_shouldNotCoerceToInteger() { + @ParameterizedTest + @MethodSource("parameters") + public void integerToBigDecimalVariableCoercionTwice_shouldNotCoerceToInteger(RUN_TYPE runType) { // DROOLS-7540 String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -1821,7 +1876,7 @@ public void integerToBigDecimalVariableCoercionTwice_shouldNotCoerceToInteger() " results.add($var1);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1834,8 +1889,9 @@ public void integerToBigDecimalVariableCoercionTwice_shouldNotCoerceToInteger() assertThat(results).contains(new BigDecimal("5")); } - @Test - public void integerToBigDecimalBindVariableCoercionAndAddition_shouldNotThrowClassCastException() { + @ParameterizedTest + @MethodSource("parameters") + public void integerToBigDecimalBindVariableCoercionAndAddition_shouldNotThrowClassCastException(RUN_TYPE runType) { // DROOLS-7540 String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -1850,7 +1906,7 @@ public void integerToBigDecimalBindVariableCoercionAndAddition_shouldNotThrowCla " results.add($total);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1863,8 +1919,9 @@ public void integerToBigDecimalBindVariableCoercionAndAddition_shouldNotThrowCla assertThat(results).contains(new BigDecimal("15")); } - @Test - public void integerToBigDecimalVaribleSetFromBindVariableCoercionAndAddition_shouldNotThrowClassCastException() { + @ParameterizedTest + @MethodSource("parameters") + public void integerToBigDecimalVaribleSetFromBindVariableCoercionAndAddition_shouldNotThrowClassCastException(RUN_TYPE runType) { // DROOLS-7540 String str = "package com.example.reproducer\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -1882,7 +1939,7 @@ public void integerToBigDecimalVaribleSetFromBindVariableCoercionAndAddition_sho " results.add($total);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MvelOperatorsTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MvelOperatorsTest.java index 9aa6b4fb81c..9986cba4046 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MvelOperatorsTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/MvelOperatorsTest.java @@ -24,7 +24,8 @@ import java.util.Map; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.builder.Message; import org.kie.api.builder.Results; import org.kie.api.runtime.KieSession; @@ -34,47 +35,46 @@ public class MvelOperatorsTest extends BaseModelTest { - public MvelOperatorsTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testIn() { + @ParameterizedTest + @MethodSource("parameters") + public void testIn(RUN_TYPE runType) { String str = "rule R when\n" + " String(this in (\"a\", \"b\"))" + "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert( "b" ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testStr() { + @ParameterizedTest + @MethodSource("parameters") + public void testStr(RUN_TYPE runType) { String str = "rule R when\n" + " String(this str[startsWith] \"M\")" + "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert( "Mario" ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testStrNot() { + @ParameterizedTest + @MethodSource("parameters") + public void testStrNot(RUN_TYPE runType) { String str = "rule R when\n" + " String(this not str[startsWith] \"M\")" + "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert( "Mario" ); ksession.insert( "Luca" ); @@ -82,15 +82,16 @@ public void testStrNot() { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testStrHalf() { + @ParameterizedTest + @MethodSource("parameters") + public void testStrHalf(RUN_TYPE runType) { String str = "rule R when\n" + " String(this str[startsWith] \"M\" || str[endsWith] \"a\" || str[length] 10)"+ "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert( "Mario" ); ksession.insert( "Luca" ); @@ -99,15 +100,16 @@ public void testStrHalf() { assertThat(ksession.fireAllRules()).isEqualTo(3); } - @Test - public void testStrHalfOrAndAmpersand() { + @ParameterizedTest + @MethodSource("parameters") + public void testStrHalfOrAndAmpersand(RUN_TYPE runType) { String str = "rule R when\n" + " String(this str[startsWith] \"M\" || str[endsWith] \"a\" && str[length] 4)"+ "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert( "Mario" ); ksession.insert( "Luca" ); @@ -116,8 +118,9 @@ public void testStrHalfOrAndAmpersand() { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testRange() { + @ParameterizedTest + @MethodSource("parameters") + public void testRange(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List list\n" + @@ -127,7 +130,7 @@ public void testRange() { " list.add($name);" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -142,8 +145,9 @@ public void testRange() { assertThat(list.containsAll(asList("Mark", "Edson"))).isTrue(); } - @Test - public void testExcludedRange() { + @ParameterizedTest + @MethodSource("parameters") + public void testExcludedRange(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List list\n" + @@ -153,7 +157,7 @@ public void testExcludedRange() { " list.add($name);" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -168,8 +172,9 @@ public void testExcludedRange() { assertThat(list.containsAll(asList("Luca", "Mario"))).isTrue(); } - @Test - public void testBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testBinding(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List list\n" + @@ -179,7 +184,7 @@ public void testBinding() { " list.add($name);" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -192,22 +197,24 @@ public void testBinding() { assertThat(list.get(0)).isEqualTo("Mario"); } - @Test - public void testMatches() { + @ParameterizedTest + @MethodSource("parameters") + public void testMatches(RUN_TYPE runType) { String str = "rule R when\n" + " String(this matches \"\\\\w\")" + "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert( "b" ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testExcludes() { + @ParameterizedTest + @MethodSource("parameters") + public void testExcludes(RUN_TYPE runType) { String str = "import java.util.List\n" + "rule R when\n" + @@ -215,15 +222,16 @@ public void testExcludes() { "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert( asList("ciao", "test") ); assertThat(ksession.fireAllRules()).isEqualTo(0); ksession.insert( asList("hello", "world") ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNotContains() { + @ParameterizedTest + @MethodSource("parameters") + public void testNotContains(RUN_TYPE runType) { String str = "import java.util.List\n" + "rule R when\n" + @@ -231,15 +239,16 @@ public void testNotContains() { "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert( asList("ciao", "test") ); assertThat(ksession.fireAllRules()).isEqualTo(0); ksession.insert( asList("hello", "world") ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testStartsWithWithChar() { + @ParameterizedTest + @MethodSource("parameters") + public void testStartsWithWithChar(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List list\n" + @@ -250,7 +259,7 @@ public void testStartsWithWithChar() { " list.add($p.getName());" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -263,8 +272,9 @@ public void testStartsWithWithChar() { assertThat(list.get(0)).isEqualTo("Luca"); } - @Test - public void testNotIn() { + @ParameterizedTest + @MethodSource("parameters") + public void testNotIn(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List list\n" + @@ -274,7 +284,7 @@ public void testNotIn() { " list.add($name);" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -288,8 +298,9 @@ public void testNotIn() { assertThat(list.get(0)).isEqualTo("Mario"); } - @Test - public void testNotInUsingShort() { + @ParameterizedTest + @MethodSource("parameters") + public void testNotInUsingShort(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List list\n" + @@ -299,7 +310,7 @@ public void testNotInUsingShort() { " list.add($name);" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -313,8 +324,9 @@ public void testNotInUsingShort() { assertThat(list.get(0)).isEqualTo("Mario"); } - @Test - public void testMatchesWithFunction() { + @ParameterizedTest + @MethodSource("parameters") + public void testMatchesWithFunction(RUN_TYPE runType) { // DROOLS-4382 String str = "import " + Person.class.getCanonicalName() + "\n" + @@ -324,7 +336,7 @@ public void testMatchesWithFunction() { "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mark", 40); p.setLikes( "M." ); @@ -332,8 +344,9 @@ public void testMatchesWithFunction() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testMatchesOnNullString() { + @ParameterizedTest + @MethodSource("parameters") + public void testMatchesOnNullString(RUN_TYPE runType) { // DROOLS-4525 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -346,7 +359,7 @@ public void testMatchesOnNullString() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person first = new Person("686878"); ksession.insert(first); @@ -377,8 +390,9 @@ public String toString() { } } - @Test - public void testInDouble() { + @ParameterizedTest + @MethodSource("parameters") + public void testInDouble(RUN_TYPE runType) { // DROOLS-4892 String str = "import " + DoubleFact.class.getCanonicalName() + ";" + @@ -406,10 +420,10 @@ public void testInDouble() { " System.out.println(\"Rule[\"+kcontext.getRule().getName()+\"] fires.\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); DoubleFact f = new DoubleFact(); - f.setDoubleVal(new Double(100)); + f.setDoubleVal(Double.valueOf(100.0)); f.setPrimitiveDoubleVal(200); ksession.insert(f); assertThat(ksession.fireAllRules()).isEqualTo(4); @@ -432,8 +446,9 @@ public List getIntList() { } } - @Test - public void testContainsOnNull() { + @ParameterizedTest + @MethodSource("parameters") + public void testContainsOnNull(RUN_TYPE runType) { // DROOLS-5315 String str = "import " + ListContainer.class.getCanonicalName() + ";" + @@ -442,7 +457,7 @@ public void testContainsOnNull() { "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ListContainer() ); assertThat(ksession.fireAllRules()).isEqualTo(0); @@ -451,8 +466,9 @@ public void testContainsOnNull() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNumericStringsWithLeadingZero() { + @ParameterizedTest + @MethodSource("parameters") + public void testNumericStringsWithLeadingZero(RUN_TYPE runType) { // DROOLS-5926 String str = "rule R when\n" + @@ -460,14 +476,15 @@ public void testNumericStringsWithLeadingZero() { "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert( 800 ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testNumericHexadecimal() { + @ParameterizedTest + @MethodSource("parameters") + public void testNumericHexadecimal(RUN_TYPE runType) { // DROOLS-5926 String str = "rule R when\n" + @@ -475,14 +492,15 @@ public void testNumericHexadecimal() { "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert( 2048 ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testListLiteralCreation() { + @ParameterizedTest + @MethodSource("parameters") + public void testListLiteralCreation(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List result;" + @@ -492,7 +510,7 @@ public void testListLiteralCreation() { " result.add($myList);" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); ksession.insert( new Person() ); @@ -503,8 +521,9 @@ public void testListLiteralCreation() { assertThat((List)obj).containsExactlyInAnyOrder("aaa", "bbb", "ccc"); } - @Test - public void testMapLiteralCreation() { + @ParameterizedTest + @MethodSource("parameters") + public void testMapLiteralCreation(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List result;" + @@ -514,7 +533,7 @@ public void testMapLiteralCreation() { " result.add($myMap);" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); ksession.insert(new Person()); @@ -525,8 +544,9 @@ public void testMapLiteralCreation() { assertThat(((Map) obj).get("key")).isEqualTo("value"); } - @Test - public void testEmptySingleApexString() { + @ParameterizedTest + @MethodSource("parameters") + public void testEmptySingleApexString(RUN_TYPE runType) { // DROOLS-6057 String str = "import " + Person.class.getCanonicalName() + "\n" + @@ -537,7 +557,7 @@ public void testEmptySingleApexString() { " list.add($name);" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -550,8 +570,9 @@ public void testEmptySingleApexString() { assertThat(list.get(0)).isEqualTo(""); } - @Test - public void testContainsOnString() { + @ParameterizedTest + @MethodSource("parameters") + public void testContainsOnString(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + "\n" + "rule R when\n" + @@ -559,7 +580,7 @@ public void testContainsOnString() { "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person person1 = new Person(""); ksession.insert(new Person("mario", 47)); @@ -567,8 +588,9 @@ public void testContainsOnString() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testContainsOnMapShouldntCompile() { + @ParameterizedTest + @MethodSource("parameters") + public void testContainsOnMapShouldntCompile(RUN_TYPE runType) { // BAPL-1957 String str = "import " + Person.class.getCanonicalName() + "\n" + @@ -577,12 +599,13 @@ public void testContainsOnMapShouldntCompile() { "then\n" + "end "; - Results results = createKieBuilder( str ).getResults(); + Results results = createKieBuilder(runType, str).getResults(); assertThat(results.getMessages(Message.Level.ERROR).isEmpty()).isFalse(); } - @Test - public void testContainsOnIntShouldntCompile() { + @ParameterizedTest + @MethodSource("parameters") + public void testContainsOnIntShouldntCompile(RUN_TYPE runType) { // BAPL-1957 String str = "import " + Person.class.getCanonicalName() + "\n" + @@ -591,7 +614,7 @@ public void testContainsOnIntShouldntCompile() { "then\n" + "end "; - Results results = createKieBuilder( str ).getResults(); + Results results = createKieBuilder(runType, str).getResults(); assertThat(results.getMessages(Message.Level.ERROR).isEmpty()).isFalse(); } } diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NamedConsequencesTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NamedConsequencesTest.java index 6a764ebcb07..80ec5862f25 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NamedConsequencesTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NamedConsequencesTest.java @@ -26,7 +26,8 @@ import org.drools.model.codegen.execmodel.domain.Cheese; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.builder.Message.Level; import org.kie.api.builder.Results; import org.kie.api.runtime.KieSession; @@ -37,12 +38,9 @@ public class NamedConsequencesTest extends BaseModelTest { - public NamedConsequencesTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testNamedConsequence() { + @ParameterizedTest + @MethodSource("parameters") + public void testNamedConsequence(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -57,7 +55,7 @@ public void testNamedConsequence() { " $r.addValue(\"Found \" + $p1.getName());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -72,8 +70,9 @@ public void testNamedConsequence() { assertThat(results.containsAll(asList("Found Mark", "Mario is older than Mark"))).isTrue(); } - @Test - public void testBreakingNamedConsequence() { + @ParameterizedTest + @MethodSource("parameters") + public void testBreakingNamedConsequence(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -94,7 +93,7 @@ public void testBreakingNamedConsequence() { " $r.addValue(\"Found \" + $p1.getName());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -110,8 +109,9 @@ public void testBreakingNamedConsequence() { assertThat(results.iterator().next()).isEqualTo("Found Mark"); } - @Test - public void testNonBreakingNamedConsequence() { + @ParameterizedTest + @MethodSource("parameters") + public void testNonBreakingNamedConsequence(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -132,7 +132,7 @@ public void testNonBreakingNamedConsequence() { " $r.addValue(\"Found \" + $p1.getName());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -148,8 +148,9 @@ public void testNonBreakingNamedConsequence() { assertThat(results.containsAll(asList("Found Mark", "Mario is older than Mark"))).isTrue(); } - @Test - public void testIfAfterAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testIfAfterAccumulate(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -166,7 +167,7 @@ public void testIfAfterAccumulate() { " $r.addValue(\"greater\");\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -180,8 +181,9 @@ public void testIfAfterAccumulate() { assertThat(results.get(0)).isEqualTo("greater"); } - @Test - public void testNonCompilingIFAfterOR() { + @ParameterizedTest + @MethodSource("parameters") + public void testNonCompilingIFAfterOR(RUN_TYPE runType) { String str = "import " + Cheese.class.getCanonicalName() + ";\n " + "global java.util.List results;\n" + "\n" + @@ -197,12 +199,13 @@ public void testNonCompilingIFAfterOR() { " results.add( $a.getType() );\n" + "end\n"; - Results results = createKieBuilder(str).getResults(); + Results results = createKieBuilder(runType, str).getResults(); assertThat(results.hasMessages(Level.ERROR)).isTrue(); } - @Test - public void testIfElseWithMvelAccessor() { + @ParameterizedTest + @MethodSource("parameters") + public void testIfElseWithMvelAccessor(RUN_TYPE runType) { String str = "import " + Cheese.class.getCanonicalName() + ";\n " + "global java.util.List results;\n" + "\n" + @@ -218,7 +221,7 @@ public void testIfElseWithMvelAccessor() { " results.add( $a.getType().toUpperCase() );\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList(); ksession.setGlobal("results", results); @@ -237,8 +240,9 @@ public void testIfElseWithMvelAccessor() { assertThat(results.contains("STILTON")).isTrue(); } - @Test - public void testWrongConsequenceName() { + @ParameterizedTest + @MethodSource("parameters") + public void testWrongConsequenceName(RUN_TYPE runType) { String str = "import " + Cheese.class.getCanonicalName() + ";\n " + "global java.util.List results;\n" + "\n" + @@ -252,12 +256,13 @@ public void testWrongConsequenceName() { " results.add( $a.getType().toUpperCase() );\n" + "end\n"; - Results results = createKieBuilder(str).getResults(); + Results results = createKieBuilder(runType, str).getResults(); assertThat(results.hasMessages(Level.ERROR)).isTrue(); } - @Test - public void testMvelInsertWithNamedConsequence() { + @ParameterizedTest + @MethodSource("parameters") + public void testMvelInsertWithNamedConsequence(RUN_TYPE runType) { String drl = "package org.drools.compiler\n" + "global java.util.concurrent.atomic.AtomicInteger counter\n" + @@ -283,7 +288,7 @@ public void testMvelInsertWithNamedConsequence() { " counter.incrementAndGet();\n" + "end\n"; - KieSession kSession = getKieSession(drl); + KieSession kSession = getKieSession(runType, drl); AtomicInteger counter = new AtomicInteger(0); kSession.setGlobal("counter", counter); @@ -298,8 +303,9 @@ public void testMvelInsertWithNamedConsequence() { assertThat(counter.get()).isEqualTo(2); } - @Test - public void testMVELBreak() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVELBreak(RUN_TYPE runType) { String str = "import " + Cheese.class.getCanonicalName() + ";\n " + "global java.util.List results;\n" + "\n" + @@ -313,7 +319,7 @@ public void testMVELBreak() { " results.add( $a.type.toUpperCase() );\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList(); ksession.setGlobal("results", results); @@ -331,8 +337,9 @@ public void testMVELBreak() { assertThat(results.contains("STILTON")).isTrue(); } - @Test - public void testMVELNoBreak() { + @ParameterizedTest + @MethodSource("parameters") + public void testMVELNoBreak(RUN_TYPE runType) { String str = "import " + Cheese.class.getCanonicalName() + ";\n " + "global java.util.List results;\n" + "\n" + @@ -346,7 +353,7 @@ public void testMVELNoBreak() { " results.add( $a.type.toUpperCase() );\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList(); ksession.setGlobal("results", results); @@ -365,8 +372,9 @@ public void testMVELNoBreak() { assertThat(results.contains("cheddar")).isTrue(); } - @Test - public void testMultipleIfElseInARow() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleIfElseInARow(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "global java.util.List result;\n" + @@ -394,7 +402,7 @@ public void testMultipleIfElseInARow() { " result.add(\"Age100\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -408,8 +416,9 @@ public void testMultipleIfElseInARow() { assertThat(result.containsAll(asList("Default", "Mark", "Edson", "Age35", "Age37"))).isTrue(); } - @Test - public void testMultipleIfElseInARowWithJoin() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleIfElseInARowWithJoin(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -432,7 +441,7 @@ public void testMultipleIfElseInARowWithJoin() { " $r.addValue(\"Age37\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert(result); @@ -448,8 +457,9 @@ public void testMultipleIfElseInARowWithJoin() { assertThat(results.containsAll(asList("Default", "Mark", "Edson", "Age35", "Age37"))).isTrue(); } - @Test - public void testMultipleIfElseInARowWithJoin2() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleIfElseInARowWithJoin2(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";\n" + "import " + Person.class.getCanonicalName() + ";\n" + @@ -473,7 +483,7 @@ public void testMultipleIfElseInARowWithJoin2() { " $r.addValue(\"Age37\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert(result); @@ -490,7 +500,7 @@ public void testMultipleIfElseInARowWithJoin2() { assertThat(results.containsAll(asList("DefaultMario", "Mark", "Edson", "Age35", "Age37"))).isTrue(); } - public void testModifyInNamedConsequence() { + public void testModifyInNamedConsequence(RUN_TYPE runType) { String str = "import " + Cheese.class.getCanonicalName() + ";\n " + "global java.util.List results;\n" + "\n" + @@ -504,7 +514,7 @@ public void testModifyInNamedConsequence() { " modify( $a ) { setPrice(15) };\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList(); ksession.setGlobal("results", results); @@ -522,8 +532,9 @@ public void testModifyInNamedConsequence() { assertThat(results.contains("stilton")).isTrue(); } - @Test - public void test2ModifyBlocksInNamedConsequences() { + @ParameterizedTest + @MethodSource("parameters") + public void test2ModifyBlocksInNamedConsequences(RUN_TYPE runType) { String str = "import " + Cheese.class.getCanonicalName() + ";\n " + "global java.util.List results;\n" + "\n" + @@ -538,7 +549,7 @@ public void test2ModifyBlocksInNamedConsequences() { " results.add( $a.getPrice() );\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -554,8 +565,9 @@ public void test2ModifyBlocksInNamedConsequences() { assertThat(results).containsExactlyInAnyOrder(10, 15); } - @Test - public void testMultipleIfAfterEval() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleIfAfterEval(RUN_TYPE runType) { String str = "import " + Cheese.class.getCanonicalName() + ";\n " + "global java.util.List results;\n" + "\n" + @@ -573,7 +585,7 @@ public void testMultipleIfAfterEval() { " results.add( $a.getType() );\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -590,7 +602,7 @@ public void testMultipleIfAfterEval() { assertThat(results.contains("stilton")).isTrue(); } - public void testIfTrue() { + public void testIfTrue(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "global java.util.List result;\n" + @@ -603,7 +615,7 @@ public void testIfTrue() { " result.add(\"t1\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NativeCompilerTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NativeCompilerTest.java index 12860f98815..3f9bd8d9376 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NativeCompilerTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NativeCompilerTest.java @@ -20,7 +20,9 @@ import org.drools.compiler.compiler.JavaDialectConfiguration; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import org.kie.memorycompiler.JavaConfiguration; @@ -28,12 +30,10 @@ public class NativeCompilerTest extends BaseModelTest { - public NativeCompilerTest(RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test(timeout = 5000) - public void testPropertyReactivity() { + @ParameterizedTest + @MethodSource("parameters") + @Timeout(5000) + public void testPropertyReactivity(RUN_TYPE runType) { // DROOLS-6580 // Since ecj is transitively imported by drools-compiler (we may want to review this with drools 8) // by default the executable model compiler always use it. This test also tries it with the native compiler. @@ -50,7 +50,7 @@ public void testPropertyReactivity() { " modify($p) { setAge($p.getAge()+1) }\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person me = new Person("Mario", 40); ksession.insert(me); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NodeSharingTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NodeSharingTest.java index 65eef03f77f..2cf30843a3b 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NodeSharingTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NodeSharingTest.java @@ -41,7 +41,8 @@ import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Result; import org.drools.model.codegen.execmodel.domain.StockTick; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.runtime.KieSession; import org.kie.api.time.SessionPseudoClock; @@ -50,12 +51,9 @@ public class NodeSharingTest extends BaseModelTest { - public NodeSharingTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testShareAlpha() { + @ParameterizedTest + @MethodSource("parameters") + public void testShareAlpha(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -69,7 +67,7 @@ public void testShareAlpha() { " $r.add($p3);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Set result = new HashSet<>(); ksession.insert( result ); @@ -91,8 +89,9 @@ public void testShareAlpha() { assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(2); } - @Test - public void testShareAlphaInDifferentRules() { + @ParameterizedTest + @MethodSource("parameters") + public void testShareAlphaInDifferentRules(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + @@ -104,13 +103,14 @@ public void testShareAlphaInDifferentRules() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); } - @Test - public void testShareAlphaInDifferentPackages() { + @ParameterizedTest + @MethodSource("parameters") + public void testShareAlphaInDifferentPackages(RUN_TYPE runType) { String str1 = "package org.drools.a\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -126,13 +126,14 @@ public void testShareAlphaInDifferentPackages() { "then\n" + "end"; - KieSession ksession = getKieSession( str1, str2 ); + KieSession ksession = getKieSession(runType, str1, str2); assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); } - @Test - public void testShareBetaWithConstraintReordering() { + @ParameterizedTest + @MethodSource("parameters") + public void testShareBetaWithConstraintReordering(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + @@ -146,7 +147,7 @@ public void testShareBetaWithConstraintReordering() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ReteDumper.collectNodes(ksession).stream().filter(BetaNode.class::isInstance).count()).isEqualTo(1); @@ -155,8 +156,9 @@ public void testShareBetaWithConstraintReordering() { assertThat(otn.getSinks().length).isEqualTo(1); } - @Test - public void testTrimmedConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testTrimmedConstraint(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + @@ -169,13 +171,14 @@ public void testTrimmedConstraint() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); } - @Test - public void testOrWithTrimmedConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testOrWithTrimmedConstraint(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List list\n" + @@ -193,7 +196,7 @@ public void testOrWithTrimmedConstraint() { " list.add( $p + \" has \" + $age + \" years\");\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(2); @@ -212,8 +215,9 @@ public void testOrWithTrimmedConstraint() { assertThat(results.contains("Mario has 40 years")).isTrue(); } - @Test - public void testShareAlphaHashable() { + @ParameterizedTest + @MethodSource("parameters") + public void testShareAlphaHashable(RUN_TYPE runType) { String str = "import " + Factor.class.getCanonicalName() + ";\n" + "rule R1 when\n" + @@ -223,7 +227,7 @@ public void testShareAlphaHashable() { " Factor( factorAmt == 10.0 )\n" + "then end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Factor(10.0)); assertThat(ksession.fireAllRules()).isEqualTo(2); @@ -231,8 +235,9 @@ public void testShareAlphaHashable() { assertThat(ReteDumper.collectNodes(ksession).stream().filter(AlphaNode.class::isInstance).count()).isEqualTo(1); } - @Test - public void testShareAlphaRangeIndexable() { + @ParameterizedTest + @MethodSource("parameters") + public void testShareAlphaRangeIndexable(RUN_TYPE runType) { String str = "import " + Factor.class.getCanonicalName() + ";\n" + "rule R1 when\n" + @@ -242,7 +247,7 @@ public void testShareAlphaRangeIndexable() { " Factor( factorAmt > 10.0 )\n" + "then end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Factor(25.0)); assertThat(ksession.fireAllRules()).isEqualTo(2); @@ -263,8 +268,9 @@ public double getFactorAmt() { } } - @Test - public void testShareEval() { + @ParameterizedTest + @MethodSource("parameters") + public void testShareEval(RUN_TYPE runType) { final String str = "package myPkg;\n" + "rule R1 when\n" + " i : Integer()\n" + @@ -278,7 +284,7 @@ public void testShareEval() { "end\n" + ""; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); KieBase kbase = ksession.getKieBase(); EntryPointNode epn = ((InternalKnowledgeBase) kbase).getRete().getEntryPointNodes().values().iterator().next(); @@ -287,7 +293,7 @@ public void testShareEval() { assertThat(lian.getSinks().length).isEqualTo(1); } - public void testShareFrom() { + public void testShareFrom(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "import " + Address.class.getCanonicalName() + ";\n" + @@ -305,7 +311,7 @@ public void testShareFrom() { " list.add($a);\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List
list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -322,8 +328,9 @@ public void testShareFrom() { assertThat(ReteDumper.collectNodes(ksession).stream().filter(FromNode.class::isInstance).count()).isEqualTo(1); } - @Test - public void testShareAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testShareAccumulate(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -342,7 +349,7 @@ public void testShareAccumulate() { " insert(new Result($sum));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -357,8 +364,9 @@ public void testShareAccumulate() { assertThat(ReteDumper.collectNodes(ksession).stream().filter(AccumulateNode.class::isInstance).count()).isEqualTo(1); } - @Test - public void testShareFromAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testShareFromAccumulate(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -377,7 +385,7 @@ public void testShareFromAccumulate() { " insert(new Result($sum));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mark", 37)); ksession.insert(new Person("Edson", 35)); @@ -392,8 +400,9 @@ public void testShareFromAccumulate() { assertThat(ReteDumper.collectNodes(ksession).stream().filter(AccumulateNode.class::isInstance).count()).isEqualTo(1); } - @Test - public void testShareExists() { + @ParameterizedTest + @MethodSource("parameters") + public void testShareExists(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -408,7 +417,7 @@ public void testShareExists() { " insert(new Result(\"ok\"));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person mario = new Person("Mario", 40); @@ -422,8 +431,9 @@ public void testShareExists() { assertThat(ReteDumper.collectNodes(ksession).stream().filter(ExistsNode.class::isInstance).count()).isEqualTo(1); } - @Test - public void testShareNot() { + @ParameterizedTest + @MethodSource("parameters") + public void testShareNot(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Result.class.getCanonicalName() + ";" + @@ -438,7 +448,7 @@ public void testShareNot() { " insert(new Result(\"ok\"));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person mario = new Person("Mario", 40); @@ -452,8 +462,9 @@ public void testShareNot() { assertThat(ReteDumper.collectNodes(ksession).stream().filter(NotNode.class::isInstance).count()).isEqualTo(1); } - @Test - public void testShareCombinedConstraintAnd() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testShareCombinedConstraintAnd(RUN_TYPE runType) throws Exception { // DROOLS-6330 // Note: if DROOLS-6329 is resolved, this test may not produce CombinedConstraint String str = @@ -471,7 +482,7 @@ public void testShareCombinedConstraintAnd() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(CepTest.getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, CepTest.getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); @@ -489,8 +500,9 @@ public void testShareCombinedConstraintAnd() throws Exception { assertThat(ReteDumper.collectNodes(ksession).stream().filter(JoinNode.class::isInstance).count()).isEqualTo(1); } - @Test - public void testShareCombinedConstraintOr() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testShareCombinedConstraintOr(RUN_TYPE runType) throws Exception { // DROOLS-6330 String str = "import " + StockTick.class.getCanonicalName() + ";" + @@ -507,7 +519,7 @@ public void testShareCombinedConstraintOr() throws Exception { " System.out.println(\"fired\");\n" + "end\n"; - KieSession ksession = getKieSession(CepTest.getCepKieModuleModel(), str); + KieSession ksession = getKieSession(runType, CepTest.getCepKieModuleModel(), str); SessionPseudoClock clock = ksession.getSessionClock(); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NullSafeDereferencingTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NullSafeDereferencingTest.java index 536af82f868..a442f36b28c 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NullSafeDereferencingTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NullSafeDereferencingTest.java @@ -26,19 +26,17 @@ import org.drools.model.codegen.execmodel.domain.MysteriousMan; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class NullSafeDereferencingTest extends BaseModelTest { - public NullSafeDereferencingTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testNullSafeDereferncing() { + @ParameterizedTest + @MethodSource("parameters") + public void testNullSafeDereferncing(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -49,7 +47,7 @@ public void testNullSafeDereferncing() { " $r.setValue(\"Found: \" + $p);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -115,8 +113,9 @@ public void setSomething(String something) { } } - @Test - public void testNullSafeMultiple() { + @ParameterizedTest + @MethodSource("parameters") + public void testNullSafeMultiple(RUN_TYPE runType) { String str = "import " + NullUnsafeA.class.getCanonicalName() + ";" + "import " + NullUnsafeB.class.getCanonicalName() + ";" + "import " + NullUnsafeD.class.getCanonicalName() + ";" + @@ -127,7 +126,7 @@ public void testNullSafeMultiple() { "end"; for (int i = 0; i <= 4; i++) { - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); NullUnsafeA a = new NullUnsafeA(); NullUnsafeB b = new NullUnsafeB(); @@ -162,8 +161,9 @@ public void testNullSafeMultiple() { } } - @Test - public void testNullSafeDereferncingOnFieldWithMethodInvocation() { + @ParameterizedTest + @MethodSource("parameters") + public void testNullSafeDereferncingOnFieldWithMethodInvocation(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -173,7 +173,7 @@ public void testNullSafeDereferncingOnFieldWithMethodInvocation() { " insert(r);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("John1", 41, (Address) null)); ksession.insert(new Person("John2", 42, new Address("Milan"))); @@ -184,8 +184,9 @@ public void testNullSafeDereferncingOnFieldWithMethodInvocation() { assertThat(results.get(0).getValue()).isEqualTo("John2"); } - @Test - public void testNullSafeDereferncingOnMethodInvocation() { + @ParameterizedTest + @MethodSource("parameters") + public void testNullSafeDereferncingOnMethodInvocation(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -195,7 +196,7 @@ public void testNullSafeDereferncingOnMethodInvocation() { " insert(r);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("John1", 41, new Address(null))); ksession.insert(new Person("John2", 42, new Address("Milan"))); @@ -206,8 +207,9 @@ public void testNullSafeDereferncingOnMethodInvocation() { assertThat(results.get(0).getValue()).isEqualTo("John2"); } - @Test - public void testNullSafeDereferncingOnFirstField() { + @ParameterizedTest + @MethodSource("parameters") + public void testNullSafeDereferncingOnFirstField(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -217,7 +219,7 @@ public void testNullSafeDereferncingOnFirstField() { " insert(r);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("John1", 41, (Address) null)); ksession.insert(new Person("John2", 42, new Address("Milan"))); @@ -228,8 +230,9 @@ public void testNullSafeDereferncingOnFirstField() { assertThat(results.get(0).getValue()).isEqualTo("John2"); } - @Test - public void testNullSafeDereferncingOnSecondField() { + @ParameterizedTest + @MethodSource("parameters") + public void testNullSafeDereferncingOnSecondField(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -239,7 +242,7 @@ public void testNullSafeDereferncingOnSecondField() { " insert(r);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("John1", 41, new Address(null))); ksession.insert(new Person("John2", 42, new Address("Milan"))); @@ -250,8 +253,9 @@ public void testNullSafeDereferncingOnSecondField() { assertThat(results.get(0).getValue()).isEqualTo("John2"); } - @Test - public void testNullSafeDereferncingWithOrHalfBinary() { + @ParameterizedTest + @MethodSource("parameters") + public void testNullSafeDereferncingWithOrHalfBinary(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "global java.util.List result;\n" + @@ -262,7 +266,7 @@ public void testNullSafeDereferncingWithOrHalfBinary() { " result.add($p.getName());\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -274,8 +278,9 @@ public void testNullSafeDereferncingWithOrHalfBinary() { assertThat(result).containsExactlyInAnyOrder("John", "George"); } - @Test - public void testNullSafeDereferencingNonPredicate() { + @ParameterizedTest + @MethodSource("parameters") + public void testNullSafeDereferencingNonPredicate(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "global java.util.List result;\n" + @@ -285,7 +290,7 @@ public void testNullSafeDereferencingNonPredicate() { " result.add($cityName);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -297,8 +302,9 @@ public void testNullSafeDereferencingNonPredicate() { assertThat(result).containsExactlyInAnyOrder("London", "Tokyo"); } - @Test - public void testMultipleNullSafeDereferencingNonPredicate() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleNullSafeDereferencingNonPredicate(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "global java.util.List result;\n" + @@ -308,7 +314,7 @@ public void testMultipleNullSafeDereferencingNonPredicate() { " result.add($cityNameLength);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -320,8 +326,9 @@ public void testMultipleNullSafeDereferencingNonPredicate() { assertThat(result).containsExactlyInAnyOrder(6); } - @Test - public void testNullSafeDereferencingPredicateMethod() { + @ParameterizedTest + @MethodSource("parameters") + public void testNullSafeDereferencingPredicateMethod(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "global java.util.List result;\n" + @@ -331,7 +338,7 @@ public void testNullSafeDereferencingPredicateMethod() { " result.add($containsL);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -343,8 +350,9 @@ public void testNullSafeDereferencingPredicateMethod() { assertThat(result).containsExactlyInAnyOrder(true, false); } - @Test - public void testNullSafeIndex() { + @ParameterizedTest + @MethodSource("parameters") + public void testNullSafeIndex(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "rule R1 when\n" + " $city : String()\n"+ @@ -352,7 +360,7 @@ public void testNullSafeIndex() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mario", 38)); @@ -369,8 +377,9 @@ public void testNullSafeIndex() { ksession.dispose(); } - @Test - public void testNullSafeDereferncingWithOr() { + @ParameterizedTest + @MethodSource("parameters") + public void testNullSafeDereferncingWithOr(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";\n" + "global java.util.List result;\n" + @@ -381,7 +390,7 @@ public void testNullSafeDereferncingWithOr() { " result.add($p.getName());\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -400,8 +409,9 @@ public void testNullSafeDereferncingWithOr() { assertThat(result).containsExactlyInAnyOrder("Bob", "Paul"); } - @Test - public void testNullSafeDereferncingWithInstanceof() { + @ParameterizedTest + @MethodSource("parameters") + public void testNullSafeDereferncingWithInstanceof(RUN_TYPE runType) { // instanceof has to be evaluated before null check String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -414,7 +424,7 @@ public void testNullSafeDereferncingWithInstanceof() { " result.add($p.getName());\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NumberAndStringArithmeticOperationCoercionTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NumberAndStringArithmeticOperationCoercionTest.java index b92641ad932..10b5c36a39e 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NumberAndStringArithmeticOperationCoercionTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/NumberAndStringArithmeticOperationCoercionTest.java @@ -21,148 +21,162 @@ import java.math.BigDecimal; import org.drools.model.codegen.execmodel.domain.ValueHolder; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class NumberAndStringArithmeticOperationCoercionTest extends BaseModelTest { - public NumberAndStringArithmeticOperationCoercionTest(RUN_TYPE testRunType) { - super(testRunType); - } // NOTE: For BigDecimal specific issues, use BigDecimalTest - @Test - public void testMultiplyStringInt() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyStringInt(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setIntValue(100); holder.setStrValue("10"); - testValueHolder("ValueHolder( intValue == strValue * 10 )", holder); + testValueHolder(runType, "ValueHolder( intValue == strValue * 10 )", holder); } - @Test - public void testMultiplyStringIntWithBindVariable() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyStringIntWithBindVariable(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setIntValue(100); holder.setStrValue("10"); - testValueHolder("ValueHolder( $strValue : strValue, intValue == $strValue * 10 )", holder); + testValueHolder(runType, "ValueHolder( $strValue : strValue, intValue == $strValue * 10 )", holder); } - @Test - public void testMultiplyIntStringWithBindVariable() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyIntStringWithBindVariable(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setIntValue(100); holder.setStrValue("10"); - testValueHolder("ValueHolder( $strValue : strValue, intValue == 10 * $strValue)", holder); + testValueHolder(runType, "ValueHolder( $strValue : strValue, intValue == 10 * $strValue)", holder); } - @Test - public void testMultiplyStringIntWithBindVariableCompareToBigDecimal() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyStringIntWithBindVariableCompareToBigDecimal(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setStrValue("10"); holder.setBdValue(new BigDecimal("-10")); - testValueHolder("ValueHolder( $strValue : strValue, bdValue == $strValue * -1 )", holder); + testValueHolder(runType, "ValueHolder( $strValue : strValue, bdValue == $strValue * -1 )", holder); } - @Test - public void testMultiplyStringIntWithBindVariableCompareToObject() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyStringIntWithBindVariableCompareToObject(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setStrValue("20"); holder.setObjValue("200"); - testValueHolder("ValueHolder( $strValue : strValue, objValue == $strValue * 10 )", holder); + testValueHolder(runType, "ValueHolder( $strValue : strValue, objValue == $strValue * 10 )", holder); } - @Test - public void testMultiplyStringBigDecimal() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyStringBigDecimal(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setIntValue(10); holder.setStrValue("20"); - testValueHolder("ValueHolder( intValue == strValue * 0.5B )", holder); + testValueHolder(runType, "ValueHolder( intValue == strValue * 0.5B )", holder); } - @Test - public void testMultiplyDecimalStringInt() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyDecimalStringInt(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setIntValue(5); holder.setStrValue("0.5"); - testValueHolder("ValueHolder( intValue == strValue * 10 )", holder); + testValueHolder(runType, "ValueHolder( intValue == strValue * 10 )", holder); } - @Test - public void testMultiplyDecimalStringBigDecimal() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyDecimalStringBigDecimal(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setIntValue(5); holder.setStrValue("0.5"); - testValueHolder("ValueHolder( intValue == strValue * 10B )", holder); + testValueHolder(runType, "ValueHolder( intValue == strValue * 10B )", holder); } - @Test - public void testMultiplyIntDecimalString() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyIntDecimalString(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setIntValue(5); holder.setStrValue("0.5"); - testValueHolder("ValueHolder( intValue == 10 * strValue )", holder); + testValueHolder(runType, "ValueHolder( intValue == 10 * strValue )", holder); } - @Test - public void testMultiplyStringDouble() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyStringDouble(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setIntValue(101); holder.setStrValue("10"); - testValueHolder("ValueHolder( intValue == strValue * 10.1 )", holder); + testValueHolder(runType, "ValueHolder( intValue == strValue * 10.1 )", holder); } - @Test - public void testAddStringIntWithBindVariableCompareToObject() { + @ParameterizedTest + @MethodSource("parameters") + public void testAddStringIntWithBindVariableCompareToObject(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setStrValue("20"); holder.setObjValue("2010"); // String concat - testValueHolder("ValueHolder( $strValue : strValue, objValue == $strValue + 10 )", holder); + testValueHolder(runType, "ValueHolder( $strValue : strValue, objValue == $strValue + 10 )", holder); } - @Test - public void testAddIntStringWithBindVariableCompareToObject() { + @ParameterizedTest + @MethodSource("parameters") + public void testAddIntStringWithBindVariableCompareToObject(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setStrValue("20"); holder.setObjValue("1020"); // String concat - testValueHolder("ValueHolder( $strValue : strValue, objValue == 10 + $strValue )", holder); + testValueHolder(runType, "ValueHolder( $strValue : strValue, objValue == 10 + $strValue )", holder); } - @Test - public void testAddStringIntWithBindVariableCompareToObjectNonNumeric() { + @ParameterizedTest + @MethodSource("parameters") + public void testAddStringIntWithBindVariableCompareToObjectNonNumeric(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setStrValue("ABC"); holder.setObjValue("ABC10"); // String concat - testValueHolder("ValueHolder( $strValue : strValue, objValue == $strValue + 10 )", holder); + testValueHolder(runType, "ValueHolder( $strValue : strValue, objValue == $strValue + 10 )", holder); } - @Test - public void testSubtractStringInt() { + @ParameterizedTest + @MethodSource("parameters") + public void testSubtractStringInt(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setIntValue(40); holder.setStrValue("50"); - testValueHolder("ValueHolder( intValue == strValue - 10 )", holder); + testValueHolder(runType, "ValueHolder( intValue == strValue - 10 )", holder); } - @Test - public void testModStringInt() { + @ParameterizedTest + @MethodSource("parameters") + public void testModStringInt(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setIntValue(2); holder.setStrValue("12"); - testValueHolder("ValueHolder( intValue == strValue % 10 )", holder); + testValueHolder(runType, "ValueHolder( intValue == strValue % 10 )", holder); } - @Test - public void testDivideStringInt() { + @ParameterizedTest + @MethodSource("parameters") + public void testDivideStringInt(RUN_TYPE runType) { ValueHolder holder = new ValueHolder(); holder.setIntValue(5); holder.setStrValue("50"); - testValueHolder("ValueHolder( intValue == strValue / 10 )", holder); + testValueHolder(runType, "ValueHolder( intValue == strValue / 10 )", holder); } - private void testValueHolder(String pattern, ValueHolder holder) { + private void testValueHolder(RUN_TYPE runType, String pattern, ValueHolder holder) { String str = "import " + ValueHolder.class.getCanonicalName() + "\n" + "rule R dialect \"mvel\" when\n" + @@ -170,7 +184,7 @@ private void testValueHolder(String pattern, ValueHolder holder) { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(holder); int fired = ksession.fireAllRules(); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OOPathTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OOPathTest.java index edba0258d31..037397677ad 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OOPathTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OOPathTest.java @@ -28,19 +28,17 @@ import org.drools.model.codegen.execmodel.domain.Man; import org.drools.model.codegen.execmodel.domain.Toy; import org.drools.model.codegen.execmodel.domain.Woman; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class OOPathTest extends BaseModelTest { - public OOPathTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testOOPath() { + @ParameterizedTest + @MethodSource("parameters") + public void testOOPath(RUN_TYPE runType) { final String str = "import org.drools.model.codegen.execmodel.domain.*;\n" + "global java.util.List list\n" + @@ -51,7 +49,7 @@ public void testOOPath() { " list.add( $man.getName() );\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -73,8 +71,9 @@ public void testOOPath() { assertThat(list).containsExactlyInAnyOrder("Bob"); } - @Test - public void testOOPathBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testOOPathBinding(RUN_TYPE runType) { final String str = "import org.drools.model.codegen.execmodel.domain.*;\n" + "global java.util.List list\n" + @@ -85,7 +84,7 @@ public void testOOPathBinding() { " list.add( $age );\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -102,8 +101,9 @@ public void testOOPathBinding() { assertThat(list).containsExactlyInAnyOrder(38); } - @Test - public void testReactiveOOPath() { + @ParameterizedTest + @MethodSource("parameters") + public void testReactiveOOPath(RUN_TYPE runType) { final String str = "import org.drools.model.codegen.execmodel.domain.*;\n" + "global java.util.List list\n" + @@ -114,7 +114,7 @@ public void testReactiveOOPath() { " list.add( $toy.getName() );\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -145,8 +145,9 @@ public void testReactiveOOPath() { } - @Test - public void testBackReferenceConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testBackReferenceConstraint(RUN_TYPE runType) { final String str = "import org.drools.model.codegen.execmodel.domain.*;\n" + "global java.util.List list\n" + @@ -157,7 +158,7 @@ public void testBackReferenceConstraint() { " list.add( $toy.getName() );\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -182,8 +183,9 @@ public void testBackReferenceConstraint() { assertThat(list).containsExactlyInAnyOrder("ball", "guitar"); } - @Test - public void testSimpleOOPathCast1() { + @ParameterizedTest + @MethodSource("parameters") + public void testSimpleOOPathCast1(RUN_TYPE runType) { final String str = "import org.drools.model.codegen.execmodel.domain.*;\n" + "global java.util.List list\n" + "\n" + @@ -193,7 +195,7 @@ public void testSimpleOOPathCast1() { " list.add( $man.getName() );\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -206,8 +208,9 @@ public void testSimpleOOPathCast1() { assertThat(list).containsExactlyInAnyOrder("Bob"); } - @Test - public void testSimpleOOPathCast2() { + @ParameterizedTest + @MethodSource("parameters") + public void testSimpleOOPathCast2(RUN_TYPE runType) { final String str = "import org.drools.model.codegen.execmodel.domain.*;\n" + "global java.util.List list\n" + "\n" + @@ -217,7 +220,7 @@ public void testSimpleOOPathCast2() { " list.add( $name );\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -230,8 +233,9 @@ public void testSimpleOOPathCast2() { assertThat(list).containsExactlyInAnyOrder("Bob"); } - @Test - public void testSimpleOOPathCast3() { + @ParameterizedTest + @MethodSource("parameters") + public void testSimpleOOPathCast3(RUN_TYPE runType) { final String str = "import org.drools.model.codegen.execmodel.domain.*;\n" + "global java.util.List list\n" + "\n" + @@ -241,7 +245,7 @@ public void testSimpleOOPathCast3() { " list.add( $name );\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -254,8 +258,9 @@ public void testSimpleOOPathCast3() { assertThat(list).containsExactlyInAnyOrder("Bob"); } - @Test - public void testOOPathMultipleConditions() { + @ParameterizedTest + @MethodSource("parameters") + public void testOOPathMultipleConditions(RUN_TYPE runType) { final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + @@ -267,7 +272,7 @@ public void testOOPathMultipleConditions() { " list.add( $address.getCity() );\n" + "end\n"; - KieSession kieSession = getKieSession(drl); + KieSession kieSession = getKieSession(runType, drl); List results = new ArrayList<>(); kieSession.setGlobal("list", results); @@ -283,8 +288,9 @@ public void testOOPathMultipleConditions() { assertThat(results).containsExactlyInAnyOrder("Big City"); } - @Test - public void testOOPathMultipleConditionsWithBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testOOPathMultipleConditionsWithBinding(RUN_TYPE runType) { final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + @@ -298,7 +304,7 @@ public void testOOPathMultipleConditionsWithBinding() { " list.add( $employee.getName() );\n" + "end\n"; - KieSession kieSession = getKieSession(drl); + KieSession kieSession = getKieSession(runType, drl); List results = new ArrayList<>(); kieSession.setGlobal("list", results); @@ -314,8 +320,9 @@ public void testOOPathMultipleConditionsWithBinding() { assertThat(results).containsExactlyInAnyOrder("Alice"); } - @Test - public void testOrConditionalElementNoBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testOrConditionalElementNoBinding(RUN_TYPE runType) { final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + @@ -331,7 +338,7 @@ public void testOrConditionalElementNoBinding() { " list.add( $employee.getName() );\n" + "end\n"; - KieSession kieSession = getKieSession(drl); + KieSession kieSession = getKieSession(runType, drl); List results = new ArrayList<>(); kieSession.setGlobal("list", results); @@ -347,8 +354,9 @@ public void testOrConditionalElementNoBinding() { assertThat(results).containsExactlyInAnyOrder("Bruno", "Alice"); } - @Test - public void testOrConditionalElement() { + @ParameterizedTest + @MethodSource("parameters") + public void testOrConditionalElement(RUN_TYPE runType) { final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + @@ -362,7 +370,7 @@ public void testOrConditionalElement() { " list.add( $address.getCity() );\n" + "end\n"; - KieSession kieSession = getKieSession(drl); + KieSession kieSession = getKieSession(runType, drl); List results = new ArrayList<>(); kieSession.setGlobal("list", results); @@ -378,8 +386,9 @@ public void testOrConditionalElement() { assertThat(results).containsExactlyInAnyOrder("Big City", "Small City"); } - @Test - public void testOrConstraintNoBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testOrConstraintNoBinding(RUN_TYPE runType) { final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + @@ -392,7 +401,7 @@ public void testOrConstraintNoBinding() { " list.add( $emp.getName() );\n" + "end\n"; - KieSession kieSession = getKieSession(drl); + KieSession kieSession = getKieSession(runType, drl); List results = new ArrayList<>(); kieSession.setGlobal("list", results); @@ -408,8 +417,9 @@ public void testOrConstraintNoBinding() { assertThat(results).containsExactlyInAnyOrder("Bruno", "Alice"); } - @Test - public void testOrConstraintWithJoin() { + @ParameterizedTest + @MethodSource("parameters") + public void testOrConstraintWithJoin(RUN_TYPE runType) { final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + @@ -422,7 +432,7 @@ public void testOrConstraintWithJoin() { " list.add( $address.getCity() );\n" + "end\n"; - KieSession kieSession = getKieSession(drl); + KieSession kieSession = getKieSession(runType, drl); List results = new ArrayList<>(); kieSession.setGlobal("list", results); @@ -438,8 +448,9 @@ public void testOrConstraintWithJoin() { assertThat(results).containsExactlyInAnyOrder("Big City", "Small City"); } - @Test - public void testOrConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testOrConstraint(RUN_TYPE runType) { final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + @@ -452,7 +463,7 @@ public void testOrConstraint() { " list.add( $address.getCity() );\n" + "end\n"; - KieSession kieSession = getKieSession(drl); + KieSession kieSession = getKieSession(runType, drl); List results = new ArrayList<>(); kieSession.setGlobal("list", results); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OnlyExecModelTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OnlyExecModelTest.java index 8c36c433a9e..99193325f11 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OnlyExecModelTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OnlyExecModelTest.java @@ -18,24 +18,14 @@ */ package org.drools.model.codegen.execmodel; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import java.util.stream.Stream; + import static org.drools.model.codegen.execmodel.BaseModelTest.RUN_TYPE.PATTERN_DSL; -@RunWith(Parameterized.class) public abstract class OnlyExecModelTest extends BaseModelTest { - public OnlyExecModelTest(RUN_TYPE testRunType) { - super(testRunType); - } - - final static Object[] ONLY_EXEC_MODEL = { - PATTERN_DSL, - }; - - @Parameterized.Parameters(name = "{0}") - public static Object[] params() { - return ONLY_EXEC_MODEL; + public static Stream parameters() { + return Stream.of(PATTERN_DSL); } } diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OnlyPatternTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OnlyPatternTest.java index 3c89f4d35ca..0f5e553b1ac 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OnlyPatternTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OnlyPatternTest.java @@ -18,25 +18,13 @@ */ package org.drools.model.codegen.execmodel; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - import static org.drools.model.codegen.execmodel.BaseModelTest.RUN_TYPE.PATTERN_DSL; -@RunWith(Parameterized.class) -public abstract class OnlyPatternTest extends BaseModelTest { +import java.util.stream.Stream; - public OnlyPatternTest(RUN_TYPE testRunType) { - super(testRunType); - } - - final static Object[] EXCLUDE_FLOW = { - RUN_TYPE.STANDARD_FROM_DRL, - PATTERN_DSL, - }; +public abstract class OnlyPatternTest extends BaseModelTest { - @Parameterized.Parameters(name = "{0}") - public static Object[] params() { - return EXCLUDE_FLOW; + public static Stream parameters() { + return Stream.of(RUN_TYPE.STANDARD_FROM_DRL, PATTERN_DSL); } } diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OrTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OrTest.java index 242e13f7ab8..c041a4f5f42 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OrTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/OrTest.java @@ -21,7 +21,8 @@ import org.drools.model.codegen.execmodel.domain.Address; import org.drools.model.codegen.execmodel.domain.Employee; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.builder.Results; import org.kie.api.runtime.KieSession; @@ -32,12 +33,9 @@ public class OrTest extends BaseModelTest { - public OrTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testOr() { + @ParameterizedTest + @MethodSource("parameters") + public void testOr(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -50,7 +48,7 @@ public void testOr() { " System.out.println(\"Found: \" + $s);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( "Mario" ); ksession.insert( new Person( "Mark", 37 ) ); @@ -59,8 +57,9 @@ public void testOr() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testOrWhenStringFirst() { + @ParameterizedTest + @MethodSource("parameters") + public void testOrWhenStringFirst(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + @@ -74,7 +73,7 @@ public void testOrWhenStringFirst() { " System.out.println(\"Found: \" + $s.getClass());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( "Go" ); ksession.insert( new Person( "Mark", 37 ) ); @@ -84,8 +83,9 @@ public void testOrWhenStringFirst() { } - @Test - public void testOrWithBetaIndex() { + @ParameterizedTest + @MethodSource("parameters") + public void testOrWithBetaIndex(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -98,7 +98,7 @@ public void testOrWithBetaIndex() { " System.out.println(\"Found: \" + $s);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert("Mario"); ksession.insert(new Person("Mark", 37)); @@ -107,8 +107,9 @@ public void testOrWithBetaIndex() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testOrWithBetaIndexOffset() { + @ParameterizedTest + @MethodSource("parameters") + public void testOrWithBetaIndexOffset(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -122,7 +123,7 @@ public void testOrWithBetaIndexOffset() { " System.out.println(\"Found: \" + $s);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert("Mario"); ksession.insert(new Person("Mark", 37)); @@ -131,8 +132,9 @@ public void testOrWithBetaIndexOffset() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testOrConditional() { + @ParameterizedTest + @MethodSource("parameters") + public void testOrConditional(RUN_TYPE runType) { final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + @@ -146,7 +148,7 @@ public void testOrConditional() { " list.add( $address.getCity() );\n" + "end\n"; - KieSession kieSession = getKieSession(drl); + KieSession kieSession = getKieSession(runType, drl); List results = new ArrayList<>(); kieSession.setGlobal("list", results); @@ -162,8 +164,9 @@ public void testOrConditional() { assertThat(results).containsExactlyInAnyOrder("Big City", "Small City"); } - @Test - public void testOrConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testOrConstraint(RUN_TYPE runType) { final String drl = "import " + Employee.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + @@ -175,7 +178,7 @@ public void testOrConstraint() { " list.add( $address.getCity() );\n" + "end\n"; - KieSession kieSession = getKieSession(drl); + KieSession kieSession = getKieSession(runType, drl); List results = new ArrayList<>(); kieSession.setGlobal("list", results); @@ -191,8 +194,9 @@ public void testOrConstraint() { assertThat(results).containsExactlyInAnyOrder("Big City", "Small City"); } - @Test - public void testOrWithDuplicatedVariables() { + @ParameterizedTest + @MethodSource("parameters") + public void testOrWithDuplicatedVariables(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.util.List list\n" + @@ -210,7 +214,7 @@ public void testOrWithDuplicatedVariables() { " list.add( $p + \" has \" + $age + \" years\");\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("list", results); @@ -227,8 +231,9 @@ public void testOrWithDuplicatedVariables() { assertThat(results.contains("Mario has 40 years")).isTrue(); } - @Test - public void generateErrorForEveryFieldInRHSNotDefinedInLHS() { + @ParameterizedTest + @MethodSource("parameters") + public void generateErrorForEveryFieldInRHSNotDefinedInLHS(RUN_TYPE runType) { // JBRULES-3390 final String drl1 = "package org.drools.compiler.integrationtests.operators; \n" + "declare B\n" + @@ -245,16 +250,17 @@ public void generateErrorForEveryFieldInRHSNotDefinedInLHS() { " System.out.println($bField);\n" + "end\n"; - Results results = getCompilationResults(drl1); + Results results = getCompilationResults(runType, drl1); assertThat(results.getMessages().isEmpty()).isFalse(); } - private Results getCompilationResults( String drl ) { - return createKieBuilder( drl ).getResults(); + private Results getCompilationResults( RUN_TYPE runType, String drl ) { + return createKieBuilder(runType, drl ).getResults(); } - @Test - public void testMultipleFiringWithOr() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleFiringWithOr(RUN_TYPE runType) { // DROOLS-7466 final String str = "rule R when\n" + @@ -264,7 +270,7 @@ public void testMultipleFiringWithOr() { "then\n" + "end \n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ksession.fireAllRules()).isEqualTo(2); } } diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PackagesIsolationTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PackagesIsolationTest.java index 41c912e99a1..e1d99b0e546 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PackagesIsolationTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PackagesIsolationTest.java @@ -20,21 +20,19 @@ import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class PackagesIsolationTest extends BaseModelTest { - public PackagesIsolationTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - public static class HashSet { } - @Test - public void testDoNotMixImports() { + @ParameterizedTest + @MethodSource("parameters") + public void testDoNotMixImports(RUN_TYPE runType) { // DROOLS-5390 String str2 = "package mypkg2\n" + @@ -47,11 +45,12 @@ public void testDoNotMixImports() { " list.add(\"R2\");\n" + "end"; - check( str2 ); + check( runType, str2 ); } - @Test - public void testImportWildcard() { + @ParameterizedTest + @MethodSource("parameters") + public void testImportWildcard(RUN_TYPE runType) { String str2 = "package mypkg2\n" + "import mypkg1.*;\n" + @@ -62,11 +61,12 @@ public void testImportWildcard() { " list.add(\"R2\");\n" + "end"; - check( str2 ); + check( runType, str2 ); } - @Test - public void testImportType() { + @ParameterizedTest + @MethodSource("parameters") + public void testImportType(RUN_TYPE runType) { String str2 = "package mypkg2\n" + "import mypkg1.MyPojo;\n" + @@ -77,10 +77,10 @@ public void testImportType() { " list.add(\"R2\");\n" + "end"; - check( str2 ); + check( runType, str2 ); } - private void check( String str2 ) { + private void check( RUN_TYPE runType, String str2 ) { String str1 = "package mypkg1\n" + "global java.util.List list\n" + @@ -92,7 +92,7 @@ private void check( String str2 ) { " list.add(\"R1\");\n" + "end"; - KieSession ksession = getKieSession( str1, str2 ); + KieSession ksession = getKieSession(runType, str1, str2); java.util.List list = new java.util.ArrayList<>(); ksession.setGlobal( "list", list ); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PrimitiveConversionErrorsTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PrimitiveConversionErrorsTest.java index 0b335efb372..52dacae6c6b 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PrimitiveConversionErrorsTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PrimitiveConversionErrorsTest.java @@ -20,14 +20,13 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.model.codegen.ExecutableModelProject; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; @@ -39,9 +38,9 @@ import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; // DROOLS-6506 -@RunWith(Parameterized.class) public class PrimitiveConversionErrorsTest { private static final String RULE_TEMPLATE = "" + @@ -66,63 +65,49 @@ public class PrimitiveConversionErrorsTest { " $values.add($value);\n" + "end"; - @Parameterized.Parameters(name = "value{0} != {2}: Method Returns {0}, test against {1}") - public static Collection data() { - Object[][] data = new Object[][]{ - {Float.class, Float.class, 4f, 5f, 6f}, - {Float.class, Double.class, 4d, 5f, 6f}, - {Float.class, Integer.class, 4, 5f, 6f}, - {Float.class, Short.class, (short) 4, 5f, 6f}, - {Float.class, Byte.class, (byte) 4, 5f, 6f}, - - {Double.class, Float.class, 4f, 5d, 6d}, - {Double.class, Double.class, 4d, 5d, 6d}, - {Double.class, Integer.class, 4, 5d, 6d}, - {Double.class, Short.class, (short) 4, 5d, 6d}, - {Double.class, Byte.class, (byte) 4, 5d, 6d}, - - {Integer.class, Float.class, 4f, 5, 6}, - {Integer.class, Double.class, 4d, 5, 6}, - {Integer.class, Integer.class, 4, 5, 6}, - {Integer.class, Short.class, (short) 4, 5, 6}, - {Integer.class, Byte.class, (byte) 4, 5, 6}, - - {Short.class, Float.class, 4f, (short) 5, (short) 6}, - {Short.class, Double.class, 4d, (short) 5, (short) 6}, - {Short.class, Integer.class, 4, (short) 5, (short) 6}, - {Short.class, Short.class, (short) 4, (short) 5, (short) 6}, - {Short.class, Byte.class, (byte) 4, (short) 5, (short) 6}, - - {Byte.class, Float.class, 4f, (byte) 5, (byte) 6}, - {Byte.class, Double.class, 4d, (byte) 5, (byte) 6}, - {Byte.class, Integer.class, 4, (byte) 5, (byte) 6}, - {Byte.class, Short.class, (short) 4, (byte) 5, (byte) 6}, - {Byte.class, Byte.class, (byte) 4, (byte) 5, (byte) 6}, - }; - return Arrays.asList(data); + public static Stream data() { + return Stream.of( + arguments(Float.class, Float.class, 4f, 5f, 6f), + arguments(Float.class, Double.class, 4d, 5f, 6f), + arguments(Float.class, Integer.class, 4, 5f, 6f), + arguments(Float.class, Short.class, (short) 4, 5f, 6f), + arguments(Float.class, Byte.class, (byte) 4, 5f, 6f), + + arguments(Double.class, Float.class, 4f, 5d, 6d), + arguments(Double.class, Double.class, 4d, 5d, 6d), + arguments(Double.class, Integer.class, 4, 5d, 6d), + arguments(Double.class, Short.class, (short) 4, 5d, 6d), + arguments(Double.class, Byte.class, (byte) 4, 5d, 6d), + + arguments(Integer.class, Float.class, 4f, 5, 6), + arguments(Integer.class, Double.class, 4d, 5, 6), + arguments(Integer.class, Integer.class, 4, 5, 6), + arguments(Integer.class, Short.class, (short) 4, 5, 6), + arguments(Integer.class, Byte.class, (byte) 4, 5, 6), + + arguments(Short.class, Float.class, 4f, (short) 5, (short) 6), + arguments(Short.class, Double.class, 4d, (short) 5, (short) 6), + arguments(Short.class, Integer.class, 4, (short) 5, (short) 6), + arguments(Short.class, Short.class, (short) 4, (short) 5, (short) 6), + arguments(Short.class, Byte.class, (byte) 4, (short) 5, (short) 6), + + arguments(Byte.class, Float.class, 4f, (byte) 5, (byte) 6), + arguments(Byte.class, Double.class, 4d, (byte) 5, (byte) 6), + arguments(Byte.class, Integer.class, 4, (byte) 5, (byte) 6), + arguments(Byte.class, Short.class, (short) 4, (byte) 5, (byte) 6), + arguments(Byte.class, Byte.class, (byte) 4, (byte) 5, (byte) 6)); } - private final Object valueCheck; - private final Class valueType; - private final Object valueA; - private final Object valueB; + @ParameterizedTest(name="value{0} != {2}: Method Returns {0}, test against {1}") + @MethodSource("data") + public void withExecutableModel(Class valueType, Class valueCheckType, Object valueCheck, Object valueA, Object valueB) throws IOException { - public PrimitiveConversionErrorsTest(Class valueType, Class valueCheckType, Object valueCheck, Object valueA, Object valueB) { - this.valueCheck = valueCheck; - this.valueType = valueType; - this.valueA = valueA; - this.valueB = valueB; - } - - @Test - public void withExecutableModel() throws IOException { - - KieBase kbase = loadRules(this.valueType, this.valueCheck, true); + KieBase kbase = loadRules(valueType, valueCheck, true); KieSession session = kbase.newKieSession(); List values = new ArrayList<>(); - ClassWithValue ca = makeClassWithValue(this.valueA); - ClassWithValue cb = makeClassWithValue(this.valueB); + ClassWithValue ca = makeClassWithValue(valueA); + ClassWithValue cb = makeClassWithValue(valueB); session.insert(values); session.insert(ca); @@ -131,19 +116,20 @@ public void withExecutableModel() throws IOException { session.fireAllRules(); assertThat(values.size()).isEqualTo(2); - assertThat(values.contains(this.valueA)).isTrue(); - assertThat(values.contains(this.valueB)).isTrue(); + assertThat(values.contains(valueA)).isTrue(); + assertThat(values.contains(valueB)).isTrue(); } - @Test - public void withoutExecutableModel() throws IOException { + @ParameterizedTest(name="value{0} != {2}: Method Returns {0}, test against {1}") + @MethodSource("data") + public void withoutExecutableModel(Class valueType, Class valueCheckType, Object valueCheck, Object valueA, Object valueB) throws IOException { - KieBase kbase = loadRules(this.valueType, this.valueCheck, false); + KieBase kbase = loadRules(valueType, valueCheck, false); KieSession session = kbase.newKieSession(); List values = new ArrayList<>(); - ClassWithValue ca = makeClassWithValue(this.valueA); - ClassWithValue cb = makeClassWithValue(this.valueB); + ClassWithValue ca = makeClassWithValue(valueA); + ClassWithValue cb = makeClassWithValue(valueB); session.insert(values); session.insert(ca); @@ -152,8 +138,8 @@ public void withoutExecutableModel() throws IOException { session.fireAllRules(); assertThat(values.size()).isEqualTo(2); - assertThat(values.contains(this.valueA)).isTrue(); - assertThat(values.contains(this.valueB)).isTrue(); + assertThat(values.contains(valueA)).isTrue(); + assertThat(values.contains(valueB)).isTrue(); } private static KieBase loadRules(Class valueType, Object value, boolean useExecutable) throws IOException { diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PropertyReactivityMatrixTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PropertyReactivityMatrixTest.java index d4742f74e93..070b929db58 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PropertyReactivityMatrixTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PropertyReactivityMatrixTest.java @@ -19,15 +19,19 @@ package org.drools.model.codegen.execmodel; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; +import org.drools.model.codegen.execmodel.BaseModelTest.RUN_TYPE; import org.drools.util.StringUtils; -import org.junit.Test; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; +import static org.drools.model.codegen.execmodel.BaseModelTest.RUN_TYPE.PATTERN_DSL; +import static org.junit.jupiter.params.provider.Arguments.arguments; public class PropertyReactivityMatrixTest extends BaseModelTest { @@ -36,23 +40,23 @@ enum Dialect { MVEL } - private Dialect dialect; - @Parameters(name = "{0} {1}") - public static Collection parameters() { - List parameterData = new ArrayList(); + final static Object[] PLAIN = { + RUN_TYPE.STANDARD_FROM_DRL, + PATTERN_DSL, + }; + + + public static Stream parametersData() { + List parameterData = new ArrayList(); for (Object runType : PLAIN) { for (Dialect dialect : Dialect.values()) { - parameterData.add(new Object[]{runType, dialect}); + parameterData.add(arguments(runType, dialect)); } } - return parameterData; + return Stream.of(parameterData.toArray(new Arguments[0])); } - public PropertyReactivityMatrixTest(RUN_TYPE testRunType, Dialect testDialect) { - super(testRunType); - this.dialect = testDialect; - } public static class Fact { @@ -85,7 +89,7 @@ public void setValue2(int value2) { } } - private String setValueStatement(String property, int value) { + private String setValueStatement(Dialect dialect, String property, int value) { if (dialect == Dialect.JAVA) { return "set" + StringUtils.ucFirst(property) + "(" + value + ");"; } else { @@ -93,123 +97,136 @@ private String setValueStatement(String property, int value) { } } - @Test - public void modifyInsideIfTrueBlock_shouldTriggerReactivity() { - statementInsideBlock_shouldTriggerReactivity(" if (true) {\n" + + @ParameterizedTest + @MethodSource("parametersData") + public void modifyInsideIfTrueBlock_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { + statementInsideBlock_shouldTriggerReactivity(runType, dialect, " if (true) {\n" + " modify($fact) {\n" + - " " + setValueStatement("value1", 2) + "\n" + + " " + setValueStatement(dialect, "value1", 2) + "\n" + " }\n" + " }\n"); } - @Test - public void modifyInsideForBlock_shouldTriggerReactivity() { - statementInsideBlock_shouldTriggerReactivity(" for (int i = 0; i < 1; i++) {\n" + + @ParameterizedTest + @MethodSource("parametersData") + public void modifyInsideForBlock_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { + statementInsideBlock_shouldTriggerReactivity(runType, dialect, " for (int i = 0; i < 1; i++) {\n" + " modify($fact) {\n" + - " " + setValueStatement("value1", 2) + "\n" + + " " + setValueStatement(dialect, "value1", 2) + "\n" + " }\n" + " }\n"); } - @Test - public void modifyInsideCommentedIfTrueBlock_shouldTriggerReactivity() { - statementInsideBlock_shouldTriggerReactivity(" // if (true) {\n" + + @ParameterizedTest + @MethodSource("parametersData") + public void modifyInsideCommentedIfTrueBlock_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { + statementInsideBlock_shouldTriggerReactivity(runType, dialect, " // if (true) {\n" + " modify($fact) {\n" + - " " + setValueStatement("value1", 2) + "\n" + + " " + setValueStatement(dialect, "value1", 2) + "\n" + " }\n" + " // }\n"); } - @Test - public void modifyInsideIfBlockInsideAndOutsideAssignment_shouldTriggerReactivity() { - statementInsideBlock_shouldTriggerReactivity(" $fact." + setValueStatement("value1", 2) + "\n" + + @ParameterizedTest + @MethodSource("parametersData") + public void modifyInsideIfBlockInsideAndOutsideAssignment_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { + statementInsideBlock_shouldTriggerReactivity(runType, dialect, " $fact." + setValueStatement(dialect, "value1", 2) + "\n" + " if (true) {\n" + " modify($fact) {\n" + - " " + setValueStatement("value2", 2) + "\n" + + " " + setValueStatement(dialect, "value2", 2) + "\n" + " }\n" + " }"); } - @Test - public void updateInsideIfTrueBlock_shouldTriggerReactivity() { - statementInsideBlock_shouldTriggerReactivity(" if (true) {\n" + - " $fact." + setValueStatement("value1", 2) + ";\n" + + @ParameterizedTest + @MethodSource("parametersData") + public void updateInsideIfTrueBlock_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { + statementInsideBlock_shouldTriggerReactivity(runType, dialect, " if (true) {\n" + + " $fact." + setValueStatement(dialect, "value1", 2) + ";\n" + " update($fact);\n" + " }\n"); } - @Test - public void updateInsideForBlock_shouldTriggerReactivity() { - statementInsideBlock_shouldTriggerReactivity(" for (int i = 0; i < 1; i++) {\n" + - " $fact." + setValueStatement("value1", 2) + "\n" + + @ParameterizedTest + @MethodSource("parametersData") + public void updateInsideForBlock_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { + statementInsideBlock_shouldTriggerReactivity(runType, dialect, " for (int i = 0; i < 1; i++) {\n" + + " $fact." + setValueStatement(dialect, "value1", 2) + "\n" + " update($fact);\n" + " }\n"); } - @Test - public void updateInsideCommentedIfTrueBlock_shouldTriggerReactivity() { - statementInsideBlock_shouldTriggerReactivity(" // if (true) {\n" + - " $fact." + setValueStatement("value1", 2) + "\n" + + @ParameterizedTest + @MethodSource("parametersData") + public void updateInsideCommentedIfTrueBlock_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { + statementInsideBlock_shouldTriggerReactivity(runType, dialect, " // if (true) {\n" + + " $fact." + setValueStatement(dialect, "value1", 2) + "\n" + " update($fact);\n" + " // }\n"); } - @Test - public void updateInsideIfBlockInsideAndOutsideAssignment_shouldTriggerReactivity() { - statementInsideBlock_shouldTriggerReactivity(" $fact." + setValueStatement("value1", 2) + "\n" + + @ParameterizedTest + @MethodSource("parametersData") + public void updateInsideIfBlockInsideAndOutsideAssignment_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { + statementInsideBlock_shouldTriggerReactivity(runType, dialect, " $fact." + setValueStatement(dialect, "value1", 2) + "\n" + " if (true) {\n" + - " $fact." + setValueStatement("value2", 2) + "\n" + + " $fact." + setValueStatement(dialect, "value2", 2) + "\n" + " update($fact);\n" + " }"); } - @Test - public void assignmentAfterModify_shouldTriggerReactivity() { + @ParameterizedTest + @MethodSource("parametersData") + public void assignmentAfterModify_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { // DROOLS-7497 - statementInsideBlock_shouldTriggerReactivity(" modify($fact) {\n" + - " " + setValueStatement("value2", 2) + "\n" + + statementInsideBlock_shouldTriggerReactivity(runType, dialect, " modify($fact) {\n" + + " " + setValueStatement(dialect, "value2", 2) + "\n" + " }\n" + - " $fact." + setValueStatement("value1", 2) + "\n"); + " $fact." + setValueStatement(dialect, "value1", 2) + "\n"); } - @Test - public void assignmentBeforeAndAfterModify_shouldTriggerReactivity() { + @ParameterizedTest + @MethodSource("parametersData") + public void assignmentBeforeAndAfterModify_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { // DROOLS-7497 - statementInsideBlock_shouldTriggerReactivity(" $fact." + setValueStatement("value2", 2) + "\n" + + statementInsideBlock_shouldTriggerReactivity(runType, dialect, " $fact." + setValueStatement(dialect, "value2", 2) + "\n" + " modify($fact) {\n" + " }\n" + - " $fact." + setValueStatement("value1", 2) + "\n"); + " $fact." + setValueStatement(dialect, "value1", 2) + "\n"); } - @Test - public void assignmentAfterIfBlockModify_shouldTriggerReactivity() { + @ParameterizedTest + @MethodSource("parametersData") + public void assignmentAfterIfBlockModify_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { // DROOLS-7497 - statementInsideBlock_shouldTriggerReactivity(" if (true) {\n" + + statementInsideBlock_shouldTriggerReactivity(runType, dialect, " if (true) {\n" + " modify($fact) {\n" + - " " + setValueStatement("value2", 2) + "\n" + + " " + setValueStatement(dialect, "value2", 2) + "\n" + " }\n" + " }\n" + - " $fact." + setValueStatement("value1", 2) + "\n"); + " $fact." + setValueStatement(dialect, "value1", 2) + "\n"); } - @Test - public void assignmentBeforeAndAfterUpdate_shouldTriggerReactivity() { + @ParameterizedTest + @MethodSource("parametersData") + public void assignmentBeforeAndAfterUpdate_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { // DROOLS-7497 - statementInsideBlock_shouldTriggerReactivity(" $fact." + setValueStatement("value2", 2) + "\n" + + statementInsideBlock_shouldTriggerReactivity(runType, dialect, " $fact." + setValueStatement(dialect, "value2", 2) + "\n" + " update($fact);\n" + - " $fact." + setValueStatement("value1", 2) + "\n"); + " $fact." + setValueStatement(dialect, "value1", 2) + "\n"); } - @Test - public void assignmentAfterIfBlockUpdate_shouldTriggerReactivity() { + @ParameterizedTest + @MethodSource("parametersData") + public void assignmentAfterIfBlockUpdate_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { // DROOLS-7497 - statementInsideBlock_shouldTriggerReactivity(" if (true) {\n" + + statementInsideBlock_shouldTriggerReactivity(runType, dialect, " if (true) {\n" + " update($fact);\n" + " }\n" + - " $fact." + setValueStatement("value1", 2) + "\n"); + " $fact." + setValueStatement(dialect, "value1", 2) + "\n"); } - private void statementInsideBlock_shouldTriggerReactivity(String rhs) { + private void statementInsideBlock_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect, String rhs) { final String str = "import " + Fact.class.getCanonicalName() + ";\n" + "dialect \"" + dialect.name().toLowerCase() + "\"\n" + @@ -227,7 +244,7 @@ private void statementInsideBlock_shouldTriggerReactivity(String rhs) { " results.add(\"R2 fired\");\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -239,11 +256,12 @@ private void statementInsideBlock_shouldTriggerReactivity(String rhs) { .containsExactly("R2 fired"); } - @Test - public void modifyInsideIfFalseAndTrueBlock_shouldTriggerReactivity() { + @ParameterizedTest + @MethodSource("parametersData") + public void modifyInsideIfFalseAndTrueBlock_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { // DROOLS-7493 - statementInsideBlock_shouldTriggerReactivityWithLoop(" if (false) {\n" + - " $fact." + setValueStatement("value1", 2) + "\n" + // this line is not executed, but analyzed as a property reactivity + statementInsideBlock_shouldTriggerReactivityWithLoop(runType, dialect, " if (false) {\n" + + " $fact." + setValueStatement(dialect, "value1", 2) + "\n" + // this line is not executed, but analyzed as a property reactivity " }\n" + " if (true) {\n" + " modify($fact) {\n" + @@ -251,17 +269,18 @@ public void modifyInsideIfFalseAndTrueBlock_shouldTriggerReactivity() { " }\n"); } - @Test - public void updateInsideIfFalseAndTrueBlock_shouldTriggerReactivity() { - statementInsideBlock_shouldTriggerReactivityWithLoop(" if (false) {\n" + - " $fact." + setValueStatement("value1", 2) + "\n" + // this line is not executed, but analyzed as a property reactivity + @ParameterizedTest + @MethodSource("parametersData") + public void updateInsideIfFalseAndTrueBlock_shouldTriggerReactivity(RUN_TYPE runType, Dialect dialect) { + statementInsideBlock_shouldTriggerReactivityWithLoop(runType, dialect, " if (false) {\n" + + " $fact." + setValueStatement(dialect, "value1", 2) + "\n" + // this line is not executed, but analyzed as a property reactivity " }\n" + " if (true) {\n" + " update($fact);\n" + " }\n"); } - private void statementInsideBlock_shouldTriggerReactivityWithLoop(String rhs) { + private void statementInsideBlock_shouldTriggerReactivityWithLoop(RUN_TYPE runType, Dialect dialect, String rhs) { final String str = "import " + Fact.class.getCanonicalName() + ";\n" + "dialect \"" + dialect.name().toLowerCase() + "\"\n" + @@ -273,7 +292,7 @@ private void statementInsideBlock_shouldTriggerReactivityWithLoop(String rhs) { rhs + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -285,25 +304,27 @@ private void statementInsideBlock_shouldTriggerReactivityWithLoop(String rhs) { .isEqualTo(10); } - @Test - public void modifyInsideIfFalseBlock_shouldNotTriggerReactivity() { + @ParameterizedTest + @MethodSource("parametersData") + public void modifyInsideIfFalseBlock_shouldNotTriggerReactivity(RUN_TYPE runType, Dialect dialect) { // DROOLS-7493 - statementInsideIfFalseBlock_shouldNotTriggerReactivityNorSelfLoop(" if (false) {\n" + + statementInsideIfFalseBlock_shouldNotTriggerReactivityNorSelfLoop(runType, dialect, " if (false) {\n" + " modify($fact) {\n" + - " " + setValueStatement("value1", 2) + "\n" + + " " + setValueStatement(dialect, "value1", 2) + "\n" + " }\n" + " }\n"); } - @Test - public void updateInsideIfFalseBlock_shouldNotTriggerReactivity() { - statementInsideIfFalseBlock_shouldNotTriggerReactivityNorSelfLoop(" if (false) {\n" + - " $fact." + setValueStatement("value1", 2) + "\n" + + @ParameterizedTest + @MethodSource("parametersData") + public void updateInsideIfFalseBlock_shouldNotTriggerReactivity(RUN_TYPE runType, Dialect dialect) { + statementInsideIfFalseBlock_shouldNotTriggerReactivityNorSelfLoop(runType, dialect, " if (false) {\n" + + " $fact." + setValueStatement(dialect, "value1", 2) + "\n" + " update($fact);\n" + " }\n"); } - private void statementInsideIfFalseBlock_shouldNotTriggerReactivityNorSelfLoop(String rhs) { + private void statementInsideIfFalseBlock_shouldNotTriggerReactivityNorSelfLoop(RUN_TYPE runType, Dialect dialect, String rhs) { final String str = "import " + Fact.class.getCanonicalName() + ";\n" + "dialect \"" + dialect.name().toLowerCase() + "\"\n" + @@ -321,7 +342,7 @@ private void statementInsideIfFalseBlock_shouldNotTriggerReactivityNorSelfLoop(S " results.add(\"R2 fired\");\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PropertyReactivityTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PropertyReactivityTest.java index 66b9b8549c4..8c16a9c5a51 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PropertyReactivityTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PropertyReactivityTest.java @@ -30,8 +30,9 @@ import org.drools.model.codegen.execmodel.domain.Pet; import org.drools.model.codegen.execmodel.domain.Result; import org.drools.model.codegen.execmodel.domain.VariousCasePropFact; - -import org.junit.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.Message.Level; import org.kie.api.definition.type.Modifies; @@ -42,12 +43,9 @@ public class PropertyReactivityTest extends BaseModelTest { - public PropertyReactivityTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testPropertyReactivity() { + @ParameterizedTest + @MethodSource("parameters") + public void testPropertyReactivity(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -57,7 +55,7 @@ public void testPropertyReactivity() { " modify($p) { setAge( $p.getAge()+1 ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -66,8 +64,9 @@ public void testPropertyReactivity() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testPropertyReactivityWithUpdate() { + @ParameterizedTest + @MethodSource("parameters") + public void testPropertyReactivityWithUpdate(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -78,7 +77,7 @@ public void testPropertyReactivityWithUpdate() { " update($p);\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -87,8 +86,9 @@ public void testPropertyReactivityWithUpdate() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testPropertyReactivityMvel() { + @ParameterizedTest + @MethodSource("parameters") + public void testPropertyReactivityMvel(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -98,7 +98,7 @@ public void testPropertyReactivityMvel() { " modify($p) { age = $p.age+1 };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -107,8 +107,9 @@ public void testPropertyReactivityMvel() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testPropertyReactivityMvelWithUpdate() { + @ParameterizedTest + @MethodSource("parameters") + public void testPropertyReactivityMvelWithUpdate(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -119,7 +120,7 @@ public void testPropertyReactivityMvelWithUpdate() { " update($p);\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -128,8 +129,9 @@ public void testPropertyReactivityMvelWithUpdate() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testWatch() { + @ParameterizedTest + @MethodSource("parameters") + public void testWatch(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -139,7 +141,7 @@ public void testWatch() { " modify($p) { setAge( $p.getAge()+1 ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -148,8 +150,9 @@ public void testWatch() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testWatchAll() { + @ParameterizedTest + @MethodSource("parameters") + public void testWatchAll(RUN_TYPE runType) { // DROOLS-4509 final String str = @@ -161,7 +164,7 @@ public void testWatchAll() { " modify($p) { setAge( $p.getAge()+1 ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -170,8 +173,9 @@ public void testWatchAll() { assertThat(p.getAge()).isEqualTo(50); } - @Test - public void testWatchAllBeforeBeta() { + @ParameterizedTest + @MethodSource("parameters") + public void testWatchAllBeforeBeta(RUN_TYPE runType) { // DROOLS-4509 final String str = @@ -185,7 +189,7 @@ public void testWatchAllBeforeBeta() { " modify($p) { setAge( $p.getAge()+1 ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -195,8 +199,9 @@ public void testWatchAllBeforeBeta() { assertThat(p.getAge()).isEqualTo(50); } - @Test - public void testWatchAllBeforeFrom() { + @ParameterizedTest + @MethodSource("parameters") + public void testWatchAllBeforeFrom(RUN_TYPE runType) { // DROOLS-4509 final String str = @@ -210,7 +215,7 @@ public void testWatchAllBeforeFrom() { " modify($p) { setAge( $p.getAge()+1 ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); p.addAddress( new Address( "Milan" ) ); @@ -221,8 +226,9 @@ public void testWatchAllBeforeFrom() { assertThat(p.getAge()).isEqualTo(50); } - @Test - public void testImplicitWatch() { + @ParameterizedTest + @MethodSource("parameters") + public void testImplicitWatch(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -234,7 +240,7 @@ public void testImplicitWatch() { " $r.setValue($p2.getName() + \" is older than \" + $p1.getName());\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert(result); @@ -262,8 +268,9 @@ public void testImplicitWatch() { assertThat(result.getValue()).isEqualTo("Edson is older than Mark"); } - @Test - public void testImplicitWatchWithDeclaration() { + @ParameterizedTest + @MethodSource("parameters") + public void testImplicitWatchWithDeclaration(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -275,7 +282,7 @@ public void testImplicitWatchWithDeclaration() { " $r.setValue($p2.getName() + \" is older than \" + $p1.getName());\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert(result); @@ -303,8 +310,9 @@ public void testImplicitWatchWithDeclaration() { assertThat(result.getValue()).isEqualTo("Edson is older than Mark"); } - @Test - public void testImmutableField() { + @ParameterizedTest + @MethodSource("parameters") + public void testImmutableField(RUN_TYPE runType) { final String str = "declare Integer @propertyReactive end\n" + "declare Long @propertyReactive end\n" + @@ -314,16 +322,17 @@ public void testImmutableField() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( 42 ); ksession.insert( 42L ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - - @Test(timeout = 5000L) - public void testPRAfterAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + @Timeout(5000) + public void testPRAfterAccumulate(RUN_TYPE runType) { // DROOLS-2427 final String str = "import " + Order.class.getCanonicalName() + "\n" + @@ -338,7 +347,7 @@ public void testPRAfterAccumulate() { " modify($o) { setPrice(10) }\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Order order = new Order( Arrays.asList(new OrderLine( 9 ), new OrderLine( 8 )), 12 ); ksession.insert( order ); @@ -396,8 +405,10 @@ public String getValue() { public void setValue(String value) {} } - @Test(timeout = 5000L) - public void testPRWithAddOnList() { + @ParameterizedTest + @MethodSource("parameters") + @Timeout(5000) + public void testPRWithAddOnList(RUN_TYPE runType) { final String str = "import " + Bean.class.getCanonicalName() + "\n" + "rule R when\n" + @@ -407,14 +418,15 @@ public void testPRWithAddOnList() { " update($b);\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Bean() ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testPRWithUpdateOnList() { + @ParameterizedTest + @MethodSource("parameters") + public void testPRWithUpdateOnList(RUN_TYPE runType) { final String str = "import " + List.class.getCanonicalName() + "\n" + "rule R1 when\n" + @@ -428,14 +440,15 @@ public void testPRWithUpdateOnList() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ArrayList() ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testPROnAtomic() { + @ParameterizedTest + @MethodSource("parameters") + public void testPROnAtomic(RUN_TYPE runType) { final String str = "import " + AtomicInteger.class.getCanonicalName() + "\n" + "rule R2 when\n" + @@ -446,33 +459,41 @@ public void testPROnAtomic() { " update($i);" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert(new AtomicInteger(0)); assertThat(ksession.fireAllRules()).isEqualTo(3); } - @Test(timeout = 10000L) - public void testPropertyReactivityWith2Rules() { - checkPropertyReactivityWith2Rules( "age == 41\n" ); + @ParameterizedTest + @MethodSource("parameters") + @Timeout(10000) + public void testPropertyReactivityWith2Rules(RUN_TYPE runType) { + checkPropertyReactivityWith2Rules(runType, "age == 41\n"); } - @Test(timeout = 10000L) - public void testPropertyReactivityWith2RulesUsingAccessor() { - checkPropertyReactivityWith2Rules( "getAge() == 41\n" ); + @ParameterizedTest + @MethodSource("parameters") + @Timeout(10000) + public void testPropertyReactivityWith2RulesUsingAccessor(RUN_TYPE runType) { + checkPropertyReactivityWith2Rules(runType, "getAge() == 41\n"); } - @Test(timeout = 10000L) - public void testPropertyReactivityWith2RulesLiteralFirst() { - checkPropertyReactivityWith2Rules( "41 == age\n" ); + @ParameterizedTest + @MethodSource("parameters") + @Timeout(10000) + public void testPropertyReactivityWith2RulesLiteralFirst(RUN_TYPE runType) { + checkPropertyReactivityWith2Rules(runType, "41 == age\n"); } - @Test(timeout = 10000L) - public void testPropertyReactivityWith2RulesLiteralFirstUsingAccessor() { - checkPropertyReactivityWith2Rules( "41 == getAge()\n" ); + @ParameterizedTest + @MethodSource("parameters") + @Timeout(10000) + public void testPropertyReactivityWith2RulesLiteralFirstUsingAccessor(RUN_TYPE runType) { + checkPropertyReactivityWith2Rules(runType, "41 == getAge()\n"); } - private void checkPropertyReactivityWith2Rules( String constraint ) { + private void checkPropertyReactivityWith2Rules(RUN_TYPE runType, String constraint) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -487,7 +508,7 @@ private void checkPropertyReactivityWith2Rules( String constraint ) { " modify($p) { setEmployed( true ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person( "Mario", 40 ); ksession.insert( p ); @@ -497,8 +518,9 @@ private void checkPropertyReactivityWith2Rules( String constraint ) { assertThat(p.getEmployed()).isTrue(); } - @Test - public void testReassignment() { + @ParameterizedTest + @MethodSource("parameters") + public void testReassignment(RUN_TYPE runType) { // DROOLS-4884 final String str = "package com.example\n" + @@ -523,13 +545,14 @@ public void testReassignment() { " update($c);\n" + "end\n\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ksession.fireAllRules(5)).isEqualTo(5); } - @Test - public void testReassignment2() { + @ParameterizedTest + @MethodSource("parameters") + public void testReassignment2(RUN_TYPE runType) { // DROOLS-4884 final String str = "package com.example\n" + @@ -554,13 +577,14 @@ public void testReassignment2() { " update($c);\n" + "end\n\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ksession.fireAllRules(5)).isEqualTo(2); } - @Test - public void testMultipleFieldUpdate() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleFieldUpdate(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -575,7 +599,7 @@ public void testMultipleFieldUpdate() { " modify($p) { setAge( $p.getAge()+1 ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); p.setLikes("Beer"); @@ -585,8 +609,9 @@ public void testMultipleFieldUpdate() { assertThat(p.getAge()).isEqualTo(42); } - @Test - public void testComplexSetterArgument() { + @ParameterizedTest + @MethodSource("parameters") + public void testComplexSetterArgument(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R \n" + @@ -596,7 +621,7 @@ public void testComplexSetterArgument() { " modify($p) { setLikes( String.valueOf(($p.getAddress().getStreet() + $p.getAddress().getCity()))) };\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person me = new Person( "Mario", 40 ); me.setAddress(new Address("street1", 2, "city1")); @@ -607,8 +632,9 @@ public void testComplexSetterArgument() { assertThat(me.getLikes()).isEqualTo("street1city1"); } - @Test - public void thisWithGetter() { + @ParameterizedTest + @MethodSource("parameters") + public void thisWithGetter(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R \n" + @@ -618,7 +644,7 @@ public void thisWithGetter() { " modify($p) { setLikes(\"Cheese\") };\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person me = new Person( "Mario", 40 ); me.setAddress(new Address("street1", 2, "city1")); @@ -627,8 +653,9 @@ public void thisWithGetter() { assertThat(ksession.fireAllRules(10)).as("should not loop").isEqualTo(1); } - @Test - public void nullSafeDereferencing() { + @ParameterizedTest + @MethodSource("parameters") + public void nullSafeDereferencing(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R \n" + @@ -638,7 +665,7 @@ public void nullSafeDereferencing() { " modify($p) { setLikes(\"Cheese\") };\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person me = new Person( "Mario", 40 ); me.setAddress(new Address("street1", 2, "city1")); @@ -647,8 +674,9 @@ public void nullSafeDereferencing() { assertThat(ksession.fireAllRules(10)).as("should not loop").isEqualTo(1); } - @Test - public void testNestedPropInRHS() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testNestedPropInRHS(RUN_TYPE runType) throws Exception { // Property Reactivity for "owner" final String str = "package org.drools.test;\n" + @@ -665,7 +693,7 @@ public void testNestedPropInRHS() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); Pet pet = new Pet(Pet.PetType.cat); Person person = new Person("John"); @@ -677,8 +705,9 @@ public void testNestedPropInRHS() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testDeeplyNestedPropInRHS() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testDeeplyNestedPropInRHS(RUN_TYPE runType) throws Exception { // Property Reactivity for "owner" final String str = "package org.drools.test;\n" + @@ -695,7 +724,7 @@ public void testDeeplyNestedPropInRHS() throws Exception { "then\n" + "end"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); Pet pet = new Pet(Pet.PetType.cat); Person person = new Person("John"); @@ -707,8 +736,9 @@ public void testDeeplyNestedPropInRHS() throws Exception { assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testOutsideModifyBlockWithGetterAsArgument() { + @ParameterizedTest + @MethodSource("parameters") + public void testOutsideModifyBlockWithGetterAsArgument(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -719,7 +749,7 @@ public void testOutsideModifyBlockWithGetterAsArgument() { " modify($p) { setAge(41) };\n" + "end\n"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert(p); @@ -729,8 +759,9 @@ public void testOutsideModifyBlockWithGetterAsArgument() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testOutsideModifyBlockWithNonGetterAsArgument() { + @ParameterizedTest + @MethodSource("parameters") + public void testOutsideModifyBlockWithNonGetterAsArgument(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -741,7 +772,7 @@ public void testOutsideModifyBlockWithNonGetterAsArgument() { " modify($p) { setAge(41) };\n" + "end\n"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert(p); @@ -751,8 +782,9 @@ public void testOutsideModifyBlockWithNonGetterAsArgument() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testMultipleModifyBlocksWithNonGetterAsArgument() { + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleModifyBlocksWithNonGetterAsArgument(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "import " + Address.class.getCanonicalName() + ";\n" + @@ -768,7 +800,7 @@ public void testMultipleModifyBlocksWithNonGetterAsArgument() { " modify($a) { setNumber(20) };\n" + "end\n"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert(p); @@ -783,8 +815,9 @@ public void testMultipleModifyBlocksWithNonGetterAsArgument() { assertThat(a.getNumber()).isEqualTo(20); } - @Test - public void testUpdateWithGetterAsArgument() { + @ParameterizedTest + @MethodSource("parameters") + public void testUpdateWithGetterAsArgument(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -796,7 +829,7 @@ public void testUpdateWithGetterAsArgument() { " update($p);\n" + "end\n"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert(p); @@ -806,8 +839,9 @@ public void testUpdateWithGetterAsArgument() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testUpdateWithNonGetterAsArgument() { + @ParameterizedTest + @MethodSource("parameters") + public void testUpdateWithNonGetterAsArgument(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -819,7 +853,7 @@ public void testUpdateWithNonGetterAsArgument() { " update($p);\n" + "end\n"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert(p); @@ -829,8 +863,9 @@ public void testUpdateWithNonGetterAsArgument() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testUpdateWithNonGetterAsDeclaration() { + @ParameterizedTest + @MethodSource("parameters") + public void testUpdateWithNonGetterAsDeclaration(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -843,7 +878,7 @@ public void testUpdateWithNonGetterAsDeclaration() { " update($p);\n" + "end\n"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert(p); @@ -853,8 +888,9 @@ public void testUpdateWithNonGetterAsDeclaration() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testUpdateWithNonGetterIntentinalLoop() { + @ParameterizedTest + @MethodSource("parameters") + public void testUpdateWithNonGetterIntentinalLoop(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -866,7 +902,7 @@ public void testUpdateWithNonGetterIntentinalLoop() { " update($p);\n" + "end\n"; - final KieSession ksession = getKieSession(str); + final KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert(p); @@ -879,8 +915,9 @@ public void testUpdateWithNonGetterIntentinalLoop() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testPropertyReactivityOnBoundVariable() { + @ParameterizedTest + @MethodSource("parameters") + public void testPropertyReactivityOnBoundVariable(RUN_TYPE runType) { // RHDM-1387 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -891,7 +928,7 @@ public void testPropertyReactivityOnBoundVariable() { " modify($p) { setAge( $p.getAge()+1 ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -904,8 +941,9 @@ public static int dummy(int i) { return i; } - @Test - public void testWatchCallingExternalMethod() { + @ParameterizedTest + @MethodSource("parameters") + public void testWatchCallingExternalMethod(RUN_TYPE runType) { // DROOLS-5514 final String str = "import static " + this.getClass().getCanonicalName() + ".dummy;\n" + @@ -917,7 +955,7 @@ public void testWatchCallingExternalMethod() { " modify($p) { setAge( $p.getAge()+1 ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -926,8 +964,9 @@ public void testWatchCallingExternalMethod() { assertThat(p.getAge()).isEqualTo(50); } - @Test - public void testWatchCallingExternalMethod2() { + @ParameterizedTest + @MethodSource("parameters") + public void testWatchCallingExternalMethod2(RUN_TYPE runType) { // DROOLS-5514 final String str = "import static " + this.getClass().getCanonicalName() + ".dummy;\n" + @@ -939,7 +978,7 @@ public void testWatchCallingExternalMethod2() { " modify($p) { setName( $p.getName()+\"1\" ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -948,8 +987,9 @@ public void testWatchCallingExternalMethod2() { assertThat(p.getName()).isEqualTo("Mario111"); } - @Test - public void testWatchCallingExternalMethod3() { + @ParameterizedTest + @MethodSource("parameters") + public void testWatchCallingExternalMethod3(RUN_TYPE runType) { // DROOLS-5514 final String str = "import static " + this.getClass().getCanonicalName() + ".dummy;\n" + @@ -961,7 +1001,7 @@ public void testWatchCallingExternalMethod3() { " modify($p) { setName( $p.getName()+\"1\" ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -970,8 +1010,9 @@ public void testWatchCallingExternalMethod3() { assertThat(p.getName()).isEqualTo("Mario1"); } - @Test - public void test2PropertiesInOneExpression() { + @ParameterizedTest + @MethodSource("parameters") + public void test2PropertiesInOneExpression(RUN_TYPE runType) { // DROOLS-5677 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -998,7 +1039,7 @@ public void test2PropertiesInOneExpression() { " modify($p) { setSalary( 100 ) };\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person("John", 0); p.setSalary(0); @@ -1011,8 +1052,9 @@ public void test2PropertiesInOneExpression() { assertThat(p.getSalary().intValue()).isEqualTo(20); // R2 should be cancelled } - @Test - public void test3PropertiesInOneExpression() { + @ParameterizedTest + @MethodSource("parameters") + public void test3PropertiesInOneExpression(RUN_TYPE runType) { // DROOLS-5677 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1046,7 +1088,7 @@ public void test3PropertiesInOneExpression() { " modify($p) { setSalary( 100 ) };\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person("John", 0); p.setSalary(0); @@ -1109,8 +1151,9 @@ public static String convertToString(int num) { return "BIG"; } - @Test - public void testExternalFunction() { + @ParameterizedTest + @MethodSource("parameters") + public void testExternalFunction(RUN_TYPE runType) { // BAPL-1773 final String str = "import " + Fact.class.getCanonicalName() + ";\n" + @@ -1122,7 +1165,7 @@ public void testExternalFunction() { " modify($fact) { setResult(\"OK\") };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Fact fact = new Fact(); fact.setA(99999); @@ -1133,8 +1176,9 @@ public void testExternalFunction() { assertThat(fact.getResult()).isEqualTo("OK"); } - @Test - public void testExternalFunction2() { + @ParameterizedTest + @MethodSource("parameters") + public void testExternalFunction2(RUN_TYPE runType) { // BAPL-1773 final String str = "import " + Fact.class.getCanonicalName() + ";\n" + @@ -1146,7 +1190,7 @@ public void testExternalFunction2() { " modify($fact) { setA(99999) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Fact fact = new Fact(); fact.setA(99999); @@ -1156,8 +1200,9 @@ public void testExternalFunction2() { assertThat(ksession.fireAllRules(3)).isEqualTo(3); } - @Test - public void externalFunctionWithBindVariable_shouldNotCauseInfiniteLoop() { + @ParameterizedTest + @MethodSource("parameters") + public void externalFunctionWithBindVariable_shouldNotCauseInfiniteLoop(RUN_TYPE runType) { // DROOLS-7372 final String str = "import " + Fact.class.getCanonicalName() + ";\n" + "import static " + PropertyReactivityTest.class.getCanonicalName() + ".*;\n" + @@ -1168,7 +1213,7 @@ public void externalFunctionWithBindVariable_shouldNotCauseInfiniteLoop() { " modify($fact) { setResult(\"OK\") };\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Fact bigString = new Fact(); bigString.setA(99999); @@ -1181,8 +1226,9 @@ public void externalFunctionWithBindVariable_shouldNotCauseInfiniteLoop() { assertThat(bigString.getResult()).isEqualTo("OK"); } - @Test - public void externalFunctionWithBindVariableFromAnotherPatternOfSameType_shouldTriggerClassReactive() { + @ParameterizedTest + @MethodSource("parameters") + public void externalFunctionWithBindVariableFromAnotherPatternOfSameType_shouldTriggerClassReactive(RUN_TYPE runType) { // DROOLS-7398 final String str = "import " + Fact.class.getCanonicalName() + ";\n" + @@ -1194,7 +1240,7 @@ public void externalFunctionWithBindVariableFromAnotherPatternOfSameType_shouldT " modify($fact2) { setResult(\"OK\") };\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Fact bigStringFact = new Fact(); bigStringFact.setA(99999); @@ -1206,8 +1252,9 @@ public void externalFunctionWithBindVariableFromAnotherPatternOfSameType_shouldT .isEqualTo(10); } - @Test - public void multipleExternalFunctionsWithBindVariablesFromAnotherPatternOfSameType_shouldTriggerClassReactive() { + @ParameterizedTest + @MethodSource("parameters") + public void multipleExternalFunctionsWithBindVariablesFromAnotherPatternOfSameType_shouldTriggerClassReactive(RUN_TYPE runType) { // DROOLS-7398 final String str = "import " + Fact.class.getCanonicalName() + ";\n" + @@ -1219,7 +1266,7 @@ public void multipleExternalFunctionsWithBindVariablesFromAnotherPatternOfSameTy " modify($fact2) { setResult(\"OK\") };\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Fact bigStringFact = new Fact(); bigStringFact.setA(99999); @@ -1232,8 +1279,9 @@ public void multipleExternalFunctionsWithBindVariablesFromAnotherPatternOfSameTy .isEqualTo(10); } - @Test - public void externalFunctionWithBindVariableFromAnotherPatternOfDifferentType_shouldTriggerClassReactive() { + @ParameterizedTest + @MethodSource("parameters") + public void externalFunctionWithBindVariableFromAnotherPatternOfDifferentType_shouldTriggerClassReactive(RUN_TYPE runType) { // DROOLS-7390 final String str = "import " + Fact.class.getCanonicalName() + ";\n" + @@ -1246,7 +1294,7 @@ public void externalFunctionWithBindVariableFromAnotherPatternOfDifferentType_sh " modify($fact2) { setResult(\"OK\") };\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); AnotherFact bigStringAnotherFact = new AnotherFact(); bigStringAnotherFact.setA(99999); @@ -1262,8 +1310,9 @@ public void externalFunctionWithBindVariableFromAnotherPatternOfDifferentType_sh .isEqualTo(10); } - @Test - public void testUnwatch() { + @ParameterizedTest + @MethodSource("parameters") + public void testUnwatch(RUN_TYPE runType) { // RHDM-1553 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1274,7 +1323,7 @@ public void testUnwatch() { " modify($p) { setAge( $p.getAge() + 1 ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -1283,8 +1332,9 @@ public void testUnwatch() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testUnwatchWithFieldBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testUnwatchWithFieldBinding(RUN_TYPE runType) { // RHDM-1553 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1295,7 +1345,7 @@ public void testUnwatchWithFieldBinding() { " modify($p) { setAge( $age + 1 ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -1304,8 +1354,9 @@ public void testUnwatchWithFieldBinding() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testUnwatchWithFieldBindingAndMvel() { + @ParameterizedTest + @MethodSource("parameters") + public void testUnwatchWithFieldBindingAndMvel(RUN_TYPE runType) { // RHDM-1553 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1316,7 +1367,7 @@ public void testUnwatchWithFieldBindingAndMvel() { " modify($p) { age = $age + 1 };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -1325,8 +1376,9 @@ public void testUnwatchWithFieldBindingAndMvel() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testUnwatchWithWatchedField() { + @ParameterizedTest + @MethodSource("parameters") + public void testUnwatchWithWatchedField(RUN_TYPE runType) { // RHDM-1553 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1337,7 +1389,7 @@ public void testUnwatchWithWatchedField() { " modify($p) { setAge( $p.getAge() + 1 ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -1346,8 +1398,9 @@ public void testUnwatchWithWatchedField() { assertThat(p.getAge()).isEqualTo(43); } - @Test - public void testNoConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testNoConstraint(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -1357,7 +1410,7 @@ public void testNoConstraint() { " modify($p) { setAge( $p.getAge()+1 ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -1366,8 +1419,9 @@ public void testNoConstraint() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testNoConstraintWithUpdate() { + @ParameterizedTest + @MethodSource("parameters") + public void testNoConstraintWithUpdate(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -1378,7 +1432,7 @@ public void testNoConstraintWithUpdate() { " update($p);\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -1387,8 +1441,9 @@ public void testNoConstraintWithUpdate() { assertThat(p.getAge()).isEqualTo(41); } - @Test - public void testModifiesAnnotation() { + @ParameterizedTest + @MethodSource("parameters") + public void testModifiesAnnotation(RUN_TYPE runType) { final String str = "import " + Light.class.getCanonicalName() + ";\n" + "\n" + @@ -1398,7 +1453,7 @@ public void testModifiesAnnotation() { " modify($l) { turnOn() };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Light l = new Light("Alert"); ksession.insert( l ); @@ -1437,8 +1492,9 @@ public void setName(String name) { } } - @Test - public void testSettersInAndOutModifyBlock() { + @ParameterizedTest + @MethodSource("parameters") + public void testSettersInAndOutModifyBlock(RUN_TYPE runType) { // RHDM-1552 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1450,7 +1506,7 @@ public void testSettersInAndOutModifyBlock() { " modify($p) { setName( \"Mario\" ) };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -1459,8 +1515,9 @@ public void testSettersInAndOutModifyBlock() { assertThat(p.getAge()).isEqualTo(43); } - @Test - public void testSettersInAndOutModifyBlockMvel() { + @ParameterizedTest + @MethodSource("parameters") + public void testSettersInAndOutModifyBlockMvel(RUN_TYPE runType) { // RHDM-1552 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1472,7 +1529,7 @@ public void testSettersInAndOutModifyBlockMvel() { " modify($p) { name = \"Mario\" };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -1481,8 +1538,9 @@ public void testSettersInAndOutModifyBlockMvel() { assertThat(p.getAge()).isEqualTo(43); } - @Test - public void testMvelModifyBlockWithComma() { + @ParameterizedTest + @MethodSource("parameters") + public void testMvelModifyBlockWithComma(RUN_TYPE runType) { // RHDM-1552 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1493,7 +1551,7 @@ public void testMvelModifyBlockWithComma() { " modify($p) { setName(\"Mario\"), age = $p.age + 1 };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -1542,8 +1600,9 @@ private static class StackFrame { } } - @Test - public void testUpdateNonPropertyInMvel() { + @ParameterizedTest + @MethodSource("parameters") + public void testUpdateNonPropertyInMvel(RUN_TYPE runType) { // DROOLS-6096 final String str = "import " + AssessmentContext.class.getCanonicalName() + ";\n" + @@ -1567,7 +1626,7 @@ public void testUpdateNonPropertyInMvel() { " update($ac);\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); AssessmentContext ac1 = new AssessmentContext(); ac1.pushStackFrame(null); @@ -1578,8 +1637,9 @@ public void testUpdateNonPropertyInMvel() { assertThat(ksession.fireAllRules(2)).isEqualTo(2); } - @Test - public void testPropertyReactivityWithPublicField() { + @ParameterizedTest + @MethodSource("parameters") + public void testPropertyReactivityWithPublicField(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "rule R1 when\n" + @@ -1596,7 +1656,7 @@ public void testPropertyReactivityWithPublicField() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person("John"); p.publicAge = 40; @@ -1607,8 +1667,9 @@ public void testPropertyReactivityWithPublicField() { assertThat(p.publicAge).isEqualTo(41); } - @Test - public void testUnknownPropertyNameInWatch() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testUnknownPropertyNameInWatch(RUN_TYPE runType) throws Exception { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "global java.util.List result;\n" + @@ -1624,12 +1685,13 @@ public void testUnknownPropertyNameInWatch() throws Exception { " modify($p) { setAge(20) }\n" + "end\n"; - KieBuilder kbuilder = createKieBuilder(str); + KieBuilder kbuilder = createKieBuilder(runType, str); assertThat(kbuilder.getResults().hasMessages(Level.ERROR)).isTrue(); } - @Test - public void testSetterWithoutGetter() { + @ParameterizedTest + @MethodSource("parameters") + public void testSetterWithoutGetter(RUN_TYPE runType) { // DROOLS-6523 final String str = "import " + ClassWithValue.class.getCanonicalName() + ";\n" + @@ -1640,7 +1702,7 @@ public void testSetterWithoutGetter() { " update($cwv);\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ClassWithValue cwv = new ClassWithValue(); ksession.insert(cwv); @@ -1671,8 +1733,9 @@ public void addDoubleValue(double doubleValue) { } } - @Test - public void testPropertyReactivityOn2Properties() { + @ParameterizedTest + @MethodSource("parameters") + public void testPropertyReactivityOn2Properties(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "\n" + @@ -1685,7 +1748,7 @@ public void testPropertyReactivityOn2Properties() { " };\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -1695,8 +1758,9 @@ public void testPropertyReactivityOn2Properties() { assertThat(p.getId()).isEqualTo(1); } - @Test - public void testPropertyReactivityOn2PropertiesWithWrongSeparator() { + @ParameterizedTest + @MethodSource("parameters") + public void testPropertyReactivityOn2PropertiesWithWrongSeparator(RUN_TYPE runType) { // DROOLS-6480 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1710,12 +1774,13 @@ public void testPropertyReactivityOn2PropertiesWithWrongSeparator() { " };\n" + "end\n"; - KieBuilder kbuilder = createKieBuilder(str); + KieBuilder kbuilder = createKieBuilder(runType, str); assertThat(kbuilder.getResults().hasMessages(Level.ERROR)).isTrue(); } - @Test - public void testMvelModifyAfterSingleQuote() { + @ParameterizedTest + @MethodSource("parameters") + public void testMvelModifyAfterSingleQuote(RUN_TYPE runType) { // DROOLS-6542 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1733,7 +1798,7 @@ public void testMvelModifyAfterSingleQuote() { " insert(\"ok\");\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); @@ -1743,38 +1808,43 @@ public void testMvelModifyAfterSingleQuote() { assertThat(ksession.getObjects((Object object) -> object.equals("ok")).size()).isEqualTo(1); } - @Test - public void testOnlyFirstLetterIsUpperCaseProperty() { + @ParameterizedTest + @MethodSource("parameters") + public void testOnlyFirstLetterIsUpperCaseProperty(RUN_TYPE runType) { // See JavaBeans 1.01 spec : 8.8 Capitalization of inferred names // “FooBah” becomes “fooBah” - testVariousCasePropFact("modify($f) { MyTarget = \"123\" };", "R1", "R2"); // Actually, this modifies "myTarget" property (backed by private "MyTarget" field). This shouldn't react R1 + testVariousCasePropFact(runType, "modify($f) { MyTarget = \"123\" };", "R1", "R2"); // Actually, this modifies "myTarget" property (backed by private "MyTarget" field). This shouldn't react R1 } - @Test - public void testTwoFirstLettersAreUpperCaseProperty() { + @ParameterizedTest + @MethodSource("parameters") + public void testTwoFirstLettersAreUpperCaseProperty(RUN_TYPE runType) { // See JavaBeans 1.01 spec : 8.8 Capitalization of inferred names // “URL” becomes “URL” - testVariousCasePropFact("modify($f) { URL = \"123\" };", "R1", "R2"); // This shouldn't react R1 + testVariousCasePropFact(runType, "modify($f) { URL = \"123\" };", "R1", "R2"); // This shouldn't react R1 } - @Test - public void testFirstLetterIsMultibyteProperty() { + @ParameterizedTest + @MethodSource("parameters") + public void testFirstLetterIsMultibyteProperty(RUN_TYPE runType) { // Multibyte is not mentioned in JavaBeans spec - testVariousCasePropFact("modify($f) { 名前 = \"123\" };", "R1", "R2"); // This shouldn't react R1 + testVariousCasePropFact(runType, "modify($f) { 名前 = \"123\" };", "R1", "R2"); // This shouldn't react R1 } - @Test - public void testOnlyFirstLetterIsUpperCaseAndMultibyteProperty() { + @ParameterizedTest + @MethodSource("parameters") + public void testOnlyFirstLetterIsUpperCaseAndMultibyteProperty(RUN_TYPE runType) { // Multibyte is not mentioned in JavaBeans spec - testVariousCasePropFact("modify($f) { My名前 = \"123\" };", "R1", "R2"); // Actually, this modifies "my名前" property (backed by private "My名前" field). This shouldn't react R1 + testVariousCasePropFact(runType, "modify($f) { My名前 = \"123\" };", "R1", "R2"); // Actually, this modifies "my名前" property (backed by private "My名前" field). This shouldn't react R1 } - @Test - public void testOnlyFirstLetterIsUpperCasePublicFieldProperty() { - testVariousCasePropFact("modify($f) { MyPublicTarget = \"123\" };", "R1", "R2"); // this modifies "MyPublicTarget" public field directly. This shouldn't react R1 + @ParameterizedTest + @MethodSource("parameters") + public void testOnlyFirstLetterIsUpperCasePublicFieldProperty(RUN_TYPE runType) { + testVariousCasePropFact(runType, "modify($f) { MyPublicTarget = \"123\" };", "R1", "R2"); // this modifies "MyPublicTarget" public field directly. This shouldn't react R1 } - private void testVariousCasePropFact(String modifyStatement, String... expectedResults) { + private void testVariousCasePropFact(RUN_TYPE runType, String modifyStatement, String... expectedResults) { final String str = "import " + VariousCasePropFact.class.getCanonicalName() + ";\n" + "dialect \"mvel\"\n" + @@ -1795,7 +1865,7 @@ private void testVariousCasePropFact(String modifyStatement, String... expectedR modifyStatement + "\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List results = new ArrayList<>(); ksession.setGlobal("results", results); @@ -1807,8 +1877,9 @@ private void testVariousCasePropFact(String modifyStatement, String... expectedR assertThat(results).containsExactly(expectedResults); } - @Test - public void bindOnlyPropertyReacts() { + @ParameterizedTest + @MethodSource("parameters") + public void bindOnlyPropertyReacts(RUN_TYPE runType) { // DROOLS-7214 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1819,7 +1890,7 @@ public void bindOnlyPropertyReacts() { " modify($p) { age = $age + 1 };\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert(p); @@ -1828,8 +1899,9 @@ public void bindOnlyPropertyReacts() { assertThat(fired).isEqualTo(10); } - @Test - public void bindOnlyMapPropertyReacts() { + @ParameterizedTest + @MethodSource("parameters") + public void bindOnlyMapPropertyReacts(RUN_TYPE runType) { // DROOLS-7214 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1841,7 +1913,7 @@ public void bindOnlyMapPropertyReacts() { " modify($p) { itemsString = $p.itemsString };\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); p.getItemsString().put("A", "itemA"); @@ -1851,8 +1923,9 @@ public void bindOnlyMapPropertyReacts() { assertThat(fired).isEqualTo(10); } - @Test - public void bindOnlyMapPropertyWithAccessOperatorReacts() { + @ParameterizedTest + @MethodSource("parameters") + public void bindOnlyMapPropertyWithAccessOperatorReacts(RUN_TYPE runType) { // DROOLS-7214 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1864,7 +1937,7 @@ public void bindOnlyMapPropertyWithAccessOperatorReacts() { " modify($p) { itemsString = $p.itemsString };\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); p.getItemsString().put("A", "itemA"); @@ -1874,8 +1947,9 @@ public void bindOnlyMapPropertyWithAccessOperatorReacts() { assertThat(fired).isEqualTo(10); } - @Test - public void bindOnlyListPropertyWithAccessOperatorReacts() { + @ParameterizedTest + @MethodSource("parameters") + public void bindOnlyListPropertyWithAccessOperatorReacts(RUN_TYPE runType) { // DROOLS-7214 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1888,7 +1962,7 @@ public void bindOnlyListPropertyWithAccessOperatorReacts() { " modify($p) { addresses = $p.addresses };\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); p.getAddresses().add(new Address("A")); @@ -1899,8 +1973,9 @@ public void bindOnlyListPropertyWithAccessOperatorReacts() { assertThat(fired).isEqualTo(10); } - @Test - public void testPropertyReactivityWithRedundantVariableDeclaration() { + @ParameterizedTest + @MethodSource("parameters") + public void testPropertyReactivityWithRedundantVariableDeclaration(RUN_TYPE runType) { // KIE-DROOLS-5943 final String str = "import " + Person.class.getCanonicalName() + ";\n" + @@ -1912,7 +1987,7 @@ public void testPropertyReactivityWithRedundantVariableDeclaration() { " update($p);\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p = new Person("Mario", 40); ksession.insert( p ); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PrototypeTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PrototypeTest.java index 7e3ccd1154d..05a4202a55a 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PrototypeTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PrototypeTest.java @@ -49,7 +49,7 @@ import org.drools.model.prototype.PrototypeExpression; import org.drools.model.prototype.PrototypeVariable; import org.drools.modelcompiler.KieBaseBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.api.conf.EventProcessingOption; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PrototypesAllowedTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PrototypesAllowedTest.java index 28c257ea97e..1eb18501903 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PrototypesAllowedTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/PrototypesAllowedTest.java @@ -30,7 +30,7 @@ import org.drools.model.impl.ModelImpl; import org.drools.model.prototype.PrototypeVariable; import org.drools.modelcompiler.KieBaseBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieBase; import org.kie.api.conf.PrototypesOption; import org.kie.api.io.ResourceType; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/QueryTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/QueryTest.java index 65f5cc039af..e06419bf327 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/QueryTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/QueryTest.java @@ -31,7 +31,8 @@ import org.drools.model.codegen.execmodel.domain.Result; import org.drools.model.codegen.execmodel.oopathdtables.InternationalAddress; import org.drools.model.codegen.execmodel.util.TrackingAgendaEventListener; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieServices; import org.kie.api.command.Command; import org.kie.api.definition.type.FactType; @@ -46,12 +47,9 @@ public class QueryTest extends BaseModelTest { - public QueryTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testQueryZeroArgs() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryZeroArgs(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "global java.lang.Integer ageG;" + @@ -59,7 +57,7 @@ public void testQueryZeroArgs() { " $p : Person(age > ageG)\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal("ageG", 40); @@ -75,15 +73,16 @@ public void testQueryZeroArgs() { } - @Test - public void testQueryOneArgument() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryOneArgument(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "query olderThan( int $age )\n" + " $p : Person(age > $age)\n" + "end "; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mark", 39 ) ); ksession.insert( new Person( "Mario", 41 ) ); @@ -95,15 +94,16 @@ public void testQueryOneArgument() { assertThat(p.getName()).isEqualTo("Mario"); } - @Test - public void testQueryOneArgumentWithoutType() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryOneArgumentWithoutType(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "query olderThan( $age )\n" + " $p : Person(age > (Integer)$age)\n" + "end "; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mark", 39 ) ); ksession.insert( new Person( "Mario", 41 ) ); @@ -115,8 +115,9 @@ public void testQueryOneArgumentWithoutType() { assertThat(p.getName()).isEqualTo("Mario"); } - @Test - public void testQueryInRule() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryInRule(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -129,7 +130,7 @@ public void testQueryInRule() { " insert(new Result($p.getName()));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mark", 39 ) ); ksession.insert( new Person( "Mario", 41 ) ); @@ -141,8 +142,9 @@ public void testQueryInRule() { assertThat(results.iterator().next().getValue()).isEqualTo("Mario"); } - @Test - public void testQueryInRuleWithDeclaration() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryInRuleWithDeclaration(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -156,7 +158,7 @@ public void testQueryInRuleWithDeclaration() { " insert(new Result($p.getName()));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mark", 39 ) ); ksession.insert( new Person( "Mario", 41 ) ); @@ -170,8 +172,9 @@ public void testQueryInRuleWithDeclaration() { } - @Test - public void testQueryInvokedWithGlobal() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryInvokedWithGlobal(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -186,7 +189,7 @@ public void testQueryInvokedWithGlobal() { " insert(new Result($p.getName()));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.setGlobal("ageG", 40); @@ -201,8 +204,9 @@ public void testQueryInvokedWithGlobal() { assertThat(results.iterator().next().getValue()).isEqualTo("Mario"); } - @Test - public void testNonPositionalQuery() { + @ParameterizedTest + @MethodSource("parameters") + public void testNonPositionalQuery(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -210,7 +214,7 @@ public void testNonPositionalQuery() { " $p : Person(name == $n, age == $a)\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mark", 39 ) ); ksession.insert( new Person( "Mario", 41 ) ); @@ -222,15 +226,16 @@ public void testNonPositionalQuery() { assertThat(p.getName()).isEqualTo("Mario"); } - @Test - public void testPositionalQuery() { + @ParameterizedTest + @MethodSource("parameters") + public void testPositionalQuery(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "query findPerson( String $n, int $a )\n" + " $p : Person($n, $a;)\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mark", 39 ) ); ksession.insert( new Person( "Mario", 41 ) ); @@ -242,15 +247,16 @@ public void testPositionalQuery() { assertThat(p.getName()).isEqualTo("Mario"); } - @Test - public void testUnificationParameterInPattern() { + @ParameterizedTest + @MethodSource("parameters") + public void testUnificationParameterInPattern(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "query personsAges(int ages)\n" + "$p : Person(ages := age)\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mark", 39 ) ); ksession.insert( new Person( "Mario", 41 ) ); @@ -262,8 +268,9 @@ public void testUnificationParameterInPattern() { assertThat(p.getName()).isEqualTo("Mario"); } - @Test - public void testQueryCallingQuery() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryCallingQuery(RUN_TYPE runType) { String str = "import " + Relationship.class.getCanonicalName() + ";" + "query isRelatedTo(String x, String y)\n" + @@ -273,7 +280,7 @@ public void testQueryCallingQuery() { " Relationship(x, y;)\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Relationship( "A", "B" ) ); ksession.insert( new Relationship( "B", "C" ) ); @@ -286,8 +293,9 @@ public void testQueryCallingQuery() { } - @Test - public void testQueryWithOOPath() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryWithOOPath(RUN_TYPE runType) { String str = "import " + java.util.List.class.getCanonicalName() + ";" + "import " + org.drools.model.codegen.execmodel.oopathdtables.Person.class.getCanonicalName() + ";" + @@ -297,7 +305,7 @@ public void testQueryWithOOPath() { "$cities : List() from accumulate (Person ( $city: /address#InternationalAddress[state == \"Safecountry\"]/city), collectList($city))\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); org.drools.model.codegen.execmodel.oopathdtables.Person person = new org.drools.model.codegen.execmodel.oopathdtables.Person(); person.setAddress(new InternationalAddress("", 1, "Milan", "Safecountry")); @@ -314,8 +322,9 @@ public void testQueryWithOOPath() { assertThat(cities.get(0)).isEqualTo("Milan"); } - @Test - public void testQueryWithOOPathTransformedToFrom() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryWithOOPathTransformedToFrom(RUN_TYPE runType) { String str = "import " + java.util.List.class.getCanonicalName() + ";" + "import " + org.drools.model.codegen.execmodel.oopathdtables.Person.class.getCanonicalName() + ";" + @@ -327,7 +336,7 @@ public void testQueryWithOOPathTransformedToFrom() { "$cities : List() from accumulate ($city : String() from $a.city, collectList($city))\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); org.drools.model.codegen.execmodel.oopathdtables.Person person = new org.drools.model.codegen.execmodel.oopathdtables.Person(); person.setAddress(new InternationalAddress("", 1, "Milan", "Safecountry")); @@ -344,8 +353,9 @@ public void testQueryWithOOPathTransformedToFrom() { assertThat(cities.get(0)).isEqualTo("Milan"); } - @Test - public void testQueryWithOOPathTransformedToFromInsideAcc() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryWithOOPathTransformedToFromInsideAcc(RUN_TYPE runType) { String str = "import " + java.util.List.class.getCanonicalName() + ";" + "import " + org.drools.model.codegen.execmodel.oopathdtables.Person.class.getCanonicalName() + ";" + @@ -358,7 +368,7 @@ public void testQueryWithOOPathTransformedToFromInsideAcc() { " $city : String() from $a.city, collectList($city))\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); org.drools.model.codegen.execmodel.oopathdtables.Person person2 = new org.drools.model.codegen.execmodel.oopathdtables.Person(); person2.setAddress(new InternationalAddress("", 1, "Rome", "Unsafecountry")); @@ -376,8 +386,9 @@ public void testQueryWithOOPathTransformedToFromInsideAcc() { assertThat(cities.get(0)).isEqualTo("Milan"); } - @Test - public void testPositionalRecursiveQueryWithUnification() { + @ParameterizedTest + @MethodSource("parameters") + public void testPositionalRecursiveQueryWithUnification(RUN_TYPE runType) { String str = "import " + Relationship.class.getCanonicalName() + ";" + "query isRelatedTo(String x, String y)\n" + @@ -386,7 +397,7 @@ public void testPositionalRecursiveQueryWithUnification() { " ( Relationship (z, y;) and ?isRelatedTo(x, z;))\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Relationship( "A", "B" ) ); ksession.insert( new Relationship( "B", "C" ) ); @@ -400,8 +411,9 @@ public void testPositionalRecursiveQueryWithUnification() { assertThat("B".equals(resultDrlx)).isTrue(); } - @Test - public void testPositionalRecursiveQuery() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testPositionalRecursiveQuery(RUN_TYPE runType) throws Exception { String query = "query isContainedIn(String x, String y)\n" + " Location (x, y;)\n" + @@ -409,11 +421,12 @@ public void testPositionalRecursiveQuery() throws Exception { " ( Location (z, y;) and ?isContainedIn(x, z;))\n" + "end\n"; - checkRecursiveQuery( query ); + checkRecursiveQuery(runType, query); } - @Test - public void testUnificationRecursiveQuery() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testUnificationRecursiveQuery(RUN_TYPE runType) throws Exception { String query = "query isContainedIn(String x, String y)\n" + " Location( x := thing, y := location)\n" + @@ -421,10 +434,10 @@ public void testUnificationRecursiveQuery() throws Exception { " ( Location(z := thing, y := location) and ?isContainedIn( x := x, z := y ) )\n" + "end\n"; - checkRecursiveQuery( query ); + checkRecursiveQuery(runType, query); } - private void checkRecursiveQuery( String query ) throws InstantiationException, IllegalAccessException { + private void checkRecursiveQuery(RUN_TYPE runType , String query) throws InstantiationException, IllegalAccessException { String str = "package org.test;\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -449,7 +462,7 @@ private void checkRecursiveQuery( String query ) throws InstantiationException, // "then\n" + // "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); FactType locationType = ksession.getKieBase().getFactType("org.test", "Location"); @@ -501,8 +514,9 @@ private void checkRecursiveQuery( String query ) throws InstantiationException, assertThat(listener.isRuleFired("testPushQueryRule")).isFalse(); } - @Test - public void testRecursiveQueryWithBatchCommand() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testRecursiveQueryWithBatchCommand(RUN_TYPE runType) throws Exception { String str = "package org.test;\n" + "import " + Person.class.getCanonicalName() + ";" + @@ -517,7 +531,7 @@ public void testRecursiveQueryWithBatchCommand() throws Exception { "end"; KieServices kieServices = KieServices.Factory.get(); - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); FactType locationType = ksession.getKieBase().getFactType("org.test", "Location"); @@ -576,8 +590,9 @@ public void testRecursiveQueryWithBatchCommand() throws Exception { assertThat(l.contains("key")).isTrue(); } - @Test - public void testQueryUnificationUnset() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryUnificationUnset(RUN_TYPE runType) { String str = "package drl;\n" + "declare Anon " + " cld : String @key " + @@ -618,12 +633,13 @@ public void testQueryUnificationUnset() { "then " + "end "; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.fireAllRules(); } - @Test - public void testQueryCalling2Queries() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryCalling2Queries(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "query isPersonOlderThan(Person p, int ageFrom)\n" + @@ -639,7 +655,7 @@ public void testQueryCalling2Queries() { "end\n" + "\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person( "Mark", 39 ) ); ksession.insert( new Person( "Mario", 41 ) ); @@ -651,15 +667,16 @@ public void testQueryCalling2Queries() { assertThat(p.getName()).isEqualTo("Mario"); } - @Test - public void testQueriesWithVariableUnification() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testQueriesWithVariableUnification(RUN_TYPE runType) throws Exception { String str = "import " + Person.class.getCanonicalName() + ";" + "query peeps( String $name, int $age ) \n" + " $p : Person( $name := name, $age := age ) \n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person p1 = new Person( "darth", 100 ); Person p2 = new Person( "yoda", 300 ); @@ -704,8 +721,9 @@ public void testQueriesWithVariableUnification() throws Exception { assertThat(names.contains("darth")).isTrue(); } - @Test - public void testQueryWithUpdateOnFactHandle() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryWithUpdateOnFactHandle(RUN_TYPE runType) throws Exception { String str = "global java.util.List list; " + "query foo( Integer $i ) " + @@ -727,7 +745,7 @@ public void testQueryWithUpdateOnFactHandle() throws Exception { "end\n" + "\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -742,8 +760,9 @@ public void testQueryWithUpdateOnFactHandle() throws Exception { assertThat((int) list.get(1)).isEqualTo(22); } - @Test - public void testQueryCallWithBindings() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryCallWithBindings(RUN_TYPE runType) { String str = "package org.drools.compiler.test \n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -760,7 +779,7 @@ public void testQueryCallWithBindings() { " Person( $name := name, $age := age; ) \n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -772,8 +791,9 @@ public void testQueryCallWithBindings() { assertThat(list.get(0)).isEqualTo("Mario : 44"); } - @Test - public void testQueryCallWithJoinInputAndOutput() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryCallWithJoinInputAndOutput(RUN_TYPE runType) { String str = "package org.drools.compiler.test \n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -790,7 +810,7 @@ public void testQueryCallWithJoinInputAndOutput() { " list.add( $name1 + \" : \" + $age1 );\n" + "end \n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -802,8 +822,9 @@ public void testQueryCallWithJoinInputAndOutput() { assertThat(list.get(0)).isEqualTo("Mario : 44"); } - @Test - public void testQueryWithDyanmicInsert() throws IOException, ClassNotFoundException { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryWithDyanmicInsert(RUN_TYPE runType) throws IOException, ClassNotFoundException { String str = "package org.drools.compiler.test \n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -820,7 +841,7 @@ public void testQueryWithDyanmicInsert() throws IOException, ClassNotFoundExcept " list.add( $p );\n" + "end \n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); try { final List list = new ArrayList<>(); @@ -837,8 +858,9 @@ public void testQueryWithDyanmicInsert() throws IOException, ClassNotFoundExcept } } - @Test - public void testQuerySameNameBinding() throws IOException, ClassNotFoundException { + @ParameterizedTest + @MethodSource("parameters") + public void testQuerySameNameBinding(RUN_TYPE runType) throws IOException, ClassNotFoundException { String str = "package org.drools.compiler.test \n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -847,7 +869,7 @@ public void testQuerySameNameBinding() throws IOException, ClassNotFoundExceptio " Person( name := name ) \n" + "end \n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new Person("Mario", 44) ); ksession.insert( new Person("Mark", 40) ); @@ -870,8 +892,9 @@ public void testQuerySameNameBinding() throws IOException, ClassNotFoundExceptio assertThat(list.get(0)).isEqualTo("Mario"); } - @Test - public void testQuery10Args() throws IOException, ClassNotFoundException { + @ParameterizedTest + @MethodSource("parameters") + public void testQuery10Args(RUN_TYPE runType) throws IOException, ClassNotFoundException { String str = "package org.drools.compiler.test \n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -880,7 +903,7 @@ public void testQuery10Args() throws IOException, ClassNotFoundException { " Person( name := name, age := age, ageLong := ageLong, id := id, likes := likes ) \n" + "end \n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person mario = new Person("Mario", 44); mario.setAgeLong(44L); @@ -908,8 +931,9 @@ public void testQuery10Args() throws IOException, ClassNotFoundException { assertThat(list.get(0)).isEqualTo("Mario"); } - @Test - public void testPositionalQueryWithAccumulate() { + @ParameterizedTest + @MethodSource("parameters") + public void testPositionalQueryWithAccumulate(RUN_TYPE runType) { // DROOLS-6128 String str = "import " + Result.class.getCanonicalName() + ";" + @@ -930,7 +954,7 @@ public void testPositionalQueryWithAccumulate() { " ) \n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.fireAllRules(); QueryResults results = ksession.getQueryResults( "accAge", "Mark" ); @@ -942,8 +966,9 @@ public void testPositionalQueryWithAccumulate() { assertThat(resultDrlx).isEqualTo(37); } - @Test - public void testPositionalQueryWithAmbigousName() { + @ParameterizedTest + @MethodSource("parameters") + public void testPositionalQueryWithAmbigousName(RUN_TYPE runType) { // DROOLS-6128 String str = "import " + Result.class.getCanonicalName() + ";" + @@ -964,7 +989,7 @@ public void testPositionalQueryWithAmbigousName() { " ) \n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.fireAllRules(); QueryResults results = ksession.getQueryResults( "accAge", "Mark" ); @@ -976,8 +1001,9 @@ public void testPositionalQueryWithAmbigousName() { assertThat(resultDrlx).isEqualTo(37); } - @Test - public void testQueryWithAccumulateAndUnification() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryWithAccumulateAndUnification(RUN_TYPE runType) { // DROOLS-6105 String str = "import " + Result.class.getCanonicalName() + ";\n" + @@ -1005,7 +1031,7 @@ public void testQueryWithAccumulateAndUnification() { " result.add($sum);" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal( "result", result ); @@ -1017,8 +1043,9 @@ public void testQueryWithAccumulateAndUnification() { assertThat((int) result.get(0)).isEqualTo(37); } - @Test - public void testQueryWithAccumulateInvokingQuery() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryWithAccumulateInvokingQuery(RUN_TYPE runType) { // DROOLS-6105 String str = "import " + Result.class.getCanonicalName() + ";\n" + @@ -1049,7 +1076,7 @@ public void testQueryWithAccumulateInvokingQuery() { " result.add($sum);" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal( "result", result ); @@ -1061,8 +1088,9 @@ public void testQueryWithAccumulateInvokingQuery() { assertThat((int) result.get(0)).isEqualTo(37); } - @Test - public void testQueryDoubleUnification() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryDoubleUnification(RUN_TYPE runType) { // DROOLS-6105 final String str = "" + "package org.drools.compiler.test \n" + @@ -1087,7 +1115,7 @@ public void testQueryDoubleUnification() { "end\n" + ""; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.fireAllRules(); QueryResults results = ksession.getQueryResults("whereFood", Variable.v, "kitchen"); @@ -1096,8 +1124,9 @@ public void testQueryDoubleUnification() { assertThat(row.get("x")).isEqualTo("crackers"); } - @Test - public void testQueryWithInheritance() { + @ParameterizedTest + @MethodSource("parameters") + public void testQueryWithInheritance(RUN_TYPE runType) { // DROOLS-6105 final String str = "" + "global java.util.List list;\n" + @@ -1124,7 +1153,7 @@ public void testQueryWithInheritance() { " list.addAll( $food ); \n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/RuleAttributesTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/RuleAttributesTest.java index 02c73e43f83..a553aafed21 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/RuleAttributesTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/RuleAttributesTest.java @@ -27,7 +27,9 @@ import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.event.rule.AfterMatchFiredEvent; import org.kie.api.event.rule.DefaultAgendaEventListener; import org.kie.api.runtime.KieSession; @@ -37,12 +39,10 @@ public class RuleAttributesTest extends BaseModelTest { - public RuleAttributesTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test(timeout = 5000) - public void testNoLoop() { + @ParameterizedTest + @MethodSource("parameters") + @Timeout(5000) + public void testNoLoop(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R no-loop when\n" + @@ -51,7 +51,7 @@ public void testNoLoop() { " modify($p) { setAge($p.getAge()+1) };\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Person me = new Person( "Mario", 40 ); ksession.insert( me ); @@ -60,8 +60,9 @@ public void testNoLoop() { assertThat(me.getAge()).isEqualTo(41); } - @Test - public void testSalience() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testSalience(RUN_TYPE runType) throws Exception { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -79,7 +80,7 @@ public void testSalience() throws Exception { " delete($p);" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mario", 40)); ksession.fireAllRules(); @@ -89,8 +90,9 @@ public void testSalience() throws Exception { assertThat(results.contains("R2")).isTrue(); } - @Test - public void testSalienceExpressionAttribute() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testSalienceExpressionAttribute(RUN_TYPE runType) throws Exception { String str = "import " + Person.class.getCanonicalName() + ";" + "\n" + "rule R1 salience -$p.getAge() when\n" + @@ -106,7 +108,7 @@ public void testSalienceExpressionAttribute() throws Exception { " delete($p);" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Mario", 40)); ksession.fireAllRules(); @@ -116,8 +118,9 @@ public void testSalienceExpressionAttribute() throws Exception { assertThat(results.contains("R2")).isTrue(); } - @Test - public void testExpressionEnabledAttribute() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testExpressionEnabledAttribute(RUN_TYPE runType) throws Exception { String str = "import " + Person.class.getCanonicalName() + ";\n" + "rule R1\n" + "enabled ($b)\n" + @@ -129,7 +132,7 @@ public void testExpressionEnabledAttribute() throws Exception { " delete($p);" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(Boolean.FALSE); Person mario = new Person("Mario", 40); @@ -142,8 +145,9 @@ public void testExpressionEnabledAttribute() throws Exception { assertThat(!results.contains("R1")).isTrue(); } - @Test - public void testCrossNoLoopWithNodeSharing() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testCrossNoLoopWithNodeSharing(RUN_TYPE runType) throws Exception { String str = "package org.drools.compiler.loop " + "rule 'Rule 1' " + @@ -168,7 +172,7 @@ public void testCrossNoLoopWithNodeSharing() throws Exception { " update( $thing2 ); " + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert( "hello" ); ksession.insert( new Integer( 42 ) ); @@ -181,8 +185,9 @@ public void testCrossNoLoopWithNodeSharing() throws Exception { assertThat(x).isEqualTo(2); } - @Test - public void testCalendars() { + @ParameterizedTest + @MethodSource("parameters") + public void testCalendars(RUN_TYPE runType) { String str = "package org.drools.compiler.integrationtests;\n" + "\n" + @@ -204,7 +209,7 @@ public void testCalendars() { " list.add(\"weekday\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ArrayList list = new ArrayList(); @@ -243,8 +248,9 @@ public boolean isTimeIncluded(long timestamp) { } }; - @Test - public void testAutoFocus() { + @ParameterizedTest + @MethodSource("parameters") + public void testAutoFocus(RUN_TYPE runType) { String str = "package org.drools.testcoverage.functional;\n" + "//generated from Decision Table\n" + @@ -335,7 +341,7 @@ public void testAutoFocus() { "end\n" + "\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final OrderListener listener = new OrderListener(); ksession.addEventListener(listener); @@ -378,8 +384,9 @@ public String get(final int index) { } } - @Test - public void testMetadataBasics() { + @ParameterizedTest + @MethodSource("parameters") + public void testMetadataBasics(RUN_TYPE runType) { final String PACKAGE_NAME = "org.asd"; final String RULE_NAME = "hello world"; final String RULE_KEY = "output"; @@ -392,7 +399,7 @@ public void testMetadataBasics() { " System.out.println(\"Hello world!\");\n" + " end"; - KieSession ksession = getKieSession(rule); + KieSession ksession = getKieSession(runType, rule); final Map metadata = ksession.getKieBase().getRule(PACKAGE_NAME, RULE_NAME).getMetaData(); @@ -400,8 +407,9 @@ public void testMetadataBasics() { assertThat(metadata.get(RULE_KEY)).isEqualTo("\"" + RULE_VALUE + "\""); } - @Test - public void testMetadataValue() { + @ParameterizedTest + @MethodSource("parameters") + public void testMetadataValue(RUN_TYPE runType) { final String rule = " package org.test;\n" + " rule R1\n" + " @metaValueString(\"asd\")\n" + @@ -413,7 +421,7 @@ public void testMetadataValue() { " System.out.println(\"Hello world!\");\n" + " end"; - KieSession ksession = getKieSession(rule); + KieSession ksession = getKieSession(runType, rule); final Map metadata = ksession.getKieBase().getRule("org.test", "R1").getMetaData(); @@ -423,8 +431,9 @@ public void testMetadataValue() { assertThat(metadata.get("metaValueCheck3")).isSameAs(System.out); } - @Test - public void testDynamicSalience() { + @ParameterizedTest + @MethodSource("parameters") + public void testDynamicSalience(RUN_TYPE runType) { String str = "global java.util.List list;\n" + "rule R1 salience $s.length when\n" + @@ -438,7 +447,7 @@ public void testDynamicSalience() { " list.add($i);" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -454,8 +463,9 @@ public void testDynamicSalience() { public static final int CONST_SALIENCE = 1; - @Test - public void testSalienceFromConstant() { + @ParameterizedTest + @MethodSource("parameters") + public void testSalienceFromConstant(RUN_TYPE runType) { // DROOLS-5550 String str = "import " + RuleAttributesTest.class.getCanonicalName() + "\n;" + @@ -471,7 +481,7 @@ public void testSalienceFromConstant() { " list.add($i);" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/SegmentPrototypeExpressionTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/SegmentPrototypeExpressionTest.java index 383a1a044f0..66ee1911396 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/SegmentPrototypeExpressionTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/SegmentPrototypeExpressionTest.java @@ -19,7 +19,7 @@ package org.drools.model.codegen.execmodel; import org.drools.model.prototype.PrototypeExpression; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.prototype.PrototypeFact; import org.kie.api.prototype.PrototypeFactInstance; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TextBlockTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TextBlockTest.java index b0c237961d5..d3517a1124b 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TextBlockTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TextBlockTest.java @@ -22,19 +22,17 @@ import java.util.List; import org.drools.model.codegen.execmodel.domain.Person; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class TextBlockTest extends OnlyExecModelTest { - public TextBlockTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Test - public void testMultiLineStrings() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testMultiLineStrings(RUN_TYPE runType) { final String str = "package org.drools.mvel.compiler\n" + "global java.util.List list;\n" + @@ -53,7 +51,7 @@ public void testMultiLineStrings() { "end\n"; - KieSession ksession = getKieSession(str ); + KieSession ksession = getKieSession(runType, str); final List list = new ArrayList<>(); ksession.setGlobal("list", list); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ToStringTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ToStringTest.java index db49afe2372..1400bf32346 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ToStringTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/ToStringTest.java @@ -31,7 +31,7 @@ import org.drools.model.functions.Predicate1; import org.drools.model.functions.Predicate2; import org.drools.model.view.ExprViewItem; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.runtime.rule.AccumulateFunction; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeCoercionTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeCoercionTest.java index 67cd73f3bd3..b83c11cc216 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeCoercionTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeCoercionTest.java @@ -28,19 +28,17 @@ import org.drools.model.codegen.execmodel.domain.DateTimeHolder; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class TypeCoercionTest extends BaseModelTest { - public TypeCoercionTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testEqualCoercion() { + @ParameterizedTest + @MethodSource("parameters") + public void testEqualCoercion(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List list\n" + @@ -50,7 +48,7 @@ public void testEqualCoercion() { " list.add($name);" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -63,8 +61,9 @@ public void testEqualCoercion() { assertThat(list.get(0)).isEqualTo("40"); } - @Test - public void testComparisonCoercion() { + @ParameterizedTest + @MethodSource("parameters") + public void testComparisonCoercion(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List list\n" + @@ -74,7 +73,7 @@ public void testComparisonCoercion() { " list.add($name);" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -87,8 +86,9 @@ public void testComparisonCoercion() { assertThat(list.get(0)).isEqualTo("40"); } - @Test - public void testComparisonCoercion2() { + @ParameterizedTest + @MethodSource("parameters") + public void testComparisonCoercion2(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List list\n" + @@ -98,7 +98,7 @@ public void testComparisonCoercion2() { " list.add($name);" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -111,8 +111,9 @@ public void testComparisonCoercion2() { assertThat(list.get(0)).isEqualTo("Mario"); } - @Test - public void testPrimitiveCoercion() { + @ParameterizedTest + @MethodSource("parameters") + public void testPrimitiveCoercion(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List list\n" + @@ -122,7 +123,7 @@ public void testPrimitiveCoercion() { " list.add(\"\" + $n);" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -147,8 +148,9 @@ public Long getValue() { } } - @Test - public void testDoubleToInt() { + @ParameterizedTest + @MethodSource("parameters") + public void testDoubleToInt(RUN_TYPE runType) { final String drl1 = "import " + DoubleHolder.class.getCanonicalName() + ";\n" + "rule R when\n" + @@ -156,14 +158,15 @@ public void testDoubleToInt() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert(new DoubleHolder()); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testLongToInt() { + @ParameterizedTest + @MethodSource("parameters") + public void testLongToInt(RUN_TYPE runType) { final String drl1 = "import " + LongHolder.class.getCanonicalName() + ";\n" + "rule R when\n" + @@ -171,14 +174,15 @@ public void testLongToInt() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert(new LongHolder()); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testJoinLongToDouble() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinLongToDouble(RUN_TYPE runType) { final String drl1 = "import " + DoubleHolder.class.getCanonicalName() + ";\n" + "import " + LongHolder.class.getCanonicalName() + ";\n" + @@ -188,15 +192,16 @@ public void testJoinLongToDouble() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert(new LongHolder()); ksession.insert(new DoubleHolder()); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testJoinDoubleToLong() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinDoubleToLong(RUN_TYPE runType) { final String drl1 = "import " + DoubleHolder.class.getCanonicalName() + ";\n" + "import " + LongHolder.class.getCanonicalName() + ";\n" + @@ -206,15 +211,16 @@ public void testJoinDoubleToLong() { "then\n" + "end\n"; - KieSession ksession = getKieSession( drl1 ); + KieSession ksession = getKieSession(runType, drl1); ksession.insert(new LongHolder()); ksession.insert(new DoubleHolder()); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testStringToDateComparison() { + @ParameterizedTest + @MethodSource("parameters") + public void testStringToDateComparison(RUN_TYPE runType) { String str = "import " + Date.class.getCanonicalName() + ";\n" + "declare Flight departuretime : java.util.Date end\n" + @@ -224,13 +230,14 @@ public void testStringToDateComparison() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ChildFactWithObject(5, 1, new Object[0]) ); assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testBetaJoinShortInt() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaJoinShortInt(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -239,12 +246,13 @@ public void testBetaJoinShortInt() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testBetaJoinShortIntBoxed() { + @ParameterizedTest + @MethodSource("parameters") + public void testBetaJoinShortIntBoxed(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + @@ -253,12 +261,13 @@ public void testBetaJoinShortIntBoxed() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testPrimitivePromotionInLHS() { + @ParameterizedTest + @MethodSource("parameters") + public void testPrimitivePromotionInLHS(RUN_TYPE runType) { // DROOLS-4717 String str = "import " + Person.class.getCanonicalName() + ";" + @@ -269,7 +278,7 @@ public void testPrimitivePromotionInLHS() { " insert(new Result($p));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); final Person luca = new Person("Luca", 35); ksession.insert(luca); @@ -281,8 +290,9 @@ public void testPrimitivePromotionInLHS() { assertThat(results.stream().map(Result::getValue)).containsExactlyInAnyOrder(luca); } - @Test - public void testIntToObjectCoercion() { + @ParameterizedTest + @MethodSource("parameters") + public void testIntToObjectCoercion(RUN_TYPE runType) { // DROOLS-5320 String str = "rule R when\n" + @@ -291,14 +301,15 @@ public void testIntToObjectCoercion() { "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert( 3 ); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testDoubleNaN() { + @ParameterizedTest + @MethodSource("parameters") + public void testDoubleNaN(RUN_TYPE runType) { // DROOLS-5692 String str = "import " + DoubleNaNPojo.class.getCanonicalName() + ";\n" + @@ -312,7 +323,7 @@ public void testDoubleNaN() { " update($nanTest);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); DoubleNaNPojo nan = new DoubleNaNPojo(); nan.setTestBoolean(false); @@ -386,8 +397,9 @@ public Short getTestShort() { } } - @Test - public void testStringToIntCoercion() { + @ParameterizedTest + @MethodSource("parameters") + public void testStringToIntCoercion(RUN_TYPE runType) { // DROOLS-5939 String str = "import " + ClassWithIntProperty.class.getCanonicalName() + ";\n" + @@ -399,7 +411,7 @@ public void testStringToIntCoercion() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ClassWithIntProperty( 10 ) ); ksession.insert( new ClassWithStringProperty( "10" ) ); @@ -407,8 +419,9 @@ public void testStringToIntCoercion() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testIntToStringCoercion() { + @ParameterizedTest + @MethodSource("parameters") + public void testIntToStringCoercion(RUN_TYPE runType) { // DROOLS-5939 String str = "import " + ClassWithIntProperty.class.getCanonicalName() + ";\n" + @@ -420,7 +433,7 @@ public void testIntToStringCoercion() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ClassWithIntProperty( 10 ) ); ksession.insert( new ClassWithStringProperty( "10" ) ); @@ -428,8 +441,9 @@ public void testIntToStringCoercion() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testShortToIntCoercion() { + @ParameterizedTest + @MethodSource("parameters") + public void testShortToIntCoercion(RUN_TYPE runType) { // DROOLS-5939 String str = "import " + ClassWithShortProperty.class.getCanonicalName() + ";\n" + @@ -441,7 +455,7 @@ public void testShortToIntCoercion() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ClassWithShortProperty( (short)10 ) ); ksession.insert( new ClassWithIntProperty( 10 ) ); @@ -449,8 +463,9 @@ public void testShortToIntCoercion() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testIntToShortCoercion() { + @ParameterizedTest + @MethodSource("parameters") + public void testIntToShortCoercion(RUN_TYPE runType) { // DROOLS-5939 String str = "import " + ClassWithShortProperty.class.getCanonicalName() + ";\n" + @@ -462,7 +477,7 @@ public void testIntToShortCoercion() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ClassWithShortProperty( (short)10 ) ); ksession.insert( new ClassWithIntProperty( 10 ) ); @@ -470,8 +485,9 @@ public void testIntToShortCoercion() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testCoercionOnBoundVariable() { + @ParameterizedTest + @MethodSource("parameters") + public void testCoercionOnBoundVariable(RUN_TYPE runType) { // DROOLS-5945 String str = "import " + ClassWithIntProperty.class.getCanonicalName() + ";\n" + @@ -481,15 +497,16 @@ public void testCoercionOnBoundVariable() { "then\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( new ClassWithIntProperty( 3 ) ); assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testCompareDateLiteral() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testCompareDateLiteral(RUN_TYPE runType) throws Exception { String str = "import " + DateTimeHolder.class.getCanonicalName() + ";" + "rule R when\n" + @@ -497,15 +514,16 @@ public void testCompareDateLiteral() throws Exception { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new DateTimeHolder(ZonedDateTime.now())); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testCompareLocalDateLiteral() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testCompareLocalDateLiteral(RUN_TYPE runType) throws Exception { String str = "import " + DateTimeHolder.class.getCanonicalName() + ";" + "rule R when\n" + @@ -513,15 +531,16 @@ public void testCompareLocalDateLiteral() throws Exception { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new DateTimeHolder(ZonedDateTime.now())); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testCompareLocalDateTimeLiteral() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testCompareLocalDateTimeLiteral(RUN_TYPE runType) throws Exception { String str = "import " + DateTimeHolder.class.getCanonicalName() + ";" + "rule R when\n" + @@ -529,15 +548,16 @@ public void testCompareLocalDateTimeLiteral() throws Exception { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new DateTimeHolder(ZonedDateTime.now())); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testCompareLocalDateTimeLiteral2() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testCompareLocalDateTimeLiteral2(RUN_TYPE runType) throws Exception { String str = "import " + DateTimeHolder.class.getCanonicalName() + ";" + "rule R when\n" + @@ -545,21 +565,22 @@ public void testCompareLocalDateTimeLiteral2() throws Exception { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new DateTimeHolder(ZonedDateTime.now())); assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testPrimitiveDoubleToIntCoercion() { + @ParameterizedTest + @MethodSource("parameters") + public void testPrimitiveDoubleToIntCoercion(RUN_TYPE runType) { // DROOLS-6491 - checkDoubleToIntCoercion(true); - checkDoubleToIntCoercion(false); + checkDoubleToIntCoercion(runType, true); + checkDoubleToIntCoercion(runType, false); } - private void checkDoubleToIntCoercion(boolean boxed) { + private void checkDoubleToIntCoercion(RUN_TYPE runType, boolean boxed) { String str = "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List list\n" + @@ -569,7 +590,7 @@ private void checkDoubleToIntCoercion(boolean boxed) { " list.add($name);" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -582,8 +603,9 @@ private void checkDoubleToIntCoercion(boolean boxed) { assertThat(list.get(0)).isEqualTo("Mario"); } - @Test - public void testFloatOperation() { + @ParameterizedTest + @MethodSource("parameters") + public void testFloatOperation(RUN_TYPE runType) { // DROOLS-7334 String str = "import " + Person.class.getCanonicalName() + "\n" + @@ -594,7 +616,7 @@ public void testFloatOperation() { " list.add($name);" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List list = new ArrayList<>(); ksession.setGlobal( "list", list ); @@ -613,8 +635,9 @@ public void testFloatOperation() { assertThat(list.get(0)).isEqualTo("Mario"); } - @Test - public void testCoerceObjectToString() { + @ParameterizedTest + @MethodSource("parameters") + public void testCoerceObjectToString(RUN_TYPE runType) { String str = "package constraintexpression\n" + "\n" + "import " + Person.class.getCanonicalName() + "\n" + @@ -627,7 +650,7 @@ public void testCoerceObjectToString() { " System.out.println($p); \n" + "end \n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); try { Person person = new Person("someName"); ksession.insert(person); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeDeclarationTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeDeclarationTest.java index e34aeb6ffed..a985ac0c156 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeDeclarationTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeDeclarationTest.java @@ -18,14 +18,14 @@ */ package org.drools.model.codegen.execmodel; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.definition.type.FactType; import org.kie.api.runtime.KieSession; @@ -34,12 +34,9 @@ public class TypeDeclarationTest extends BaseModelTest { - public TypeDeclarationTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testRecursiveDeclaration() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testRecursiveDeclaration(RUN_TYPE runType) throws Exception { String str = "package org.drools.compiler\n" + "declare Node\n" + @@ -53,7 +50,7 @@ public void testRecursiveDeclaration() throws Exception { " System.out.println( $value );\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); KieBase kbase = ksession.getKieBase(); FactType nodeType = kbase.getFactType( "org.drools.compiler", "Node" ); @@ -70,8 +67,9 @@ public void testRecursiveDeclaration() throws Exception { assertThat(rules).isEqualTo(1); } - @Test - public void testGenerics() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testGenerics(RUN_TYPE runType) throws Exception { // DROOLS-4939 String str = "package org.drools.compiler\n" + @@ -85,7 +83,7 @@ public void testGenerics() throws Exception { " System.out.println( $node );\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); KieBase kbase = ksession.getKieBase(); FactType nodeType = kbase.getFactType( "org.drools.compiler", "Node" ); @@ -101,8 +99,9 @@ public interface ValuesProvider { Map getValues(); } - @Test - public void testGenericsMap() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testGenericsMap(RUN_TYPE runType) throws Exception { // DROOLS-4939 String str = "package org.drools.compiler\n" + @@ -117,7 +116,7 @@ public void testGenericsMap() throws Exception { " System.out.println( $node );\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); KieBase kbase = ksession.getKieBase(); FactType nodeType = kbase.getFactType( "org.drools.compiler", "Node" ); @@ -131,8 +130,9 @@ public void testGenericsMap() throws Exception { assertThat(rules).isEqualTo(1); } - @Test - public void testSerialVersionUID() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testSerialVersionUID(RUN_TYPE runType) throws Exception { // DROOLS-5340 String str = "package org.drools.compiler\n" + @@ -150,13 +150,14 @@ public void testSerialVersionUID() throws Exception { " insert( new ServiceInformation(\"123456\", \"ServiceTest\", new ArrayList()) );\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); int rules = ksession.fireAllRules(); assertThat(rules).isEqualTo(1); } - @Test - public void testSerialVersionUIDWithAllkeys() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testSerialVersionUIDWithAllkeys(RUN_TYPE runType) throws Exception { // DROOLS-5400 String str = "package org.drools.compiler\n" + @@ -174,13 +175,14 @@ public void testSerialVersionUIDWithAllkeys() throws Exception { " insert( new ServiceInformation(\"123456\", \"ServiceTest\", new ArrayList()) );\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); int rules = ksession.fireAllRules(); assertThat(rules).isEqualTo(1); } - @Test - public void testPositionalWithLiteral() { + @ParameterizedTest + @MethodSource("parameters") + public void testPositionalWithLiteral(RUN_TYPE runType) { // DROOLS-6128 String str = "import " + Result.class.getCanonicalName() + ";" + @@ -200,7 +202,7 @@ public void testPositionalWithLiteral() { " insert(new Result($age));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.fireAllRules(); @@ -209,8 +211,9 @@ public void testPositionalWithLiteral() { assertThat(results.iterator().next().getValue()).isEqualTo(37); } - @Test - public void testPositionalWithJoin() { + @ParameterizedTest + @MethodSource("parameters") + public void testPositionalWithJoin(RUN_TYPE runType) { // DROOLS-6128 String str = "import " + Result.class.getCanonicalName() + ";" + @@ -231,7 +234,7 @@ public void testPositionalWithJoin() { " insert(new Result($age));\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.insert( "Mark" ); ksession.fireAllRules(); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeObjectCoercionTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeObjectCoercionTest.java index fdf022aa260..a70c563e22b 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeObjectCoercionTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeObjectCoercionTest.java @@ -23,7 +23,8 @@ import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; @@ -31,11 +32,7 @@ public class TypeObjectCoercionTest extends BaseModelTest { - public TypeObjectCoercionTest(RUN_TYPE testRunType) { - super(testRunType); - } - - private KieSession getKieSessionForJoinObjectToString() { + private KieSession getKieSessionForJoinObjectToString(RUN_TYPE runType) { // NOTE: If we write a test with IntegerHolder instead of ObjectHolder, standard-drl fails with a compilation error // text=Unable to Analyse Expression value >= $i: @@ -51,13 +48,14 @@ private KieSession getKieSessionForJoinObjectToString() { "then\n" + "end\n"; - return getKieSession(drl1); + return getKieSession(runType, drl1); } - @Test - public void testJoinObjectToString1() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinObjectToString1(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinObjectToString(); + KieSession ksession = getKieSessionForJoinObjectToString(runType); // String "10" > Integer 5 ksession.insert(new ObjectHolder(Integer.valueOf(5))); @@ -65,10 +63,11 @@ public void testJoinObjectToString1() { assertThat(ksession.fireAllRules()).isEqualTo(1); // standard-drl : 10 > 5 (Number comparison) } - @Test - public void testJoinObjectToString2() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinObjectToString2(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinObjectToString(); + KieSession ksession = getKieSessionForJoinObjectToString(runType); // String "10" > String "5" ksession.insert(new ObjectHolder("5")); @@ -76,10 +75,11 @@ public void testJoinObjectToString2() { assertThat(ksession.fireAllRules()).isEqualTo(0); // standard-drl : "10" < "5" (String comparison) } - @Test - public void testJoinObjectToString3() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinObjectToString3(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinObjectToString(); + KieSession ksession = getKieSessionForJoinObjectToString(runType); // String "ABC" > Integer 5 ksession.insert(new ObjectHolder(Integer.valueOf(5))); @@ -88,10 +88,11 @@ public void testJoinObjectToString3() { assertThatThrownBy(()->ksession.fireAllRules()).isInstanceOf(RuntimeException.class); // standard-drl : ClassCastException: java.lang.Integer cannot be cast to java.lang.String } - @Test - public void testJoinObjectToString4() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinObjectToString4(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinObjectToString(); + KieSession ksession = getKieSessionForJoinObjectToString(runType); // String "10" > String "ABC" ksession.insert(new ObjectHolder("ABC")); @@ -100,10 +101,11 @@ public void testJoinObjectToString4() { ksession.dispose(); } - @Test - public void testJoinObjectToString5() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinObjectToString5(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinObjectToString(); + KieSession ksession = getKieSessionForJoinObjectToString(runType); // String "ABC" > String "DEF" ksession.insert(new ObjectHolder("DEF")); @@ -112,10 +114,11 @@ public void testJoinObjectToString5() { ksession.dispose(); } - @Test - public void testJoinObjectToStringNonComparable() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinObjectToStringNonComparable(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinObjectToString(); + KieSession ksession = getKieSessionForJoinObjectToString(runType); // String "10" > Object ksession.insert(new ObjectHolder(new Object())); // not Comparable @@ -126,7 +129,7 @@ public void testJoinObjectToStringNonComparable() { } - private KieSession getKieSessionForJoinStringToObject() { + private KieSession getKieSessionForJoinStringToObject(RUN_TYPE runType) { final String drl1 = "import " + ObjectHolder.class.getCanonicalName() + ";\n" + @@ -137,13 +140,14 @@ private KieSession getKieSessionForJoinStringToObject() { "then\n" + "end\n"; - return getKieSession(drl1); + return getKieSession(runType, drl1); } - @Test - public void testJoinStringToObject1() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinStringToObject1(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinStringToObject(); + KieSession ksession = getKieSessionForJoinStringToObject(runType); // Integer 5 > String "10" ksession.insert(new StringHolder("10")); @@ -151,10 +155,11 @@ public void testJoinStringToObject1() { assertThat(ksession.fireAllRules()).isEqualTo(0); // standard-drl : 5 < 10 (Number comparison) } - @Test - public void testJoinStringToObject2() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinStringToObject2(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinStringToObject(); + KieSession ksession = getKieSessionForJoinStringToObject(runType); // String "5" > String "10" ksession.insert(new StringHolder("10")); @@ -162,10 +167,11 @@ public void testJoinStringToObject2() { assertThat(ksession.fireAllRules()).isEqualTo(1); // standard-drl : "5" > "10" (String comparison) } - @Test - public void testJoinStringToObject3() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinStringToObject3(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinStringToObject(); + KieSession ksession = getKieSessionForJoinStringToObject(runType); // Integer 5 > String "ABC" ksession.insert(new StringHolder("ABC")); @@ -176,10 +182,11 @@ public void testJoinStringToObject3() { } - @Test - public void testJoinStringToObject4() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinStringToObject4(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinStringToObject(); + KieSession ksession = getKieSessionForJoinStringToObject(runType); // String "ABC" > String "10" ksession.insert(new StringHolder("10")); @@ -188,10 +195,11 @@ public void testJoinStringToObject4() { ksession.dispose(); } - @Test - public void testJoinStringToObject5() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinStringToObject5(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinStringToObject(); + KieSession ksession = getKieSessionForJoinStringToObject(runType); // String "DEF" > String "ABC" ksession.insert(new StringHolder("ABC")); @@ -200,7 +208,7 @@ public void testJoinStringToObject5() { ksession.dispose(); } - private KieSession getKieSessionForJoinIntegerToObject() { + private KieSession getKieSessionForJoinIntegerToObject(RUN_TYPE runType) { final String drl1 = "import " + ObjectHolder.class.getCanonicalName() + ";\n" + @@ -211,13 +219,14 @@ private KieSession getKieSessionForJoinIntegerToObject() { "then\n" + "end\n"; - return getKieSession(drl1); + return getKieSession(runType, drl1); } - @Test - public void testJoinIntegerToObject1() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinIntegerToObject1(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinIntegerToObject(); + KieSession ksession = getKieSessionForJoinIntegerToObject(runType); // Integer 10 > Integer 5 ksession.insert(new IntegerHolder(Integer.valueOf(5))); @@ -225,10 +234,11 @@ public void testJoinIntegerToObject1() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testJoinIntegerToObject2() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinIntegerToObject2(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinIntegerToObject(); + KieSession ksession = getKieSessionForJoinIntegerToObject(runType); // String "10" > Integer 5 ksession.insert(new IntegerHolder(Integer.valueOf(5))); @@ -236,10 +246,11 @@ public void testJoinIntegerToObject2() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testJoinIntegerToObject3() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinIntegerToObject3(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinIntegerToObject(); + KieSession ksession = getKieSessionForJoinIntegerToObject(runType); // String "ABC" > Integer 5 ksession.insert(new IntegerHolder(Integer.valueOf(5))); @@ -248,10 +259,11 @@ public void testJoinIntegerToObject3() { assertThatThrownBy(()->ksession.fireAllRules()).isInstanceOf(RuntimeException.class); // standard-drl : Caused by ClassCastException: java.lang.String cannot be cast to java.lang.Integer } - @Test - public void testJoinIntegerToObjectNonComparable() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinIntegerToObjectNonComparable(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinIntegerToObject(); + KieSession ksession = getKieSessionForJoinIntegerToObject(runType); // Object > Integer 5 ksession.insert(new IntegerHolder(Integer.valueOf(5))); @@ -259,7 +271,7 @@ public void testJoinIntegerToObjectNonComparable() { assertThat(ksession.fireAllRules()).isEqualTo(0); // in case of standard-drl, MathProcessor.doOperationNonNumeric() returns false when the left operand is not Comparable } - private KieSession getKieSessionForJoinObjectToInteger() { + private KieSession getKieSessionForJoinObjectToInteger(RUN_TYPE runType) { final String drl1 = "import " + ObjectHolder.class.getCanonicalName() + ";\n" + @@ -270,13 +282,14 @@ private KieSession getKieSessionForJoinObjectToInteger() { "then\n" + "end\n"; - return getKieSession(drl1); + return getKieSession(runType, drl1); } - @Test - public void testJoinObjectToInteger1() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinObjectToInteger1(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinObjectToInteger(); + KieSession ksession = getKieSessionForJoinObjectToInteger(runType); // Integer 10 > Integer 5 ksession.insert(new ObjectHolder(Integer.valueOf(5))); @@ -284,10 +297,11 @@ public void testJoinObjectToInteger1() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testJoinObjectToInteger2() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinObjectToInteger2(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinObjectToInteger(); + KieSession ksession = getKieSessionForJoinObjectToInteger(runType); // Integer 10 > String "5" ksession.insert(new ObjectHolder(new String("5"))); @@ -295,10 +309,11 @@ public void testJoinObjectToInteger2() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testJoinObjectToInteger3() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinObjectToInteger3(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinObjectToInteger(); + KieSession ksession = getKieSessionForJoinObjectToInteger(runType); // Integer 10 > String "ABC" ksession.insert(new ObjectHolder(new String("ABC"))); @@ -307,10 +322,11 @@ public void testJoinObjectToInteger3() { assertThatThrownBy(()->ksession.fireAllRules()).isInstanceOf(RuntimeException.class); // standard-drl : Caused by ClassCastException: java.lang.String cannot be cast to java.lang.Integer } - @Test - public void testJoinObjectToIntegerNonComparable() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinObjectToIntegerNonComparable(RUN_TYPE runType) { - KieSession ksession = getKieSessionForJoinObjectToInteger(); + KieSession ksession = getKieSessionForJoinObjectToInteger(runType); // Integer 10 > Object ksession.insert(new ObjectHolder(new Object())); // not Comparable @@ -359,8 +375,9 @@ public Integer getValue() { } } - @Test - public void testJoinObjectToStringWithMap() { + @ParameterizedTest + @MethodSource("parameters") + public void testJoinObjectToStringWithMap(RUN_TYPE runType) { // This rule mimics JittingTest#testJitMapCoercion() @@ -373,7 +390,7 @@ public void testJoinObjectToStringWithMap() { "then\n" + "end\n"; - KieSession ksession = getKieSession(drl1); + KieSession ksession = getKieSession(runType, drl1); Map map = new HashMap<>(); map.put("key", 5); @@ -382,8 +399,9 @@ public void testJoinObjectToStringWithMap() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testCoercionStringVsObjectIntegerWithMap() { + @ParameterizedTest + @MethodSource("parameters") + public void testCoercionStringVsObjectIntegerWithMap(RUN_TYPE runType) { final String drl = "package org.drools.compiler.integrationtests;\n" + "import " + Map.class.getCanonicalName() + ";\n" + "import " + StringHolder.class.getCanonicalName() + ";\n" + @@ -398,7 +416,7 @@ public void testCoercionStringVsObjectIntegerWithMap() { // String is coerced to Integer (thus, Number comparison) - KieSession ksession = getKieSession(drl); + KieSession ksession =getKieSession(runType, drl); try { final List list = new ArrayList<>(); ksession.setGlobal("list", list); @@ -424,8 +442,9 @@ public void testCoercionStringVsObjectIntegerWithMap() { } } - @Test - public void testCoercionStringVsExplicitIntegerWithMap() { + @ParameterizedTest + @MethodSource("parameters") + public void testCoercionStringVsExplicitIntegerWithMap(RUN_TYPE runType) { final String drl = "package org.drools.compiler.integrationtests;\n" + "import " + Map.class.getCanonicalName() + ";\n" + "import " + StringHolder.class.getCanonicalName() + ";\n" + @@ -440,7 +459,7 @@ public void testCoercionStringVsExplicitIntegerWithMap() { // String is coerced to Integer (thus, Number comparison) - KieSession ksession = getKieSession(drl); + KieSession ksession =getKieSession(runType, drl); try { final List list = new ArrayList<>(); ksession.setGlobal("list", list); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/UseClassFieldsInRulesTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/UseClassFieldsInRulesTest.java index beec7efc349..3e1a920ea99 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/UseClassFieldsInRulesTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/UseClassFieldsInRulesTest.java @@ -18,16 +18,14 @@ */ package org.drools.model.codegen.execmodel; -import org.junit.Test; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; -public class UseClassFieldsInRulesTest extends BaseModelTest { +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; - public UseClassFieldsInRulesTest( BaseModelTest.RUN_TYPE testRunType ) { - super( testRunType ); - } +public class UseClassFieldsInRulesTest extends BaseModelTest { public static class ClassWithFields { public final int field = 3; @@ -38,54 +36,63 @@ public int getValue() { } } - @Test - public void testUseAccessor() { - doCheck(true, "value > 2"); + @ParameterizedTest + @MethodSource("parameters") + public void testUseAccessor(RUN_TYPE runType) { + doCheck(runType, true, "value > 2"); } - @Test - public void testUseField() { - doCheck(true, "field > 2"); + @ParameterizedTest + @MethodSource("parameters") + public void testUseField(RUN_TYPE runType) { + doCheck(runType, true, "field > 2"); } - @Test - public void testUseStaticField() { - doCheck(true, "STATIC_FIELD > 2"); + @ParameterizedTest + @MethodSource("parameters") + public void testUseStaticField(RUN_TYPE runType) { + doCheck(runType, true, "STATIC_FIELD > 2"); } - @Test - public void testUseAccessorInFunction() { - doCheck(true, "greaterThan( value, 2 )"); + @ParameterizedTest + @MethodSource("parameters") + public void testUseAccessorInFunction(RUN_TYPE runType) { + doCheck(runType, true, "greaterThan( value, 2 )"); } - @Test - public void testUseFieldInFunction() { - doCheck(true, "greaterThan( field, 2 )"); + @ParameterizedTest + @MethodSource("parameters") + public void testUseFieldInFunction(RUN_TYPE runType) { + doCheck(runType, true, "greaterThan( field, 2 )"); } - @Test - public void testUseStaticFieldInFunction() { - doCheck(true, "greaterThan( STATIC_FIELD, 2 )"); + @ParameterizedTest + @MethodSource("parameters") + public void testUseStaticFieldInFunction(RUN_TYPE runType) { + doCheck(runType, true, "greaterThan( STATIC_FIELD, 2 )"); } public static boolean greaterThanMethod(int i1, int i2) { return i1 > i2; } - @Test - public void testUseAccessorInMethod() { - doCheck(false, "greaterThanMethod( value, 2 )"); + @ParameterizedTest + @MethodSource("parameters") + public void testUseAccessorInMethod(RUN_TYPE runType) { + doCheck(runType, false, "greaterThanMethod( value, 2 )"); } - @Test - public void testUseFieldInMethod() { - doCheck(false, "greaterThanMethod( field, 2 )"); + @ParameterizedTest + @MethodSource("parameters") + public void testUseFieldInMethod(RUN_TYPE runType) { + doCheck(runType, false, "greaterThanMethod( field, 2 )"); } - @Test - public void testUseStaticFieldInMethod() { - doCheck(false, "greaterThanMethod( STATIC_FIELD, 2 )"); + @ParameterizedTest + @MethodSource("parameters") + public void testUseStaticFieldInMethod(RUN_TYPE runType) { + doCheck(runType, false, "greaterThanMethod( STATIC_FIELD, 2 )"); } - private void doCheck(boolean useFunction, String pattern) { + private void doCheck(RUN_TYPE runType, boolean useFunction, String pattern) { String str = "import " + ClassWithFields.class.getCanonicalName() + "\n" + (useFunction ? @@ -96,14 +103,15 @@ private void doCheck(boolean useFunction, String pattern) { "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new ClassWithFields()); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testMethodInFrom() { + @ParameterizedTest + @MethodSource("parameters") + public void testMethodInFrom(RUN_TYPE runType) { String str = "import " + ClassWithFields.class.getCanonicalName() + "\n" + "import static " + UseClassFieldsInRulesTest.class.getCanonicalName() + ".*\n" + @@ -112,12 +120,13 @@ public void testMethodInFrom() { "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testMethodInEval() { + @ParameterizedTest + @MethodSource("parameters") + public void testMethodInEval(RUN_TYPE runType) { String str = "import " + ClassWithFields.class.getCanonicalName() + "\n" + "import static " + UseClassFieldsInRulesTest.class.getCanonicalName() + ".*\n" + @@ -126,12 +135,13 @@ public void testMethodInEval() { "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testFunctionInFrom() { + @ParameterizedTest + @MethodSource("parameters") + public void testFunctionInFrom(RUN_TYPE runType) { String str = "import " + ClassWithFields.class.getCanonicalName() + "\n" + "function boolean greaterThan(int i1, int i2) { return i1 > i2; }\n" + @@ -140,12 +150,13 @@ public void testFunctionInFrom() { "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testFunctionWithEval() { + @ParameterizedTest + @MethodSource("parameters") + public void testFunctionWithEval(RUN_TYPE runType) { String str = "import " + ClassWithFields.class.getCanonicalName() + "\n" + "function boolean greaterThan(int i1, int i2) { return i1 > i2; }\n" + @@ -154,7 +165,7 @@ public void testFunctionWithEval() { "then\n" + "end "; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); assertThat(ksession.fireAllRules()).isEqualTo(1); } } diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/alphaNetworkCompiler/ObjectTypeNodeCompilerTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/alphaNetworkCompiler/ObjectTypeNodeCompilerTest.java index 682c060394c..8c4a9610d73 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/alphaNetworkCompiler/ObjectTypeNodeCompilerTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/alphaNetworkCompiler/ObjectTypeNodeCompilerTest.java @@ -25,19 +25,17 @@ import org.drools.model.codegen.execmodel.domain.EnumFact1; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class ObjectTypeNodeCompilerTest extends BaseModelTest { - public ObjectTypeNodeCompilerTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Test - public void testAlphaConstraint() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaConstraint(RUN_TYPE runType) { String str = "rule \"Bind\"\n" + "when\n" + @@ -45,7 +43,7 @@ public void testAlphaConstraint() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert("Luca"); ksession.insert("Asdrubale"); @@ -53,8 +51,9 @@ public void testAlphaConstraint() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAlphaConstraintsSwitchString() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaConstraintsSwitchString(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule \"Bind1\"\n" + @@ -73,7 +72,7 @@ public void testAlphaConstraintsSwitchString() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Luca")); ksession.insert(new Person("Asdrubale")); @@ -84,8 +83,9 @@ public void testAlphaConstraintsSwitchString() { /* This generates the switch but not the inlining */ - @Test - public void testAlphaConstraintsSwitchBigDecimal() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaConstraintsSwitchBigDecimal(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + BigDecimal.class.getCanonicalName() + ";" + @@ -105,7 +105,7 @@ public void testAlphaConstraintsSwitchBigDecimal() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Luca", new BigDecimal(0))); ksession.insert(new Person("Asdrubale", new BigDecimal(10))); @@ -113,8 +113,9 @@ public void testAlphaConstraintsSwitchBigDecimal() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAlphaConstraintsSwitchPerson() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaConstraintsSwitchPerson(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule \"Bind1\"\n" + @@ -133,7 +134,7 @@ public void testAlphaConstraintsSwitchPerson() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new Person("Luca")); ksession.insert(new Person("Asdrubale")); @@ -141,8 +142,9 @@ public void testAlphaConstraintsSwitchPerson() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testAlphaConstraintsSwitchIntegers() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaConstraintsSwitchIntegers(RUN_TYPE runType) { String str = "rule \"Bind1\"\n" + "when\n" + @@ -160,7 +162,7 @@ public void testAlphaConstraintsSwitchIntegers() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert("Luca"); ksession.insert("Asdrubale"); @@ -168,8 +170,9 @@ public void testAlphaConstraintsSwitchIntegers() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testEnum() { + @ParameterizedTest + @MethodSource("parameters") + public void testEnum(RUN_TYPE runType) { String str = "import " + EnumFact1.class.getCanonicalName() + ";\n" + "import " + ChildFactWithEnum1.class.getCanonicalName() + ";\n" + @@ -186,14 +189,15 @@ public void testEnum() { "then\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert(new ChildFactWithEnum1(1, 3, EnumFact1.FIRST)); ksession.insert(new ChildFactWithEnum1(1, 3, EnumFact1.SECOND)); assertThat(ksession.fireAllRules()).isEqualTo(2); } - @Test - public void testAlphaConstraintWithModification() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaConstraintWithModification(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "rule \"Bind\"\n" + @@ -204,7 +208,7 @@ public void testAlphaConstraintWithModification() { " $r.setValue($s + \" is greater than 4 and smaller than 10\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ksession.insert("Luca"); ksession.insert("Asdrubale"); @@ -218,8 +222,9 @@ public void testAlphaConstraintWithModification() { assertThat(result.getValue()).isEqualTo("Asdrubale is greater than 4 and smaller than 10"); } - @Test - public void testModify() { + @ParameterizedTest + @MethodSource("parameters") + public void testModify(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule \"Modify\"\n" + @@ -229,7 +234,7 @@ public void testModify() { " modify($p) { setName($p.getName() + \"30\"); }" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); final Person luca = new Person("Luca", 30); ksession.insert(luca); @@ -240,8 +245,9 @@ public void testModify() { assertThat(luca.getName()).isEqualTo("Luca30"); } - @Test - public void testModify2() { + @ParameterizedTest + @MethodSource("parameters") + public void testModify2(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule \"Modify\"\n" + @@ -251,7 +257,7 @@ public void testModify2() { " modify($p) { setAge($p.getAge() + 1); }" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); final Person luca = new Person("Luca", 30); ksession.insert(luca); @@ -265,8 +271,9 @@ public void testModify2() { assertThat(luca.getAge() == 40).isTrue(); } - @Test - public void testAlphaConstraintNagate() { + @ParameterizedTest + @MethodSource("parameters") + public void testAlphaConstraintNagate(RUN_TYPE runType) { final String str = "import " + Person.class.getCanonicalName() + ";\n" + "rule R1 when\n" + @@ -274,7 +281,7 @@ public void testAlphaConstraintNagate() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); try { ksession.insert(new Person("Mario", 45)); assertThat(ksession.fireAllRules()).isEqualTo(0); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/assembler/AssemblerTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/assembler/AssemblerTest.java index 244c35e90eb..5b29de0af4e 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/assembler/AssemblerTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/assembler/AssemblerTest.java @@ -21,7 +21,7 @@ import java.util.List; import org.drools.model.codegen.ExecutableModelProject; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/bigdecimaltest/BigDecimalTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/bigdecimaltest/BigDecimalTest.java index 885b27cb026..038b4950442 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/bigdecimaltest/BigDecimalTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/bigdecimaltest/BigDecimalTest.java @@ -23,19 +23,17 @@ import java.util.List; import org.drools.model.codegen.execmodel.BaseModelTest; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class BigDecimalTest extends BaseModelTest { - public BigDecimalTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Test - public void testBigDecimalGreaterThan() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalGreaterThan(RUN_TYPE runType) { String str = "package org.drools.modelcompiler.bigdecimals\n" + "import " + Customer.class.getCanonicalName() + ";\n" + @@ -50,7 +48,7 @@ public void testBigDecimalGreaterThan() { "update($policy);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Customer customer = new Customer(); customer.setCode("code1"); @@ -67,8 +65,9 @@ public void testBigDecimalGreaterThan() { } - @Test - public void testBigDecimalCompare() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalCompare(RUN_TYPE runType) { String str = "package org.drools.modelcompiler.bigdecimals\n" + "import " + Customer.class.getCanonicalName() + ";\n" + @@ -83,7 +82,7 @@ public void testBigDecimalCompare() { "update($policy);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Customer customer = new Customer(); customer.setCode("code1"); @@ -100,8 +99,9 @@ public void testBigDecimalCompare() { } - @Test - public void testBigDecimalEqualsToNull() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalEqualsToNull(RUN_TYPE runType) { String str = "package org.drools.modelcompiler.bigdecimals\n" + "import " + Customer.class.getCanonicalName() + ";\n" + @@ -112,7 +112,7 @@ public void testBigDecimalEqualsToNull() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Customer customer = new Customer(); @@ -120,8 +120,9 @@ public void testBigDecimalEqualsToNull() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testBigDecimalNotEqualsToNull() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalNotEqualsToNull(RUN_TYPE runType) { String str = "package org.drools.modelcompiler.bigdecimals\n" + "import " + Customer.class.getCanonicalName() + ";\n" + @@ -132,7 +133,7 @@ public void testBigDecimalNotEqualsToNull() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Customer customer = new Customer(); customer.setCode("code1"); @@ -142,8 +143,9 @@ public void testBigDecimalNotEqualsToNull() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testBigDecimalNotEqualsToLiteralNull() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalNotEqualsToLiteralNull(RUN_TYPE runType) { String str = "package org.drools.modelcompiler.bigdecimals\n" + "import " + Customer.class.getCanonicalName() + ";\n" + @@ -154,7 +156,7 @@ public void testBigDecimalNotEqualsToLiteralNull() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Customer customer = new Customer(); customer.setCode("code1"); @@ -164,8 +166,9 @@ public void testBigDecimalNotEqualsToLiteralNull() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testBigDecimalNotEqualsToLiteralValue() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalNotEqualsToLiteralValue(RUN_TYPE runType) { String str = "package org.drools.modelcompiler.bigdecimals\n" + "import " + Customer.class.getCanonicalName() + ";\n" + @@ -176,7 +179,7 @@ public void testBigDecimalNotEqualsToLiteralValue() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Customer customer = new Customer(); customer.setCode("code1"); @@ -186,8 +189,9 @@ public void testBigDecimalNotEqualsToLiteralValue() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testBigDecimalGreaterThanNull() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalGreaterThanNull(RUN_TYPE runType) { String str = "package org.drools.modelcompiler.bigdecimals\n" + "import " + Customer.class.getCanonicalName() + ";\n" + @@ -198,7 +202,7 @@ public void testBigDecimalGreaterThanNull() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Customer customer = new Customer(); customer.setCode("code1"); @@ -208,8 +212,9 @@ public void testBigDecimalGreaterThanNull() { assertThat(ksession.fireAllRules()).isEqualTo(0); } - @Test - public void testBigDecimalEquals() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalEquals(RUN_TYPE runType) { // DROOLS-3527 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -220,7 +225,7 @@ public void testBigDecimalEquals() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Customer customer = new Customer(); customer.setRate(new BigDecimal("12.111")); @@ -231,8 +236,9 @@ public void testBigDecimalEquals() { } - @Test - public void testBigDecimalAdd() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalAdd(RUN_TYPE runType) { // RHDM-1635 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -243,7 +249,7 @@ public void testBigDecimalAdd() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Customer c1 = new Customer(); c1.setRate(new BigDecimal("10")); @@ -256,8 +262,9 @@ public void testBigDecimalAdd() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testBigDecimalRemainder() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalRemainder(RUN_TYPE runType) { // RHDM-1635 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -268,7 +275,7 @@ public void testBigDecimalRemainder() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Customer c1 = new Customer(); c1.setRate(new BigDecimal("20")); @@ -313,8 +320,9 @@ public String toString() { } } - @Test - public void testNonTerminatingDecimalExpansion() { + @ParameterizedTest + @MethodSource("parameters") + public void testNonTerminatingDecimalExpansion(RUN_TYPE runType) { // DROOLS-6804 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -325,7 +333,7 @@ public void testNonTerminatingDecimalExpansion() { " $o.setTax($price - ($price / ($taxRate + 1)));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Order order = new Order(); order.setPrice(new BigDecimal("100000000")); @@ -336,8 +344,9 @@ public void testNonTerminatingDecimalExpansion() { assertThat(order.getTax()).isEqualTo(new BigDecimal("9090909.09090909090909090909090909")); } - @Test - public void testBigDecimalAndStringComparison() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalAndStringComparison(RUN_TYPE runType) { // DROOLS-6823 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -348,7 +357,7 @@ public void testBigDecimalAndStringComparison() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Order order = new Order(); order.setPrice(new BigDecimal(300)); @@ -358,8 +367,9 @@ public void testBigDecimalAndStringComparison() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testStringAndBigDecimalComparison() { + @ParameterizedTest + @MethodSource("parameters") + public void testStringAndBigDecimalComparison(RUN_TYPE runType) { // DROOLS-6823 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -370,7 +380,7 @@ public void testStringAndBigDecimalComparison() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Order order = new Order(); order.setPrice(new BigDecimal(300)); @@ -412,62 +422,73 @@ public void setBd2(BigDecimal bd2) { } } - @Test - public void testMultiply() { - testBigDecimalArithmeticOperation("BdHolder(bd2 == bd1 * 10)", "10", "100"); + @ParameterizedTest + @MethodSource("parameters") + public void testMultiply(RUN_TYPE runType) { + testBigDecimalArithmeticOperation(runType, "BdHolder(bd2 == bd1 * 10)", "10", "100"); } - @Test - public void testMultiplyWithNegativeValue() { - testBigDecimalArithmeticOperation("BdHolder(bd2 == bd1 * -1)", "10", "-10"); + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyWithNegativeValue(RUN_TYPE runType) { + testBigDecimalArithmeticOperation(runType, "BdHolder(bd2 == bd1 * -1)", "10", "-10"); } - @Test - public void testMultiplyWithBindVariable() { - testBigDecimalArithmeticOperation("BdHolder($bd1 : bd1, bd2 == $bd1 * 10)", "10", "100"); + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyWithBindVariable(RUN_TYPE runType) { + testBigDecimalArithmeticOperation(runType, "BdHolder($bd1 : bd1, bd2 == $bd1 * 10)", "10", "100"); } - @Test - public void testMultiplyWithBindVariableWithNegativeValue() { - testBigDecimalArithmeticOperation("BdHolder($bd1 : bd1, bd2 == $bd1 * -1)", "10", "-10"); + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyWithBindVariableWithNegativeValue(RUN_TYPE runType) { + testBigDecimalArithmeticOperation(runType, "BdHolder($bd1 : bd1, bd2 == $bd1 * -1)", "10", "-10"); } - @Test - public void testMultiplyWithBindVariableWithNegativeValueEnclosed() { - testBigDecimalArithmeticOperation("BdHolder($bd1 : bd1, bd2 == $bd1 * (-1))", "10", "-10"); + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyWithBindVariableWithNegativeValueEnclosed(RUN_TYPE runType) { + testBigDecimalArithmeticOperation(runType, "BdHolder($bd1 : bd1, bd2 == $bd1 * (-1))", "10", "-10"); } - @Test - public void testMultiplyWithBindVariableWithNegativeValueEnclosedBoth() { - testBigDecimalArithmeticOperation("BdHolder($bd1 : bd1, bd2 == ($bd1 * -1))", "10", "-10"); + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyWithBindVariableWithNegativeValueEnclosedBoth(RUN_TYPE runType) { + testBigDecimalArithmeticOperation(runType, "BdHolder($bd1 : bd1, bd2 == ($bd1 * -1))", "10", "-10"); } - @Test - public void testMultiplyWithBindVariableWithNegativeValueEnclosedNest() { - testBigDecimalArithmeticOperation("BdHolder($bd1 : bd1, bd2 == ($bd1 * (-1)))", "10", "-10"); + @ParameterizedTest + @MethodSource("parameters") + public void testMultiplyWithBindVariableWithNegativeValueEnclosedNest(RUN_TYPE runType) { + testBigDecimalArithmeticOperation(runType, "BdHolder($bd1 : bd1, bd2 == ($bd1 * (-1)))", "10", "-10"); } - @Test - public void testAddWithBindVariable() { - testBigDecimalArithmeticOperation("BdHolder($bd1 : bd1, bd2 == $bd1 + 10)", "10", "20"); + @ParameterizedTest + @MethodSource("parameters") + public void testAddWithBindVariable(RUN_TYPE runType) { + testBigDecimalArithmeticOperation(runType, "BdHolder($bd1 : bd1, bd2 == $bd1 + 10)", "10", "20"); } - @Test - public void testSubtractWithBindVariable() { - testBigDecimalArithmeticOperation("BdHolder($bd1 : bd1, bd2 == $bd1 - 10)", "10", "0"); + @ParameterizedTest + @MethodSource("parameters") + public void testSubtractWithBindVariable(RUN_TYPE runType) { + testBigDecimalArithmeticOperation(runType, "BdHolder($bd1 : bd1, bd2 == $bd1 - 10)", "10", "0"); } - @Test - public void testDivideWithBindVariable() { - testBigDecimalArithmeticOperation("BdHolder($bd1 : bd1, bd2 == $bd1 / 10)", "10", "1"); + @ParameterizedTest + @MethodSource("parameters") + public void testDivideWithBindVariable(RUN_TYPE runType) { + testBigDecimalArithmeticOperation(runType, "BdHolder($bd1 : bd1, bd2 == $bd1 / 10)", "10", "1"); } - @Test - public void testModWithBindVariable() { - testBigDecimalArithmeticOperation("BdHolder($bd1 : bd1, bd2 == $bd1 % 10)", "10", "0"); + @ParameterizedTest + @MethodSource("parameters") + public void testModWithBindVariable(RUN_TYPE runType) { + testBigDecimalArithmeticOperation(runType, "BdHolder($bd1 : bd1, bd2 == $bd1 % 10)", "10", "0"); } - private void testBigDecimalArithmeticOperation(String pattern, String bd1, String bd2) { + private void testBigDecimalArithmeticOperation(RUN_TYPE runType, String pattern, String bd1, String bd2) { String str = "package org.drools.modelcompiler.bigdecimals\n" + "import " + BdHolder.class.getCanonicalName() + ";\n" + @@ -476,7 +497,7 @@ private void testBigDecimalArithmeticOperation(String pattern, String bd1, Strin "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); BdHolder holder = new BdHolder(new BigDecimal(bd1), new BigDecimal(bd2)); ksession.insert(holder); @@ -484,8 +505,9 @@ private void testBigDecimalArithmeticOperation(String pattern, String bd1, Strin assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void testBigDecimalLiteralLhsNegative() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalLiteralLhsNegative(RUN_TYPE runType) { // DROOLS-6596 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -495,7 +517,7 @@ public void testBigDecimalLiteralLhsNegative() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); BdHolder holder = new BdHolder(); holder.setBd1(new BigDecimal("10")); @@ -505,8 +527,9 @@ public void testBigDecimalLiteralLhsNegative() { assertThat(fired).isEqualTo(1); } - @Test - public void testBigDecimalLiteralRhsNegative() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalLiteralRhsNegative(RUN_TYPE runType) { // DROOLS-6596 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -517,7 +540,7 @@ public void testBigDecimalLiteralRhsNegative() { " $holder.bd1 = -10.5B;\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); BdHolder holder = new BdHolder(); ksession.insert(holder); @@ -526,8 +549,9 @@ public void testBigDecimalLiteralRhsNegative() { assertThat(holder.getBd1()).isEqualTo(new BigDecimal("-10.5")); } - @Test - public void testBigDecimalLiteralWithBinding() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigDecimalLiteralWithBinding(RUN_TYPE runType) { // DROOLS-6936 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -540,7 +564,7 @@ public void testBigDecimalLiteralWithBinding() { " result.add($zero);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -552,8 +576,9 @@ public void testBigDecimalLiteralWithBinding() { assertThat(result).containsExactly(new BigDecimal("0")); } - @Test - public void testModifyWithNegativeBigDecimal() { + @ParameterizedTest + @MethodSource("parameters") + public void testModifyWithNegativeBigDecimal(RUN_TYPE runType) { // DROOLS-7324 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -565,7 +590,7 @@ public void testModifyWithNegativeBigDecimal() { " modify($bd) { bd1 = -1 }\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -577,8 +602,9 @@ public void testModifyWithNegativeBigDecimal() { assertThat(fires).isEqualTo(1); } - @Test - public void bigDecimalArithmeticInMethodCallScope() { + @ParameterizedTest + @MethodSource("parameters") + public void bigDecimalArithmeticInMethodCallScope(RUN_TYPE runType) { // DROOLS-7364 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -592,7 +618,7 @@ public void bigDecimalArithmeticInMethodCallScope() { " result.add($ans);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -604,8 +630,9 @@ public void bigDecimalArithmeticInMethodCallScope() { assertThat(result).contains(2000L); } - @Test - public void bigDecimalArithmeticInMethodCallScopeInMethodCallArgument() { + @ParameterizedTest + @MethodSource("parameters") + public void bigDecimalArithmeticInMethodCallScopeInMethodCallArgument(RUN_TYPE runType) { // DROOLS-7364 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -619,7 +646,7 @@ public void bigDecimalArithmeticInMethodCallScopeInMethodCallArgument() { " result.add($ans);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -631,8 +658,9 @@ public void bigDecimalArithmeticInMethodCallScopeInMethodCallArgument() { assertThat(result).contains("2,000"); } - @Test - public void nonBigDecimalArithmeticInMethodCallScopeInMethodCallArgument() { + @ParameterizedTest + @MethodSource("parameters") + public void nonBigDecimalArithmeticInMethodCallScopeInMethodCallArgument(RUN_TYPE runType) { // DROOLS-7364 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -646,7 +674,7 @@ public void nonBigDecimalArithmeticInMethodCallScopeInMethodCallArgument() { " result.add($ans);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -658,8 +686,9 @@ public void nonBigDecimalArithmeticInMethodCallScopeInMethodCallArgument() { assertThat(result).contains("2,000"); } - @Test - public void bigDecimalArithmeticInMethodCallArgumentWithoutEnclosedExpr() { + @ParameterizedTest + @MethodSource("parameters") + public void bigDecimalArithmeticInMethodCallArgumentWithoutEnclosedExpr(RUN_TYPE runType) { // DROOLS-7364 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -674,7 +703,7 @@ public void bigDecimalArithmeticInMethodCallArgumentWithoutEnclosedExpr() { " result.add($ans);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -693,8 +722,9 @@ public static String getString(String format, BigDecimal bd) { } } - @Test - public void bigDecimalEqualityWithDifferentScale_shouldBeEqual() { + @ParameterizedTest + @MethodSource("parameters") + public void bigDecimalEqualityWithDifferentScale_shouldBeEqual(RUN_TYPE runType) { // DROOLS-7414 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -708,7 +738,7 @@ public void bigDecimalEqualityWithDifferentScale_shouldBeEqual() { " result.add($rate);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -722,8 +752,9 @@ public void bigDecimalEqualityWithDifferentScale_shouldBeEqual() { assertThat(result).contains(new BigDecimal("1.00")); } - @Test - public void bigDecimalCoercionInMethodArgument_shouldNotFailToBuild() { + @ParameterizedTest + @MethodSource("parameters") + public void bigDecimalCoercionInMethodArgument_shouldNotFailToBuild(RUN_TYPE runType) { // KIE-748 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -735,7 +766,7 @@ public void bigDecimalCoercionInMethodArgument_shouldNotFailToBuild() { " then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); BDFact bdFact = new BDFact(); bdFact.setValue2(new BigDecimal("3")); @@ -745,8 +776,9 @@ public void bigDecimalCoercionInMethodArgument_shouldNotFailToBuild() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void bigDecimalCoercionInNestedMethodArgument_shouldNotFailToBuild() { + @ParameterizedTest + @MethodSource("parameters") + public void bigDecimalCoercionInNestedMethodArgument_shouldNotFailToBuild(RUN_TYPE runType) { // KIE-748 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -758,7 +790,7 @@ public void bigDecimalCoercionInNestedMethodArgument_shouldNotFailToBuild() { " then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); BDFact bdFact = new BDFact(); bdFact.setValue1(new BigDecimal("10")); @@ -773,22 +805,25 @@ public static String intToString(int value) { return Integer.toString(value); } - @Test - public void bindVariableToBigDecimalCoercion2Operands_shouldBindCorrectResult() { - bindVariableToBigDecimalCoercion("$var : (1000 * value1)"); + @ParameterizedTest + @MethodSource("parameters") + public void bindVariableToBigDecimalCoercion2Operands_shouldBindCorrectResult(RUN_TYPE runType) { + bindVariableToBigDecimalCoercion(runType, "$var : (1000 * value1)"); } - @Test - public void bindVariableToBigDecimalCoercion3Operands_shouldBindCorrectResult() { - bindVariableToBigDecimalCoercion("$var : (100000 * value1 / 100)"); + @ParameterizedTest + @MethodSource("parameters") + public void bindVariableToBigDecimalCoercion3Operands_shouldBindCorrectResult(RUN_TYPE runType) { + bindVariableToBigDecimalCoercion(runType, "$var : (100000 * value1 / 100)"); } - @Test - public void bindVariableToBigDecimalCoercion3OperandsWithParentheses_shouldBindCorrectResult() { - bindVariableToBigDecimalCoercion("$var : ((100000 * value1) / 100)"); + @ParameterizedTest + @MethodSource("parameters") + public void bindVariableToBigDecimalCoercion3OperandsWithParentheses_shouldBindCorrectResult(RUN_TYPE runType) { + bindVariableToBigDecimalCoercion(runType, "$var : ((100000 * value1) / 100)"); } - private void bindVariableToBigDecimalCoercion(String binding) { + private void bindVariableToBigDecimalCoercion(RUN_TYPE runType, String binding) { // KIE-775 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -801,7 +836,7 @@ private void bindVariableToBigDecimalCoercion(String binding) { " result.add($var);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); List result = new ArrayList<>(); ksession.setGlobal("result", result); @@ -814,8 +849,9 @@ private void bindVariableToBigDecimalCoercion(String binding) { assertThat(result).contains(new BigDecimal("80000")); } - @Test - public void bigDecimalInWithInt_shouldNotFailToBuild() { + @ParameterizedTest + @MethodSource("parameters") + public void bigDecimalInWithInt_shouldNotFailToBuild(RUN_TYPE runType) { String str = "package org.drools.modelcompiler.bigdecimals\n" + "import " + BDFact.class.getCanonicalName() + ";\n" + @@ -825,7 +861,7 @@ public void bigDecimalInWithInt_shouldNotFailToBuild() { " then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); BDFact bdFact = new BDFact(); bdFact.setValue1(new BigDecimal("100")); @@ -835,8 +871,9 @@ public void bigDecimalInWithInt_shouldNotFailToBuild() { assertThat(ksession.fireAllRules()).isEqualTo(1); } - @Test - public void bigDecimalInWithBD_shouldNotFailToBuild() { + @ParameterizedTest + @MethodSource("parameters") + public void bigDecimalInWithBD_shouldNotFailToBuild(RUN_TYPE runType) { String str = "package org.drools.modelcompiler.bigdecimals\n" + "import " + BDFact.class.getCanonicalName() + ";\n" + @@ -846,7 +883,7 @@ public void bigDecimalInWithBD_shouldNotFailToBuild() { " then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); BDFact bdFact = new BDFact(); bdFact.setValue1(new BigDecimal("100")); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/bigintegertest/BigIntegerTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/bigintegertest/BigIntegerTest.java index abaf1ea4ab4..d1703048680 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/bigintegertest/BigIntegerTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/bigintegertest/BigIntegerTest.java @@ -21,17 +21,14 @@ import java.math.BigInteger; import org.drools.model.codegen.execmodel.BaseModelTest; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class BigIntegerTest extends BaseModelTest { - public BigIntegerTest(RUN_TYPE testRunType) { - super(testRunType); - } - public static class BiHolder { private BigInteger bi1; @@ -64,8 +61,9 @@ public void setBi2(BigInteger bi2) { } } - @Test - public void testBigIntegerLiteralLhsNegative() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigIntegerLiteralLhsNegative(RUN_TYPE runType) { // DROOLS-6596 String str = "package org.drools.modelcompiler.bigintegerss\n" + @@ -75,7 +73,7 @@ public void testBigIntegerLiteralLhsNegative() { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); BiHolder holder = new BiHolder(); holder.setBi1(new BigInteger("10")); @@ -85,8 +83,9 @@ public void testBigIntegerLiteralLhsNegative() { assertThat(fired).isEqualTo(1); } - @Test - public void testBigIntegerLiteralRhsNegative() { + @ParameterizedTest + @MethodSource("parameters") + public void testBigIntegerLiteralRhsNegative(RUN_TYPE runType) { // DROOLS-6596 String str = "package org.drools.modelcompiler.bigdecimals\n" + @@ -97,7 +96,7 @@ public void testBigIntegerLiteralRhsNegative() { " $holder.bi1 = -10I;\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); BiHolder holder = new BiHolder(); ksession.insert(holder); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/constraints/ConstraintEvaluationExceptionTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/constraints/ConstraintEvaluationExceptionTest.java index 896985761cd..07699c328ab 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/constraints/ConstraintEvaluationExceptionTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/constraints/ConstraintEvaluationExceptionTest.java @@ -27,7 +27,8 @@ import org.drools.model.functions.PredicateInformation; import org.drools.modelcompiler.constraints.ConstraintEvaluationException; import org.drools.mvel.MVELConstraint; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.io.Resource; import java.util.Collections; @@ -40,58 +41,58 @@ public class ConstraintEvaluationExceptionTest extends BaseModelTest { private MVELConstraint mvelConstraint; // non-exec-model - public ConstraintEvaluationExceptionTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Test - public void testMultipleRules() { - initConstraintTestField("age > 20", "R1", "sample.drl"); - addRuleToConstraintTestField("R2", "sample.drl"); - addRuleToConstraintTestField("R3", "sample.drl"); + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleRules(RUN_TYPE runType) { + initConstraintTestField(runType, "age > 20", "R1", "sample.drl"); + addRuleToConstraintTestField(runType, "R2", "sample.drl"); + addRuleToConstraintTestField(runType, "R3", "sample.drl"); - assertMessage("Error evaluating constraint 'age > 20' in [Rule \"R1\", \"R2\", \"R3\" in sample.drl]"); + assertMessage(runType, "Error evaluating constraint 'age > 20' in [Rule \"R1\", \"R2\", \"R3\" in sample.drl]"); } - @Test - public void testMultipleRuleFiles() { - initConstraintTestField("age > 20", "R1", "sample1.drl"); - addRuleToConstraintTestField("R2", "sample1.drl"); - addRuleToConstraintTestField("R3", "sample2.drl"); + @ParameterizedTest + @MethodSource("parameters") + public void testMultipleRuleFiles(RUN_TYPE runType) { + initConstraintTestField(runType, "age > 20", "R1", "sample1.drl"); + addRuleToConstraintTestField(runType, "R2", "sample1.drl"); + addRuleToConstraintTestField(runType, "R3", "sample2.drl"); - assertMessage("Error evaluating constraint 'age > 20' in [Rule \"R1\", \"R2\" in sample1.drl] [Rule \"R3\" in sample2.drl]"); + assertMessage(runType, "Error evaluating constraint 'age > 20' in [Rule \"R1\", \"R2\" in sample1.drl] [Rule \"R3\" in sample2.drl]"); } - @Test - public void testNull() { - initConstraintTestField("age > 20", null, "sample1.drl"); - addRuleToConstraintTestField("R2", null); - addRuleToConstraintTestField(null, null); + @ParameterizedTest + @MethodSource("parameters") + public void testNull(RUN_TYPE runType) { + initConstraintTestField(runType, "age > 20", null, "sample1.drl"); + addRuleToConstraintTestField(runType, "R2", null); + addRuleToConstraintTestField(runType, null, null); // Irregular case. Not much useful info but doesn't throw NPE - assertMessage("Error evaluating constraint 'age > 20' in [Rule \"\", \"R2\" in ] [Rule \"\" in sample1.drl]"); + assertMessage(runType, "Error evaluating constraint 'age > 20' in [Rule \"\", \"R2\" in ] [Rule \"\" in sample1.drl]"); } - @Test - public void testExceedMaxRuleDefs() { - initConstraintTestField("age > 20", "R1", "sample1.drl"); - addRuleToConstraintTestField("R2", "sample1.drl"); - addRuleToConstraintTestField("R3", "sample1.drl"); - addRuleToConstraintTestField("R4", "sample1.drl"); - addRuleToConstraintTestField("R5", "sample1.drl"); - addRuleToConstraintTestField("R6", "sample1.drl"); - addRuleToConstraintTestField("R7", "sample2.drl"); - addRuleToConstraintTestField("R8", "sample2.drl"); - addRuleToConstraintTestField("R9", "sample2.drl"); - addRuleToConstraintTestField("R10", "sample3.drl"); - addRuleToConstraintTestField("R11", "sample3.drl"); - - assertMessage("Error evaluating constraint 'age > 20' in [Rule \"R1\", \"R2\", \"R3\", \"R4\", \"R5\", \"R6\" in sample1.drl] [Rule \"R7\", \"R8\", \"R9\" in sample2.drl] [Rule \"R10\" in sample3.drl]" + + @ParameterizedTest + @MethodSource("parameters") + public void testExceedMaxRuleDefs(RUN_TYPE runType) { + initConstraintTestField(runType, "age > 20", "R1", "sample1.drl"); + addRuleToConstraintTestField(runType, "R2", "sample1.drl"); + addRuleToConstraintTestField(runType, "R3", "sample1.drl"); + addRuleToConstraintTestField(runType, "R4", "sample1.drl"); + addRuleToConstraintTestField(runType, "R5", "sample1.drl"); + addRuleToConstraintTestField(runType, "R6", "sample1.drl"); + addRuleToConstraintTestField(runType, "R7", "sample2.drl"); + addRuleToConstraintTestField(runType, "R8", "sample2.drl"); + addRuleToConstraintTestField(runType, "R9", "sample2.drl"); + addRuleToConstraintTestField(runType, "R10", "sample3.drl"); + addRuleToConstraintTestField(runType, "R11", "sample3.drl"); + + assertMessage(runType, "Error evaluating constraint 'age > 20' in [Rule \"R1\", \"R2\", \"R3\", \"R4\", \"R5\", \"R6\" in sample1.drl] [Rule \"R7\", \"R8\", \"R9\" in sample2.drl] [Rule \"R10\" in sample3.drl]" + " and in more rules"); } - private void initConstraintTestField(String constraint, String ruleName, String ruleFileName) { - if (testRunType.isExecutableModel()) { + private void initConstraintTestField(RUN_TYPE runType, String constraint, String ruleName, String ruleFileName) { + if (runType.isExecutableModel()) { predicateInformation = new PredicateInformation(constraint, ruleName, ruleFileName); } else { mvelConstraint = new MVELConstraint("com.example", constraint, null, null, null, null, null); @@ -108,8 +109,8 @@ private void initConstraintTestField(String constraint, String ruleName, String } } - private void addRuleToConstraintTestField(String ruleName, String ruleFileName) { - if (testRunType.isExecutableModel()) { + private void addRuleToConstraintTestField(RUN_TYPE runType, String ruleName, String ruleFileName) { + if (runType.isExecutableModel()) { predicateInformation.addRuleNames(ruleName, ruleFileName); } else { // in non-exec-model, node sharing triggers merging @@ -128,9 +129,9 @@ private void addRuleToConstraintTestField(String ruleName, String ruleFileName) } } - private void assertMessage(String expected) { + private void assertMessage(RUN_TYPE runType, String expected) { Exception ex; - if (testRunType.isExecutableModel()) { + if (runType.isExecutableModel()) { ex = new ConstraintEvaluationException(predicateInformation, new RuntimeException("OriginalException")); } else { ex = new org.drools.mvel.ConstraintEvaluationException(mvelConstraint.getExpression(), mvelConstraint.getEvaluationContext(), new RuntimeException("OriginalException")); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/drlx/DrlxCompilerTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/drlx/DrlxCompilerTest.java index 83687215e6d..12d250a8dd9 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/drlx/DrlxCompilerTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/drlx/DrlxCompilerTest.java @@ -39,9 +39,9 @@ import org.drools.mvel.DrlDumper; import org.drools.mvel.parser.MvelParser; import org.drools.mvel.parser.ParseStart; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.drools.io.InputStreamResource; -import org.junit.Ignore; -import org.junit.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.KieFileSystem; @@ -81,7 +81,7 @@ public void testSingleFileUnit() throws Exception { } @Test - @Ignore("Rule Unit compiler is not available in Drools 8 yet") + @Disabled("Rule Unit compiler is not available in Drools 8 yet") public void testCompileUnit() throws IOException { InputStream p = getClass().getClassLoader().getResourceAsStream("drlx1/Example.drlx"); InputStreamResource r = new InputStreamResource(p); @@ -114,7 +114,7 @@ public void testCompileUnit() throws IOException { } @Test - @Ignore("Rule Unit Executor is not available in Drools 8 yet") + @Disabled("Rule Unit Executor is not available in Drools 8 yet") public void testCompileUnitFull() throws IOException { String path = "drlx1/Example.drlx"; InputStream p = getClass().getClassLoader().getResourceAsStream(path); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/exchange/SendReceiveTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/exchange/SendReceiveTest.java index 93a63835411..a278ff378d1 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/exchange/SendReceiveTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/exchange/SendReceiveTest.java @@ -29,7 +29,7 @@ import org.drools.model.impl.Exchange; import org.drools.model.impl.ModelImpl; import org.drools.modelcompiler.KieBaseBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieBase; import org.kie.api.runtime.KieSession; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/fireandalarm/CompilerTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/fireandalarm/CompilerTest.java index 977d7ef186a..71a699e8268 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/fireandalarm/CompilerTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/fireandalarm/CompilerTest.java @@ -22,21 +22,19 @@ import org.drools.model.codegen.execmodel.fireandalarm.model.Alarm; import org.drools.model.codegen.execmodel.fireandalarm.model.Fire; import org.drools.model.codegen.execmodel.fireandalarm.model.Room; -import org.drools.model.codegen.execmodel.fireandalarm.model.Sprinkler; -import org.junit.Test; +import org.drools.model.codegen.execmodel.fireandalarm.model.Sprinkler; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; -import org.kie.api.runtime.rule.FactHandle; +import org.kie.api.runtime.rule.FactHandle; import static org.assertj.core.api.Assertions.assertThat; public class CompilerTest extends BaseModelTest { - public CompilerTest( RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testFireAndAlarm() { + @ParameterizedTest + @MethodSource("parameters") + public void testFireAndAlarm(RUN_TYPE runType) { String str = "import " + StringBuilder.class.getCanonicalName() + ";\n" + "import " + Alarm.class.getCanonicalName() + ";\n" + @@ -87,7 +85,7 @@ public void testFireAndAlarm() { " sb.append( \"Everything is ok\\n\" );\n" + "end\n"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); StringBuilder sb = new StringBuilder(); ksession.setGlobal( "sb", sb ); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/fireandalarm/FireAndAlarmTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/fireandalarm/FireAndAlarmTest.java index 1c07380ae2d..7161da15f7e 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/fireandalarm/FireAndAlarmTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/fireandalarm/FireAndAlarmTest.java @@ -27,7 +27,7 @@ import org.drools.model.codegen.execmodel.fireandalarm.model.Sprinkler; import org.drools.model.impl.ModelImpl; import org.drools.modelcompiler.KieBaseBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieBase; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/fireandalarm/FireAndAlarmUsingDroolsTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/fireandalarm/FireAndAlarmUsingDroolsTest.java index 24de303265d..04cbc8cfaca 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/fireandalarm/FireAndAlarmUsingDroolsTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/fireandalarm/FireAndAlarmUsingDroolsTest.java @@ -27,7 +27,7 @@ import org.drools.model.codegen.execmodel.fireandalarm.model.Sprinkler; import org.drools.model.impl.ModelImpl; import org.drools.modelcompiler.KieBaseBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieBase; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/ConsequenceTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/ConsequenceTest.java index e2c7c131dfc..56d31bd34a2 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/ConsequenceTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/ConsequenceTest.java @@ -18,7 +18,7 @@ */ package org.drools.model.codegen.execmodel.generator; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.drools.model.codegen.execmodel.generator.Consequence.containsWord; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/ConstraintTestUtil.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/ConstraintTestUtil.java index 15819559b52..d09a5308380 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/ConstraintTestUtil.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/ConstraintTestUtil.java @@ -1,5 +1,5 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one +e * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/DrlxParseUtilTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/DrlxParseUtilTest.java index d6c52b92838..0f2e568b92a 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/DrlxParseUtilTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/DrlxParseUtilTest.java @@ -40,7 +40,7 @@ import org.drools.util.ClassTypeResolver; import org.drools.util.MethodUtils; import org.drools.util.TypeResolver; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static java.util.Optional.of; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/ExpressionTyperTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/ExpressionTyperTest.java index 619214eeec6..40c3e3885f8 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/ExpressionTyperTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/ExpressionTyperTest.java @@ -50,10 +50,11 @@ import org.drools.mvel.parser.printer.PrintUtil; import org.drools.util.ClassTypeResolver; import org.drools.util.TypeResolver; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.drools.model.codegen.execmodel.generator.DrlxParseUtil.THIS_PLACEHOLDER; public class ExpressionTyperTest { @@ -65,7 +66,7 @@ public class ExpressionTyperTest { private KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl(); private RuleDescr ruleDescr = new RuleDescr("testRule"); - @Before + @BeforeEach public void setUp() throws Exception { imports = new HashSet<>(); packageModel = new PackageModel("", "", null, null, new DRLIdGenerator()); @@ -242,9 +243,9 @@ public void halfBinaryOrAndAmpersand() { assertThat(toTypedExpression("age < 15 || > 20 && < 30", Person.class).getExpression().toString()).isEqualTo(expected); } - @Test(expected = CannotTypeExpressionException.class) + @Test public void invalidHalfBinary() { - toTypedExpression("> 20 && < 30", Person.class).getExpression(); + assertThatExceptionOfType(CannotTypeExpressionException.class).isThrownBy(() ->toTypedExpression("> 20 && < 30", Person.class).getExpression()); } @Test @@ -253,9 +254,9 @@ public void halfPointFreeOrAndAmpersand() { assertThat(toTypedExpression("name str[startsWith] \"M\" || str[endsWith] \"a\" && str[length] 4", Person.class).getExpression().toString()).isEqualTo(expected); } - @Test(expected = CannotTypeExpressionException.class) + @Test public void invalidHalfPointFree() { - toTypedExpression("str[endsWith] \"a\" && str[length] 4", Person.class).getExpression(); + assertThatExceptionOfType(CannotTypeExpressionException.class).isThrownBy(() -> toTypedExpression("str[endsWith] \"a\" && str[length] 4", Person.class).getExpression()); } @Test diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/FlattenScopeTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/FlattenScopeTest.java index e34e2ecd4db..3dcdd3b77c0 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/FlattenScopeTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/FlattenScopeTest.java @@ -33,7 +33,7 @@ import com.github.javaparser.ast.expr.SimpleName; import com.github.javaparser.ast.expr.StringLiteralExpr; import org.drools.util.TypeResolver; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.github.javaparser.ast.NodeList.nodeList; import static java.util.Arrays.asList; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/GeneratedClassDeclarationTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/GeneratedClassDeclarationTest.java index 84a50b8d325..1b8a3537c1c 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/GeneratedClassDeclarationTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/GeneratedClassDeclarationTest.java @@ -26,7 +26,7 @@ import org.drools.model.codegen.execmodel.generator.declaredtype.api.MethodDefinition; import org.drools.model.codegen.execmodel.generator.declaredtype.api.TypeDefinition; import org.drools.model.codegen.execmodel.generator.declaredtype.generator.GeneratedClassDeclaration; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/StringUtilTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/StringUtilTest.java index 3d136d6baa1..8566f953ed2 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/StringUtilTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/StringUtilTest.java @@ -18,7 +18,7 @@ */ package org.drools.model.codegen.execmodel.generator; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.drools.modelcompiler.util.StringUtil.toId; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/drlxparse/CoercedExpressionTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/drlxparse/CoercedExpressionTest.java index 83e1a2c3a6d..0f2232b39e6 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/drlxparse/CoercedExpressionTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/drlxparse/CoercedExpressionTest.java @@ -18,14 +18,12 @@ */ package org.drools.model.codegen.execmodel.generator.drlxparse; -import java.util.Map; - import com.github.javaparser.ast.expr.StringLiteralExpr; import org.drools.util.MethodUtils; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.drools.model.codegen.execmodel.generator.DrlxParseUtil; import org.drools.model.codegen.execmodel.generator.TypedExpression; -import org.junit.Ignore; -import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -193,7 +191,7 @@ private TypedExpression expr(String exprString, Class exprClass) { } @Test - @Ignore("should support bigDecimal coercion also?") + @Disabled("should support bigDecimal coercion also?") public void coerceBigDecimal() { final TypedExpression left = expr(THIS_PLACEHOLDER + ".getRate()", java.math.BigDecimal.class); final TypedExpression right = expr("0.0d", Double.class); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/drlxparse/ConstraintParserTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/drlxparse/ConstraintParserTest.java index cc62dedfdc3..6dd9391edae 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/drlxparse/ConstraintParserTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/generator/drlxparse/ConstraintParserTest.java @@ -31,8 +31,8 @@ import org.drools.modelcompiler.util.EvaluationUtil; import org.drools.util.ClassTypeResolver; import org.drools.util.TypeResolver; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -40,7 +40,7 @@ public class ConstraintParserTest { private ConstraintParser parser; - @Before + @BeforeEach public void setup() { PackageModel packageModel = new PackageModel("org.kie.test:constraint-parser-test:1.0.0", "org.kie.test", null, null, new DRLIdGenerator()); Set imports = new HashSet<>(); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/inlinecast/InlineCastTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/inlinecast/InlineCastTest.java index 1d7eb90b6c8..3c60fc5f311 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/inlinecast/InlineCastTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/inlinecast/InlineCastTest.java @@ -25,20 +25,18 @@ import org.drools.model.codegen.execmodel.domain.InternationalAddress; import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.Result; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class InlineCastTest extends BaseModelTest { - public InlineCastTest(RUN_TYPE testRunType ) { - super( testRunType ); - } - - @Test - public void testInlineCastThis() { + @ParameterizedTest + @MethodSource("parameters") + public void testInlineCastThis(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -49,7 +47,7 @@ public void testInlineCastThis() { " $r.setValue(\"Found: \" + $o);\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -62,8 +60,9 @@ public void testInlineCastThis() { assertThat(result.getValue()).isEqualTo("Found: Mark"); } - @Test - public void testInlineCastProjectionThis() { + @ParameterizedTest + @MethodSource("parameters") + public void testInlineCastProjectionThis(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -74,7 +73,7 @@ public void testInlineCastProjectionThis() { " $r.setValue(\"Found: \" + $name + \" $p class: \" + $p.getClass().getCanonicalName());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -86,8 +85,9 @@ public void testInlineCastProjectionThis() { assertThat(result.getValue()).isEqualTo("Found: Mark $p class: " + Person.class.getCanonicalName()); } - @Test - public void testInlineCastProjectionThisExplicit() { + @ParameterizedTest + @MethodSource("parameters") + public void testInlineCastProjectionThisExplicit(RUN_TYPE runType) { String str = "import " + Result.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + @@ -98,7 +98,7 @@ public void testInlineCastProjectionThisExplicit() { " $r.setValue(\"Found: \" + $name + \" $p class: \" + $p.getClass().getCanonicalName());\n" + "end"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); Result result = new Result(); ksession.insert( result ); @@ -131,9 +131,10 @@ public interface DMNModelInstrumentedBase { DMNModelInstrumentedBase getParent(); } - @Ignore("This test is not testing anything") - @Test - public void testExplicitCast() { + @Disabled("This test is not testing anything") + @ParameterizedTest + @MethodSource("parameters") + public void testExplicitCast(RUN_TYPE runType) { String str = "import " + OutputClause.class.getCanonicalName() + "\n;" + "import " + DecisionTable.class.getCanonicalName() + "\n;" + @@ -143,13 +144,14 @@ public void testExplicitCast() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.fireAllRules(); } - @Ignore("This test is not testing anything") - @Test - public void testInlineCastParent() { + @Disabled("This test is not testing anything") + @ParameterizedTest + @MethodSource("parameters") + public void testInlineCastParent(RUN_TYPE runType) { String str = "import " + OutputClause.class.getCanonicalName() + "\n;" + "import " + DecisionTable.class.getCanonicalName() + "\n;" + @@ -159,12 +161,13 @@ public void testInlineCastParent() { "then\n" + "end\n"; - KieSession ksession = getKieSession( str ); + KieSession ksession = getKieSession(runType, str); ksession.fireAllRules(); } - @Test - public void testInlineCastProjection() { + @ParameterizedTest + @MethodSource("parameters") + public void testInlineCastProjection(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + InternationalAddress.class.getCanonicalName() + ";" + "rule R when\n" + @@ -173,7 +176,7 @@ public void testInlineCastProjection() { " insert($a);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person john = new Person("John", 47); InternationalAddress a = new InternationalAddress("address", "Italy"); @@ -186,8 +189,9 @@ public void testInlineCastProjection() { assertThat(results.iterator().next()).isEqualTo("Italy"); } - @Test - public void testInlineCastProjectionOnMethod() { + @ParameterizedTest + @MethodSource("parameters") + public void testInlineCastProjectionOnMethod(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + InternationalAddress.class.getCanonicalName() + ";" + "rule R when\n" + @@ -196,7 +200,7 @@ public void testInlineCastProjectionOnMethod() { " insert($a);\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person john = new Person("John", 47); InternationalAddress a = new InternationalAddress("address", "Italy"); @@ -210,8 +214,9 @@ public void testInlineCastProjectionOnMethod() { } - @Test - public void testInlineCastForAField() { + @ParameterizedTest + @MethodSource("parameters") + public void testInlineCastForAField(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + InternationalAddress.class.getCanonicalName() + ";" + "rule R when\n" + @@ -220,7 +225,7 @@ public void testInlineCastForAField() { " insert(\"matched\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person john = new Person("John", 47); InternationalAddress a = new InternationalAddress("address", "Italy"); @@ -233,8 +238,9 @@ public void testInlineCastForAField() { assertThat(results.size()).isEqualTo(1); } - @Test - public void testInlineCastForAFieldWithFQN() { + @ParameterizedTest + @MethodSource("parameters") + public void testInlineCastForAFieldWithFQN(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + " $p : Person( address#" + InternationalAddress.class.getCanonicalName() + ".state.length == 5 )\n" + @@ -242,7 +248,7 @@ public void testInlineCastForAFieldWithFQN() { " insert(\"matched\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person john = new Person("John", 47); InternationalAddress a = new InternationalAddress("address", "Italy"); @@ -255,8 +261,9 @@ public void testInlineCastForAFieldWithFQN() { assertThat(results.size()).isEqualTo(1); } - @Test - public void testInlineCastForAFieldAndMixMethodCall() { + @ParameterizedTest + @MethodSource("parameters") + public void testInlineCastForAFieldAndMixMethodCall(RUN_TYPE runType) { String str = "import " + Person.class.getCanonicalName() + ";" + "import " + InternationalAddress.class.getCanonicalName() + ";" + "rule R when\n" + @@ -265,7 +272,7 @@ public void testInlineCastForAFieldAndMixMethodCall() { " insert(\"matched\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); Person john = new Person("John", 47); InternationalAddress a = new InternationalAddress("address", "Italy"); @@ -278,8 +285,9 @@ public void testInlineCastForAFieldAndMixMethodCall() { assertThat(results.size()).isEqualTo(1); } - @Test - public void testInlineCastSingle() { + @ParameterizedTest + @MethodSource("parameters") + public void testInlineCastSingle(RUN_TYPE runType) { String str = "import " + ICAbstractA.class.getCanonicalName() + ";" + "import " + ICAbstractB.class.getCanonicalName() + ";" + "import " + ICAbstractC.class.getCanonicalName() + ";" + @@ -292,7 +300,7 @@ public void testInlineCastSingle() { " insert(\"matched\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ICA a = new ICA(); ICB b = new ICB(); @@ -307,8 +315,9 @@ public void testInlineCastSingle() { assertThat(results.size()).isEqualTo(1); } - @Test - public void testInlineCastMultiple() { + @ParameterizedTest + @MethodSource("parameters") + public void testInlineCastMultiple(RUN_TYPE runType) { String str = "import " + ICAbstractA.class.getCanonicalName() + ";" + "import " + ICAbstractB.class.getCanonicalName() + ";" + "import " + ICAbstractC.class.getCanonicalName() + ";" + @@ -321,7 +330,7 @@ public void testInlineCastMultiple() { " insert(\"matched\");\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); ICA a = new ICA(); ICB b = new ICB(); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/BaseOperatorsTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/BaseOperatorsTest.java index e378e6f0a55..98e0fb4f970 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/BaseOperatorsTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/BaseOperatorsTest.java @@ -26,7 +26,6 @@ import org.drools.compiler.kie.builder.impl.DrlProject; import org.drools.model.codegen.ExecutableModelProject; -import org.drools.model.codegen.execmodel.BaseModelTest; import org.drools.model.codegen.execmodel.BaseModelTest.RUN_TYPE; import org.drools.model.codegen.execmodel.KJARUtils; import org.kie.api.KieServices; @@ -38,16 +37,16 @@ import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.fail; public abstract class BaseOperatorsTest { - protected static final RUN_TYPE[] RUN_TYPES = new BaseModelTest.RUN_TYPE[]{RUN_TYPE.STANDARD_FROM_DRL, RUN_TYPE.PATTERN_DSL}; - protected static final Class[] TYPES = new Class[]{Integer.class, Long.class, Byte.class, Character.class, Short.class, Float.class, Double.class, BigInteger.class, BigDecimal.class}; - protected static final String[] EQUALITY_COMPARISON_OPERATORS = new String[]{"==", "!="}; - protected static final boolean[] NULL_PROPERTY_ON_LEFT = new boolean[]{true, false}; + protected static final RUN_TYPE[] RUN_TYPES = {RUN_TYPE.STANDARD_FROM_DRL, RUN_TYPE.PATTERN_DSL}; + protected static final Class[] TYPES = {Integer.class, Long.class, Byte.class, Character.class, Short.class, Float.class, Double.class, BigInteger.class, BigDecimal.class}; + protected static final String[] EQUALITY_COMPARISON_OPERATORS = {"==", "!="}; + protected static final boolean[] NULL_PROPERTY_ON_LEFT = {true, false}; - protected KieSession getKieSession(String drl, RUN_TYPE testRunType) { + protected KieSession getKieSession(String drl, RUN_TYPE runType) { KieServices ks = KieServices.get(); ReleaseId releaseId = ks.newReleaseId("org.kie", "kjar-test-" + UUID.randomUUID(), "1.0"); @@ -60,12 +59,12 @@ protected KieSession getKieSession(String drl, RUN_TYPE testRunType) { kfs.write("src/main/resources/com/sample/Sample1.drl", drl); KieBuilder kieBuilder; - if (testRunType.equals(RUN_TYPE.STANDARD_FROM_DRL)) { + if (runType.equals(RUN_TYPE.STANDARD_FROM_DRL)) { kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class); - } else if (testRunType.equals(RUN_TYPE.PATTERN_DSL)) { + } else if (runType.equals(RUN_TYPE.PATTERN_DSL)) { kieBuilder = ks.newKieBuilder(kfs).buildAll(ExecutableModelProject.class); } else { - throw new UnsupportedOperationException(testRunType + " is not supported"); + throw new UnsupportedOperationException(runType + " is not supported"); } List messages = kieBuilder.getResults().getMessages(); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/DateOperatorTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/DateOperatorTest.java index 482bf005670..588bbcef0ed 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/DateOperatorTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/DateOperatorTest.java @@ -22,22 +22,18 @@ import java.text.SimpleDateFormat; import org.drools.model.codegen.execmodel.BaseModelTest; -import org.drools.model.codegen.execmodel.domain.Person; import org.drools.model.codegen.execmodel.domain.SimpleDateHolder; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; public class DateOperatorTest extends BaseModelTest { - public DateOperatorTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Test - public void dateBetweenGlobals() throws ParseException { + @ParameterizedTest + @MethodSource("parameters") + public void dateBetweenGlobals(RUN_TYPE runType) throws ParseException { String str = "import " + SimpleDateHolder.class.getCanonicalName() + ";" + "global java.util.Date $startDate;\n" + @@ -47,7 +43,7 @@ public void dateBetweenGlobals() throws ParseException { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); ksession.setGlobal("$startDate", sdf.parse("04/01/2019")); ksession.setGlobal("$endDate", sdf.parse("05/01/2019")); @@ -59,8 +55,9 @@ public void dateBetweenGlobals() throws ParseException { assertThat(fired).isEqualTo(1); } - @Test - public void dateBetweenVariables() throws ParseException { + @ParameterizedTest + @MethodSource("parameters") + public void dateBetweenVariables(RUN_TYPE runType) throws ParseException { String str = "import " + SimpleDateHolder.class.getCanonicalName() + ";" + "rule R when\n" + @@ -70,7 +67,7 @@ public void dateBetweenVariables() throws ParseException { "then\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(runType, str); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateHolder holderA = new SimpleDateHolder("A", sdf.parse("04/01/2019")); diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/EqualityComparisonTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/EqualityComparisonTest.java index 60c5b548361..824bce2c014 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/EqualityComparisonTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/EqualityComparisonTest.java @@ -19,64 +19,52 @@ package org.drools.model.codegen.execmodel.operators; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.model.codegen.execmodel.BaseModelTest.RUN_TYPE; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.params.provider.Arguments.arguments; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; -@RunWith(Parameterized.class) public class EqualityComparisonTest extends BaseOperatorsTest { - @Parameters(name = "{0} {1} {2} {3}") - public static Collection ruleParams() { - List parameterData = new ArrayList(); + public static Stream ruleParams() { + List parameterData = new ArrayList(); for (RUN_TYPE runType : RUN_TYPES) { for (Class type : TYPES) { for (String operator : EQUALITY_COMPARISON_OPERATORS) { for (boolean nullPropertyOnLeft : NULL_PROPERTY_ON_LEFT) - parameterData.add(new Object[]{runType, type, operator, nullPropertyOnLeft}); + parameterData.add(arguments(runType, type, operator, nullPropertyOnLeft)); } } } - return parameterData; + + return Stream.of(parameterData.toArray(new Arguments[0])); } - @Parameterized.Parameter(0) - public RUN_TYPE testRunType; - - @Parameterized.Parameter(1) - public Class type; - - @Parameterized.Parameter(2) - public String operator; - - @Parameterized.Parameter(3) - public boolean nullPropertyOnLeft; - - @Before + @BeforeEach public void setUp() { org.drools.compiler.rule.builder.util.ConstraintTestUtil.disableNormalizeConstraint(); org.drools.model.codegen.execmodel.generator.ConstraintTestUtil.disableNormalizeConstraint(); } - @After + @AfterEach public void tearDown() { org.drools.compiler.rule.builder.util.ConstraintTestUtil.enableNormalizeConstraint(); org.drools.model.codegen.execmodel.generator.ConstraintTestUtil.enableNormalizeConstraint(); } - @Test - public void compareWithNullProperty() throws Exception { + @ParameterizedTest(name = "{0} {1} {2} {3}") + @MethodSource("ruleParams") + public void compareWithNullProperty(RUN_TYPE testRunType, Class type, String operator, boolean nullPropertyOnLeft) throws Exception { String propertyName = BaseOperatorsTest.getPropertyName(type); String instanceValueString = BaseOperatorsTest.getInstanceValueString(type); String drl = "import " + type.getCanonicalName() + ";\n" + @@ -95,11 +83,7 @@ public void compareWithNullProperty() throws Exception { ksession.insert(new ValueHolder()); try { int fired = ksession.fireAllRules(); - if (operator.equals("==") && fired == 0 || operator.equals("!=") && fired == 1) { - assertTrue(true); - } else { - fail("Wrong result"); - } + assertThat(operator.equals("==") && fired == 0 || operator.equals("!=") && fired == 1).withFailMessage("Wrong result").isTrue(); } catch (org.drools.mvel.ConstraintEvaluationException | org.drools.modelcompiler.constraints.ConstraintEvaluationException e) { throw new RuntimeException("Unexpected Exception", e); } diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/EqualityComparisonWith2PropertiesTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/EqualityComparisonWith2PropertiesTest.java index 67439d0513f..93c5dc7e34f 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/EqualityComparisonWith2PropertiesTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/operators/EqualityComparisonWith2PropertiesTest.java @@ -19,64 +19,54 @@ package org.drools.model.codegen.execmodel.operators; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.model.codegen.execmodel.BaseModelTest.RUN_TYPE; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.runtime.KieSession; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; -@RunWith(Parameterized.class) public class EqualityComparisonWith2PropertiesTest extends BaseOperatorsTest { - @Parameters(name = "{0} {1} {2} {3}") - public static Collection ruleParams() { - List parameterData = new ArrayList(); + + + public static Stream ruleParams() { + List parameterData = new ArrayList(); for (RUN_TYPE runType : RUN_TYPES) { for (Class type : TYPES) { for (String operator : EQUALITY_COMPARISON_OPERATORS) { for (boolean nullPropertyOnLeft : NULL_PROPERTY_ON_LEFT) - parameterData.add(new Object[]{runType, type, operator, nullPropertyOnLeft}); + parameterData.add(arguments(runType, type, operator, nullPropertyOnLeft)); } } } - return parameterData; + + return Stream.of(parameterData.toArray(new Arguments[0])); } + - @Parameterized.Parameter(0) - public RUN_TYPE testRunType; - - @Parameterized.Parameter(1) - public Class type; - - @Parameterized.Parameter(2) - public String operator; - - @Parameterized.Parameter(3) - public boolean nullPropertyOnLeft; - - @Before + @BeforeEach public void setUp() { org.drools.compiler.rule.builder.util.ConstraintTestUtil.disableNormalizeConstraint(); org.drools.model.codegen.execmodel.generator.ConstraintTestUtil.disableNormalizeConstraint(); } - @After + @AfterEach public void tearDown() { org.drools.compiler.rule.builder.util.ConstraintTestUtil.enableNormalizeConstraint(); org.drools.model.codegen.execmodel.generator.ConstraintTestUtil.enableNormalizeConstraint(); } - @Test - public void compareWithNullProperty() throws Exception { + @ParameterizedTest(name = "{0} {1} {2} {3}") + @MethodSource("ruleParams") + public void compareWithNullProperty(RUN_TYPE testRunType, Class type, String operator, boolean nullPropertyOnLeft) throws Exception { String firstPropertyName = BaseOperatorsTest.getPropertyNameWithPrefix(type, "first"); String secondPropertyName = BaseOperatorsTest.getPropertyNameWithPrefix(type, "second"); String drl = "import " + type.getCanonicalName() + ";\n" + @@ -95,11 +85,7 @@ public void compareWithNullProperty() throws Exception { ksession.insert(new ValueHolderWith2Properties()); try { int fired = ksession.fireAllRules(); - if (operator.equals("==") && fired == 0 || operator.equals("!=") && fired == 1) { - assertTrue(true); - } else { - fail("Wrong result"); - } + assertThat(operator.equals("==") && fired == 0 || operator.equals("!=") && fired == 1).withFailMessage("Wrong result").isTrue(); } catch (org.drools.mvel.ConstraintEvaluationException | org.drools.modelcompiler.constraints.ConstraintEvaluationException e) { throw new RuntimeException("Unexpected Exception", e); } diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/LambdaUtilTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/LambdaUtilTest.java index 115868333e5..63e3698eb08 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/LambdaUtilTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/LambdaUtilTest.java @@ -20,7 +20,8 @@ import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.LambdaExpr; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import static com.github.javaparser.StaticJavaParser.parseExpression; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/ExecModelLambdaPostProcessorTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/ExecModelLambdaPostProcessorTest.java index 877ce72394c..8551686e008 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/ExecModelLambdaPostProcessorTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/ExecModelLambdaPostProcessorTest.java @@ -22,18 +22,19 @@ import java.util.ArrayList; import java.util.HashMap; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.MethodDeclaration; -import org.junit.Before; -import org.junit.Test; import static com.github.javaparser.StaticJavaParser.parseResource; import static org.drools.model.codegen.execmodel.util.lambdareplace.MaterializedLambdaTestUtils.verifyCreatedClass; public class ExecModelLambdaPostProcessorTest { - @Before + @BeforeEach public void configJP() { StaticJavaParser.getConfiguration().setCharacterEncoding(Charset.defaultCharset()); } diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/MaterializedLambdaConsequenceTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/MaterializedLambdaConsequenceTest.java index 0505fb10a40..747aa5b188f 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/MaterializedLambdaConsequenceTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/MaterializedLambdaConsequenceTest.java @@ -23,7 +23,7 @@ import java.util.Collections; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.drools.model.codegen.execmodel.util.lambdareplace.MaterializedLambdaTestUtils.verifyCreatedClass; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/MaterializedLambdaExtractorTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/MaterializedLambdaExtractorTest.java index a238d833c71..bff83366078 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/MaterializedLambdaExtractorTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/MaterializedLambdaExtractorTest.java @@ -20,7 +20,7 @@ import java.util.ArrayList; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.drools.model.codegen.execmodel.generator.DrlxParseUtil.toClassOrInterfaceType; import static org.drools.model.codegen.execmodel.util.lambdareplace.MaterializedLambdaTestUtils.verifyCreatedClass; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/MaterializedLambdaPredicateTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/MaterializedLambdaPredicateTest.java index 643d4b976f6..678e63daa73 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/MaterializedLambdaPredicateTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/util/lambdareplace/MaterializedLambdaPredicateTest.java @@ -21,7 +21,7 @@ import java.util.ArrayList; import org.drools.model.functions.PredicateInformation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.drools.model.codegen.execmodel.util.lambdareplace.MaterializedLambdaTestUtils.verifyCreatedClass; diff --git a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/variables/VariablesTest.java b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/variables/VariablesTest.java index ea8744845ef..a9f229d0ce0 100644 --- a/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/variables/VariablesTest.java +++ b/drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/variables/VariablesTest.java @@ -21,19 +21,17 @@ import java.util.Collection; import org.drools.model.codegen.execmodel.BaseModelTest; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; import org.kie.api.runtime.KieSession; public class VariablesTest extends BaseModelTest { - - public VariablesTest(RUN_TYPE testRunType) { - super(testRunType); - } - - @Test - public void testThreeVariables() { + + @ParameterizedTest + @MethodSource("parameters") + public void testThreeVariables(BaseModelTest.RUN_TYPE testRunType) { String str = "import " + SimpleObject.class.getCanonicalName() + ";\n" + "import " + Result.class.getCanonicalName() + ";\n" + @@ -46,7 +44,7 @@ public void testThreeVariables() { "insert (new Result($id, $v1 + $v2));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); SimpleObject m1 = new SimpleObject("id", 1); SimpleObject m2 = new SimpleObject("id", 2); @@ -60,8 +58,9 @@ public void testThreeVariables() { assertThat(results.iterator().next().getValue()).isEqualTo(3); } - @Test - public void testFourVariables() { + @ParameterizedTest + @MethodSource("parameters") + public void testFourVariables(BaseModelTest.RUN_TYPE testRunType) { String str = "import " + SimpleObject.class.getCanonicalName() + ";\n" + "import " + Result.class.getCanonicalName() + ";\n" + @@ -75,7 +74,7 @@ public void testFourVariables() { "insert (new Result($id, $v1 + $v2 + $v3));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); SimpleObject m1 = new SimpleObject("id", 1); SimpleObject m2 = new SimpleObject("id", 2); @@ -91,8 +90,9 @@ public void testFourVariables() { assertThat(results.iterator().next().getValue()).isEqualTo(6); } - @Test - public void testFiveVariables() { + @ParameterizedTest + @MethodSource("parameters") + public void testFiveVariables(BaseModelTest.RUN_TYPE testRunType) { String str = "import " + SimpleObject.class.getCanonicalName() + ";\n" + "import " + Result.class.getCanonicalName() + ";\n" + @@ -107,7 +107,7 @@ public void testFiveVariables() { "insert (new Result($id, $v1 + $v2 + $v3 + $v4));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); SimpleObject m1 = new SimpleObject("id", 1); SimpleObject m2 = new SimpleObject("id", 2); @@ -125,8 +125,9 @@ public void testFiveVariables() { assertThat(results.iterator().next().getValue()).isEqualTo(10); } - @Test - public void testSixVariables() { + @ParameterizedTest + @MethodSource("parameters") + public void testSixVariables(BaseModelTest.RUN_TYPE testRunType) { String str = "import " + SimpleObject.class.getCanonicalName() + ";\n" + "import " + Result.class.getCanonicalName() + ";\n" + @@ -142,7 +143,7 @@ public void testSixVariables() { "insert (new Result($id, $v1 + $v2 + $v3 + $v4 + $v5));\n" + "end"; - KieSession ksession = getKieSession(str); + KieSession ksession = getKieSession(testRunType, str); SimpleObject m1 = new SimpleObject("id", 1); SimpleObject m2 = new SimpleObject("id", 2); diff --git a/drools-model/drools-model-compiler/pom.xml b/drools-model/drools-model-compiler/pom.xml index c7128d54f13..99d7f28ba6a 100644 --- a/drools-model/drools-model-compiler/pom.xml +++ b/drools-model/drools-model-compiler/pom.xml @@ -68,9 +68,9 @@ - junit - junit - test + org.junit.jupiter + junit-jupiter + test org.assertj diff --git a/drools-model/drools-model-compiler/src/test/java/org/drools/modelcompiler/PatternDSLTest.java b/drools-model/drools-model-compiler/src/test/java/org/drools/modelcompiler/PatternDSLTest.java index bb7f803825f..a9692d970b9 100644 --- a/drools-model/drools-model-compiler/src/test/java/org/drools/modelcompiler/PatternDSLTest.java +++ b/drools-model/drools-model-compiler/src/test/java/org/drools/modelcompiler/PatternDSLTest.java @@ -59,11 +59,10 @@ import org.drools.modelcompiler.domain.Woman; import org.drools.modelcompiler.dsl.pattern.D; import org.drools.modelcompiler.util.EvaluationUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.ClassObjectFilter; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.KieSessionConfiguration; import org.kie.api.runtime.conf.ClockTypeOption; diff --git a/drools-model/drools-model-prototype/pom.xml b/drools-model/drools-model-prototype/pom.xml index 55892638c63..7d035e24bdd 100644 --- a/drools-model/drools-model-prototype/pom.xml +++ b/drools-model/drools-model-prototype/pom.xml @@ -56,9 +56,9 @@ - junit - junit - test + org.junit.jupiter + junit-jupiter + test org.assertj diff --git a/drools-model/drools-model-prototype/src/test/java/org/drools/model/prototype/PrototypeFieldExtractorTest.java b/drools-model/drools-model-prototype/src/test/java/org/drools/model/prototype/PrototypeFieldExtractorTest.java index 0b081f3c43c..9f9e0c5c1cd 100644 --- a/drools-model/drools-model-prototype/src/test/java/org/drools/model/prototype/PrototypeFieldExtractorTest.java +++ b/drools-model/drools-model-prototype/src/test/java/org/drools/model/prototype/PrototypeFieldExtractorTest.java @@ -23,7 +23,7 @@ import org.drools.base.rule.Declaration; import org.drools.base.rule.Pattern; import org.drools.base.rule.accessor.ReadAccessor; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.prototype.PrototypeFact; import org.kie.api.prototype.PrototypeFactInstance; diff --git a/drools-model/drools-mvel-compiler/pom.xml b/drools-model/drools-mvel-compiler/pom.xml index 7bb56461fac..68e8e37d9a7 100644 --- a/drools-model/drools-mvel-compiler/pom.xml +++ b/drools-model/drools-mvel-compiler/pom.xml @@ -38,11 +38,6 @@ - - junit - junit - test - com.github.javaparser @@ -57,6 +52,11 @@ drools-core + + org.junit.jupiter + junit-jupiter + test + org.assertj assertj-core diff --git a/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvel/ArithmeticTest.java b/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvel/ArithmeticTest.java index d8b43dfb040..c4aa468b007 100644 --- a/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvel/ArithmeticTest.java +++ b/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvel/ArithmeticTest.java @@ -24,8 +24,8 @@ import java.util.LinkedHashMap; import java.util.Map; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; @@ -43,7 +43,7 @@ public class ArithmeticTest { - @Ignore("DROOLS-6572 - Generates wrong code for promotion") + @Disabled("DROOLS-6572 - Generates wrong code for promotion") @Test public void testMath() { String expression = "pi * hour"; @@ -57,7 +57,7 @@ public void testMath2() { assertThat(executeExpressionWithDefaultVariables("foo.number-1")).isEqualTo(3); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath3() { String expression = "(10 * 5) * 2 / 3"; @@ -66,7 +66,7 @@ public void testMath3() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath4() { String expression = "(100 % 3) * 2 - 1 / 1 + 8 + (5 * 2)"; @@ -75,7 +75,7 @@ public void testMath4() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath4a() { String expression = "(100 % 90) * 20 - 15 / 16 + 80 + (50 * 21)"; @@ -100,7 +100,7 @@ public void testMath5a() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath6() { String expression = "(300 * five + 1) + (100 / 2 * 2)"; @@ -109,7 +109,7 @@ public void testMath6() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath7() { String expression = "(100 % 3) * 2 - 1 / 1 + 8 + (5 * 2)"; @@ -126,13 +126,13 @@ public void testMath8() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Unable to parse **") + @Disabled("DROOLS-6572 - Unable to parse **") @Test public void testPowerOf() { assertThat(executeExpressionWithDefaultVariables("5 ** 2")).isEqualTo(25); } - @Ignore("DROOLS-6572 - Unable to parse") + @Disabled("DROOLS-6572 - Unable to parse") @Test public void testSignOperator() { String expr = "int x = 15; -x"; @@ -173,7 +173,7 @@ public void testMath17() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Unable to parse multiple assignements") + @Disabled("DROOLS-6572 - Unable to parse multiple assignements") @Test public void testMath18() { String expression = "a = 100d; b = 50d; c = 20d; d = 30d; e = 2d; (a * b) * c / d * e"; @@ -182,7 +182,7 @@ public void testMath18() { assertThat(executeExpression(expression, Collections.emptyMap())).isEqualTo(result); } - @Ignore("DROOLS-6572 - Unable to parse multiple assignments") + @Disabled("DROOLS-6572 - Unable to parse multiple assignments") @Test public void testMath19() { String expression = "a = 100; b = 500; c = 200; d = 150; e = 500; f = 800; g = 400; a-b*c*d + e*f-g"; @@ -190,7 +190,7 @@ public void testMath19() { assertThat(executeExpression(expression, Collections.emptyMap())).isEqualTo(result); } - @Ignore("DROOLS-6572 - Unable to parse") + @Disabled("DROOLS-6572 - Unable to parse") @Test public void testMath32() { String expression = "x = 20; y = 10; z = 5; x-y-z"; @@ -199,7 +199,7 @@ public void testMath32() { assertThat(executeExpression(expression, Collections.emptyMap())).isEqualTo(result); } - @Ignore("DROOLS-6572 - Unable to parse") + @Disabled("DROOLS-6572 - Unable to parse") @Test public void testMath33() { String expression = "x = 20; y = 2; z = 2; x/y/z"; @@ -224,7 +224,7 @@ public void testMath21() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(expected); } - @Ignore("DROOLS-6572 - Unable to parse **") + @Disabled("DROOLS-6572 - Unable to parse **") @Test public void testMath22() { String expression = "(100-50)*70-30*(20-9)**3"; @@ -233,7 +233,7 @@ public void testMath22() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Unable to parse **") + @Disabled("DROOLS-6572 - Unable to parse **") @Test public void testMath22b() { String expression = "a = 100; b = 50; c = 70; d = 30; e = 20; f = 9; g = 3; (a-b)*c-d*(e-f)**g"; @@ -242,7 +242,7 @@ public void testMath22b() { assertThat(executeExpression(expression, Collections.emptyMap())).isEqualTo(result); } - @Ignore("DROOLS-6572 - Unable to parse **") + @Disabled("DROOLS-6572 - Unable to parse **") @Test public void testMath23() { String expression = "10 ** (3)*10**3"; @@ -251,7 +251,7 @@ public void testMath23() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath24() { String expression = "51 * 52 * 33 / 24 / 15 + 45 * 66 * 47 * 28 + 19"; @@ -260,7 +260,7 @@ public void testMath24() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Calculation error") + @Disabled("DROOLS-6572 - Calculation error") @Test public void testMath25() { String expression = "51 * (40 - 1000 * 50) + 100 + 50 * 20 / 10 + 11 + 12 - 80"; @@ -269,7 +269,7 @@ public void testMath25() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Unable to parse **") + @Disabled("DROOLS-6572 - Unable to parse **") @Test public void testMath26() { String expression = "5 + 3 * 8 * 2 ** 2"; @@ -278,7 +278,7 @@ public void testMath26() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Unable to parse **") + @Disabled("DROOLS-6572 - Unable to parse **") @Test public void testMath27() { String expression = "50 + 30 * 80 * 20 ** 3 * 51"; @@ -287,7 +287,7 @@ public void testMath27() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo((int) result); } - @Ignore("DROOLS-6572 - Unable to parse **") + @Disabled("DROOLS-6572 - Unable to parse **") @Test public void testMath28() { String expression = "50 + 30 + 80 + 11 ** 2 ** 2 * 51"; @@ -296,7 +296,7 @@ public void testMath28() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo((int) result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath29() { String expression = "10 + 20 / 4 / 4"; @@ -305,7 +305,7 @@ public void testMath29() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath30() { String expression = "40 / 20 + 10 + 60 / 21"; @@ -314,7 +314,7 @@ public void testMath30() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Unable to parse **") + @Disabled("DROOLS-6572 - Unable to parse **") @Test public void testMath31() { String expression = "40 / 20 + 5 - 4 + 8 / 2 * 2 * 6 ** 2 + 6 - 8"; @@ -323,7 +323,7 @@ public void testMath31() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath34() { String expression = "a+b-c*d*x/y-z+10"; @@ -341,7 +341,7 @@ public void testMath34() { assertThat(executeExpression(expression, map)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath34_Interpreted() { String expression = "a+b-c*x/y-z"; @@ -358,7 +358,7 @@ public void testMath34_Interpreted() { assertThat(executeExpression(expression, map)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath35() { String expression = "b/x/b/b*y+a"; @@ -376,7 +376,7 @@ public void testMath35() { } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath35_Interpreted() { String expression = "b/x/b/b*y+a"; @@ -393,7 +393,7 @@ public void testMath35_Interpreted() { assertThat(executeExpression(expression, map)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath36() { String expression = "b/x*z/a+x-b+x-b/z+y"; @@ -410,7 +410,7 @@ public void testMath36() { assertThat(executeExpression(expression, map)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath37() { String expression = "x+a*a*c/x*b*z+x/y-b"; @@ -427,7 +427,7 @@ public void testMath37() { assertThat(executeExpression(expression, map)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath38() { String expression = "100 + 200 - 300 + 400 - 500 + 105 / 205 - 405 + 305 * 206"; @@ -436,7 +436,7 @@ public void testMath38() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath39() { String expression = "147 + 60 / 167 % 448 + 36 * 23 / 166"; @@ -445,7 +445,7 @@ public void testMath39() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testMath40() { String expression = "228 - 338 % 375 - 103 + 260 + 412 * 177 + 121"; @@ -507,21 +507,21 @@ public void testMath44b() { assertThat(executeExpression(expression, vars)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Unable to parse") + @Disabled("DROOLS-6572 - Unable to parse") @Test public void testOperatorPrecedence() { String expression = "_x_001 = 500.2; _x_002 = 200.8; _r_001 = 701; _r_001 == _x_001 + _x_002 || _x_001 == 500 + 0.1"; assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(true); } - @Ignore("DROOLS-6572 - Unable to parse") + @Disabled("DROOLS-6572 - Unable to parse") @Test public void testOperatorPrecedence2() { String expression = "_x_001 = 500.2; _x_002 = 200.8; _r_001 = 701; _r_001 == _x_001 + _x_002 && _x_001 == 500 + 0.2"; assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(true); } - @Ignore("DROOLS-6572 - Unable to parse") + @Disabled("DROOLS-6572 - Unable to parse") @Test public void testOperatorPrecedence3() { String expression = "_x_001 = 500.2; _x_002 = 200.9; _r_001 = 701; _r_001 == _x_001 + _x_002 && _x_001 == 500 + 0.2"; @@ -529,7 +529,7 @@ public void testOperatorPrecedence3() { assertThat(executeExpressionWithDefaultVariables(expression)).isEqualTo(false); } - @Ignore("DROOLS-6572 - Unable to parse") + @Disabled("DROOLS-6572 - Unable to parse") @Test public void testOperatorPrecedence4() { String expression = "_x_001 = 500.2; _x_002 = 200.9; _r_001 = 701; _r_001 == _x_001 + _x_002 || _x_001 == 500 + 0.2"; @@ -558,13 +558,13 @@ public void testBitwiseOr1() { assertThat(executeExpressionWithDefaultVariables("2|4")).isEqualTo(6); } - @Ignore("DROOLS-6572 - Considers second element a boolean") + @Disabled("DROOLS-6572 - Considers second element a boolean") @Test public void testBitwiseOr2() { assertThat(executeExpressionWithDefaultVariables("(2 | 1) > 0")).isEqualTo(true); } - @Ignore("DROOLS-6572 - Considers second element a boolean") + @Disabled("DROOLS-6572 - Considers second element a boolean") @Test public void testBitwiseOr3() { assertThat(executeExpressionWithDefaultVariables("(2|1) == 3")).isEqualTo(true); @@ -595,7 +595,7 @@ public void testShiftLeft2() { assertThat(executeExpressionWithDefaultVariables("five << 1")).isEqualTo(5 << 1); } - @Ignore("DROOLS-6572 - Generates wrong code - unable to parse <<<") + @Disabled("DROOLS-6572 - Generates wrong code - unable to parse <<<") @Test public void testUnsignedShiftLeft() { assertThat(executeExpressionWithDefaultVariables("-2 <<< 0")).isEqualTo(2); @@ -631,7 +631,7 @@ public void testShiftLeftAssign() { assertThat(executeExpressionWithDefaultVariables("_yYy = 10; _yYy <<= 2")).isEqualTo(10 << 2); } - @Ignore("DROOLS-6572 - Unable to parse") + @Disabled("DROOLS-6572 - Unable to parse") @Test public void testUnsignedShiftRightAssign() { String expression = "_xXx = -5; _xXx >>>= 2"; @@ -669,7 +669,7 @@ public void testDeepPropertyAdd() { assertThat(executeExpressionWithDefaultVariables("foo.countTest+ 10")).isEqualTo(10); } - @Ignore("DROOLS-6572 - Generates wrong code") + @Disabled("DROOLS-6572 - Generates wrong code") @Test public void testDeepAssignmentIncrement() { String expression = "foo.countTest += 5; if (foo.countTest == 5) { foo.countTest = 0; return true; }" + @@ -681,7 +681,7 @@ public void testDeepAssignmentIncrement() { " else { foo.countTest = 0; return false; }")).isEqualTo(true); } - @Ignore("DROOLS-6572 - Generates wrong code - check for statements") + @Disabled("DROOLS-6572 - Generates wrong code - check for statements") @Test public void testDeepAssignmentWithBlock() { String expression = "with (foo) { countTest += 5 }; if (foo.countTest == 5) { foo.countTest = 0; return true; }" + @@ -723,19 +723,19 @@ public void testOperativeAssignShift3() { assertThat(executeExpressionWithDefaultVariables("int val = -5; val >>>= 2; val")).isEqualTo(val >>>= 2); } - @Ignore("DROOLS-6572 - Unable to parse") + @Disabled("DROOLS-6572 - Unable to parse") @Test public void testAssignPlus() { assertThat(executeExpressionWithDefaultVariables("xx0 = 5; xx0 += 4; xx0 + 1")).isEqualTo(10); } - @Ignore("DROOLS-6572 - Unable to parse") + @Disabled("DROOLS-6572 - Unable to parse") @Test public void testAssignPlus2() { assertThat(executeExpressionWithDefaultVariables("xx0 = 5; xx0 =+ 4; xx0 + 1")).isEqualTo(10); } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testAssignDiv() { assertThat(executeExpressionWithDefaultVariables("xx0 = 20; xx0 /= 10; xx0")).isEqualTo(2.0); @@ -750,7 +750,7 @@ public void testAssignSub() { assertThat(executeExpressionWithDefaultVariables("xx0 = 15; xx0 -= 4; xx0")).isEqualTo(11); } - @Ignore("DROOLS-6572 - Calculation error") + @Disabled("DROOLS-6572 - Calculation error") @Test public void testAssignSub2() { assertThat(executeExpressionWithDefaultVariables("xx0 = 5; xx0 =- 100")).isEqualTo(-95); @@ -762,7 +762,7 @@ public void testBooleanStrAppend() { } - @Ignore("DROOLS-6572 - Unable to parse") + @Disabled("DROOLS-6572 - Unable to parse") @Test public void testStringAppend() { String expression = "c + 'bar'"; @@ -784,7 +784,7 @@ public void testStrongTypingModeComparison() { } - @Ignore("DROOLS-6572 - Rounding error") + @Disabled("DROOLS-6572 - Rounding error") @Test public void testJIRA158() { String expression = "(float) (4/2 + Math.sin(1))"; @@ -822,7 +822,7 @@ public void testJIRA163() { assertThat(executeExpression(expression, vars)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Wrong value calculated") + @Disabled("DROOLS-6572 - Wrong value calculated") @Test public void testJIRA164() { String expression = "1 / (var1 + var1) * var1"; @@ -837,7 +837,7 @@ public void testJIRA164() { } - @Ignore("DROOLS-6572 - Wrong value calculated") + @Disabled("DROOLS-6572 - Wrong value calculated") @Test public void testJIRA164b() { String expression = "1 + 1 / (var1 + var1) * var1"; @@ -850,7 +850,7 @@ public void testJIRA164b() { assertThat(executeExpression(expression, vars)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Wrong value calculated") + @Disabled("DROOLS-6572 - Wrong value calculated") @Test public void testJIRA164c() { double var1 = 1d; @@ -864,7 +864,7 @@ public void testJIRA164c() { assertThat(executeExpression(expression, vars)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Wrong value calculated") + @Disabled("DROOLS-6572 - Wrong value calculated") @Test public void testJIRA164d() { double var1 = 1d; @@ -877,7 +877,7 @@ public void testJIRA164d() { assertThat(executeExpression(expression, vars)).isEqualTo(result); } - @Ignore("DROOLS-6572 - Wrong value calculated") + @Disabled("DROOLS-6572 - Wrong value calculated") @Test public void testJIRA164e() { String expression = "10 + 11 + 12 / (var1 + var1 + 51 + 71) * var1 + 13 + 14"; @@ -889,7 +889,7 @@ public void testJIRA164e() { assertThat(((Double) executeExpression(expression, vars)).floatValue()).isCloseTo((float) (10 + 11 + 12 / (var1 + var1 + 51 + 71) * var1 + 13 + 14), within(0.01f)); } - @Ignore("DROOLS-6572 - Wrong value calculated") + @Disabled("DROOLS-6572 - Wrong value calculated") @Test public void testJIRA164f() { String expression = "10 + 11 + 12 / (var1 + 1 + var1 + 51 + 71) * var1 + 13 + 14"; @@ -995,7 +995,7 @@ public void testJIRA210() { } } - @Ignore("DROOLS-6572 - Generates wrong code - missing symbol") + @Disabled("DROOLS-6572 - Generates wrong code - missing symbol") @Test public void testMathDec30() { Map params = new HashMap<>(); @@ -1027,7 +1027,7 @@ public void testJIRA99_Compiled() { assertThat(executeExpression("x - y - z", map)).isEqualTo(20 - 10 - 5); } - @Ignore("DROOLS-6572 - Too many iterations - why") + @Disabled("DROOLS-6572 - Too many iterations - why") @Test public void testModExpr() { String str = "$y % 4 == 0 && $y % 100 != 0 || $y % 400 == 0 "; @@ -1054,7 +1054,7 @@ public void testIntsWithDivision() { assertThat(result).isTrue(); } - @Ignore("DROOLS-6572 - Wrong result") + @Disabled("DROOLS-6572 - Wrong result") @Test public void testMathCeil() { String expression = "Math.ceil( x/3 ) == 2"; @@ -1065,7 +1065,7 @@ public void testMathCeil() { assertThat(result).isTrue(); } - @Ignore("DROOLS-6572 - Generates wrong code") + @Disabled("DROOLS-6572 - Generates wrong code") @Test public void testStaticMathCeil() { int x = 4; @@ -1078,7 +1078,7 @@ public void testStaticMathCeil() { assertThat(executeExpression(expression, vars)).isEqualTo(Integer.valueOf(2)); } - @Ignore("DROOLS-6572 - Calculates wrong result") + @Disabled("DROOLS-6572 - Calculates wrong result") @Test public void testStaticMathCeilWithJavaClassStyleLiterals() { String expression = "java.lang.Math.ceil( x/3 )"; diff --git a/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/ConstraintCompilerTest.java b/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/ConstraintCompilerTest.java index a84d73bd9f0..0f6401d3710 100644 --- a/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/ConstraintCompilerTest.java +++ b/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/ConstraintCompilerTest.java @@ -27,8 +27,8 @@ import org.drools.Person; import org.drools.util.ClassTypeResolver; import org.drools.util.TypeResolver; +import org.junit.jupiter.api.Test; import org.drools.mvelcompiler.context.MvelCompilerContext; -import org.junit.Test; public class ConstraintCompilerTest implements CompilerTest { diff --git a/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/MvelCompilerTest.java b/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/MvelCompilerTest.java index 9604a497243..74bdd45d5b6 100644 --- a/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/MvelCompilerTest.java +++ b/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/MvelCompilerTest.java @@ -24,7 +24,7 @@ import org.drools.Person; import org.drools.util.MethodUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/PreprocessCompilerTest.java b/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/PreprocessCompilerTest.java index c02fc88b30b..1296cee6214 100644 --- a/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/PreprocessCompilerTest.java +++ b/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/PreprocessCompilerTest.java @@ -23,7 +23,7 @@ import org.drools.Person; import org.drools.mvelcompiler.context.MvelCompilerContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/util/MethodResolutionUtilsTest.java b/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/util/MethodResolutionUtilsTest.java index 7bef361efae..1d561331f0a 100644 --- a/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/util/MethodResolutionUtilsTest.java +++ b/drools-model/drools-mvel-compiler/src/test/java/org/drools/mvelcompiler/util/MethodResolutionUtilsTest.java @@ -35,7 +35,7 @@ import org.drools.mvelcompiler.ast.StringLiteralExpressionT; import org.drools.mvelcompiler.ast.TypedExpression; import org.drools.mvelcompiler.context.MvelCompilerContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.lang.reflect.Method; import java.util.ArrayList; diff --git a/drools-model/drools-mvel-parser/pom.xml b/drools-model/drools-mvel-parser/pom.xml index 00c721b6eca..5d0bf9a42cc 100644 --- a/drools-model/drools-mvel-parser/pom.xml +++ b/drools-model/drools-mvel-parser/pom.xml @@ -48,9 +48,9 @@ test - junit - junit - test + org.junit.jupiter + junit-jupiter + test org.assertj diff --git a/drools-model/drools-mvel-parser/src/test/java/org/drools/mvel/parser/DrlxParserTest.java b/drools-model/drools-mvel-parser/src/test/java/org/drools/mvel/parser/DrlxParserTest.java index 6bb61df814a..9c505d358f5 100644 --- a/drools-model/drools-mvel-parser/src/test/java/org/drools/mvel/parser/DrlxParserTest.java +++ b/drools-model/drools-mvel-parser/src/test/java/org/drools/mvel/parser/DrlxParserTest.java @@ -21,10 +21,11 @@ import java.io.IOException; import java.nio.file.Paths; +import org.junit.jupiter.api.Test; + import com.github.javaparser.ParseResult; import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; -import org.junit.Test; import static org.assertj.core.api.Assertions.fail; import static org.drools.mvel.parser.Providers.provider; diff --git a/drools-model/drools-mvel-parser/src/test/java/org/drools/mvel/parser/DroolsMvelParserTest.java b/drools-model/drools-mvel-parser/src/test/java/org/drools/mvel/parser/DroolsMvelParserTest.java index 49910e35269..2092885874c 100644 --- a/drools-model/drools-mvel-parser/src/test/java/org/drools/mvel/parser/DroolsMvelParserTest.java +++ b/drools-model/drools-mvel-parser/src/test/java/org/drools/mvel/parser/DroolsMvelParserTest.java @@ -47,11 +47,12 @@ import org.drools.mvel.parser.ast.expr.TemporalLiteralChunkExpr; import org.drools.mvel.parser.ast.expr.TemporalLiteralExpr; import org.drools.mvel.parser.printer.PrintUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.drools.mvel.parser.DrlxParser.parseExpression; import static org.drools.mvel.parser.printer.PrintUtil.printNode; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; public class DroolsMvelParserTest { @@ -293,10 +294,10 @@ public void testHalfDotFreeExprWithFourTemporalArgs() { assertThat(printNode(expression)).isEqualTo(expr); } - @Test(expected = ParseProblemException.class) + @Test public void testInvalidTemporalArgs() { String expr = "this after[5ms,8f] $a"; - Expression expression = parseExpression( parser, expr ).getExpr(); + assertThatExceptionOfType(ParseProblemException.class).isThrownBy(() -> parseExpression( parser, expr ).getExpr()); } @Test @@ -797,10 +798,10 @@ public void testModifyStatement() { "}"); } - @Test(expected = ParseProblemException.class) + @Test public void testModifyFailing() { String expr = "{ modify { name = \"Luca\", age = \"35\" }; }"; - MvelParser.parseBlock(expr); + assertThatExceptionOfType(ParseProblemException.class).isThrownBy(() -> MvelParser.parseBlock(expr)); } @Test @@ -875,10 +876,10 @@ public void testWithStatement() { "}"); } - @Test(expected = ParseProblemException.class) + @Test public void testWithFailing() { String expr = "{ with { name = \"Luca\", age = \"35\" }; }"; - MvelParser.parseBlock(expr); + assertThatExceptionOfType(ParseProblemException.class).isThrownBy(() -> MvelParser.parseBlock(expr)); } @Test