Created
November 15, 2010 12:31
-
-
Save leogomes/700306 to your computer and use it in GitHub Desktop.
MiscTest changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void testRuleRemovalWithJoinedRootPattern() { | |
String str = ""; | |
str += "package org.drools \n"; | |
str += "rule rule1 \n"; | |
str += "when \n"; | |
str += " String() \n"; | |
str += " Person() \n"; | |
str += "then \n"; | |
str += "end \n"; | |
str += "rule rule2 \n"; | |
str += "when \n"; | |
str += " String() \n"; | |
str += " Cheese() \n"; | |
str += "then \n"; | |
str += "end \n"; | |
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); | |
kbuilder.add( ResourceFactory.newByteArrayResource( str.getBytes() ), | |
ResourceType.DRL ); | |
if ( kbuilder.hasErrors() ) { | |
System.out.println( kbuilder.getErrors() ); | |
assertTrue( kbuilder.hasErrors() ); | |
} | |
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); | |
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() ); | |
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); | |
DefaultFactHandle stringHandle = (DefaultFactHandle) ksession.insert( "hello" ); | |
// Left side is initially unlinked, so the tuple wasn't generated. | |
assertNull( stringHandle.getFirstLeftTuple() ); | |
DefaultFactHandle personHandle = (DefaultFactHandle) ksession.insert( new Person() ); | |
LeftTuple stringLT = stringHandle.getFirstLeftTuple(); | |
// Now there should be a left tuple there. | |
assertNotNull(stringLT); | |
// I need a Cheese for this to be propagated | |
assertNull( stringLT.getLeftParentNext() ); | |
// Add the Cheese | |
DefaultFactHandle cheeseHandle = (DefaultFactHandle) ksession.insert( new Cheese() ); | |
// Now the tuple was propagated | |
assertNotNull( stringLT.getLeftParentNext() ); | |
// Removing the rule will remove the node and its tuples | |
kbase.removeRule( "org.drools", | |
"rule2" ); | |
// Now the second tuple for the string should have been removed. | |
assertNotNull( stringLT ); | |
assertNull( stringLT.getLeftParentNext() ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment