use of org.drools.template.model.DRLOutput in project drools by kiegroup.
the class DefaultTemplateRuleBase method getDTRules.
/**
* @param templates
* @return
*/
private String getDTRules(Map<String, RuleTemplate> templates) {
org.drools.template.model.Package p = new org.drools.template.model.Package(DefaultTemplateRuleBase.class.getPackage().getName());
addImports(p);
addGlobals(p);
int i = 1;
for (RuleTemplate template : templates.values()) {
createTemplateRule(p, i++, template);
}
DRLOutput out = new DRLOutput();
p.renderDRL(out);
return out.getDRL();
}
use of org.drools.template.model.DRLOutput in project drools by kiegroup.
the class SpreadsheetCompiler method listenerToString.
public String listenerToString(RuleSheetListener listener) {
final Package rulePackage = listener.getRuleSet();
final DRLOutput out = new DRLOutput();
rulePackage.renderDRL(out);
return out.getDRL();
}
use of org.drools.template.model.DRLOutput in project drools by kiegroup.
the class RuleWorksheetParseTest method testNumericDisabled.
@Test
public void testNumericDisabled() throws Exception {
// DROOLS-1378
final InputStream stream = RuleWorksheetParseTest.class.getResourceAsStream("/data/NumericDisabled.xls");
final RuleSheetListener listener = getRuleSheetListener(stream);
final Package ruleset = listener.getRuleSet();
assertNotNull(ruleset);
DRLOutput dout = new DRLOutput();
ruleset.renderDRL(dout);
String drl = dout.getDRL();
System.out.println(drl);
// check rules
Rule rule = (Rule) ruleset.getRules().get(0);
Condition cond = (Condition) rule.getConditions().get(0);
assertEquals("Cheese(price == 6600)", cond.getSnippet());
}
use of org.drools.template.model.DRLOutput in project drools by kiegroup.
the class RuleWorksheetParseTest method testMissingCodeSnippetAction.
/**
* Must have a code snippet in an action.
*/
@Test
public void testMissingCodeSnippetAction() {
try {
makeRuleSet();
makeRuleTable();
makeRow(11, "C", "A");
makeRow(12, "foo: Foo", "Bar()");
makeRow(13, "attr == $param");
makeRow(15, "1", "1");
makeRow(16, "2", "2");
listener.finishSheet();
Package p = listener.getRuleSet();
DRLOutput dout = new DRLOutput();
p.renderDRL(dout);
String drl = dout.getDRL();
System.out.println(drl);
fail("should have failed");
} catch (DecisionTableParseException e) {
String badCell = RuleSheetParserUtil.rc2name(13, 2);
System.err.println(e.getMessage());
assertTrue(e.getMessage().contains(badCell));
}
}
use of org.drools.template.model.DRLOutput in project drools by kiegroup.
the class RuleWorksheetParseTest method testDuplicatePackageAttribute.
/**
* Duplicate package level attribute
*/
@Test
public void testDuplicatePackageAttribute() {
try {
makeRuleSet();
// B3, C3
makeAttribute("agenda-group", "agroup");
// B3. B4
makeAttribute("agenda-group", "bgroup");
makeRuleTable();
makeRow(11, "C", "A", "P");
makeRow(12, "Foo", "Foo");
makeRow(13, "attr == $param", "x");
makeRow(15, "1", "show()", "10");
listener.finishSheet();
Package p = listener.getRuleSet();
DRLOutput dout = new DRLOutput();
p.renderDRL(dout);
String drl = dout.getDRL();
// System.out.println( drl );
fail("should have failed");
} catch (DecisionTableParseException e) {
System.err.println(e.getMessage());
assertTrue(e.getMessage().contains("C3, C4"));
}
}
Aggregations