[jboss-svn-commits] JBL Code SVN: r7089 - in labs/jbossrules/trunk/drools-compiler/src/test: java/org/drools/integrationtests resources/org/drools/integrationtests
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Oct 24 12:56:17 EDT 2006
Author: mark.proctor at jboss.com
Date: 2006-10-24 12:56:11 -0400 (Tue, 24 Oct 2006)
New Revision: 7089
Modified:
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java
labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsDynamicRule.drl
labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsDynamicRule2.drl
labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNotPingPong.drl
Log:
-Fixed testLogicalAssertionsDynamic
-Fixed modify
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2006-10-24 15:34:08 UTC (rev 7088)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2006-10-24 16:56:11 UTC (rev 7089)
@@ -2505,25 +2505,23 @@
// workingMemory.addEventListener(new
// DebugWorkingMemoryEventListener());
- final List list;
+ final List list = new ArrayList();
- final List l = new ArrayList();
+ final Person person = new Person( "person" );
+ final Cheese cheese = new Cheese( "cheese", 0 );
+ workingMemory.setGlobal( "cheese",
+ cheese );
+ workingMemory.setGlobal( "person",
+ person );
+ workingMemory.setGlobal( "list",
+ list );
- final String s = new String( "s" );
- final Integer i = new Integer( 1 );
- workingMemory.setGlobal( "i",
- i );
- workingMemory.setGlobal( "s",
- s );
- workingMemory.setGlobal( "l",
- l );
-
workingMemory.fireAllRules();
// not sure about desired state of working memory.
assertEquals( "Rules have not fired (looped) expected number of times",
10,
- l.size() );
+ list.size() );
}
public void testLogicalAssertionsDynamicRule() throws Exception {
@@ -2560,13 +2558,16 @@
final FactHandle h = workingMemory.assertObject( c2 );
workingMemory.assertObject( c3 );
workingMemory.fireAllRules();
- list = workingMemory.getObjects( c1.getType().getClass() );
+
+ // Check logical assertions where made for c2 and c3
+ list = workingMemory.getObjects( Person.class );
assertEquals( 2,
- list.size() );
- assertFalse( list.contains( c1.getType() ) );
- assertTrue( list.contains( c2.getType() ) );
- assertTrue( list.contains( c3.getType() ) );
+ list.size() );
+ assertFalse( list.contains( new Person( c1.getType() ) ) );
+ assertTrue( list.contains( new Person( c2.getType() ) ) );
+ assertTrue( list.contains( new Person( c3.getType() ) ) );
+ // this rule will make a logical assertion for c1 too
final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_LogicalAssertionsDynamicRule2.drl" ) );
builder = new PackageBuilder();
builder.addPackageFromDrl( reader );
@@ -2575,13 +2576,15 @@
workingMemory.fireAllRules();
- list = workingMemory.getObjects( c1.getType().getClass() );
+ // check all now have just one logical assertion each
+ list = workingMemory.getObjects( Person.class );
assertEquals( 3,
list.size() );
- assertTrue( list.contains( c1.getType() ) );
- assertTrue( list.contains( c2.getType() ) );
- assertTrue( list.contains( c3.getType() ) );
+ assertTrue( list.contains( new Person( c1.getType() ) ) );
+ assertTrue( list.contains( new Person( c2.getType() ) ) );
+ assertTrue( list.contains( new Person( c3.getType() ) ) );
+ // check the packages are correctly populated
assertEquals( "org.drools.test",
ruleBase.getPackages()[0].getName() );
assertEquals( "org.drools.test2",
@@ -2591,6 +2594,7 @@
assertEquals( "rule2",
ruleBase.getPackages()[1].getRules()[0].getName() );
+ // now remove the first rule
if ( reteooRuleBase != null ) {
reteooRuleBase.removeRule( ruleBase.getPackages()[0].getName(),
ruleBase.getPackages()[0].getRules()[0].getName() );
@@ -2599,6 +2603,7 @@
// ruleBase.getPackages()[0].getRules()[0].getName() );
}
+ // Check the rule was correctly remove
assertEquals( 0,
ruleBase.getPackages()[0].getRules().length );
assertEquals( 1,
@@ -2608,28 +2613,28 @@
assertEquals( "rule2",
ruleBase.getPackages()[1].getRules()[0].getName() );
- list = workingMemory.getObjects( c1.getType().getClass() );
- assertEquals( "remove of rule should retract objects logically asserted based on the rule",
+ list = workingMemory.getObjects( Person.class );
+ assertEquals( "removal of the rule should result in retraction of c3's logical assertion",
2,
list.size() );
- assertTrue( "remove of rule should retract objects logically asserted based on the rule",
- list.contains( c1.getType() ) );
- assertTrue( "remove of rule should retract objects logically asserted based on the rule",
- list.contains( c2.getType() ) );
- assertFalse( "remove of rule should retract objects logically asserted based on the rule",
- list.contains( c3.getType() ) );
+ assertTrue( "c1's logical assertion should not be retracted",
+ list.contains( new Person( c1.getType() ) ) );
+ assertTrue( "c2's logical assertion should not be retracted",
+ list.contains( new Person( c2.getType() ) ) );
+ assertFalse( "c3's logical assertion should be retracted",
+ list.contains( new Person( c3.getType() ) ) );
c2.setPrice( 3 );
workingMemory.modifyObject( h,
c2 );
- list = workingMemory.getObjects( c1.getType().getClass() );
- assertEquals( "remove of rule should remove one justification for c2 -> type",
+ list = workingMemory.getObjects( Person.class );
+ assertEquals( "c2 now has a higher price, its logical assertion should be cancelled",
1,
list.size() );
- assertFalse( "remove of rule should remove one justification for c2 -> type",
- list.contains( c2.getType() ) );
- assertTrue( "remove of rule should remove one justification for c2 -> type",
- list.contains( c1.getType() ) );
+ assertFalse( "The logical assertion cor c2 should have been retracted",
+ list.contains( new Person( c2.getType() ) ) );
+ assertTrue( "The logical assertion for c1 should exist",
+ list.contains( new Person( c1.getType() ) ) );
if ( reteooRuleBase != null ) {
reteooRuleBase.removeRule( ruleBase.getPackages()[1].getName(),
@@ -2642,7 +2647,7 @@
ruleBase.getPackages()[0].getRules().length );
assertEquals( 0,
ruleBase.getPackages()[1].getRules().length );
- list = workingMemory.getObjects( c1.getType().getClass() );
+ list = workingMemory.getObjects( Person.class );
assertEquals( 0,
list.size() );
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsDynamicRule.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsDynamicRule.drl 2006-10-24 15:34:08 UTC (rev 7088)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsDynamicRule.drl 2006-10-24 16:56:11 UTC (rev 7089)
@@ -1,11 +1,12 @@
package org.drools.test;
+import org.drools.Person;
import org.drools.Cheese;
rule "rule1"
when
- Cheese( type : type, price : price -> (price.intValue() > 1))
+ Cheese( type : type, price : price -> (price > 1))
#Cheese( type : type, price > 1 )
then
- assertLogical( type );
+ assertLogical( new Person( type ) );
end
Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsDynamicRule2.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsDynamicRule2.drl 2006-10-24 15:34:08 UTC (rev 7088)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsDynamicRule2.drl 2006-10-24 16:56:11 UTC (rev 7089)
@@ -1,11 +1,12 @@
package org.drools.test2;
+import org.drools.Person;
import org.drools.Cheese;
rule "rule2"
when
- Cheese( type : type, price : price -> (price.intValue() < 3))
+ Cheese( type : type, price : price -> (price < 3))
#Cheese( type : type, price < 3)
then
- assertLogical( type );
+ assertLogical( new Person( type ) );
end
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNotPingPong.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNotPingPong.drl 2006-10-24 15:34:08 UTC (rev 7088)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_LogicalAssertionsNotPingPong.drl 2006-10-24 16:56:11 UTC (rev 7089)
@@ -1,28 +1,28 @@
package org.drools.test;
-import java.lang.String;
-import java.lang.Integer;
import java.util.List;
+import org.drools.Person
+import org.drools.Cheese
-global java.lang.Integer i;
-global java.lang.String s;
-global java.util.List l;
+global Cheese cheese;
+global Person person;
+global java.util.List list;
-rule "not s then i"
+rule "not person then cheese"
when
- not String()
+ not Person()
then
- if (l.size() < 10) {
- l.add(new Integer(0));
- assertLogical(i);
+ if (list.size() < 10) {
+ list.add(new Integer(0));
+ assertLogical( cheese );
}
end
-rule "i then s"
+rule "if cheese then person"
when
- Integer()
+ Cheese()
then
- if (l.size() < 10) {
- l.add(new Integer(0));
- assertLogical(s);
+ if (list.size() < 10) {
+ list.add(new Integer(0));
+ assertLogical( person );
}
end
\ No newline at end of file
More information about the jboss-svn-commits
mailing list