Search in sources :

Example 11 with Package

use of org.drools.template.model.Package 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));
    }
}
Also used : DRLOutput(org.drools.template.model.DRLOutput) DecisionTableParseException(org.drools.template.parser.DecisionTableParseException) Package(org.drools.template.model.Package) Test(org.junit.Test)

Example 12 with Package

use of org.drools.template.model.Package 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"));
    }
}
Also used : DRLOutput(org.drools.template.model.DRLOutput) DecisionTableParseException(org.drools.template.parser.DecisionTableParseException) Package(org.drools.template.model.Package) Test(org.junit.Test)

Example 13 with Package

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

the class RuleWorksheetParseTest method testMetadata.

@Test
public void testMetadata() {
    makeRuleSet();
    makeRuleTable();
    makeRow(11, "C", "A", "@", "@");
    makeRow(12, "foo: Foo", "foo");
    makeRow(13, "attr == $param", "goaway($param)", "Author($param)", "Version($1-$2)");
    makeRow(15, "1", "1", "J.W.Goethe", "3,14");
    makeRow(16, "2", "2", "", "");
    listener.finishSheet();
    Package p = listener.getRuleSet();
    DRLOutput dout = new DRLOutput();
    p.renderDRL(dout);
    String drl = dout.getDRL();
    assertTrue(drl.contains("@Author(J.W.Goethe)"));
    assertTrue(drl.contains("@Version(3-14)"));
    assertFalse(drl.contains("@Author()"));
    assertFalse(drl.contains("@Version(-)"));
}
Also used : DRLOutput(org.drools.template.model.DRLOutput) Package(org.drools.template.model.Package) Test(org.junit.Test)

Example 14 with Package

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

the class RuleWorksheetParseTest method testPackageAttributeRendering.

/**
 * Check correct rendering of package level attributes
 */
@Test
public void testPackageAttributeRendering() {
    makeRuleSet();
    makeAttribute("NO-LOOP", "true");
    makeAttribute("agenda-group", "agroup");
    makeRuleTable();
    makeRow(11, "C", "A", "P");
    makeRow(12, "foo:Foo", "foo");
    makeRow(13, "attr == $param", "x($param)");
    makeRow(15, "1", "1", "100");
    listener.finishSheet();
    Package p = listener.getRuleSet();
    DRLOutput dout = new DRLOutput();
    p.renderDRL(dout);
    String drl = dout.getDRL();
    // System.out.println( drl );
    assertTrue(drl.contains("no-loop true"));
    assertTrue(drl.contains("agenda-group \"agroup\""));
}
Also used : DRLOutput(org.drools.template.model.DRLOutput) Package(org.drools.template.model.Package) Test(org.junit.Test)

Aggregations

Package (org.drools.template.model.Package)14 Test (org.junit.Test)11 DRLOutput (org.drools.template.model.DRLOutput)10 InputStream (java.io.InputStream)7 Rule (org.drools.template.model.Rule)7 Condition (org.drools.template.model.Condition)5 DecisionTableParseException (org.drools.template.parser.DecisionTableParseException)3 Consequence (org.drools.template.model.Consequence)2 Import (org.drools.template.model.Import)2 Code (org.drools.decisiontable.parser.ActionType.Code)1 Global (org.drools.template.model.Global)1