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 test coverage to JUnit5 - #4 #6147 #6162

Merged
merged 1 commit into from
Nov 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;

import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
import org.drools.testcoverage.common.util.KieBaseUtil;
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.KieBuilder;
Expand All @@ -53,23 +53,17 @@

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

@RunWith(Parameterized.class)
public class DeclarativeAgendaTest {

private final KieBaseTestConfiguration kieBaseTestConfiguration;

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

@Parameterized.Parameters(name = "KieBase type={0}")
public static Collection<Object[]> getParameters() {
public static Stream<KieBaseTestConfiguration> parameters() {
// Declarative Agenda is experimental. Not supported by exec-model
return TestParametersUtil.getKieBaseCloudConfigurations(false);
return TestParametersUtil2.getKieBaseCloudConfigurations(false).stream();
}

@Test(timeout=10000)
public void testSimpleBlockingUsingForall() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testSimpleBlockingUsingForall(KieBaseTestConfiguration kieBaseTestConfiguration) {
String str = "";
str += "package org.domain.test \n";
str += "import " + Match.class.getName() + "\n";
Expand Down Expand Up @@ -107,8 +101,10 @@ public void testSimpleBlockingUsingForall() {
ksession.dispose();
}

@Test(timeout=10000)
public void testBasicBlockOnAnnotation() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testBasicBlockOnAnnotation(KieBaseTestConfiguration kieBaseTestConfiguration) {
String str = "";
str += "package org.domain.test \n";
str += "import " + Match.class.getName() + "\n";
Expand Down Expand Up @@ -169,9 +165,11 @@ public void testBasicBlockOnAnnotation() {
ksession.dispose();
}

@Test(timeout=10000)
public void testApplyBlockerFirst() {
KieSession ksession = getStatefulKnowledgeSession();
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testApplyBlockerFirst(KieBaseTestConfiguration kieBaseTestConfiguration) {
KieSession ksession = getStatefulKnowledgeSession(kieBaseTestConfiguration);

List list = new ArrayList();
ksession.setGlobal( "list",
Expand All @@ -193,9 +191,11 @@ public void testApplyBlockerFirst() {
assertThat(list.contains("rule1:go1")).isTrue();
}

@Test(timeout=10000)
public void testApplyBlockerFirstWithFireAllRulesInbetween() {
KieSession ksession = getStatefulKnowledgeSession();
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testApplyBlockerFirstWithFireAllRulesInbetween(KieBaseTestConfiguration kieBaseTestConfiguration) {
KieSession ksession = getStatefulKnowledgeSession(kieBaseTestConfiguration);

List list = new ArrayList();
ksession.setGlobal( "list",
Expand All @@ -219,9 +219,11 @@ public void testApplyBlockerFirstWithFireAllRulesInbetween() {
assertThat(list.contains("rule1:go1")).isTrue();
}

@Test(timeout=10000)
public void testApplyBlockerSecond() {
KieSession ksession = getStatefulKnowledgeSession();
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testApplyBlockerSecond(KieBaseTestConfiguration kieBaseTestConfiguration) {
KieSession ksession = getStatefulKnowledgeSession(kieBaseTestConfiguration);

List list = new ArrayList();
ksession.setGlobal( "list",
Expand All @@ -242,9 +244,11 @@ public void testApplyBlockerSecond() {
assertThat(list.contains("rule1:go1")).isTrue();
}

@Test(timeout=10000)
public void testApplyBlockerSecondWithUpdate() {
KieSession ksession = getStatefulKnowledgeSession();
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testApplyBlockerSecondWithUpdate(KieBaseTestConfiguration kieBaseTestConfiguration) {
KieSession ksession = getStatefulKnowledgeSession(kieBaseTestConfiguration);

List list = new ArrayList();
ksession.setGlobal( "list",
Expand Down Expand Up @@ -273,9 +277,11 @@ public void testApplyBlockerSecondWithUpdate() {
assertThat(list.contains("rule1:go1")).isTrue();
}

@Test(timeout=10000)
public void testApplyBlockerSecondAfterUpdate() {
KieSession ksession = getStatefulKnowledgeSession();
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testApplyBlockerSecondAfterUpdate(KieBaseTestConfiguration kieBaseTestConfiguration) {
KieSession ksession = getStatefulKnowledgeSession(kieBaseTestConfiguration);

List list = new ArrayList();
ksession.setGlobal( "list",
Expand Down Expand Up @@ -312,7 +318,7 @@ public void testApplyBlockerSecondAfterUpdate() {
assertThat(list.contains("rule1:go1")).isTrue();
}

public KieSession getStatefulKnowledgeSession() {
public KieSession getStatefulKnowledgeSession(KieBaseTestConfiguration kieBaseTestConfiguration) {
String str = "";
str += "package org.domain.test \n";
str += "import " + Match.class.getName() + "\n";
Expand Down Expand Up @@ -342,8 +348,10 @@ public KieSession getStatefulKnowledgeSession() {
return ksession;
}

@Test(timeout=10000)
public void testMultipleBlockers() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testMultipleBlockers(KieBaseTestConfiguration kieBaseTestConfiguration) {
String str = "";
str += "package org.domain.test \n";
str += "import " + Match.class.getName() + "\n";
Expand Down Expand Up @@ -419,8 +427,10 @@ public void testMultipleBlockers() {
ksession.dispose();
}

@Test(timeout=10000)
public void testMultipleBlockersWithUnblockAll() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testMultipleBlockersWithUnblockAll(KieBaseTestConfiguration kieBaseTestConfiguration) {
// This test is a bit wierd as it recurses. Maybe unblockAll is not feasible...
String str = "";
str += "package org.domain.test \n";
Expand Down Expand Up @@ -503,8 +513,10 @@ public void testMultipleBlockersWithUnblockAll() {
assertThat(list.contains("blockerAllSalesRules3:rule0:go3")).isTrue();
}

@Test(timeout=10000)
public void testIterativeUpdate() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testIterativeUpdate(KieBaseTestConfiguration kieBaseTestConfiguration) {
String str = "";
str += "package org.domain.test \n";
str += "import " + Match.class.getName() + "\n";
Expand Down Expand Up @@ -641,8 +653,10 @@ public void testIterativeUpdate() {
assertThat(list.contains("block:rule2")).isTrue();
}

@Test(timeout=10000)
public void testCancelActivation() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testCancelActivation(KieBaseTestConfiguration kieBaseTestConfiguration) {
String str = "";
str += "package org.domain.test \n";
str += "import " + Match.class.getName() + "\n";
Expand Down Expand Up @@ -715,8 +729,10 @@ public void matchCancelled(MatchCancelledEvent event) {
ksession.dispose();
}

@Test(timeout=10000)
public void testActiveInActiveChanges() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testActiveInActiveChanges(KieBaseTestConfiguration kieBaseTestConfiguration) {
String str = "";
str += "package org.domain.test \n";
str += "import " + Match.class.getName() + "\n";
Expand Down Expand Up @@ -770,8 +786,10 @@ public void testActiveInActiveChanges() {
ksession.dispose();
}

@Test(timeout=10000)
public void testCancelMultipleActivations() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testCancelMultipleActivations(KieBaseTestConfiguration kieBaseTestConfiguration) {
String str = "package org.domain.test\n" +
"import " + Match.class.getName() + "\n" +
"global java.util.List list\n" +
Expand Down Expand Up @@ -811,8 +829,10 @@ public void testCancelMultipleActivations() {
ksession.dispose();
}

@Test(timeout=10000)
public void testCancelActivationOnInsertAndUpdate() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
@Timeout(10000)
public void testCancelActivationOnInsertAndUpdate(KieBaseTestConfiguration kieBaseTestConfiguration) {
String str = "package org.domain.test\n" +
"import " + Match.class.getName() + "\n" +
"global java.util.List list\n" +
Expand Down Expand Up @@ -860,8 +880,9 @@ public void testCancelActivationOnInsertAndUpdate() {
ksession.dispose();
}

@Test
public void testFiredRuleDoNotRefireAfterUnblock() {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
public void testFiredRuleDoNotRefireAfterUnblock(KieBaseTestConfiguration kieBaseTestConfiguration) {
// BZ-1038076
String drl =
"package org.drools.mvel.integrationtests\n" +
Expand Down Expand Up @@ -947,8 +968,9 @@ public boolean add( T t ) {
}
}

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

String drl = "package org.drools.test;\n" +
"\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
package org.drools.mvel.integrationtests;

import java.io.File;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Stream;

import org.drools.mvel.compiler.Message;
import org.drools.mvel.expr.MVELDebugHandler;
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.logger.KieRuntimeLogger;
import org.kie.api.runtime.KieSession;
Expand All @@ -44,25 +43,18 @@
/**
* This is a sample class to launch a rule.
*/
@RunWith(Parameterized.class)
public class HelloWorldTest {

private final KieBaseTestConfiguration kieBaseTestConfiguration;

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

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

@Test
public void testHelloWorld() throws Exception {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
public void testHelloWorld(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception {
// load up the knowledge base
KieBase kbase = readKnowledgeBase();
KieBase kbase = readKnowledgeBase(kieBaseTestConfiguration);
KieSession ksession = kbase.newKieSession();
File testTmpDir = new File("target/test-tmp/");
testTmpDir.mkdirs();
Expand All @@ -77,8 +69,9 @@ public void testHelloWorld() throws Exception {
logger.close();
}

@Test
public void testHelloWorldDebug() throws Exception {
@ParameterizedTest(name = "KieBase type={0}")
@MethodSource("parameters")
public void testHelloWorldDebug(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception {
final Set<String> knownVariables = new HashSet<String>();
MVELRuntime.resetDebugger();
MVELDebugHandler.setDebugMode(true);
Expand All @@ -92,7 +85,7 @@ public int onBreak(Frame frame) {
String source = "org.drools.integrationtests.Rule_Hello_World";
MVELRuntime.registerBreakpoint(source, 1);
// load up the knowledge base
KieBase kbase = readKnowledgeBase();
KieBase kbase = readKnowledgeBase(kieBaseTestConfiguration);
KieSession ksession = kbase.newKieSession();
File testTmpDir = new File("target/test-tmp/");
testTmpDir.mkdirs();
Expand All @@ -114,7 +107,7 @@ public int onBreak(Frame frame) {
assertThat(knownVariables.contains("myMessage")).isTrue();
}

private KieBase readKnowledgeBase() throws Exception {
private KieBase readKnowledgeBase(KieBaseTestConfiguration kieBaseTestConfiguration) throws Exception {
return KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "Sample.drl");
}

Expand Down
Loading
Loading