use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class StrEvaluatorTest method readKnowledgeBase.
private KieBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newInputStreamResource(getClass().getResourceAsStream("strevaluator_test.drl")), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge." + errors.toArray());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
return kbase;
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class SwitchOverStringTest method testShouldFailToCompileSwitchOverStringWithLngLevel16.
@Test
public void testShouldFailToCompileSwitchOverStringWithLngLevel16() {
System.setProperty("drools.dialect.java.compiler.lnglevel", "1.6");
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(FUNCTION_WITH_SWITCH_OVER_STRING.getBytes()), ResourceType.DRL);
Assert.assertTrue("Compilation error(s) expected!", kbuilder.hasErrors());
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class TimerAndCalendarTest method wrongTimerExpression.
private void wrongTimerExpression(String timer) {
String str = "";
str += "package org.simple \n";
str += "rule xxx \n";
str += " timer (" + timer + ") ";
str += "when \n";
str += "then \n";
str += "end \n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertTrue(kbuilder.hasErrors());
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class StatelessSessionTest method getSession2.
private StatelessKieSession getSession2(final Resource resource) throws Exception {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(resource, ResourceType.DRL);
if (kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors());
}
assertFalse(kbuilder.hasErrors());
final Collection<KiePackage> pkgs = kbuilder.getKnowledgePackages();
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(pkgs);
kbase = SerializationHelper.serializeObject(kbase);
final StatelessKieSession session = kbase.newStatelessKieSession();
session.setGlobal("list", this.list);
session.setGlobal("cheesery", this.cheesery);
return session;
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class PatternTest method testCheckDuplicateVariables.
@Test
public void testCheckDuplicateVariables() throws Exception {
// JBRULES-3035
String str = "package com.sample\n" + "import org.drools.compiler.*\n" + "rule R1 when\n" + " Person( $a: age, $a: name ) // this should cause a compile-time error\n" + "then\n" + "end";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertTrue(kbuilder.hasErrors());
str = "package com.sample\n" + "rule R1 when\n" + " accumulate( Object(), $c: count(1), $c: max(1) ) // this should cause a compile-time error\n" + "then\n" + "end";
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertTrue(kbuilder.hasErrors());
str = "package com.sample\n" + "rule R1 when\n" + " Number($i: intValue) from accumulate( Object(), $i: count(1) ) // this should cause a compile-time error\n" + "then\n" + "end";
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertTrue(kbuilder.hasErrors());
}
Aggregations