@Test public void testLineNumberError() throws Exception { DSLMappingFile file = new DSLTokenizedMappingFile(); String dsl = "[when]foo=Foo()" + NL + "[then]bar {num}=baz({num});"; file.parseAndLoad(new StringReader(dsl)); DefaultExpander ex = new DefaultExpander(); ex.addDSLMapping(file.getMapping()); String source = "rule 'q'" + NL + "agenda-group 'x'" + NL + "when" + NL + " __ " + NL + "then" + NL + " bar 42" + NL + "\tgoober" + NL + "end"; ex.expand(source); assertTrue(ex.hasErrors()); assertEquals(2, ex.getErrors().size()); ExpanderException err = (ExpanderException) ex.getErrors().get(0); assertEquals(4, err.getLine()); err = (ExpanderException) ex.getErrors().get(1); assertEquals(7, err.getLine()); }
@Test public void testANTLRLineNumberError() throws Exception { DSLTokenizedMappingFile file = new DSLTokenizedMappingFile(); String dsl = "[when]foo=Foo()" + NL + "[then]bar {num}=baz({num});"; file.parseAndLoad(new StringReader(dsl)); DefaultExpander ex = new DefaultExpander(); ex.addDSLMapping(file.getMapping()); String source = "rule 'q'" + NL + "agenda-group 'x'" + NL + "when" + NL + " __ " + NL + "then" + NL + " bar 42" + NL + "\tgoober" + NL + "end"; ex.expand(source); assertTrue(ex.hasErrors()); assertEquals(2, ex.getErrors().size()); ExpanderException err = (ExpanderException) ex.getErrors().get(0); assertEquals(4, err.getLine()); err = (ExpanderException) ex.getErrors().get(1); assertEquals(7, err.getLine()); }
@Test public void testANTLREnumExpand() throws Exception { DSLTokenizedMappingFile file = new DSLTokenizedMappingFile(); String dsl = "[when]When the credit rating is {rating:ENUM:Applicant.creditRating} = applicant:Applicant(credit=={rating})"; file.parseAndLoad(new StringReader(dsl)); assertEquals(0, file.getErrors().size()); DefaultExpander ex = new DefaultExpander(); ex.addDSLMapping(file.getMapping()); String source = "rule \"TestNewDslSetup\"" + NL + "dialect \"mvel\"" + NL + "when" + NL + "When the credit rating is AA" + NL + "then " + NL + "end"; // String source="rule \"TestNewDslSetup\"" + NL+ // "dialect \"mvel\"" + NL+ // "when" + NL+ // "When the credit rating is OK" + NL+ // "then" + NL+ // "end" + NL; String drl = ex.expand(source); String expected = "rule \"TestNewDslSetup\"" + NL + "dialect \"mvel\"" + NL + "when" + NL + "applicant:Applicant(credit==AA)" + NL + "then " + NL + "end"; assertFalse(ex.getErrors().toString(), ex.hasErrors()); assertEquals(expected, drl); //System.err.println(ex.expand( "rule 'x' " + NL + " when " + NL + " foo " + NL + " then " + NL + " end" )); }
@Test public void testANTLRExpandFailure() throws Exception { DSLTokenizedMappingFile 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()); }
@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()); }