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 - #1 (apache#6137)

* Initial test migration

* Migrated more unit tests

* Migrated more unit tests

* Fixed test

* More tests migrated to junit5

* Fixed test
  • Loading branch information
pibizza authored and rgdoliveira committed Oct 24, 2024
1 parent bb48f8d commit 9133aee
Show file tree
Hide file tree
Showing 56 changed files with 1,674 additions and 1,429 deletions.
21 changes: 20 additions & 1 deletion drools-test-coverage/test-compiler-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,26 @@
<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.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@
package org.drools.compiler.integrationtests;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import org.drools.compiler.integrationtests.incrementalcompilation.TestUtil;
import org.drools.kiesession.rulebase.InternalKnowledgeBase;
import org.drools.core.impl.RuleBaseFactory;
import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.KieBaseUtil;
import org.drools.testcoverage.common.util.TestParametersUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.drools.testcoverage.common.util.TestParametersUtil2;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.kie.api.KieBase;
import org.kie.api.definition.type.FactType;
import org.kie.api.runtime.KieSession;
Expand All @@ -42,7 +41,6 @@
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;

@RunWith(Parameterized.class)
public class AccumulateCepTest {

public static final String TEST_MANY_SLIDING_WINDOWS_DRL = "package com.sample;\n" +
Expand Down Expand Up @@ -72,19 +70,13 @@ public class AccumulateCepTest {
"end\n" +
"\n";

private final KieBaseTestConfiguration kieBaseTestConfiguration;

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

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

@Test
public void testAccumulatesExpireVsCancel() throws Exception {
@ParameterizedTest
@MethodSource("parameters")
public void testAccumulatesExpireVsCancel(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception {
// JBRULES-3201
final String drl = "package com.sample;\n" +
"\n" +
Expand Down Expand Up @@ -134,8 +126,9 @@ public void testAccumulatesExpireVsCancel() throws Exception {
}
}

@Test
public void testManySlidingWindows() {
@ParameterizedTest
@MethodSource("parameters")
public void testManySlidingWindows(KieBaseTestConfiguration kieBaseTestConfiguration) {

final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("accumulate-test", kieBaseTestConfiguration,
TEST_MANY_SLIDING_WINDOWS_DRL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import org.drools.testcoverage.common.model.MyFact;
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.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.kie.api.KieBase;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieSession;
Expand All @@ -40,31 +41,25 @@
import org.kie.api.runtime.rule.Variable;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.params.provider.Arguments.arguments;

@RunWith(Parameterized.class)
public class AccumulateConsistencyTest {

private final KieBaseTestConfiguration kieBaseTestConfiguration;
private final boolean accumulateNullPropagation;

public AccumulateConsistencyTest(final KieBaseTestConfiguration kieBaseTestConfiguration, boolean accumulateNullPropagation) {
this.kieBaseTestConfiguration = kieBaseTestConfiguration;
this.accumulateNullPropagation = accumulateNullPropagation;
}

// accumulateNullPropagation is false by default in drools 7.x
@Parameterized.Parameters(name = "KieBase type={0}, accumulateNullPropagation= {1}")
public static Collection<Object[]> getParameters() {
Collection<Object[]> parameters = new ArrayList<>();
parameters.add(new Object[]{KieBaseTestConfiguration.CLOUD_IDENTITY, false});
parameters.add(new Object[]{KieBaseTestConfiguration.CLOUD_IDENTITY_MODEL_PATTERN, false});
parameters.add(new Object[]{KieBaseTestConfiguration.CLOUD_IDENTITY, true});
parameters.add(new Object[]{KieBaseTestConfiguration.CLOUD_IDENTITY_MODEL_PATTERN, true});
return parameters;
public static Stream<Arguments> parameters() {
Collection<Arguments> parameters = new ArrayList<>();
parameters.add(arguments(KieBaseTestConfiguration.CLOUD_IDENTITY, false));
parameters.add(arguments(KieBaseTestConfiguration.CLOUD_IDENTITY_MODEL_PATTERN, false));
parameters.add(arguments(KieBaseTestConfiguration.CLOUD_IDENTITY, true));
parameters.add(arguments(KieBaseTestConfiguration.CLOUD_IDENTITY_MODEL_PATTERN, true));
return parameters.stream();
}

@Test
public void testMinNoMatch() {
@ParameterizedTest(name = "KieBase type={0}, accumulateNullPropagation= {1}")
@MethodSource("parameters")
public void testMinNoMatch(KieBaseTestConfiguration kieBaseTestConfiguration, boolean accumulateNullPropagation) {
final String drl =
"package org.drools.compiler.integrationtests;\n" +
"import " + Person.class.getCanonicalName() + ";\n" +
Expand Down Expand Up @@ -93,8 +88,9 @@ public void testMinNoMatch() {
}
}

@Test
public void testMaxNoMatch() {
@ParameterizedTest(name = "KieBase type={0}, accumulateNullPropagation= {1}")
@MethodSource("parameters")
public void testMaxNoMatch(KieBaseTestConfiguration kieBaseTestConfiguration, boolean accumulateNullPropagation) {
final String drl =
"package org.drools.compiler.integrationtests;\n" +
"import " + Person.class.getCanonicalName() + ";\n" +
Expand Down Expand Up @@ -123,8 +119,9 @@ public void testMaxNoMatch() {
}
}

@Test
public void testAveNoMatch() {
@ParameterizedTest(name = "KieBase type={0}, accumulateNullPropagation= {1}")
@MethodSource("parameters")
public void testAveNoMatch(KieBaseTestConfiguration kieBaseTestConfiguration, boolean accumulateNullPropagation) {
final String drl =
"package org.drools.compiler.integrationtests;\n" +
"import " + Person.class.getCanonicalName() + ";\n" +
Expand Down Expand Up @@ -153,8 +150,9 @@ public void testAveNoMatch() {
}
}

@Test
public void testSumNoMatch() {
@ParameterizedTest(name = "KieBase type={0}, accumulateNullPropagation= {1}")
@MethodSource("parameters")
public void testSumNoMatch(KieBaseTestConfiguration kieBaseTestConfiguration, boolean accumulateNullPropagation) {
final String drl =
"package org.drools.compiler.integrationtests;\n" +
"import " + Person.class.getCanonicalName() + ";\n" +
Expand All @@ -179,8 +177,9 @@ public void testSumNoMatch() {
}
}

@Test
public void testCountNoMatch() {
@ParameterizedTest(name = "KieBase type={0}, accumulateNullPropagation= {1}")
@MethodSource("parameters")
public void testCountNoMatch(KieBaseTestConfiguration kieBaseTestConfiguration, boolean accumulateNullPropagation) {
final String drl =
"package org.drools.compiler.integrationtests;\n" +
"import " + Person.class.getCanonicalName() + ";\n" +
Expand All @@ -205,8 +204,9 @@ public void testCountNoMatch() {
}
}

@Test
public void testMinMaxNoMatch() {
@ParameterizedTest(name = "KieBase type={0}, accumulateNullPropagation= {1}")
@MethodSource("parameters")
public void testMinMaxNoMatch(KieBaseTestConfiguration kieBaseTestConfiguration, boolean accumulateNullPropagation) {
final String drl =
"package org.drools.compiler.integrationtests;\n" +
"import " + Person.class.getCanonicalName() + ";\n" +
Expand All @@ -232,8 +232,9 @@ public void testMinMaxNoMatch() {
}
}

@Test
public void testMinMaxMatch() {
@ParameterizedTest(name = "KieBase type={0}, accumulateNullPropagation= {1}")
@MethodSource("parameters")
public void testMinMaxMatch(KieBaseTestConfiguration kieBaseTestConfiguration, boolean accumulateNullPropagation) {
final String drl =
"package org.drools.compiler.integrationtests;\n" +
"import " + Person.class.getCanonicalName() + ";\n" +
Expand Down Expand Up @@ -269,8 +270,9 @@ public void testMinMaxMatch() {
}
}

@Test
public void testMinNoMatchAccFrom() {
@ParameterizedTest(name = "KieBase type={0}, accumulateNullPropagation= {1}")
@MethodSource("parameters")
public void testMinNoMatchAccFrom(KieBaseTestConfiguration kieBaseTestConfiguration, boolean accumulateNullPropagation) {

final String drl =
"package org.drools.compiler.integrationtests;\n" +
Expand Down Expand Up @@ -300,8 +302,9 @@ public void testMinNoMatchAccFrom() {
}
}

@Test
public void testMinMatchUnification() {
@ParameterizedTest(name = "KieBase type={0}, accumulateNullPropagation= {1}")
@MethodSource("parameters")
public void testMinMatchUnification(KieBaseTestConfiguration kieBaseTestConfiguration, boolean accumulateNullPropagation) {

final String drl =
"package org.drools.compiler.integrationtests;\n" +
Expand Down Expand Up @@ -330,8 +333,9 @@ public void testMinMatchUnification() {
}
}

@Test
public void testMinNoMatchUnification() {
@ParameterizedTest(name = "KieBase type={0}, accumulateNullPropagation= {1}")
@MethodSource("parameters")
public void testMinNoMatchUnification(KieBaseTestConfiguration kieBaseTestConfiguration, boolean accumulateNullPropagation) {
final String drl =
"package org.drools.compiler.integrationtests;\n" +
"import " + Person.class.getCanonicalName() + ";\n" +
Expand Down Expand Up @@ -363,8 +367,9 @@ public void testMinNoMatchUnification() {
}
}

@Test
public void testMinMatchUnificationQuery() {
@ParameterizedTest(name = "KieBase type={0}, accumulateNullPropagation= {1}")
@MethodSource("parameters")
public void testMinMatchUnificationQuery(KieBaseTestConfiguration kieBaseTestConfiguration, boolean accumulateNullPropagation) {

final String drl =
"package org.drools.compiler.integrationtests;\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,29 @@
*/
package org.drools.compiler.integrationtests;

import java.util.Collection;
import java.util.stream.Stream;

import org.drools.testcoverage.common.model.Person;
import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.KieBaseUtil;
import org.drools.testcoverage.common.util.TestParametersUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.drools.testcoverage.common.util.TestParametersUtil2;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.kie.api.KieBase;
import org.kie.api.conf.MBeansOption;
import org.kie.api.definition.rule.Rule;

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

@RunWith(Parameterized.class)
public class AnnotationsCepTest {

private final KieBaseTestConfiguration kieBaseTestConfiguration;

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

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

@Test
public void testRuleAnnotation() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
public void testRuleAnnotation(KieBaseTestConfiguration kieBaseTestConfiguration) {
final String drl = "package org.drools.compiler.integrationtests\n" +
"import " + Person.class.getCanonicalName() + "; \n" +
"rule X\n" +
Expand All @@ -74,8 +66,9 @@ public void testRuleAnnotation() {

}

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

0 comments on commit 9133aee

Please sign in to comment.