use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class RHSTest method testRHSClone.
@Test
public void testRHSClone() {
// JBRULES-3539
final String str = "import java.util.Map;\n" + "dialect \"mvel\"\n" + "rule \"RHSClone\"\n" + "when\n" + " Map($valOne : this['keyOne'] !=null)\n" + "then\n" + " System.out.println( $valOne.clone() );\n" + "end\n";
final KnowledgeBuilderConfigurationImpl pkgBuilderCfg = new KnowledgeBuilderConfigurationImpl();
final MVELDialectConfiguration mvelConf = (MVELDialectConfiguration) pkgBuilderCfg.getDialectConfiguration("mvel");
mvelConf.setStrict(false);
mvelConf.setLangLevel(5);
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pkgBuilderCfg);
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
final KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (final KnowledgeBuilderError error : errors) {
System.err.println(error);
}
fail("Could not parse knowledge");
}
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class AddRemoveRulesTest method testAddRemoveDeletingFact.
@Test
public void testAddRemoveDeletingFact() {
// DROOLS-328
final String drl = "\n" + "rule B\n" + " when\n" + " Boolean()\n" + " Float()\n" + " then\n" + " end\n" + "\n" + "";
final KnowledgeBuilder kbuilder = TestUtil.createKnowledgeBuilder(null, drl);
final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
// Create kSession and initialize it
final KieSession kSession = kbase.newKieSession();
final FactHandle fh = kSession.insert(new Float(0.0f));
kSession.fireAllRules();
((InternalKnowledgeBase) kSession.getKieBase()).addPackages(kbuilder.getKnowledgePackages());
kSession.delete(fh);
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class AddRemoveRulesTest method loadRule.
private boolean loadRule(final String rule) {
String prefix = getPrefix();
prefix += rule;
final KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
builder.add(ResourceFactory.newReaderResource(new StringReader(prefix)), ResourceType.DRL);
final Collection<KiePackage> pkgs = this.buildKnowledge(builder);
this.addKnowledgeToBase(pkgs);
return true;
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class AddRemoveRulesTest method testAddRemoveWithPartialSharing.
@Test
public void testAddRemoveWithPartialSharing() {
final String drl = "package org.drools.test; \n" + "\n" + "declare A end \n" + "declare B end \n" + "declare C end \n" + "declare D end \n" + "" + "rule Init \n" + " when\n" + " then\n" + " insert( new A() ); \n" + " insert( new B() ); \n" + " end\n" + "" + "rule One\n" + " when\n" + " A()\n" + " B()\n" + " C()\n" + " then\n" + " end\n" + "\n" + "rule Two\n" + " when\n" + " A()\n" + " B()\n" + " D()\n" + " then\n" + " end\n" + "\n" + "";
final KnowledgeBuilder kbuilder = TestUtil.createKnowledgeBuilder(null, drl);
final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
// Create kSession and initialize it
final KieSession kSession = kbase.newKieSession();
kSession.fireAllRules();
kSession.getKieBase().removeRule("org.drools.test", "Two");
kSession.fireAllRules();
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class QueryTest3 method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
String text = "";
text += "package org.drools.integrationtests\n";
text += "import " + QueryTest3.Bar.class.getCanonicalName() + "\n";
text += "import " + QueryTest3.Foo.class.getCanonicalName() + "\n";
text += "import " + QueryTest3.Foo2.class.getCanonicalName() + "\n";
text += "query \"testDifferent\"\n";
text += " foo : Foo();\n";
text += " bar : Bar(id == foo.id)\n";
text += "end\n";
text += "query \"testSame\"\n";
text += " foo : Foo();\n";
text += " foo2 : Foo(id == foo.id);\n";
text += "end\n";
text += "query \"testExtends\"\n";
text += " foo : Foo();\n";
text += " foo2 : Foo2(id == foo.id);\n";
text += "end\n";
KnowledgeBuilder knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
knowledgeBuilder.add(ResourceFactory.newByteArrayResource(text.getBytes()), ResourceType.DRL);
assertFalse(knowledgeBuilder.hasErrors());
knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowledgeBase.addPackages(knowledgeBuilder.getKnowledgePackages());
}
Aggregations