@Test public void testExpandComplex() throws Exception { String source = "rule \"R\"" + NL + "dialect \"mvel\"" + NL + "when" + NL + "There is an TestObject" + NL + "-startDate is before 01-Jul-2011" + NL + "-endDate is after 01-Jul-2011" + NL + "then" + NL + "end" + NL; String expected = "rule \"R\"" + NL + "dialect \"mvel\"" + NL + "when" + NL + "TestObject(startDate>DateUtils.parseDate(\"01-Jul-2011\"), endDate>DateUtils.parseDate(\"01-Jul-2011\"))" + NL + "then" + NL + "end" + NL; checkExpansion(source, expected); }
@Test public void testExpandWithKeywordClashes() throws Exception { DSLMappingFile file = new DSLTokenizedMappingFile(); String dsl = "[when]Invoke rule executor=ruleExec: RuleExecutor()" + NL + "[then]Execute rule \"{id}\"=ruleExec.ExecuteSubRule( new Long({id}));"; file.parseAndLoad(new StringReader(dsl)); assertEquals(0, file.getErrors().size()); DefaultExpander ex = new DefaultExpander(); ex.addDSLMapping(file.getMapping()); String source = "package something;" + NL + NL + "rule \"1\"" + NL + "when" + NL + " Invoke rule executor" + NL + "then" + NL + " Execute rule \"5\"" + NL + "end"; String expected = "package something;" + NL + NL + "rule \"1\"" + NL + "when" + NL + " ruleExec: RuleExecutor()" + NL + "then" + NL + " ruleExec.ExecuteSubRule( new Long(5));" + NL + "end" + NL; String drl = ex.expand(source); // System.out.println("["+drl+"]" ); // System.out.println("["+expected+"]" ); assertFalse(ex.hasErrors()); equalsIgnoreWhiteSpace(expected, drl); }
@Test public void testDontExpandCommentedLines() throws Exception { String source = "rule \"R\"" + NL + "dialect \"mvel\"" + NL + "when" + NL + "// There is an TestObject" + NL + "// -startDate is before 01-Jul-2011" + NL + "// -endDate is after 01-Jul-2011" + NL + "then" + NL + "end" + NL; String expected = "rule \"R\"" + NL + "dialect \"mvel\"" + NL + "when" + NL + "// There is an TestObject" + NL + "// -startDate is before 01-Jul-2011" + NL + "// -endDate is after 01-Jul-2011" + NL + "then" + NL + "end" + NL; checkExpansion(source, expected); }
@Test public void testDontExpandCommentedBlocks() throws Exception { String source = "rule \"R\"" + NL + "dialect \"mvel\"" + NL + "when" + NL + "/*" + NL + "There is an TestObject" + NL + "-startDate is before 01-Jul-2011" + NL + "-endDate is after 01-Jul-2011" + NL + "*/" + NL + "then" + NL + "end" + NL; String expected = "rule \"R\"" + NL + "dialect \"mvel\"" + NL + "when" + NL + "" + NL + "then" + NL + "end" + NL; checkExpansion(source, expected); }