Skip to content

Commit

Permalink
[incubator-kie-drools-6136] Migrate drools tests to JUnit5 - apache#9 (
Browse files Browse the repository at this point in the history
…apache#6191)

* Migrated last tests. A number of tests disabled

* Opened issue for failing test
  • Loading branch information
pibizza authored and rgdoliveira committed Dec 17, 2024
1 parent 0d0e64f commit e834124
Show file tree
Hide file tree
Showing 35 changed files with 861 additions and 751 deletions.
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

0 comments on commit e834124

Please sign in to comment.