use of org.drools.drl.parser.DroolsError in project drools by kiegroup.
the class PackageBuilderErrors method readExternal.
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
SerializableDroolsError[] temp = (SerializableDroolsError[]) in.readObject();
this.errors = temp;
for (DroolsError error : temp) {
add(error);
}
}
use of org.drools.drl.parser.DroolsError in project drools by kiegroup.
the class RuleBuilder method registerError.
private static void registerError(String error, RuleImpl rule, RuleBuildContext context) {
DroolsError err = new RuleBuildError(rule, context.getParentDescr(), null, error);
context.addError(err);
}
use of org.drools.drl.parser.DroolsError in project drools by kiegroup.
the class DRLDumperTest method testDumpers.
@Test
public void testDumpers() throws Exception {
final DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
final Resource resource = new InputStreamResource(getClass().getResourceAsStream("drl/test_Dumpers.drl"));
final PackageDescr pkg = parser.parse(resource);
if (parser.hasErrors()) {
for (final DroolsError error : parser.getErrors()) {
logger.warn(error.toString());
}
fail(parser.getErrors().toString());
}
final Resource descrResource = KieServices.Factory.get().getResources().newDescrResource(pkg);
descrResource.setSourcePath(TestConstants.TEST_RESOURCES_FOLDER + "test_Dumpers.descr");
KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, descrResource);
KieSession ksession = kbase.newKieSession();
List list = new ArrayList();
ksession.setGlobal("list", list);
final Cheese brie = new Cheese("brie", 12);
ksession.insert(brie);
ksession.fireAllRules();
assertEquals(3, list.size());
assertEquals("3 1", list.get(0));
assertEquals("MAIN", list.get(1));
assertEquals("1 1", list.get(2));
// ---------------------------
final DrlDumper drlDumper = new DrlDumper();
final String drlResult = drlDumper.dump(pkg);
System.out.println(drlResult);
kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drlResult);
ksession = kbase.newKieSession();
list = new ArrayList();
ksession.setGlobal("list", list);
ksession.insert(brie);
ksession.fireAllRules();
assertEquals(3, list.size());
assertEquals("3 1", list.get(0));
assertEquals("MAIN", list.get(1));
assertEquals("1 1", list.get(2));
}
Aggregations