use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class SessionInspectorTest method testGetSessionInfo.
@Test
public void testGetSessionInfo() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_SubNetworks.drl"), ResourceType.DRL);
kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_AccumulateWithFromChaining.drl"), ResourceType.DRL);
kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_CollectResultsBetaConstraint.drl"), ResourceType.DRL);
kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_QueryMemoryLeak.drl"), ResourceType.DRL);
assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = createKnowledgeSession(kbase);
ksession.setGlobal("results", new ArrayList<Object>());
ksession.insert(new Dimension(100, 50));
ksession.insert(new Dimension(130, 80));
ksession.insert(new Dimension(50, 40));
ksession.insert(new Dimension(50, 40));
Cheesery cheesery = new Cheesery();
cheesery.addCheese(new Cheese("brie", 10));
cheesery.addCheese(new Cheese("brie", 10));
cheesery.addCheese(new Cheese("brie", 10));
cheesery.addCheese(new Cheese("brie", 10));
cheesery.addCheese(new Cheese("muzzarella", 10));
cheesery.addCheese(new Cheese("muzzarella", 10));
cheesery.addCheese(new Cheese("muzzarella", 10));
cheesery.addCheese(new Cheese("muzzarella", 10));
cheesery.addCheese(new Cheese("muzzarella", 10));
cheesery.addCheese(new Cheese("muzzarella", 10));
cheesery.addCheese(new Cheese("muzzarella", 10));
cheesery.addCheese(new Cheese("stilton", 10));
cheesery.addCheese(new Cheese("stilton", 10));
cheesery.addCheese(new Cheese("stilton", 10));
cheesery.addCheese(new Cheese("stilton", 10));
cheesery.addCheese(new Cheese("stilton", 10));
cheesery.addCheese(new Cheese("stilton", 10));
cheesery.addCheese(new Cheese("stilton", 10));
ksession.insert(cheesery);
ksession.insert(new Person("Bob", "muzzarella"));
ksession.insert(new Person("Mark", "brie"));
ksession.insert(new Cheese("brie", 10));
ksession.insert(new Cheese("brie", 10));
ksession.insert(new Cheese("brie", 10));
ksession.insert(new Cheese("brie", 10));
ksession.insert(new Cheese("muzzarella", 10));
ksession.insert(new Cheese("muzzarella", 10));
ksession.insert(new Cheese("muzzarella", 10));
ksession.insert(new Cheese("muzzarella", 10));
ksession.insert(new Cheese("Stilton", 10));
ksession.insert(new Cheese("Stilton", 10));
ksession.insert(new Cheese("Stilton", 10));
ksession.insert(new Double(10));
ksession.insert(new Double(11));
ksession.insert(new Double(12));
ksession.insert(new Double(13));
ksession.insert(new Double(14));
ksession.insert(new Integer(15));
ksession.insert(new Integer(16));
ksession.insert(new Integer(17));
ksession.insert(new Integer(18));
FactHandle handle = ksession.insert(new Worker());
ksession.retract(handle);
SessionInspector inspector = new SessionInspector(ksession);
StatefulKnowledgeSessionInfo info = inspector.getSessionInfo();
String report = SessionReporter.generateReport("simple", info, null);
assertNotNull(report);
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class AddRuleTest method buildKnowledgeBase.
private InternalKnowledgeBase buildKnowledgeBase(String ruleName, String rule) {
String str = "";
str += "package org.kie \n";
str += "import " + A.class.getCanonicalName() + "\n";
str += "import " + B.class.getCanonicalName() + "\n";
str += "import " + C.class.getCanonicalName() + "\n";
str += "import " + D.class.getCanonicalName() + "\n";
str += "import " + E.class.getCanonicalName() + "\n";
str += "global java.util.List list \n";
int i = 0;
str += "rule " + ruleName + " when \n";
str += rule;
str += "then \n";
str += " list.add( kcontext.getMatch() );\n";
str += "end \n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
return kbase;
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class AddRuleTest method buildKnowledgePackage.
private Collection<KiePackage> buildKnowledgePackage(String ruleName, String rule) {
String str = "";
str += "package org.kie \n";
str += "import " + A.class.getCanonicalName() + "\n";
str += "import " + B.class.getCanonicalName() + "\n";
str += "import " + C.class.getCanonicalName() + "\n";
str += "import " + D.class.getCanonicalName() + "\n";
str += "import " + E.class.getCanonicalName() + "\n";
str += "global java.util.List list \n";
int i = 0;
str += "rule " + ruleName + " when \n";
str += rule;
str += "then \n";
str += " list.add( kcontext.getMatch() );\n";
str += "end \n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
return kbuilder.getKnowledgePackages();
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class PhreakLiaNodeTest method test.
@Test
public void test() {
String str = "package org.drools.compiler.test\n" + "\n" + "import " + A.class.getCanonicalName() + "\n" + "import " + B.class.getCanonicalName() + "\n" + "\n" + "rule r1 \n" + " when \n" + " $a : A( object == 1 )\n" + " then \n" + " System.out.println( $a ); \n" + "end \n" + "rule r2 \n" + " when \n" + " $a : A( object == 2 )\n" + " then \n" + " System.out.println( $a ); \n" + "end \n " + "rule r3 \n" + " when \n" + " $a : A( object == 2 )\n" + " $b : B( )\n" + " then \n" + " System.out.println( $a ); \n" + "end \n " + "rule r4 \n" + " when \n" + " $a : A( object == 3 )\n" + " then \n" + " System.out.println( $a ); \n" + "end \n";
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
builder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
if (builder.hasErrors()) {
throw new RuntimeException(builder.getErrors().toString());
}
InternalKnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowledgeBase.addPackages(builder.getKnowledgePackages());
KieSession ksession = knowledgeBase.newKieSession();
InternalFactHandle fhB = (InternalFactHandle) ksession.insert(B.b(1));
InternalFactHandle fhA = (InternalFactHandle) ksession.insert(A.a(1));
ksession.fireAllRules();
System.out.println("---1---");
// ksession.update( fhA, a(1) );
// ksession.fireAllRules();
// System.out.println( "---2---" );
//
ksession.update(fhA, A.a(2));
ksession.fireAllRules();
System.out.println("---3---");
ksession.update(fhA, A.a(2));
ksession.fireAllRules();
System.out.println("---4---");
ksession.update(fhA, A.a(3));
ksession.fireAllRules();
System.out.println("---5---");
ksession.update(fhB, B.b(1));
ksession.update(fhA, A.a(3));
ksession.fireAllRules();
// ksession.update( fhA, a(1) );
// ksession.fireAllRules();
//
// ksession.update( fhA, a(1) );
// ksession.fireAllRules();
ksession.dispose();
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class RemoveRuleTest method buildKnowledgeBase.
private InternalKnowledgeBase buildKnowledgeBase(String ruleName, String rule) {
String str = "";
str += "package org.kie \n";
str += "import " + A.class.getCanonicalName() + "\n";
str += "import " + B.class.getCanonicalName() + "\n";
str += "import " + C.class.getCanonicalName() + "\n";
str += "import " + D.class.getCanonicalName() + "\n";
str += "import " + E.class.getCanonicalName() + "\n";
str += "global java.util.List list \n";
int i = 0;
str += "rule " + ruleName + " when \n";
str += rule;
str += "then \n";
str += " list.add( kcontext.getMatch() );\n";
str += "end \n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
return kbase;
}
Aggregations