use of org.drools.compiler.lang.DrlDumper 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.compiler.lang.DrlDumper 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("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());
}
KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase(pkg));
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 = SerializationHelper.serializeObject(loadKnowledgeBaseFromString(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));
}
use of org.drools.compiler.lang.DrlDumper in project drools by kiegroup.
the class XmlPackageReaderTest method testParseRule.
@Test
public void testParseRule() throws Exception {
final XmlPackageReader xmlPackageReader = getXmReader();
xmlPackageReader.read(new InputStreamReader(getClass().getResourceAsStream("test_ParseRule.xml")));
final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
String expected = StringUtils.readFileAsString(new InputStreamReader(getClass().getResourceAsStream("test_ParseRule.drl")));
// remove license header as that one is not stored in the XML
String expectedWithoutHeader = removeLicenseHeader(expected);
System.out.println(expectedWithoutHeader);
String actual = new DrlDumper().dump(packageDescr);
Assertions.assertThat(expectedWithoutHeader).isEqualToIgnoringWhitespace(actual);
}
use of org.drools.compiler.lang.DrlDumper in project drools by kiegroup.
the class XmlPackageReaderTest method testParseLhs.
@Test
public void testParseLhs() throws Exception {
final XmlPackageReader xmlPackageReader = getXmReader();
xmlPackageReader.read(new InputStreamReader(getClass().getResourceAsStream("test_ParseLhs.xml")));
final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
String expected = StringUtils.readFileAsString(new InputStreamReader(getClass().getResourceAsStream("test_ParseLhs.drl")));
String expectedWithoutHeader = removeLicenseHeader(expected);
String actual = new DrlDumper().dump(packageDescr);
Assertions.assertThat(expectedWithoutHeader).isEqualToIgnoringWhitespace(actual);
}
use of org.drools.compiler.lang.DrlDumper 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);
}
Aggregations