Search in sources :

Example 1 with DRLOutput

use of org.drools.template.model.DRLOutput in project drools by kiegroup.

the class RuleWorksheetParseTest method testQuoteEscapingDisabled.

@Test
public void testQuoteEscapingDisabled() throws Exception {
    final InputStream stream = RuleWorksheetParseTest.class.getResourceAsStream("/data/QuoteEscapeDisabledWorkbook.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("Foo(myObject.getColour().equals(red), myObject.size () > \"12\")", cond.getSnippet());
    rule = ruleset.getRules().get(1);
    cond = rule.getConditions().get(0);
    assertEquals("Foo(myObject.getColour().equals(blue), myObject.size () > 12\")", cond.getSnippet());
}
Also used : Condition(org.drools.template.model.Condition) DRLOutput(org.drools.template.model.DRLOutput) InputStream(java.io.InputStream) Package(org.drools.template.model.Package) Rule(org.drools.template.model.Rule) Test(org.junit.Test)

Example 2 with DRLOutput

use of org.drools.template.model.DRLOutput in project drools by kiegroup.

the class RuleWorksheetParseTest method testSalienceRange.

@Test
public void testSalienceRange() throws Exception {
    // DROOLS-1225
    final InputStream stream = RuleWorksheetParseTest.class.getResourceAsStream("/data/SalienceRangeWorkbook.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
    List<Rule> rules = ruleset.getRules();
    assertEquals("10000", rules.get(0).getSalience());
    assertEquals("9999", rules.get(1).getSalience());
}
Also used : DRLOutput(org.drools.template.model.DRLOutput) InputStream(java.io.InputStream) Package(org.drools.template.model.Package) Rule(org.drools.template.model.Rule) Test(org.junit.Test)

Example 3 with DRLOutput

use of org.drools.template.model.DRLOutput in project drools by kiegroup.

the class RuleWorksheetParseTest method testQuoteEscapingEnabled.

@Test
public void testQuoteEscapingEnabled() throws Exception {
    final InputStream stream = RuleWorksheetParseTest.class.getResourceAsStream("/data/QuoteEscapeEnabledWorkbook.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 = ruleset.getRules().get(0);
    Condition cond = rule.getConditions().get(0);
    assertEquals("Foo(myObject.getColour().equals(red), myObject.size () > 12\\\")", cond.getSnippet());
}
Also used : Condition(org.drools.template.model.Condition) DRLOutput(org.drools.template.model.DRLOutput) InputStream(java.io.InputStream) Package(org.drools.template.model.Package) Rule(org.drools.template.model.Rule) Test(org.junit.Test)

Example 4 with DRLOutput

use of org.drools.template.model.DRLOutput in project drools by kiegroup.

the class RuleWorksheetParseTest method testRuleAttributeRendering.

/**
 * Check correct rendering of string-valued attribute
 */
@Test
public void testRuleAttributeRendering() {
    makeRuleSet();
    makeRuleTable();
    makeRow(11, "C", "A", "G");
    makeRow(12, "Foo", "Foo");
    makeRow(13, "attr == $param", "x");
    makeRow(15, "1", "show()", "foo bar");
    makeRow(16, "2", "list()", "\"10\" group\"");
    listener.finishSheet();
    Package p = listener.getRuleSet();
    DRLOutput dout = new DRLOutput();
    p.renderDRL(dout);
    String drl = dout.getDRL();
    // System.out.println( drl );
    assertTrue(drl.contains("agenda-group \"foo bar\""));
    assertTrue(drl.contains("agenda-group \"10\\\" group\""));
}
Also used : DRLOutput(org.drools.template.model.DRLOutput) Package(org.drools.template.model.Package) Test(org.junit.Test)

Example 5 with DRLOutput

use of org.drools.template.model.DRLOutput in project drools by kiegroup.

the class TemplateDataListener method renderDRL.

public String renderDRL() {
    DRLOutput out = new DRLOutput();
    out.writeLine(templateContainer.getHeader());
    out.writeLine(generator.getDrl());
    // System.err.println(out.getDRL());
    return out.getDRL();
}
Also used : DRLOutput(org.drools.template.model.DRLOutput)

Aggregations

DRLOutput (org.drools.template.model.DRLOutput)12 Package (org.drools.template.model.Package)10 Test (org.junit.Test)9 InputStream (java.io.InputStream)4 Rule (org.drools.template.model.Rule)4 Condition (org.drools.template.model.Condition)3 DecisionTableParseException (org.drools.template.parser.DecisionTableParseException)2 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1