Skip to content

Commit

Permalink
-Moved test to differnet file
Browse files Browse the repository at this point in the history
-Corrected type in droolsmessage.proto
-creted typo in KProjectTest
  • Loading branch information
Mark Proctor committed Nov 7, 2012
1 parent 9c85d54 commit 4f79a5c
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.drools.CommonTestMethodBase;
import org.drools.FactA;
import org.drools.FactHandle;
import org.drools.Father;
import org.drools.Foo;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
Expand All @@ -24,6 +25,7 @@
import org.drools.Pet;
import org.drools.RuleBase;
import org.drools.StatefulSession;
import org.drools.TotalHolder;
import org.drools.WorkingMemory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
Expand All @@ -45,6 +47,7 @@
import org.drools.spi.Activation;
import org.drools.spi.ActivationGroup;
import org.drools.spi.AgendaGroup;
import org.junit.Ignore;
import org.junit.Test;

public class ExecutionFlowControlTest extends CommonTestMethodBase {
Expand Down Expand Up @@ -720,6 +723,76 @@ public void testActivationGroups() throws Exception {
assertEquals( "rule2", list.get( 1 ) );

}

@Test
@Ignore("FIXME for Planner")
public void testUnMatchListenerForChainedPlanningEntities() {
String str =""+
"package org.drools.test;\n" +
"\n" +
"import org.drools.Father;\n" +
"import org.drools.TotalHolder;\n" +
"\n" +
"global TotalHolder totalHolder;\n" +
"\n" +
"rule \"sumWeightOfFather\"\n" +
"when\n" +
" $h: Father(father != null, $wf : weightOfFather)\n" +
"then\n" +
" totalHolder.add($wf);\n" +
" System.out.println(\"match \" + totalHolder.getTotal());\n" +
" final TotalHolder finalTotalHolder = totalHolder;\n" +
" final int finalWf = $wf;\n" +
" org.drools.common.AgendaItem agendaItem = (org.drools.common.AgendaItem) kcontext.getActivation();" +
" agendaItem.setActivationUnMatchListener(new org.drools.event.rule.ActivationUnMatchListener() {" +
" public void unMatch(org.drools.runtime.rule.WorkingMemory workingMemory, org.drools.runtime.rule.Activation activation) {" +
" finalTotalHolder.subtract(finalWf);" +
" System.out.println(\"unmatch \" + finalTotalHolder.getTotal());\n" +
" }" +
" });" +
"end";

KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newByteArrayResource(str.getBytes()),
ResourceType.DRL );
assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession kSession = createKnowledgeSession(kbase);

kSession.setGlobal("totalHolder", new TotalHolder());
Father abraham = new Father("abraham", null, 100);
Father homer = new Father("homer", null, 20);
Father bart = new Father("bart", null, 3);

org.drools.runtime.rule.FactHandle abrahamHandle = kSession.insert(abraham);
org.drools.runtime.rule.FactHandle bartHandle = kSession.insert(bart);
kSession.fireAllRules();
assertEquals(0, ((TotalHolder) kSession.getGlobal("totalHolder")).getTotal());

bart.setFather(abraham);
kSession.update(bartHandle, bart);
kSession.fireAllRules();
assertEquals(100, ((TotalHolder) kSession.getGlobal("totalHolder")).getTotal());

bart.setFather(null);
kSession.update(bartHandle, bart);
kSession.fireAllRules();
assertEquals(0, ((TotalHolder) kSession.getGlobal("totalHolder")).getTotal());

bart.setFather(abraham);
kSession.update(bartHandle, bart);
kSession.fireAllRules();
assertEquals(100, ((TotalHolder) kSession.getGlobal("totalHolder")).getTotal());

org.drools.runtime.rule.FactHandle homerHandle = kSession.insert(homer);
homer.setFather(abraham);
kSession.update(homerHandle, homer);
bart.setFather(homer);
kSession.update(bartHandle, bart);
kSession.fireAllRules();
assertEquals(120, ((TotalHolder) kSession.getGlobal("totalHolder")).getTotal());
}

