Skip to content

Commit

Permalink
[incubator-kie-drools-6136] Migrate droos test coverage module to JUn…
Browse files Browse the repository at this point in the history
…it5 - #2 (#6139)

* More tests migrated to JUnit5

* More tests migrated

* More unit tests migrated to JUnit5
  • Loading branch information
pibizza authored Oct 31, 2024
1 parent f8c9fbf commit 6b2d92d
Show file tree
Hide file tree
Showing 63 changed files with 1,963 additions and 1,804 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,20 @@
import org.drools.testcoverage.common.model.Person;
import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.KieBaseUtil;
import org.junit.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.kie.api.KieBase;
import org.kie.api.runtime.KieSession;

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

public abstract class AbstractBackwardChainingTest {

protected final KieBaseTestConfiguration kieBaseTestConfiguration;

public AbstractBackwardChainingTest(final KieBaseTestConfiguration kieBaseTestConfiguration) {
this.kieBaseTestConfiguration = kieBaseTestConfiguration;
}

@Test(timeout = 10000)
public void testQueryPositional() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testQueryPositional(KieBaseTestConfiguration kieBaseTestConfiguration) {
String drl = getQueryHeader();

drl += "rule x1\n" +
Expand Down Expand Up @@ -81,11 +79,13 @@ public void testQueryPositional() {
" list.add( $name1 + \" : \" + $age1 );\n" +
"end \n";

testQuery(drl);
testQuery(kieBaseTestConfiguration, drl);
}

@Test(timeout = 10000)
public void testQueryNamed() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testQueryNamed(KieBaseTestConfiguration kieBaseTestConfiguration) {
String drl = getQueryHeader();

drl += "rule x1\n" +
Expand Down Expand Up @@ -127,11 +127,13 @@ public void testQueryNamed() {
" list.add( $name1 + \" : \" + $age1 );\n" +
"end \n";

testQuery(drl);
testQuery(kieBaseTestConfiguration, drl);
}

@Test(timeout = 10000)
public void testQueryMixed() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testQueryMixed(KieBaseTestConfiguration kieBaseTestConfiguration) {
String drl = getQueryHeader();

drl += "rule x1\n" +
Expand Down Expand Up @@ -173,10 +175,10 @@ public void testQueryMixed() {
" list.add( $name1 + \" : \" + $age1 );\n" +
"end \n";

testQuery(drl);
testQuery(kieBaseTestConfiguration, drl);
}

private void testQuery(final String drl) {
private void testQuery(KieBaseTestConfiguration kieBaseTestConfiguration, final String drl) {
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("backward-chaining-test", kieBaseTestConfiguration, drl);
final KieSession ksession = kbase.newKieSession();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import org.drools.testcoverage.common.util.KieBaseUtil;
import org.drools.testcoverage.common.util.KieSessionTestConfiguration;
import org.drools.testcoverage.common.util.SerializationHelper;
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.marshalling.ObjectMarshallingStrategy;
import org.kie.api.runtime.Environment;
Expand All @@ -39,14 +40,9 @@

public abstract class AbstractCellTest {

protected final KieBaseTestConfiguration kieBaseTestConfiguration;

public AbstractCellTest(final KieBaseTestConfiguration kieBaseTestConfiguration) {
this.kieBaseTestConfiguration = kieBaseTestConfiguration;
}

@Test
public void testCell() throws IOException, ClassNotFoundException {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
public void testCell(KieBaseTestConfiguration kieBaseTestConfiguration) throws IOException, ClassNotFoundException {

final String drl = "package evalmodify;\n" +
"\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.KieBaseUtil;
import org.drools.testcoverage.common.util.KieSessionTestConfiguration;
import org.junit.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.kie.api.KieBase;
import org.kie.api.event.rule.AfterMatchFiredEvent;
import org.kie.api.event.rule.AgendaEventListener;
Expand All @@ -43,14 +45,10 @@

public abstract class AbstractCepEspTest {

protected final KieBaseTestConfiguration kieBaseTestConfiguration;

public AbstractCepEspTest(final KieBaseTestConfiguration kieBaseTestConfiguration) {
this.kieBaseTestConfiguration = kieBaseTestConfiguration;
}

@Test(timeout = 10000)
public void testAssertBehaviorOnEntryPoints() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testAssertBehaviorOnEntryPoints(KieBaseTestConfiguration kieBaseTestConfiguration) {
final KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources("cep-esp-test", kieBaseTestConfiguration,
"org/drools/compiler/integrationtests/test_CEP_AssertBehaviorOnEntryPoints.drl");
final KieSession ksession = kbase.newKieSession();
Expand Down Expand Up @@ -91,8 +89,10 @@ public void testAssertBehaviorOnEntryPoints() {
}
}

@Test(timeout = 10000L)
public void testDuplicateFiring2() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testDuplicateFiring2(KieBaseTestConfiguration kieBaseTestConfiguration) {

final String drl = "package org.test;\n" +
"import " + StockTick.class.getCanonicalName() + ";\n " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static Stream<KieBaseTestConfiguration> parameters() {
return TestParametersUtil2.getKieBaseStreamConfigurations(true).stream();
}

@ParameterizedTest
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
public void testAccumulatesExpireVsCancel(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception {
// JBRULES-3201
Expand Down Expand Up @@ -126,7 +126,7 @@ public void testAccumulatesExpireVsCancel(KieBaseTestConfiguration kieBaseTestCo
}
}

@ParameterizedTest
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
public void testManySlidingWindows(KieBaseTestConfiguration kieBaseTestConfiguration) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
package org.drools.compiler.integrationtests;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import org.drools.core.reteoo.JoinNode;
import org.drools.core.reteoo.LeftTupleSink;
Expand All @@ -36,10 +36,10 @@
import org.drools.testcoverage.common.util.KieBaseUtil;
import org.drools.testcoverage.common.util.KieSessionTestConfiguration;
import org.drools.testcoverage.common.util.KieUtil;
import org.drools.testcoverage.common.util.TestParametersUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.drools.testcoverage.common.util.TestParametersUtil2;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.kie.api.KieBase;
import org.kie.api.KieServices;
import org.kie.api.builder.KieModule;
Expand All @@ -51,23 +51,17 @@
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;

@RunWith(Parameterized.class)
public class AccumulateMvelDialectTest {

private final KieBaseTestConfiguration kieBaseTestConfiguration;

public AccumulateMvelDialectTest( final KieBaseTestConfiguration kieBaseTestConfiguration) {
this.kieBaseTestConfiguration = kieBaseTestConfiguration;
}

@Parameterized.Parameters(name = "KieBase type={0}")
public static Collection<Object[]> getParameters() {
return TestParametersUtil.getKieBaseCloudConfigurations(true);
public static Stream<KieBaseTestConfiguration> parameters() {
return TestParametersUtil2.getKieBaseCloudConfigurations(true).stream();
}

// See https://issues.jboss.org/browse/DROOLS-2733
@Test(timeout = 10000)
public void testMVELAccumulate() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testMVELAccumulate(KieBaseTestConfiguration kieBaseTestConfiguration) {
final KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources("accumulate-test", kieBaseTestConfiguration,
"org/drools/compiler/integrationtests/test_AccumulateMVEL.drl");
final KieSession wm = kbase.newKieSession();
Expand Down Expand Up @@ -101,8 +95,10 @@ public void testMVELAccumulate() {
}

// See https://issues.jboss.org/browse/DROOLS-2733
@Test(timeout = 10000)
public void testMVELAccumulate2WM() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testMVELAccumulate2WM(KieBaseTestConfiguration kieBaseTestConfiguration) {

final KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources("accumulate-test", kieBaseTestConfiguration,
"org/drools/compiler/integrationtests/test_AccumulateMVEL.drl");
Expand Down Expand Up @@ -167,20 +163,22 @@ public void testMVELAccumulate2WM() {
}


@Test
public void testAccFunctionOpaqueJoins() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
public void testAccFunctionOpaqueJoins(KieBaseTestConfiguration kieBaseTestConfiguration) {
// DROOLS-661
testAccFunctionOpaqueJoins(PropertySpecificOption.ALLOWED);
testAccFunctionOpaqueJoins(kieBaseTestConfiguration, PropertySpecificOption.ALLOWED);
}

@Test
public void testAccFunctionOpaqueJoinsWithPropertyReactivity() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
public void testAccFunctionOpaqueJoinsWithPropertyReactivity(KieBaseTestConfiguration kieBaseTestConfiguration) {
// DROOLS-1445
testAccFunctionOpaqueJoins(PropertySpecificOption.ALWAYS);
testAccFunctionOpaqueJoins(kieBaseTestConfiguration, PropertySpecificOption.ALWAYS);
}

// This is unsupported as the declared type Data is loosely typed
private void testAccFunctionOpaqueJoins(final PropertySpecificOption propertySpecificOption) {
private void testAccFunctionOpaqueJoins(KieBaseTestConfiguration kieBaseTestConfiguration, final PropertySpecificOption propertySpecificOption) {
final String drl = "package org.test; " +
"import java.util.*; " +
"global List list; " +
Expand Down Expand Up @@ -273,8 +271,9 @@ private void testAccFunctionOpaqueJoins(final PropertySpecificOption propertySpe
}
}

@Test
public void testAccumulateWithSameSubnetwork() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
public void testAccumulateWithSameSubnetwork(KieBaseTestConfiguration kieBaseTestConfiguration) {
final String drl = "package org.drools.compiler.test;\n" +
"import " + Cheese.class.getCanonicalName() + ";\n" +
"import " + Person.class.getCanonicalName() + ";\n" +
Expand Down
Loading

0 comments on commit 6b2d92d

Please sign in to comment.