use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class DumperTestHelper method dump.
public static String dump(String filename) throws Exception {
DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
final PackageDescr pkgOriginal = parser.parse(new InputStreamReader(DumperTestHelper.class.getResourceAsStream(filename)));
final DrlDumper dumper = new DrlDumper();
return dumper.dump(pkgOriginal);
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class DumperTestHelper method DrlFile.
public static void DrlFile(String filename) throws Exception {
DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
final PackageDescr pkgOriginal = parser.parse(new InputStreamReader(DumperTestHelper.class.getResourceAsStream(filename)));
final DrlDumper dumper = new DrlDumper();
String result1 = dumper.dump(pkgOriginal);
final PackageDescr pkgDerivated = parser.parse(new StringReader(result1));
String result2 = dumper.dump(pkgDerivated);
System.out.println(result1);
Assertions.assertThat(result1).isEqualToIgnoringWhitespace(result2);
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class DumperTest method checkRoundtrip.
private void checkRoundtrip(String drl) throws DroolsParserException {
DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
final PackageDescr pkgOriginal = parser.parse(false, drl);
final DrlDumper dumper = new DrlDumper();
String out = dumper.dump(pkgOriginal);
Assertions.assertThat(drl).isEqualToIgnoringWhitespace(out);
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class DrlParserTest method testExpandDRLUsingInjectedExpander.
@Test
public void testExpandDRLUsingInjectedExpander() throws Exception {
String dsl = "[condition]Something=Something()" + NL + "[then]another=another();";
String drl = "rule 'foo' " + NL + " when " + NL + " Something " + NL + " then " + NL + " another " + NL + "end";
DefaultExpanderResolver resolver = new DefaultExpanderResolver(new StringReader(dsl));
final DSLMappingFile file = new DSLTokenizedMappingFile();
if (file.parseAndLoad(new StringReader(dsl))) {
final Expander expander = new DefaultExpander();
expander.addDSLMapping(file.getMapping());
resolver.addExpander("*", expander);
} else {
throw new RuntimeException("Error parsing and loading DSL file." + file.getErrors());
}
DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
String result = parser.getExpandedDRL(drl, resolver);
Assertions.assertThat("rule 'foo' " + NL + " when " + NL + " Something() " + NL + " then " + NL + " another(); " + NL + "end").isEqualToIgnoringWhitespace(result);
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class DrlParserTest method testExpandDRL.
@Test
public void testExpandDRL() throws Exception {
String dsl = "[condition]Something=Something()" + NL + "[then]another=another();";
String drl = "rule 'foo' " + NL + " when " + NL + " Something " + NL + " then " + NL + " another " + NL + "end";
DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
String result = parser.getExpandedDRL(drl, new StringReader(dsl));
Assertions.assertThat("rule 'foo' " + NL + " when " + NL + " Something() " + NL + " then " + NL + " another(); " + NL + "end").isEqualToIgnoringWhitespace(result);
}
Aggregations