Search in sources :

Example 6 with DSLMappingFile

use of org.drools.drl.parser.lang.dsl.DSLMappingFile in project drools by kiegroup.

the class DefaultExpanderTest method testExpandInfiniteLoop.

@Test(timeout = 1000)
public void testExpandInfiniteLoop() throws Exception {
    // DROOLS-73
    DSLMappingFile file = new DSLTokenizedMappingFile();
    String dsl = "[when]Foo with {var} bars=Foo( bars == {var} )";
    file.parseAndLoad(new StringReader(dsl));
    assertEquals(0, file.getErrors().size());
    DefaultExpander ex = new DefaultExpander();
    ex.addDSLMapping(file.getMapping());
    String source = "rule 'dsl rule'" + NL + "when" + NL + " Foo with {var} bars" + NL + "then" + NL + NL + "end";
    ex.expand(source);
    assertFalse(ex.hasErrors());
}
Also used : StringReader(java.io.StringReader) DSLMappingFile(org.drools.drl.parser.lang.dsl.DSLMappingFile) DSLTokenizedMappingFile(org.drools.drl.parser.lang.dsl.DSLTokenizedMappingFile) DefaultExpander(org.drools.drl.parser.lang.dsl.DefaultExpander) Test(org.junit.Test)

Example 7 with DSLMappingFile

use of org.drools.drl.parser.lang.dsl.DSLMappingFile in project drools by kiegroup.

the class DefaultExpanderTest method testExpandFailure.

@Test
public void testExpandFailure() throws Exception {
    DSLMappingFile file = new DSLTokenizedMappingFile();
    String dsl = "[when]foo=Foo()" + NL + "[then]bar {num}=baz({num});";
    file.parseAndLoad(new StringReader(dsl));
    assertEquals(0, file.getErrors().size());
    DefaultExpander ex = new DefaultExpander();
    ex.addDSLMapping(file.getMapping());
    String source = "rule 'q'" + NL + "agenda-group 'x'" + NL + "when" + NL + "    foo  " + NL + "then" + NL + "    bar 42" + NL + "end";
    String drl = ex.expand(source);
    assertFalse(ex.hasErrors());
    ex = new DefaultExpander();
    ex.addDSLMapping(file.getMapping());
    source = "rule 'q' agenda-group 'x'" + NL + "when" + NL + "    foos " + NL + "then" + NL + "    bar 42" + NL + " end";
    drl = ex.expand(source);
    // System.out.println( drl );
    assertTrue(ex.hasErrors());
    assertEquals(1, ex.getErrors().size());
// System.err.println(( (ExpanderException) ex.getErrors().get( 0 )).getMessage());
}
Also used : StringReader(java.io.StringReader) DSLMappingFile(org.drools.drl.parser.lang.dsl.DSLMappingFile) DSLTokenizedMappingFile(org.drools.drl.parser.lang.dsl.DSLTokenizedMappingFile) DefaultExpander(org.drools.drl.parser.lang.dsl.DefaultExpander) Test(org.junit.Test)

Aggregations

StringReader (java.io.StringReader)7 DSLMappingFile (org.drools.drl.parser.lang.dsl.DSLMappingFile)7 DSLTokenizedMappingFile (org.drools.drl.parser.lang.dsl.DSLTokenizedMappingFile)7 DefaultExpander (org.drools.drl.parser.lang.dsl.DefaultExpander)7 Test (org.junit.Test)7 DrlParser (org.drools.drl.parser.DrlParser)1 Expander (org.drools.drl.parser.lang.Expander)1 ExpanderException (org.drools.drl.parser.lang.ExpanderException)1 DefaultExpanderResolver (org.drools.drl.parser.lang.dsl.DefaultExpanderResolver)1