From 8acf155a2e8e3e3d5496fddbf61371822c63724f Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Tue, 19 Nov 2024 14:23:43 +0100 Subject: [PATCH 1/6] Migrated tests to JUnit5 --- .../NegativePatternsTest.java | 53 +++--- .../concurrency/AbstractConcurrentTest.java | 33 ++-- .../ConcurrentBasesParallelTest.java | 164 +++++++++++------ ...aTypeEvaluationConcurrentSessionsTest.java | 171 ++++++++++++------ .../EnumEvaluationConcurrentSessionsTest.java | 40 ++-- .../JoinsConcurrentSessionsTest.java | 41 +++-- .../SharedSessionParallelTest.java | 109 ++++++----- .../SubnetworkConcurrentSessionsTest.java | 89 +++++---- 8 files changed, 424 insertions(+), 276 deletions(-) diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/NegativePatternsTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/NegativePatternsTest.java index 6aa38d2258a..b8e8dbaa79e 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/NegativePatternsTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/NegativePatternsTest.java @@ -19,20 +19,18 @@ package org.drools.compiler.integrationtests; import java.io.Serializable; -import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.KieSessionTestConfiguration; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.event.rule.AfterMatchFiredEvent; import org.kie.api.event.rule.DefaultAgendaEventListener; @@ -48,29 +46,22 @@ * inserted through one or more entry points. * BZ-978979 */ -@RunWith(Parameterized.class) public class NegativePatternsTest { private static final int LOOPS = 300; private static final int SHORT_SLEEP_TIME = 20; private static final int LONG_SLEEP_TIME = 30; - private final KieBaseTestConfiguration kieBaseTestConfiguration; private KieSession ksession; private TrackingAgendaEventListener firedRulesListener; - public NegativePatternsTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseStreamConfigurations(true); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseStreamConfigurations(true).stream(); } - - @Before - public void prepareKieSession() { + + public void prepareKieSession(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "package org.drools.compiler.integrationtests\n" + "\n" + "import " + NegativePatternsTest.TestEvent.class.getCanonicalName() + "\n" + @@ -124,15 +115,17 @@ public void prepareKieSession() { ksession.addEventListener(firedRulesListener); } - @After + @AfterEach public void cleanKieSession() { if (ksession != null) { ksession.dispose(); } } - @Test - public void testSingleEvent() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testSingleEvent(KieBaseTestConfiguration kieBaseTestConfiguration) { + prepareKieSession(kieBaseTestConfiguration); final EntryPoint entryPoint = ksession.getEntryPoint("EventStream"); int count = 0; @@ -169,8 +162,10 @@ public void testSingleEvent() { assertThat(firedRulesListener.ruleFiredCount("SingleAbsence")).isEqualTo(count); } - @Test - public void testConstrainedAbsence() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testConstrainedAbsence(KieBaseTestConfiguration kieBaseTestConfiguration) { + prepareKieSession(kieBaseTestConfiguration); final EntryPoint entryPoint = ksession.getEntryPoint("EventStream"); int count = 0; @@ -198,8 +193,10 @@ public void testConstrainedAbsence() { assertThat(firedRulesListener.ruleFiredCount("SingleConstrained")).isEqualTo(count); } - @Test - public void testMultipleEvents() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testMultipleEvents(KieBaseTestConfiguration kieBaseTestConfiguration) { + prepareKieSession(kieBaseTestConfiguration); final EntryPoint entryPoint = ksession.getEntryPoint("EventStream"); int count = 0; @@ -237,8 +234,10 @@ public void testMultipleEvents() { assertThat(firedRulesListener.ruleFiredCount("MultipleEvents")).isEqualTo(count); } - @Test - public void testMultipleEntryPoints() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testMultipleEntryPoints(KieBaseTestConfiguration kieBaseTestConfiguration) { + prepareKieSession(kieBaseTestConfiguration); final EntryPoint entryPoint = ksession.getEntryPoint("EventStream"); final EntryPoint otherStream = ksession.getEntryPoint("OtherStream"); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/AbstractConcurrentTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/AbstractConcurrentTest.java index c92061492b3..4a8253f4ac4 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/AbstractConcurrentTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/AbstractConcurrentTest.java @@ -45,20 +45,12 @@ public abstract class AbstractConcurrentTest { - protected final boolean enforcedJitting; - protected final boolean serializeKieBase; - protected final boolean sharedKieBase; - protected final boolean sharedKieSession; - protected final KieBaseTestConfiguration kieBaseTestConfiguration; - - public AbstractConcurrentTest(final boolean enforcedJitting, final boolean serializeKieBase, - final boolean sharedKieBase, final boolean sharedKieSession, KieBaseTestConfiguration kieBaseTestConfiguration) { - this.enforcedJitting = enforcedJitting; - this.serializeKieBase = serializeKieBase; - this.sharedKieBase = sharedKieBase; - this.sharedKieSession = sharedKieSession; - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } + protected boolean enforcedJitting; + protected boolean isKieBaseSerialized; + protected boolean isKieBaseShared; + protected boolean isKieSessionShared; + protected KieBaseTestConfiguration kieBaseTestConfiguration; + interface TestWithSessionExecutor { boolean execute(KieSession kieSession, int counter); @@ -67,6 +59,15 @@ interface TestWithSessionExecutor { interface TestExecutor { boolean execute(int counter); } + + protected void initTest(boolean enforcedJitting, boolean isKieBaseSerialized, + boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) { + this.enforcedJitting = enforcedJitting; + this.isKieBaseSerialized = isKieBaseSerialized; + this.isKieBaseShared = isKieBaseShared; + this.isKieSessionShared = isKieSessionShared; + this.kieBaseTestConfiguration = kieBaseTestConfiguration; + } protected void parallelTest(final int threadCount, final TestExecutor testExecutor) throws InterruptedException { final List> tasks = new ArrayList<>(); @@ -96,8 +97,8 @@ protected void parallelTest(final int repetitions, final int threadCount, final for (int i = 0; i < threadCount; i++) { final int counter = i; tasks.add(() -> { - final KieBase kieBaseForTest = this.sharedKieBase ? sharedKieBase : getKieBase(drls); - if (this.sharedKieSession) { + final KieBase kieBaseForTest = this.isKieBaseShared ? sharedKieBase : getKieBase(drls); + if (this.isKieSessionShared) { return testExecutor.execute(sharedKieSession, counter); } else { return executeInSeparateSession(testExecutor, kieBaseForTest, globalName, global, counter); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/ConcurrentBasesParallelTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/ConcurrentBasesParallelTest.java index c0208f8a904..e354b9c4c6f 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/ConcurrentBasesParallelTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/ConcurrentBasesParallelTest.java @@ -23,56 +23,55 @@ import java.util.Collection; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Stream; import org.drools.mvel.integrationtests.facts.BeanA; import org.drools.mvel.integrationtests.facts.BeanB; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.Timeout; +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.runtime.KieSession; import org.kie.api.runtime.rule.QueryResults; import org.kie.api.runtime.rule.QueryResultsRow; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; + /** * Test each thread having it's own separate KieBase and KieSession. */ -@RunWith(Parameterized.class) public class ConcurrentBasesParallelTest extends AbstractConcurrentTest { - @Parameterized.Parameters(name = "Enforced jitting={0}, KieBase type={1}") - public static List getTestParameters() { - List baseParams = Arrays.asList( - new Boolean[]{false}, - new Boolean[]{true}); + public static Stream parameters() { + List baseParams = Arrays.asList(false, true); - Collection kbParams = TestParametersUtil.getKieBaseCloudConfigurations(true); + Collection kbParams = TestParametersUtil2.getKieBaseCloudConfigurations(true); // combine - List params = new ArrayList<>(); - for (Boolean[] baseParam : baseParams) { - for (Object[] kbParam : kbParams) { - if (baseParam[0] == true && ((KieBaseTestConfiguration) kbParam[0]).isExecutableModel()) { + List params = new ArrayList<>(); + for (Boolean baseParam : baseParams) { + for (KieBaseTestConfiguration kbParam : kbParams) { + if (baseParam && kbParam.isExecutableModel()) { // jitting & exec-model test is not required } else { - params.add(new Object[]{baseParam[0], kbParam[0]}); + params.add(arguments(baseParam, kbParam)); } } } - return params; + return params.stream(); } private static final Integer NUMBER_OF_THREADS = 10; - public ConcurrentBasesParallelTest(final boolean enforcedJitting, final KieBaseTestConfiguration kieBaseTestConfiguration) { - super(enforcedJitting, false, false, false, kieBaseTestConfiguration); - }; - - @Test(timeout = 40000) - public void testOneOfAllFactsMatches() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testOneOfAllFactsMatches(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final int numberOfObjects = 100; final TestExecutor exec = counter -> { @@ -99,8 +98,11 @@ public void testOneOfAllFactsMatches() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testNoFactMatches() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testNoFactMatches(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final TestExecutor exec = counter -> { final String rule = "import " + BeanA.class.getCanonicalName() + ";\n" + "rule Rule_" + counter + " " + @@ -128,8 +130,11 @@ public void testNoFactMatches() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testFireAndGlobalSeparation() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testFireAndGlobalSeparation(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final TestExecutor exec = counter -> { final String rule = "import " + BeanA.class.getCanonicalName() + ";\n" + "global " + AtomicInteger.class.getCanonicalName() + " result;\n" + @@ -158,8 +163,11 @@ public void testFireAndGlobalSeparation() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testFireAndGlobalSeparation2() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testFireAndGlobalSeparation2(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final String ruleTemplate = "import " + BeanA.class.getCanonicalName() + ";\n" + "import " + BeanB.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + @@ -197,8 +205,11 @@ public void testFireAndGlobalSeparation2() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testNonMatchingFact() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testNonMatchingFact(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final String ruleTemplate = "import " + BeanA.class.getCanonicalName() + ";\n" + "import " + BeanB.class.getCanonicalName() + ";\n" + "rule ${ruleName} " + @@ -231,8 +242,11 @@ public void testNonMatchingFact() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testMatchingFact() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testMatchingFact(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final String ruleTemplate = "import " + BeanA.class.getCanonicalName() + ";\n" + "import " + BeanB.class.getCanonicalName() + ";\n" + "rule ${ruleName} " + @@ -265,8 +279,11 @@ public void testMatchingFact() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testNot() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testNot(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final String ruleTemplate = "import " + BeanA.class.getCanonicalName() + ";\n" + "import " + BeanB.class.getCanonicalName() + ";\n" + "rule ${ruleName} " + @@ -300,8 +317,11 @@ public void testNot() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testExists() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testExists(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final String ruleTemplate = "import " + BeanA.class.getCanonicalName() + ";\n" + "import " + BeanB.class.getCanonicalName() + ";\n" + "rule ${ruleName} " + @@ -336,8 +356,11 @@ public void testExists() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testSubnetwork() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testSubnetwork(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final String ruleTemplate = "import " + BeanA.class.getCanonicalName() + ";\n" + "import " + BeanB.class.getCanonicalName() + ";\n" + "rule ${ruleName} " + @@ -383,8 +406,11 @@ public void testSubnetwork() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testAccumulatesMatchOnlyBeanA() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testAccumulatesMatchOnlyBeanA(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final String ruleA = "import " + BeanA.class.getCanonicalName() + ";\n" + "rule RuleA " + "when " + @@ -421,8 +447,11 @@ public void testAccumulatesMatchOnlyBeanA() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testAccumulatesMatchBoth() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testAccumulatesMatchBoth(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final String ruleA = "import " + BeanA.class.getCanonicalName() + ";\n" + "rule RuleA " + "when " + @@ -454,8 +483,11 @@ public void testAccumulatesMatchBoth() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testAccumulatesMatchOnlyOne() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testAccumulatesMatchOnlyOne(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final String ruleA = "import " + BeanA.class.getCanonicalName() + ";\n" + "rule RuleA " + "when " + @@ -491,8 +523,11 @@ public void testAccumulatesMatchOnlyOne() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testNotsMatchOnlyOne() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testNotsMatchOnlyOne(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final String ruleA = "import " + BeanA.class.getCanonicalName() + ";\n" + "rule RuleNotA " + "when " + @@ -528,8 +563,11 @@ public void testNotsMatchOnlyOne() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testNotsMatchBoth() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testNotsMatchBoth(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final String ruleA = "import " + BeanA.class.getCanonicalName() + ";\n" + "rule RuleNotA " + "when " + @@ -565,8 +603,11 @@ public void testNotsMatchBoth() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testFunctions() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testFunctions(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final String rule = "import " + BeanA.class.getCanonicalName() + ";\n" + "global java.util.List list;" + "rule Rule " + @@ -602,8 +643,11 @@ public void testFunctions() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testFunctions2() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testFunctions2(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final int objectCount = 100; final String rule = "import " + BeanA.class.getCanonicalName() + ";\n" + @@ -651,8 +695,11 @@ public void testFunctions2() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testQueries() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testQueries(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final int numberOfObjects = 100; final TestExecutor exec = counter -> { @@ -686,8 +733,11 @@ public void testQueries() throws InterruptedException { parallelTest(NUMBER_OF_THREADS, exec); } - @Test(timeout = 40000) - public void testQueries2() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testQueries2(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final int numberOfObjects = 100; final String queryTemplate = "import " + BeanA.class.getCanonicalName() + ";\n" + diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/DataTypeEvaluationConcurrentSessionsTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/DataTypeEvaluationConcurrentSessionsTest.java index 5e840e1f2f8..b51c6ff2ea0 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/DataTypeEvaluationConcurrentSessionsTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/DataTypeEvaluationConcurrentSessionsTest.java @@ -24,6 +24,7 @@ import java.util.Collection; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Stream; import org.drools.mvel.integrationtests.facts.AnEnum; import org.drools.mvel.integrationtests.facts.FactWithBigDecimal; @@ -38,21 +39,21 @@ import org.drools.mvel.integrationtests.facts.FactWithShort; import org.drools.mvel.integrationtests.facts.FactWithString; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; -@RunWith(Parameterized.class) public class DataTypeEvaluationConcurrentSessionsTest extends AbstractConcurrentTest { private static final Integer NUMBER_OF_THREADS = 10; private static final Integer NUMBER_OF_REPETITIONS = 1; - @Parameterized.Parameters(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") - public static List getTestParameters() { + public static Stream parameters() { List baseParams = Arrays.asList( new Boolean[]{false, false, false}, new Boolean[]{true, false, false}, @@ -64,118 +65,170 @@ public static List getTestParameters() { new Boolean[]{false, true, true}, new Boolean[]{true, true, true}); // TODO: EM failed with some tests. File JIRAs - Collection kbParams = TestParametersUtil.getKieBaseCloudConfigurations(false); + Collection kbParams = TestParametersUtil2.getKieBaseCloudConfigurations(false); // combine - List params = new ArrayList<>(); + List params = new ArrayList<>(); for (Boolean[] baseParam : baseParams) { - for (Object[] kbParam : kbParams) { - if (baseParam[0] == true && ((KieBaseTestConfiguration) kbParam[0]).isExecutableModel()) { + for (KieBaseTestConfiguration kbParam : kbParams) { + if (baseParam[0] && kbParam.isExecutableModel()) { // jitting & exec-model test is not required } else { - params.add(new Object[]{baseParam[0], baseParam[1], baseParam[2], kbParam[0]}); + params.add(arguments(baseParam[0], baseParam[1], baseParam[2], kbParam)); } } } - return params; + return params.stream(); } - public DataTypeEvaluationConcurrentSessionsTest(final boolean enforcedJitting, - final boolean sharedKieBase, final boolean sharedKieSession, final KieBaseTestConfiguration kieBaseTestConfiguration) { - super(enforcedJitting, false, sharedKieBase, sharedKieSession, kieBaseTestConfiguration); + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testBooleanPrimitive(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); + testFactAttributeType(" $factWithBoolean: FactWithBoolean(booleanValue == false) \n", new FactWithBoolean(false)); } - @Test(timeout = 40000) - public void testBooleanPrimitive() throws InterruptedException { - testFactAttributeType(" $factWithBoolean: FactWithBoolean(booleanValue == false) \n", new FactWithBoolean(false)); - } - - @Test(timeout = 40000) - public void testBoolean() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testBoolean(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithBoolean: FactWithBoolean(booleanObjectValue == false) \n", new FactWithBoolean(false)); } - @Test(timeout = 40000) - public void testBytePrimitive() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testBytePrimitive(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithByte: FactWithByte(byteValue == 15) \n", new FactWithByte((byte) 15)); } - @Test(timeout = 40000) - public void testByte() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testByte(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithByte: FactWithByte(byteObjectValue == 15) \n", new FactWithByte((byte) 15)); } - @Test(timeout = 40000) - public void testShortPrimitive() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testShortPrimitive(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithShort: FactWithShort(shortValue == 15) \n", new FactWithShort((short) 15)); } - @Test(timeout = 40000) - public void testShort() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testShort(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithShort: FactWithShort(shortObjectValue == 15) \n", new FactWithShort((short) 15)); } - @Test(timeout = 40000) - public void testIntPrimitive() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testIntPrimitive(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithInt: FactWithInteger(intValue == 15) \n", new FactWithInteger(15)); } - @Test(timeout = 40000) - public void testInteger() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testInteger(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithInteger: FactWithInteger(integerValue == 15) \n", new FactWithInteger(15)); } - @Test(timeout = 40000) - public void testLongPrimitive() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testLongPrimitive(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithLong: FactWithLong(longValue == 15) \n", new FactWithLong(15)); } - @Test(timeout = 40000) - public void testLong() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testLong(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithLong: FactWithLong(longObjectValue == 15) \n", new FactWithLong(15)); } - @Test(timeout = 40000) - public void testFloatPrimitive() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testFloatPrimitive(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithFloat: FactWithFloat(floatValue == 15.1) \n", new FactWithFloat(15.1f)); } - @Test(timeout = 40000) - public void testFloat() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testFloat(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithFloat: FactWithFloat(floatObjectValue == 15.1) \n", new FactWithFloat(15.1f)); } - @Test(timeout = 40000) - public void testDoublePrimitive() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testDoublePrimitive(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithDouble: FactWithDouble(doubleValue == 15.1) \n", new FactWithDouble(15.1d)); } - @Test(timeout = 40000) - public void testDouble() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testDouble(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithDouble: FactWithDouble(doubleObjectValue == 15.1) \n", new FactWithDouble(15.1d)); } - @Test(timeout = 40000) - public void testBigDecimal() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testBigDecimal(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithBigDecimal: FactWithBigDecimal(bigDecimalValue == 10) \n", new FactWithBigDecimal(BigDecimal.TEN)); } - @Test(timeout = 40000) - public void testCharPrimitive() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testCharPrimitive(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithChar: FactWithCharacter(charValue == 'a') \n", new FactWithCharacter('a')); } - @Test(timeout = 40000) - public void testCharacter() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testCharacter(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithChar: FactWithCharacter(characterValue == 'a') \n", new FactWithCharacter('a')); } - @Test(timeout = 40000) - public void testString() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testString(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithString: FactWithString(stringValue == \"test\") \n", new FactWithString("test")); } - @Test(timeout = 40000) - public void testEnum() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, Share KieSession={2}, KieBase type={3}") + @MethodSource("parameters") + @Timeout(40000) + public void testEnum(boolean enforcedJitting, boolean isKieBaseShared, boolean isKieSessionShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, isKieSessionShared, kieBaseTestConfiguration); testFactAttributeType(" $factWithEnum: FactWithEnum(enumValue == AnEnum.FIRST) \n", new FactWithEnum(AnEnum.FIRST)); } @@ -195,10 +248,10 @@ private void testFactAttributeType(final String ruleConstraint, final Object fac parallelTest(NUMBER_OF_REPETITIONS, NUMBER_OF_THREADS, (kieSession, counter) -> { kieSession.insert(factInserted); final int rulesFired = kieSession.fireAllRules(); - return sharedKieSession || rulesFired == 1; + return isKieSessionShared || rulesFired == 1; }, "numberOfFirings", numberOfFirings, drl); - if (sharedKieSession) { + if (isKieSessionShared) { // This is 1 because engine doesn't insert an already existing object twice, so when sharing a session // the object should be present just once in the session. When not sharing a session, there is N separate // sessions, so each one should fire. diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/EnumEvaluationConcurrentSessionsTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/EnumEvaluationConcurrentSessionsTest.java index c0b1469f58c..e270e41caf0 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/EnumEvaluationConcurrentSessionsTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/EnumEvaluationConcurrentSessionsTest.java @@ -22,51 +22,51 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.mvel.integrationtests.facts.CategoryTypeEnum; import org.drools.mvel.integrationtests.facts.Product; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.params.provider.Arguments.arguments; -@RunWith(Parameterized.class) public class EnumEvaluationConcurrentSessionsTest extends AbstractConcurrentTest { private static final Integer NUMBER_OF_THREADS = 10; private static final Integer NUMBER_OF_REPETITIONS = 1; - @Parameterized.Parameters(name = "Enforced jitting={0}, Share KieBase={1}, KieBase type={2}") - public static List getTestParameters() { + public static Stream parameters() { List baseParams = Arrays.asList( new Boolean[]{false, false}, new Boolean[]{true, false}, new Boolean[]{false, true}, new Boolean[]{true, true}); - Collection kbParams = TestParametersUtil.getKieBaseCloudConfigurations(true); + Collection kbParams = TestParametersUtil2.getKieBaseCloudConfigurations(true); // combine - List params = new ArrayList<>(); + List params = new ArrayList<>(); for (Boolean[] baseParam : baseParams) { - for (Object[] kbParam : kbParams) { - if (baseParam[0] == true && ((KieBaseTestConfiguration) kbParam[0]).isExecutableModel()) { + for (KieBaseTestConfiguration kbParam : kbParams) { + if (baseParam[0] == true && kbParam.isExecutableModel()) { // jitting & exec-model test is not required } else { - params.add(new Object[]{baseParam[0], baseParam[1], kbParam[0]}); + params.add(arguments(baseParam[0], baseParam[1], kbParam)); } } } - return params; - } - - public EnumEvaluationConcurrentSessionsTest(final boolean enforcedJitting, - final boolean sharedKieBase, final KieBaseTestConfiguration kieBaseTestConfiguration) { - super(enforcedJitting, false, sharedKieBase, false, kieBaseTestConfiguration); + return params.stream(); } - @Test(timeout = 40000) - public void testEnum2() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, KieBase type={2}") + @MethodSource("parameters") + @Timeout(40000) + public void testEnum2(boolean enforcedJitting, boolean isKieBaseShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, false, kieBaseTestConfiguration); final String drl1 = "import " + Product.class.getCanonicalName() + ";\n" + "import " + CategoryTypeEnum.class.getCanonicalName() + ";\n" + diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/JoinsConcurrentSessionsTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/JoinsConcurrentSessionsTest.java index e9dad3fb574..d06d16611f6 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/JoinsConcurrentSessionsTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/JoinsConcurrentSessionsTest.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.mvel.integrationtests.facts.AnEnum; import org.drools.mvel.integrationtests.facts.ChildFact1; @@ -30,47 +31,47 @@ import org.drools.mvel.integrationtests.facts.ChildFact4WithFirings; import org.drools.mvel.integrationtests.facts.RootFact; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.params.provider.Arguments.arguments; + -@RunWith(Parameterized.class) public class JoinsConcurrentSessionsTest extends AbstractConcurrentTest { private static final Integer NUMBER_OF_THREADS = 10; private static final Integer NUMBER_OF_REPETITIONS = 1; - @Parameterized.Parameters(name = "Enforced jitting={0}, Share KieBase={1}, KieBase type={2}") - public static List getTestParameters() { + public static Stream parameters() { List baseParams = Arrays.asList( new Boolean[]{false, false}, new Boolean[]{true, false}, new Boolean[]{false, true}, new Boolean[]{true, true}); - Collection kbParams = TestParametersUtil.getKieBaseCloudConfigurations(true); + Collection kbParams = TestParametersUtil2.getKieBaseCloudConfigurations(true); // combine - List params = new ArrayList<>(); + List params = new ArrayList<>(); for (Boolean[] baseParam : baseParams) { - for (Object[] kbParam : kbParams) { - if (baseParam[0] == true && ((KieBaseTestConfiguration) kbParam[0]).isExecutableModel()) { + for (KieBaseTestConfiguration kbParam : kbParams) { + if (baseParam[0] && kbParam.isExecutableModel()) { // jitting & exec-model test is not required } else { - params.add(new Object[]{baseParam[0], baseParam[1], kbParam[0]}); + params.add(arguments(baseParam[0], baseParam[1], kbParam)); } } } - return params; - } - - public JoinsConcurrentSessionsTest(final boolean enforcedJitting, - final boolean sharedKieBase, final KieBaseTestConfiguration kieBaseTestConfiguration) { - super(enforcedJitting, false, sharedKieBase, false, kieBaseTestConfiguration); + return params.stream(); } - @Test(timeout = 40000) - public void test5() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, KieBase type={2}") + @MethodSource("parameters") + @Timeout(40000) + public void test5(boolean enforcedJitting, boolean isKieBaseShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, false, kieBaseTestConfiguration); final String drlTemplate = " import org.drools.mvel.integrationtests.facts.*;\n" + " rule \"${ruleName}\"\n" + diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/SharedSessionParallelTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/SharedSessionParallelTest.java index 6e2a258f7c7..23516200e9b 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/SharedSessionParallelTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/SharedSessionParallelTest.java @@ -19,57 +19,53 @@ package org.drools.mvel.integrationtests.concurrency; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.CyclicBarrier; +import java.util.stream.Stream; import org.drools.mvel.integrationtests.facts.BeanA; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; +import org.drools.testcoverage.common.util.TestParametersUtil2; import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Timeout; +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 org.kie.test.testcategory.TurtleTestCategory; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; -@RunWith(Parameterized.class) @Category(TurtleTestCategory.class) public class SharedSessionParallelTest extends AbstractConcurrentTest { - @Parameterized.Parameters(name = "Enforced jitting={0}, KieBase type={1}") - public static List getTestParameters() { - List baseParams = Arrays.asList( - new Boolean[] {false}, - new Boolean[] {true} - ); + public static Stream parameters() { + List baseParams = List.of(false, true); - Collection kbParams = TestParametersUtil.getKieBaseCloudConfigurations(true); + Collection kbParams = TestParametersUtil2.getKieBaseCloudConfigurations(true); // combine - List params = new ArrayList<>(); - for (Boolean[] baseParam : baseParams) { - for (Object[] kbParam : kbParams) { - if (baseParam[0] == true && ((KieBaseTestConfiguration) kbParam[0]).isExecutableModel()) { + List params = new ArrayList<>(); + for (Boolean baseParam : baseParams) { + for (KieBaseTestConfiguration kbParam : kbParams) { + if (baseParam && kbParam.isExecutableModel()) { // jitting & exec-model test is not required } else { - params.add(new Object[] {baseParam[0], kbParam[0]}); + params.add(arguments(baseParam, kbParam)); } } } - return params; + return params.stream(); } - public SharedSessionParallelTest(final boolean enforcedJitting, final KieBaseTestConfiguration kieBaseTestConfiguration) { - super(enforcedJitting, false, false, false, kieBaseTestConfiguration); - } - - @Test(timeout = 120000) - public void testNoExceptions() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(120000) + public void testNoExceptions(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final String drl = "rule R1 when String() then end"; final int repetitions = 100; @@ -96,8 +92,11 @@ public void testNoExceptions() throws InterruptedException { } } - @Test(timeout = 40000) - public void testCheckOneThreadOnly() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testCheckOneThreadOnly(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final int threadCount = 100; final List list = Collections.synchronizedList(new ArrayList<>()); @@ -139,8 +138,11 @@ public void testCheckOneThreadOnly() throws InterruptedException { } } - @Test(timeout = 40000) - public void testCorrectFirings() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testCorrectFirings(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final int threadCount = 100; final String drl = "import " + BeanA.class.getCanonicalName() + ";\n" + @@ -168,8 +170,11 @@ public void testCorrectFirings() throws InterruptedException { checkList(threadCount, list); } - @Test(timeout = 40000) - public void testCorrectFirings2() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testCorrectFirings2(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final int threadCount = 100; final String drl = "import " + BeanA.class.getCanonicalName() + ";\n" + @@ -199,8 +204,11 @@ public void testCorrectFirings2() throws InterruptedException { assertThat(list).hasSize(expectedListSize); } - @Test(timeout = 40000) - public void testLongRunningRule() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testLongRunningRule(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final int threadCount = 100; final int seed = threadCount + 200; final int objectCount = 1000; @@ -257,8 +265,11 @@ public void testLongRunningRule() throws InterruptedException { checkList(1, threadCount, list2, (threadCount - 1) * objectCount); } - @Test(timeout = 40000) - public void testLongRunningRule2() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testLongRunningRule2(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final int threadCount = 100; final int seed = 1000; @@ -308,8 +319,11 @@ public void testLongRunningRule2() throws InterruptedException { checkList(0, seed, list, seed * threadCount); } - @Test(timeout = 40000) - public void testLongRunningRule3() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testLongRunningRule3(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final int threadCount = 10; final int seed = threadCount + 50; final int objectCount = 1000; @@ -374,8 +388,11 @@ public void testLongRunningRule3() throws InterruptedException { assertThat(list2).hasSize(list2ExpectedSize); } - @Test(timeout = 40000) - public void testCountdownBean() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testCountdownBean(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final int threadCount = 100; final int seed = 1000; @@ -414,8 +431,11 @@ public void testCountdownBean() throws InterruptedException { assertThat(bean).hasFieldOrPropertyWithValue("seed", 0); } - @Test(timeout = 40000) - public void testCountdownBean2() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(40000) + public void testCountdownBean2(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final int threadCount = 100; final int seed = 1000; @@ -455,8 +475,11 @@ public void testCountdownBean2() throws InterruptedException { } } - @Test(timeout = 60000) - public void testOneRulePerThread() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, KieBase type={1}") + @MethodSource("parameters") + @Timeout(60000) + public void testOneRulePerThread(boolean enforcedJitting, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, false, false, kieBaseTestConfiguration); final int threadCount = 1000; final String[] drls = new String[threadCount]; diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/SubnetworkConcurrentSessionsTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/SubnetworkConcurrentSessionsTest.java index 559dd6405e5..344374446ea 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/SubnetworkConcurrentSessionsTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/concurrency/SubnetworkConcurrentSessionsTest.java @@ -22,22 +22,24 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.mvel.integrationtests.facts.Product; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.params.provider.Arguments.arguments; -@RunWith(Parameterized.class) public class SubnetworkConcurrentSessionsTest extends AbstractConcurrentTest { private static final Integer NUMBER_OF_THREADS = 10; private static final Integer NUMBER_OF_REPETITIONS = 1; - @Parameterized.Parameters(name = "Enforced jitting={0}, Share KieBase={1}, KieBase type={2}") - public static List getTestParameters() { + public static Stream parameters() { List baseParams = Arrays.asList( new Boolean[]{false, false}, new Boolean[]{true, false}, @@ -45,28 +47,26 @@ public static List getTestParameters() { new Boolean[]{true, true} ); - Collection kbParams = TestParametersUtil.getKieBaseCloudConfigurations(true); + Collection kbParams = TestParametersUtil2.getKieBaseCloudConfigurations(true); // combine - List params = new ArrayList<>(); + List params = new ArrayList<>(); for (Boolean[] baseParam : baseParams) { - for (Object[] kbParam : kbParams) { - if (baseParam[0] == true && ((KieBaseTestConfiguration) kbParam[0]).isExecutableModel()) { + for (KieBaseTestConfiguration kbParam : kbParams) { + if (baseParam[0] && kbParam.isExecutableModel()) { // jitting & exec-model test is not required } else { - params.add(new Object[] {baseParam[0], baseParam[1], kbParam[0]}); + params.add(arguments(baseParam[0], baseParam[1], kbParam)); } } } - return params; - } - - public SubnetworkConcurrentSessionsTest(final boolean enforcedJitting, - final boolean sharedKieBase, final KieBaseTestConfiguration kieBaseTestConfiguration) { - super(enforcedJitting, false, sharedKieBase, false, kieBaseTestConfiguration); + return params.stream(); } - @Test(timeout = 80000) - public void test1() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, KieBase type={2}") + @MethodSource("parameters") + @Timeout(80000) + public void test1(boolean enforcedJitting, boolean isKieBaseShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, false, kieBaseTestConfiguration); final String drl = "rule R when String() then end"; parallelTest(NUMBER_OF_REPETITIONS, NUMBER_OF_THREADS, (kieSession, counter) -> { @@ -75,14 +75,20 @@ public void test1() throws InterruptedException { }, null, null, drl ); } - @Test(timeout = 80000) - public void test2NoSubnetwork() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, KieBase type={2}") + @MethodSource("parameters") + @Timeout(80000) + public void test2NoSubnetwork(boolean enforcedJitting, boolean isKieBaseShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, false, kieBaseTestConfiguration); test2(getRule("R1", "this == \"odd\"", false, false, "Number( intValue > 0 )"), getRule("R2", "this == \"pair\"", false, false, "Number( intValue < 10000 )")); } - @Test(timeout = 80000) - public void test2WithSubnetwork() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, KieBase type={2}") + @MethodSource("parameters") + @Timeout(80000) + public void test2WithSubnetwork(boolean enforcedJitting, boolean isKieBaseShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, false, kieBaseTestConfiguration); test2(getRule("R1", "this == \"odd\"", false, true, "Number( intValue > 0 )"), getRule("R2", "this == \"pair\"", false, true, "Number( intValue < 10000 )")); } @@ -111,20 +117,29 @@ private void test2(final String... drls) throws InterruptedException { }, null, null, drls ); } - @Test(timeout = 80000) - public void test3NoSubnetwork() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, KieBase type={2}") + @MethodSource("parameters") + @Timeout(80000) + public void test3NoSubnetwork(boolean enforcedJitting, boolean isKieBaseShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, false, kieBaseTestConfiguration); test3(getRule("R1", "this == \"odd\"", false, false, "Number( intValue > 0 )"), getRule("R2", "this == \"pair\"", false, false, "Number( intValue < 10000 )")); } - @Test(timeout = 80000) - public void test3WithSubnetwork() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, KieBase type={2}") + @MethodSource("parameters") + @Timeout(80000) + public void test3WithSubnetwork(boolean enforcedJitting, boolean isKieBaseShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, false, kieBaseTestConfiguration); test3(getRule("R1", "this == \"odd\"", false, true, "Number( intValue > 0 )"), getRule("R2", "this == \"pair\"", false, true, "Number( intValue < 10000 )")); } - @Test(timeout = 80000) - public void test3WithSharedSubnetwork() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, KieBase type={2}") + @MethodSource("parameters") + @Timeout(80000) + public void test3WithSharedSubnetwork(boolean enforcedJitting, boolean isKieBaseShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, false, kieBaseTestConfiguration); final String ruleTemplate = "import " + Product.class.getCanonicalName() + ";\n" + "rule ${ruleName} when\n" + " $s : String()\n" + @@ -185,14 +200,20 @@ private void test3(final String... drls) throws InterruptedException { }, null, null, drls ); } - @Test(timeout = 20000) - public void test4NoSharing() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, KieBase type={2}") + @MethodSource("parameters") + @Timeout(20000) + public void test4NoSharing(boolean enforcedJitting, boolean isKieBaseShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, false, kieBaseTestConfiguration); test4(getRule("R1", "", false, true, "Number( intValue > 5 )"), getRule("R2", "", false, true, "Number( intValue < 5 )")); } - @Test(timeout = 20000) - public void test4WithSharing() throws InterruptedException { + @ParameterizedTest(name = "Enforced jitting={0}, Share KieBase={1}, KieBase type={2}") + @MethodSource("parameters") + @Timeout(20000) + public void test4WithSharing(boolean enforcedJitting, boolean isKieBaseShared, KieBaseTestConfiguration kieBaseTestConfiguration) throws InterruptedException { + initTest(enforcedJitting, false, isKieBaseShared, false, kieBaseTestConfiguration); test4(getRule("R1", "", true, true, "Number( intValue > 5 )"), getRule("R2", "", true, true, "Number( intValue < 5 )")); } From 95a0dd7e168d8169e3868f1259eb3cee8ed173f9 Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Tue, 19 Nov 2024 15:16:28 +0100 Subject: [PATCH 2/6] More tests migrated --- drools-test-coverage/test-suite/pom.xml | 21 +++++++-- .../AbstractCompositeRestrictionTest.java | 26 ++++------- .../AccumulateRecalculationTest.java | 2 +- .../regression/AmbiguousExceptionTest.java | 26 +++++------ .../BetaMemoryLeakOnDeleteTest.java | 3 +- .../regression/DateExtendingFactTest.java | 26 ++++------- .../regression/DeclarationWithOrTest.java | 26 ++++------- ...serializationWithCompositeTriggerTest.java | 35 ++++++--------- .../regression/DroolsGcCausesNPETest.java | 13 +++--- .../regression/EscapesInMetadataTest.java | 27 ++++-------- .../EventDeserializationInPastTest.java | 2 +- .../EventFactHandleDeserializationTest.java | 2 +- .../regression/FixedPatternTest.java | 31 ++++++------- .../regression/FromGenericCollectionTest.java | 27 ++++-------- .../regression/FusionAfterBeforeTest.java | 34 ++++++--------- .../regression/GenericsWithModifyTest.java | 43 +++++++------------ .../regression/ImportReplaceTest.java | 27 +++++------- .../regression/InaccurateComparisonTest.java | 27 ++++-------- .../SerializationWithCollectTest.java | 10 ++--- ...TruthMaintenanceSystemConcurrencyTest.java | 2 +- .../UnwantedStringConversionTest.java | 27 ++++-------- .../regression/XSDResourceTest.java | 3 +- .../regression/mvel/MvelLinkageErrorTest.java | 2 +- 23 files changed, 174 insertions(+), 268 deletions(-) diff --git a/drools-test-coverage/test-suite/pom.xml b/drools-test-coverage/test-suite/pom.xml index 1e56254af0b..209e64e4e09 100644 --- a/drools-test-coverage/test-suite/pom.xml +++ b/drools-test-coverage/test-suite/pom.xml @@ -170,9 +170,24 @@ - junit - junit - 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.mockito diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AbstractCompositeRestrictionTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AbstractCompositeRestrictionTest.java index 7b00490e119..9454031c660 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AbstractCompositeRestrictionTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AbstractCompositeRestrictionTest.java @@ -18,15 +18,14 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +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; @@ -37,22 +36,15 @@ * Bugfix test for bz#724655 'NPE in AbstractCompositionRestriction when using * unbound variables' */ -@RunWith(Parameterized.class) public class AbstractCompositeRestrictionTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public AbstractCompositeRestrictionTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void test() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void test(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBuilder builder = KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, false, KieServices.Factory.get().getResources().newClassPathResource("abstractCompositeRestrictionTest.drl", getClass())); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AccumulateRecalculationTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AccumulateRecalculationTest.java index 37aa30b0be2..2d307bc9c90 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AccumulateRecalculationTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AccumulateRecalculationTest.java @@ -19,7 +19,7 @@ package org.drools.testcoverage.regression; import org.drools.testcoverage.common.model.MyFact; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.io.ResourceType; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AmbiguousExceptionTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AmbiguousExceptionTest.java index 41239cfd089..197655bd2fb 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AmbiguousExceptionTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AmbiguousExceptionTest.java @@ -21,17 +21,17 @@ import java.io.StringReader; import java.util.Collection; +import java.util.stream.Stream; + import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieServices; import org.kie.api.builder.KieFileSystem; -@RunWith(Parameterized.class) public class AmbiguousExceptionTest { private static final String DRL = " package " + TestConstants.PACKAGE_REGRESSION + "\n\n " @@ -41,19 +41,13 @@ public class AmbiguousExceptionTest { + " then\n" + " end\n"; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public AmbiguousExceptionTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testCompilation() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testCompilation(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieFileSystem fileSystem = KieServices.Factory.get().newKieFileSystem(); fileSystem.write( TestConstants.DRL_TEST_TARGET_PATH, diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/BetaMemoryLeakOnDeleteTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/BetaMemoryLeakOnDeleteTest.java index 6ea368db35d..c8285a98927 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/BetaMemoryLeakOnDeleteTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/BetaMemoryLeakOnDeleteTest.java @@ -21,9 +21,8 @@ import org.drools.core.common.InternalWorkingMemory; import org.drools.core.common.Memory; import org.drools.core.common.NodeMemories; -import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.TupleImpl; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.io.ResourceType; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DateExtendingFactTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DateExtendingFactTest.java index 54a594eb4aa..f4707ea295e 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DateExtendingFactTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DateExtendingFactTest.java @@ -18,15 +18,14 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; import java.util.Date; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +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; @@ -35,7 +34,6 @@ /** * Tests compilation of facts extending java.util.Date (BZ 1072629). */ -@RunWith(Parameterized.class) public class DateExtendingFactTest { private static final String FACT_CLASS_NAME = MyDate.class.getCanonicalName(); @@ -49,22 +47,16 @@ public class DateExtendingFactTest { "$date.setDescription(\"test\");\n" + "end\n"; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public DateExtendingFactTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } /** * Tests compiling DRL with a fact extending java.util.Date. */ - @Test - public void testDateExtendingFact() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testDateExtendingFact(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBuilder kbuilder = KieUtil.getKieBuilderFromDrls(kieBaseTestConfiguration, true, DRL); assertThat(kbuilder.getResults().getMessages(Message.Level.ERROR)).isEmpty(); } diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DeclarationWithOrTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DeclarationWithOrTest.java index bb3cd845864..a3db14e497e 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DeclarationWithOrTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DeclarationWithOrTest.java @@ -19,16 +19,15 @@ package org.drools.testcoverage.regression; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.builder.KieBuilder; import org.kie.api.runtime.KieSession; @@ -37,7 +36,6 @@ /** * Tests handling a variable binding in LHS with OR (BZ 1136424). */ -@RunWith(Parameterized.class) public class DeclarationWithOrTest { private static final String FACT = "working"; @@ -52,22 +50,16 @@ public class DeclarationWithOrTest { " list.add(\"" + FACT + "\");\n" + "end"; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public DeclarationWithOrTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } /** * Verifies that the rule with binding and OR in LHS compiles and works as expected. */ - @Test - public void testBindingWithOrInLHS() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testBindingWithOrInLHS(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBuilder kbuilder = KieUtil.getKieBuilderFromDrls(kieBaseTestConfiguration, true, DRL); final KieSession ksession = KieBaseUtil.getDefaultKieBaseFromKieBuilder(kbuilder).newKieSession(); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DeserializationWithCompositeTriggerTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DeserializationWithCompositeTriggerTest.java index 6257071f715..35bb168579e 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DeserializationWithCompositeTriggerTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DeserializationWithCompositeTriggerTest.java @@ -18,18 +18,16 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.mvel.compiler.StockTick; import org.drools.mvel.integrationtests.SerializationHelper; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.AfterEach; +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; @@ -45,7 +43,6 @@ /** * Verifies that serialization and de-serialization of a composite trigger succeeds (BZ 1142914). */ -@RunWith(Parameterized.class) public class DeserializationWithCompositeTriggerTest { private static final String DRL = @@ -68,19 +65,12 @@ public class DeserializationWithCompositeTriggerTest { private KieSession ksession; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public DeserializationWithCompositeTriggerTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); - } - @Before - public void prepare() { + public void prepare(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBuilder kbuilder = KieUtil.getKieBuilderFromDrls(kieBaseTestConfiguration, true, DRL); final KieContainer kcontainer = KieServices.Factory.get().newKieContainer(kbuilder.getKieModule().getReleaseId()); @@ -94,7 +84,7 @@ public void prepare() { this.ksession = kbase.newKieSession(kieSessionConfiguration, null); } - @After + @AfterEach public void cleanup() { if (this.ksession != null) { this.ksession.dispose(); @@ -104,9 +94,12 @@ public void cleanup() { /** * Verifies that serialization of a rule with composite trigger does not fail on * org.drools.core.time.impl.CompositeMaxDurationTrigger class serialization. + * @param kieBaseTestConfiguration */ - @Test - public void testSerializationAndDeserialization() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testSerializationAndDeserialization(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception { + prepare(kieBaseTestConfiguration); this.ksession.insert(new StockTick(2, "AAA", 1.0, 0)); this.ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true, false); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DroolsGcCausesNPETest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DroolsGcCausesNPETest.java index cf918036098..89fff39cdcc 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DroolsGcCausesNPETest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DroolsGcCausesNPETest.java @@ -22,10 +22,9 @@ import java.util.Random; import java.util.concurrent.TimeUnit; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.KieFileSystem; @@ -40,7 +39,6 @@ import org.kie.api.runtime.KieSessionConfiguration; import org.kie.api.runtime.conf.ClockTypeOption; import org.kie.api.time.SessionPseudoClock; -import org.kie.test.testcategory.TurtleTestCategory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,7 +64,7 @@ public class DroolsGcCausesNPETest { private SessionPseudoClock clock; private FactType eventFactType; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { final KieModuleModel module = SERVICES.newKieModuleModel(); @@ -88,7 +86,7 @@ public static void beforeClass() throws Exception { SERVICES.getRepository().addKieModule(builder.getKieModule()); } - @Before + @BeforeEach public void setUp() throws Exception { final KieSessionConfiguration conf = SERVICES.newKieSessionConfiguration(); conf.setOption(ClockTypeOption.PSEUDO); @@ -105,7 +103,6 @@ public void setUp() throws Exception { * BZ 1181584 */ @Test - @Category(TurtleTestCategory.class) public void testMoreTimesRepeated() throws Exception { final Random r = new Random(1); int i = 0; diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EscapesInMetadataTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EscapesInMetadataTest.java index b1ab477b5ff..eaa192f70ca 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EscapesInMetadataTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EscapesInMetadataTest.java @@ -18,17 +18,15 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; import java.util.Map; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +37,6 @@ * Test to verify BRMS-312 (Allow escaping characters in metadata value) is * fixed */ -@RunWith(Parameterized.class) public class EscapesInMetadataTest { private static final Logger LOGGER = LoggerFactory.getLogger(EscapesInMetadataTest.class); @@ -48,19 +45,13 @@ public class EscapesInMetadataTest { private static final String RULE_KEY = "output"; private static final String RULE_VALUE = "Hello world!"; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public EscapesInMetadataTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameters - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testMetadataEscapes() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testMetadataEscapes(KieBaseTestConfiguration kieBaseTestConfiguration) { final String rule = "package " + TestConstants.PACKAGE_REGRESSION + "\n" + " rule \"" + RULE_NAME + "\"\n" + " @" + RULE_KEY + "(\"\\\""+ RULE_VALUE + "\\\"\")\n" diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EventDeserializationInPastTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EventDeserializationInPastTest.java index 6772d48e886..eb36ad6c289 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EventDeserializationInPastTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EventDeserializationInPastTest.java @@ -26,7 +26,7 @@ import org.drools.core.ClockType; import org.drools.core.impl.RuleBaseFactory; import org.drools.core.time.impl.PseudoClockScheduler; -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-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EventFactHandleDeserializationTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EventFactHandleDeserializationTest.java index 269b4b20e99..0738cfd8f12 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EventFactHandleDeserializationTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EventFactHandleDeserializationTest.java @@ -20,8 +20,8 @@ import org.assertj.core.api.SoftAssertions; import org.drools.core.common.DefaultFactHandle; +import org.junit.jupiter.api.Test; import org.drools.core.common.DefaultEventHandle; -import org.junit.Test; import org.kie.api.io.ResourceType; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FixedPatternTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FixedPatternTest.java index 326dc004c05..c64b72e457b 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FixedPatternTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FixedPatternTest.java @@ -19,17 +19,16 @@ package org.drools.testcoverage.regression; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.AfterEach; +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.io.Resource; @@ -40,23 +39,15 @@ /** * Test for BZ 1150308. */ -@RunWith(Parameterized.class) public class FixedPatternTest { private KieSession ksession; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public FixedPatternTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @After + @AfterEach public void cleanup() { if (this.ksession != null) { this.ksession.dispose(); @@ -65,9 +56,11 @@ public void cleanup() { /** * Tests fixed pattern without constraint in Decision table (BZ 1150308). + * @param kieBaseTestConfiguration */ - @Test - public void testFixedPattern() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testFixedPattern(KieBaseTestConfiguration kieBaseTestConfiguration) { final Resource resource = KieServices.Factory.get().getResources().newClassPathResource("fixedPattern.drl.xls", getClass()); final KieBuilder kbuilder = KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, true, resource); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FromGenericCollectionTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FromGenericCollectionTest.java index fcb1b32925b..d05020b503e 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FromGenericCollectionTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FromGenericCollectionTest.java @@ -18,41 +18,32 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.runtime.ClassObjectFilter; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(Parameterized.class) public class FromGenericCollectionTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public FromGenericCollectionTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameters - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testGenerics() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testGenerics(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "package " + TestConstants.PACKAGE_REGRESSION + "\n" + " import java.util.Map.Entry\n" diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FusionAfterBeforeTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FusionAfterBeforeTest.java index 65fed9548a2..8409a4ecb50 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FusionAfterBeforeTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FusionAfterBeforeTest.java @@ -18,10 +18,10 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; import java.util.SortedSet; import java.util.TreeSet; import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; import org.drools.core.impl.RuleBaseFactory; import org.drools.testcoverage.common.listener.TrackingAgendaEventListener; @@ -33,11 +33,10 @@ import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.Timeout; +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.io.Resource; @@ -55,22 +54,15 @@ * Test to verify BRMS-582 (use of 'after' and 'before' operators ends with NPE) * is fixed. */ -@RunWith(Parameterized.class) public class FusionAfterBeforeTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public FusionAfterBeforeTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameters - public static Collection getParameters() { - return TestParametersUtil.getKieBaseStreamConfigurations(true); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseStreamConfigurations(true).stream(); } - @Test - public void testAfterBeforeOperators() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testAfterBeforeOperators(KieBaseTestConfiguration kieBaseTestConfiguration) { final Resource drlResource = KieServices.Factory.get().getResources().newClassPathResource("fusionAfterBeforeTest.drl", getClass()); final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromResources(TestConstants.PACKAGE_REGRESSION, @@ -112,8 +104,10 @@ public void testAfterBeforeOperators() { + firedCount + " time(s)!").isEqualTo(actuallyFired); } - @Test(timeout = 10000) - public void testExpireEventsWhenSharingAllRules() throws InstantiationException, IllegalAccessException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + @Timeout(10000) + public void testExpireEventsWhenSharingAllRules(KieBaseTestConfiguration kieBaseTestConfiguration) throws InstantiationException, IllegalAccessException { final StringBuilder drlBuilder = new StringBuilder(); for (int i = 0; i < 64; i++) { drlBuilder.append(" import " + EventA.class.getCanonicalName() + ";\n"); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/GenericsWithModifyTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/GenericsWithModifyTest.java index 8a49cee936a..05b4981c4db 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/GenericsWithModifyTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/GenericsWithModifyTest.java @@ -18,16 +18,14 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.AfterEach; +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.runtime.KieContainer; @@ -36,7 +34,6 @@ /** * Tests generics in RHS with modify - BZ 1142886. */ -@RunWith(Parameterized.class) public class GenericsWithModifyTest { private static final String DRL = @@ -52,26 +49,11 @@ public class GenericsWithModifyTest { private KieSession kieSession; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public GenericsWithModifyTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Before - public void initialize() { - final KieBuilder kbuilder = KieUtil.getKieBuilderFromDrls(kieBaseTestConfiguration, true, DRL); - - final KieContainer kieContainer = KieServices.Factory.get().newKieContainer(kbuilder.getKieModule().getReleaseId()); - this.kieSession = kieContainer.newKieSession(); - } - - @After + @AfterEach public void dispose() { if (this.kieSession != null) { this.kieSession.dispose(); @@ -81,8 +63,13 @@ public void dispose() { /** * Tests generics on rule's RHS with modify. */ - @Test - public void testModifyWithGenericsOnRHS() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testModifyWithGenericsOnRHS(KieBaseTestConfiguration kieBaseTestConfiguration) { + final KieBuilder kbuilder = KieUtil.getKieBuilderFromDrls(kieBaseTestConfiguration, true, DRL); + + final KieContainer kieContainer = KieServices.Factory.get().newKieContainer(kbuilder.getKieModule().getReleaseId()); + this.kieSession = kieContainer.newKieSession(); this.kieSession.insert("1"); this.kieSession.fireAllRules(); } diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/ImportReplaceTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/ImportReplaceTest.java index 70264fa75ab..ed44e60bbb1 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/ImportReplaceTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/ImportReplaceTest.java @@ -20,18 +20,17 @@ import java.io.StringReader; -import java.util.Collection; +import java.util.stream.Stream; + import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieServices; import org.kie.api.io.Resource; -@RunWith(Parameterized.class) public class ImportReplaceTest { private static final String declares = @@ -59,19 +58,13 @@ public class ImportReplaceTest { + " insert(new Holder(person));\n" + "end\n"; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public ImportReplaceTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void test() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void test(KieBaseTestConfiguration kieBaseTestConfiguration) { final Resource declaresResource = KieServices.Factory.get().getResources().newReaderResource(new StringReader(declares)); declaresResource.setTargetPath("src/main/resources/declares.drl"); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/InaccurateComparisonTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/InaccurateComparisonTest.java index d03f8026d66..fbd41ddd06a 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/InaccurateComparisonTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/InaccurateComparisonTest.java @@ -18,17 +18,15 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.model.Message; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.runtime.KieSession; @@ -37,22 +35,15 @@ /** * Tests problems with large numbers to String conversion. See DROOLS-167. */ -@RunWith(Parameterized.class) public class InaccurateComparisonTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public InaccurateComparisonTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameters - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testStringCoercionComparison() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testStringCoercionComparison(KieBaseTestConfiguration kieBaseTestConfiguration) { final String rule = "package " + TestConstants.PACKAGE_REGRESSION + "\n" + " import " + TestConstants.PACKAGE_TESTCOVERAGE_MODEL + ".Message;\n" + " rule \"string coercion\" \n" + diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SerializationWithCollectTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SerializationWithCollectTest.java index 440e889df2f..f171707ae51 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SerializationWithCollectTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SerializationWithCollectTest.java @@ -21,9 +21,9 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -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.api.Test; import org.kie.api.KieBase; import org.kie.api.io.ResourceType; import org.kie.api.marshalling.Marshaller; @@ -50,13 +50,13 @@ public class SerializationWithCollectTest { private KieBase kbase; private KieSession ksession; - @Before + @BeforeEach public void setup() { this.kbase = new KieHelper().addContent(DRL, ResourceType.DRL).build(); this.ksession = kbase.newKieSession(); } - @After + @AfterEach public void cleanup() { if (this.ksession != null) { this.ksession.dispose(); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/TruthMaintenanceSystemConcurrencyTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/TruthMaintenanceSystemConcurrencyTest.java index 83ee2daddb2..5f0b9f9b0df 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/TruthMaintenanceSystemConcurrencyTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/TruthMaintenanceSystemConcurrencyTest.java @@ -29,7 +29,7 @@ import org.drools.kiesession.rulebase.KnowledgeBaseFactory; import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; import org.drools.mvel.compiler.Cheese; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.definition.KiePackage; import org.kie.api.io.ResourceType; import org.kie.api.runtime.ClassObjectFilter; diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/UnwantedStringConversionTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/UnwantedStringConversionTest.java index 8e6e206ee91..e30919d5604 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/UnwantedStringConversionTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/UnwantedStringConversionTest.java @@ -18,17 +18,15 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.listener.TrackingAgendaEventListener; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.drools.testcoverage.common.util.TestParametersUtil2; +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.io.Resource; @@ -38,23 +36,16 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(Parameterized.class) public class UnwantedStringConversionTest { private static final Logger LOGGER = LoggerFactory.getLogger(UnwantedStringConversionTest.class); - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public UnwantedStringConversionTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameters - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testStringToDecimalConversion() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testStringToDecimalConversion(KieBaseTestConfiguration kieBaseTestConfiguration) { final Resource drlResource = KieServices.Factory.get().getResources().newClassPathResource("unwantedStringConversionTest.drl", getClass()); final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromResources(TestConstants.PACKAGE_REGRESSION, diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/XSDResourceTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/XSDResourceTest.java index 3818ecd5e8c..62efcb7181d 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/XSDResourceTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/XSDResourceTest.java @@ -18,12 +18,13 @@ */ package org.drools.testcoverage.regression; -import org.junit.Test; import org.kie.api.KieServices; import org.kie.api.runtime.KieContainer; import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.Test; + /** * Tests KIE package compilation when there is a XSD resource (BZ 1120972). */ diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/mvel/MvelLinkageErrorTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/mvel/MvelLinkageErrorTest.java index 1bf15cce662..65b06e34867 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/mvel/MvelLinkageErrorTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/mvel/MvelLinkageErrorTest.java @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieFileSystem; import org.kie.api.runtime.KieSession; From 022022f8545852bfcd11a6fec184cc90f1b5ac8c Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Tue, 19 Nov 2024 16:48:12 +0100 Subject: [PATCH 3/6] Migrated tests to Junit5 --- .../functional/DecisionTableTest.java | 123 ++++++++++-------- .../functional/DeclarativeAgendaTest.java | 21 ++- .../functional/DuplicityTest.java | 26 ++-- .../functional/FactHandleTest.java | 28 ++-- .../functional/InternalMatchGroupTest.java | 54 ++++---- .../functional/KieContainerDefaultsTest.java | 6 +- .../functional/KieContainerTest.java | 6 +- .../functional/KieRepositoryTest.java | 6 +- .../functional/LiveQueriesBadResultTest.java | 46 +++---- .../LogicalInsertFromCollectionTest.java | 44 +++---- .../functional/QueryBadResultTest.java | 49 ++++--- .../functional/ResourcesTest.java | 51 ++++---- .../functional/RuleTemplateTest.java | 25 ++-- .../functional/TemplatesTest.java | 87 +++++++------ .../testcoverage/functional/UnicodeTest.java | 54 ++++---- .../DecisionTableKieContainerTest.java | 2 +- .../functional/model/RulesWithInTest.java | 2 +- ...serializationWithCompositeTriggerTest.java | 1 - .../regression/FixedPatternTest.java | 1 - .../MultipleKieBaseListenersTest.java | 27 ++-- .../regression/MultipleSheetsLoadingTest.java | 29 ++--- .../regression/NonStringCompareTest.java | 48 +++---- .../regression/NullInListInFromTest.java | 26 ++-- .../regression/POJOAnnotationMergeTest.java | 26 ++-- .../regression/PropertyListenerTest.java | 26 ++-- .../SerializableGeneratedTypesTest.java | 27 ++-- .../SessionInsertMultiThreadingTest.java | 47 +++---- 27 files changed, 400 insertions(+), 488 deletions(-) diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/DecisionTableTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/DecisionTableTest.java index 369338df410..973e9464049 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/DecisionTableTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/DecisionTableTest.java @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.stream.Stream; import org.drools.template.parser.DecisionTableParseException; import org.drools.testcoverage.common.listener.OrderListener; @@ -34,11 +35,10 @@ import org.drools.testcoverage.common.util.KieUtil; import org.drools.testcoverage.common.util.ResourceUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.definition.KiePackage; import org.kie.api.definition.type.FactType; @@ -48,22 +48,15 @@ import org.kie.internal.builder.DecisionTableInputType; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * Tests all features which can be used in decision tables. */ -@RunWith(Parameterized.class) public class DecisionTableTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public DecisionTableTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } private static Resource sampleXlsDecisionTable; @@ -92,7 +85,7 @@ public static Collection getParameters() { private static Resource sampleDateXLSXDecisionTable; - @BeforeClass + @BeforeAll public static void loadDecisionTablesToAvoidLoadingThemForEachKieBaseConfiguration() { sampleXlsDecisionTable = ResourceUtil.getDecisionTableResourceFromClasspath("sample.drl.xls", DecisionTableTest.class, @@ -148,17 +141,19 @@ public static void loadDecisionTablesToAvoidLoadingThemForEachKieBaseConfigurati } - @Test - public void testSimpleXLS() { - testSimpleDecisionTable(sampleXlsDecisionTable); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testSimpleXLS(KieBaseTestConfiguration kieBaseTestConfiguration) { + testSimpleDecisionTable(kieBaseTestConfiguration, sampleXlsDecisionTable); } - @Test - public void testSimpleCSV() { - testSimpleDecisionTable(sampleCsvDecisionTable); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testSimpleCSV(KieBaseTestConfiguration kieBaseTestConfiguration) { + testSimpleDecisionTable(kieBaseTestConfiguration, sampleCsvDecisionTable); } - private void testSimpleDecisionTable(final Resource decisionTable) { + private void testSimpleDecisionTable(KieBaseTestConfiguration kieBaseTestConfiguration, final Resource decisionTable) { final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, decisionTable); final KieSession session = kbase.newKieSession(); @@ -177,8 +172,9 @@ private void testSimpleDecisionTable(final Resource decisionTable) { session.dispose(); } - @Test - public void testMultipleTableXLS() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testMultipleTableXLS(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, multipleTablesDecisionTable); assertThat(2).isEqualTo(kbase.getKiePackages().size()); @@ -214,8 +210,9 @@ public void testMultipleTableXLS() { * test for various evaluations, file sample_eval_dt.xls need to rewrite xls * table and maybe add some classes to be able to do the test */ - @Test - public void testEvalTable() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testEvalTable(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, evalDecisionTable); assertThat(2).isEqualTo(kbase.getKiePackages().size()); @@ -316,8 +313,9 @@ public void testEvalTable() { * covers also bugfix for Bug724257 (agenda group not added from dtable to * .drl) */ - @Test - public void testAdvancedTable() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testAdvancedTable(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, advancedDecisionTable); KieSession session = kbase.newKieSession(); @@ -343,8 +341,9 @@ public void testAdvancedTable() { session.dispose(); } - @Test - public void testPushQueryWithFactDeclaration() throws IllegalAccessException, InstantiationException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testPushQueryWithFactDeclaration(KieBaseTestConfiguration kieBaseTestConfiguration) throws IllegalAccessException, InstantiationException { final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, queriesDecisionTable); final FactType locationType = kbase.getFactType(TestConstants.PACKAGE_FUNCTIONAL, "Location"); @@ -401,8 +400,9 @@ public void testPushQueryWithFactDeclaration() throws IllegalAccessException, In ksession.dispose(); } - @Test - public void testPullQueryWithFactDeclaration() throws IllegalAccessException, InstantiationException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testPullQueryWithFactDeclaration(KieBaseTestConfiguration kieBaseTestConfiguration) throws IllegalAccessException, InstantiationException { final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, queriesDecisionTable); final FactType locationType = kbase.getFactType(TestConstants.PACKAGE_FUNCTIONAL, "Location"); @@ -462,8 +462,9 @@ public void testPullQueryWithFactDeclaration() throws IllegalAccessException, In /** * Test sequential turned on, it overrides all user defined saliences. */ - @Test - public void testSequential() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testSequential(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, sequentialDecisionTable); final KieSession ksession = kbase.newKieSession(); @@ -479,8 +480,9 @@ public void testSequential() { ksession.dispose(); } - @Test - public void testLockOnActive() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testLockOnActive(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, agendaGroupDecisionTable); final KieSession ksession = kbase.newKieSession(); final OrderListener listener = new OrderListener(); @@ -499,8 +501,9 @@ public void testLockOnActive() { * Agenda group rule with auto focus can fire a give focus to agenda group * without focus set on whole agenda group. */ - @Test - public void testAutoFocus() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testAutoFocus(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, agendaGroupDecisionTable); final KieSession ksession = kbase.newKieSession(); final OrderListener listener = new OrderListener(); @@ -527,8 +530,9 @@ public void testAutoFocus() { ksession.dispose(); } - @Test - public void testActivationGroup() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testActivationGroup(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, agendaGroupDecisionTable); final KieSession ksession = kbase.newKieSession(); final TrackingAgendaEventListener listener = new TrackingAgendaEventListener(); @@ -543,27 +547,33 @@ public void testActivationGroup() { ksession.dispose(); } - @Test(expected = DecisionTableParseException.class) - public void testEmptyConditionInXLS() { - KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, true, emptyConditionDecisionTable); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testEmptyConditionInXLS(KieBaseTestConfiguration kieBaseTestConfiguration) { + assertThatExceptionOfType(DecisionTableParseException.class).isThrownBy(() -> + KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, true, emptyConditionDecisionTable)); } - @Test(expected = DecisionTableParseException.class) - public void testEmptyActionInCSV() { - KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, true, emptyActionDecisionTable); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testEmptyActionInCSV(KieBaseTestConfiguration kieBaseTestConfiguration) { + assertThatExceptionOfType(DecisionTableParseException.class).isThrownBy(() -> + KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, true, emptyActionDecisionTable)); } - @Test - public void testCSVWithDateAttributes() { - testDecisionTableWithDateAttributes(sampleDatesCsvDecisionTable); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testCSVWithDateAttributes(KieBaseTestConfiguration kieBaseTestConfiguration) { + testDecisionTableWithDateAttributes(kieBaseTestConfiguration, sampleDatesCsvDecisionTable); } - @Test - public void testXLSWithDateAttributes() { - testDecisionTableWithDateAttributes(sampleDatesXlsDecisionTable); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testXLSWithDateAttributes(KieBaseTestConfiguration kieBaseTestConfiguration) { + testDecisionTableWithDateAttributes(kieBaseTestConfiguration, sampleDatesXlsDecisionTable); } - private void testDecisionTableWithDateAttributes(final Resource decisionTable) { + private void testDecisionTableWithDateAttributes(KieBaseTestConfiguration kieBaseTestConfiguration, final Resource decisionTable) { final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, decisionTable); final ArrayList names = new ArrayList<>(); @@ -595,8 +605,9 @@ public void setDate(Date date) { } - @Test - public void testXLSXComparingDates() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testXLSXComparingDates(KieBaseTestConfiguration kieBaseTestConfiguration) { // DROOLS-6820 KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, sampleDateXLSXDecisionTable); KieSession ksession = kbase.newKieSession(); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/DeclarativeAgendaTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/DeclarativeAgendaTest.java index a49b4e7f995..4ce2e9298c8 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/DeclarativeAgendaTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/DeclarativeAgendaTest.java @@ -25,7 +25,8 @@ import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.kie.api.KieBase; import org.kie.api.KieBaseConfiguration; import org.kie.api.KieServices; @@ -46,7 +47,8 @@ public class DeclarativeAgendaTest { // rule activation is blocked and after several iterations (fireAllRules) it // is unblocked and the rule fires - @Test(timeout = 10000L) + @Test + @Timeout(10000L) public void testSimpleActivationBlock() { final KieBase kbase = buildKieBase("declarative-agenda-simple-block.drl"); final KieSession ksession = kbase.newKieSession(); @@ -107,7 +109,8 @@ public void testSimpleActivationBlock() { // test activation block together with agenda group // BZ 999360 - @Test(timeout = 10000L) + @Test + @Timeout(10000L) public void testActivationBlock() { final KieBase kbase = buildKieBase("declarative-agenda-block.drl"); final KieSession ksession = kbase.newKieSession(); @@ -144,7 +147,8 @@ public void testActivationBlock() { } // test activation count, test case from doc - @Test(timeout = 10000L) + @Test + @Timeout(10000L) public void testActivationCount() { final KieBase kbase = buildKieBase("declarative-agenda-count.drl"); final KieSession ksession = kbase.newKieSession(); @@ -171,7 +175,8 @@ public void testActivationCount() { } // testing unblockall command - @Test(timeout = 10000L) + @Test + @Timeout(10000L) public void testUnblockAll() { final KieBase kbase = buildKieBase("declarative-agenda-unblockall.drl"); final KieSession ksession = kbase.newKieSession(); @@ -202,7 +207,8 @@ public void testUnblockAll() { ksession.dispose(); } - @Test(timeout = 10000L) + @Test + @Timeout(10000L) public void testSimpleCancel() { final KieBase kbase = buildKieBase("declarative-agenda-cancel.drl"); final KieSession ksession = kbase.newKieSession(); @@ -229,7 +235,8 @@ public void testSimpleCancel() { // working memory // but activationListener('direct') annotation should guarantee priority to // fire - @Test(timeout = 10000L) + @Test + @Timeout(10000L) public void testCancelWithUpdatingFacts() { final KieBase kbase = buildKieBase("declarative-agenda-cancel.drl"); final KieSession ksession = kbase.newKieSession(); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/DuplicityTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/DuplicityTest.java index 9807d06c6ea..e9b4730a2e5 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/DuplicityTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/DuplicityTest.java @@ -18,14 +18,13 @@ */ package org.drools.testcoverage.functional; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieServices; import org.kie.api.io.Resource; import org.slf4j.LoggerFactory; @@ -36,22 +35,15 @@ * Testing of duplicities in rule files. * https://bugzilla.redhat.com/show_bug.cgi?id=724753 */ -@RunWith(Parameterized.class) public class DuplicityTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public DuplicityTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testTwoRulesWithSameNameInOneFile() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTwoRulesWithSameNameInOneFile(KieBaseTestConfiguration kieBaseTestConfiguration) { try { final Resource resource = KieServices.Factory.get().getResources().newClassPathResource("rule-name.drl", getClass()); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/FactHandleTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/FactHandleTest.java index 34248d39c77..44e2ad34572 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/FactHandleTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/FactHandleTest.java @@ -19,42 +19,32 @@ package org.drools.testcoverage.functional; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.core.common.InternalFactHandle; import org.drools.core.event.DefaultRuleRuntimeEventListener; import org.drools.testcoverage.common.model.Cheese; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.event.rule.ObjectInsertedEvent; import org.kie.api.runtime.KieSession; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(Parameterized.class) public class FactHandleTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public FactHandleTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseCloudConfigurations(true); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseCloudConfigurations(true).stream(); } - - - @Test - public void testFactHandleSequence() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testFactHandleSequence(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception { String drlString = "package org.jboss.brms\n" + "import " + Cheese.class.getCanonicalName() + ";\n" + "rule \"FactHandleId\"\n" + diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/InternalMatchGroupTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/InternalMatchGroupTest.java index eb8752ac038..da3bd9d57b4 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/InternalMatchGroupTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/InternalMatchGroupTest.java @@ -19,17 +19,16 @@ package org.drools.testcoverage.functional; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.testcoverage.common.listener.TrackingAgendaEventListener; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +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.command.Command; @@ -38,59 +37,56 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(Parameterized.class) public class InternalMatchGroupTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - public InternalMatchGroupTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } /** * Only one rule from activation group fires. */ - @Test - public void basicTestActivationGroup() { - TrackingAgendaEventListener listener = prepareKSession("basicActivationGroup"); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void basicTestActivationGroup(KieBaseTestConfiguration kieBaseTestConfiguration) { + TrackingAgendaEventListener listener = prepareKSession(kieBaseTestConfiguration, "basicActivationGroup"); assertThat(listener.isRuleFired("basic1")).isFalse(); assertThat(listener.isRuleFired("basic2")).isTrue(); assertThat(listener.isRuleFired("basic3")).isFalse(); } - @Test - public void recursiveTestActivationGroup() { - TrackingAgendaEventListener listener = prepareKSession("recursiveActivationGroup"); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void recursiveTestActivationGroup(KieBaseTestConfiguration kieBaseTestConfiguration) { + TrackingAgendaEventListener listener = prepareKSession(kieBaseTestConfiguration, "recursiveActivationGroup"); assertThat(listener.isRuleFired("simplyRecursive1")).isFalse(); assertThat(listener.isRuleFired("simplyRecursive2")).isTrue(); assertThat(listener.isRuleFired("simplyRecursive3")).isTrue(); } - @Test - public void testActivationGroupWithDefaultSalience() { - TrackingAgendaEventListener listener = prepareKSession("defaultSalienceActivationGroup"); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testActivationGroupWithDefaultSalience(KieBaseTestConfiguration kieBaseTestConfiguration) { + TrackingAgendaEventListener listener = prepareKSession(kieBaseTestConfiguration, "defaultSalienceActivationGroup"); assertThat(listener.rulesCount()).isEqualTo(1); } - @Test - public void testActivationGroupRecursivelyWithDefaultSalience() { - TrackingAgendaEventListener listener = prepareKSession("defaultSalienceWithRecursion"); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testActivationGroupRecursivelyWithDefaultSalience(KieBaseTestConfiguration kieBaseTestConfiguration) { + TrackingAgendaEventListener listener = prepareKSession(kieBaseTestConfiguration, "defaultSalienceWithRecursion"); assertThat(listener.rulesCount()).isEqualTo(2); } - private TrackingAgendaEventListener prepareKSession(String startingRule) { + private TrackingAgendaEventListener prepareKSession(KieBaseTestConfiguration kieBaseTestConfiguration, String startingRule) { List> commands = new ArrayList>(); TrackingAgendaEventListener listener = new TrackingAgendaEventListener(); - final KieSession ksession = getKieBaseForTest().newKieSession(); + final KieSession ksession = getKieBaseForTest(kieBaseTestConfiguration).newKieSession(); try { ksession.addEventListener(listener); @@ -102,7 +98,7 @@ private TrackingAgendaEventListener prepareKSession(String startingRule) { return listener; } - private KieBase getKieBaseForTest() { + private KieBase getKieBaseForTest(KieBaseTestConfiguration kieBaseTestConfiguration) { final Resource drlResource = KieServices.Factory.get().getResources().newClassPathResource("activation-group.drl", getClass()); return KieBaseUtil.getKieBaseFromKieModuleFromResources(TestConstants.PACKAGE_FUNCTIONAL, diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/KieContainerDefaultsTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/KieContainerDefaultsTest.java index ac8069390d9..a17ebb12d69 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/KieContainerDefaultsTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/KieContainerDefaultsTest.java @@ -22,8 +22,8 @@ import org.drools.core.impl.InternalKieContainer; import org.drools.testcoverage.common.util.TestConstants; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; @@ -53,7 +53,7 @@ public class KieContainerDefaultsTest { private KieServices kieServices; - @Before + @BeforeEach public void initialize() throws IOException { kieServices = KieServices.Factory.get(); } diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/KieContainerTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/KieContainerTest.java index 70fa0601986..529f23283fd 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/KieContainerTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/KieContainerTest.java @@ -23,8 +23,8 @@ import java.util.Collection; import org.drools.testcoverage.common.util.TestConstants; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.kie.api.KieBase; import org.kie.api.KieBaseConfiguration; import org.kie.api.KieServices; @@ -58,7 +58,7 @@ public class KieContainerTest { private KieServices kieServices; - @Before + @BeforeEach public void initialize() throws IOException { kieServices = KieServices.Factory.get(); } diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/KieRepositoryTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/KieRepositoryTest.java index 970bfaf245e..5da18a0b326 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/KieRepositoryTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/KieRepositoryTest.java @@ -21,8 +21,8 @@ import java.io.IOException; import org.drools.testcoverage.common.util.TestConstants; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.KieFileSystem; @@ -45,7 +45,7 @@ public class KieRepositoryTest { private static final String DRL = "package defaultKBase;\n rule testRule when then end\n"; - @Before + @BeforeEach public void initialize() throws IOException { kieServices = KieServices.Factory.get(); } diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/LiveQueriesBadResultTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/LiveQueriesBadResultTest.java index 8a1636bd831..da0ea75919c 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/LiveQueriesBadResultTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/LiveQueriesBadResultTest.java @@ -19,17 +19,16 @@ package org.drools.testcoverage.functional; import java.util.ArrayList; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.model.Person; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +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.runtime.rule.Row; @@ -40,32 +39,25 @@ /** * Tests bad using and accessing to livequeries. */ -@RunWith(Parameterized.class) public class LiveQueriesBadResultTest { private ArrayList inserted, updated, deleted; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public LiveQueriesBadResultTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Before + @BeforeEach public void initialize() { inserted = new ArrayList<>(); updated = new ArrayList<>(); deleted = new ArrayList<>(); } - @Ignore("TODO - check correct exception in this test when DROOLS-2186 is fixed.") - @Test - public void testCallingLiveQueryWithoutParametersButItHasParams() { + @Disabled("TODO - check correct exception in this test when DROOLS-2186 is fixed.") + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testCallingLiveQueryWithoutParametersButItHasParams(KieBaseTestConfiguration kieBaseTestConfiguration) { final ViewChangedEventListener listener = new ViewChangedEventListener() { @@ -93,8 +85,9 @@ public void rowDeleted(Row row) { ksession.openLiveQuery("queryWithParams", new Object[] {}, listener); } - @Test - public void testAccessToNotExistingVariable() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testAccessToNotExistingVariable(KieBaseTestConfiguration kieBaseTestConfiguration) { ViewChangedEventListener listener = new ViewChangedEventListener() { @@ -125,9 +118,10 @@ public void rowDeleted(Row row) { .hasMessage("The identifier 'bad' does not exist as a bound variable for this query"); } - @Ignore("TODO - check correct exception in this test when DROOLS-2187 is fixed.") - @Test - public void testOfBadParameters() { + @Disabled("TODO - check correct exception in this test when DROOLS-2187 is fixed.") + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testOfBadParameters(KieBaseTestConfiguration kieBaseTestConfiguration) { ViewChangedEventListener listener = new ViewChangedEventListener() { diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/LogicalInsertFromCollectionTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/LogicalInsertFromCollectionTest.java index eeb15d1c0ed..302db8067d3 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/LogicalInsertFromCollectionTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/LogicalInsertFromCollectionTest.java @@ -20,16 +20,15 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.model.SimplePerson; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.drools.testcoverage.common.util.TestParametersUtil2; +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.io.Resource; @@ -43,23 +42,16 @@ * its elements, than changes the collection in program and checks the correct * changes. */ -@RunWith(Parameterized.class) public class LogicalInsertFromCollectionTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public LogicalInsertFromCollectionTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameters - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testRemoveElement() { - final KieSession ksession = getKieBaseForTest().newKieSession(); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testRemoveElement(KieBaseTestConfiguration kieBaseTestConfiguration) { + final KieSession ksession = getKieBaseForTest(kieBaseTestConfiguration).newKieSession(); final Collection collection = new ArrayList(); for (int i = 0; i < 4; i++) { @@ -83,9 +75,10 @@ public void testRemoveElement() { } - @Test - public void testAddElement() { - final KieSession ksession = getKieBaseForTest().newKieSession(); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testAddElement(KieBaseTestConfiguration kieBaseTestConfiguration) { + final KieSession ksession = getKieBaseForTest(kieBaseTestConfiguration).newKieSession(); final Collection collection = new ArrayList(); @@ -107,9 +100,10 @@ public void testAddElement() { assertThat(ksession.getFactCount()).isEqualTo(6); } - @Test - public void testChangeElement() { - final KieSession ksession = getKieBaseForTest().newKieSession(); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testChangeElement(KieBaseTestConfiguration kieBaseTestConfiguration) { + final KieSession ksession = getKieBaseForTest(kieBaseTestConfiguration).newKieSession(); final Collection collection = new ArrayList<>(); @@ -138,7 +132,7 @@ public void testChangeElement() { } - private KieBase getKieBaseForTest() { + private KieBase getKieBaseForTest(KieBaseTestConfiguration kieBaseTestConfiguration) { final Resource drlResource = KieServices.Factory.get().getResources().newClassPathResource("logicalInsertFromCollectionTest.drl", getClass()); return KieBaseUtil.getKieBaseFromKieModuleFromResources(TestConstants.PACKAGE_REGRESSION, diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/QueryBadResultTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/QueryBadResultTest.java index 55958bf9bc1..7fa6b7aac4f 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/QueryBadResultTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/QueryBadResultTest.java @@ -18,16 +18,15 @@ */ package org.drools.testcoverage.functional; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.model.Person; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.Message.Level; @@ -35,34 +34,29 @@ import org.kie.api.runtime.rule.QueryResults; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.fail; /** * Tests bad using and accessing to queries. */ -@RunWith(Parameterized.class) public class QueryBadResultTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public QueryBadResultTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testQueriesWithSameNameInOneFile() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testQueriesWithSameNameInOneFile(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBuilder kieBuilder = KieUtil.getKieBuilderFromClasspathResources(kieBaseTestConfiguration, getClass(), false, "query-two-same-names.drl"); assertThat(kieBuilder.getResults().getMessages(Level.ERROR).isEmpty()).isFalse(); } - @Test - public void testQueriesWithSameNameInTwoFiles() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testQueriesWithSameNameInTwoFiles(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBuilder kieBuilder = KieUtil.getKieBuilderFromClasspathResources( kieBaseTestConfiguration, @@ -74,15 +68,17 @@ public void testQueriesWithSameNameInTwoFiles() { assertThat(kieBuilder.getResults().getMessages(Level.ERROR).isEmpty()).isFalse(); } - @Test - public void testQueryWithoutName() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testQueryWithoutName(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBuilder kieBuilder = KieUtil.getKieBuilderFromClasspathResources(kieBaseTestConfiguration, getClass(), false, "query-without-name.drl"); assertThat(kieBuilder.getResults().getMessages(Level.ERROR).isEmpty()).isFalse(); } - @Test - public void testQueryCalledWithoutParamsButItHasParams() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testQueryCalledWithoutParamsButItHasParams(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBase kieBase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "query.drl"); final KieSession ksession = kieBase.newKieSession(); ksession.insert(new Person("Petr")); @@ -95,13 +91,14 @@ public void testQueryCalledWithoutParamsButItHasParams() { } } - @Test(expected = IllegalArgumentException.class) - public void testAccessToNotExistingVariable() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testAccessToNotExistingVariable(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBase kieBase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration,"query.drl"); final KieSession ksession = kieBase.newKieSession(); ksession.insert(new Person("Petr")); final QueryResults results = ksession.getQueryResults("simple query with no parameters"); - results.iterator().next().get("bad"); + assertThatIllegalArgumentException().isThrownBy(() -> results.iterator().next().get("bad")); } } diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/ResourcesTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/ResourcesTest.java index cf8603c11e4..a042326508b 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/ResourcesTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/ResourcesTest.java @@ -19,17 +19,16 @@ package org.drools.testcoverage.functional; import java.io.StringReader; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.decisiontable.ExternalSpreadsheetCompiler; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.ResourceUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +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.definition.KiePackage; @@ -43,22 +42,15 @@ * Tests loading of different types of resources (DRL, DSL, DRF, BPMN2, DTABLE). * Packages are loaded and built using KnowledgeBuilder. */ -@RunWith(Parameterized.class) public class ResourcesTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public ResourcesTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testDRL() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testDRL(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "aggregation.drl"); @@ -70,8 +62,9 @@ public void testDRL() { verifyPackageWithImports(kbase, TestConstants.PACKAGE_TESTCOVERAGE_MODEL); } - @Test - public void testDSL() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testDSL(KieBaseTestConfiguration kieBaseTestConfiguration) { // DSL must go before rules otherwise error is thrown during building final KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "sample.dsl", "sample.dslr"); @@ -80,8 +73,9 @@ public void testDSL() { verifyPackageWithRules(kbase, TestConstants.PACKAGE_FUNCTIONAL, 1); } - @Test - public void testXLS() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testXLS(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "sample.drl.xls"); @@ -91,8 +85,9 @@ public void testXLS() { verifyPackageWithImports(kbase, TestConstants.PACKAGE_TESTCOVERAGE_MODEL); } - @Test - public void testCSV() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testCSV(KieBaseTestConfiguration kieBaseTestConfiguration) { final Resource decisionTable = ResourceUtil.getDecisionTableResourceFromClasspath("sample.drl.csv", getClass(), DecisionTableInputType.CSV); final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, decisionTable); @@ -103,8 +98,9 @@ public void testCSV() { verifyPackageWithImports(kbase, TestConstants.PACKAGE_TESTCOVERAGE_MODEL); } - @Test - public void testRuleTemplate() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testRuleTemplate(KieBaseTestConfiguration kieBaseTestConfiguration) { // first we compile the decision table into a whole lot of rules. final ExternalSpreadsheetCompiler converter = new ExternalSpreadsheetCompiler(); @@ -124,8 +120,9 @@ public void testRuleTemplate() { verifyPackageWithImports(kbase, TestConstants.PACKAGE_TESTCOVERAGE_MODEL); } - @Test - public void testWrongExtension() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testWrongExtension(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "package org.drools.testcoverage.functional\n" + "import org.drools.testcoverage.common.model.Message\n" + "rule sampleRule\n" + diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/RuleTemplateTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/RuleTemplateTest.java index 79235ccaaa9..277e9967eb1 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/RuleTemplateTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/RuleTemplateTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.decisiontable.ExternalSpreadsheetCompiler; import org.drools.testcoverage.common.model.Cheese; @@ -30,10 +31,9 @@ import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +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.definition.KiePackage; @@ -44,24 +44,17 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(Parameterized.class) public class RuleTemplateTest { private static final Logger LOGGER = LoggerFactory.getLogger(RuleTemplateTest.class); - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public RuleTemplateTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testSampleCheese() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testSampleCheese(KieBaseTestConfiguration kieBaseTestConfiguration) { // first we compile the decision table into a whole lot of rules. final ExternalSpreadsheetCompiler converter = new ExternalSpreadsheetCompiler(); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/TemplatesTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/TemplatesTest.java index b94e49e572b..d08eaecd1af 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/TemplatesTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/TemplatesTest.java @@ -27,6 +27,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import org.drools.decisiontable.ExternalSpreadsheetCompiler; import org.drools.template.DataProviderCompiler; @@ -35,10 +36,10 @@ import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.Timeout; +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.definition.KiePackage; @@ -52,21 +53,13 @@ /** * Tests templates - providers, generating rules, performance. */ -@RunWith(Parameterized.class) public class TemplatesTest { private static final Logger LOGGER = LoggerFactory.getLogger(TemplatesTest.class); private static final StringBuffer EXPECTED_RULES = new StringBuffer(); - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public TemplatesTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } static { @@ -98,8 +91,9 @@ public static Collection getParameters() { EXPECTED_RULES.append(rule2_when).append(rule2_then); } - @Test - public void loadingFromDLRObjsCorrectnessCheck() throws IOException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void loadingFromDLRObjsCorrectnessCheck(KieBaseTestConfiguration kieBaseTestConfiguration) throws IOException { final KieServices kieServices = KieServices.Factory.get(); final Collection cfl = new ArrayList(); cfl.add(new ParamSet("tomato", "weight", 200, 1000, 6, EnumSet.of(Taste.GOOD, Taste.EXCELENT))); @@ -115,12 +109,13 @@ public void loadingFromDLRObjsCorrectnessCheck() throws IOException { assertEqualsIgnoreWhitespace(EXPECTED_RULES.toString(), drl); - testCorrectnessCheck(drl); + testCorrectnessCheck(kieBaseTestConfiguration, drl); } } - @Test - public void loadingFromDLRMapsCorrectnessCheck() throws IOException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void loadingFromDLRMapsCorrectnessCheck(KieBaseTestConfiguration kieBaseTestConfiguration) throws IOException { final KieServices kieServices = KieServices.Factory.get(); final ObjectDataCompiler converter = new ObjectDataCompiler(); @@ -132,12 +127,13 @@ public void loadingFromDLRMapsCorrectnessCheck() throws IOException { assertEqualsIgnoreWhitespace(EXPECTED_RULES.toString(), drl); - testCorrectnessCheck(drl); + testCorrectnessCheck(kieBaseTestConfiguration, drl); } } - @Test - public void loadingFromDLRArrayCorrectnessCheck() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void loadingFromDLRArrayCorrectnessCheck(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception { final String[][] rows = new String[3][6]; rows[0] = new String[]{"tomato", "weight", "200", "1000", "6", "== Taste.GOOD || == Taste.EXCELENT"}; rows[1] = new String[]{"cucumber", "length", "20", "40", "15", "== Taste.EXCELENT"}; @@ -154,12 +150,13 @@ public void loadingFromDLRArrayCorrectnessCheck() throws Exception { assertEqualsIgnoreWhitespace(EXPECTED_RULES.toString(), drl); - testCorrectnessCheck(drl); + testCorrectnessCheck(kieBaseTestConfiguration, drl); } } - @Test - public void loadingFromDLRSpreadsheetCorrectnessCheck() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void loadingFromDLRSpreadsheetCorrectnessCheck(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception { final ExternalSpreadsheetCompiler converter = new ExternalSpreadsheetCompiler(); final KieServices kieServices = KieServices.Factory.get(); @@ -174,12 +171,14 @@ public void loadingFromDLRSpreadsheetCorrectnessCheck() throws Exception { assertEqualsIgnoreWhitespace(EXPECTED_RULES.toString(), drl); - testCorrectnessCheck(drl); + testCorrectnessCheck(kieBaseTestConfiguration, drl); } } - @Test(timeout = 30000L) - public void OneRuleManyRows() throws IOException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + @Timeout(30000L) + public void OneRuleManyRows(KieBaseTestConfiguration kieBaseTestConfiguration) throws IOException { final KieServices kieServices = KieServices.Factory.get(); final Collection cfl = new ArrayList(); cfl.add(new ParamSet("tomato", "weight", 200, 1000, 6, EnumSet.of(Taste.GOOD, Taste.EXCELENT))); @@ -191,12 +190,14 @@ public void OneRuleManyRows() throws IOException { // prints rules generated from template LOGGER.debug(drl); - testManyRows(drl, 0, 1); + testManyRows(kieBaseTestConfiguration, drl, 0, 1); } } - @Test(timeout = 30000L) - public void TenRulesManyRows() throws IOException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + @Timeout(30000L) + public void TenRulesManyRows(KieBaseTestConfiguration kieBaseTestConfiguration) throws IOException { final KieServices kieServices = KieServices.Factory.get(); final ObjectDataCompiler converter = new ObjectDataCompiler(); @@ -206,12 +207,14 @@ public void TenRulesManyRows() throws IOException { // prints rules generated from template LOGGER.debug(drl); - testManyRows(drl, 500, 10); + testManyRows(kieBaseTestConfiguration, drl, 500, 10); } } - @Test(timeout = 30000L) - public void OneTemplateManyRules() throws IOException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + @Timeout(30000L) + public void OneTemplateManyRules(KieBaseTestConfiguration kieBaseTestConfiguration) throws IOException { final KieServices kieServices = KieServices.Factory.get(); final ObjectDataCompiler converter = new ObjectDataCompiler(); @@ -221,12 +224,14 @@ public void OneTemplateManyRules() throws IOException { // prints rules generated from template LOGGER.debug(drl); - testManyRules(drl, 50); + testManyRules(kieBaseTestConfiguration, drl, 50); } } - @Test(timeout = 30000L) - public void TenTemplatesManyRules() throws IOException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + @Timeout(30000L) + public void TenTemplatesManyRules(KieBaseTestConfiguration kieBaseTestConfiguration) throws IOException { final KieServices kieServices = KieServices.Factory.get(); final ObjectDataCompiler converter = new ObjectDataCompiler(); try (InputStream resourceStream = kieServices.getResources().newClassPathResource("template_2.drl", getClass()).getInputStream()) { @@ -237,11 +242,11 @@ public void TenTemplatesManyRules() throws IOException { // prints rules generated from template LOGGER.debug(drl); - testManyRules(drl, 500); + testManyRules(kieBaseTestConfiguration, drl, 500); } } - private void testCorrectnessCheck(final String drl) { + private void testCorrectnessCheck(KieBaseTestConfiguration kieBaseTestConfiguration, final String drl) { final Resource drlResource = KieServices.Factory.get().getResources().newReaderResource(new StringReader(drl)); drlResource.setTargetPath(TestConstants.DRL_TEST_TARGET_PATH); final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, drlResource); @@ -278,7 +283,7 @@ private void testCorrectnessCheck(final String drl) { assertThat(pkg.getRules().size()).isEqualTo(3); } - private void testManyRows(final String drl, final int expectedResultListSize, final int expectedRulesCount) { + private void testManyRows(KieBaseTestConfiguration kieBaseTestConfiguration, final String drl, final int expectedResultListSize, final int expectedRulesCount) { final Resource drlResource = KieServices.Factory.get().getResources().newReaderResource(new StringReader(drl)); drlResource.setTargetPath(TestConstants.DRL_TEST_TARGET_PATH); final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, drlResource); @@ -309,7 +314,7 @@ private void testManyRows(final String drl, final int expectedResultListSize, fi assertThat(pkg.getRules().size()).isEqualTo(expectedRulesCount); } - private void testManyRules(final String drl, final int expectedRulesCount) { + private void testManyRules(KieBaseTestConfiguration kieBaseTestConfiguration, final String drl, final int expectedRulesCount) { final Resource drlResource = KieServices.Factory.get().getResources().newReaderResource(new StringReader(drl)); drlResource.setTargetPath(TestConstants.DRL_TEST_TARGET_PATH); final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, drlResource); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/UnicodeTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/UnicodeTest.java index 6fb00f80f52..fdb4803402d 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/UnicodeTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/UnicodeTest.java @@ -20,18 +20,17 @@ import java.io.FileNotFoundException; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.ResourceUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +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.command.Command; @@ -52,22 +51,15 @@ * Tests Drools engine capabilities regarding Unicode characters * */ -@RunWith(Parameterized.class) public class UnicodeTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public UnicodeTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testJapanese() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testJapanese(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieServices kieServices = KieServices.Factory.get(); final Resource resource = kieServices.getResources().newClassPathResource("unicode.drl", getClass()); final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, @@ -94,8 +86,9 @@ public void testJapanese() { assertThat(一覧.iterator().next().getの名前()).isEqualTo("横綱"); } - @Test - public void testCzech() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testCzech(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieServices kieServices = KieServices.Factory.get(); final Resource resource = kieServices.getResources().newClassPathResource("unicode.drl", getClass()); final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, resource); @@ -122,8 +115,9 @@ public void testCzech() { assertThat(lidé.get(1).getJméno()).isEqualTo("Oldřiška"); } - @Test - public void testCzechDomainSpecificLanguage() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testCzechDomainSpecificLanguage(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieServices kieServices = KieServices.Factory.get(); final Resource dsl = kieServices.getResources().newClassPathResource("unicode.dsl", getClass()); final Resource dslr = kieServices.getResources().newClassPathResource("unicode.dslr", getClass()); @@ -146,8 +140,9 @@ public void testCzechDomainSpecificLanguage() { assertThat(dospělí.iterator().next().getJméno()).isEqualTo("Řehoř"); } - @Test - public void testCzechXLSDecisionTable() throws FileNotFoundException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testCzechXLSDecisionTable(KieBaseTestConfiguration kieBaseTestConfiguration) throws FileNotFoundException { final KieServices kieServices = KieServices.Factory.get(); final Resource resource = kieServices.getResources().newClassPathResource("unicode.drl.xls", getClass()); final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, resource); @@ -169,8 +164,9 @@ public void testCzechXLSDecisionTable() throws FileNotFoundException { assertThat(dospělí.iterator().next().getJméno()).isEqualTo("Řehoř"); } - @Test - public void testCzechCSVDecisionTable() throws FileNotFoundException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testCzechCSVDecisionTable(KieBaseTestConfiguration kieBaseTestConfiguration) throws FileNotFoundException { final KieServices kieServices = KieServices.Factory.get(); final Resource decisionTable = @@ -196,8 +192,9 @@ public void testCzechCSVDecisionTable() throws FileNotFoundException { } // test queries in Czech language - @Test - public void testQueryCallFromJava() throws InstantiationException, IllegalAccessException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testQueryCallFromJava(KieBaseTestConfiguration kieBaseTestConfiguration) throws InstantiationException, IllegalAccessException { final KieServices kieServices = KieServices.Factory.get(); final Resource resource = kieServices.getResources().newClassPathResource("unicode.drl", getClass()); final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, resource); @@ -318,7 +315,8 @@ public static class Člověk { } } - @Test + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") public void testMutibyteJavaDialect() { // DROOLS-1200 final String drl = diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/decisiontable/DecisionTableKieContainerTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/decisiontable/DecisionTableKieContainerTest.java index e74058b61c0..895e1c7cfec 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/decisiontable/DecisionTableKieContainerTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/decisiontable/DecisionTableKieContainerTest.java @@ -19,7 +19,7 @@ package org.drools.testcoverage.functional.decisiontable; import org.drools.testcoverage.common.model.Record; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.api.runtime.KieContainer; diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/model/RulesWithInTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/model/RulesWithInTest.java index d1bfdee0246..95254e37221 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/model/RulesWithInTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/model/RulesWithInTest.java @@ -20,7 +20,7 @@ import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieServices; import org.kie.api.builder.ReleaseId; import org.kie.api.io.Resource; diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DeserializationWithCompositeTriggerTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DeserializationWithCompositeTriggerTest.java index 35bb168579e..3d0dc37700b 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DeserializationWithCompositeTriggerTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/DeserializationWithCompositeTriggerTest.java @@ -94,7 +94,6 @@ public void cleanup() { /** * Verifies that serialization of a rule with composite trigger does not fail on * org.drools.core.time.impl.CompositeMaxDurationTrigger class serialization. - * @param kieBaseTestConfiguration */ @ParameterizedTest(name = "KieBase type={0}") @MethodSource("parameters") diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FixedPatternTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FixedPatternTest.java index c64b72e457b..2ae5e7f56dc 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FixedPatternTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/FixedPatternTest.java @@ -56,7 +56,6 @@ public void cleanup() { /** * Tests fixed pattern without constraint in Decision table (BZ 1150308). - * @param kieBaseTestConfiguration */ @ParameterizedTest(name = "KieBase type={0}") @MethodSource("parameters") diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultipleKieBaseListenersTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultipleKieBaseListenersTest.java index f2161255955..15c795e3cdd 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultipleKieBaseListenersTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultipleKieBaseListenersTest.java @@ -18,38 +18,29 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.event.kiebase.DefaultKieBaseEventListener; import org.kie.api.event.kiebase.KieBaseEventListener; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(Parameterized.class) public class MultipleKieBaseListenersTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public MultipleKieBaseListenersTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameters - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testKnowledgeBaseEventSupportLeak() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testKnowledgeBaseEventSupportLeak(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception { final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromDrl(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, ""); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultipleSheetsLoadingTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultipleSheetsLoadingTest.java index 8efc92fc519..2e17eb0319b 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultipleSheetsLoadingTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultipleSheetsLoadingTest.java @@ -21,15 +21,15 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; +import java.util.stream.Stream; import org.drools.compiler.builder.conf.DecisionTableConfigurationImpl; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +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; @@ -48,18 +48,10 @@ /** * Tests loading decision tables from several worksheets in a XLS file. */ -@RunWith(Parameterized.class) public class MultipleSheetsLoadingTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public MultipleSheetsLoadingTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } private static final Logger LOGGER = LoggerFactory.getLogger(MultipleSheetsLoadingTest.class); @@ -71,9 +63,10 @@ public static Collection getParameters() { private static final String WORKSHEET_1_NAME = "first"; private static final String WORKSHEET_2_NAME = "second"; - @Test - public void test() { - final KieBuilder kbuilder = this.buildResources(); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void test(KieBaseTestConfiguration kieBaseTestConfiguration) { + final KieBuilder kbuilder = this.buildResources(kieBaseTestConfiguration); final Collection results = kbuilder.getResults().getMessages(Level.ERROR, Level.WARNING); if (results.size() > 0) { @@ -93,7 +86,7 @@ public void test() { } } - private KieBuilder buildResources() { + private KieBuilder buildResources(KieBaseTestConfiguration kieBaseTestConfiguration) { final Resource resourceXlsFirst = this.createResourceWithConfig(WORKSHEET_1_NAME); final Resource resourceXlsSecond = this.createResourceWithConfig(WORKSHEET_2_NAME); return KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, false, resourceXlsFirst, resourceXlsSecond); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/NonStringCompareTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/NonStringCompareTest.java index 34851e4380f..91eb88684a6 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/NonStringCompareTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/NonStringCompareTest.java @@ -18,16 +18,15 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.KieUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.Message.Level; @@ -36,7 +35,6 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(Parameterized.class) public class NonStringCompareTest { private static final String genericDrl = @@ -51,37 +49,33 @@ public class NonStringCompareTest { + " // consequence\n" + "end\n"; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public NonStringCompareTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testStringCompare() throws Exception { - testScenario("\"someString\"", "someString"); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testStringCompare(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception { + testScenario(kieBaseTestConfiguration, "\"someString\"", "someString"); } - @Test - public void testNonQuotedStringComapre() { - final KieBuilder kbuilder = build("someString"); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testNonQuotedStringComapre(KieBaseTestConfiguration kieBaseTestConfiguration) { + final KieBuilder kbuilder = build(kieBaseTestConfiguration, "someString"); assertThat(kbuilder.getResults().getMessages(Level.ERROR).size()).isEqualTo(1); } - @Test - public void testIntCompare() throws Exception { - testScenario("13", "13"); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testIntCompare(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception { + testScenario(kieBaseTestConfiguration, "13", "13"); } - private void testScenario(final String factFieldValueForDrl, final String factFieldValueForTest) + private void testScenario(KieBaseTestConfiguration kieBaseTestConfiguration, final String factFieldValueForDrl, final String factFieldValueForTest) throws IllegalAccessException, InstantiationException { - final KieBuilder kbuilder = build(factFieldValueForDrl); + final KieBuilder kbuilder = build(kieBaseTestConfiguration, factFieldValueForDrl); assertThat(kbuilder.getResults().getMessages(Level.ERROR)).isEmpty(); final KieBase kbase = KieBaseUtil.getDefaultKieBaseFromKieBuilder(kbuilder); @@ -100,7 +94,7 @@ private void testScenario(final String factFieldValueForDrl, final String factFi } } - private KieBuilder build(final String replacement) { + private KieBuilder build(KieBaseTestConfiguration kieBaseTestConfiguration, final String replacement) { final String drl = String.format(genericDrl, replacement); return KieUtil.getKieBuilderFromDrls(kieBaseTestConfiguration, false, drl); } diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/NullInListInFromTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/NullInListInFromTest.java index 4924f758fb9..3d2f84f8f2e 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/NullInListInFromTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/NullInListInFromTest.java @@ -19,16 +19,15 @@ package org.drools.testcoverage.regression; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.builder.KieBuilder; import org.kie.api.runtime.KieSession; @@ -36,7 +35,6 @@ /** * Tests handling a null value in a list used in FROM (BZ 1093174). */ -@RunWith(Parameterized.class) public class NullInListInFromTest { private static final String DRL = @@ -48,19 +46,13 @@ public class NullInListInFromTest { "then\n" + "end\n"; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public NullInListInFromTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testNullValueInFrom() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testNullValueInFrom(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBuilder kbuilder = KieUtil.getKieBuilderFromDrls(kieBaseTestConfiguration, true, DRL); final KieBase kbase = KieBaseUtil.getDefaultKieBaseFromKieBuilder(kbuilder); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/POJOAnnotationMergeTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/POJOAnnotationMergeTest.java index c6055f0a674..2ac5ec81d7f 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/POJOAnnotationMergeTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/POJOAnnotationMergeTest.java @@ -18,34 +18,25 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.definition.type.Position; /** * Tests merging the POJO annotations (e.g. @Position) with fact declaration in * DRL. */ -@RunWith(Parameterized.class) public class POJOAnnotationMergeTest { private static final String EVENT_CLASS_NAME = PositionAnnotatedEvent.class.getCanonicalName(); - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public POJOAnnotationMergeTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } // should add metadata to metadata already defined in POJO @@ -63,8 +54,9 @@ public static Collection getParameters() { /** * Tests adding metadata in DRL to the metadata already declared in a POJO. */ - @Test - public void testPositionFromPOJOIgnored() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testPositionFromPOJOIgnored(KieBaseTestConfiguration kieBaseTestConfiguration) { KieUtil.getKieBuilderFromDrls(kieBaseTestConfiguration,true, DRL); } diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/PropertyListenerTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/PropertyListenerTest.java index 9bf56450f60..d114fcc7e4d 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/PropertyListenerTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/PropertyListenerTest.java @@ -23,15 +23,14 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.drools.testcoverage.common.util.TestParametersUtil2; +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.command.Command; @@ -47,23 +46,16 @@ * https://bugzilla.redhat.com/show_bug.cgi?id=746887 * https://issues.jboss.org/browse/JBRULES-3256 */ -@RunWith(Parameterized.class) public class PropertyListenerTest { private static final Logger LOGGER = LoggerFactory.getLogger(PropertyListenerTest.class); - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public PropertyListenerTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameters - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void runTest() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void runTest(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieServices kieServices = KieServices.Factory.get(); final Resource drlResource = kieServices.getResources().newClassPathResource("propertyListenerTest.drl", getClass()); final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromResources(TestConstants.PACKAGE_REGRESSION, diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SerializableGeneratedTypesTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SerializableGeneratedTypesTest.java index c592c6a3182..89ad0f8f3c8 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SerializableGeneratedTypesTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SerializableGeneratedTypesTest.java @@ -18,16 +18,14 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.drools.testcoverage.common.util.TestParametersUtil2; +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.definition.type.FactType; @@ -38,22 +36,15 @@ /** * Test to verify BRMS-360 (Generated types should be serializable) is fixed */ -@RunWith(Parameterized.class) public class SerializableGeneratedTypesTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public SerializableGeneratedTypesTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameters - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void testSerializability() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testSerializability(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception { final Resource drlResource = KieServices.Factory.get().getResources().newClassPathResource("serializableGeneratedTypesTest.drl", getClass()); final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromResources(TestConstants.PACKAGE_REGRESSION, diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SessionInsertMultiThreadingTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SessionInsertMultiThreadingTest.java index 4e52b9447e6..55fe2abdb4f 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SessionInsertMultiThreadingTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SessionInsertMultiThreadingTest.java @@ -19,23 +19,21 @@ package org.drools.testcoverage.regression; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; import org.drools.testcoverage.common.model.Message; import org.drools.testcoverage.common.model.Person; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.AfterEach; +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.command.Command; @@ -52,7 +50,6 @@ * Test to verify BRMS-532 (Drools Session insert * ConcurrentModificationException in Multithreading Environment) is fixed */ -@RunWith(Parameterized.class) public class SessionInsertMultiThreadingTest { private static final Logger LOGGER = LoggerFactory.getLogger(SessionInsertMultiThreadingTest.class); @@ -63,19 +60,11 @@ public class SessionInsertMultiThreadingTest { private KieBase kbase; private ExecutorService executor; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public SessionInsertMultiThreadingTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Before - public void createExecutor() { + public void createExecutor(KieBaseTestConfiguration kieBaseTestConfiguration) { final Resource resource = KieServices.Factory.get().getResources().newClassPathResource( "sessionInsertMultithreadingTest.drl", SessionInsertMultiThreadingTest.class); @@ -85,7 +74,7 @@ public void createExecutor() { executor = Executors.newFixedThreadPool(THREADS); } - @After + @AfterEach public void shutdownExecutor() throws Exception { if (kbase != null) { for (KieSession ksession : kbase.getKieSessions()) { @@ -101,8 +90,10 @@ public void shutdownExecutor() throws Exception { executor = null; } - @Test - public void testCommonBase() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testCommonBase(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception { + createExecutor(kieBaseTestConfiguration); final List> futures = new ArrayList>(); for (int i = 0; i < RUNS_PER_THREAD; i++) { @@ -114,8 +105,10 @@ public void testCommonBase() throws Exception { waitForCompletion(futures); } - @Test - public void testCommonSession() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testCommonSession(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception { + createExecutor(kieBaseTestConfiguration); for (int i = 0; i < RUNS_PER_THREAD; i++) { testSingleCommonSession(); } @@ -138,8 +131,10 @@ private void testSingleCommonSession() throws Exception { /** * Reproducer for BZ 1187070. */ - @Test - public void testCommonStatelessSessionBZ1187070() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testCommonStatelessSessionBZ1187070(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception { + createExecutor(kieBaseTestConfiguration); for (int i = 0; i < RUNS_PER_THREAD; i++) { testSingleCommonStatelessSession(); } From 4386c399fdcc4b34532ce4939db49cffcc712a2f Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Wed, 20 Nov 2024 08:57:08 +0100 Subject: [PATCH 4/6] Migrated more tests --- .../common/util/TestParametersUtilTest.java | 43 +++--- .../functional/oopath/OOPathCepTest.java | 130 ++++++++++-------- .../functional/oopath/OOPathDslTest.java | 2 +- .../functional/oopath/OOPathDtablesTest.java | 54 ++++---- .../oopath/OOPathLogicalBranchesTest.java | 80 +++++------ .../functional/oopath/OOPathSmokeTest.java | 38 +++-- .../functional/parser/DrlParserTest.java | 18 +-- .../functional/parser/DslParserTest.java | 37 ++--- .../functional/parser/ParserTest.java | 23 +--- .../functional/parser/SmokeParserTest.java | 21 ++- 10 files changed, 219 insertions(+), 227 deletions(-) diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/common/util/TestParametersUtilTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/common/util/TestParametersUtilTest.java index 0f467c2fdf0..4d0d2d9cbde 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/common/util/TestParametersUtilTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/common/util/TestParametersUtilTest.java @@ -18,7 +18,7 @@ */ package org.drools.testcoverage.common.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.drools.testcoverage.common.util.KieBaseTestConfiguration.CLOUD_EQUALITY; @@ -34,41 +34,42 @@ import static org.drools.testcoverage.common.util.KieBaseTestConfiguration.STREAM_IDENTITY_MODEL_PATTERN; import static org.drools.testcoverage.common.util.KieBaseTestConfiguration.STREAM_IDENTITY_MODEL_PATTERN_ALPHA_NETWORK; + public class TestParametersUtilTest { @Test public void testGetEqualityInstanceOf() { - assertThat(TestParametersUtil.getEqualityInstanceOf(CLOUD_IDENTITY)).isEqualTo(CLOUD_EQUALITY); - assertThat(TestParametersUtil.getEqualityInstanceOf(CLOUD_EQUALITY)).isEqualTo(CLOUD_EQUALITY); - assertThat(TestParametersUtil.getEqualityInstanceOf(CLOUD_IDENTITY_ALPHA_NETWORK)).isEqualTo(CLOUD_EQUALITY_ALPHA_NETWORK); - assertThat(TestParametersUtil.getEqualityInstanceOf(CLOUD_IDENTITY_MODEL_PATTERN)).isEqualTo(CLOUD_EQUALITY_MODEL_PATTERN); - assertThat(TestParametersUtil.getEqualityInstanceOf(CLOUD_IDENTITY_MODEL_PATTERN_ALPHA_NETWORK)).isEqualTo(CLOUD_EQUALITY_MODEL_PATTERN_ALPHA_NETWORK); + assertThat(TestParametersUtil2.getEqualityInstanceOf(CLOUD_IDENTITY)).isEqualTo(CLOUD_EQUALITY); + assertThat(TestParametersUtil2.getEqualityInstanceOf(CLOUD_EQUALITY)).isEqualTo(CLOUD_EQUALITY); + assertThat(TestParametersUtil2.getEqualityInstanceOf(CLOUD_IDENTITY_ALPHA_NETWORK)).isEqualTo(CLOUD_EQUALITY_ALPHA_NETWORK); + assertThat(TestParametersUtil2.getEqualityInstanceOf(CLOUD_IDENTITY_MODEL_PATTERN)).isEqualTo(CLOUD_EQUALITY_MODEL_PATTERN); + assertThat(TestParametersUtil2.getEqualityInstanceOf(CLOUD_IDENTITY_MODEL_PATTERN_ALPHA_NETWORK)).isEqualTo(CLOUD_EQUALITY_MODEL_PATTERN_ALPHA_NETWORK); } @Test public void testGetIdentityInstanceOf() { - assertThat(TestParametersUtil.getIdentityInstanceOf(CLOUD_EQUALITY)).isEqualTo(CLOUD_IDENTITY); - assertThat(TestParametersUtil.getIdentityInstanceOf(CLOUD_IDENTITY)).isEqualTo(CLOUD_IDENTITY); - assertThat(TestParametersUtil.getIdentityInstanceOf(CLOUD_EQUALITY_ALPHA_NETWORK)).isEqualTo(CLOUD_IDENTITY_ALPHA_NETWORK); - assertThat(TestParametersUtil.getIdentityInstanceOf(CLOUD_EQUALITY_MODEL_PATTERN)).isEqualTo(CLOUD_IDENTITY_MODEL_PATTERN); - assertThat(TestParametersUtil.getIdentityInstanceOf(CLOUD_EQUALITY_MODEL_PATTERN_ALPHA_NETWORK)).isEqualTo(CLOUD_IDENTITY_MODEL_PATTERN_ALPHA_NETWORK); + assertThat(TestParametersUtil2.getIdentityInstanceOf(CLOUD_EQUALITY)).isEqualTo(CLOUD_IDENTITY); + assertThat(TestParametersUtil2.getIdentityInstanceOf(CLOUD_IDENTITY)).isEqualTo(CLOUD_IDENTITY); + assertThat(TestParametersUtil2.getIdentityInstanceOf(CLOUD_EQUALITY_ALPHA_NETWORK)).isEqualTo(CLOUD_IDENTITY_ALPHA_NETWORK); + assertThat(TestParametersUtil2.getIdentityInstanceOf(CLOUD_EQUALITY_MODEL_PATTERN)).isEqualTo(CLOUD_IDENTITY_MODEL_PATTERN); + assertThat(TestParametersUtil2.getIdentityInstanceOf(CLOUD_EQUALITY_MODEL_PATTERN_ALPHA_NETWORK)).isEqualTo(CLOUD_IDENTITY_MODEL_PATTERN_ALPHA_NETWORK); } @Test public void testGetStreamInstanceOf() { - assertThat(TestParametersUtil.getStreamInstanceOf(CLOUD_IDENTITY)).isEqualTo(STREAM_IDENTITY); - assertThat(TestParametersUtil.getStreamInstanceOf(STREAM_IDENTITY)).isEqualTo(STREAM_IDENTITY); - assertThat(TestParametersUtil.getStreamInstanceOf(CLOUD_IDENTITY_ALPHA_NETWORK)).isEqualTo(STREAM_IDENTITY_ALPHA_NETWORK); - assertThat(TestParametersUtil.getStreamInstanceOf(CLOUD_IDENTITY_MODEL_PATTERN)).isEqualTo(STREAM_IDENTITY_MODEL_PATTERN); - assertThat(TestParametersUtil.getStreamInstanceOf(CLOUD_IDENTITY_MODEL_PATTERN_ALPHA_NETWORK)).isEqualTo(STREAM_IDENTITY_MODEL_PATTERN_ALPHA_NETWORK); + assertThat(TestParametersUtil2.getStreamInstanceOf(CLOUD_IDENTITY)).isEqualTo(STREAM_IDENTITY); + assertThat(TestParametersUtil2.getStreamInstanceOf(STREAM_IDENTITY)).isEqualTo(STREAM_IDENTITY); + assertThat(TestParametersUtil2.getStreamInstanceOf(CLOUD_IDENTITY_ALPHA_NETWORK)).isEqualTo(STREAM_IDENTITY_ALPHA_NETWORK); + assertThat(TestParametersUtil2.getStreamInstanceOf(CLOUD_IDENTITY_MODEL_PATTERN)).isEqualTo(STREAM_IDENTITY_MODEL_PATTERN); + assertThat(TestParametersUtil2.getStreamInstanceOf(CLOUD_IDENTITY_MODEL_PATTERN_ALPHA_NETWORK)).isEqualTo(STREAM_IDENTITY_MODEL_PATTERN_ALPHA_NETWORK); } @Test public void testGetCloudInstanceOf() { - assertThat(TestParametersUtil.getCloudInstanceOf(STREAM_IDENTITY)).isEqualTo(CLOUD_IDENTITY); - assertThat(TestParametersUtil.getCloudInstanceOf(CLOUD_IDENTITY)).isEqualTo(CLOUD_IDENTITY); - assertThat(TestParametersUtil.getCloudInstanceOf(STREAM_IDENTITY_ALPHA_NETWORK)).isEqualTo(CLOUD_IDENTITY_ALPHA_NETWORK); - assertThat(TestParametersUtil.getCloudInstanceOf(STREAM_IDENTITY_MODEL_PATTERN)).isEqualTo(CLOUD_IDENTITY_MODEL_PATTERN); - assertThat(TestParametersUtil.getCloudInstanceOf(STREAM_IDENTITY_MODEL_PATTERN_ALPHA_NETWORK)).isEqualTo(CLOUD_IDENTITY_MODEL_PATTERN_ALPHA_NETWORK); + assertThat(TestParametersUtil2.getCloudInstanceOf(STREAM_IDENTITY)).isEqualTo(CLOUD_IDENTITY); + assertThat(TestParametersUtil2.getCloudInstanceOf(CLOUD_IDENTITY)).isEqualTo(CLOUD_IDENTITY); + assertThat(TestParametersUtil2.getCloudInstanceOf(STREAM_IDENTITY_ALPHA_NETWORK)).isEqualTo(CLOUD_IDENTITY_ALPHA_NETWORK); + assertThat(TestParametersUtil2.getCloudInstanceOf(STREAM_IDENTITY_MODEL_PATTERN)).isEqualTo(CLOUD_IDENTITY_MODEL_PATTERN); + assertThat(TestParametersUtil2.getCloudInstanceOf(STREAM_IDENTITY_MODEL_PATTERN_ALPHA_NETWORK)).isEqualTo(CLOUD_IDENTITY_MODEL_PATTERN_ALPHA_NETWORK); } } diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathCepTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathCepTest.java index ee09fdaaacf..cfb349c0600 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathCepTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathCepTest.java @@ -19,20 +19,19 @@ package org.drools.testcoverage.functional.oopath; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; import org.drools.testcoverage.common.model.Message; import org.drools.testcoverage.common.model.MessageEvent; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.KieSessionUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.AfterEach; +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.runtime.KieSessionConfiguration; @@ -46,7 +45,6 @@ /** * Tests usage of OOPath expressions with CEP (events, event windows, event streams). */ -@RunWith(Parameterized.class) public class OOPathCepTest { private static final String MODULE_GROUP_ID = "oopath-cep-test"; @@ -58,18 +56,11 @@ public class OOPathCepTest { private List events; private List messages; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public OOPathCepTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseStreamConfigurations(true); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseStreamConfigurations(true).stream(); } - @After + @AfterEach public void disposeKieSession() { if (this.kieSession != null) { this.kieSession.dispose(); @@ -80,8 +71,9 @@ public void disposeKieSession() { } } - @Test - public void testEventWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testEventWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -102,8 +94,9 @@ public void testEventWithOOPath() { this.populateAndVerifyEventCase(this.kieSession); } - @Test - public void testEntryPointWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testEntryPointWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -136,8 +129,9 @@ private void populateAndVerifyEventCase(final EntryPoint entryPoint) { assertThat(this.messages).containsExactlyInAnyOrder(helloMessage); } - @Test - public void testTemporalOperatorAfterWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTemporalOperatorAfterWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -169,8 +163,9 @@ public void testTemporalOperatorAfterWithOOPath() { assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage); } - @Test - public void testTemporalOperatorBeforeWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTemporalOperatorBeforeWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -202,8 +197,9 @@ public void testTemporalOperatorBeforeWithOOPath() { assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage); } - @Test - public void testTemporalOperatorCoincidesWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTemporalOperatorCoincidesWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -235,8 +231,9 @@ public void testTemporalOperatorCoincidesWithOOPath() { assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage); } - @Test - public void testTemporalOperatorDuringWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTemporalOperatorDuringWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -269,8 +266,9 @@ public void testTemporalOperatorDuringWithOOPath() { assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage); } - @Test - public void testTemporalOperatorFinishesWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTemporalOperatorFinishesWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -303,8 +301,9 @@ public void testTemporalOperatorFinishesWithOOPath() { assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage); } - @Test - public void testTemporalOperatorFinishedByWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTemporalOperatorFinishedByWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -337,8 +336,9 @@ public void testTemporalOperatorFinishedByWithOOPath() { assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage); } - @Test - public void testTemporalOperatorIncludesWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTemporalOperatorIncludesWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -371,8 +371,9 @@ public void testTemporalOperatorIncludesWithOOPath() { assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage); } - @Test - public void testTemporalOperatorMeetsWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTemporalOperatorMeetsWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -404,8 +405,9 @@ public void testTemporalOperatorMeetsWithOOPath() { assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage); } - @Test - public void testTemporalOperatorMetByWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTemporalOperatorMetByWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -437,8 +439,9 @@ public void testTemporalOperatorMetByWithOOPath() { assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage); } - @Test - public void testTemporalOperatorOverlapsWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTemporalOperatorOverlapsWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -472,8 +475,9 @@ public void testTemporalOperatorOverlapsWithOOPath() { assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage); } - @Test - public void testTemporalOperatorOverlappedByWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTemporalOperatorOverlappedByWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -506,8 +510,9 @@ public void testTemporalOperatorOverlappedByWithOOPath() { assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage); } - @Test - public void testTemporalOperatorStartsWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTemporalOperatorStartsWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -540,8 +545,9 @@ public void testTemporalOperatorStartsWithOOPath() { assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage); } - @Test - public void testTemporalOperatorStartedByWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTemporalOperatorStartedByWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -574,8 +580,9 @@ public void testTemporalOperatorStartedByWithOOPath() { assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage); } - @Test - public void testLengthWindowWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testLengthWindowWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -595,8 +602,9 @@ public void testLengthWindowWithOOPath() { this.populateAndVerifyLengthWindowCase(kieBase); } - @Test - public void testDeclaredLengthWindowWithOOPathInRule() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testDeclaredLengthWindowWithOOPathInRule(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -620,8 +628,9 @@ public void testDeclaredLengthWindowWithOOPathInRule() { this.populateAndVerifyLengthWindowCase(kieBase); } - @Test - public void testOOPathNotAllowedInDeclaredWindow() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testOOPathNotAllowedInDeclaredWindow(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -670,8 +679,9 @@ private void populateAndVerifyLengthWindowCase(final KieBase kieBase) { assertThat(this.events).as("The rule should have fired for ping event only").contains(ping4Event); } - @Test - public void testTimeWindowWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTimeWindowWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -691,8 +701,9 @@ public void testTimeWindowWithOOPath() { this.populateAndVerifyTimeWindowCase(kieBase); } - @Test - public void testDeclaredTimeWindowWithOOPathInRule() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testDeclaredTimeWindowWithOOPathInRule(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + @@ -749,8 +760,9 @@ private void populateAndVerifyTimeWindowCase(final KieBase kieBase) { assertThat(this.events).as("The rule should have fired for ping event only").contains(ping4Event); } - @Test - public void testEventExplicitExpirationWithOOPath() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testEventExplicitExpirationWithOOPath(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathDslTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathDslTest.java index 244f25c17da..a3a3eb8de4a 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathDslTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathDslTest.java @@ -20,7 +20,7 @@ import org.drools.testcoverage.common.model.InternationalAddress; import org.drools.testcoverage.common.model.Person; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.io.ResourceType; import org.kie.api.runtime.KieSession; import org.kie.internal.utils.KieHelper; diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathDtablesTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathDtablesTest.java index a84ecd548a3..f77e2112fc8 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathDtablesTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathDtablesTest.java @@ -19,8 +19,8 @@ package org.drools.testcoverage.functional.oopath; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.testcoverage.common.model.Address; import org.drools.testcoverage.common.model.InternationalAddress; @@ -28,10 +28,9 @@ import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.ResourceUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.io.Resource; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.QueryResults; @@ -44,35 +43,30 @@ * Test basic OOPath expressions used in Decision tables (*.xls, *.xlsx, *.csv) * in both RuleTable and Queries as well. */ -@RunWith(Parameterized.class) public class OOPathDtablesTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public OOPathDtablesTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @Test - public void xlsWithOOPathTest() { - final KieSession kieSession = getKieSessionFromXls("oopath.drl.xls"); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void xlsWithOOPathTest(KieBaseTestConfiguration kieBaseTestConfiguration) { + final KieSession kieSession = getKieSessionFromXls(kieBaseTestConfiguration, "oopath.drl.xls"); testOOPathWithDTable(kieSession); } - @Test - public void xlsxWithOOPathTest() { - final KieSession kieSession = getKieSessionFromXlsx("oopath.drl.xlsx"); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void xlsxWithOOPathTest(KieBaseTestConfiguration kieBaseTestConfiguration) { + final KieSession kieSession = getKieSessionFromXlsx(kieBaseTestConfiguration, "oopath.drl.xlsx"); testOOPathWithDTable(kieSession); } - @Test - public void csvWithOOPathTest() { - final KieSession kieSession = getKieSessionFromCsv("oopath.drl.csv"); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void csvWithOOPathTest(KieBaseTestConfiguration kieBaseTestConfiguration) { + final KieSession kieSession = getKieSessionFromCsv(kieBaseTestConfiguration, "oopath.drl.csv"); testOOPathWithDTable(kieSession); } @@ -87,22 +81,22 @@ private void testOOPathWithDTable(final KieSession kieSession) { verifyQueryResults(kieSession.getQueryResults("listSafeCities")); } - private KieSession getKieSessionFromCsv(final String csvFile) { + private KieSession getKieSessionFromCsv(KieBaseTestConfiguration kieBaseTestConfiguration, final String csvFile) { final Resource resource = ResourceUtil.getDecisionTableResourceFromClasspath(csvFile, getClass(), DecisionTableInputType.CSV); return KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, resource).newKieSession(); } - private KieSession getKieSessionFromXls(final String xlsFile) { - return getKieSessionFromExcel(xlsFile, DecisionTableInputType.XLS); + private KieSession getKieSessionFromXls(KieBaseTestConfiguration kieBaseTestConfiguration, final String xlsFile) { + return getKieSessionFromExcel(kieBaseTestConfiguration, xlsFile, DecisionTableInputType.XLS); } - private KieSession getKieSessionFromXlsx(final String xlsxFile) { - return getKieSessionFromExcel(xlsxFile, DecisionTableInputType.XLSX); + private KieSession getKieSessionFromXlsx(KieBaseTestConfiguration kieBaseTestConfiguration, final String xlsxFile) { + return getKieSessionFromExcel(kieBaseTestConfiguration, xlsxFile, DecisionTableInputType.XLSX); } - private KieSession getKieSessionFromExcel(final String file, final DecisionTableInputType fileType) { + private KieSession getKieSessionFromExcel(KieBaseTestConfiguration kieBaseTestConfiguration, final String file, final DecisionTableInputType fileType) { final Resource resource = ResourceUtil.getDecisionTableResourceFromClasspath(file, getClass(), fileType); return KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, resource).newKieSession(); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathLogicalBranchesTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathLogicalBranchesTest.java index dc76b246e0a..045f9a8ef9e 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathLogicalBranchesTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathLogicalBranchesTest.java @@ -19,18 +19,17 @@ package org.drools.testcoverage.functional.oopath; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.testcoverage.common.model.Address; import org.drools.testcoverage.common.model.Employee; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.AfterEach; +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.runtime.KieSession; @@ -41,7 +40,6 @@ /** * Tests usage of OOPath expressions resulting in multiple conditional branches (e.g. OR operator). */ -@RunWith(Parameterized.class) public class OOPathLogicalBranchesTest { private static final KieServices KIE_SERVICES = KieServices.Factory.get(); @@ -49,18 +47,11 @@ public class OOPathLogicalBranchesTest { private KieSession kieSession; private List results; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public OOPathLogicalBranchesTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @After + @AfterEach public void disposeKieSession() { if (this.kieSession != null) { this.kieSession.dispose(); @@ -69,8 +60,9 @@ public void disposeKieSession() { } } - @Test - public void testBasicOrCondition() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testBasicOrCondition(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Employee;\n" + "import org.drools.testcoverage.common.model.Address;\n" + @@ -90,8 +82,9 @@ public void testBasicOrCondition() { assertThat(this.results).containsExactlyInAnyOrder("Big City", "Small City"); } - @Test - public void testOrConstraint() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testOrConstraint(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Employee;\n" + "import org.drools.testcoverage.common.model.Address;\n" + @@ -112,8 +105,9 @@ public void testOrConstraint() { assertThat(this.results).containsExactlyInAnyOrder("Big City", "Small City"); } - @Test - public void testOrConstraintWithJoin() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testOrConstraintWithJoin(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Employee;\n" + "import org.drools.testcoverage.common.model.Address;\n" + @@ -134,8 +128,9 @@ public void testOrConstraintWithJoin() { assertThat(this.results).containsExactlyInAnyOrder("Big City", "Small City"); } - @Test - public void testOrConstraintNoBinding() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testOrConstraintNoBinding(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Employee;\n" + "import org.drools.testcoverage.common.model.Address;\n" + @@ -156,8 +151,9 @@ public void testOrConstraintNoBinding() { assertThat(this.results).containsExactlyInAnyOrder("Bruno", "Alice"); } - @Test - public void testOrConditionalElement() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testOrConditionalElement(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Employee;\n" + "import org.drools.testcoverage.common.model.Address;\n" + @@ -179,8 +175,9 @@ public void testOrConditionalElement() { assertThat(this.results).containsExactlyInAnyOrder("Big City", "Small City"); } - @Test - public void testOrConditionalElementNoBinding() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testOrConditionalElementNoBinding(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Employee;\n" + "import org.drools.testcoverage.common.model.Address;\n" + @@ -204,8 +201,9 @@ public void testOrConditionalElementNoBinding() { assertThat(this.results).containsExactlyInAnyOrder("Bruno", "Alice"); } - @Test - public void testBasicAndCondition() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testBasicAndCondition(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Employee;\n" + "import org.drools.testcoverage.common.model.Address;\n" + @@ -225,8 +223,9 @@ public void testBasicAndCondition() { assertThat(this.results).containsExactly("Big City"); } - @Test - public void testAndConstraint() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testAndConstraint(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Employee;\n" + "import org.drools.testcoverage.common.model.Address;\n" + @@ -247,8 +246,9 @@ public void testAndConstraint() { assertThat(this.results).containsExactlyInAnyOrder("Big City"); } - @Test - public void testAndConstraintNoBinding() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testAndConstraintNoBinding(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Employee;\n" + "import org.drools.testcoverage.common.model.Address;\n" + @@ -269,8 +269,9 @@ public void testAndConstraintNoBinding() { assertThat(this.results).containsExactlyInAnyOrder("Alice"); } - @Test - public void testAndConditionalElement() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testAndConditionalElement(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Employee;\n" + "import org.drools.testcoverage.common.model.Address;\n" + @@ -292,8 +293,9 @@ public void testAndConditionalElement() { assertThat(this.results).containsExactlyInAnyOrder("Big City"); } - @Test - public void testAndConditionalElementWithNot() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testAndConditionalElementWithNot(KieBaseTestConfiguration kieBaseTestConfiguration) { final String drl = "import org.drools.testcoverage.common.model.Employee;\n" + "import org.drools.testcoverage.common.model.Address;\n" + diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathSmokeTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathSmokeTest.java index c19bb1b8ddc..09f4abd0462 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathSmokeTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/oopath/OOPathSmokeTest.java @@ -18,18 +18,17 @@ */ package org.drools.testcoverage.functional.oopath; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.model.Address; import org.drools.testcoverage.common.model.Person; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.AfterEach; +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.ReleaseId; @@ -42,25 +41,17 @@ /** * Tests basic usage of OOPath expressions. */ -@RunWith(Parameterized.class) public class OOPathSmokeTest { private static final KieServices KIE_SERVICES = KieServices.Factory.get(); private static final ReleaseId RELEASE_ID = KIE_SERVICES.newReleaseId("org.drools.testcoverage.oopath", "marshalling-test", "1.0"); private KieSession kieSession; - private final KieBaseTestConfiguration kieBaseTestConfiguration; - - public OOPathSmokeTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseConfigurations().stream(); } - @After + @AfterEach public void disposeKieSession() { if (this.kieSession != null) { this.kieSession.dispose(); @@ -68,14 +59,16 @@ public void disposeKieSession() { } } - @Test - public void testBuildKieBase() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testBuildKieBase(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBase kieBase = KieBaseUtil.getKieBaseFromClasspathResources(this.getClass(), kieBaseTestConfiguration, "oopath.drl"); assertThat(kieBase).isNotNull(); } - @Test + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") public void testBuildTwoKieBases() { final Resource drlResource = KIE_SERVICES.getResources().newClassPathResource("oopath.drl", this.getClass()); KieUtil.getKieModuleFromResources(RELEASE_ID, KieBaseTestConfiguration.CLOUD_IDENTITY, drlResource); @@ -88,8 +81,9 @@ public void testBuildTwoKieBases() { } } - @Test - public void testFireRule() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testFireRule(KieBaseTestConfiguration kieBaseTestConfiguration) { final KieBase kieBase = KieBaseUtil.getKieBaseFromClasspathResources(this.getClass(), kieBaseTestConfiguration, "oopath.drl"); this.kieSession = kieBase.newKieSession(); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/DrlParserTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/DrlParserTest.java index 9aa85201e2a..22fd5520ef6 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/DrlParserTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/DrlParserTest.java @@ -19,28 +19,28 @@ package org.drools.testcoverage.functional.parser; import java.io.File; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.junit.runners.Parameterized.Parameters; import org.kie.api.KieServices; import org.kie.api.io.Resource; public class DrlParserTest extends ParserTest { - public DrlParserTest(final File file, final KieBaseTestConfiguration kieBaseTestConfiguration) { - super(file, kieBaseTestConfiguration); - } @Parameters(name = "{index}: {0}, {1}") - public static Collection getParameters() { - return getTestParamsFromFiles(getFiles("drl")); + public static Stream parameters() { + return getTestParamsFromFiles(getFiles("drl")).stream(); } - @Test - public void testParserSmoke() { + @ParameterizedTest(name = "{index}: {0}, {1}") + @MethodSource("parameters") + public void testParserSmoke(File file, KieBaseTestConfiguration kieBaseTestConfiguration) { final Resource fileResource = KieServices.Factory.get().getResources().newFileSystemResource(file); KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, true, fileResource); } diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/DslParserTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/DslParserTest.java index 7c0001b40aa..b2d0335a9ef 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/DslParserTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/DslParserTest.java @@ -22,47 +22,48 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.junit.runners.Parameterized.Parameters; import org.kie.api.KieServices; import org.kie.api.io.Resource; -public class DslParserTest extends ParserTest { - private final File dsl; +import static org.junit.jupiter.params.provider.Arguments.arguments; - public DslParserTest(final File dslr, final File dsl, final KieBaseTestConfiguration kieBaseTestConfiguration) { - super(dslr, kieBaseTestConfiguration); - this.dsl = dsl; - } +public class DslParserTest extends ParserTest { @Parameters - public static Collection getParameters() { - final Set set = new HashSet<>(); + public static Stream parameters() { + final Set set = new HashSet<>(); for (File f : getFiles("dsl", "dslr")) { final String dslPath = f.getAbsolutePath(); final File dsl = new File(dslPath.substring(0, dslPath.length() - 1)); - set.add(new Object[] {dsl, f, KieBaseTestConfiguration.CLOUD_EQUALITY}); - set.add(new Object[]{dsl, f, KieBaseTestConfiguration.CLOUD_EQUALITY_MODEL_PATTERN}); + set.add(arguments(dsl, f, KieBaseTestConfiguration.CLOUD_EQUALITY)); + set.add(arguments(dsl, f, KieBaseTestConfiguration.CLOUD_EQUALITY_MODEL_PATTERN)); } - return set; + return set.stream(); } - @Test - public void testParserDsl() { + @ParameterizedTest + @MethodSource("parameters") + public void testParserDsl(File dslr, File dsl, KieBaseTestConfiguration kieBaseTestConfiguration) { final Resource dslResource = KieServices.Factory.get().getResources().newFileSystemResource(dsl); - final Resource dslrResource = KieServices.Factory.get().getResources().newFileSystemResource(file); + final Resource dslrResource = KieServices.Factory.get().getResources().newFileSystemResource(dslr); KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, true, dslResource, dslrResource); } - @Test - public void testParserDsl2() { + @ParameterizedTest + @MethodSource("parameters") + public void testParserDsl2(File dslr, File dsl, KieBaseTestConfiguration kieBaseTestConfiguration) { final Resource dslResource = KieServices.Factory.get().getResources().newFileSystemResource(dsl); - final Resource dslrResource = KieServices.Factory.get().getResources().newFileSystemResource(file); + final Resource dslrResource = KieServices.Factory.get().getResources().newFileSystemResource(dslr); KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, true, dslrResource, dslResource); } } diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/ParserTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/ParserTest.java index 73433ea58f3..acc977b85d6 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/ParserTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/ParserTest.java @@ -26,8 +26,9 @@ import java.util.Set; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.provider.Arguments; + +import static org.junit.jupiter.params.provider.Arguments.arguments; /** * Tests ability to parse resources. To add a test to this class simply add a @@ -40,20 +41,10 @@ * new folder can be added * */ -@RunWith(Parameterized.class) public abstract class ParserTest { private static final String PARSER_RESOURCES_DIR_PATH = "src/test/resources/org/drools/testcoverage/functional/parser"; private static final File PARSER_RESOURCES_DIR = new File(PARSER_RESOURCES_DIR_PATH); - protected final File file; - - protected final KieBaseTestConfiguration kieBaseTestConfiguration; - - public ParserTest(final File file, final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.file = file; - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - protected static List getFiles(final String directory) { return getFiles(directory, null); } @@ -73,12 +64,12 @@ protected static List getFiles(final String directory, final String extens return result; } - protected static Collection getTestParamsFromFiles(Collection files) { - final Set set = new HashSet<>(); + protected static Collection getTestParamsFromFiles(Collection files) { + final Set set = new HashSet<>(); for (File file : files) { - set.add(new Object[] {file, KieBaseTestConfiguration.CLOUD_EQUALITY}); - set.add(new Object[]{file, KieBaseTestConfiguration.CLOUD_EQUALITY_MODEL_PATTERN}); + set.add(arguments(file, KieBaseTestConfiguration.CLOUD_EQUALITY)); + set.add(arguments(file, KieBaseTestConfiguration.CLOUD_EQUALITY_MODEL_PATTERN)); } return set; diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/SmokeParserTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/SmokeParserTest.java index a323631bb89..014e154f464 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/SmokeParserTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/functional/parser/SmokeParserTest.java @@ -19,12 +19,13 @@ package org.drools.testcoverage.functional.parser; import java.io.File; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -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.KieServices; import org.kie.api.io.Resource; import org.slf4j.Logger; @@ -36,17 +37,13 @@ public class SmokeParserTest extends ParserTest { private static int count = 0; - public SmokeParserTest(final File file, final KieBaseTestConfiguration kieBaseTestConfiguration) { - super(file, kieBaseTestConfiguration); + public static Stream parameters() { + return getTestParamsFromFiles(getFiles("smoke")).stream(); } - @Parameters - public static Collection getParameters() { - return getTestParamsFromFiles(getFiles("smoke")); - } - - @Test - public void testParserSmoke() { + @ParameterizedTest + @MethodSource("parameters") + public void testParserSmoke(File file, KieBaseTestConfiguration kieBaseTestConfiguration) { LOGGER.warn(count++ + " : " + file.getName()); final Resource fileResource = KieServices.Factory.get().getResources().newFileSystemResource(file); KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, true, fileResource); From b5a22b9c617a4912409c050164ca0d8798a49d1a Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Wed, 20 Nov 2024 10:20:45 +0100 Subject: [PATCH 5/6] Migrated test suite to JUnit5 --- drools-test-coverage/test-suite/pom.xml | 23 ++----- .../testcoverage/common/KieSessionTest.java | 20 ++----- .../common/util/TestParametersUtil2.java | 19 +++--- .../memory/KieScannerMemoryTest.java | 17 +++--- .../regression/AmbiguousExceptionTest.java | 2 - .../regression/EqualityKeyOverrideTest.java | 26 ++++---- .../regression/GlobalOnLHSTest.java | 27 ++++----- .../regression/InternalMatchTest.java | 24 ++++---- .../LogicalInsertionsSerializationTest.java | 35 +++++------ .../MultiRestrictionPatternTest.java | 46 +++++++------- .../MultipleSalienceUpdateFactTest.java | 28 ++++----- .../MvelOverloadedMethodsUsageTest.java | 26 ++++---- .../regression/NotInFusionTest.java | 60 ++++++++++++------- .../SerializableInstantiationTest.java | 24 ++++---- .../regression/StarImportTest.java | 28 ++++----- 15 files changed, 188 insertions(+), 217 deletions(-) diff --git a/drools-test-coverage/test-suite/pom.xml b/drools-test-coverage/test-suite/pom.xml index 209e64e4e09..9947867730f 100644 --- a/drools-test-coverage/test-suite/pom.xml +++ b/drools-test-coverage/test-suite/pom.xml @@ -170,25 +170,10 @@ - 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.junit.jupiter + junit-jupiter + test + org.mockito mockito-core diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/common/KieSessionTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/common/KieSessionTest.java index 403ba5ae61a..bf47781778f 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/common/KieSessionTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/common/KieSessionTest.java @@ -20,29 +20,17 @@ import org.drools.testcoverage.common.listener.TrackingAgendaEventListener; import org.drools.testcoverage.common.util.*; -import org.junit.After; -import org.junit.Before; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterEach; import org.kie.api.io.Resource; -@RunWith(Parameterized.class) public abstract class KieSessionTest { - protected final KieBaseTestConfiguration kieBaseTestConfiguration; - protected final KieSessionTestConfiguration kieSessionTestConfiguration; - protected Session session; protected TrackingAgendaEventListener firedRules; - public KieSessionTest(final KieBaseTestConfiguration kieBaseTestConfiguration, - final KieSessionTestConfiguration kieSessionTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - this.kieSessionTestConfiguration = kieSessionTestConfiguration; - } - @Before - public void createKieSession() { + public void createKieSession(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) { Resource[] resources = createResources(); if (resources == null) { session = KieSessionUtil.getKieSessionFromKieBaseModel(TestConstants.PACKAGE_REGRESSION, @@ -55,7 +43,7 @@ public void createKieSession() { session.addEventListener(firedRules); } - @After + @AfterEach public void disposeKieSession() { if (session != null) { session.dispose(); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/common/util/TestParametersUtil2.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/common/util/TestParametersUtil2.java index 46011c70122..69674624ba4 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/common/util/TestParametersUtil2.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/common/util/TestParametersUtil2.java @@ -27,6 +27,9 @@ import java.util.stream.Collectors; import org.drools.model.codegen.ExecutableModelProject; +import org.junit.jupiter.params.provider.Arguments; + +import static org.junit.jupiter.params.provider.Arguments.arguments; /** * Utility class that holds default tests parameters. @@ -229,13 +232,13 @@ public static Collection getKieBaseAndKieSessionConfigurations() { * Use only stateful kie sessions. * @return Collection of combinations for parameterized tests. */ - public static Collection getKieBaseAndStatefulKieSessionConfigurations() { - final Collection parameters = new ArrayList<>(); + public static Collection getKieBaseAndStatefulKieSessionConfigurations() { + final Collection parameters = new ArrayList<>(); final Collection kieBaseConfigurations = getKieBaseConfigurations(); for (final KieBaseTestConfiguration kieBaseConfigWrapped : kieBaseConfigurations) { - parameters.add(new Object[]{kieBaseConfigWrapped, KieSessionTestConfiguration.STATEFUL_REALTIME}); + parameters.add(arguments(kieBaseConfigWrapped, KieSessionTestConfiguration.STATEFUL_REALTIME)); if ((kieBaseConfigWrapped).isStreamMode()) { - parameters.add(new Object[]{kieBaseConfigWrapped, KieSessionTestConfiguration.STATEFUL_PSEUDO}); + parameters.add(arguments(kieBaseConfigWrapped, KieSessionTestConfiguration.STATEFUL_PSEUDO)); } } @@ -247,12 +250,12 @@ public static Collection getKieBaseAndStatefulKieSessionConfigurations * Use only stream kie bases and stateful kie sessions. * @return Collection of combinations for parameterized tests. */ - public static Collection getStreamKieBaseAndStatefulKieSessionConfigurations() { - final Collection parameters = new ArrayList<>(); + public static Collection getStreamKieBaseAndStatefulKieSessionConfigurations() { + final Collection parameters = new ArrayList<>(); final Collection kieBaseConfigurations = getKieBaseStreamConfigurations(true); for (final KieBaseTestConfiguration kieBaseConfigWrapped : kieBaseConfigurations) { - parameters.add(new Object[]{kieBaseConfigWrapped, KieSessionTestConfiguration.STATEFUL_REALTIME}); - parameters.add(new Object[]{kieBaseConfigWrapped, KieSessionTestConfiguration.STATEFUL_PSEUDO}); + parameters.add(arguments(kieBaseConfigWrapped, KieSessionTestConfiguration.STATEFUL_REALTIME)); + parameters.add(arguments(kieBaseConfigWrapped, KieSessionTestConfiguration.STATEFUL_PSEUDO)); } return parameters; diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/memory/KieScannerMemoryTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/memory/KieScannerMemoryTest.java index 6ab640b74a5..05dc3fde95d 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/memory/KieScannerMemoryTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/memory/KieScannerMemoryTest.java @@ -28,38 +28,35 @@ import org.drools.testcoverage.common.util.KieUtil; import org.drools.testcoverage.common.util.MavenUtil; import org.drools.testcoverage.common.util.TestConstants; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.Ignore; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieModule; import org.kie.api.builder.KieScanner; import org.kie.api.builder.ReleaseId; import org.kie.api.runtime.KieContainer; import org.kie.scanner.KieMavenRepository; -import org.kie.test.testcategory.TurtleTestCategory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.assertj.core.api.Assertions.assertThat; -@Ignore("DROOLS-3628 Ignoring, because it can be useful when run locally, however due to unpredictable GC behaviour, unstable in automation.") -@Category(TurtleTestCategory.class) +@Disabled("DROOLS-3628 Ignoring, because it can be useful when run locally, however due to unpredictable GC behaviour, unstable in automation.") public class KieScannerMemoryTest { private static final Logger logger = LoggerFactory.getLogger(KieScannerMemoryTest.class); private FileManager fileManager; - @Before + @BeforeEach public void setUp() throws Exception { this.fileManager = new FileManager(); this.fileManager.setUp(); } - @After + @AfterEach public void tearDown() throws Exception { this.fileManager.tearDown(); } diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AmbiguousExceptionTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AmbiguousExceptionTest.java index 197655bd2fb..69fce23b084 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AmbiguousExceptionTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/AmbiguousExceptionTest.java @@ -19,8 +19,6 @@ package org.drools.testcoverage.regression; import java.io.StringReader; - -import java.util.Collection; import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EqualityKeyOverrideTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EqualityKeyOverrideTest.java index e9249f8b4f5..6be29743c6d 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EqualityKeyOverrideTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/EqualityKeyOverrideTest.java @@ -18,15 +18,16 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.KieSessionTest; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieSessionTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.io.Resource; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; @@ -56,18 +57,15 @@ public class EqualityKeyOverrideTest extends KieSessionTest { " insertLogical(new Superclass());\n" + "end\n"; - public EqualityKeyOverrideTest(final KieBaseTestConfiguration kieBaseTestConfiguration, - final KieSessionTestConfiguration kieSessionTestConfiguration) { - super(kieBaseTestConfiguration, kieSessionTestConfiguration); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseAndStatefulKieSessionConfigurations().stream(); } - @Parameterized.Parameters(name = "{1}" + " (from " + "{0}" + ")") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseAndStatefulKieSessionConfigurations(); - } - - @Test - public void testEqualityOverride() { + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void testEqualityOverride(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); KieSession ksession = session.getStateful(); FactHandle string = ksession.insert("testString"); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/GlobalOnLHSTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/GlobalOnLHSTest.java index d2c514d50ec..084ed5b3762 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/GlobalOnLHSTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/GlobalOnLHSTest.java @@ -19,17 +19,18 @@ package org.drools.testcoverage.regression; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.testcoverage.common.KieSessionTest; import org.drools.testcoverage.common.model.Message; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieSessionTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.io.Resource; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; @@ -44,19 +45,15 @@ public class GlobalOnLHSTest extends KieSessionTest { private static final String DRL_FILE = "bz1019473.drl"; - public GlobalOnLHSTest(final KieBaseTestConfiguration kieBaseTestConfiguration, - final KieSessionTestConfiguration kieSessionTestConfiguration) { - super(kieBaseTestConfiguration, kieSessionTestConfiguration); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseAndStatefulKieSessionConfigurations().stream(); } - @Parameterized.Parameters(name = "{1}" + " (from " + "{0}" + ")") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseAndStatefulKieSessionConfigurations(); - } - - @Test - public void testNPEOnMutableGlobal() throws Exception { - + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void testNPEOnMutableGlobal(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) throws Exception { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); KieSession ksession = session.getStateful(); List context = new ArrayList(); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/InternalMatchTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/InternalMatchTest.java index cbd4ce061e7..0a984d1edb5 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/InternalMatchTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/InternalMatchTest.java @@ -22,8 +22,9 @@ import org.drools.testcoverage.common.model.Cheese; import org.drools.testcoverage.common.model.Person; import org.drools.testcoverage.common.util.*; -import org.junit.Test; -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.command.Command; import org.kie.api.event.rule.AfterMatchFiredEvent; import org.kie.api.event.rule.AgendaEventListener; @@ -33,8 +34,8 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import static org.drools.testcoverage.common.util.KieUtil.getCommands; import static org.mockito.Mockito.*; @@ -64,22 +65,19 @@ public class InternalMatchTest extends KieSessionTest { " LOGGER.debug(\"noop\");\n" + "end\n"; - public InternalMatchTest(final KieBaseTestConfiguration kieBaseTestConfiguration, - final KieSessionTestConfiguration kieSessionTestConfiguration) { - super(kieBaseTestConfiguration, kieSessionTestConfiguration); - } - - @Parameterized.Parameters(name = "{1}" + " (from " + "{0}" + ")") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseAndKieSessionConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseAndStatefulKieSessionConfigurations().stream(); } /** * Tests improper deactivation of already activated rule on the agenda. See * BZ 862325. */ - @Test - public void noDormantCheckOnModifies() throws Exception { + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void noDormantCheckOnModifies(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) throws Exception { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); AgendaEventListener ael = mock(AgendaEventListener.class); session.addEventListener(ael); session.setGlobal("LOGGER", LOGGER); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/LogicalInsertionsSerializationTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/LogicalInsertionsSerializationTest.java index 82aa28cd3f7..7c9bf00f604 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/LogicalInsertionsSerializationTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/LogicalInsertionsSerializationTest.java @@ -23,18 +23,18 @@ import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.KieSessionTest; import org.drools.testcoverage.common.model.Promotion; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieSessionTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.api.io.TempDir; +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.io.Resource; import org.kie.api.marshalling.Marshaller; @@ -47,23 +47,20 @@ public class LogicalInsertionsSerializationTest extends KieSessionTest { private static final String DRL_FILE = "logical-insertion.drl"; - public LogicalInsertionsSerializationTest(final KieBaseTestConfiguration kieBaseTestConfiguration, - final KieSessionTestConfiguration kieSessionTestConfiguration) { - super(kieBaseTestConfiguration, kieSessionTestConfiguration); - } - - @Rule - public TestName name = new TestName(); + @TempDir + public File name; - @Parameterized.Parameters(name = "{1}" + " (from " + "{0}" + ")") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseAndStatefulKieSessionConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseAndStatefulKieSessionConfigurations().stream(); } - @Test - public void testSerializeAndDeserializeSession() throws Exception { + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void testSerializeAndDeserializeSession(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) throws Exception { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); KieSession ksession = session.getStateful(); - File tempFile = File.createTempFile(name.getMethodName(), null); + File tempFile = File.createTempFile("Junit5", "serializeAndDeserializeSession", name); ksession.fireAllRules(); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultiRestrictionPatternTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultiRestrictionPatternTest.java index b4c96864cb4..01fcb74a43c 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultiRestrictionPatternTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultiRestrictionPatternTest.java @@ -19,17 +19,18 @@ package org.drools.testcoverage.regression; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.testcoverage.common.KieSessionTest; import org.drools.testcoverage.common.model.Person; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieSessionTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.command.Command; import org.kie.api.io.Resource; @@ -41,21 +42,18 @@ * fixed */ public class MultiRestrictionPatternTest extends KieSessionTest { - + private static final String DRL_FILE = "BRMS-364.drl"; - public MultiRestrictionPatternTest(final KieBaseTestConfiguration kieBaseTestConfiguration, - final KieSessionTestConfiguration kieSessionTestConfiguration) { - super(kieBaseTestConfiguration, kieSessionTestConfiguration); - } - - @Parameterized.Parameters(name = "{1}" + " (from " + "{0}" + ")") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseAndStatefulKieSessionConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseAndStatefulKieSessionConfigurations().stream(); } - @Test - public void multiRestriction1() throws Exception { + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void multiRestriction1(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) throws Exception { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); List> commands = new ArrayList>(); commands.add(getCommands().newInsert(new Person("multi"))); commands.add(getCommands().newFireAllRules()); @@ -65,9 +63,12 @@ public void multiRestriction1() throws Exception { assertThat(firedRules.isRuleFired("or1")).isTrue(); } - @Test - public void multiRestriction2() throws Exception { - List> commands = new ArrayList>(); + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void multiRestriction2(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) throws Exception { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); + List> commands = new ArrayList>(); commands.add(getCommands().newInsert(new Person("MULTIRESTRICTION"))); commands.add(getCommands().newFireAllRules()); @@ -76,9 +77,12 @@ public void multiRestriction2() throws Exception { assertThat(firedRules.isRuleFired("or2")).isTrue(); } - @Test - public void multiRestriction3() throws Exception { - List> commands = new ArrayList>(); + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void multiRestriction3(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) throws Exception { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); + List> commands = new ArrayList>(); Person p = new Person(); p.setId(3); commands.add(getCommands().newInsert(p)); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultipleSalienceUpdateFactTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultipleSalienceUpdateFactTest.java index dc8d078fdda..717db29662a 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultipleSalienceUpdateFactTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MultipleSalienceUpdateFactTest.java @@ -20,8 +20,8 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.testcoverage.common.KieSessionTest; import org.drools.testcoverage.common.model.ListHolder; @@ -29,9 +29,10 @@ import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieSessionTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.command.Command; import org.kie.api.io.Resource; import org.slf4j.Logger; @@ -50,18 +51,15 @@ public class MultipleSalienceUpdateFactTest extends KieSessionTest { private static final String DRL_FILE = "BRMS-580.drl"; - public MultipleSalienceUpdateFactTest(final KieBaseTestConfiguration kieBaseTestConfiguration, - final KieSessionTestConfiguration kieSessionTestConfiguration) { - super(kieBaseTestConfiguration, kieSessionTestConfiguration); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseAndStatefulKieSessionConfigurations().stream(); } - - @Parameterized.Parameters(name = "{1}" + " (from " + "{0}" + ")") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseAndStatefulKieSessionConfigurations(); - } - - @Test - public void test() { + + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void test(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); session.setGlobal("LOGGER", LOGGER); List> commands = new ArrayList>(); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MvelOverloadedMethodsUsageTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MvelOverloadedMethodsUsageTest.java index 862c4d080fe..16d8ce8a25c 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MvelOverloadedMethodsUsageTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/MvelOverloadedMethodsUsageTest.java @@ -19,17 +19,18 @@ package org.drools.testcoverage.regression; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.testcoverage.common.KieSessionTest; import org.drools.testcoverage.common.model.Overloaded; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieSessionTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.command.Command; import org.kie.api.io.Resource; import org.kie.internal.command.CommandFactory; @@ -64,18 +65,15 @@ public class MvelOverloadedMethodsUsageTest extends KieSessionTest { " then\n" + "end\n"; - public MvelOverloadedMethodsUsageTest(final KieBaseTestConfiguration kieBaseTestConfiguration, - final KieSessionTestConfiguration kieSessionTestConfiguration) { - super(kieBaseTestConfiguration, kieSessionTestConfiguration); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseAndStatefulKieSessionConfigurations().stream(); } - @Parameterized.Parameters(name = "{1}" + " (from " + "{0}" + ")") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseAndKieSessionConfigurations(); - } - - @Test - public void testMvelOverloadedMethodsUsage() { + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void testMvelOverloadedMethodsUsage(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); List> commands = new ArrayList>(); commands.add(CommandFactory.newInsert(new Overloaded())); commands.add(CommandFactory.newFireAllRules()); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/NotInFusionTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/NotInFusionTest.java index 31d946e21d3..c367d6740c4 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/NotInFusionTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/NotInFusionTest.java @@ -18,15 +18,16 @@ */ package org.drools.testcoverage.regression; -import java.util.Collection; +import java.util.stream.Stream; import org.drools.testcoverage.common.KieSessionTest; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieSessionTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.definition.type.FactType; import org.kie.api.io.Resource; import org.kie.api.runtime.KieSession; @@ -42,26 +43,27 @@ public class NotInFusionTest extends KieSessionTest { private static final String RULE2 = "not equal 2"; private static final String RULE3 = "different"; - public NotInFusionTest(final KieBaseTestConfiguration kieBaseTestConfiguration, - final KieSessionTestConfiguration kieSessionTestConfiguration) { - super(kieBaseTestConfiguration, kieSessionTestConfiguration); - } - @Parameterized.Parameters(name = "{1}" + " (from " + "{0}" + ")") - public static Collection getParameters() { - return TestParametersUtil.getStreamKieBaseAndStatefulKieSessionConfigurations(); + public static Stream parameters() { + return TestParametersUtil2.getStreamKieBaseAndStatefulKieSessionConfigurations().stream(); } - @Test - public void testNoEvent() { + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void testNoEvent(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); KieSession ksession = session.getStateful(); ksession.fireAllRules(); assertThat(firedRules.isRuleFired(RULE1)).as(RULE1).isTrue(); } - @Test - public void testInsertFirst() throws Exception { + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void testInsertFirst(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) throws Exception { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); KieSession ksession = session.getStateful(); insertNotEvent(ksession); @@ -70,8 +72,11 @@ public void testInsertFirst() throws Exception { assertThat(firedRules.isRuleFired(RULE1)).as(RULE1).isFalse(); } - @Test - public void testInsertFirstAndAdd() throws Exception { + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void testInsertFirstAndAdd(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) throws Exception { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); KieSession ksession = session.getStateful(); insertNotEvent(ksession); @@ -87,8 +92,11 @@ public void testInsertFirstAndAdd() throws Exception { assertThat(firedRules.isRuleFired(RULE1)).as(RULE1).isTrue(); } - @Test - public void testInsertFirstAndAdd2() throws Exception { + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void testInsertFirstAndAdd2(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) throws Exception { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); KieSession ksession = session.getStateful(); insertNotEvent(ksession); @@ -105,8 +113,11 @@ public void testInsertFirstAndAdd2() throws Exception { assertThat(firedRules.isRuleFired(RULE1)).as(RULE1).isTrue(); } - @Test - public void testInsertFirstAndAdd3() throws Exception { + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void testInsertFirstAndAdd3(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) throws Exception { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); KieSession ksession = session.getStateful(); insertNotEvent(ksession); @@ -124,8 +135,11 @@ public void testInsertFirstAndAdd3() throws Exception { assertThat(firedRules.isRuleFired(RULE1)).as(RULE1).isTrue(); } - @Test - public void testNoEntryPoint() throws Exception { + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void testNoEntryPoint(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) throws Exception { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); KieSession ksession = session.getStateful(); ksession.insert(createNotEvent(ksession, "value")); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SerializableInstantiationTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SerializableInstantiationTest.java index b5a8c9c2f64..81b254416f4 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SerializableInstantiationTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/SerializableInstantiationTest.java @@ -20,17 +20,18 @@ import org.drools.testcoverage.common.KieSessionTest; import org.drools.testcoverage.common.util.*; -import org.junit.Test; -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.command.Command; import org.kie.api.io.Resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.Serializable; -import java.util.Collection; import java.util.LinkedList; import java.util.List; +import java.util.stream.Stream; import static org.drools.testcoverage.common.util.KieUtil.getCommands; @@ -49,18 +50,15 @@ public class SerializableInstantiationTest extends KieSessionTest { "// LOGGER.info(\"Works like a charm!\");\n" + "end\n"; - public SerializableInstantiationTest(final KieBaseTestConfiguration kieBaseTestConfiguration, - final KieSessionTestConfiguration kieSessionTestConfiguration) { - super(kieBaseTestConfiguration, kieSessionTestConfiguration); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseAndStatefulKieSessionConfigurations().stream(); } - @Parameterized.Parameters(name = "{1}" + " (from " + "{0}" + ")") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseAndKieSessionConfigurations(); - } - - @Test - public void testSerializableInstantiation() { + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void testSerializableInstantiation(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); session.setGlobal("LOGGER", LOGGER); List> commands = new LinkedList>(); commands.add(getCommands().newInsert(new SerializableWrapper("hello"))); diff --git a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/StarImportTest.java b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/StarImportTest.java index 0944a3b3c31..f5269f5d3f2 100644 --- a/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/StarImportTest.java +++ b/drools-test-coverage/test-suite/src/test/java/org/drools/testcoverage/regression/StarImportTest.java @@ -19,17 +19,18 @@ package org.drools.testcoverage.regression; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.testcoverage.common.KieSessionTest; import org.drools.testcoverage.common.model.TestEvent; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieSessionTestConfiguration; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.command.Command; import org.kie.api.event.rule.AfterMatchFiredEvent; import org.kie.api.event.rule.AgendaEventListener; @@ -55,24 +56,21 @@ public class StarImportTest extends KieSessionTest { private static final String DRL_FILE = "star_import.drl"; - public StarImportTest(final KieBaseTestConfiguration kieBaseTestConfiguration, - final KieSessionTestConfiguration kieSessionTestConfiguration) { - super(kieBaseTestConfiguration, kieSessionTestConfiguration); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseAndStatefulKieSessionConfigurations().stream(); } - - @Parameterized.Parameters(name = "{1}" + " (from " + "{0}" + ")") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseAndKieSessionConfigurations(); - } - /** * Tests that rule fires if supplied with a fact that is imported using * "star" import. * * See BZ 973264. */ - @Test - public void starImportedFactAlsoDeclaredInDRL() throws Exception { + + @ParameterizedTest(name = "{1}" + " (from " + "{0}" + ")") + @MethodSource("parameters") + public void starImportedFactAlsoDeclaredInDRL(KieBaseTestConfiguration kieBaseTestConfiguration, + KieSessionTestConfiguration kieSessionTestConfiguration) throws Exception { + createKieSession(kieBaseTestConfiguration, kieSessionTestConfiguration); session.setGlobal("LOGGER", LOGGER); AgendaEventListener ael = mock(AgendaEventListener.class); session.addEventListener(ael); From a0945e1356382704e21a63f1cafd659bc3ae7de0 Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Wed, 20 Nov 2024 10:50:29 +0100 Subject: [PATCH 6/6] More tests moved to JUnit5 --- .../kie-ci-with-domain/tests/pom.xml | 6 ++-- .../kieci/withdomain/KJarLoadingTest.java | 10 +++---- .../kie-ci-without-domain/tests/pom.xml | 6 ++-- .../kieci/withoutdomain/KJarLoadingTest.java | 10 +++---- .../test-integration-nomvel/pom.xml | 5 ++++ .../integrationtests/nomvel/TimerTest.java | 3 +- .../integrationtests/nomvel/VerifyTest.java | 2 +- .../test-integration-notms/pom.xml | 6 +++- .../integrationtests/notms/NoTmsTest.java | 30 ++++++++----------- .../test-integration-noxml/pom.xml | 10 +++---- .../integrationtests/noxml/CommandTest.java | 2 +- .../integrationtests/noxml/NoXmlTest.java | 2 +- 12 files changed, 48 insertions(+), 44 deletions(-) diff --git a/drools-test-coverage/standalone/kie-ci-with-domain/tests/pom.xml b/drools-test-coverage/standalone/kie-ci-with-domain/tests/pom.xml index 9b8ff7c8d4a..a844387f49c 100644 --- a/drools-test-coverage/standalone/kie-ci-with-domain/tests/pom.xml +++ b/drools-test-coverage/standalone/kie-ci-with-domain/tests/pom.xml @@ -98,10 +98,10 @@ test - junit - junit + org.junit.jupiter + junit-jupiter test - + diff --git a/drools-test-coverage/standalone/kie-ci-with-domain/tests/src/test/java/org/drools/testcoverage/kieci/withdomain/KJarLoadingTest.java b/drools-test-coverage/standalone/kie-ci-with-domain/tests/src/test/java/org/drools/testcoverage/kieci/withdomain/KJarLoadingTest.java index b445e929da1..8dcd61b7a5e 100644 --- a/drools-test-coverage/standalone/kie-ci-with-domain/tests/src/test/java/org/drools/testcoverage/kieci/withdomain/KJarLoadingTest.java +++ b/drools-test-coverage/standalone/kie-ci-with-domain/tests/src/test/java/org/drools/testcoverage/kieci/withdomain/KJarLoadingTest.java @@ -22,9 +22,9 @@ import org.drools.testcoverage.domain.Drink; import org.drools.testcoverage.domain.Order; import org.drools.testcoverage.kieci.withdomain.util.KJarLoadUtils; -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.api.Test; import org.kie.api.KieServices; import org.kie.api.builder.ReleaseId; import org.kie.api.runtime.KieContainer; @@ -45,13 +45,13 @@ public class KJarLoadingTest { private KieSession kieSession; - @Before + @BeforeEach public void init() { final KieContainer container = KS.newKieContainer(KJAR_RELEASE_ID, this.getClass().getClassLoader()); this.kieSession = container.newKieSession(); } - @After + @AfterEach public void dispose() { if (this.kieSession != null) { this.kieSession.dispose(); diff --git a/drools-test-coverage/standalone/kie-ci-without-domain/tests/pom.xml b/drools-test-coverage/standalone/kie-ci-without-domain/tests/pom.xml index 3a89a203fd9..c7c1e7bb0af 100644 --- a/drools-test-coverage/standalone/kie-ci-without-domain/tests/pom.xml +++ b/drools-test-coverage/standalone/kie-ci-without-domain/tests/pom.xml @@ -93,10 +93,10 @@ test - junit - junit + org.junit.jupiter + junit-jupiter test - + diff --git a/drools-test-coverage/standalone/kie-ci-without-domain/tests/src/test/java/org/drools/testcoverage/kieci/withoutdomain/KJarLoadingTest.java b/drools-test-coverage/standalone/kie-ci-without-domain/tests/src/test/java/org/drools/testcoverage/kieci/withoutdomain/KJarLoadingTest.java index 06a5f294f66..aecebd946d8 100644 --- a/drools-test-coverage/standalone/kie-ci-without-domain/tests/src/test/java/org/drools/testcoverage/kieci/withoutdomain/KJarLoadingTest.java +++ b/drools-test-coverage/standalone/kie-ci-without-domain/tests/src/test/java/org/drools/testcoverage/kieci/withoutdomain/KJarLoadingTest.java @@ -19,9 +19,9 @@ package org.drools.testcoverage.kieci.withoutdomain; import org.drools.testcoverage.kieci.withoutdomain.util.KJarLoadUtils; -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.api.Test; import org.kie.api.KieServices; import org.kie.api.builder.ReleaseId; import org.kie.api.runtime.KieContainer; @@ -42,13 +42,13 @@ public class KJarLoadingTest { private KieSession kieSession; - @Before + @BeforeEach public void init() { final KieContainer container = KS.newKieContainer(KJAR_RELEASE_ID); this.kieSession = container.newKieSession(); } - @After + @AfterEach public void dispose() { if (this.kieSession != null) { this.kieSession.dispose(); diff --git a/drools-test-coverage/test-integration-nomvel/pom.xml b/drools-test-coverage/test-integration-nomvel/pom.xml index 3472bf3087f..09a4e65fba9 100644 --- a/drools-test-coverage/test-integration-nomvel/pom.xml +++ b/drools-test-coverage/test-integration-nomvel/pom.xml @@ -79,6 +79,11 @@ test-jar test + + org.junit.jupiter + junit-jupiter + test + org.assertj diff --git a/drools-test-coverage/test-integration-nomvel/src/test/java/org/drools/compiler/integrationtests/nomvel/TimerTest.java b/drools-test-coverage/test-integration-nomvel/src/test/java/org/drools/compiler/integrationtests/nomvel/TimerTest.java index f31c25f1bd7..0922a34df74 100644 --- a/drools-test-coverage/test-integration-nomvel/src/test/java/org/drools/compiler/integrationtests/nomvel/TimerTest.java +++ b/drools-test-coverage/test-integration-nomvel/src/test/java/org/drools/compiler/integrationtests/nomvel/TimerTest.java @@ -27,7 +27,7 @@ import org.drools.core.ClockType; import org.drools.core.time.impl.PseudoClockScheduler; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieServices; import org.kie.api.builder.model.KieModuleModel; import org.kie.api.conf.EventProcessingOption; @@ -35,7 +35,6 @@ import org.kie.api.runtime.conf.ClockTypeOption; import org.kie.api.runtime.rule.FactHandle; import org.kie.api.time.Calendar; -import org.kie.api.time.SessionClock; import static org.assertj.core.api.Assertions.assertThat; import static org.drools.compiler.integrationtests.nomvel.TestUtil.getKieSession; diff --git a/drools-test-coverage/test-integration-nomvel/src/test/java/org/drools/compiler/integrationtests/nomvel/VerifyTest.java b/drools-test-coverage/test-integration-nomvel/src/test/java/org/drools/compiler/integrationtests/nomvel/VerifyTest.java index e41ad34bec3..bf857690360 100644 --- a/drools-test-coverage/test-integration-nomvel/src/test/java/org/drools/compiler/integrationtests/nomvel/VerifyTest.java +++ b/drools-test-coverage/test-integration-nomvel/src/test/java/org/drools/compiler/integrationtests/nomvel/VerifyTest.java @@ -19,7 +19,7 @@ package org.drools.compiler.integrationtests.nomvel; import org.drools.testcoverage.common.model.Person; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.builder.Results; import org.kie.api.runtime.KieContainer; diff --git a/drools-test-coverage/test-integration-notms/pom.xml b/drools-test-coverage/test-integration-notms/pom.xml index 4f51657a1e6..8ca004d44f6 100644 --- a/drools-test-coverage/test-integration-notms/pom.xml +++ b/drools-test-coverage/test-integration-notms/pom.xml @@ -84,7 +84,11 @@ test-jar test - + + org.junit.jupiter + junit-jupiter + test + org.assertj assertj-core diff --git a/drools-test-coverage/test-integration-notms/src/test/java/org/drools/compiler/integrationtests/notms/NoTmsTest.java b/drools-test-coverage/test-integration-notms/src/test/java/org/drools/compiler/integrationtests/notms/NoTmsTest.java index 097a5779c4d..0eb91b67b23 100644 --- a/drools-test-coverage/test-integration-notms/src/test/java/org/drools/compiler/integrationtests/notms/NoTmsTest.java +++ b/drools-test-coverage/test-integration-notms/src/test/java/org/drools/compiler/integrationtests/notms/NoTmsTest.java @@ -18,16 +18,15 @@ */ package org.drools.compiler.integrationtests.notms; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.drools.testcoverage.common.util.KieBaseTestConfiguration; import org.drools.testcoverage.common.util.KieBaseUtil; import org.drools.testcoverage.common.util.KieUtil; -import org.drools.testcoverage.common.util.TestParametersUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.drools.testcoverage.common.util.TestParametersUtil2; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.Message; @@ -35,21 +34,17 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(Parameterized.class) + public class NoTmsTest { - private final KieBaseTestConfiguration kieBaseTestConfiguration; - public NoTmsTest(final KieBaseTestConfiguration kieBaseTestConfiguration) { - this.kieBaseTestConfiguration = kieBaseTestConfiguration; - } - @Parameterized.Parameters(name = "KieBase type={0}") - public static Collection getParameters() { - return TestParametersUtil.getKieBaseCloudConfigurations(true); + public static Stream parameters() { + return TestParametersUtil2.getKieBaseCloudConfigurations(true).stream(); } - @Test - public void testUnsupportedTms() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testUnsupportedTms(KieBaseTestConfiguration kieBaseTestConfiguration) { String drl = "package org.drools.test; \n" + "" + @@ -70,8 +65,9 @@ public void testUnsupportedTms() { assertThat(errors.get(0).getText().contains("drools-tms")).isTrue(); } - @Test - public void testPlainInsert() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testPlainInsert(KieBaseTestConfiguration kieBaseTestConfiguration) { String drl = "package org.drools.test; \n" + "" + diff --git a/drools-test-coverage/test-integration-noxml/pom.xml b/drools-test-coverage/test-integration-noxml/pom.xml index a65f9429e32..579873e9314 100644 --- a/drools-test-coverage/test-integration-noxml/pom.xml +++ b/drools-test-coverage/test-integration-noxml/pom.xml @@ -45,11 +45,11 @@ drools-engine test - - junit - junit - test - + + org.junit.jupiter + junit-jupiter + test + org.assertj assertj-core diff --git a/drools-test-coverage/test-integration-noxml/src/test/java/org/drools/compiler/integrationtests/noxml/CommandTest.java b/drools-test-coverage/test-integration-noxml/src/test/java/org/drools/compiler/integrationtests/noxml/CommandTest.java index 07e8a754d38..c36e37218c6 100644 --- a/drools-test-coverage/test-integration-noxml/src/test/java/org/drools/compiler/integrationtests/noxml/CommandTest.java +++ b/drools-test-coverage/test-integration-noxml/src/test/java/org/drools/compiler/integrationtests/noxml/CommandTest.java @@ -22,7 +22,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.model.KieModuleModel; diff --git a/drools-test-coverage/test-integration-noxml/src/test/java/org/drools/compiler/integrationtests/noxml/NoXmlTest.java b/drools-test-coverage/test-integration-noxml/src/test/java/org/drools/compiler/integrationtests/noxml/NoXmlTest.java index 3a7a8145c6d..1322cbb09f5 100644 --- a/drools-test-coverage/test-integration-noxml/src/test/java/org/drools/compiler/integrationtests/noxml/NoXmlTest.java +++ b/drools-test-coverage/test-integration-noxml/src/test/java/org/drools/compiler/integrationtests/noxml/NoXmlTest.java @@ -19,7 +19,7 @@ package org.drools.compiler.integrationtests.noxml; 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.model.KieModuleModel;