public static class Holder {
private Integer val;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1164,76 +1164,6 @@ public void testTMSWithLateUpdate() {

//System.err.println(reportWMObjects(kSession));
}

@Test
@Ignore("FIXME for Planner")
public void testUnMatchListenerForChainedPlanningEntities() {
String str =""+
"package org.drools.test;\n" +
"\n" +
"import org.drools.Father;\n" +
"import org.drools.TotalHolder;\n" +
"\n" +
"global TotalHolder totalHolder;\n" +
"\n" +
"rule \"sumWeightOfFather\"\n" +
"when\n" +
" $h: Father(father != null, $wf : weightOfFather)\n" +
"then\n" +
" totalHolder.add($wf);\n" +
" System.out.println(\"match \" + totalHolder.getTotal());\n" +
" final TotalHolder finalTotalHolder = totalHolder;\n" +
" final int finalWf = $wf;\n" +
" org.drools.common.AgendaItem agendaItem = (org.drools.common.AgendaItem) kcontext.getActivation();" +
" agendaItem.setActivationUnMatchListener(new org.drools.event.rule.ActivationUnMatchListener() {" +
" public void unMatch(org.drools.runtime.rule.WorkingMemory workingMemory, org.drools.runtime.rule.Activation activation) {" +
" finalTotalHolder.subtract(finalWf);" +
" System.out.println(\"unmatch \" + finalTotalHolder.getTotal());\n" +
" }" +
" });" +
"end";

KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newByteArrayResource(str.getBytes()),
ResourceType.DRL );
assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession kSession = createKnowledgeSession(kbase);

kSession.setGlobal("totalHolder", new TotalHolder());
Father abraham = new Father("abraham", null, 100);
Father homer = new Father("homer", null, 20);
Father bart = new Father("bart", null, 3);

FactHandle abrahamHandle = kSession.insert(abraham);
FactHandle bartHandle = kSession.insert(bart);
kSession.fireAllRules();
assertEquals(0, ((TotalHolder) kSession.getGlobal("totalHolder")).getTotal());

bart.setFather(abraham);
kSession.update(bartHandle, bart);
kSession.fireAllRules();
assertEquals(100, ((TotalHolder) kSession.getGlobal("totalHolder")).getTotal());

bart.setFather(null);
kSession.update(bartHandle, bart);
kSession.fireAllRules();
assertEquals(0, ((TotalHolder) kSession.getGlobal("totalHolder")).getTotal());

bart.setFather(abraham);
kSession.update(bartHandle, bart);
kSession.fireAllRules();
assertEquals(100, ((TotalHolder) kSession.getGlobal("totalHolder")).getTotal());

FactHandle homerHandle = kSession.insert(homer);
homer.setFather(abraham);
kSession.update(homerHandle, homer);
bart.setFather(homer);
kSession.update(bartHandle, bart);
kSession.fireAllRules();
assertEquals(120, ((TotalHolder) kSession.getGlobal("totalHolder")).getTotal());
}

@Test
public void testTMSAdditionalValueArgument() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.jboss.weld.resources.spi.ResourceLoader;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import com.thoughtworks.xstream.XStream;
Expand Down Expand Up @@ -93,8 +92,7 @@ public String value() {
}

@Test
@Ignore
public void treatCreateMultpleJarAndFileResources() throws IOException,
public void ctreatCreateMultpleJarAndFileResources() throws IOException,
ClassNotFoundException,
InterruptedException {
createKProjectJar( "jar1", true );
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ message ActionQueue {
message LogicalRetract {
optional int32 handle_id = 1;
optional Activation activation = 2;
optional bool fullyRetract = 3;
optional bool fully_retract = 3;
optional bool update = 4;

}
Expand Down
Loading

0 comments on commit 4f79a5c

Please sign in to comment.