Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[incubator-kie-drools-6136] Migrate drools tests to JUnit5 - #9 #6191

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 5 additions & 31 deletions drools-test-coverage/test-compiler-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,26 +119,11 @@
<artifactId>xstream</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down Expand Up @@ -190,17 +175,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@

import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.TestParametersUtil2;
import org.junit.experimental.categories.Category;
import org.kie.test.testcategory.TurtleTestCategory;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;

@Category(TurtleTestCategory.class)
@EnabledIfEnvironmentVariable(named = "runTurtleTests", matches = "*")
public class AccumulateFunctionConcurrencyTest extends BaseConcurrencyTest {

public static Stream<KieBaseTestConfiguration> parameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@

import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.TestParametersUtil2;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.kie.api.runtime.KieSession;
import org.kie.test.testcategory.TurtleTestCategory;

@Category(TurtleTestCategory.class)
@EnabledIfEnvironmentVariable(named = "runTurtleTests", matches = "*")
public class ConsequenceConcurrencyTest extends BaseConcurrencyTest {

public static Stream<KieBaseTestConfiguration> parameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@

import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.TestParametersUtil2;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.kie.api.KieBase;
import org.kie.api.runtime.KieSession;
import org.kie.test.testcategory.TurtleTestCategory;

@Category(TurtleTestCategory.class)
@EnabledIfEnvironmentVariable(named = "runTurtleTests", matches = "*")
public class ConsequenceWithAndOrConcurrencyTest extends BaseConcurrencyTest {

public static Stream<KieBaseTestConfiguration> parameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@

import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.TestParametersUtil2;
import org.junit.experimental.categories.Category;
import org.kie.test.testcategory.TurtleTestCategory;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;

@Category(TurtleTestCategory.class)
@EnabledIfEnvironmentVariable(named = "runTurtleTests", matches = "*")
public class ConstraintConcurrencyTest extends BaseConcurrencyTest {

public static Stream<KieBaseTestConfiguration> parameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@

import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.TestParametersUtil2;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.kie.api.KieBase;
import org.kie.api.runtime.KieSession;
import org.kie.test.testcategory.TurtleTestCategory;

@Category(TurtleTestCategory.class)
@EnabledIfEnvironmentVariable(named = "runTurtleTests", matches = "*")
public class ConstraintWithAndOrConcurrencyTest extends BaseConcurrencyTest {

public static Stream<KieBaseTestConfiguration> parameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@

import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.TestParametersUtil2;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.kie.api.KieBase;
import org.kie.api.runtime.KieSession;
import org.kie.test.testcategory.TurtleTestCategory;

@Category(TurtleTestCategory.class)
@EnabledIfEnvironmentVariable(named = "runTurtleTests", matches = "*")
public class ConstraintWithAndOrJittingConcurrencyTest extends BaseConcurrencyTest {

public static Stream<KieBaseTestConfiguration> parameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@

import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.TestParametersUtil2;
import org.junit.experimental.categories.Category;
import org.kie.test.testcategory.TurtleTestCategory;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;

@Category(TurtleTestCategory.class)
@EnabledIfEnvironmentVariable(named = "runTurtleTests", matches = "*")
public class EvalConcurrencyTest extends BaseConcurrencyTest {

public static Stream<KieBaseTestConfiguration> parameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@

import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.TestParametersUtil2;
import org.junit.experimental.categories.Category;
import org.kie.test.testcategory.TurtleTestCategory;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;

@Category(TurtleTestCategory.class)
@EnabledIfEnvironmentVariable(named = "runTurtleTests", matches = "*")
public class FromAccumulateConcurrencyTest extends BaseConcurrencyTest {

public static Stream<KieBaseTestConfiguration> parameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@
import org.drools.testcoverage.common.model.Result;
import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.KieBaseUtil;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.kie.api.KieBase;
import org.kie.api.runtime.KieSession;
import org.kie.test.testcategory.TurtleTestCategory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.assertj.core.api.Assertions.assertThat;

@Category(TurtleTestCategory.class)
@EnabledIfEnvironmentVariable(named = "runTurtleTests", matches = "*")
public class GlobalConcurrencyTest {

private static final Logger LOGGER = LoggerFactory.getLogger(GlobalConcurrencyTest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@

import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.TestParametersUtil2;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.kie.api.runtime.KieSession;
import org.kie.test.testcategory.TurtleTestCategory;

@Category(TurtleTestCategory.class)
@EnabledIfEnvironmentVariable(named = "runTurtleTests", matches = "*")
public class MVELDateClassFieldReaderConcurrencyTest extends BaseConcurrencyTest {

public static Stream<KieBaseTestConfiguration> parameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@

import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.TestParametersUtil2;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.kie.api.runtime.KieSession;
import org.kie.test.testcategory.TurtleTestCategory;

@Category(TurtleTestCategory.class)
@EnabledIfEnvironmentVariable(named = "runTurtleTests", matches = "*")
public class MVELNumberClassFieldReaderConcurrencyTest extends BaseConcurrencyTest {

public static Stream<KieBaseTestConfiguration> parameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@

import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.TestParametersUtil2;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.kie.api.runtime.KieSession;
import org.kie.test.testcategory.TurtleTestCategory;

@Category(TurtleTestCategory.class)
@EnabledIfEnvironmentVariable(named = "runTurtleTests", matches = "*")
public class MVELObjectClassFieldReaderConcurrencyTest extends BaseConcurrencyTest {

public static Stream<KieBaseTestConfiguration> parameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@
import java.util.Map;
import java.util.Set;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.kie.test.testcategory.TurtleTestCategory;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

@Category(TurtleTestCategory.class)
@EnabledIfEnvironmentVariable(named = "runTurtleTests", matches = "*")
public abstract class AbstractAddRemoveGenerated2RulesTest {

private final String rule1;
private final String rule2;
private String rule1;
private String rule2;

public AbstractAddRemoveGenerated2RulesTest(final ConstraintsPair constraintsPair) {
private void generateRules(final ConstraintsPair constraintsPair) {
final String rule1 = "package " + TestUtil.RULES_PACKAGE_NAME + ";" +
"global java.util.List list\n" +
"rule " + TestUtil.RULE1_NAME + " \n" +
Expand All @@ -59,11 +60,11 @@ public AbstractAddRemoveGenerated2RulesTest(final ConstraintsPair constraintsPai

// This takes only three different constraints - this is intentional, because it is needed to
// keep the number of combinations at reasonable number.
public static Collection<ConstraintsPair[]> generateRulesConstraintsCombinations(final String constraint1,
public static Collection<ConstraintsPair> generateRulesConstraintsCombinations(final String constraint1,
final String constraint2,
final String constraint3) {
final Set<ConstraintsPair> constraintsPairs = new HashSet<>();
final List<ConstraintsPair[]> result = new ArrayList<>();
final List<ConstraintsPair> result = new ArrayList<>();

final List<String> constraintsList = new ArrayList<>();
constraintsList.add(constraint1);
Expand All @@ -75,7 +76,7 @@ public static Collection<ConstraintsPair[]> generateRulesConstraintsCombinations
for (final String constraintsRule2 : constraintsCombinations) {
final ConstraintsPair constraintsPair = new ConstraintsPair(constraintsRule1, constraintsRule2);
if (constraintsPairs.add(constraintsPair)) {
result.add(new ConstraintsPair[]{constraintsPair});
result.add(constraintsPair);
}
}
}
Expand All @@ -98,57 +99,81 @@ private static List<String> getConstraintsCombinations(final List<String> constr

/////////////////////////// TESTS //////////////////////////////////

@Test(timeout = 40000)
public void testInsertFactsFireRulesRemoveRules() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(40000)
public void testInsertFactsFireRulesRemoveRules(ConstraintsPair constraintsPair) {
generateRules(constraintsPair);
AddRemoveTestCases.insertFactsFireRulesRemoveRules1(rule1, rule2, TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, null, getFacts());
AddRemoveTestCases.insertFactsFireRulesRemoveRules2(rule1, rule2, TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, null, getFacts());
AddRemoveTestCases.insertFactsFireRulesRemoveRules3(rule1, rule2, TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, null, getFacts());
}

@Test(timeout = 40000)
public void testInsertFactsFireRulesRemoveRulesRevertedRules() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(40000)
public void testInsertFactsFireRulesRemoveRulesRevertedRules(ConstraintsPair constraintsPair) {
generateRules(constraintsPair);
AddRemoveTestCases.insertFactsFireRulesRemoveRules1(rule2, rule1, TestUtil.RULE2_NAME, TestUtil.RULE1_NAME, null, getFacts());
AddRemoveTestCases.insertFactsFireRulesRemoveRules2(rule2, rule1, TestUtil.RULE2_NAME, TestUtil.RULE1_NAME, null, getFacts());
AddRemoveTestCases.insertFactsFireRulesRemoveRules3(rule2, rule1, TestUtil.RULE2_NAME, TestUtil.RULE1_NAME, null, getFacts());
}

@Test(timeout = 40000)
public void testFireRulesInsertFactsFireRulesRemoveRules() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(40000)
public void testFireRulesInsertFactsFireRulesRemoveRules(ConstraintsPair constraintsPair) {
generateRules(constraintsPair);
AddRemoveTestCases.fireRulesInsertFactsFireRulesRemoveRules1(rule1, rule2, TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, null, getFacts());
AddRemoveTestCases.fireRulesInsertFactsFireRulesRemoveRules2(rule1, rule2, TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, null, getFacts());
AddRemoveTestCases.fireRulesInsertFactsFireRulesRemoveRules3(rule1, rule2, TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, null, getFacts());
}

@Test(timeout = 40000)
public void testFireRulesInsertFactsFireRulesRemoveRulesRevertedRules() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(40000)
public void testFireRulesInsertFactsFireRulesRemoveRulesRevertedRules(ConstraintsPair constraintsPair) {
generateRules(constraintsPair);
AddRemoveTestCases.fireRulesInsertFactsFireRulesRemoveRules1(rule2, rule1, TestUtil.RULE2_NAME, TestUtil.RULE1_NAME, null, getFacts());
AddRemoveTestCases.fireRulesInsertFactsFireRulesRemoveRules2(rule2, rule1, TestUtil.RULE2_NAME, TestUtil.RULE1_NAME, null, getFacts());
AddRemoveTestCases.fireRulesInsertFactsFireRulesRemoveRules3(rule2, rule1, TestUtil.RULE2_NAME, TestUtil.RULE1_NAME, null, getFacts());
}

@Test(timeout = 40000)
public void testInsertFactsRemoveRulesFireRulesRemoveRules() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(40000)
public void testInsertFactsRemoveRulesFireRulesRemoveRules(ConstraintsPair constraintsPair) {
generateRules(constraintsPair);
AddRemoveTestCases.insertFactsRemoveRulesFireRulesRemoveRules1(rule1, rule2, TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, null, getFacts());
AddRemoveTestCases.insertFactsRemoveRulesFireRulesRemoveRules2(rule1, rule2, TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, null, getFacts());
AddRemoveTestCases.insertFactsRemoveRulesFireRulesRemoveRules3(rule1, rule2, TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, null, getFacts());
}

@Test(timeout = 40000)
public void testInsertFactsRemoveRulesFireRulesRemoveRulesRevertedRules() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(40000)
public void testInsertFactsRemoveRulesFireRulesRemoveRulesRevertedRules(ConstraintsPair constraintsPair) {
generateRules(constraintsPair);
AddRemoveTestCases.insertFactsRemoveRulesFireRulesRemoveRules1(rule2, rule1, TestUtil.RULE2_NAME, TestUtil.RULE1_NAME, null, getFacts());
AddRemoveTestCases.insertFactsRemoveRulesFireRulesRemoveRules2(rule2, rule1, TestUtil.RULE2_NAME, TestUtil.RULE1_NAME, null, getFacts());
AddRemoveTestCases.insertFactsRemoveRulesFireRulesRemoveRules3(rule2, rule1, TestUtil.RULE2_NAME, TestUtil.RULE1_NAME, null, getFacts());
}

@Test(timeout = 40000)
public void testInsertFactsFireRulesRemoveRulesReinsertRules() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(40000)
public void testInsertFactsFireRulesRemoveRulesReinsertRules(ConstraintsPair constraintsPair) {
generateRules(constraintsPair);
AddRemoveTestCases.insertFactsFireRulesRemoveRulesReinsertRules1(rule1, rule2, TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, null, getFacts());
AddRemoveTestCases.insertFactsFireRulesRemoveRulesReinsertRules2(rule1, rule2, TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, null, getFacts());
AddRemoveTestCases.insertFactsFireRulesRemoveRulesReinsertRules3(rule1, rule2, TestUtil.RULE1_NAME, TestUtil.RULE2_NAME, null, getFacts());
}

@Test(timeout = 40000)
public void testInsertFactsFireRulesRemoveRulesReinsertRulesRevertedRules() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(40000)
public void testInsertFactsFireRulesRemoveRulesReinsertRulesRevertedRules(ConstraintsPair constraintsPair) {
generateRules(constraintsPair);
AddRemoveTestCases.insertFactsFireRulesRemoveRulesReinsertRules1(rule2, rule1, TestUtil.RULE2_NAME, TestUtil.RULE1_NAME, null, getFacts());
AddRemoveTestCases.insertFactsFireRulesRemoveRulesReinsertRules2(rule2, rule1, TestUtil.RULE2_NAME, TestUtil.RULE1_NAME, null, getFacts());
AddRemoveTestCases.insertFactsFireRulesRemoveRulesReinsertRules3(rule2, rule1, TestUtil.RULE2_NAME, TestUtil.RULE1_NAME, null, getFacts());
Expand Down
Loading
Loading