use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class XmlPackageReaderTest method testParseForall.
@Test
public void testParseForall() throws Exception {
final XmlPackageReader xmlPackageReader = getXmReader();
xmlPackageReader.read(new InputStreamReader(getClass().getResourceAsStream("test_ParseForall.xml")));
final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
assertNotNull(packageDescr);
RuleDescr obj = (RuleDescr) packageDescr.getRules().get(0);
ForallDescr forall = (ForallDescr) obj.getLhs().getDescrs().get(0);
List forallPaterns = forall.getDescrs();
PatternDescr pattarnState = (PatternDescr) forallPaterns.get(0);
PatternDescr personState = (PatternDescr) forallPaterns.get(1);
PatternDescr cheeseState = (PatternDescr) forallPaterns.get(2);
assertEquals(pattarnState.getObjectType(), "State");
assertEquals(personState.getObjectType(), "Person");
assertEquals(cheeseState.getObjectType(), "Cheese");
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class XmlPackageReaderTest method testAccumulate.
@Test
public void testAccumulate() throws Exception {
final XmlPackageReader xmlPackageReader = getXmReader();
xmlPackageReader.read(new InputStreamReader(getClass().getResourceAsStream("test_ParseAccumulate.xml")));
final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
assertNotNull(packageDescr);
RuleDescr obj = (RuleDescr) packageDescr.getRules().get(0);
Object patternobj = obj.getLhs().getDescrs().get(0);
assertTrue(patternobj instanceof PatternDescr);
final PatternDescr patterncheese = (PatternDescr) patternobj;
assertEquals(patterncheese.getIdentifier(), "cheese");
assertEquals(patterncheese.getObjectType(), "Cheese");
AccumulateDescr accumulatedescr = (AccumulateDescr) patterncheese.getSource();
assertEquals("total += $cheese.getPrice();", accumulatedescr.getActionCode());
assertEquals("int total = 0;", accumulatedescr.getInitCode());
assertEquals("new Integer( total ) );", accumulatedescr.getResultCode());
patternobj = obj.getLhs().getDescrs().get(1);
assertTrue(patternobj instanceof PatternDescr);
final PatternDescr patternmax = (PatternDescr) patternobj;
assertEquals(patternmax.getIdentifier(), "max");
assertEquals(patternmax.getObjectType(), "Number");
accumulatedescr = (AccumulateDescr) patternmax.getSource();
assertTrue(accumulatedescr.isExternalFunction());
assertEquals("max", accumulatedescr.getFunctions().get(0).getFunction());
assertNull(accumulatedescr.getInitCode());
assertNull(accumulatedescr.getActionCode());
assertNull(accumulatedescr.getResultCode());
assertNull(accumulatedescr.getReverseCode());
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class XmlPackageReaderTest method testParsePackageName.
@Test
public void testParsePackageName() throws Exception {
final XmlPackageReader xmlPackageReader = getXmReader();
xmlPackageReader.read(new InputStreamReader(getClass().getResourceAsStream("test_ParsePackageName.xml")));
final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
assertNotNull(packageDescr);
assertEquals("com.sample", packageDescr.getName());
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class XmlPackageReaderTest method testParseCollect.
@Test
public void testParseCollect() throws Exception {
final XmlPackageReader xmlPackageReader = getXmReader();
xmlPackageReader.read(new InputStreamReader(getClass().getResourceAsStream("test_ParseCollect.xml")));
final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
String expected = StringUtils.readFileAsString(new InputStreamReader(getClass().getResourceAsStream("test_ParseCollect.drl")));
String expectedWithoutHeader = removeLicenseHeader(expected);
String actual = new DrlDumper().dump(packageDescr);
Assertions.assertThat(expectedWithoutHeader).isEqualToIgnoringWhitespace(actual);
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class DumperTestHelper method XmlFile.
public static void XmlFile(String filename) throws Exception {
KnowledgeBuilderConfigurationImpl conf = new KnowledgeBuilderConfigurationImpl();
XmlPackageReader xmlPackageReader = new XmlPackageReader(conf.getSemanticModules());
xmlPackageReader.getParser().setClassLoader(DumperTestHelper.class.getClassLoader());
xmlPackageReader.read(new InputStreamReader(DumperTestHelper.class.getResourceAsStream(filename)));
final PackageDescr pkgOriginal = xmlPackageReader.getPackageDescr();
final XmlDumper dumper = new XmlDumper();
final String result = dumper.dump(pkgOriginal);
String buffer = readFile(filename);
System.out.println(buffer);
System.out.println(result);
Assertions.assertThat(buffer).isEqualToIgnoringWhitespace(result);
assertNotNull(result);
}
Aggregations