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

GUVNOR-2980: Test scenarios do not show correct results #1226

Merged
merged 1 commit into from
Apr 27, 2017
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 @@ -58,7 +58,7 @@ public boolean accept( Match activation ) {
if ( ruleNames.isEmpty() ) {
return true;
}
String ruleName = activation.getRule().getName();
String ruleName = getFullyQualifiedRuleName(activation.getRule());

if ( inclusive ) {
return ruleNames.contains( ruleName );
Expand Down Expand Up @@ -89,14 +89,19 @@ public void beforeMatchFired( BeforeMatchFiredEvent event ) {
private void record( Rule rule,
Map<String, Integer> counts ) {
this.totalFires++;
String name = rule.getName();
String name = getFullyQualifiedRuleName(rule);
if ( !counts.containsKey( name ) ) {
counts.put( name, 1 );
} else {
counts.put( name, counts.get( name ) + 1 );
}
}

private String getFullyQualifiedRuleName(final Rule rule) {
String packageName = rule.getPackageName();
return (packageName.isEmpty()?rule.getName():packageName+"."+rule.getName());
}

/**
* @return A map of the number of times a given rule "fired".
* (of course in reality the side effect of its firing may have been nilled out).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ public void testIntegrationWithSuccess() throws Exception {

ExecutionTrace executionTrace = new ExecutionTrace();

sc.getRules().add("rule1");
sc.getRules().add("rule2");
sc.getRules().add("foo.bar.rule1");
sc.getRules().add("foo.bar.rule2");
sc.setInclusive(true);
sc.getFixtures().add(executionTrace);

Expand All @@ -448,13 +448,13 @@ public void testIntegrationWithSuccess() throws Exception {

);

assertions[2] = new VerifyRuleFired("rule1",
assertions[2] = new VerifyRuleFired("foo.bar.rule1",
1,
null);
assertions[3] = new VerifyRuleFired("rule2",
assertions[3] = new VerifyRuleFired("foo.bar.rule2",
1,
null);
assertions[4] = new VerifyRuleFired("rule3",
assertions[4] = new VerifyRuleFired("foo.bar.rule3",
0,
null);

Expand Down Expand Up @@ -502,8 +502,8 @@ public void testIntegrationInfiniteLoop() throws Exception {

ExecutionTrace executionTrace = new ExecutionTrace();

sc.getRules().add("rule1");
sc.getRules().add("rule2");
sc.getRules().add("foo.bar.rule1");
sc.getRules().add("foo.bar.rule2");
sc.setInclusive(true);
sc.getFixtures().add(executionTrace);

Expand All @@ -526,13 +526,13 @@ public void testIntegrationInfiniteLoop() throws Exception {

);

assertions[2] = new VerifyRuleFired("rule1",
assertions[2] = new VerifyRuleFired("foo.bar.rule1",
1,
null);
assertions[3] = new VerifyRuleFired("rule2",
assertions[3] = new VerifyRuleFired("foo.bar.rule2",
1,
null);
assertions[4] = new VerifyRuleFired("rule3",
assertions[4] = new VerifyRuleFired("foo.bar.rule3",
0,
null);

Expand Down Expand Up @@ -565,7 +565,7 @@ public void testIntegrationWithDeclaredTypes() throws Exception {

ExecutionTrace executionTrace = new ExecutionTrace();

scenario.getRules().add("rule1");
scenario.getRules().add("foo.bar.rule1");
scenario.setInclusive(true);
scenario.getFixtures().add(executionTrace);

Expand All @@ -578,7 +578,7 @@ public void testIntegrationWithDeclaredTypes() throws Exception {

));

assertions[1] = new VerifyRuleFired("rule1",
assertions[1] = new VerifyRuleFired("foo.bar.rule1",
1,
null);

Expand Down Expand Up @@ -867,8 +867,8 @@ private Expectation[] populateScenarioForFailure(Scenario sc) {
false));

ExecutionTrace executionTrace = new ExecutionTrace();
sc.getRules().add("rule1");
sc.getRules().add("rule2");
sc.getRules().add("foo.bar.rule1");
sc.getRules().add("foo.bar.rule2");
sc.setInclusive(true);
sc.getFixtures().add(executionTrace);

Expand All @@ -886,18 +886,18 @@ private Expectation[] populateScenarioForFailure(Scenario sc) {
"XXX",
"=="),
new VerifyField("status",
"rule2",
"foo.bar.rule2",
"==")

));

assertions[2] = new VerifyRuleFired("rule1",
assertions[2] = new VerifyRuleFired("foo.bar.rule1",
1,
null);
assertions[3] = new VerifyRuleFired("rule2",
assertions[3] = new VerifyRuleFired("foo.bar.rule2",
1,
null);
assertions[4] = new VerifyRuleFired("rule3",
assertions[4] = new VerifyRuleFired("foo.bar.rule3",
2,
null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class TestingEventListenerTest extends RuleUnit {
@Test
public void testInclusive() throws Exception {
HashSet<String> set = new HashSet<String>();
set.add( "rule1" );
set.add( "rule2" );
set.add( "org.pkg1.rule1" );
set.add( "org.pkg1.rule2" );

KieSession session = getKieSession( "test_rules.drl" );

Expand All @@ -43,26 +43,26 @@ public void testInclusive() throws Exception {
session.insert( new Cheese() );
session.fireAllRules( ls.getAgendaFilter( set, true ) );

assertEquals( new Integer( 1 ), (Integer) ls.firingCounts.get( "rule1" ) );
assertEquals( new Integer( 1 ), (Integer) ls.firingCounts.get( "rule2" ) );
assertEquals( new Integer( 1 ), (Integer) ls.firingCounts.get( "org.pkg1.rule1" ) );
assertEquals( new Integer( 1 ), (Integer) ls.firingCounts.get( "org.pkg1.rule2" ) );

//assertEquals(new Integer(1), (Integer) ls.firingCounts.get("rule3"));
assertFalse( ls.firingCounts.containsKey( "rule3" ) );
assertFalse( ls.firingCounts.containsKey( "rule4" ) );
assertFalse( ls.firingCounts.containsKey( "org.pkg1.rule3" ) );
assertFalse( ls.firingCounts.containsKey( "org.pkg1.rule4" ) );

session.insert( new Cheese() );
session.fireAllRules( ls.getAgendaFilter( set, true ) );
assertEquals( new Integer( 2 ), (Integer) ls.firingCounts.get( "rule1" ) );
assertEquals( new Integer( 2 ), (Integer) ls.firingCounts.get( "rule2" ) );
assertFalse( ls.firingCounts.containsKey( "rule3" ) );
assertEquals( new Integer( 2 ), (Integer) ls.firingCounts.get( "org.pkg1.rule1" ) );
assertEquals( new Integer( 2 ), (Integer) ls.firingCounts.get( "org.pkg1.rule2" ) );
assertFalse( ls.firingCounts.containsKey( "org.pkg1.rule3" ) );
assertEquals( 4, ls.totalFires );

}

@Test
public void testExclusive() throws Exception {
HashSet<String> set = new HashSet<String>();
set.add( "rule3" );
set.add( "org.pkg1.rule3" );

KieSession session = getKieSession( "test_rules.drl" );

Expand All @@ -77,10 +77,10 @@ public void testExclusive() throws Exception {
//assertEquals(new Integer(1), (Integer) ls.firingCounts.get("rule1"));
//assertEquals(new Integer(1), (Integer) ls.firingCounts.get("rule2"));

assertEquals( new Integer( 1 ), (Integer) ls.firingCounts.get( "rule2" ) );
assertEquals( new Integer( 1 ), (Integer) ls.firingCounts.get( "rule1" ) );
assertFalse( ls.firingCounts.containsKey( "rule3" ) );
assertFalse( ls.firingCounts.containsKey( "rule4" ) );
assertEquals( new Integer( 1 ), (Integer) ls.firingCounts.get( "org.pkg1.rule2" ) );
assertEquals( new Integer( 1 ), (Integer) ls.firingCounts.get( "org.pkg1.rule1" ) );
assertFalse( ls.firingCounts.containsKey( "org.pkg1.rule3" ) );
assertFalse( ls.firingCounts.containsKey( "org.pkg1.rule4" ) );

}

Expand All @@ -101,9 +101,9 @@ public void testNoFilter() throws Exception {
session.setGlobal( "list", list );
session.fireAllRules( ls.getAgendaFilter( set, false ) );

assertEquals( new Integer( 1 ), (Integer) ls.firingCounts.get( "rule1" ) );
assertEquals( new Integer( 1 ), (Integer) ls.firingCounts.get( "rule2" ) );
assertEquals( new Integer( 1 ), (Integer) ls.firingCounts.get( "rule3" ) );
assertEquals( new Integer( 1 ), (Integer) ls.firingCounts.get( "org.pkg1.rule1" ) );
assertEquals( new Integer( 1 ), (Integer) ls.firingCounts.get( "org.pkg1.rule2" ) );
assertEquals( new Integer( 1 ), (Integer) ls.firingCounts.get( "org.pkg1.rule3" ) );

String[] summary = ls.getRulesFiredSummary();
assertEquals( 3, summary.length );
Expand Down