From 7f5a23f908d4b36d0a3946a8bb56c35da424a0be Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Tue, 19 Nov 2024 15:16:28 +0100 Subject: [PATCH 01/12] More tests migrated --- .../regression/DeserializationWithCompositeTriggerTest.java | 1 + .../org/drools/testcoverage/regression/FixedPatternTest.java | 1 + 2 files changed, 2 insertions(+) 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 3d0dc37700b..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 @@ -94,6 +94,7 @@ 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 2ae5e7f56dc..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 @@ -56,6 +56,7 @@ public void cleanup() { /** * Tests fixed pattern without constraint in Decision table (BZ 1150308). + * @param kieBaseTestConfiguration */ @ParameterizedTest(name = "KieBase type={0}") @MethodSource("parameters") From 38e40e93d3b687554d1ea8e998d02cde19d8fb4f Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Tue, 19 Nov 2024 16:48:12 +0100 Subject: [PATCH 02/12] Migrated tests to Junit5 --- .../regression/DeserializationWithCompositeTriggerTest.java | 1 - .../org/drools/testcoverage/regression/FixedPatternTest.java | 1 - 2 files changed, 2 deletions(-) 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") From 4c97ec94ca5591249ec914d770b45c3805604899 Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Thu, 28 Nov 2024 15:33:53 +0100 Subject: [PATCH 03/12] Migrated serialization protobuf module --- drools-serialization-protobuf/pom.xml | 10 +- .../protobuf/EventAccessorRestoreTest.java | 24 ++-- .../protobuf/FactHandleMarshallingTest.java | 2 +- .../MarshalledInternalMatchSortTest.java | 3 +- .../protobuf/MarshallerTest.java | 107 +++++++++++------- .../protobuf/MarshallingTest.java | 24 ++-- .../ObjectMarshallingStrategyStoreTest.java | 2 +- .../ProtobufOutputMarshallerTest.java | 2 +- .../serialization/protobuf/QueryTest.java | 11 +- .../protobuf/TruthMaintenanceTest.java | 37 +++--- .../protobuf/UnmarshallingTest.java | 2 +- 11 files changed, 123 insertions(+), 101 deletions(-) diff --git a/drools-serialization-protobuf/pom.xml b/drools-serialization-protobuf/pom.xml index 728273f4cf4..5c2c4611fc0 100644 --- a/drools-serialization-protobuf/pom.xml +++ b/drools-serialization-protobuf/pom.xml @@ -93,16 +93,16 @@ commons-lang3 test + + org.junit.jupiter + junit-jupiter + test + org.assertj assertj-core test - - junit - junit - test - org.mockito mockito-core diff --git a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/EventAccessorRestoreTest.java b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/EventAccessorRestoreTest.java index dacb7ca5c6d..b4b3e97e1c6 100644 --- a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/EventAccessorRestoreTest.java +++ b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/EventAccessorRestoreTest.java @@ -19,19 +19,19 @@ package org.drools.serialization.protobuf; import java.io.EOFException; -import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import org.drools.base.common.DroolsObjectInputStream; import org.drools.base.common.DroolsObjectOutputStream; import org.drools.mvel.CommonTestMethodBase; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.kie.api.KieBase; import org.kie.api.marshalling.Marshaller; import org.kie.api.marshalling.ObjectMarshallingStrategy; @@ -44,14 +44,14 @@ public class EventAccessorRestoreTest extends CommonTestMethodBase { - @Rule - public TemporaryFolder temp = new TemporaryFolder(); + @TempDir + public Path temp; - private File kbaseFile = null; + private Path kbaseFile = null; private KieBase kbase; - @Before + @BeforeEach public void setUp() { String str = "package org.drools.test;\n" + @@ -80,8 +80,8 @@ public void setUp() { KieSession ksession = kbase.newKieSession(); try { - kbaseFile = temp.newFile( "test.bin" ); - FileOutputStream fos = new FileOutputStream( kbaseFile ) ; + kbaseFile = Files.createFile(temp.resolve("test.bin" )); + FileOutputStream fos = new FileOutputStream( kbaseFile.toFile() ) ; saveSession( fos, ksession ); fos.close(); } catch ( Exception e ) { @@ -123,7 +123,7 @@ public KieSession loadSession( FileInputStream input ) throws IOException, Class @Test public void testDeserialization() { try { - FileInputStream fis = new FileInputStream( kbaseFile ); + FileInputStream fis = new FileInputStream( kbaseFile.toFile() ); KieSession knowledgeSession = loadSession( fis ); ArrayList list = new ArrayList(); diff --git a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/FactHandleMarshallingTest.java b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/FactHandleMarshallingTest.java index 254f6beec3f..44e849c40aa 100644 --- a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/FactHandleMarshallingTest.java +++ b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/FactHandleMarshallingTest.java @@ -41,7 +41,7 @@ import org.drools.mvel.compiler.Person; import org.drools.serialization.protobuf.marshalling.ObjectMarshallingStrategyStoreImpl; import org.drools.util.StringUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieBaseConfiguration; import org.kie.api.conf.EventProcessingOption; import org.kie.api.marshalling.ObjectMarshallingStrategy; diff --git a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshalledInternalMatchSortTest.java b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshalledInternalMatchSortTest.java index 7b7e2cb3631..83538a96c4f 100644 --- a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshalledInternalMatchSortTest.java +++ b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshalledInternalMatchSortTest.java @@ -29,8 +29,7 @@ import org.drools.base.definitions.rule.impl.RuleImpl; import org.drools.core.reteoo.TupleImpl; import org.drools.core.rule.consequence.InternalMatch; -import org.drools.core.reteoo.Tuple; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; diff --git a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshallerTest.java b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshallerTest.java index 6b2a95f6e49..df518c80cda 100644 --- a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshallerTest.java +++ b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshallerTest.java @@ -23,16 +23,16 @@ import java.util.List; import java.util.Objects; import java.util.UUID; +import java.util.stream.Stream; import org.drools.core.common.InternalFactHandle; import org.drools.core.impl.EnvironmentFactory; import org.drools.core.marshalling.ClassObjectMarshallingStrategyAcceptor; import org.drools.serialization.protobuf.marshalling.JavaSerializableResolverStrategy; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.drools.core.marshalling.SerializablePlaceholderResolverStrategy; import org.drools.mvel.compiler.Person; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.kie.api.KieBase; import org.kie.api.conf.EqualityBehaviorOption; import org.kie.api.io.ResourceType; @@ -44,24 +44,23 @@ import static org.assertj.core.api.Assertions.assertThat; -@RunWith(Parameterized.class) public class MarshallerTest { - private Environment env; + private Environment env = EnvironmentFactory.newEnvironment(); - @Parameterized.Parameters(name = "{0}") - public static Object[] params() { - return new Object[] { new JavaSerializableResolverStrategy( ClassObjectMarshallingStrategyAcceptor.DEFAULT ), - new SerializablePlaceholderResolverStrategy( ClassObjectMarshallingStrategyAcceptor.DEFAULT ) }; + public static Stream parameters() { + return Stream.of(new JavaSerializableResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT), + new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT)); } - public MarshallerTest(ObjectMarshallingStrategy strategy) { - this.env = EnvironmentFactory.newEnvironment(); + private void setupEnvironment(ObjectMarshallingStrategy strategy) { this.env.set( EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[]{ strategy } ); } - @Test - public void testAgendaDoNotSerializeObject() throws Exception { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testAgendaDoNotSerializeObject(ObjectMarshallingStrategy strategy) throws Exception { + setupEnvironment(strategy); KieSession ksession = null; try { String str = @@ -96,8 +95,10 @@ public void testAgendaDoNotSerializeObject() throws Exception { } } - @Test - public void testFromWithFireBeforeSerialization() throws Exception { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testFromWithFireBeforeSerialization(ObjectMarshallingStrategy strategy) throws Exception { + setupEnvironment(strategy); String str = "import java.util.Collection\n" + "rule R1 when\n" + @@ -121,8 +122,10 @@ public void testFromWithFireBeforeSerialization() throws Exception { } } - @Test - public void testFromWithFireAfterSerialization() throws Exception { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testFromWithFireAfterSerialization(ObjectMarshallingStrategy strategy) throws Exception { + setupEnvironment(strategy); String str = "import java.util.Collection\n" + "rule R1 when\n" + @@ -145,8 +148,10 @@ public void testFromWithFireAfterSerialization() throws Exception { } } - @Test - public void testFromWithPartialFiring() throws Exception { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testFromWithPartialFiring(ObjectMarshallingStrategy strategy) throws Exception { + setupEnvironment(strategy); String str = "import java.util.Collection\n" + "rule R1 when\n" + @@ -170,8 +175,10 @@ public void testFromWithPartialFiring() throws Exception { } } - @Test - public void test2FromsWithPartialFiring() throws Exception { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void test2FromsWithPartialFiring(ObjectMarshallingStrategy strategy) throws Exception { + setupEnvironment(strategy); String str = "import java.util.Collection\n" + "rule R1 when\n" + @@ -196,8 +203,10 @@ public void test2FromsWithPartialFiring() throws Exception { } } - @Test - public void testFromAndJoinWithPartialFiring() throws Exception { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testFromAndJoinWithPartialFiring(ObjectMarshallingStrategy strategy) throws Exception { + setupEnvironment(strategy); String str = "import java.util.Collection\n" + "rule R1 when\n" + @@ -223,9 +232,10 @@ public void testFromAndJoinWithPartialFiring() throws Exception { } } - @Test - public void testAgendaReconciliationAccumulate() throws Exception { - + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testAgendaReconciliationAccumulate(ObjectMarshallingStrategy strategy) throws Exception { + setupEnvironment(strategy); String str = "import " + Person.class.getCanonicalName() + ";" + "rule X when\n" + @@ -257,10 +267,11 @@ public void testAgendaReconciliationAccumulate() throws Exception { } } - @Test - public void testAgendaReconciliationAccumulate2() throws Exception { - - String str = + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testAgendaReconciliationAccumulate2(ObjectMarshallingStrategy strategy) throws Exception { + setupEnvironment(strategy); + String str = "import " + Person.class.getCanonicalName() + ";" + "rule X when\n" + " accumulate ( $p: Person ( getName().startsWith(\"M\")); \n" + @@ -289,10 +300,12 @@ public void testAgendaReconciliationAccumulate2() throws Exception { } } - @Test - public void testMultiAccumulate() throws Exception { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testMultiAccumulate(ObjectMarshallingStrategy strategy) throws Exception { // DROOLS-5579 - String str = + setupEnvironment(strategy); + String str = "import " + Person.class.getCanonicalName() + ";" + "rule X when\n" + " accumulate ( Person ( getName().startsWith(\"M\"), $age : age ); \n" + @@ -323,9 +336,11 @@ public void testMultiAccumulate() throws Exception { } } - @Test - public void testSubnetwork() throws Exception { - final String str = + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testSubnetwork(ObjectMarshallingStrategy strategy) throws Exception { + setupEnvironment(strategy); + final String str = "rule R1 when\n" + " String()\n" + " Long()\n" + @@ -361,9 +376,11 @@ public void testSubnetwork() throws Exception { } } - @Test - public void testSubnetwork2() throws Exception { - final String str = + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testSubnetwork2(ObjectMarshallingStrategy strategy) throws Exception { + setupEnvironment(strategy); + final String str = "rule R1 when\n" + " String()\n" + " Long()\n" + @@ -394,8 +411,10 @@ public void testSubnetwork2() throws Exception { } } - @Test - public void testFromJoinWithPartialFiring() throws Exception { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testFromJoinWithPartialFiring(ObjectMarshallingStrategy strategy) throws Exception { + setupEnvironment(strategy); String str = "import java.util.Collection\n" + "rule R1 when\n" + @@ -489,9 +508,11 @@ public int hashCode() { } } - @Test - public void testFromWithInsertLogical() throws Exception { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testFromWithInsertLogical(ObjectMarshallingStrategy strategy) throws Exception { // DROOLS-5713 + setupEnvironment(strategy); String str = "import " + LongFact.class.getCanonicalName() + "\n" + "import " + LongFacts.class.getCanonicalName() + "\n" + diff --git a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshallingTest.java b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshallingTest.java index 97e72f878d0..f80c8a7ee42 100644 --- a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshallingTest.java +++ b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/MarshallingTest.java @@ -32,8 +32,6 @@ import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import java.util.jar.JarEntry; -import java.util.jar.JarInputStream; import org.drools.base.base.ClassObjectType; import org.drools.base.base.ValueResolver; @@ -41,7 +39,6 @@ import org.drools.base.common.DroolsObjectOutputStream; import org.drools.base.definitions.InternalKnowledgePackage; import org.drools.base.definitions.rule.impl.RuleImpl; -import org.drools.base.rule.MapBackedClassLoader; import org.drools.base.rule.consequence.Consequence; import org.drools.base.rule.consequence.ConsequenceContext; import org.drools.core.ClockType; @@ -77,8 +74,9 @@ import org.drools.mvel.integrationtests.IteratorToList; import org.drools.serialization.protobuf.marshalling.IdentityPlaceholderResolverStrategy; import org.drools.serialization.protobuf.marshalling.RuleBaseNodes; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +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; @@ -101,8 +99,6 @@ import org.kie.api.runtime.conf.TimerJobFactoryOption; import org.kie.api.runtime.rule.EntryPoint; import org.kie.api.time.SessionPseudoClock; -import org.kie.internal.builder.KnowledgeBuilderConfiguration; -import org.kie.internal.builder.KnowledgeBuilderFactory; import org.kie.internal.marshalling.MarshallerFactory; import org.kie.internal.utils.KieHelper; @@ -1843,7 +1839,8 @@ public void testAccumulateSessionSerialization() throws Exception { * * @throws Exception */ - @Test @Ignore + @Test + @Disabled public void testDroolsObjectOutputInputStream() throws Exception { KieBase kbase = loadKnowledgeBase("org/drools/compiler/integrationtests/test_Serializable.drl" ); KieSession session = kbase.newKieSession(); @@ -1992,7 +1989,8 @@ public void testMarshallEvents() throws Exception { assertThat(ksession.getObjects().size()).isEqualTo(2); } - @Test @Ignore("This test is suspicious to say the least...") + @Test + @Disabled("This test is suspicious to say the least...") public void testScheduledActivation() { InternalKnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase(); InternalKnowledgePackage impl = CoreComponentFactory.get().createKnowledgePackage( "test" ); @@ -2223,7 +2221,8 @@ public void testMarshallEntryPointsWithNot() throws Exception { assertThat(list.size()).isEqualTo(0); } - @Test @Ignore("beta4 phreak") + @Test + @Disabled("beta4 phreak") public void testMarshallEntryPointsWithSlidingTimeWindow() throws Exception { String str = "package org.domain.test \n" + @@ -2515,7 +2514,7 @@ public void testMarshallWithTimedRule() { } @Test - @Ignore("Reproduces with pseudoclock. It takes too long with system clock") + @Disabled("Reproduces with pseudoclock. It takes too long with system clock") public void testMarshallWithTimedRuleRealClock() { // DROOLS-795 String drl = "rule \"Rule A Timeout\"\n" + @@ -2765,7 +2764,8 @@ public void setJob( String job ) { } } - @Test(timeout = 10_000L) + @Test + @Timeout(10000) public void testDisposeAfterMarshall() throws InterruptedException, IOException { // DROOLS-4413 diff --git a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/ObjectMarshallingStrategyStoreTest.java b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/ObjectMarshallingStrategyStoreTest.java index 754043397af..e32f198d3c9 100644 --- a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/ObjectMarshallingStrategyStoreTest.java +++ b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/ObjectMarshallingStrategyStoreTest.java @@ -32,7 +32,7 @@ import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.kiesession.rulebase.KnowledgeBaseFactory; import org.drools.serialization.protobuf.marshalling.IdentityPlaceholderResolverStrategy; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieBaseConfiguration; import org.kie.api.KieServices; import org.kie.api.conf.EventProcessingOption; diff --git a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/ProtobufOutputMarshallerTest.java b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/ProtobufOutputMarshallerTest.java index 987e6148471..519e57cc4c5 100644 --- a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/ProtobufOutputMarshallerTest.java +++ b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/ProtobufOutputMarshallerTest.java @@ -24,7 +24,7 @@ import org.drools.core.common.DefaultFactHandle; import org.drools.core.common.InternalFactHandle; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/QueryTest.java b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/QueryTest.java index fbf4b1ba491..7b1c4e7bab4 100644 --- a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/QueryTest.java +++ b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/QueryTest.java @@ -30,9 +30,7 @@ import org.drools.core.runtime.rule.impl.FlatQueryResultRow; import org.drools.mvel.CommonTestMethodBase; import org.drools.mvel.compiler.Cheese; -import org.junit.Before; -import org.junit.Test; -import org.junit.rules.TestName; +import org.junit.jupiter.api.Test; import org.kie.api.KieBase; import org.kie.api.definition.rule.Rule; import org.kie.api.runtime.KieSession; @@ -44,13 +42,6 @@ public class QueryTest extends CommonTestMethodBase { - @org.junit.Rule - public TestName testName = new TestName(); - - @Before - public void before() { - System.out.println( "] " + testName.getMethodName()); - } private static QueryResults getQueryResults(KieSession session, String queryName, Object... arguments ) throws Exception { QueryResultsImpl results = (QueryResultsImpl) session.getQueryResults( queryName, arguments ); diff --git a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/TruthMaintenanceTest.java b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/TruthMaintenanceTest.java index 24ede56803d..b3a81cf5d16 100644 --- a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/TruthMaintenanceTest.java +++ b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/TruthMaintenanceTest.java @@ -38,8 +38,9 @@ import org.drools.mvel.compiler.CheeseEqual; import org.drools.mvel.compiler.Person; import org.drools.mvel.compiler.Sensor; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; import org.kie.api.KieBase; import org.kie.api.definition.KiePackage; import org.kie.api.io.ResourceType; @@ -211,7 +212,8 @@ public void testLogicalInsertionsDynamicRule() throws Exception { } } - @Test(timeout=10000) + @Test + @Timeout(10000) public void testLogicalInsertions() throws Exception { final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertions.drl", @@ -263,7 +265,8 @@ public void testLogicalInsertions() throws Exception { } } - @Test(timeout=10000) + @Test + @Timeout(10000) public void testLogicalInsertionsBacking() throws Exception { final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ResourceFactory.newClassPathResource( "test_LogicalInsertionsBacking.drl", @@ -328,7 +331,8 @@ public void testLogicalInsertionsBacking() throws Exception { } } - @Test(timeout=10000) + @Test + @Timeout(10000) //@Ignore("in Java 8, the byte[] generated by serialization are not the same and requires investigation") public void testLogicalInsertionsWithModify() throws Exception { KieBase kbase = loadKnowledgeBase("test_LogicalInsertionsWithUpdate.drl"); @@ -364,7 +368,8 @@ public void testLogicalInsertionsWithModify() throws Exception { } } - @Test(timeout=10000) + @Test + @Timeout(10000) public void testLogicalInsertions2() throws Exception { KieBase kbase = loadKnowledgeBase("test_LogicalInsertions2.drl"); KieSession ksession = kbase.newKieSession(); @@ -408,7 +413,8 @@ public void testLogicalInsertions2() throws Exception { } } - @Test(timeout=10000) + @Test + @Timeout(10000) //@Ignore("in Java 8, the byte[] generated by serialization are not the same and requires investigation") public void testLogicalInsertionsNot() throws Exception { KieBase kbase = loadKnowledgeBase("test_LogicalInsertionsNot.drl"); @@ -456,8 +462,9 @@ public void testLogicalInsertionsNot() throws Exception { } } - @Test(timeout=10000) - @Ignore("Currently cannot support updates") + @Test + @Timeout(10000) + @Disabled("Currently cannot support updates") //@Ignore("in Java 8, the byte[] generated by serialization are not the same and requires investigation") public void testLogicalInsertionsUpdateEqual() throws Exception { // calling update on a justified FH, states it @@ -503,7 +510,8 @@ public void testLogicalInsertionsUpdateEqual() throws Exception { } } - @Test(timeout=10000) + @Test + @Timeout(10000) //@Ignore("in Java 8, the byte[] generated by serialization are not the same and requires investigation") public void testLogicalInsertionsWithExists() throws Exception { KieBase kbase = loadKnowledgeBase("test_LogicalInsertionWithExists.drl"); @@ -602,7 +610,8 @@ public void testLogicalInsertionsWithExists() throws Exception { } } - @Test(timeout=10000) + @Test + @Timeout(10000) public void testLogicalInsertions3() throws Exception { KieBase kbase = loadKnowledgeBase("test_logicalInsertions3.drl"); KieSession ksession = kbase.newKieSession(); @@ -650,7 +659,8 @@ public void testLogicalInsertions3() throws Exception { } } - @Test(timeout=10000) + @Test + @Timeout(10000) public void testLogicalInsertionsAccumulatorPattern() throws Exception { // JBRULES-449 KieBase kbase = loadKnowledgeBase( "test_LogicalInsertionsAccumulatorPattern.drl" ); @@ -692,7 +702,8 @@ public void testLogicalInsertionsAccumulatorPattern() throws Exception { } } - @Test(timeout=10000) + @Test + @Timeout(10000) public void testLogicalInsertionsModifySameRuleGivesDifferentLogicalInsertion() throws Exception { // TODO JBRULES-1804 diff --git a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/UnmarshallingTest.java b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/UnmarshallingTest.java index cfb2ca99a71..d4338f631fb 100644 --- a/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/UnmarshallingTest.java +++ b/drools-serialization-protobuf/src/test/java/org/drools/serialization/protobuf/UnmarshallingTest.java @@ -26,7 +26,7 @@ import org.drools.core.impl.RuleBaseFactory; import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.kiesession.rulebase.KnowledgeBaseFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.api.KieBase; import org.kie.api.KieBaseConfiguration; import org.kie.api.KieServices; From 74120cbc266b2ceaf503dd2a7e8f5e8012422f59 Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Thu, 28 Nov 2024 15:35:03 +0100 Subject: [PATCH 04/12] Migrated drools-ecj --- drools-ecj/pom.xml | 10 +++++----- .../test/java/org/drools/ecj/JavaCompilerI18NTest.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drools-ecj/pom.xml b/drools-ecj/pom.xml index 1393a5669d0..0f64225390b 100644 --- a/drools-ecj/pom.xml +++ b/drools-ecj/pom.xml @@ -49,11 +49,11 @@ ecj - - junit - junit - test - + + org.junit.jupiter + junit-jupiter + test + org.assertj assertj-core diff --git a/drools-ecj/src/test/java/org/drools/ecj/JavaCompilerI18NTest.java b/drools-ecj/src/test/java/org/drools/ecj/JavaCompilerI18NTest.java index c2db63729d0..2ed1f3fbd49 100644 --- a/drools-ecj/src/test/java/org/drools/ecj/JavaCompilerI18NTest.java +++ b/drools-ecj/src/test/java/org/drools/ecj/JavaCompilerI18NTest.java @@ -21,10 +21,10 @@ import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.Test; import org.kie.memorycompiler.CompilationResult; import org.kie.memorycompiler.resources.MemoryResourceReader; import org.kie.memorycompiler.resources.MemoryResourceStore; -import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; From fe6c27a4e548ec9840e602e119b0cf5be931555f Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Fri, 29 Nov 2024 16:05:42 +0100 Subject: [PATCH 05/12] Migrated drools persistance --- .../drools-persistence-jpa/pom.xml | 6 +- .../TransactionManagerFactoryTest.java | 6 +- .../MoreBatchExecutionPersistenceTest.java | 47 +++---- .../SimpleBatchExecutionPersistenceTest.java | 86 ++++++------ .../jta/JtaTransactionManagerFactoryTest.java | 6 +- .../jta/JtaTransactionManagerTest.java | 10 +- .../JpaPersistentStatefulSessionTest.java | 112 ++++++++------- .../session/PersistentSessionForallTest.java | 46 +++---- .../map/impl/JpaBasedPersistenceTest.java | 32 ++--- .../map/impl/MapBasedPersistenceTest.java | 14 +- .../map/impl/MapPersistenceTest.java | 35 ++--- ...MonitoringWithJPAKnowledgeServiceTest.java | 10 +- .../session/AgendaRuleFlowGroupsTest.java | 60 ++++----- ...aOptLockPersistentStatefulSessionTest.java | 10 +- .../JpaPersistentStatefulSessionTest.java | 127 ++++++++++-------- .../session/ReloadSessionTest.java | 68 +++++----- .../session/RuleFlowGroupRollbackTest.java | 43 +++--- .../TimerAndCalendarTest.java | 64 ++++----- 18 files changed, 374 insertions(+), 408 deletions(-) diff --git a/drools-persistence/drools-persistence-jpa/pom.xml b/drools-persistence/drools-persistence-jpa/pom.xml index 17680599b83..914db801384 100644 --- a/drools-persistence/drools-persistence-jpa/pom.xml +++ b/drools-persistence/drools-persistence-jpa/pom.xml @@ -254,7 +254,11 @@ - + + org.junit.jupiter + junit-jupiter + test + org.assertj assertj-core diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/TransactionManagerFactoryTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/TransactionManagerFactoryTest.java index 51851a96b2e..2528568d053 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/TransactionManagerFactoryTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/TransactionManagerFactoryTest.java @@ -23,8 +23,8 @@ import org.drools.persistence.api.TransactionManagerFactory; import org.drools.persistence.jta.JtaTransactionManager; import org.drools.persistence.jta.JtaTransactionManagerFactory; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.kie.api.runtime.Environment; import static org.assertj.core.api.Assertions.assertThat; @@ -34,7 +34,7 @@ public class TransactionManagerFactoryTest { TransactionManagerFactory transactionManagerFactory = getTransactionManagerFactory(); - @After + @AfterEach public void cleanup() { System.clearProperty("org.kie.txm.factory.class"); transactionManagerFactory.resetInstance(); diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/command/MoreBatchExecutionPersistenceTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/command/MoreBatchExecutionPersistenceTest.java index a0864484736..6c96d9eecce 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/command/MoreBatchExecutionPersistenceTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/command/MoreBatchExecutionPersistenceTest.java @@ -23,18 +23,16 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import org.drools.core.impl.RuleBaseFactory; import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.kiesession.rulebase.KnowledgeBaseFactory; -import org.drools.mvel.CommonTestMethodBase; import org.drools.mvel.compiler.Cheese; import org.drools.persistence.util.DroolsPersistenceUtil; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.command.Command; import org.kie.api.io.ResourceType; @@ -59,29 +57,18 @@ import static org.drools.persistence.util.DroolsPersistenceUtil.cleanUp; import static org.drools.persistence.util.DroolsPersistenceUtil.createEnvironment; -@RunWith(Parameterized.class) -public class MoreBatchExecutionPersistenceTest extends CommonTestMethodBase { +public class MoreBatchExecutionPersistenceTest { private KieSession ksession = null; private Map context; - private boolean locking; - @Parameters(name="{0}") - public static Collection persistence() { - Object[][] locking = new Object[][] { - { OPTIMISTIC_LOCKING }, - { PESSIMISTIC_LOCKING } - }; - return Arrays.asList(locking); + public static Stream parameters() { + return Stream.of(OPTIMISTIC_LOCKING, PESSIMISTIC_LOCKING); }; - public MoreBatchExecutionPersistenceTest(String locking) { - this.locking = PESSIMISTIC_LOCKING.equals(locking); - } - - @After + @AfterEach public void cleanUpPersistence() throws Exception { disposeKSession(); cleanUp(context); @@ -95,21 +82,22 @@ public void disposeKSession() { } } - protected StatefulKnowledgeSession createKnowledgeSession(KieBase kbase) { + private StatefulKnowledgeSession createKnowledgeSession(String locking, KieBase kbase) { if( context == null ) { context = DroolsPersistenceUtil.setupWithPoolingDataSource(DROOLS_PERSISTENCE_UNIT_NAME); } KieSessionConfiguration ksconf = RuleBaseFactory.newKnowledgeSessionConfiguration(); Environment env = createEnvironment(context); - if( this.locking ) { + if(PESSIMISTIC_LOCKING.equals(locking)) { env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true); } return JPAKnowledgeService.newStatefulKnowledgeSession(kbase, ksconf, env); } - @Test - public void testFireAllRules() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testFireAllRules(String locking) { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource("org/drools/mvel/integrationtests/drl/test_ImportFunctions.drl"), ResourceType.DRL); if (kbuilder.hasErrors()) { @@ -117,7 +105,7 @@ public void testFireAllRules() { } InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addPackages(kbuilder.getKnowledgePackages()); - ksession = createKnowledgeSession(kbase); + ksession = createKnowledgeSession(locking, kbase); final Cheese cheese = new Cheese("stilton", 15); ksession.insert(cheese); @@ -143,8 +131,9 @@ public void testFireAllRules() { assertThat(list.get(3)).isEqualTo("rule4"); } - @Test - public void testQuery() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testQuery(String locking) { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource("org/drools/mvel/integrationtests/simple_query_test.drl"), ResourceType.DRL); if (kbuilder.hasErrors()) { @@ -152,7 +141,7 @@ public void testQuery() { } InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addPackages(kbuilder.getKnowledgePackages()); - ksession = createKnowledgeSession(kbase); + ksession = createKnowledgeSession(locking, kbase); ksession.insert( new Cheese( "stinky", 5 ) ); ksession.insert( new Cheese( "smelly", 7 ) ); diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/command/SimpleBatchExecutionPersistenceTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/command/SimpleBatchExecutionPersistenceTest.java index bdce54ea33d..6c9257f37e3 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/command/SimpleBatchExecutionPersistenceTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/command/SimpleBatchExecutionPersistenceTest.java @@ -19,25 +19,23 @@ package org.drools.persistence.command; import static org.assertj.core.api.Assertions.assertThat; +import static org.drools.persistence.util.DroolsPersistenceUtil.OPTIMISTIC_LOCKING; +import static org.drools.persistence.util.DroolsPersistenceUtil.PESSIMISTIC_LOCKING; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import org.drools.core.impl.RuleBaseFactory; import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.kiesession.rulebase.KnowledgeBaseFactory; -import org.drools.mvel.CommonTestMethodBase; -import org.drools.mvel.compiler.command.SimpleBatchExecutionTest; import org.drools.persistence.util.DroolsPersistenceUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.command.Command; import org.kie.api.io.ResourceType; @@ -54,39 +52,28 @@ import org.kie.internal.persistence.jpa.JPAKnowledgeService; import org.kie.internal.runtime.StatefulKnowledgeSession; -@RunWith(Parameterized.class) -public class SimpleBatchExecutionPersistenceTest extends CommonTestMethodBase { +public class SimpleBatchExecutionPersistenceTest { private Map context; - private boolean locking; - @Parameters(name="{0}") - public static Collection persistence() { - Object[][] locking = new Object[][] { - { DroolsPersistenceUtil.OPTIMISTIC_LOCKING }, - { DroolsPersistenceUtil.PESSIMISTIC_LOCKING } - }; - return Arrays.asList(locking); + public static Stream parameters() { + return Stream.of(OPTIMISTIC_LOCKING, PESSIMISTIC_LOCKING); }; - public SimpleBatchExecutionPersistenceTest(String locking) { - this.locking = DroolsPersistenceUtil.PESSIMISTIC_LOCKING.equals(locking); - }; - - @After + @AfterEach public void cleanUpPersistence() throws Exception { disposeKSession(); DroolsPersistenceUtil.cleanUp(context); context = null; } - protected StatefulKnowledgeSession createKnowledgeSession(KieBase kbase) { + private StatefulKnowledgeSession createKnowledgeSession(String locking, KieBase kbase) { if( context == null ) { context = DroolsPersistenceUtil.setupWithPoolingDataSource(DroolsPersistenceUtil.DROOLS_PERSISTENCE_UNIT_NAME); } KieSessionConfiguration ksconf = RuleBaseFactory.newKnowledgeSessionConfiguration(); Environment env = DroolsPersistenceUtil.createEnvironment(context); - if( this.locking ) { + if(PESSIMISTIC_LOCKING.equals(locking)) { env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true); } return JPAKnowledgeService.newStatefulKnowledgeSession(kbase, ksconf, env); @@ -102,18 +89,17 @@ protected StatefulKnowledgeSession createKnowledgeSession(KieBase kbase) { + " then\n" + "end\n"; - @Before - public void createKSession() throws Exception { + private void createKSession(String locking) throws Exception { final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ResourceFactory.newByteArrayResource(ruleString.getBytes()), ResourceType.DRL ); InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); assertThat(kbuilder.hasErrors()).isFalse(); kbase.addPackages( kbuilder.getKnowledgePackages() ); - ksession = createKnowledgeSession(kbase); + ksession = createKnowledgeSession(locking, kbase); } - @After + @AfterEach public void disposeKSession() throws Exception { if( ksession != null ) { ksession.dispose(); @@ -121,10 +107,11 @@ public void disposeKSession() throws Exception { } } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") @SuppressWarnings({ "rawtypes", "unchecked" }) - public void testInsertObjectCommand() throws Exception { - + public void testInsertObjectCommand(String locking) throws Exception { + createKSession(locking); String expected_1 = "expected_1"; String expected_2 = "expected_2"; @@ -152,10 +139,11 @@ public void testInsertObjectCommand() throws Exception { assertThat(expectedList.isEmpty()).as("Retrieved object list did not contain expected objects.").isTrue(); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") @SuppressWarnings({ "rawtypes", "unchecked" }) - public void testInsertElementsCommand() throws Exception { - + public void testInsertElementsCommand(String locking) throws Exception { + createKSession(locking); String expected_1 = "expected_1"; String expected_2 = "expected_2"; Object [] expectedArr = {expected_1, expected_2}; @@ -181,10 +169,11 @@ public void testInsertElementsCommand() throws Exception { assertThat(expectedList.isEmpty()).as("Retrieved object list did not contain expected objects.").isTrue(); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") @SuppressWarnings({ "rawtypes", "unchecked" }) - public void testSetGlobalCommand() throws Exception { - + public void testSetGlobalCommand(String locking) throws Exception { + createKSession(locking); ksession.insert(new Integer(5)); ksession.insert(new Integer(7)); ksession.fireAllRules(); @@ -201,10 +190,11 @@ public void testSetGlobalCommand() throws Exception { assertThat(global).isEqualTo("France"); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") @SuppressWarnings({ "rawtypes", "unchecked" }) - public void testGetGlobalCommand() throws Exception { - + public void testGetGlobalCommand(String locking) throws Exception { + createKSession(locking); ksession.insert(new Integer(5)); ksession.insert(new Integer(7)); ksession.fireAllRules(); @@ -221,10 +211,11 @@ public void testGetGlobalCommand() throws Exception { assertThat(global).as("Retrieved global is not equal to 'France'.").isEqualTo("France"); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") @SuppressWarnings({ "rawtypes", "unchecked" }) - public void testGetObjectCommand() throws Exception { - + public void testGetObjectCommand(String locking) throws Exception { + createKSession(locking); String expected_1 = "expected_1"; String expected_2 = "expected_2"; FactHandle handle_1 = ksession.insert( expected_1 ); @@ -247,10 +238,11 @@ public void testGetObjectCommand() throws Exception { assertThat(result.getValue("out_2")).isEqualTo(expected_2); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") @SuppressWarnings({ "rawtypes", "unchecked" }) - public void testGetObjectsCommand() throws Exception { - + public void testGetObjectsCommand(String locking) throws Exception { + createKSession(locking); String expected_1 = "expected_1"; String expected_2 = "expected_2"; FactHandle handle_1 = ksession.insert( expected_1 ); diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/JtaTransactionManagerFactoryTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/JtaTransactionManagerFactoryTest.java index d8d57b2d3c5..4d38e675155 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/JtaTransactionManagerFactoryTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/JtaTransactionManagerFactoryTest.java @@ -30,14 +30,14 @@ import org.drools.core.impl.EnvironmentFactory; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kie.api.runtime.Environment; import org.kie.api.runtime.EnvironmentName; public class JtaTransactionManagerFactoryTest { - @BeforeClass + @BeforeAll public static void setupOnce() throws NamingException { InitialContext initContext = new InitialContext(); initContext.rebind("java:comp/UserTransaction", com.arjuna.ats.jta.UserTransaction.userTransaction()); diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/JtaTransactionManagerTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/JtaTransactionManagerTest.java index f8cbff8e23a..aecde2a878e 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/JtaTransactionManagerTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/jta/JtaTransactionManagerTest.java @@ -35,9 +35,9 @@ import org.drools.persistence.api.TransactionManager; import org.drools.persistence.jpa.JpaPersistenceContextManager; import org.drools.persistence.util.DroolsPersistenceUtil; -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.KieServices; import org.kie.api.io.ResourceType; @@ -75,7 +75,7 @@ public class JtaTransactionManagerTest { + "end\n" + "\n"; - @Before + @BeforeEach public void setup() { // This test does only plays with tx's, it doesn't actually persist // any interersting (wrt marshalling) SessionInfo objects @@ -85,7 +85,7 @@ public void setup() { emf = (EntityManagerFactory) context.get(PersistenceUtil.ENTITY_MANAGER_FACTORY); } - @After + @AfterEach public void tearDown() { DroolsPersistenceUtil.cleanUp(context); } diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/kie/persistence/session/JpaPersistentStatefulSessionTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/kie/persistence/session/JpaPersistentStatefulSessionTest.java index 0863d2fdfae..388844d6da8 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/kie/persistence/session/JpaPersistentStatefulSessionTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/kie/persistence/session/JpaPersistentStatefulSessionTest.java @@ -20,31 +20,27 @@ import java.io.Serializable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Stream; import javax.naming.InitialContext; import jakarta.transaction.UserTransaction; import org.drools.core.FlowSessionConfiguration; -import org.drools.core.SessionConfiguration; import org.drools.commands.impl.CommandBasedStatefulKnowledgeSessionImpl; import org.drools.commands.impl.FireAllRulesInterceptor; import org.drools.commands.impl.LoggingInterceptor; import org.drools.mvel.compiler.Person; import org.drools.persistence.PersistableRunner; import org.drools.persistence.util.DroolsPersistenceUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.api.builder.KieFileSystem; @@ -72,44 +68,38 @@ import static org.drools.persistence.util.DroolsPersistenceUtil.PESSIMISTIC_LOCKING; import static org.drools.persistence.util.DroolsPersistenceUtil.createEnvironment; -@RunWith(Parameterized.class) public class JpaPersistentStatefulSessionTest { private static Logger logger = LoggerFactory.getLogger(JpaPersistentStatefulSessionTest.class); private Map context; private Environment env; - private boolean locking; - - @Parameters(name="{0}") - public static Collection persistence() { - Object[][] locking = new Object[][] { - { OPTIMISTIC_LOCKING }, - { PESSIMISTIC_LOCKING } - }; - return Arrays.asList(locking); - }; - public JpaPersistentStatefulSessionTest(String locking) { - this.locking = PESSIMISTIC_LOCKING.equals(locking); - } + public static Stream parameters() { + return Stream.of(OPTIMISTIC_LOCKING, PESSIMISTIC_LOCKING); + }; - @Before + @BeforeEach public void setUp() throws Exception { context = DroolsPersistenceUtil.setupWithPoolingDataSource(DROOLS_PERSISTENCE_UNIT_NAME); env = createEnvironment(context); - if( locking ) { + } + + private void setUpLocking(String locking) { + if(PESSIMISTIC_LOCKING.equals(locking)) { env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true); } } - @After + @AfterEach public void tearDown() throws Exception { DroolsPersistenceUtil.cleanUp(context); } - @Test - public void testFactHandleSerialization() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testFactHandleSerialization(String locking) { + setUpLocking(locking); String str = ""; str += "package org.kie.test\n"; str += "import java.util.concurrent.atomic.AtomicInteger\n"; @@ -164,8 +154,10 @@ public void testFactHandleSerialization() { } - @Test - public void testLocalTransactionPerStatement() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testLocalTransactionPerStatement(String locking) { + setUpLocking(locking); String str = ""; str += "package org.kie.test\n"; str += "global java.util.List list\n"; @@ -200,8 +192,10 @@ public void testLocalTransactionPerStatement() { } - @Test - public void testUserTransactions() throws Exception { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testUserTransactions(String locking) throws Exception { + setUpLocking(locking); String str = ""; str += "package org.kie.test\n"; str += "global java.util.List list\n"; @@ -282,8 +276,10 @@ public void testUserTransactions() throws Exception { assertThat(list.size()).isEqualTo(6); } - @Test - public void testInterceptor() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testInterceptor(String locking) { + setUpLocking(locking); String str = ""; str += "package org.kie.test\n"; str += "global java.util.List list\n"; @@ -317,8 +313,10 @@ public void testInterceptor() { assertThat(list.size()).isEqualTo(3); } - @Test - public void testSetFocus() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testSetFocus(String locking) { + setUpLocking(locking); String str = ""; str += "package org.kie.test\n"; str += "global java.util.List list\n"; @@ -354,8 +352,10 @@ public void testSetFocus() { assertThat(list.size()).isEqualTo(3); } - @Test - public void testSharedReferences() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testSharedReferences(String locking) { + setUpLocking(locking); KieServices ks = KieServices.Factory.get(); KieBase kbase = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).getKieBase(); KieSession ksession = ks.getStoreServices().newKieSession( kbase, null, env ); @@ -382,9 +382,11 @@ public void testSharedReferences() { } - @Test - public void testMergeConfig() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testMergeConfig(String locking) { // JBRULES-3155 + setUpLocking(locking); String str = ""; str += "package org.kie.test\n"; str += "global java.util.List list\n"; @@ -413,8 +415,10 @@ public void testMergeConfig() { assertThat(sessionConfig.getProcessInstanceManagerFactory()).isEqualTo("com.example.CustomJPAProcessInstanceManagerFactory"); } - @Test - public void testMoreComplexRulesSerialization() throws Exception { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testMoreComplexRulesSerialization(String locking) throws Exception { + setUpLocking(locking); KieServices ks = KieServices.Factory.get(); Resource drlResource = ks.getResources().newClassPathResource("collect_rules.drl", JpaPersistentStatefulSessionTest.class); @@ -482,8 +486,10 @@ public List getExits() { } } - @Test - public void testFamilyRulesSerialization() throws Exception { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testFamilyRulesSerialization(String locking) throws Exception { + setUpLocking(locking); KieServices ks = KieServices.Factory.get(); Resource drlResource = ks.getResources().newClassPathResource("family_rules.drl", JpaPersistentStatefulSessionTest.class); @@ -712,9 +718,11 @@ public List getFatherList() { } } - @Test - public void testGetCount() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testGetCount(String locking) { // BZ-1022374 + setUpLocking(locking); String str = ""; str += "package org.kie.test\n"; str += "rule rule1\n"; @@ -793,9 +801,11 @@ public void setThing(String thing) { } } - @Test - public void testSessionConfigurationFromContainer() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testSessionConfigurationFromContainer(String locking) { // DROOLS-1002 + setUpLocking(locking); String str = "rule R when then end"; KieServices ks = KieServices.Factory.get(); @@ -822,9 +832,11 @@ public void testSessionConfigurationFromContainer() { assertThat(ksession.getSessionClock() instanceof SessionPseudoClock).isTrue(); } - @Test - public void testGetFactHandles() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testGetFactHandles(String locking) { // DROOLS-1270 + setUpLocking(locking); String str = "package org.kie.test\n" + "rule rule1 when\n" + diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/kie/persistence/session/PersistentSessionForallTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/kie/persistence/session/PersistentSessionForallTest.java index 8b26e60defc..3be5f739ab9 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/kie/persistence/session/PersistentSessionForallTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/kie/persistence/session/PersistentSessionForallTest.java @@ -19,19 +19,15 @@ package org.drools.persistence.kie.persistence.session; import java.io.Serializable; -import java.util.Arrays; -import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.stream.Stream; import org.drools.mvel.compiler.Person; import org.drools.persistence.util.DroolsPersistenceUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.api.event.rule.AfterMatchFiredEvent; @@ -48,38 +44,26 @@ import static org.drools.persistence.util.DroolsPersistenceUtil.PESSIMISTIC_LOCKING; import static org.drools.persistence.util.DroolsPersistenceUtil.createEnvironment; -@RunWith(Parameterized.class) public class PersistentSessionForallTest { private KieSession kieSession; private Map context; private Environment env; - private boolean locking; - - @Parameters(name="{0}") - public static Collection persistence() { - Object[][] locking = new Object[][] { - { OPTIMISTIC_LOCKING }, - { PESSIMISTIC_LOCKING } - }; - return Arrays.asList(locking); + + public static Stream parameters() { + return Stream.of(OPTIMISTIC_LOCKING, PESSIMISTIC_LOCKING); }; - public PersistentSessionForallTest(String locking) { - this.locking = PESSIMISTIC_LOCKING.equals(locking); - } - - @Before - public void setUp() throws Exception { - setupPersistence(); + private void setUp(String locking) throws Exception { + setupPersistence(locking); createKieSession(); } - private void setupPersistence() { + private void setupPersistence(String locking) { context = DroolsPersistenceUtil.setupWithPoolingDataSource(DROOLS_PERSISTENCE_UNIT_NAME); env = createEnvironment(context); - if( locking ) { + if(PESSIMISTIC_LOCKING.equals(locking)) { env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true); } } @@ -111,7 +95,7 @@ private void createKieSession() { kieSession = KieServices.Factory.get().getStoreServices().newKieSession( kbase, null, env ); } - @After + @AfterEach public void tearDown() throws Exception { cleanUpKieSession(); DroolsPersistenceUtil.cleanUp(context); @@ -126,8 +110,10 @@ private void cleanUpKieSession() { /** * Tests marshalling of persistent KieSession with forall. */ - @Test - public void testNotMatchedCombination() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testNotMatchedCombination(String locking) throws Exception { + setUp(locking); TrackingAgendaEventListener listener = new TrackingAgendaEventListener(); kieSession.addEventListener(listener); diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/map/impl/JpaBasedPersistenceTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/map/impl/JpaBasedPersistenceTest.java index e2e75149da6..53d7e80b98d 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/map/impl/JpaBasedPersistenceTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/map/impl/JpaBasedPersistenceTest.java @@ -18,19 +18,15 @@ */ package org.drools.persistence.map.impl; -import java.util.Arrays; -import java.util.Collection; import java.util.Map; +import java.util.stream.Stream; import jakarta.persistence.EntityManagerFactory; import org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy; import org.drools.persistence.jta.JtaTransactionManager; import org.drools.persistence.util.DroolsPersistenceUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.kie.api.KieBase; import org.kie.api.runtime.Environment; import org.kie.api.runtime.EnvironmentName; @@ -47,7 +43,6 @@ import static org.kie.api.runtime.EnvironmentName.ENTITY_MANAGER_FACTORY; import static org.kie.api.runtime.EnvironmentName.USE_PESSIMISTIC_LOCKING; -@RunWith(Parameterized.class) public class JpaBasedPersistenceTest extends MapPersistenceTest { private static Logger logger = LoggerFactory.getLogger(JPAPlaceholderResolverStrategy.class); @@ -56,22 +51,13 @@ public class JpaBasedPersistenceTest extends MapPersistenceTest { private EntityManagerFactory emf; private JtaTransactionManager txm; private boolean useTransactions = false; - private boolean locking; - @Parameters(name="{0}") - public static Collection persistence() { - Object[][] locking = new Object[][] { - { OPTIMISTIC_LOCKING }, - { PESSIMISTIC_LOCKING } - }; - return Arrays.asList(locking); + public static Stream parameters() { + return Stream.of(OPTIMISTIC_LOCKING, PESSIMISTIC_LOCKING); }; - public JpaBasedPersistenceTest(String locking) { - this.locking = PESSIMISTIC_LOCKING.equals(locking); - } - @Before + @BeforeEach public void setUp() throws Exception { context = DroolsPersistenceUtil.setupWithPoolingDataSource(DROOLS_PERSISTENCE_UNIT_NAME); emf = (EntityManagerFactory) context.get(ENTITY_MANAGER_FACTORY); @@ -86,16 +72,16 @@ public void setUp() throws Exception { } } - @After + @AfterEach public void tearDown() throws Exception { DroolsPersistenceUtil.cleanUp(context); } @Override - protected KieSession createSession(KieBase kbase) { + protected KieSession createSession(String locking, KieBase kbase) { Environment env = createEnvironment(context); - if( this.locking ) { + if(PESSIMISTIC_LOCKING.equals(locking)) { env.set(USE_PESSIMISTIC_LOCKING, true); } return JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env); diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/map/impl/MapBasedPersistenceTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/map/impl/MapBasedPersistenceTest.java index 0ddf12319f8..8f50ada257d 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/map/impl/MapBasedPersistenceTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/map/impl/MapBasedPersistenceTest.java @@ -18,15 +18,19 @@ */ package org.drools.persistence.map.impl; +import static org.drools.persistence.util.DroolsPersistenceUtil.OPTIMISTIC_LOCKING; +import static org.drools.persistence.util.DroolsPersistenceUtil.PESSIMISTIC_LOCKING; + import java.util.HashMap; import java.util.Map; +import java.util.stream.Stream; import org.drools.persistence.api.PersistentSession; import org.drools.persistence.api.PersistentWorkItem; import org.drools.persistence.map.EnvironmentBuilder; import org.drools.persistence.map.KnowledgeSessionStorage; import org.drools.persistence.map.KnowledgeSessionStorageEnvironmentBuilder; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.internal.persistence.jpa.JPAKnowledgeService; @@ -38,13 +42,17 @@ public class MapBasedPersistenceTest extends MapPersistenceTest{ private SimpleKnowledgeSessionStorage storage; - @Before + public static Stream parameters() { + return Stream.of("not relevant"); + }; + + @BeforeEach public void createStorage(){ storage = new SimpleKnowledgeSessionStorage(); } @Override - protected KieSession createSession(KieBase kbase) { + protected KieSession createSession(String locking, KieBase kbase) { EnvironmentBuilder envBuilder = new KnowledgeSessionStorageEnvironmentBuilder( storage ); Environment env = KieServices.Factory.get().newEnvironment(); diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/map/impl/MapPersistenceTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/map/impl/MapPersistenceTest.java index b0843e249cc..db23987fbf0 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/map/impl/MapPersistenceTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/map/impl/MapPersistenceTest.java @@ -22,7 +22,8 @@ import org.drools.io.ByteArrayResource; import org.drools.kiesession.rulebase.KnowledgeBaseFactory; import org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.io.ResourceType; import org.kie.api.runtime.KieSession; @@ -41,20 +42,22 @@ public abstract class MapPersistenceTest { private static Logger logger = LoggerFactory.getLogger(JPAPlaceholderResolverStrategy.class); - @Test - public void createPersistentSession() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void createPersistentSession(String locking) { KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); - KieSession crmPersistentSession = createSession( kbase ); + KieSession crmPersistentSession = createSession( locking, kbase ); crmPersistentSession.fireAllRules(); - crmPersistentSession = createSession( kbase ); + crmPersistentSession = createSession( locking, kbase ); assertThat(crmPersistentSession).isNotNull(); } - @Test - public void createPersistentSessionWithRules() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void createPersistentSessionWithRules(String locking) { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory .newKnowledgeBuilder(); @@ -80,7 +83,7 @@ public void createPersistentSessionWithRules() { InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addPackages( kbuilder.getKnowledgePackages() ); - KieSession ksession = createSession( kbase ); + KieSession ksession = createSession(locking, kbase ); FactHandle buddyFactHandle = ksession.insert( new Buddy() ); ksession.fireAllRules(); @@ -98,13 +101,14 @@ public void createPersistentSessionWithRules() { } - @Test - public void dontCreateMoreSessionsThanNecessary() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void dontCreateMoreSessionsThanNecessary(String locking) { long initialNumberOfSavedSessions = getSavedSessionsCount(); KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); - KieSession crmPersistentSession = createSession(kbase); + KieSession crmPersistentSession = createSession(locking, kbase); long ksessionId = crmPersistentSession.getIdentifier(); crmPersistentSession.fireAllRules(); @@ -125,11 +129,12 @@ public void dontCreateMoreSessionsThanNecessary() { } - @Test - public void insertObjectIntoKsessionAndRetrieve() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void insertObjectIntoKsessionAndRetrieve(String locking) { KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); - KieSession crmPersistentSession = createSession(kbase); + KieSession crmPersistentSession = createSession(locking, kbase); Buddy bestBuddy = new Buddy("john"); crmPersistentSession.insert(bestBuddy); @@ -142,7 +147,7 @@ public void insertObjectIntoKsessionAndRetrieve() { crmPersistentSession.dispose(); } - protected abstract KieSession createSession(KieBase kbase); + protected abstract KieSession createSession(String locking, KieBase kbase); protected abstract KieSession disposeAndReloadSession(KieSession crmPersistentSession, KieBase kbase); diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/monitoring/MonitoringWithJPAKnowledgeServiceTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/monitoring/MonitoringWithJPAKnowledgeServiceTest.java index 73ea3c4f32e..97d768ab75d 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/monitoring/MonitoringWithJPAKnowledgeServiceTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/monitoring/MonitoringWithJPAKnowledgeServiceTest.java @@ -21,9 +21,9 @@ import org.drools.compiler.kie.builder.impl.KieServicesImpl; import org.drools.core.management.DroolsManagementAgent; import org.drools.persistence.util.DroolsPersistenceUtil; -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.KieServices; import org.kie.api.builder.model.KieSessionModel.KieSessionType; @@ -59,7 +59,7 @@ public MonitoringWithJPAKnowledgeServiceTest() { private String mbeansprop; - @Before + @BeforeEach public void setUp() throws Exception { ((KieServicesImpl) KieServices.Factory.get()).nullKieClasspathContainer(); ((KieServicesImpl) KieServices.Factory.get()).nullAllContainerIds(); @@ -70,7 +70,7 @@ public void setUp() throws Exception { env = createEnvironment(context); } - @After + @AfterEach public void tearDown() throws Exception { ((KieServicesImpl) KieServices.Factory.get()).nullKieClasspathContainer(); ((KieServicesImpl) KieServices.Factory.get()).nullAllContainerIds(); diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/AgendaRuleFlowGroupsTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/AgendaRuleFlowGroupsTest.java index 85705c46606..d05f9bcacd4 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/AgendaRuleFlowGroupsTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/AgendaRuleFlowGroupsTest.java @@ -19,10 +19,9 @@ package org.drools.persistence.session; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import org.drools.commands.impl.CommandBasedStatefulKnowledgeSessionImpl; import org.drools.core.common.InternalAgenda; @@ -30,13 +29,11 @@ import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.kiesession.rulebase.KnowledgeBaseFactory; import org.drools.persistence.util.DroolsPersistenceUtil; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.drools.io.ClassPathResource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; import org.kie.api.builder.Message; import org.kie.api.builder.Results; import org.kie.api.command.ExecutableCommand; @@ -56,36 +53,30 @@ import static org.drools.persistence.util.DroolsPersistenceUtil.DROOLS_PERSISTENCE_UNIT_NAME; import static org.drools.persistence.util.DroolsPersistenceUtil.createEnvironment; -@RunWith(Parameterized.class) public class AgendaRuleFlowGroupsTest { private Map context; - private boolean locking; - @Parameters - public static Collection persistence() { - Object[][] locking = new Object[][] { { false }, { true } }; - return Arrays.asList(locking); + public static Stream parameters() { + return Stream.of(true); }; - public AgendaRuleFlowGroupsTest(boolean locking) { - this.locking = true; - } - @Before + @BeforeEach public void setUp() throws Exception { context = DroolsPersistenceUtil.setupWithPoolingDataSource(DROOLS_PERSISTENCE_UNIT_NAME); } - @After + @AfterEach public void tearDown() { DroolsPersistenceUtil.cleanUp(context); } - @Test - public void testRuleFlowGroupOnly() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testRuleFlowGroupOnly(boolean locking) throws Exception { - CommandBasedStatefulKnowledgeSessionImpl ksession = createSession(-1, "ruleflow-groups.drl"); + CommandBasedStatefulKnowledgeSessionImpl ksession = createSession(locking, -1, "ruleflow-groups.drl"); InternalAgendaGroup[] groups = ((InternalAgenda)stripSession(ksession).getAgenda()).getAgendaGroupsManager().getAgendaGroups(); // only main is available @@ -99,7 +90,7 @@ public void testRuleFlowGroupOnly() throws Exception { ksession.execute(new ActivateRuleFlowCommand("ruleflow-group")); ksession.dispose(); - ksession = createSession(id, "ruleflow-groups.drl"); + ksession = createSession(locking, id, "ruleflow-groups.drl"); groups = ((InternalAgenda)stripSession(ksession).getAgenda()).getAgendaGroupsManager().getAgendaGroups(); // main and rule flow is now on the agenda @@ -108,10 +99,11 @@ public void testRuleFlowGroupOnly() throws Exception { assertThat(groups[1].getName()).isEqualTo("ruleflow-group"); } - @Test - public void testAgendaGroupOnly() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testAgendaGroupOnly(boolean locking) throws Exception { - CommandBasedStatefulKnowledgeSessionImpl ksession = createSession(-1, "agenda-groups.drl"); + CommandBasedStatefulKnowledgeSessionImpl ksession = createSession(locking, -1, "agenda-groups.drl"); InternalAgendaGroup[] groups = ((InternalAgenda)stripSession(ksession).getAgenda()).getAgendaGroupsManager().getAgendaGroups(); // only main is available @@ -125,7 +117,7 @@ public void testAgendaGroupOnly() throws Exception { ksession.execute(new ActivateAgendaGroupCommand("agenda-group")); ksession.dispose(); - ksession = createSession(id, "agenda-groups.drl"); + ksession = createSession(locking, id, "agenda-groups.drl"); groups = ((InternalAgenda)stripSession(ksession).getAgenda()).getAgendaGroupsManager().getAgendaGroups(); // main and agenda group is now on the agenda @@ -135,10 +127,11 @@ public void testAgendaGroupOnly() throws Exception { } - @Test - public void testAgendaGroupAndRuleFlowGroup() throws Exception { + @ParameterizedTest + @MethodSource("parameters") + public void testAgendaGroupAndRuleFlowGroup(boolean locking) throws Exception { - CommandBasedStatefulKnowledgeSessionImpl ksession = createSession(-1, "agenda-groups.drl", "ruleflow-groups.drl"); + CommandBasedStatefulKnowledgeSessionImpl ksession = createSession(locking, -1, "agenda-groups.drl", "ruleflow-groups.drl"); InternalAgendaGroup[] groups = ((InternalAgenda)stripSession(ksession).getAgenda()).getAgendaGroupsManager().getAgendaGroups(); // only main is available @@ -153,7 +146,7 @@ public void testAgendaGroupAndRuleFlowGroup() throws Exception { ksession.execute(new ActivateRuleFlowCommand("ruleflow-group")); ksession.dispose(); - ksession = createSession(id, "agenda-groups.drl", "ruleflow-groups.drl"); + ksession = createSession(locking, id, "agenda-groups.drl", "ruleflow-groups.drl"); groups = ((InternalAgenda)stripSession(ksession).getAgenda()).getAgendaGroupsManager().getAgendaGroups(); // main and agenda group is now on the agenda @@ -173,7 +166,7 @@ private KieSession stripSession(KieSession ksession) { return ksession; } - private CommandBasedStatefulKnowledgeSessionImpl createSession(long id, String...rules) { + private CommandBasedStatefulKnowledgeSessionImpl createSession(boolean locking, long id, String...rules) { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); for (String rule : rules) { @@ -241,7 +234,8 @@ public Void execute(Context context) { } - @Test + @ParameterizedTest + @MethodSource("parameters") public void testConflictingAgendaAndRuleflowGroups() throws Exception { String drl = "package org.drools.test; " + diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaOptLockPersistentStatefulSessionTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaOptLockPersistentStatefulSessionTest.java index 72520fec2d4..6b4e448529a 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaOptLockPersistentStatefulSessionTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaOptLockPersistentStatefulSessionTest.java @@ -31,9 +31,9 @@ import org.drools.persistence.PersistableRunner; import org.drools.persistence.jpa.OptimisticLockRetryInterceptor; import org.drools.persistence.util.DroolsPersistenceUtil; -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.event.rule.DefaultRuleRuntimeEventListener; import org.kie.api.event.rule.ObjectInsertedEvent; import org.kie.api.io.ResourceType; @@ -65,13 +65,13 @@ public class JpaOptLockPersistentStatefulSessionTest { public JpaOptLockPersistentStatefulSessionTest() { } - @Before + @BeforeEach public void setUp() throws Exception { context = DroolsPersistenceUtil.setupWithPoolingDataSource(DROOLS_PERSISTENCE_UNIT_NAME); env = createEnvironment(context); } - @After + @AfterEach public void tearDown() throws Exception { DroolsPersistenceUtil.cleanUp(context); } diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaPersistentStatefulSessionTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaPersistentStatefulSessionTest.java index f61559f90b1..5619f959a91 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaPersistentStatefulSessionTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/JpaPersistentStatefulSessionTest.java @@ -19,14 +19,13 @@ package org.drools.persistence.session; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.IntStream; +import java.util.stream.Stream; import javax.naming.InitialContext; import jakarta.transaction.UserTransaction; @@ -42,12 +41,10 @@ import org.drools.mvel.compiler.Person; import org.drools.persistence.PersistableRunner; import org.drools.persistence.util.DroolsPersistenceUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.api.io.ResourceType; @@ -63,54 +60,51 @@ import org.kie.internal.utils.KieHelper; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.fail; import static org.drools.persistence.util.DroolsPersistenceUtil.DROOLS_PERSISTENCE_UNIT_NAME; import static org.drools.persistence.util.DroolsPersistenceUtil.OPTIMISTIC_LOCKING; import static org.drools.persistence.util.DroolsPersistenceUtil.PESSIMISTIC_LOCKING; import static org.drools.persistence.util.DroolsPersistenceUtil.createEnvironment; -@RunWith(Parameterized.class) public class JpaPersistentStatefulSessionTest { private Map context; private Environment env; - private final boolean locking; - @Parameters(name = "{0}") - public static Collection persistence() { - final Object[][] locking = new Object[][]{ - {OPTIMISTIC_LOCKING}, - {PESSIMISTIC_LOCKING} - }; - return Arrays.asList(locking); - } - - public JpaPersistentStatefulSessionTest(final String locking) { - this.locking = PESSIMISTIC_LOCKING.equals(locking); - } + public static Stream parameters() { + return Stream.of(OPTIMISTIC_LOCKING, PESSIMISTIC_LOCKING); + }; - @Before + @BeforeEach public void setUp() throws Exception { context = DroolsPersistenceUtil.setupWithPoolingDataSource(DROOLS_PERSISTENCE_UNIT_NAME); env = createEnvironment(context); - if (locking) { + } + + private void setLocking(String locking) { + if (PESSIMISTIC_LOCKING.equals(locking)) { env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true); } + } - - @After + + @AfterEach public void tearDown() throws Exception { DroolsPersistenceUtil.cleanUp(context); } - - @Test - public void testFactHandleSerialization() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testFactHandleSerialization(String locking) { + setLocking(locking); factHandleSerialization(false); } - @Test - public void testFactHandleSerializationWithOOPath() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testFactHandleSerializationWithOOPath(String locking) { + setLocking(locking); factHandleSerialization(true); } @@ -161,13 +155,17 @@ private void factHandleSerialization(final boolean withOOPath) { assertThat(list).hasSize(3); } - @Test - public void testLocalTransactionPerStatement() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testLocalTransactionPerStatement(String locking) { + setLocking(locking); localTransactionPerStatement(false); } - @Test - public void testLocalTransactionPerStatementWithOOPath() { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testLocalTransactionPerStatementWithOOPath(String locking) { + setLocking(locking); localTransactionPerStatement(true); } @@ -188,12 +186,15 @@ private void localTransactionPerStatement(final boolean withOOPath) { assertThat(list).hasSize(3); } - @Test - public void testUserTransactions() throws Exception { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testUserTransactions(String locking) throws Exception { + setLocking(locking); userTransactions(false); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testUserTransactionsWithOOPath() throws Exception { userTransactions(true); } @@ -268,12 +269,14 @@ private void userTransactions(final boolean withOOPath) throws Exception { assertThat(list).hasSize(6); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testInterceptor() { interceptor(false); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testInterceptorWithOOPath() { interceptor(true); } @@ -295,12 +298,14 @@ private void interceptor(final boolean withOOPath) { assertThat(list).hasSize(3); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testInterceptorOnRollback() throws Exception { interceptorOnRollback(false); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testInterceptorOnRollbackWithOOPAth() throws Exception { interceptorOnRollback(true); } @@ -343,12 +348,14 @@ private void interceptorOnRollback(final boolean withOOPath) throws Exception { } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testSetFocus() { testFocus(false); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testSetFocusWithOOPath() { testFocus(true); } @@ -380,7 +387,8 @@ private void testFocus(final boolean withOOPath) { assertThat(list).hasSize(3); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testSharedReferences() { final KieBase kbase = new KieHelper().getKieContainer().getKieBase(); @@ -408,7 +416,8 @@ public void testSharedReferences() { } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testMergeConfig() { // JBRULES-3155 final KieBase kbase = new KieHelper().getKieContainer().getKieBase(); @@ -423,14 +432,16 @@ public void testMergeConfig() { assertThat(sessionConfig.as(FlowSessionConfiguration.KEY).getProcessInstanceManagerFactory()).isEqualTo("com.example.CustomJPAProcessInstanceManagerFactory"); } - @Test(expected = IllegalStateException.class) + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testCreateAndDestroySession() { - createAndDestroySession(false); + assertThatIllegalStateException().isThrownBy(() -> createAndDestroySession(false)); } - @Test(expected = IllegalStateException.class) + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testCreateAndDestroySessionWithOOPath() { - createAndDestroySession(true); + assertThatIllegalStateException().isThrownBy(() -> createAndDestroySession(true)); } public void createAndDestroySession(final boolean withOOPath) { @@ -457,14 +468,16 @@ public void createAndDestroySession(final boolean withOOPath) { } - @Test(expected = IllegalStateException.class) + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testCreateAndDestroyNonPersistentSession() { - createAndDestroyNonPersistentSession(false); + assertThatIllegalStateException().isThrownBy(() -> createAndDestroyNonPersistentSession(true)); } - @Test(expected = IllegalStateException.class) + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testCreateAndDestroyNonPersistentSessionWithOOPath() { - createAndDestroyNonPersistentSession(true); + assertThatIllegalStateException().isThrownBy(() -> createAndDestroyNonPersistentSession(true)); } private void createAndDestroyNonPersistentSession(final boolean withOOPath) { @@ -491,12 +504,14 @@ private void createAndDestroyNonPersistentSession(final boolean withOOPath) { fail("Session should already be disposed " + ksessionId); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testFromNodeWithModifiedCollection() { fromNodeWithModifiedCollection(false); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testFromNodeWithModifiedCollectionWithOOPath() { fromNodeWithModifiedCollection(true); } diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/ReloadSessionTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/ReloadSessionTest.java index b49aff78383..90cd0f67a51 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/ReloadSessionTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/ReloadSessionTest.java @@ -23,6 +23,8 @@ import java.util.Collection; import java.util.Map; import java.util.Random; +import java.util.stream.Stream; + import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.Persistence; @@ -31,13 +33,11 @@ import org.drools.kiesession.rulebase.KnowledgeBaseFactory; import org.drools.persistence.api.PersistenceContextManager; import org.drools.persistence.util.DroolsPersistenceUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.event.rule.DefaultAgendaEventListener; import org.kie.api.event.rule.DefaultRuleRuntimeEventListener; @@ -59,13 +59,11 @@ import static org.drools.persistence.util.DroolsPersistenceUtil.PESSIMISTIC_LOCKING; import static org.kie.api.runtime.EnvironmentName.ENTITY_MANAGER_FACTORY; -@RunWith(Parameterized.class) public class ReloadSessionTest { // Datasource (setup & clean up) private Map context; private EntityManagerFactory emf; - private boolean locking; private static final String ENTRY_POINT = "ep1"; @@ -91,34 +89,25 @@ public class ReloadSessionTest { + "end\n" + "\n"; - @Parameters(name="{0}") - public static Collection persistence() { - Object[][] locking = new Object[][] { - { OPTIMISTIC_LOCKING }, - { PESSIMISTIC_LOCKING } - }; - return Arrays.asList(locking); + public static Stream parameters() { + return Stream.of(OPTIMISTIC_LOCKING, PESSIMISTIC_LOCKING); }; - public ReloadSessionTest(String locking) { - this.locking = PESSIMISTIC_LOCKING.equals(locking); - } - - @Before + @BeforeEach public void setup() { context = DroolsPersistenceUtil.setupWithPoolingDataSource(DROOLS_PERSISTENCE_UNIT_NAME); emf = (EntityManagerFactory) context.get(ENTITY_MANAGER_FACTORY); } - @After + @AfterEach public void cleanUp() { DroolsPersistenceUtil.cleanUp(context); } - private Environment createEnvironment() { + private Environment createEnvironment(String locking) { Environment env = DroolsPersistenceUtil.createEnvironment(context); - if( locking ) { + if( PESSIMISTIC_LOCKING.equals(locking) ) { env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true); } return env; @@ -138,11 +127,12 @@ private KieBase initializeKnowledgeBase(String rule) { return kbase; } - @Test - public void reloadKnowledgeSessionTest() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void reloadKnowledgeSessionTest(String locking) { // Initialize drools environment stuff - Environment env = createEnvironment(); + Environment env = createEnvironment(locking); KieBase kbase = initializeKnowledgeBase(simpleRule); StatefulKnowledgeSession commandKSession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env ); assertThat(commandKSession.getFactHandles().isEmpty()).as("There should be NO facts present in a new (empty) knowledge session.").isTrue(); @@ -170,7 +160,7 @@ public void reloadKnowledgeSessionTest() { // Reload session from the database emf = Persistence.createEntityManagerFactory(DROOLS_PERSISTENCE_UNIT_NAME); context.put(ENTITY_MANAGER_FACTORY, emf); - env = createEnvironment(); + env = createEnvironment(locking); // Re-initialize the knowledge session: StatefulKnowledgeSession newCommandKSession @@ -190,10 +180,12 @@ public void reloadKnowledgeSessionTest() { assertThat(list.size()).isEqualTo(1); } - @Test @Ignore - public void testListenersAfterSessionReload() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + @Disabled + public void testListenersAfterSessionReload(String locking) { // https://bugzilla.redhat.com/show_bug.cgi?id=826952 - Environment env = createEnvironment(); + Environment env = createEnvironment(locking); KieBase kbase = initializeKnowledgeBase(simpleRule); StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env ); @@ -209,9 +201,10 @@ public void testListenersAfterSessionReload() { assertThat(ksession.getAgendaEventListeners().size()).isEqualTo(1); } - @Test - public void testInsert() { - final Environment env = createEnvironment(); + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testInsert(String locking) { + final Environment env = createEnvironment(locking); final KieBase kbase = initializeKnowledgeBase( RULE_WITH_EP ); KieSession kieSession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env ); assertThat(kieSession.getFactHandles().isEmpty()).as("There should be NO facts present in a new (empty) knowledge session.").isTrue(); @@ -223,10 +216,11 @@ public void testInsert() { assertThat(objects.size()).as("Reloaded working memory should contain the fact.").isEqualTo(1); } - @Test - public void testInsertIntoEntryPoint() { + @ParameterizedTest(name = "{0}") + @MethodSource("parameters") + public void testInsertIntoEntryPoint(String locking) { // RHBRMS-2815 - final Environment env = createEnvironment(); + final Environment env = createEnvironment(locking); final KieBase kbase = initializeKnowledgeBase(RULE_WITH_EP); KieSession kieSession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env); assertThat(kieSession.getFactHandles().isEmpty()).as("There should be NO facts present in a new (empty) knowledge session.").isTrue(); diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/RuleFlowGroupRollbackTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/RuleFlowGroupRollbackTest.java index 9fe3819f778..17fe6c35185 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/RuleFlowGroupRollbackTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/session/RuleFlowGroupRollbackTest.java @@ -19,10 +19,9 @@ package org.drools.persistence.session; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import org.drools.commands.impl.CommandBasedStatefulKnowledgeSessionImpl; import org.drools.core.common.InternalAgenda; @@ -30,12 +29,10 @@ import org.drools.io.ClassPathResource; import org.drools.kiesession.rulebase.KnowledgeBaseFactory; import org.drools.persistence.util.DroolsPersistenceUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.command.ExecutableCommand; import org.kie.api.io.ResourceType; import org.kie.api.runtime.Context; @@ -56,41 +53,31 @@ import static org.drools.persistence.util.DroolsPersistenceUtil.PESSIMISTIC_LOCKING; import static org.drools.persistence.util.DroolsPersistenceUtil.createEnvironment; -@RunWith(Parameterized.class) public class RuleFlowGroupRollbackTest { private static Logger logger = LoggerFactory.getLogger(RuleFlowGroupRollbackTest.class); private Map context; - private boolean locking; - @Parameters(name="{0}") - public static Collection persistence() { - Object[][] locking = new Object[][] { - { OPTIMISTIC_LOCKING }, - { PESSIMISTIC_LOCKING } - }; - return Arrays.asList(locking); + public static Stream parameters() { + return Stream.of(OPTIMISTIC_LOCKING, PESSIMISTIC_LOCKING); }; - public RuleFlowGroupRollbackTest(String locking) { - this.locking = PESSIMISTIC_LOCKING.equals(locking); - } - - @Before + @BeforeEach public void setUp() throws Exception { context = DroolsPersistenceUtil.setupWithPoolingDataSource(DROOLS_PERSISTENCE_UNIT_NAME); } - @After + @AfterEach public void tearDown() { DroolsPersistenceUtil.cleanUp(context); } - @Test - public void testRuleFlowGroupRollback() throws Exception { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testRuleFlowGroupRollback(String locking) throws Exception { - CommandBasedStatefulKnowledgeSessionImpl ksession = createSession(); + CommandBasedStatefulKnowledgeSessionImpl ksession = createSession(locking); List list = new ArrayList(); list.add("Test"); @@ -112,7 +99,7 @@ public void testRuleFlowGroupRollback() throws Exception { } - private CommandBasedStatefulKnowledgeSessionImpl createSession() { + private CommandBasedStatefulKnowledgeSessionImpl createSession(String locking) { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( new ClassPathResource("ruleflowgroup_rollback.drl"), ResourceType.DRL ); @@ -125,7 +112,7 @@ private CommandBasedStatefulKnowledgeSessionImpl createSession() { kbase.addPackages( kbuilder.getKnowledgePackages() ); Environment env = createEnvironment(context); - if( locking ) { + if(PESSIMISTIC_LOCKING.equals(locking)) { env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true); } return (CommandBasedStatefulKnowledgeSessionImpl) JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env ); diff --git a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/timer/integrationtests/TimerAndCalendarTest.java b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/timer/integrationtests/TimerAndCalendarTest.java index 8b8775cbbb4..2c1cb36e39e 100644 --- a/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/timer/integrationtests/TimerAndCalendarTest.java +++ b/drools-persistence/drools-persistence-jpa/src/test/java/org/drools/persistence/timer/integrationtests/TimerAndCalendarTest.java @@ -25,18 +25,17 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; import org.drools.core.ClockType; import org.drools.kiesession.rulebase.InternalKnowledgeBase; import org.drools.core.impl.RuleBaseFactory; import org.drools.kiesession.rulebase.KnowledgeBaseFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +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.conf.EventProcessingOption; @@ -67,39 +66,30 @@ import static org.drools.persistence.util.DroolsPersistenceUtil.createEnvironment; import static org.drools.persistence.util.DroolsPersistenceUtil.setupWithPoolingDataSource; -@RunWith(Parameterized.class) public class TimerAndCalendarTest { private Map context; - private boolean locking; - - @Parameters(name="{0}") - public static Collection persistence() { - Object[][] locking = new Object[][] { - { OPTIMISTIC_LOCKING }, - { PESSIMISTIC_LOCKING } - }; - return Arrays.asList(locking); + + public static Stream parameters() { + return Stream.of(OPTIMISTIC_LOCKING, PESSIMISTIC_LOCKING); }; - public TimerAndCalendarTest(String locking) { - this.locking = PESSIMISTIC_LOCKING.equals(locking); - } - - @Before + @BeforeEach public void before() throws Exception { context = setupWithPoolingDataSource(DROOLS_PERSISTENCE_UNIT_NAME); } - @After + @AfterEach public void after() throws Exception { cleanUp(context); } - @Test @Ignore("beta4 phreak") - public void testTimerRuleAfterIntReloadSession() throws Exception { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + @Disabled("beta4 phreak") + public void testTimerRuleAfterIntReloadSession(String locking) throws Exception { InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); - KieSession ksession = createSession( kbase ); + KieSession ksession = createSession(locking, kbase); // must advance time or it won't save. SessionPseudoClock clock = (SessionPseudoClock) ksession.getSessionClock(); @@ -172,10 +162,12 @@ public void testTimerRuleAfterIntReloadSession() throws Exception { assertThat(list.size()).isEqualTo(4); } - @Test @Ignore("beta4 phreak") - public void testTimerRuleAfterCronReloadSession() throws Exception { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + @Disabled("beta4 phreak") + public void testTimerRuleAfterCronReloadSession(String locking) throws Exception { InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); - KieSession ksession = createSession( kbase ); + KieSession ksession = createSession(locking, kbase); // must advance time or it won't save. SessionPseudoClock clock = (SessionPseudoClock) ksession.getSessionClock(); @@ -252,8 +244,9 @@ public void testTimerRuleAfterCronReloadSession() throws Exception { assertThat(list.size()).isEqualTo(6); } - @Test - public void testEventExpires() throws Exception { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testEventExpires(String locking) throws Exception { String timerRule = "package org.drools.test\n" + "declare TestEvent \n" + " @role( event )\n" + @@ -272,7 +265,7 @@ public void testEventExpires() throws Exception { Collection kpackages = buildKnowledgePackage( resource, ResourceType.DRL ); kbase.addPackages( kpackages ); - KieSession ksession = createSession( kbase ); + KieSession ksession = createSession(locking, kbase); FactType type = kbase.getFactType( "org.drools.test", "TestEvent" ); @@ -289,7 +282,8 @@ public void testEventExpires() throws Exception { kbase ); } - @Test + @ParameterizedTest(name="{0}") + @MethodSource("parameters") public void testTimerWithRemovingRule() throws Exception { // DROOLS-576 // Only reproducible with RETEOO @@ -361,11 +355,11 @@ public void testTimerWithRemovingRule() throws Exception { assertThat(list.size()).isEqualTo(0); } - private KieSession createSession(KieBase kbase) { + private KieSession createSession(String locking, KieBase kbase) { final KieSessionConfiguration conf = RuleBaseFactory.newKnowledgeSessionConfiguration(); conf.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) ); Environment env = createEnvironment(context); - if( locking ) { + if(PESSIMISTIC_LOCKING.equals(locking)) { env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true); } StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, From f9b640df1259c687e031e2aa627caf63157d255e Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Fri, 29 Nov 2024 17:17:12 +0100 Subject: [PATCH 06/12] Migrated drool traits tests --- .../factmodel/traits/LogicalTraitTest.java | 148 +- .../compiler/factmodel/traits/TraitTest.java | 1310 +++++++++-------- .../traits/persistence/PersistenceTest.java | 40 +- 3 files changed, 773 insertions(+), 725 deletions(-) diff --git a/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LogicalTraitTest.java b/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LogicalTraitTest.java index bedb76d286e..a500b0bb8fe 100644 --- a/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LogicalTraitTest.java +++ b/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/LogicalTraitTest.java @@ -19,10 +19,9 @@ package org.drools.traits.compiler.factmodel.traits; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.Set; +import java.util.stream.Stream; import org.drools.core.common.InternalFactHandle; import org.drools.base.factmodel.traits.CoreWrapper; @@ -35,13 +34,11 @@ import org.drools.kiesession.rulebase.KnowledgeBaseFactory; import org.drools.serialization.protobuf.SerializationHelper; import org.drools.traits.compiler.CommonTraitTest; -import org.drools.traits.compiler.ReviseTraitTestWithPRAlwaysCategory; import org.drools.traits.core.factmodel.TraitFactoryImpl; import org.drools.traits.core.factmodel.VirtualPropertyMode; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +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.definition.type.FactType; import org.kie.api.io.ResourceType; @@ -59,25 +56,17 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -@RunWith(Parameterized.class) public class LogicalTraitTest extends CommonTraitTest { private static final Logger LOGGER = LoggerFactory.getLogger(LogicalTraitTest.class); - public VirtualPropertyMode mode; - - @Parameterized.Parameters - public static Collection modes() { - return List.of(VirtualPropertyMode.MAP, VirtualPropertyMode.TRIPLES); - } - - public LogicalTraitTest( VirtualPropertyMode m ) { - this.mode = m; + public static Stream parameters() { + return Stream.of(VirtualPropertyMode.MAP, VirtualPropertyMode.TRIPLES); } - - @Test - public void testShadowAlias() throws Exception { + @ParameterizedTest() + @MethodSource("parameters") + public void testShadowAlias(VirtualPropertyMode mode) throws Exception { KnowledgeBuilder kbuilderImpl = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilderImpl.add( ResourceFactory.newClassPathResource( "org/drools/compiler/factmodel/traits/testTraitedAliasing.drl" ), ResourceType.DRL ); @@ -107,13 +96,9 @@ public void testShadowAlias() throws Exception { assertThat(list).hasSize(8); } - - - - - - @Test - public void testShadowAliasTraitOnClass() { + @ParameterizedTest() + @MethodSource("parameters") + public void testShadowAliasTraitOnClass(VirtualPropertyMode mode) { String drl = "package org.drools.test; \n" + "import org.drools.base.factmodel.traits.*; \n" + @@ -175,9 +160,9 @@ public void testShadowAliasTraitOnClass() { } - - @Test - public void testShadowAliasClassOnTrait() { + @ParameterizedTest() + @MethodSource("parameters") + public void testShadowAliasClassOnTrait(VirtualPropertyMode mode) { String drl = "package org.drools.test; \n" + "import org.drools.base.factmodel.traits.*; \n" + @@ -251,11 +236,9 @@ public void testShadowAliasClassOnTrait() { } - - - - @Test - public void testShadowAliasTraitOnTrait() { + @ParameterizedTest() + @MethodSource("parameters") + public void testShadowAliasTraitOnTrait(VirtualPropertyMode mode) { String drl = "package org.drools.test; \n" + "import org.drools.base.factmodel.traits.*; \n" + @@ -324,11 +307,9 @@ public void testShadowAliasTraitOnTrait() { } - - - - @Test - public void initializationConflictManagement() { + @ParameterizedTest() + @MethodSource("parameters") + public void initializationConflictManagement(VirtualPropertyMode mode) { String drl = "package org.drools.test; \n" + "" + "global java.util.List list; \n" + @@ -407,11 +388,9 @@ public void initializationConflictManagement() { } } - - - - @Test - public void testInitializationConflictManagementPrimitiveTypes() { + @ParameterizedTest() + @MethodSource("parameters") + public void testInitializationConflictManagementPrimitiveTypes(VirtualPropertyMode mode) { String drl = "package org.drools.test; \n" + "" + "global java.util.List list; \n" + @@ -509,9 +488,10 @@ public void setNum( Integer num ) { } } - @Category(ReviseTraitTestWithPRAlwaysCategory.class) - @Test - public void testHardGetSetOnLogicallyTraitedField() { + @ParameterizedTest() + @MethodSource("parameters") + @Disabled("check file ReviseTraitTestWithPRAlwaysCategory.java") // + public void testHardGetSetOnLogicallyTraitedField(VirtualPropertyMode mode) { String drl = "package org.drools.test; " + "import " + Qty.class.getCanonicalName() + "; " + "" + @@ -566,11 +546,9 @@ public void testHardGetSetOnLogicallyTraitedField() { knowledgeSession.dispose(); } - - - - @Test - public void testFieldTypeDonMap() { + @ParameterizedTest() + @MethodSource("parameters") + public void testFieldTypeDonMap(VirtualPropertyMode mode) { String drl = "package org.drools.test; \n" + "" + "global java.util.List list; \n" + @@ -640,11 +618,9 @@ public void testFieldTypeDonMap() { } - - - - @Test - public void testDataStructs() { + @ParameterizedTest() + @MethodSource("parameters") + public void testDataStructs(VirtualPropertyMode mode) { String drl = "package org.drools.test; \n" + "" + "global java.util.List list; \n" + @@ -722,10 +698,9 @@ public void testDataStructs() { } - - - @Test - public void shadowAliasSelf() { + @ParameterizedTest() + @MethodSource("parameters") + public void shadowAliasSelf(VirtualPropertyMode mode) { String drl = "package org.drools.test; \n" + "import org.drools.base.factmodel.traits.*; \n" + @@ -786,9 +761,9 @@ public void shadowAliasSelf() { } - - @Test - public void traitOnSet() { + @ParameterizedTest() + @MethodSource("parameters") + public void traitOnSet(VirtualPropertyMode mode) { String drl = "package org.drools.test; \n" + "import org.drools.base.factmodel.traits.*; \n" + @@ -882,12 +857,9 @@ public void traitOnSet() { assertThat(list).isEqualTo(List.of("ok1")); } - - - - - @Test - public void testShadowAliasTraitOnClassLogicalRetract() { + @ParameterizedTest() + @MethodSource("parameters") + public void testShadowAliasTraitOnClassLogicalRetract(VirtualPropertyMode mode) { String drl = "package org.drools.test; \n" + "import org.drools.base.factmodel.traits.*; \n" + @@ -1019,12 +991,9 @@ public void testShadowAliasTraitOnClassLogicalRetract() { } - - - - - @Test - public void testShadowAliasClassOnTraitLogicalRetract() { + @ParameterizedTest() + @MethodSource("parameters") + public void testShadowAliasClassOnTraitLogicalRetract(VirtualPropertyMode mode) { String drl = "package org.drools.test; \n" + "import org.drools.base.factmodel.traits.*; \n" + @@ -1124,12 +1093,9 @@ public void testShadowAliasClassOnTraitLogicalRetract() { } - - - - - @Test - public void testSerial() { + @ParameterizedTest() + @MethodSource("parameters") + public void testSerial(VirtualPropertyMode mode) { String drl = "package org.drools.test; \n" + "import org.drools.base.factmodel.traits.*; \n" + @@ -1185,8 +1151,9 @@ public void testSerial() { } } - @Test - public void testTraitMismatchTypes() + @ParameterizedTest() + @MethodSource("parameters") + public void testTraitMismatchTypes(VirtualPropertyMode mode) { String drl = "" + "package org.drools.base.factmodel.traits.test;\n" + @@ -1237,8 +1204,9 @@ public void testTraitMismatchTypes() assertThat(list).hasSize(1).containsNull(); } - @Test - public void testTraitMismatchTypes2() + @ParameterizedTest() + @MethodSource("parameters") + public void testTraitMismatchTypes2(VirtualPropertyMode mode) { String drl = "" + "package org.drools.base.factmodel.traits.test;\n" + @@ -1291,9 +1259,9 @@ public void testTraitMismatchTypes2() assertThat(list).hasSize(1).containsNull(); } - @Test - public void testTraitMismatchTypes3() - { + @ParameterizedTest() + @MethodSource("parameters") + public void testTraitMismatchTypes3(VirtualPropertyMode mode) { String drl = "" + "package org.drools.base.factmodel.traits.test;\n" + "\n" + diff --git a/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/TraitTest.java b/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/TraitTest.java index 8c9142f1664..ddfa9a038e2 100644 --- a/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/TraitTest.java +++ b/drools-traits/src/test/java/org/drools/traits/compiler/factmodel/traits/TraitTest.java @@ -40,7 +40,6 @@ import org.drools.kiesession.rulebase.KnowledgeBaseFactory; import org.drools.traits.compiler.CommonTraitTest; import org.drools.traits.compiler.Person; -import org.drools.traits.compiler.ReviseTraitTestWithPRAlwaysCategory; import org.drools.traits.core.factmodel.Entity; import org.drools.traits.core.factmodel.HierarchyEncoder; import org.drools.traits.core.factmodel.MapWrapper; @@ -53,11 +52,10 @@ import org.drools.traits.core.factmodel.VirtualPropertyMode; import org.drools.traits.core.reteoo.TraitRuntimeComponentFactory; import org.drools.traits.core.util.CodedHierarchyImpl; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.command.Command; import org.kie.api.conf.EqualityBehaviorOption; @@ -101,29 +99,21 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatException; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -@RunWith(Parameterized.class) public class TraitTest extends CommonTraitTest { private static final Logger LOGGER = LoggerFactory.getLogger(TraitTest.class); - public VirtualPropertyMode mode; - - @Parameterized.Parameters - public static Collection modes() { - return List.of(VirtualPropertyMode.MAP, VirtualPropertyMode.TRIPLES); - } - - public TraitTest(VirtualPropertyMode m) { - this.mode = m; + public static Stream parameters() { + return Stream.of(VirtualPropertyMode.MAP, VirtualPropertyMode.TRIPLES); } private KieSession getSession(String... ruleFiles) { @@ -142,8 +132,9 @@ private KieBase getKieBaseFromString(String drl, KieBaseOption... options) { return new KieHelper().addContent(drl, ResourceType.DRL).build(options); } - @Test - public void testRetract() { + @ParameterizedTest() + @MethodSource("parameters") + public void testRetract(VirtualPropertyMode mode) { String drl = "package org.drools.compiler.trait.test; \n" + "import org.drools.base.factmodel.traits.Traitable; \n" + "" + @@ -173,8 +164,9 @@ public void testRetract() { assertThat(ks.getObjects()).isEmpty(); } - @Test - public void testTraitWrapGetAndSet() throws Exception { + @ParameterizedTest() + @MethodSource("parameters") + public void testTraitWrapGetAndSet(VirtualPropertyMode mode) throws Exception { String source = "org/drools/compiler/factmodel/traits/testTraitDon.drl"; KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); @@ -191,31 +183,32 @@ public void testTraitWrapGetAndSet() throws Exception { TraitFactoryImpl tFactory = (TraitFactoryImpl) RuntimeComponentFactory.get().getTraitFactory(kb); FactType impClass = kb.getFactType("org.drools.compiler.trait.test", "Imp"); - TraitableBean imp = (TraitableBean) impClass.newInstance(); - Class trait = kb.getFactType("org.drools.compiler.trait.test", "Student").getFactClass(); + TraitableBean imp = (TraitableBean) impClass.newInstance(); + Class trait = kb.getFactType("org.drools.compiler.trait.test", "Student").getFactClass(); - TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); + TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); - Map virtualFields = imp._getDynamicProperties(); - Map wrapper = proxy.getFields(); + Map virtualFields = imp._getDynamicProperties(); + Map wrapper = proxy.getFields(); - wrapper.put("name", "john"); + wrapper.put("name", "john"); - wrapper.put("virtualField", "xyz"); + wrapper.put("virtualField", "xyz"); - wrapper.entrySet(); - assertThat(wrapper).hasSize(4); - assertThat(virtualFields).hasSize(2); + wrapper.entrySet(); + assertThat(wrapper).hasSize(4); + assertThat(virtualFields).hasSize(2); - assertThat(wrapper.get("name")).isEqualTo("john"); - assertThat(wrapper.get("virtualField")).isEqualTo("xyz"); + assertThat(wrapper.get("name")).isEqualTo("john"); + assertThat(wrapper.get("virtualField")).isEqualTo("xyz"); - assertThat(impClass.get(imp, "name")).isEqualTo("john"); + assertThat(impClass.get(imp, "name")).isEqualTo("john"); } - @Test - public void testTraitShed() { + @ParameterizedTest() + @MethodSource("parameters") + public void testTraitShed(VirtualPropertyMode mode) { String source = "org/drools/compiler/factmodel/traits/testTraitShed.drl"; KieSession ks = getSession(source); @@ -247,8 +240,9 @@ public void testTraitShed() { } - @Test - public void testTraitDon() { + @ParameterizedTest() + @MethodSource("parameters") + public void testTraitDon(VirtualPropertyMode mode) { String source = "org/drools/compiler/factmodel/traits/testTraitDon.drl"; KieSession ks = getSession(source); @@ -277,8 +271,10 @@ public void testTraitDon() { LOGGER.debug(x.getClass().getSuperclass().toString()); LOGGER.debug(List.of(x.getClass().getInterfaces()).toString()); } - @Test - public void testMixin() { + + @ParameterizedTest() + @MethodSource("parameters") + public void testMixin(VirtualPropertyMode mode) { String source = "org/drools/compiler/factmodel/traits/testTraitMixin.drl"; KieSession ks = getSession(source); @@ -292,9 +288,9 @@ public void testMixin() { assertThat(info).contains("27"); } - - @Test - public void traitMethodsWithObjects() { + @ParameterizedTest() + @MethodSource("parameters") + public void traitMethodsWithObjects(VirtualPropertyMode mode) { String source = "org/drools/compiler/factmodel/traits/testTraitWrapping.drl"; KieSession ks = getSession(source); @@ -312,9 +308,9 @@ public void traitMethodsWithObjects() { } - - @Test - public void traitMethodsWithPrimitives() { + @ParameterizedTest() + @MethodSource("parameters") + public void traitMethodsWithPrimitives(VirtualPropertyMode mode) { String source = "org/drools/compiler/factmodel/traits/testTraitWrappingPrimitives.drl"; KieSession ks = getSession(source); @@ -332,9 +328,9 @@ public void traitMethodsWithPrimitives() { } - - @Test - public void testTraitProxy() throws Exception { + @ParameterizedTest() + @MethodSource("parameters") + public void testTraitProxy(VirtualPropertyMode mode) throws Exception { String source = "org/drools/compiler/factmodel/traits/testTraitDon.drl"; @@ -351,39 +347,40 @@ public void testTraitProxy() throws Exception { TraitFactoryImpl tFactory = (TraitFactoryImpl) RuntimeComponentFactory.get().getTraitFactory(kb); FactType impClass = kb.getFactType("org.drools.compiler.trait.test", "Imp"); - TraitableBean imp = (TraitableBean) impClass.newInstance(); - impClass.set(imp, "name", "aaa"); + TraitableBean imp = (TraitableBean) impClass.newInstance(); + impClass.set(imp, "name", "aaa"); - Class trait = kb.getFactType("org.drools.compiler.trait.test", "Student").getFactClass(); - Class trait2 = kb.getFactType("org.drools.compiler.trait.test", "Role").getFactClass(); + Class trait = kb.getFactType("org.drools.compiler.trait.test", "Student").getFactClass(); + Class trait2 = kb.getFactType("org.drools.compiler.trait.test", "Role").getFactClass(); - assertThat(trait).isNotNull(); - TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); - proxy.getFields().put("field", "xyz"); - // proxy.getFields().put("name", "aaa"); + assertThat(trait).isNotNull(); + TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); + proxy.getFields().put("field", "xyz"); + // proxy.getFields().put("name", "aaa"); - assertThat(proxy).isNotNull(); + assertThat(proxy).isNotNull(); - TraitProxyImpl proxy2 = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); - assertThat(proxy).isSameAs(proxy2); + TraitProxyImpl proxy2 = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); + assertThat(proxy).isSameAs(proxy2); - TraitProxyImpl proxy3 = (TraitProxyImpl) tFactory.getProxy(imp, trait2, false); - assertThat(proxy3).isNotNull(); - assertThat(proxy3.getFields().get("field")).isEqualTo("xyz"); - assertThat(proxy3.getFields().get("name")).isEqualTo("aaa"); + TraitProxyImpl proxy3 = (TraitProxyImpl) tFactory.getProxy(imp, trait2, false); + assertThat(proxy3).isNotNull(); + assertThat(proxy3.getFields().get("field")).isEqualTo("xyz"); + assertThat(proxy3.getFields().get("name")).isEqualTo("aaa"); - TraitableBean imp2 = (TraitableBean) impClass.newInstance(); - impClass.set(imp2, "name", "aaa"); - TraitProxyImpl proxy4 = (TraitProxyImpl) tFactory.getProxy(imp2, trait, false); - // proxy4.getFields().put("name", "aaa"); - proxy4.getFields().put("field", "xyz"); + TraitableBean imp2 = (TraitableBean) impClass.newInstance(); + impClass.set(imp2, "name", "aaa"); + TraitProxyImpl proxy4 = (TraitProxyImpl) tFactory.getProxy(imp2, trait, false); + // proxy4.getFields().put("name", "aaa"); + proxy4.getFields().put("field", "xyz"); - assertThat(proxy4).isEqualTo(proxy2); + assertThat(proxy4).isEqualTo(proxy2); } - @Test - public void testWrapperSize() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testWrapperSize(VirtualPropertyMode mode) throws Exception { String source = "org/drools/compiler/factmodel/traits/testTraitDon.drl"; KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); @@ -401,72 +398,73 @@ public void testWrapperSize() throws Exception { FactType impClass = kb.getFactType("org.drools.compiler.trait.test", "Imp"); - TraitableBean imp = (TraitableBean) impClass.newInstance(); - FactType traitClass = kb.getFactType("org.drools.compiler.trait.test", "Student"); - Class trait = traitClass.getFactClass(); - TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); + TraitableBean imp = (TraitableBean) impClass.newInstance(); + FactType traitClass = kb.getFactType("org.drools.compiler.trait.test", "Student"); + Class trait = traitClass.getFactClass(); + TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); - Map virtualFields = imp._getDynamicProperties(); - Map wrapper = proxy.getFields(); - assertThat(wrapper).hasSize(3); - assertThat(virtualFields).hasSize(1); + Map virtualFields = imp._getDynamicProperties(); + Map wrapper = proxy.getFields(); + assertThat(wrapper).hasSize(3); + assertThat(virtualFields).hasSize(1); - impClass.set(imp, "name", "john"); - assertThat(wrapper).hasSize(3); - assertThat(virtualFields).hasSize(1); + impClass.set(imp, "name", "john"); + assertThat(wrapper).hasSize(3); + assertThat(virtualFields).hasSize(1); - proxy.getFields().put("school", "skol"); - assertThat(wrapper).hasSize(3); - assertThat(virtualFields).hasSize(1); + proxy.getFields().put("school", "skol"); + assertThat(wrapper).hasSize(3); + assertThat(virtualFields).hasSize(1); - proxy.getFields().put("surname", "xxx"); - assertThat(wrapper).hasSize(4); - assertThat(virtualFields).hasSize(2); + proxy.getFields().put("surname", "xxx"); + assertThat(wrapper).hasSize(4); + assertThat(virtualFields).hasSize(2); - // FactType indClass = kb.getFactType("org.drools.compiler.trait.test","Entity"); - // TraitableBean ind = (TraitableBean) indClass.newInstance(); - TraitableBean ind = new Entity(); + // FactType indClass = kb.getFactType("org.drools.compiler.trait.test","Entity"); + // TraitableBean ind = (TraitableBean) indClass.newInstance(); + TraitableBean ind = new Entity(); - TraitProxyImpl proxy2 = (TraitProxyImpl) tFactory.getProxy(ind, trait, false); + TraitProxyImpl proxy2 = (TraitProxyImpl) tFactory.getProxy(ind, trait, false); - Map virtualFields2 = ind._getDynamicProperties(); - Map wrapper2 = proxy2.getFields(); - assertThat(wrapper2).hasSize(3); - assertThat(virtualFields2).hasSize(3); + Map virtualFields2 = ind._getDynamicProperties(); + Map wrapper2 = proxy2.getFields(); + assertThat(wrapper2).hasSize(3); + assertThat(virtualFields2).hasSize(3); - traitClass.set(proxy2, "name", "john"); - assertThat(wrapper2).hasSize(3); - assertThat(virtualFields2).hasSize(3); + traitClass.set(proxy2, "name", "john"); + assertThat(wrapper2).hasSize(3); + assertThat(virtualFields2).hasSize(3); - proxy2.getFields().put("school", "skol"); - assertThat(wrapper2).hasSize(3); - assertThat(virtualFields2).hasSize(3); + proxy2.getFields().put("school", "skol"); + assertThat(wrapper2).hasSize(3); + assertThat(virtualFields2).hasSize(3); - proxy2.getFields().put("surname", "xxx"); - assertThat(wrapper2).hasSize(4); - assertThat(virtualFields2).hasSize(4); + proxy2.getFields().put("surname", "xxx"); + assertThat(wrapper2).hasSize(4); + assertThat(virtualFields2).hasSize(4); - FactType traitClass2 = kb.getFactType("org.drools.compiler.trait.test", "Role"); - Class trait2 = traitClass2.getFactClass(); - // TraitableBean ind2 = (TraitableBean) indClass.newInstance(); - TraitableBean ind2 = new Entity(); + FactType traitClass2 = kb.getFactType("org.drools.compiler.trait.test", "Role"); + Class trait2 = traitClass2.getFactClass(); + // TraitableBean ind2 = (TraitableBean) indClass.newInstance(); + TraitableBean ind2 = new Entity(); - TraitProxyImpl proxy99 = (TraitProxyImpl) tFactory.getProxy(ind2, trait2, false); + TraitProxyImpl proxy99 = (TraitProxyImpl) tFactory.getProxy(ind2, trait2, false); - proxy99.getFields().put("surname", "xxx"); - proxy99.getFields().put("name", "xyz"); - proxy99.getFields().put("school", "skol"); + proxy99.getFields().put("surname", "xxx"); + proxy99.getFields().put("name", "xyz"); + proxy99.getFields().put("school", "skol"); - assertThat(proxy99.getFields()).hasSize(3); + assertThat(proxy99.getFields()).hasSize(3); - TraitProxyImpl proxy100 = (TraitProxyImpl) tFactory.getProxy(ind2, trait, false); + TraitProxyImpl proxy100 = (TraitProxyImpl) tFactory.getProxy(ind2, trait, false); - assertThat(proxy100.getFields()).hasSize(4); + assertThat(proxy100.getFields()).hasSize(4); } - @Test - public void testWrapperEmpty() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testWrapperEmpty(VirtualPropertyMode mode) throws Exception { String source = "org/drools/compiler/factmodel/traits/testTraitDon.drl"; KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); @@ -484,47 +482,48 @@ public void testWrapperEmpty() throws Exception { TraitFactoryImpl tFactory = (TraitFactoryImpl) RuntimeComponentFactory.get().getTraitFactory(kb); FactType impClass = kb.getFactType("org.drools.compiler.trait.test", "Imp"); - TraitableBean imp = (TraitableBean) impClass.newInstance(); + TraitableBean imp = (TraitableBean) impClass.newInstance(); - FactType studentClass = kb.getFactType("org.drools.compiler.trait.test", "Student"); - Class trait = studentClass.getFactClass(); - TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); + FactType studentClass = kb.getFactType("org.drools.compiler.trait.test", "Student"); + Class trait = studentClass.getFactClass(); + TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); - Map wrapper = proxy.getFields(); - assertThat(wrapper).isNotEmpty(); + Map wrapper = proxy.getFields(); + assertThat(wrapper).isNotEmpty(); - studentClass.set(proxy, "name", "john"); - assertThat(wrapper).isNotEmpty(); - - studentClass.set(proxy, "name", null); - assertThat(wrapper).isNotEmpty(); + studentClass.set(proxy, "name", "john"); + assertThat(wrapper).isNotEmpty(); + + studentClass.set(proxy, "name", null); + assertThat(wrapper).isNotEmpty(); - studentClass.set(proxy, "age", 32); - assertThat(wrapper).isNotEmpty(); + studentClass.set(proxy, "age", 32); + assertThat(wrapper).isNotEmpty(); - studentClass.set(proxy, "age", null); - assertThat(wrapper).isNotEmpty(); + studentClass.set(proxy, "age", null); + assertThat(wrapper).isNotEmpty(); - // FactType indClass = kb.getFactType("org.drools.compiler.trait.test","Entity"); - TraitableBean ind = new Entity(); + // FactType indClass = kb.getFactType("org.drools.compiler.trait.test","Entity"); + TraitableBean ind = new Entity(); - FactType RoleClass = kb.getFactType("org.drools.compiler.trait.test", "Role"); - Class trait2 = RoleClass.getFactClass(); - TraitProxyImpl proxy2 = (TraitProxyImpl) tFactory.getProxy(ind, trait2, false); + FactType RoleClass = kb.getFactType("org.drools.compiler.trait.test", "Role"); + Class trait2 = RoleClass.getFactClass(); + TraitProxyImpl proxy2 = (TraitProxyImpl) tFactory.getProxy(ind, trait2, false); - Map wrapper2 = proxy2.getFields(); - assertThat(wrapper2).isEmpty(); + Map wrapper2 = proxy2.getFields(); + assertThat(wrapper2).isEmpty(); - proxy2.getFields().put("name", "john"); - assertThat(wrapper2).isNotEmpty(); + proxy2.getFields().put("name", "john"); + assertThat(wrapper2).isNotEmpty(); - proxy2.getFields().put("name", null); - assertThat(wrapper2).isNotEmpty(); + proxy2.getFields().put("name", null); + assertThat(wrapper2).isNotEmpty(); } - @Test - public void testWrapperContainsKey() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testWrapperContainsKey(VirtualPropertyMode mode) throws Exception { String source = "org/drools/compiler/factmodel/traits/testTraitDon.drl"; KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); @@ -542,83 +541,84 @@ public void testWrapperContainsKey() throws Exception { TraitFactoryImpl tFactory = (TraitFactoryImpl) RuntimeComponentFactory.get().getTraitFactory(kb); FactType impClass = kb.getFactType("org.drools.compiler.trait.test", "Imp"); - TraitableBean imp = (TraitableBean) impClass.newInstance(); - impClass.set(imp, "name", "john"); - - FactType traitClass = kb.getFactType("org.drools.compiler.trait.test", "Student"); - Class trait = traitClass.getFactClass(); - TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); - - Map wrapper = proxy.getFields(); - - assertThat(wrapper).containsKey("name"); - assertThat(wrapper).containsKey("school"); - assertThat(wrapper).containsKey("age"); - assertThat(wrapper).doesNotContainKey("surname"); - - proxy.getFields().put("school", "skol"); - proxy.getFields().put("surname", "xxx"); - assertThat(wrapper).containsKey("surname"); - - // FactType indClass = kb.getFactType("org.drools.compiler.trait.test","Entity"); - TraitableBean ind = new Entity(); - - TraitProxyImpl proxy2 = (TraitProxyImpl) tFactory.getProxy(ind, trait, false); - - Map wrapper2 = proxy2.getFields(); - assertThat(wrapper2).containsKey("name"); - assertThat(wrapper2).containsKey("school"); - assertThat(wrapper2).containsKey("age"); - assertThat(wrapper2).doesNotContainKey("surname"); - - traitClass.set(proxy2, "name", "john"); - proxy2.getFields().put("school", "skol"); - proxy2.getFields().put("surname", "xxx"); - assertThat(wrapper2).containsKey("surname"); - - FactType traitClass2 = kb.getFactType("org.drools.compiler.trait.test", "Role"); - Class trait2 = traitClass2.getFactClass(); - TraitableBean ind2 = new Entity(); - - TraitProxyImpl proxy99 = (TraitProxyImpl) tFactory.getProxy(ind2, trait2, false); - Map wrapper99 = proxy99.getFields(); - - assertThat(wrapper99).doesNotContainKey("name"); - assertThat(wrapper99).doesNotContainKey("school"); - assertThat(wrapper99).doesNotContainKey("age"); - assertThat(wrapper99).doesNotContainKey("surname"); - - proxy99.getFields().put("surname", "xxx"); - proxy99.getFields().put("name", "xyz"); - proxy99.getFields().put("school", "skol"); - - assertThat(wrapper99).containsKey("name"); - assertThat(wrapper99).containsKey("school"); - assertThat(wrapper99).doesNotContainKey("age"); - assertThat(wrapper99).containsKey("surname"); - assertThat(proxy99.getFields()).hasSize(3); - - TraitableBean ind0 = new Entity(); - - TraitProxyImpl proxy100 = (TraitProxyImpl) tFactory.getProxy(ind0, trait2, false); - Map wrapper100 = proxy100.getFields(); - assertThat(wrapper100).doesNotContainKey("name"); - assertThat(wrapper100).doesNotContainKey("school"); - assertThat(wrapper100).doesNotContainKey("age"); - assertThat(wrapper100).doesNotContainKey("surname"); - - TraitProxyImpl proxy101 = (TraitProxyImpl) tFactory.getProxy(ind0, trait, false); - // object gains properties by virtue of another trait - // so new props are accessible even using the old proxy - assertThat(wrapper100).containsKey("name"); - assertThat(wrapper100).containsKey("school"); - assertThat(wrapper100).containsKey("age"); - assertThat(wrapper100).doesNotContainKey("surname"); + TraitableBean imp = (TraitableBean) impClass.newInstance(); + impClass.set(imp, "name", "john"); + + FactType traitClass = kb.getFactType("org.drools.compiler.trait.test", "Student"); + Class trait = traitClass.getFactClass(); + TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); + + Map wrapper = proxy.getFields(); + + assertThat(wrapper).containsKey("name"); + assertThat(wrapper).containsKey("school"); + assertThat(wrapper).containsKey("age"); + assertThat(wrapper).doesNotContainKey("surname"); + + proxy.getFields().put("school", "skol"); + proxy.getFields().put("surname", "xxx"); + assertThat(wrapper).containsKey("surname"); + + // FactType indClass = kb.getFactType("org.drools.compiler.trait.test","Entity"); + TraitableBean ind = new Entity(); + + TraitProxyImpl proxy2 = (TraitProxyImpl) tFactory.getProxy(ind, trait, false); + + Map wrapper2 = proxy2.getFields(); + assertThat(wrapper2).containsKey("name"); + assertThat(wrapper2).containsKey("school"); + assertThat(wrapper2).containsKey("age"); + assertThat(wrapper2).doesNotContainKey("surname"); + + traitClass.set(proxy2, "name", "john"); + proxy2.getFields().put("school", "skol"); + proxy2.getFields().put("surname", "xxx"); + assertThat(wrapper2).containsKey("surname"); + + FactType traitClass2 = kb.getFactType("org.drools.compiler.trait.test", "Role"); + Class trait2 = traitClass2.getFactClass(); + TraitableBean ind2 = new Entity(); + + TraitProxyImpl proxy99 = (TraitProxyImpl) tFactory.getProxy(ind2, trait2, false); + Map wrapper99 = proxy99.getFields(); + + assertThat(wrapper99).doesNotContainKey("name"); + assertThat(wrapper99).doesNotContainKey("school"); + assertThat(wrapper99).doesNotContainKey("age"); + assertThat(wrapper99).doesNotContainKey("surname"); + + proxy99.getFields().put("surname", "xxx"); + proxy99.getFields().put("name", "xyz"); + proxy99.getFields().put("school", "skol"); + + assertThat(wrapper99).containsKey("name"); + assertThat(wrapper99).containsKey("school"); + assertThat(wrapper99).doesNotContainKey("age"); + assertThat(wrapper99).containsKey("surname"); + assertThat(proxy99.getFields()).hasSize(3); + + TraitableBean ind0 = new Entity(); + + TraitProxyImpl proxy100 = (TraitProxyImpl) tFactory.getProxy(ind0, trait2, false); + Map wrapper100 = proxy100.getFields(); + assertThat(wrapper100).doesNotContainKey("name"); + assertThat(wrapper100).doesNotContainKey("school"); + assertThat(wrapper100).doesNotContainKey("age"); + assertThat(wrapper100).doesNotContainKey("surname"); + + TraitProxyImpl proxy101 = (TraitProxyImpl) tFactory.getProxy(ind0, trait, false); + // object gains properties by virtue of another trait + // so new props are accessible even using the old proxy + assertThat(wrapper100).containsKey("name"); + assertThat(wrapper100).containsKey("school"); + assertThat(wrapper100).containsKey("age"); + assertThat(wrapper100).doesNotContainKey("surname"); } - @Test - public void testInternalComponents1() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testInternalComponents1(VirtualPropertyMode mode) throws Exception { String source = "org/drools/compiler/factmodel/traits/testTraitDon.drl"; KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); @@ -636,40 +636,41 @@ public void testInternalComponents1() throws Exception { FactType impClass = kb.getFactType("org.drools.compiler.trait.test", "Imp"); - TraitableBean imp = (TraitableBean) impClass.newInstance(); - FactType traitClass = kb.getFactType("org.drools.compiler.trait.test", "Student"); - Class trait = traitClass.getFactClass(); - TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); - Object proxyFields = proxy.getFields(); - Object coreTraits = imp._getTraitMap(); - Object coreProperties = imp._getDynamicProperties(); - - assertThat(proxyFields).isNotNull(); - assertThat(coreTraits).isNotNull(); - assertThat(coreProperties).isNotNull(); - - if (mode == VirtualPropertyMode.MAP) { - assertThat(proxyFields).isInstanceOf(MapWrapper.class); - assertThat(coreTraits).isInstanceOf(TraitTypeMapImpl.class); - assertThat(coreProperties).isInstanceOf(HashMap.class); - } else { - assertThat(proxyFields.getClass().getName()).isEqualTo("org.drools.compiler.trait.test.Student.org.drools.compiler.trait.test.Imp_ProxyWrapper"); - - assertThat(proxyFields).isInstanceOf(TripleBasedStruct.class); - assertThat(coreTraits).isInstanceOf(TraitTypeMapImpl.class); - assertThat(coreProperties).isInstanceOf(TripleBasedBean.class); - } - - - StudentProxyImpl2 sp2 = new StudentProxyImpl2(new Imp2(), null); - LOGGER.debug(sp2.toString()); + TraitableBean imp = (TraitableBean) impClass.newInstance(); + FactType traitClass = kb.getFactType("org.drools.compiler.trait.test", "Student"); + Class trait = traitClass.getFactClass(); + TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); + Object proxyFields = proxy.getFields(); + Object coreTraits = imp._getTraitMap(); + Object coreProperties = imp._getDynamicProperties(); + + assertThat(proxyFields).isNotNull(); + assertThat(coreTraits).isNotNull(); + assertThat(coreProperties).isNotNull(); + + if (mode == VirtualPropertyMode.MAP) { + assertThat(proxyFields).isInstanceOf(MapWrapper.class); + assertThat(coreTraits).isInstanceOf(TraitTypeMapImpl.class); + assertThat(coreProperties).isInstanceOf(HashMap.class); + } else { + assertThat(proxyFields.getClass().getName()).isEqualTo("org.drools.compiler.trait.test.Student.org.drools.compiler.trait.test.Imp_ProxyWrapper"); + + assertThat(proxyFields).isInstanceOf(TripleBasedStruct.class); + assertThat(coreTraits).isInstanceOf(TraitTypeMapImpl.class); + assertThat(coreProperties).isInstanceOf(TripleBasedBean.class); + } + + + StudentProxyImpl2 sp2 = new StudentProxyImpl2(new Imp2(), null); + LOGGER.debug(sp2.toString()); } - @Test - public void testWrapperKeySetAndValues() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testWrapperKeySetAndValues(VirtualPropertyMode mode) throws Exception { String source = "org/drools/compiler/factmodel/traits/testTraitDon.drl"; KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); @@ -686,53 +687,54 @@ public void testWrapperKeySetAndValues() throws Exception { TraitFactoryImpl tFactory = (TraitFactoryImpl) RuntimeComponentFactory.get().getTraitFactory(kb); FactType impClass = kb.getFactType("org.drools.compiler.trait.test", "Imp"); - TraitableBean imp = (TraitableBean) impClass.newInstance(); - FactType traitClass = kb.getFactType("org.drools.compiler.trait.test", "Student"); - Class trait = traitClass.getFactClass(); - TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); - - impClass.set(imp, "name", "john"); - proxy.getFields().put("surname", "xxx"); - proxy.getFields().put("name2", "john"); - proxy.getFields().put("nfield", null); - - assertThat(proxy.getFields()).hasSize(6); - assertThat(proxy.getFields().keySet()).contains("name", "surname", "age", "school", "name2", "nfield"); - - List col1 = new ArrayList<>(proxy.getFields().values()); - List col2 = Arrays.asList("john", null, 0, "xxx", "john", null); - - Comparator comp = new Comparator() { - - public int compare(Object o1, Object o2) { - if (o1 == null && o2 != null) { - return 1; - } - if (o1 != null && o2 == null) { - return -1; - } - if (o1 == null && o2 == null) { - return 0; - } - return o1.toString().compareTo(o2.toString()); - } - }; - - Collections.sort(col1, comp); - Collections.sort(col2, comp); - assertThat(col2).isEqualTo(col1); - - assertThat(proxy.getFields()).containsValue(null); - assertThat(proxy.getFields()).containsValue("john"); - assertThat(proxy.getFields()).containsValue(0); - assertThat(proxy.getFields()).containsValue("xxx"); - assertThat(proxy.getFields()).doesNotContainValue("randomString"); - assertThat(proxy.getFields()).doesNotContainValue(-96); + TraitableBean imp = (TraitableBean) impClass.newInstance(); + FactType traitClass = kb.getFactType("org.drools.compiler.trait.test", "Student"); + Class trait = traitClass.getFactClass(); + TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); + + impClass.set(imp, "name", "john"); + proxy.getFields().put("surname", "xxx"); + proxy.getFields().put("name2", "john"); + proxy.getFields().put("nfield", null); + + assertThat(proxy.getFields()).hasSize(6); + assertThat(proxy.getFields().keySet()).contains("name", "surname", "age", "school", "name2", "nfield"); + + List col1 = new ArrayList<>(proxy.getFields().values()); + List col2 = Arrays.asList("john", null, 0, "xxx", "john", null); + + Comparator comp = new Comparator() { + + public int compare(Object o1, Object o2) { + if (o1 == null && o2 != null) { + return 1; + } + if (o1 != null && o2 == null) { + return -1; + } + if (o1 == null && o2 == null) { + return 0; + } + return o1.toString().compareTo(o2.toString()); + } + }; + + Collections.sort(col1, comp); + Collections.sort(col2, comp); + assertThat(col2).isEqualTo(col1); + + assertThat(proxy.getFields()).containsValue(null); + assertThat(proxy.getFields()).containsValue("john"); + assertThat(proxy.getFields()).containsValue(0); + assertThat(proxy.getFields()).containsValue("xxx"); + assertThat(proxy.getFields()).doesNotContainValue("randomString"); + assertThat(proxy.getFields()).doesNotContainValue(-96); } - @Test - public void testWrapperClearAndRemove() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testWrapperClearAndRemove(VirtualPropertyMode mode) throws Exception { String source = "org/drools/compiler/factmodel/traits/testTraitDon.drl"; KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); @@ -748,75 +750,76 @@ public void testWrapperClearAndRemove() throws Exception { TraitFactoryImpl tFactory = (TraitFactoryImpl) RuntimeComponentFactory.get().getTraitFactory(kb); FactType impClass = kb.getFactType("org.drools.compiler.trait.test", "Imp"); - TraitableBean imp = (TraitableBean) impClass.newInstance(); - impClass.set(imp, "name", "john"); - FactType traitClass = kb.getFactType("org.drools.compiler.trait.test", "Student"); - Class trait = traitClass.getFactClass(); - TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); - - proxy.getFields().put("surname", "xxx"); - proxy.getFields().put("name2", "john"); - proxy.getFields().put("nfield", null); - - Set set = new HashSet<>(); - set.add("name"); - set.add("surname"); - set.add("age"); - set.add("school"); - set.add("name2"); - set.add("nfield"); - - assertThat(proxy.getFields()).hasSize(6); - assertThat(proxy.getFields().keySet()).isEqualTo(set); - - proxy.getFields().clear(); - - Map fields = proxy.getFields(); - assertThat(fields).hasSize(3); - assertThat(fields).containsKey("age"); - assertThat(fields).containsKey("school"); - assertThat(fields).containsKey("name"); - - assertThat(fields.get("age")).isEqualTo(0); - assertThat(fields.get("school")).isNull(); - assertThat(fields.get("name")).isNotNull(); - - proxy.getFields().put("surname", "xxx"); - proxy.getFields().put("name2", "john"); - proxy.getFields().put("nfield", null); - proxy.getFields().put("age", 24); - - assertThat(proxy.getFields().get("name")).isEqualTo("john"); - assertThat(proxy.getFields().get("surname")).isEqualTo("xxx"); - assertThat(proxy.getFields().get("name2")).isEqualTo("john"); - assertThat(proxy.getFields().get("nfield")).isEqualTo(null); - assertThat(proxy.getFields().get("age")).isEqualTo(24); - assertThat(proxy.getFields().get("school")).isEqualTo(null); - - proxy.getFields().remove("surname"); - proxy.getFields().remove("name2"); - proxy.getFields().remove("age"); - proxy.getFields().remove("school"); - proxy.getFields().remove("nfield"); - assertThat(proxy.getFields()).hasSize(3); - - assertThat(proxy.getFields().get("age")).isEqualTo(0); - assertThat(proxy.getFields().get("school")).isEqualTo(null); - assertThat(proxy.getFields().get("name")).isEqualTo("john"); - - assertThat(proxy.getFields().get("nfield")).isEqualTo(null); - assertThat(proxy.getFields()).doesNotContainKey("nfield"); - - assertThat(proxy.getFields().get("name2")).isEqualTo(null); - assertThat(proxy.getFields()).doesNotContainKey("name2"); - - assertThat(proxy.getFields().get("surname")).isEqualTo(null); - assertThat(proxy.getFields()).doesNotContainKey("surname"); + TraitableBean imp = (TraitableBean) impClass.newInstance(); + impClass.set(imp, "name", "john"); + FactType traitClass = kb.getFactType("org.drools.compiler.trait.test", "Student"); + Class trait = traitClass.getFactClass(); + TraitProxyImpl proxy = (TraitProxyImpl) tFactory.getProxy(imp, trait, false); + + proxy.getFields().put("surname", "xxx"); + proxy.getFields().put("name2", "john"); + proxy.getFields().put("nfield", null); + + Set set = new HashSet<>(); + set.add("name"); + set.add("surname"); + set.add("age"); + set.add("school"); + set.add("name2"); + set.add("nfield"); + + assertThat(proxy.getFields()).hasSize(6); + assertThat(proxy.getFields().keySet()).isEqualTo(set); + + proxy.getFields().clear(); + + Map fields = proxy.getFields(); + assertThat(fields).hasSize(3); + assertThat(fields).containsKey("age"); + assertThat(fields).containsKey("school"); + assertThat(fields).containsKey("name"); + + assertThat(fields.get("age")).isEqualTo(0); + assertThat(fields.get("school")).isNull(); + assertThat(fields.get("name")).isNotNull(); + + proxy.getFields().put("surname", "xxx"); + proxy.getFields().put("name2", "john"); + proxy.getFields().put("nfield", null); + proxy.getFields().put("age", 24); + + assertThat(proxy.getFields().get("name")).isEqualTo("john"); + assertThat(proxy.getFields().get("surname")).isEqualTo("xxx"); + assertThat(proxy.getFields().get("name2")).isEqualTo("john"); + assertThat(proxy.getFields().get("nfield")).isEqualTo(null); + assertThat(proxy.getFields().get("age")).isEqualTo(24); + assertThat(proxy.getFields().get("school")).isEqualTo(null); + + proxy.getFields().remove("surname"); + proxy.getFields().remove("name2"); + proxy.getFields().remove("age"); + proxy.getFields().remove("school"); + proxy.getFields().remove("nfield"); + assertThat(proxy.getFields()).hasSize(3); + + assertThat(proxy.getFields().get("age")).isEqualTo(0); + assertThat(proxy.getFields().get("school")).isEqualTo(null); + assertThat(proxy.getFields().get("name")).isEqualTo("john"); + + assertThat(proxy.getFields().get("nfield")).isEqualTo(null); + assertThat(proxy.getFields()).doesNotContainKey("nfield"); + + assertThat(proxy.getFields().get("name2")).isEqualTo(null); + assertThat(proxy.getFields()).doesNotContainKey("name2"); + + assertThat(proxy.getFields().get("surname")).isEqualTo(null); + assertThat(proxy.getFields()).doesNotContainKey("surname"); } - @Test - public void testIsAEvaluator() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testIsAEvaluator(VirtualPropertyMode mode) { String source = "package org.drools.compiler.trait.test;\n" + "\n" + "import org.drools.base.factmodel.traits.Traitable;\n" + @@ -886,8 +889,9 @@ public void testIsAEvaluator() { - @Test - public void testIsA() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testIsA(VirtualPropertyMode mode) { String source = "org/drools/compiler/factmodel/traits/testTraitIsA.drl"; KieSession ks = getSession(source); @@ -911,8 +915,9 @@ public void testIsA() { - @Test - public void testOverrideType() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testOverrideType(VirtualPropertyMode mode) { String source = "org/drools/compiler/factmodel/traits/testTraitOverride.drl"; KieSession ks = getSession(source); @@ -922,17 +927,18 @@ public void testOverrideType() { ks.setGlobal("list", info); assertThatException() - .as("An exception was expected since a trait can't override the type of a core class field with these settings ") - .isThrownBy(() -> ks.fireAllRules()) - .extracting(e -> e.getCause()) - .isInstanceOf(UnsupportedOperationException.class); + .as("An exception was expected since a trait can't override the type of a core class field with these settings ") + .isThrownBy(() -> ks.fireAllRules()) + .extracting(e -> e.getCause()) + .isInstanceOf(UnsupportedOperationException.class); } - @Test - public void testOverrideType2() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testOverrideType2(VirtualPropertyMode mode) { String drl = "package org.drools.compiler.trait.test; \n" + "import org.drools.base.factmodel.traits.Traitable; \n" + "" + @@ -951,16 +957,17 @@ public void testOverrideType2() { TraitFactoryImpl.setMode(mode, ks.getKieBase()); assertThatException() - .as("An exception was expected since a trait can't override the type of a core class field with these settings ") - .isThrownBy(() -> ks.fireAllRules()) - .extracting(e -> e.getCause()) - .isInstanceOf(UnsupportedOperationException.class); + .as("An exception was expected since a trait can't override the type of a core class field with these settings ") + .isThrownBy(() -> ks.fireAllRules()) + .extracting(e -> e.getCause()) + .isInstanceOf(UnsupportedOperationException.class); } - @Test - public void testOverrideType3() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testOverrideType3(VirtualPropertyMode mode) { String drl = "package org.drools.compiler.trait.test; \n" + "import org.drools.base.factmodel.traits.Traitable; \n" + "" + @@ -980,15 +987,16 @@ public void testOverrideType3() { assertThatException() - .as("An exception was expected since a trait can't override the type of a core class field with these settings ") - .isThrownBy(() -> ks.fireAllRules()) - .extracting(e -> e.getCause()) - .isInstanceOf(UnsupportedOperationException.class); + .as("An exception was expected since a trait can't override the type of a core class field with these settings ") + .isThrownBy(() -> ks.fireAllRules()) + .extracting(e -> e.getCause()) + .isInstanceOf(UnsupportedOperationException.class); } - @Test - public void testTraitLegacy() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitLegacy(VirtualPropertyMode mode) { String source = "org/drools/compiler/factmodel/traits/testTraitLegacyTrait.drl"; KieSession ks = getSession(source); @@ -1021,8 +1029,9 @@ private void printDebugInfoSessionObjects(final Collection fac LOGGER.debug(" -------------- ---------------- "); } - @Test - public void testTraitCollections() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitCollections(VirtualPropertyMode mode) { String source = "org/drools/compiler/factmodel/traits/testTraitCollections.drl"; KieSession ks = getSession(source); @@ -1041,8 +1050,9 @@ public void testTraitCollections() { } - @Test - public void testTraitCore() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitCore(VirtualPropertyMode mode) { String source = "org/drools/compiler/factmodel/traits/testTraitLegacyCore.drl"; KieSession ks = getSession(source); @@ -1061,8 +1071,9 @@ public void testTraitCore() { } - @Test - public void traitWithEquality() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void traitWithEquality(VirtualPropertyMode mode) { String source = "org/drools/compiler/factmodel/traits/testTraitWithEquality.drl"; KieSession ks = getSession(source); @@ -1078,8 +1089,9 @@ public void traitWithEquality() { } - @Test - public void traitDeclared() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void traitDeclared(VirtualPropertyMode mode) { List trueTraits = new ArrayList(); List untrueTraits = new ArrayList(); @@ -1099,8 +1111,9 @@ public void traitDeclared() { assertThat(untrueTraits).doesNotContain(1); } - @Test - public void traitPojo() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void traitPojo(VirtualPropertyMode mode) { List trueTraits = new ArrayList(); List untrueTraits = new ArrayList(); @@ -1120,8 +1133,9 @@ public void traitPojo() { assertThat(untrueTraits).doesNotContain(1); } - @Test - public void testIsAOperator() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testIsAOperator(VirtualPropertyMode mode) { String source = "org/drools/compiler/factmodel/traits/testTraitIsA2.drl"; KieSession ksession = getSession(source); TraitFactoryImpl.setMode(mode, ksession.getKieBase()); @@ -1146,8 +1160,9 @@ public void testIsAOperator() { } - @Test - public void testManyTraits() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testManyTraits(VirtualPropertyMode mode) { String source = "" + "import " + Message.class.getCanonicalName() + ";\n" + "" + @@ -1205,8 +1220,9 @@ public void testManyTraits() { } - @Test - public void traitManyTimes() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void traitManyTimes(VirtualPropertyMode mode) { KieSession ksession = getSession("org/drools/compiler/factmodel/traits/testTraitDonMultiple.drl"); TraitFactoryImpl.setMode(mode, ksession.getKieBase()); @@ -1229,8 +1245,9 @@ public void traitManyTimes() { } // BZ #748752 - @Test - public void traitsInBatchExecution() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void traitsInBatchExecution(VirtualPropertyMode mode) { String str = "package org.jboss.qa.brms.traits\n" + "import org.drools.traits.compiler.Person;\n" + "import org.drools.base.factmodel.traits.Traitable;\n" + @@ -1298,8 +1315,10 @@ public void traitsInBatchExecution() { assertThat(list).contains(2); } - @Test(timeout=10000) - public void testManyTraitsStateless() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + @Timeout(10000) + public void testManyTraitsStateless(VirtualPropertyMode mode) { String source = "" + "import " + Message.class.getCanonicalName() + ";\n" + "" + @@ -1357,8 +1376,9 @@ public void testManyTraitsStateless() { - @Test - public void testAliasing() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testAliasing(VirtualPropertyMode mode) { String drl = "package org.drools.traits\n" + "import org.drools.base.factmodel.traits.Traitable;\n" + "import org.drools.base.factmodel.traits.Alias;\n" + @@ -1430,8 +1450,9 @@ public void testAliasing() { - @Test - public void testTraitLogicalRemoval() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitLogicalRemoval(VirtualPropertyMode mode) { String drl = "package org.drools.trait.test;\n" + "\n" + "import org.drools.base.factmodel.traits.Traitable;\n" + @@ -1505,8 +1526,9 @@ public void testTraitLogicalRemoval() { } - @Test - public void testTMSConsistencyWithNonTraitableBeans() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTMSConsistencyWithNonTraitableBeans(VirtualPropertyMode mode) { String s1 = "package org.drools.test;\n" + "import org.drools.traits.compiler.Person; \n" + @@ -1569,8 +1591,9 @@ public static class TBean { - @Test - public void testTraitsLegacyWrapperCoherence() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitsLegacyWrapperCoherence(VirtualPropertyMode mode) { String str = "package org.drools.trait.test; \n" + "global java.util.List list; \n" + "import org.drools.base.factmodel.traits.Traitable;\n" + @@ -1641,8 +1664,9 @@ public void testTraitsLegacyWrapperCoherence() { - @Test - public void testHasTypes() throws Exception { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testHasTypes(VirtualPropertyMode mode) throws Exception { String source = "org/drools/compiler/factmodel/traits/testTraitDon.drl"; @@ -1659,31 +1683,32 @@ public void testHasTypes() throws Exception { TraitFactoryImpl.setMode(mode, kb); FactType impClass = kb.getFactType("org.drools.compiler.trait.test","Imp"); - TraitableBean imp = (TraitableBean) impClass.newInstance(); - impClass.set(imp, "name", "aaabcd"); + TraitableBean imp = (TraitableBean) impClass.newInstance(); + impClass.set(imp, "name", "aaabcd"); - Class trait = kb.getFactType("org.drools.compiler.trait.test","Student").getFactClass(); - Class trait2 = kb.getFactType("org.drools.compiler.trait.test","Role").getFactClass(); + Class trait = kb.getFactType("org.drools.compiler.trait.test","Student").getFactClass(); + Class trait2 = kb.getFactType("org.drools.compiler.trait.test","Role").getFactClass(); - assertThat(trait).isNotNull(); + assertThat(trait).isNotNull(); - TraitProxyImpl proxy = (TraitProxyImpl) traitBuilder.getProxy(imp, trait, false); - Thing thing = traitBuilder.getProxy(imp, Thing.class, false); + TraitProxyImpl proxy = (TraitProxyImpl) traitBuilder.getProxy(imp, trait, false); + Thing thing = traitBuilder.getProxy(imp, Thing.class, false); - TraitableBean core = proxy.getObject(); + TraitableBean core = proxy.getObject(); - TraitProxyImpl proxy2 = (TraitProxyImpl) traitBuilder.getProxy(imp, trait, false); - Thing thing2 = traitBuilder.getProxy(imp, Thing.class, false); + TraitProxyImpl proxy2 = (TraitProxyImpl) traitBuilder.getProxy(imp, trait, false); + Thing thing2 = traitBuilder.getProxy(imp, Thing.class, false); - assertThat(proxy2).isSameAs(proxy); - assertThat(thing2).isSameAs(thing); + assertThat(proxy2).isSameAs(proxy); + assertThat(thing2).isSameAs(thing); - assertThat(core.getTraits()).hasSize(2); + assertThat(core.getTraits()).hasSize(2); } - @Test - public void testTraitRedundancy() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitRedundancy(VirtualPropertyMode mode) { String str = "package org.drools.traits.compiler.factmodel.traits; \n" + "global java.util.List list; \n" + "" + @@ -1742,8 +1767,9 @@ public void testTraitRedundancy() { } - @Test - public void traitSimpleTypes() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void traitSimpleTypes(VirtualPropertyMode mode) { String s1 = "package org.drools.factmodel.traits;\n" + "\n" + @@ -1798,8 +1824,9 @@ public void traitSimpleTypes() { - @Test - public void testTraitEncoding() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitEncoding(VirtualPropertyMode mode) { String s1 = "package org.drools.base.factmodel.traits;\n" + "import " + Entity.class.getCanonicalName() + ";\n" + "declare trait A end\n" + @@ -1873,15 +1900,15 @@ public void testTraitEncoding() { } - - - @Test - public void testTraitActualTypeCodeWithEntities() { + @ParameterizedTest() + @MethodSource("parameters") + public void testTraitActualTypeCodeWithEntities(VirtualPropertyMode mode) { testTraitActualTypeCodeWithEntities("ent", mode); } - @Test - public void testTraitActualTypeCodeWithCoreMap() { + @ParameterizedTest() + @MethodSource("parameters") + public void testTraitActualTypeCodeWithCoreMap(VirtualPropertyMode mode) { testTraitActualTypeCodeWithEntities("kor", mode); } @@ -1933,8 +1960,9 @@ void testTraitActualTypeCodeWithEntities(String trig, VirtualPropertyMode mode) } - @Test - public void testTraitModifyCore() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitModifyCore(VirtualPropertyMode mode) { String s1 = "package test; " + "import org.drools.base.factmodel.traits.*; " + "" + @@ -2021,8 +2049,9 @@ public void testTraitModifyCore() { - @Test - public void testTraitModifyCore2() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitModifyCore2(VirtualPropertyMode mode) { String s1 = "package test; " + "import org.drools.base.factmodel.traits.*; " + "" + @@ -2107,8 +2136,9 @@ public void testTraitModifyCore2() { } - @Test - public void testTraitModifyCore2a() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitModifyCore2a(VirtualPropertyMode mode) { String s1 = "package test;\n" + "import org.drools.base.factmodel.traits.*;\n" + "import org.drools.traits.core.factmodel.*;\n" + @@ -2170,8 +2200,9 @@ public void testTraitModifyCore2a() { - @Test - public void testTraitModifyCore3() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitModifyCore3(VirtualPropertyMode mode) { String s1 = "package test;\n" + "import org.drools.base.factmodel.traits.*;\n" + "import org.drools.traits.core.factmodel.*;\n" + @@ -2281,8 +2312,9 @@ public void testTraitModifyCore3() { - @Test - public void testTraitModifyCoreWithPropertyReactivity() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitModifyCoreWithPropertyReactivity(VirtualPropertyMode mode) { String s1 = "package test;\n" + "import org.drools.base.factmodel.traits.*;\n" + "import org.drools.traits.core.factmodel.*;\n" + @@ -2390,8 +2422,9 @@ public void testTraitModifyCoreWithPropertyReactivity() { public static interface IntfParent {} - @Test - public void testTraitEncodeExtendingNonTrait() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitEncodeExtendingNonTrait(VirtualPropertyMode mode) { String s1 = "package test;\n" + "import " + IntfParent.class.getCanonicalName() + ";\n" + @@ -2426,8 +2459,9 @@ public void testTraitEncodeExtendingNonTrait() { - @Test - public void isAWithBackChaining() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void isAWithBackChaining(VirtualPropertyMode mode) { String source = "org/drools/compiler/factmodel/traits/testTraitIsAWithBC.drl"; KieSession ksession = getSession(source); @@ -2448,8 +2482,9 @@ public void isAWithBackChaining() { - @Test - public void testIsAEvaluatorOnClassification() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testIsAEvaluatorOnClassification(VirtualPropertyMode mode) { String source = "package t.x \n" + "\n" + "global java.util.List list; \n" + @@ -2506,8 +2541,9 @@ public void testIsAEvaluatorOnClassification() { - @Test - public void testShedWithTMS() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testShedWithTMS(VirtualPropertyMode mode) { String source = "package t.x \n" + "\n" + "global java.util.List list; \n" + @@ -2584,8 +2620,9 @@ public void testShedWithTMS() { - @Test - public void testTraitInitialization() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitInitialization(VirtualPropertyMode mode) { String source = "package t.x \n" + "import java.util.*; \n" + "import org.drools.base.factmodel.traits.Thing \n" + @@ -2659,8 +2696,9 @@ public void testTraitInitialization() { - @Test - public void testUnTraitedBean() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testUnTraitedBean(VirtualPropertyMode mode) { String source = "package t.x \n" + "import java.util.*; \n" + "import org.drools.base.factmodel.traits.Thing \n" + @@ -2707,8 +2745,9 @@ public void testUnTraitedBean() { - @Test - public void testIsAOptimization() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testIsAOptimization(VirtualPropertyMode mode) { String source = "package t.x \n" + "import java.util.*; \n" + "import org.drools.base.factmodel.traits.Thing \n" + @@ -2767,8 +2806,9 @@ public void testIsAOptimization() { - @Test - public void testTypeRefractionOnInsert() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTypeRefractionOnInsert(VirtualPropertyMode mode) { String source = "package t.x \n" + "import java.util.*; \n" + "import org.drools.base.factmodel.traits.Thing \n" + @@ -2820,8 +2860,9 @@ public void testTypeRefractionOnInsert() { - @Test - public void testTypeRefractionOnQuery() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTypeRefractionOnQuery(VirtualPropertyMode mode) { String source = "declare BaseObject\n" + "@Traitable\n" + "id : String @key\n" + @@ -2862,8 +2903,9 @@ public void testTypeRefractionOnQuery() { } - @Test - public void testTypeRefractionOnQuery2() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTypeRefractionOnQuery2(VirtualPropertyMode mode) { String source = "package t.x \n" + "import java.util.*; \n" + "import org.drools.base.factmodel.traits.Thing \n" + @@ -2922,8 +2964,9 @@ public void testTypeRefractionOnQuery2() { } - @Test - public void testNodePartitioningByProxies() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testNodePartitioningByProxies(VirtualPropertyMode mode) { String source = "package t.x " + "import java.util.*; " + "import org.drools.base.factmodel.traits.Thing " + @@ -2990,8 +3033,9 @@ public void testNodePartitioningByProxies() { } - @Test - public void testNodePartitioningByProxiesAfterShed() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testNodePartitioningByProxiesAfterShed(VirtualPropertyMode mode) { String source = "package t.x " + "import java.util.*; " + "import org.drools.base.factmodel.traits.Thing \n" + @@ -3063,8 +3107,9 @@ public void testNodePartitioningByProxiesAfterShed() { } - @Test - public void testTypeRefractionOnQueryWithIsA() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTypeRefractionOnQueryWithIsA(VirtualPropertyMode mode) { String source = "package t.x \n" + "import java.util.*; \n" + "import org.drools.base.factmodel.traits.Thing \n" + @@ -3121,8 +3166,9 @@ public void testTypeRefractionOnQueryWithIsA() { - @Test - public void testCoreUpdate4() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testCoreUpdate4(VirtualPropertyMode mode) { String source = "package t.x \n" + "import java.util.*; \n" + "import org.drools.base.factmodel.traits.Thing \n" + @@ -3179,8 +3225,9 @@ public void testCoreUpdate4() { - @Test - public void traitLogicalSupportAnddelete() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void traitLogicalSupportAnddelete(VirtualPropertyMode mode) { String drl = "package org.drools.trait.test;\n" + "\n" + "import org.drools.base.factmodel.traits.Traitable;\n" + @@ -3311,8 +3358,9 @@ public void traitLogicalSupportAnddelete() { assertThat(ksession.getObjects()).hasSize(1); } - @Test - public void testShedThing() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testShedThing(VirtualPropertyMode mode) { String s1 = "package test;\n" + "import org.drools.base.factmodel.traits.*;\n" + "import org.drools.traits.core.factmodel.*;\n" + @@ -3382,8 +3430,9 @@ public void testShedThing() { } - @Test - public void testdeleteThings() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testdeleteThings(VirtualPropertyMode mode) { String s1 = "package test;\n" + "import org.drools.base.factmodel.traits.*;\n" + "import org.drools.traits.core.factmodel.*;\n" + @@ -3452,8 +3501,9 @@ public void testdeleteThings() { assertThat(ksession.getObjects()).isEmpty(); } - @Test - public void traitLogicalRemovalSimple() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void traitLogicalRemovalSimple(VirtualPropertyMode mode) { String drl = "package org.drools.compiler.trait.test;\n" + "\n" + "import org.drools.base.factmodel.traits.Traitable;\n" + @@ -3540,8 +3590,9 @@ public XYZ() { } - @Test - public void testTraitDonLegacyClassWithoutEmptyConstructor() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitDonLegacyClassWithoutEmptyConstructor(VirtualPropertyMode mode) { String drl = "package org.drools.compiler.trait.test;\n" + "\n" + "import " + TraitableFoo.class.getCanonicalName() + ";" + @@ -3576,8 +3627,9 @@ public void testTraitDonLegacyClassWithoutEmptyConstructor() { - @Test - public void testdeleteCoreObjectChained() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testdeleteCoreObjectChained(VirtualPropertyMode mode) { String source = "package org.drools.test;\n" + "import java.util.List; \n" + "import org.drools.base.factmodel.traits.Thing \n" + @@ -3642,8 +3694,9 @@ public void testdeleteCoreObjectChained() { } - @Test - public void testUpdateLegacyClass() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testUpdateLegacyClass(VirtualPropertyMode mode) { String source = "package org.drools.text;\n" + "\n" + "global java.util.List list;\n" + @@ -3700,8 +3753,9 @@ public void testUpdateLegacyClass() { - @Test - public void testSoftPropertyClash() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testSoftPropertyClash(VirtualPropertyMode mode) { String source = "package org.drools.text;\n" + "\n" + "global java.util.List list;\n" + @@ -3782,8 +3836,9 @@ public void testSoftPropertyClash() { } - @Test - public void testMultipleModifications() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testMultipleModifications(VirtualPropertyMode mode) { String drl = "package org.drools.traits.test;\n" + "\n" + "import org.drools.base.factmodel.traits.Traitable;\n" + @@ -3895,8 +3950,9 @@ public void testMultipleModifications() { } - @Test - public void testPropagation() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testPropagation(VirtualPropertyMode mode) { String drl = "package org.drools.test;\n" + "import org.drools.base.factmodel.traits.*; \n" + "\n" + @@ -3965,8 +4021,9 @@ public void testPropagation() { } - @Test - public void testParentBlockers() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testParentBlockers(VirtualPropertyMode mode) { String drl = "package org.drools.test;\n" + "import org.drools.base.factmodel.traits.*; \n" + "\n" + @@ -4002,8 +4059,9 @@ public void testParentBlockers() { } - @Test - public void testTraitLogicalTMS() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitLogicalTMS(VirtualPropertyMode mode) { String drl = "package org.drools.test;\n" + "import org.drools.base.factmodel.traits.*; \n" + "\n" + @@ -4052,8 +4110,9 @@ public void testTraitLogicalTMS() { } - @Test - public void testTraitNoType() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitNoType(VirtualPropertyMode mode) { String drl = "" + "package org.drools.base.factmodel.traits.test;\n" + "\n" + @@ -4109,8 +4168,9 @@ public void testTraitNoType() { - @Test - public void testTraitdeleteOrder() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitdeleteOrder(VirtualPropertyMode mode) { String drl = "" + "package org.drools.base.factmodel.traits.test;\n" + "\n" + @@ -4160,8 +4220,9 @@ public void objectDeleted(org.kie.api.event.rule.ObjectDeletedEvent objectRetrac } - @Test - public void testTraitWithManySoftFields() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitWithManySoftFields(VirtualPropertyMode mode) { String drl = "" + "package org.drools.base.factmodel.traits.test;\n" + "\n" + @@ -4245,8 +4306,9 @@ public void reset() { } - @Test - public void testDonManyTraitsAtOnce() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testDonManyTraitsAtOnce(VirtualPropertyMode mode) { String drl = "" + "package org.drools.base.factmodel.traits.test;\n" + "\n" + @@ -4366,8 +4428,9 @@ public void testDonManyTraitsAtOnce() { assertThat(list).contains(0, 1, 2, 3); } - @Test - public void testDonManyTraitsAtOnce2() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testDonManyTraitsAtOnce2(VirtualPropertyMode mode) { String drl = "" + "package org.drools.base.factmodel.traits.test;\n" + "\n" + @@ -4451,35 +4514,36 @@ public void run() { } } - @Test - @Ignore("Triple Store is not thread safe and needs to be rewritten") - public void testMultithreadingTraits() throws InterruptedException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + @Disabled("Triple Store is not thread safe and needs to be rewritten") + public void testMultithreadingTraits(VirtualPropertyMode mode) throws InterruptedException { final String s1 = "package test;\n" + "import org.drools.base.factmodel.traits.TraitTest.Item;\n" + "declare Item end\n" + "declare trait ItemStyle\n" + - " id: String\n" + - " adjustable: boolean\n" + + " id: String\n" + + " adjustable: boolean\n" + "end\n" + "rule \"Don ItemStyle\"\n" + - " no-loop true\n" + - " when\n" + - " $p : Item ()\n" + - " not ItemStyle (id == $p.id)\n" + - " then\n" + - " don($p, ItemStyle.class);\n" + + " no-loop true\n" + + " when\n" + + " $p : Item ()\n" + + " not ItemStyle (id == $p.id)\n" + + " then\n" + + " don($p, ItemStyle.class);\n" + "end\n" + "rule \"Item Style - Adjustable\"" + - " no-loop true" + - " when" + - " $style : ItemStyle (!adjustable)" + - " Item (" + - " id == $style.id " + - " )" + - " then" + - " modify($style) {" + - " setAdjustable(true)" + - " };" + + " no-loop true" + + " when" + + " $style : ItemStyle (!adjustable)" + + " Item (" + + " id == $style.id " + + " )" + + " then" + + " modify($style) {" + + " setAdjustable(true)" + + " };" + "end"; KieBase kbase = getKieBaseFromString(s1); TraitFactoryImpl.setMode(mode, kbase); @@ -4505,8 +4569,9 @@ public void testMultithreadingTraits() throws InterruptedException { } - @Test - public void testShedOneLastTrait() throws InterruptedException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testShedOneLastTrait(VirtualPropertyMode mode) throws InterruptedException { final String s1 = "package test;\n" + "import org.drools.base.factmodel.traits.*; \n" + "global java.util.List list;\n" + @@ -4517,15 +4582,15 @@ public void testShedOneLastTrait() throws InterruptedException { "end\n" + "" + "rule \"Don ItemStyle\"\n" + - " when\n" + - " then\n" + - " don(new Core(), Mask.class);\n" + + " when\n" + + " then\n" + + " don(new Core(), Mask.class);\n" + "end\n" + "" + "rule \"React\" \n" + - " when \n" + + " when \n" + " $s : String() \n" + - " $m : Mask() \n" + + " $m : Mask() \n" + "then \n" + " delete($s); \n" + " shed($m, Mask.class); \n" + @@ -4559,8 +4624,9 @@ public void testShedOneLastTrait() throws InterruptedException { - @Test - public void testShedThingCompletelyThenDonAgain() throws InterruptedException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testShedThingCompletelyThenDonAgain(VirtualPropertyMode mode) throws InterruptedException { final String s1 = "package test;\n" + "import org.drools.base.factmodel.traits.*; \n" + "global java.util.List list;\n" + @@ -4571,35 +4637,35 @@ public void testShedThingCompletelyThenDonAgain() throws InterruptedException { "declare trait Mask2 end\n" + "" + "rule \"Don ItemStyle\"\n" + - " when\n" + + " when\n" + " $s : String(this == \"don1\") \n" + - " then\n" + + " then\n" + " delete($s); \n" + - " don(new Core(), Mask.class);\n" + + " don(new Core(), Mask.class);\n" + "end\n" + "" + "rule \"Clear\" \n" + - " when \n" + + " when \n" + " $s : String(this == \"shed1\") \n" + - " $m : Mask() \n" + + " $m : Mask() \n" + "then \n" + " delete($s); \n" + " shed($m, Thing.class); \n" + "end\n" + "" + "rule \"Add\" \n" + - " when \n" + + " when \n" + " $s : String(this == \"don2\") \n" + - " $c : Core() \n" + + " $c : Core() \n" + "then \n" + " delete($s); \n" + " don($c, Mask2.class); \n" + "end\n" + "" + "rule \"Clear Again\" \n" + - " when \n" + + " when \n" + " $s : String(this == \"shed2\") \n" + - " $m : Mask2() \n" + + " $m : Mask2() \n" + "then \n" + " delete($s); \n" + " shed($m, Mask2.class); \n" + @@ -4648,8 +4714,9 @@ public void testShedThingCompletelyThenDonAgain() throws InterruptedException { } - @Test - public void testTraitImplicitInsertionExceptionOnNonTraitable() throws InterruptedException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitImplicitInsertionExceptionOnNonTraitable(VirtualPropertyMode mode) throws InterruptedException { final String s1 = "package test;\n" + "import org.drools.base.factmodel.traits.*; \n" + "global java.util.List list;\n" + @@ -4659,9 +4726,9 @@ public void testTraitImplicitInsertionExceptionOnNonTraitable() throws Interrupt "declare trait Mask id : String end\n" + "" + "rule \"Don ItemStyle\"\n" + - " when\n" + - " then\n" + - " don(new Core(), Mask.class);\n" + + " when\n" + + " then\n" + + " don(new Core(), Mask.class);\n" + "end\n" + "" + ""; @@ -4689,8 +4756,9 @@ public static interface SomeTrait extends Thing { public void setFoo(String foo); } - @Test - public void testTraitLegacyTraitableWithLegacyTrait() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTraitLegacyTraitableWithLegacyTrait(VirtualPropertyMode mode) { final String s1 = "package org.drools.compiler.factmodel.traits;\n" + "import " + TraitTest.class.getName() + ".SomeTrait; \n" + "import " + StudentImpl.class.getCanonicalName() + ";\n" + @@ -4699,9 +4767,9 @@ public void testTraitLegacyTraitableWithLegacyTrait() { "global java.util.List list;\n" + "" + "rule \"Don ItemStyle\"\n" + - " when\n" + - " then\n" + - " don(new StudentImpl(), SomeTrait.class);\n" + + " when\n" + + " then\n" + + " don(new StudentImpl(), SomeTrait.class);\n" + "end\n"; KieBase kbase = getKieBaseFromString(s1); @@ -4716,8 +4784,9 @@ public void testTraitLegacyTraitableWithLegacyTrait() { assertThat(knowledgeSession.getObjects()).hasSize(2); } - @Test - public void testIsALegacyTrait() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testIsALegacyTrait(VirtualPropertyMode mode) { final String s1 = "package org.drools.traits.compiler.factmodel.traits;\n" + "import " + TraitTest.class.getName() + ".SomeTrait; \n" + "import " + StudentImpl.class.getCanonicalName() + ";\n" + @@ -4728,10 +4797,10 @@ public void testIsALegacyTrait() { "declare trait IStudent end \n" + "" + "rule \"Don ItemStyle\"\n" + - " when\n" + - " then\n" + - " insert(new StudentImpl());\n" + - " don(new Entity(), IStudent.class);\n" + + " when\n" + + " then\n" + + " insert(new StudentImpl());\n" + + " don(new Entity(), IStudent.class);\n" + "end\n" + "" + "rule Check " + @@ -4754,9 +4823,10 @@ public void testIsALegacyTrait() { assertThat(list).containsExactly(1); } - @Category(ReviseTraitTestWithPRAlwaysCategory.class) - @Test - public void testClassLiteralsWithOr() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + @Disabled("Check ReviseTraitTestWithPRAlwaysCategory.java file") + public void testClassLiteralsWithOr(VirtualPropertyMode mode) { String drl = "package org.drools.test; " + "import org.drools.base.factmodel.traits.*; " + @@ -4815,8 +4885,9 @@ public void testClassLiteralsWithOr() { - @Test - public void testIsASwappedArg() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testIsASwappedArg(VirtualPropertyMode mode) { String drl = "package org.drools.traits.compiler.factmodel.traits;\n" + "import " + TraitTest.class.getName() + ".SomeTrait; \n" + @@ -4877,8 +4948,9 @@ public void testIsASwappedArg() { } - @Test - public void testHierarchyEncodeOnPackageMerge() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testHierarchyEncodeOnPackageMerge(VirtualPropertyMode mode) { String drl0 = "package org.drools.test; " + "declare trait X end "; @@ -4921,8 +4993,10 @@ public void testHierarchyEncodeOnPackageMerge() { - @Test @Ignore - public void testDonThenReinsert() throws InterruptedException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + @Disabled + public void testDonThenReinsert(VirtualPropertyMode mode) throws InterruptedException { final String s1 = "package test;\n" + "import org.drools.base.factmodel.traits.*; \n" + "import org.drools.traits.compiler.factmodel.traits.TraitTest.TBean;\n" + @@ -4938,15 +5012,15 @@ public void testDonThenReinsert() throws InterruptedException { "end " + "" + "rule 'Don ItemStyle' " + - " when\n" + + " when\n" + " $e : TBean() " + - " then " + - " don($e, Mask.class);\n" + + " then " + + " don($e, Mask.class);\n" + "end\n" + "" + "rule \"React\" \n" + - " when \n" + - " $m : Mask() \n" + + " when \n" + + " $m : Mask() \n" + "then \n" + "end\n" + "" + @@ -4980,8 +5054,9 @@ public void testDonThenReinsert() throws InterruptedException { } - @Test - public void testCastOnTheFly() throws InterruptedException { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testCastOnTheFly(VirtualPropertyMode mode) throws InterruptedException { final String s1 = "package test; " + "import org.drools.base.factmodel.traits.*; " + @@ -5005,8 +5080,8 @@ public void testCastOnTheFly() throws InterruptedException { "rule Init " + " dialect 'mvel' " + - " when " + - " then " + + " when " + + " then " + " Foo o = insert(new Foo(42)).as(Foo.class); " + " list.add(o.getId()); " + "end " + @@ -5035,8 +5110,9 @@ public void testCastOnTheFly() throws InterruptedException { - @Test - public void testDonModify() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testDonModify(VirtualPropertyMode mode) { String drl = "import org.drools.traits.core.factmodel.Entity;\n" + "import org.drools.traits.compiler.factmodel.traits.IPerson;\n" + @@ -5077,8 +5153,9 @@ public void testDonModify() { assertThat(kSession.fireAllRules()).isEqualTo(3); } - @Test - public void testAlphaNodeSharing() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testAlphaNodeSharing(VirtualPropertyMode mode) { String drl = "package test; " + "import " + Entity.class.getName() + " " + @@ -5116,8 +5193,9 @@ public void testAlphaNodeSharing() { assertThat(otn.getObjectSinkPropagator().getSinks().length).isEqualTo(1); } - @Test - public void testPartitionWithSiblingsOnDelete() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testPartitionWithSiblingsOnDelete(VirtualPropertyMode mode) { String drl = "import " + Entity.class.getName() + ";" + "global java.util.List list; " + @@ -5169,8 +5247,9 @@ public void testPartitionWithSiblingsOnDelete() { } - @Test - public void testTupleIntegrityOnModification() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testTupleIntegrityOnModification(VirtualPropertyMode mode) { String drl = "package test " + "import " + Entity.class.getName() + ";" + "global java.util.List list; " + @@ -5220,8 +5299,9 @@ public void testTupleIntegrityOnModification() { assertThat(list).containsExactly(0, 42); } - @Test - public void testShedVacancy() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testShedVacancy(VirtualPropertyMode mode) { String drl = "package org.drools.test " + "import " + Entity.class.getName() + ";" + "global java.util.List list; " + @@ -5313,8 +5393,9 @@ public void testShedVacancy() { } - @Test - public void testExternalUpdateWithProxyRefreshInEqualityMode() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testExternalUpdateWithProxyRefreshInEqualityMode(VirtualPropertyMode mode) { String drl = "package org.drools.trait.test; " + "import " + ExtEntity.class.getCanonicalName() + "; " + "global " + List.class.getName() + " list; " + @@ -5354,8 +5435,9 @@ public void testExternalUpdateWithProxyRefreshInEqualityMode() { } - @Test - public void testIsAInstanceOf() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testIsAInstanceOf(VirtualPropertyMode mode) { String drl = "package org.drools.test; " + "import " + StudentImpl.class.getName() + "; " + @@ -5387,8 +5469,9 @@ public void testIsAInstanceOf() { } - @Test - public void testIsAInstanceOfNonTraitable() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testIsAInstanceOfNonTraitable(VirtualPropertyMode mode) { String drl = "package org.drools.test; " + "global java.util.List list; " + @@ -5449,8 +5532,9 @@ protected Set checkOTNPartitioning(TraitableBean core, KieSession wm) { return otns; } - @Test - public void testSerializeKieBaseWithTraits() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testSerializeKieBaseWithTraits(VirtualPropertyMode mode) { // DRL-1123 String drl = "package org.drools.test; " + "import " + StudentImpl.class.getName() + "; " + @@ -5482,8 +5566,9 @@ public void testSerializeKieBaseWithTraits() { assertThat(list).containsExactly(1, 2); } - @Test - public void testMixin2() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testMixin2(VirtualPropertyMode mode) { String drl = "package org.drools.test.traits\n" + "import " + Scholar.class.getCanonicalName() + ";\n" + @@ -5590,13 +5675,14 @@ public String getZValue() { } } - @Test - public void testMixinWithConflictsUsingDeclarationOrder() { - checkMixinResolutionUsesOrder("Y,Z", "Y"); - checkMixinResolutionUsesOrder("Z,Y", "Z"); + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testMixinWithConflictsUsingDeclarationOrder(VirtualPropertyMode mode) { + checkMixinResolutionUsesOrder("Y,Z", "Y", mode); + checkMixinResolutionUsesOrder("Z,Y", "Z", mode); } - private void checkMixinResolutionUsesOrder(String interfaces, String first) { + private void checkMixinResolutionUsesOrder(String interfaces, String first, VirtualPropertyMode mode) { String drl = "package org.drools.test.traits\n" + "import " + Y.class.getCanonicalName() + ";\n" + @@ -5640,8 +5726,9 @@ private void checkMixinResolutionUsesOrder(String interfaces, String first) { assertThat(list.get(2)).isEqualTo(first); } - @Test - public void testMixinWithConflictsThrowingError() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testMixinWithConflictsThrowingError(VirtualPropertyMode mode) { String drl = "package org.drools.test.traits\n" + "import " + Y.class.getCanonicalName() + ";\n" + @@ -5680,8 +5767,9 @@ public void testMixinWithConflictsThrowingError() { assertThatException().as("don should fail due to the conflict in getShared() method").isThrownBy(() -> ks.fireAllRules()); } - @Test - public void testPreserveAllSetBitMask() { + @ParameterizedTest(name = "KieBase type={0}") + @MethodSource("parameters") + public void testPreserveAllSetBitMask(VirtualPropertyMode mode) { // DROOLS-1699 String drl = "package t.x;\n" + diff --git a/drools-traits/src/test/java/org/drools/traits/persistence/PersistenceTest.java b/drools-traits/src/test/java/org/drools/traits/persistence/PersistenceTest.java index ddc456bf19c..b1a4224cca3 100644 --- a/drools-traits/src/test/java/org/drools/traits/persistence/PersistenceTest.java +++ b/drools-traits/src/test/java/org/drools/traits/persistence/PersistenceTest.java @@ -19,15 +19,13 @@ package org.drools.traits.persistence; import java.io.Serializable; -import java.util.Arrays; -import java.util.Collection; import java.util.Map; +import java.util.stream.Stream; import org.drools.base.factmodel.traits.Traitable; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.kie.api.KieBase; import org.kie.api.KieServices; import org.kie.api.builder.KieFileSystem; @@ -42,31 +40,23 @@ import static org.drools.traits.persistence.DroolsPersistenceUtil.PESSIMISTIC_LOCKING; import static org.drools.traits.persistence.DroolsPersistenceUtil.createEnvironment; -@RunWith(Parameterized.class) public class PersistenceTest { private Map context; private Environment env; - private boolean locking; - public PersistenceTest(String locking) { - this.locking = PESSIMISTIC_LOCKING.equals(locking); - } - - @Parameterized.Parameters(name="{0}") - public static Collection persistence() { - Object[][] locking = new Object[][] { - { OPTIMISTIC_LOCKING }, - { PESSIMISTIC_LOCKING } - }; - return Arrays.asList(locking); - } + public static Stream parameters() { + return Stream.of(OPTIMISTIC_LOCKING, PESSIMISTIC_LOCKING); + }; - @Before + @BeforeEach public void setUp() throws Exception { context = DroolsPersistenceUtil.setupWithPoolingDataSource(DROOLS_PERSISTENCE_UNIT_NAME); env = createEnvironment(context); - if( locking ) { + } + + private void setUpLocking(String locking) { + if(PESSIMISTIC_LOCKING.equals(locking)) { env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true); } } @@ -106,8 +96,10 @@ public void setToLocation(String toLocation) { } } - @Test - public void testTraitsSerialization() throws Exception { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testTraitsSerialization(String locking) throws Exception { + setUpLocking(locking); String drl = "package org.drools.persistence.kie.persistence.session\n" + "\n" + "import java.util.List\n" + From a2ae8f223011c81a100c0fa4b7b802439cdc9a6b Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Fri, 29 Nov 2024 17:26:45 +0100 Subject: [PATCH 07/12] Migrated drools util module to Junit5 --- drools-util/pom.xml | 10 ++--- .../java/org/drools/util/FileUtilsTest.java | 2 +- .../java/org/drools/util/JarUtilsTest.java | 3 +- .../java/org/drools/util/KiePathTest.java | 44 +++++++++---------- .../org/drools/util/ResourceHelperTest.java | 2 +- .../java/org/drools/util/StringUtilsTest.java | 2 +- .../org/drools/util/TypeResolverTest.java | 2 +- .../drools/util/bitmask/LongBitMaskTest.java | 10 ++--- 8 files changed, 35 insertions(+), 40 deletions(-) diff --git a/drools-util/pom.xml b/drools-util/pom.xml index 3fd81109ddf..6946ecc1471 100644 --- a/drools-util/pom.xml +++ b/drools-util/pom.xml @@ -50,11 +50,11 @@ microprofile-config-api true - - junit - junit - test - + + org.junit.jupiter + junit-jupiter + test + org.assertj assertj-core diff --git a/drools-util/src/test/java/org/drools/util/FileUtilsTest.java b/drools-util/src/test/java/org/drools/util/FileUtilsTest.java index 1a7e1064ac5..79012a9e42b 100644 --- a/drools-util/src/test/java/org/drools/util/FileUtilsTest.java +++ b/drools-util/src/test/java/org/drools/util/FileUtilsTest.java @@ -27,7 +27,7 @@ import java.nio.file.Path; import java.util.Optional; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; diff --git a/drools-util/src/test/java/org/drools/util/JarUtilsTest.java b/drools-util/src/test/java/org/drools/util/JarUtilsTest.java index 6453cc595c0..1992a7faa92 100644 --- a/drools-util/src/test/java/org/drools/util/JarUtilsTest.java +++ b/drools-util/src/test/java/org/drools/util/JarUtilsTest.java @@ -18,10 +18,11 @@ */ package org.drools.util; -import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.Test; + public class JarUtilsTest { @Test diff --git a/drools-util/src/test/java/org/drools/util/KiePathTest.java b/drools-util/src/test/java/org/drools/util/KiePathTest.java index 417db70b400..00cfd74bfe1 100644 --- a/drools-util/src/test/java/org/drools/util/KiePathTest.java +++ b/drools-util/src/test/java/org/drools/util/KiePathTest.java @@ -18,51 +18,49 @@ */ package org.drools.util; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import java.util.stream.Stream; + +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 KiePathTest { - protected final boolean isWindowsSeparator; - protected final String fileSeparator; - - public KiePathTest( boolean isWindowsSeparator ) { - this.isWindowsSeparator = isWindowsSeparator; - this.fileSeparator = isWindowsSeparator ? "\\" : "/"; - } - - @Parameterized.Parameters(name = "{0}") - public static Object[] params() { - return new Object[] { true, false }; + public static Stream parameters() { + return Stream.of(arguments(true, "\\"), + arguments(false, "/")); } - @Test - public void testAsString() throws Exception { + @ParameterizedTest(name="separator = {1}") + @MethodSource("parameters") + public void testAsString(boolean isWindowsSeparator, String fileSeparator) throws Exception { assertThat(PortablePath.of("src", isWindowsSeparator).asString()).isEqualTo("src"); assertThat(PortablePath.of("src" + fileSeparator + "test", isWindowsSeparator).asString()).isEqualTo("src/test"); assertThat(PortablePath.of("src" + fileSeparator + "test", isWindowsSeparator).asString()).isEqualTo("src/test"); assertThat(PortablePath.of("src" + fileSeparator + "test" + fileSeparator + "folder", isWindowsSeparator).asString()).isEqualTo("src/test/folder"); } - @Test - public void testParent() throws Exception { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testParent(boolean isWindowsSeparator, String fileSeparator) throws Exception { assertThat(PortablePath.of("src" + fileSeparator + "test" + fileSeparator + "folder", isWindowsSeparator).getParent().asString()).isEqualTo("src/test"); assertThat(PortablePath.of("src" + fileSeparator + "test" + fileSeparator + "folder", isWindowsSeparator).getParent().getParent().asString()).isEqualTo("src"); assertThat(PortablePath.of("src" + fileSeparator + "test" + fileSeparator + "folder", isWindowsSeparator).getParent().getParent().getParent().asString()).isEqualTo(""); } - @Test - public void testResolve() throws Exception { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testResolve(boolean isWindowsSeparator, String fileSeparator) throws Exception { assertThat(PortablePath.of("src" + fileSeparator + "test", isWindowsSeparator).resolve("folder").asString()).isEqualTo("src/test/folder"); assertThat(PortablePath.of("src" + fileSeparator + "test", isWindowsSeparator).resolve(PortablePath.of("folder" + fileSeparator + "subfolder", isWindowsSeparator)).asString()).isEqualTo("src/test/folder/subfolder"); } - @Test - public void testFileName() throws Exception { + @ParameterizedTest(name="{0}") + @MethodSource("parameters") + public void testFileName(boolean isWindowsSeparator, String fileSeparator) throws Exception { assertThat(PortablePath.of("src" + fileSeparator + "test" + fileSeparator + "folder", isWindowsSeparator).getFileName()).isEqualTo("folder"); } } \ No newline at end of file diff --git a/drools-util/src/test/java/org/drools/util/ResourceHelperTest.java b/drools-util/src/test/java/org/drools/util/ResourceHelperTest.java index f314dfc7017..2e369618312 100644 --- a/drools-util/src/test/java/org/drools/util/ResourceHelperTest.java +++ b/drools-util/src/test/java/org/drools/util/ResourceHelperTest.java @@ -26,7 +26,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.drools.util.FileUtilsTest.TEST_FILE; diff --git a/drools-util/src/test/java/org/drools/util/StringUtilsTest.java b/drools-util/src/test/java/org/drools/util/StringUtilsTest.java index 7fca6c14fe5..7d4cd21fdf8 100644 --- a/drools-util/src/test/java/org/drools/util/StringUtilsTest.java +++ b/drools-util/src/test/java/org/drools/util/StringUtilsTest.java @@ -20,7 +20,7 @@ import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.drools.util.StringUtils.getPkgUUID; diff --git a/drools-util/src/test/java/org/drools/util/TypeResolverTest.java b/drools-util/src/test/java/org/drools/util/TypeResolverTest.java index fcb359e4556..eccc5048c64 100644 --- a/drools-util/src/test/java/org/drools/util/TypeResolverTest.java +++ b/drools-util/src/test/java/org/drools/util/TypeResolverTest.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/drools-util/src/test/java/org/drools/util/bitmask/LongBitMaskTest.java b/drools-util/src/test/java/org/drools/util/bitmask/LongBitMaskTest.java index 3357d9bbbab..f6840b84b4f 100644 --- a/drools-util/src/test/java/org/drools/util/bitmask/LongBitMaskTest.java +++ b/drools-util/src/test/java/org/drools/util/bitmask/LongBitMaskTest.java @@ -19,16 +19,13 @@ package org.drools.util.bitmask; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatRuntimeException; public class LongBitMaskTest { - @Rule public final ExpectedException thrown = ExpectedException.none(); - @Test public void testSet() { assertThat(new LongBitMask().set(0).toString()).isEqualTo("1"); @@ -62,8 +59,7 @@ public void testResetAll() { assertThat(new LongBitMask().resetAll(EmptyButLastBitMask.get()).toString()).isEqualTo("0"); assertThat(new LongBitMask().resetAll(EmptyBitMask.get()).toString()).isEqualTo("0"); - thrown.expect(RuntimeException.class); - new LongBitMask().resetAll(new OpenBitSet()).toString(); + assertThatRuntimeException().isThrownBy(() -> new LongBitMask().resetAll(new OpenBitSet()).toString()); } @Test From a8c056a1ac5fd3877e0cbc61e4b3ab02b9ec4868 Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Fri, 29 Nov 2024 17:29:16 +0100 Subject: [PATCH 08/12] Migrated drools xml support module to JUnit5 --- drools-xml-support/pom.xml | 6 +++--- .../org/drools/xml/support/CommandSerializationTest.java | 2 +- .../test/java/org/drools/xml/support/XStreamXMLTest.java | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drools-xml-support/pom.xml b/drools-xml-support/pom.xml index 0f0c11aa764..faa3c4e35ad 100644 --- a/drools-xml-support/pom.xml +++ b/drools-xml-support/pom.xml @@ -132,10 +132,10 @@ - junit - junit + org.junit.jupiter + junit-jupiter test - + org.mockito mockito-core diff --git a/drools-xml-support/src/test/java/org/drools/xml/support/CommandSerializationTest.java b/drools-xml-support/src/test/java/org/drools/xml/support/CommandSerializationTest.java index 82622e17387..90455846f1e 100644 --- a/drools-xml-support/src/test/java/org/drools/xml/support/CommandSerializationTest.java +++ b/drools-xml-support/src/test/java/org/drools/xml/support/CommandSerializationTest.java @@ -68,8 +68,8 @@ import org.drools.commands.runtime.rule.UpdateCommand; import org.drools.core.common.DefaultFactHandle; import org.drools.core.common.DisconnectedFactHandle; +import org.junit.jupiter.api.Test; import org.drools.commands.jaxb.JaxbListWrapper; -import org.junit.Test; import org.kie.api.command.Command; import org.kie.api.command.Setter; import org.kie.api.runtime.rule.AgendaFilter; diff --git a/drools-xml-support/src/test/java/org/drools/xml/support/XStreamXMLTest.java b/drools-xml-support/src/test/java/org/drools/xml/support/XStreamXMLTest.java index f1be85ba3c5..ad8a6bebc40 100644 --- a/drools-xml-support/src/test/java/org/drools/xml/support/XStreamXMLTest.java +++ b/drools-xml-support/src/test/java/org/drools/xml/support/XStreamXMLTest.java @@ -42,10 +42,10 @@ import org.drools.commands.runtime.rule.ModifyCommand; import org.drools.commands.runtime.rule.UpdateCommand; import org.drools.core.common.DefaultFactHandle; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.drools.commands.runtime.ExecutionResultImpl; import org.drools.commands.runtime.FlatQueryResults; -import org.junit.Before; -import org.junit.Test; import org.kie.api.runtime.rule.FactHandle; import org.kie.api.runtime.rule.QueryResults; @@ -56,7 +56,7 @@ public class XStreamXMLTest { private XStream xstream; - @Before + @BeforeEach public void setup() { xstream = createTrustingXStream(); xstream = XStreamXML.newXStreamMarshaller(xstream); From 79705ec89d5ae4693049336fce436113c84495a7 Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Fri, 29 Nov 2024 17:32:38 +0100 Subject: [PATCH 09/12] Migrated kie internals to JUnit5 --- kie-internal/pom.xml | 6 +++--- .../manager/deploy/DeploymentDescriptorMergerTest.java | 2 +- .../runtime/manager/deploy/DeploymentDescriptorTest.java | 2 +- .../internal/runtime/manager/deploy/JaxbMarshalingTest.java | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kie-internal/pom.xml b/kie-internal/pom.xml index 619f4ee0f49..3f7b59ddfb4 100644 --- a/kie-internal/pom.xml +++ b/kie-internal/pom.xml @@ -122,10 +122,10 @@ test - junit - junit + org.junit.jupiter + junit-jupiter test - + org.assertj assertj-core diff --git a/kie-internal/src/test/java/org/kie/internal/runtime/manager/deploy/DeploymentDescriptorMergerTest.java b/kie-internal/src/test/java/org/kie/internal/runtime/manager/deploy/DeploymentDescriptorMergerTest.java index 3ae6532c952..f8f7e3bb279 100644 --- a/kie-internal/src/test/java/org/kie/internal/runtime/manager/deploy/DeploymentDescriptorMergerTest.java +++ b/kie-internal/src/test/java/org/kie/internal/runtime/manager/deploy/DeploymentDescriptorMergerTest.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.internal.runtime.conf.AuditMode; import org.kie.internal.runtime.conf.DeploymentDescriptor; import org.kie.internal.runtime.conf.MergeMode; diff --git a/kie-internal/src/test/java/org/kie/internal/runtime/manager/deploy/DeploymentDescriptorTest.java b/kie-internal/src/test/java/org/kie/internal/runtime/manager/deploy/DeploymentDescriptorTest.java index 6559973fa81..4c3dd2725a6 100644 --- a/kie-internal/src/test/java/org/kie/internal/runtime/manager/deploy/DeploymentDescriptorTest.java +++ b/kie-internal/src/test/java/org/kie/internal/runtime/manager/deploy/DeploymentDescriptorTest.java @@ -23,7 +23,7 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.internal.runtime.conf.AuditMode; import org.kie.internal.runtime.conf.DeploymentDescriptor; import org.kie.internal.runtime.conf.NamedObjectModel; diff --git a/kie-internal/src/test/java/org/kie/internal/runtime/manager/deploy/JaxbMarshalingTest.java b/kie-internal/src/test/java/org/kie/internal/runtime/manager/deploy/JaxbMarshalingTest.java index 5038a1806fa..19647fcac00 100644 --- a/kie-internal/src/test/java/org/kie/internal/runtime/manager/deploy/JaxbMarshalingTest.java +++ b/kie-internal/src/test/java/org/kie/internal/runtime/manager/deploy/JaxbMarshalingTest.java @@ -24,7 +24,7 @@ import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.Marshaller; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.internal.runtime.conf.DeploymentDescriptor; import org.kie.internal.runtime.conf.ObjectModel; import org.slf4j.Logger; From 9dbd33291c6beadc877ae0f7e1df0e2d5ddc7fb8 Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Fri, 29 Nov 2024 17:38:25 +0100 Subject: [PATCH 10/12] Migrated kie memory compiler to JUnit5 --- kie-memory-compiler/pom.xml | 6 +++--- .../memorycompiler/KieMemoryCompilerTest.java | 8 +++++--- .../jdknative/NativeJavaCompilerTest.java | 16 +++++++--------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/kie-memory-compiler/pom.xml b/kie-memory-compiler/pom.xml index 2cb34dc36f2..bfafcb26f76 100644 --- a/kie-memory-compiler/pom.xml +++ b/kie-memory-compiler/pom.xml @@ -45,10 +45,10 @@ drools-util - junit - junit + org.junit.jupiter + junit-jupiter test - + org.assertj assertj-core diff --git a/kie-memory-compiler/src/test/java/org/kie/memorycompiler/KieMemoryCompilerTest.java b/kie-memory-compiler/src/test/java/org/kie/memorycompiler/KieMemoryCompilerTest.java index 7c5e3093ebf..f22d02a106a 100644 --- a/kie-memory-compiler/src/test/java/org/kie/memorycompiler/KieMemoryCompilerTest.java +++ b/kie-memory-compiler/src/test/java/org/kie/memorycompiler/KieMemoryCompilerTest.java @@ -21,10 +21,11 @@ import java.lang.reflect.Method; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static java.util.Collections.singletonMap; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; public class KieMemoryCompilerTest { @@ -52,10 +53,11 @@ public void compileAndLoadClass() throws Exception { assertThat(result).isEqualTo(5); } - @Test(expected = KieMemoryCompilerException.class) + @Test public void invalidClass() { Map source = singletonMap("org.kie.memorycompiler.InvalidJavaClass", "Invalid Java Code"); - KieMemoryCompiler.compile(source, this.getClass().getClassLoader()); + assertThatExceptionOfType(KieMemoryCompilerException.class).isThrownBy( + () -> KieMemoryCompiler.compile(source, this.getClass().getClassLoader())); } private final static String WARNING_CLASS = diff --git a/kie-memory-compiler/src/test/java/org/kie/memorycompiler/jdknative/NativeJavaCompilerTest.java b/kie-memory-compiler/src/test/java/org/kie/memorycompiler/jdknative/NativeJavaCompilerTest.java index 268f962685a..8b9e7daba6a 100644 --- a/kie-memory-compiler/src/test/java/org/kie/memorycompiler/jdknative/NativeJavaCompilerTest.java +++ b/kie-memory-compiler/src/test/java/org/kie/memorycompiler/jdknative/NativeJavaCompilerTest.java @@ -18,29 +18,27 @@ */ package org.kie.memorycompiler.jdknative; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import javax.tools.JavaCompiler; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.kie.memorycompiler.KieMemoryCompilerException; public class NativeJavaCompilerTest { - @Test(expected = KieMemoryCompilerException.class) + @Test public void simulateJre() { - NativeJavaCompiler compiler = new NativeJavaCompiler(new NullJavaCompilerFinder()); - - compiler.compile(null, null, null, null, null); + assertThatExceptionOfType(KieMemoryCompilerException.class).isThrownBy(() -> compiler.compile(null, null, null, null, null)); } - @Test(expected = KieMemoryCompilerException.class) + @Test public void simulateJreWithException() { - NativeJavaCompiler compiler = new NativeJavaCompiler(new ExceptionThrowingJavaCompilerFinder()); - - compiler.compile(null, null, null, null, null); + assertThatExceptionOfType(KieMemoryCompilerException.class).isThrownBy(() -> compiler.compile(null, null, null, null, null)); } private static class NullJavaCompilerFinder implements JavaCompilerFinder { From f34f704143a8dc9ff54092f690d08c41fb43301c Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Fri, 29 Nov 2024 17:41:29 +0100 Subject: [PATCH 11/12] Migrated drools retediagram to JUnit5 --- drools-retediagram/pom.xml | 6 +++--- .../src/test/java/org/drools/retediagram/RuleTest.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drools-retediagram/pom.xml b/drools-retediagram/pom.xml index e1b9122311d..4096b9c59de 100644 --- a/drools-retediagram/pom.xml +++ b/drools-retediagram/pom.xml @@ -74,10 +74,10 @@ - junit - junit + org.junit.jupiter + junit-jupiter test - + org.assertj assertj-core diff --git a/drools-retediagram/src/test/java/org/drools/retediagram/RuleTest.java b/drools-retediagram/src/test/java/org/drools/retediagram/RuleTest.java index 1a34e81bd58..729eb6da06d 100644 --- a/drools-retediagram/src/test/java/org/drools/retediagram/RuleTest.java +++ b/drools-retediagram/src/test/java/org/drools/retediagram/RuleTest.java @@ -29,8 +29,8 @@ import org.drools.mvel.CommonTestMethodBase; import org.drools.retediagram.ReteDiagram.Layout; import org.drools.retediagram.model.Measurement; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.kie.api.KieBase; import org.kie.api.event.rule.DebugAgendaEventListener; import org.kie.api.io.ResourceType; @@ -47,7 +47,7 @@ public class RuleTest extends CommonTestMethodBase { static final Logger LOG = LoggerFactory.getLogger(RuleTest.class); - @BeforeClass + @BeforeAll public static void init() { // route dependencies using java util Logging to slf4j SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); From 466cfc94e4f470d07ddf28cbc3639d09310bc2f7 Mon Sep 17 00:00:00 2001 From: Paolo Bizzarri Date: Fri, 29 Nov 2024 17:44:18 +0100 Subject: [PATCH 12/12] Migrated kie api to JUnit5 --- kie-api/pom.xml | 6 +++--- kie-api/src/test/java/org/kie/api/KModuleXSDTest.java | 2 +- kie-api/src/test/java/org/kie/api/io/ResourceTypeTest.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/kie-api/pom.xml b/kie-api/pom.xml index c069d04cf26..b80233fc0d3 100644 --- a/kie-api/pom.xml +++ b/kie-api/pom.xml @@ -156,10 +156,10 @@ slf4j-api - junit - junit + org.junit.jupiter + junit-jupiter test - + org.assertj assertj-core diff --git a/kie-api/src/test/java/org/kie/api/KModuleXSDTest.java b/kie-api/src/test/java/org/kie/api/KModuleXSDTest.java index 172165a00cc..c432110fa0c 100644 --- a/kie-api/src/test/java/org/kie/api/KModuleXSDTest.java +++ b/kie-api/src/test/java/org/kie/api/KModuleXSDTest.java @@ -26,7 +26,7 @@ import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; diff --git a/kie-api/src/test/java/org/kie/api/io/ResourceTypeTest.java b/kie-api/src/test/java/org/kie/api/io/ResourceTypeTest.java index 95ad217e06e..ccdd483aac4 100644 --- a/kie-api/src/test/java/org/kie/api/io/ResourceTypeTest.java +++ b/kie-api/src/test/java/org/kie/api/io/ResourceTypeTest.java @@ -20,7 +20,7 @@ import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat;