use of org.jbpm.compiler.xml.compiler.XmlPackageReader in project kogito-runtimes 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);
assertThat(expectedWithoutHeader).isEqualToIgnoringWhitespace(actual);
}
use of org.jbpm.compiler.xml.compiler.XmlPackageReader in project kogito-runtimes 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();
assertThat(packageDescr).isNotNull();
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.jbpm.compiler.xml.compiler.XmlPackageReader in project kogito-runtimes by kiegroup.
the class XmlPackageReaderTest method testParseFrom.
@Test
public void testParseFrom() throws Exception {
final XmlPackageReader xmlPackageReader = getXmReader();
xmlPackageReader.read(new InputStreamReader(getClass().getResourceAsStream("test_ParseFrom.xml")));
final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
assertThat(packageDescr).isNotNull();
RuleDescr obj = packageDescr.getRules().get(0);
PatternDescr patterndescr = (PatternDescr) obj.getLhs().getDescrs().get(0);
FromDescr from = (FromDescr) patterndescr.getSource();
MVELExprDescr accessordescriptor = (MVELExprDescr) from.getDataSource();
assertEquals("cheesery.getCheeses(i+4)", accessordescriptor.getExpression());
assertEquals(patterndescr.getObjectType(), "Cheese");
assertEquals(patterndescr.getIdentifier(), "cheese");
}
use of org.jbpm.compiler.xml.compiler.XmlPackageReader in project kogito-runtimes by kiegroup.
the class XmlPackageReaderTest method testParseImport.
@Test
public void testParseImport() throws Exception {
final XmlPackageReader xmlPackageReader = getXmReader();
xmlPackageReader.read(new InputStreamReader(getClass().getResourceAsStream("test_ParseImport.xml")));
final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
assertThat(packageDescr).isNotNull();
assertEquals("com.sample", packageDescr.getName());
final List imports = packageDescr.getImports();
assertEquals(2, imports.size());
assertEquals("java.util.HashMap", ((ImportDescr) imports.get(0)).getTarget());
assertEquals("org.drools.mvel.compiler.*", ((ImportDescr) imports.get(1)).getTarget());
final List functionImport = packageDescr.getFunctionImports();
assertEquals("org.drools.function", ((FunctionImportDescr) functionImport.get(0)).getTarget());
}
use of org.jbpm.compiler.xml.compiler.XmlPackageReader in project kogito-runtimes 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);
assertThat(expectedWithoutHeader).isEqualToIgnoringWhitespace(actual);
}
Aggregations