use of org.drools.drl.parser.lang.dsl.DSLTokenizedMappingFile in project drools by kiegroup.
the class DefaultExpanderTest method testExpandParts.
@Test
public void testExpandParts() 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());
// System.err.println(ex.expand( "rule 'x' " + NL + " when " + NL + " foo " + NL + " then " + NL + " end" ));
}
use of org.drools.drl.parser.lang.dsl.DSLTokenizedMappingFile in project drools by kiegroup.
the class DefaultExpanderTest method testDotInPattern.
@Test
public void testDotInPattern() throws Exception {
// BZ-1013960
String source = "import org.drools.mvel.compiler.Person;" + NL + "global java.util.List list" + NL + "rule R1" + NL + "when" + NL + "then" + NL + "Log X" + NL + "end" + NL;
String dsl = "[then]Log {message:.}=list.add(\"{message}\");";
String expected = "import org.drools.mvel.compiler.Person;" + NL + "global java.util.List list" + NL + "rule R1" + NL + "when" + NL + "then" + NL + "list.add(\"X\");" + NL + "end" + NL;
DSLTokenizedMappingFile file = new DSLTokenizedMappingFile();
file.parseAndLoad(new StringReader(dsl));
assertEquals(file.getErrors().toString(), 0, file.getErrors().size());
DefaultExpander ex = new DefaultExpander();
ex.addDSLMapping(file.getMapping());
String drl = ex.expand(source);
assertFalse(ex.hasErrors());
assertEquals(expected, drl);
}
use of org.drools.drl.parser.lang.dsl.DSLTokenizedMappingFile in project drools by kiegroup.
the class DefaultExpanderTest method setUp.
@Before
public void setUp() throws Exception {
final String filename = "test_metainfo.dsl";
final Reader reader = new InputStreamReader(this.getClass().getResourceAsStream(filename));
this.file = new DSLTokenizedMappingFile();
this.tokenizedFile = new DSLTokenizedMappingFile();
this.file.parseAndLoad(reader);
reader.close();
final Reader reader2 = new InputStreamReader(this.getClass().getResourceAsStream(filename));
this.tokenizedFile.parseAndLoad(reader2);
reader2.close();
this.expander = new DefaultExpander();
}
use of org.drools.drl.parser.lang.dsl.DSLTokenizedMappingFile in project drools by kiegroup.
the class DefaultExpanderTest method testExpandExpr.
@Test
public void testExpandExpr() throws Exception {
DSLTokenizedMappingFile file = new DSLTokenizedMappingFile();
String dsl = "[when]Name of Applicant {nameVar:CF:Applicant.age}= System.out.println({nameVar})";
String source = "rule \"test rule for custom form in DSL\"" + NL + " dialect \"mvel\"" + NL + " when" + NL + " Name of Applicant Bojan Oklahoma and NJ,Andrew AMW Test" + NL + " then" + NL + "end";
String expected = "rule \"test rule for custom form in DSL\"" + NL + " dialect \"mvel\"" + NL + " when" + NL + " System.out.println(Bojan Oklahoma and NJ,Andrew AMW Test)" + NL + " then" + NL + "end";
file.parseAndLoad(new StringReader(dsl));
assertEquals(0, file.getErrors().size());
DefaultExpander ex = new DefaultExpander();
ex.addDSLMapping(file.getMapping());
String drl = ex.expand(source);
assertFalse(ex.hasErrors());
assertEquals(expected, drl);
}
use of org.drools.drl.parser.lang.dsl.DSLTokenizedMappingFile in project drools by kiegroup.
the class DSLTokenizedMappingFileTest method testParseFileWithEscaptedEquals.
@Test
public void testParseFileWithEscaptedEquals() {
String file = "[when]something:\\={value}=Attribute( something == \"{value}\" )";
try {
final Reader reader = new StringReader(file);
this.file = new DSLTokenizedMappingFile();
final boolean parsingResult = this.file.parseAndLoad(reader);
reader.close();
assertTrue(this.file.getErrors().toString(), parsingResult);
assertTrue(this.file.getErrors().isEmpty());
assertEquals(1, this.file.getMapping().getEntries().size());
DSLMappingEntry entry = (DSLMappingEntry) this.file.getMapping().getEntries().get(0);
assertEquals(DSLMappingEntry.CONDITION, entry.getSection());
assertEquals(DSLMappingEntry.EMPTY_METADATA, entry.getMetaData());
assertEquals(lookbehind + "something:\\=(.*?)$", entry.getKeyPattern().toString());
assertEquals("Attribute( something == \"{value}\" )", entry.getValuePattern());
} catch (final IOException e) {
e.printStackTrace();
fail("Should not raise exception ");
}
}
Aggregations