private DSLMappingEntry setupEntry() throws IOException { final String inputKey = "String is \"{value}\""; final String inputValue = "SomeFact(value==\"{value}\")"; return createEntry( inputKey, inputValue ); }
@Test public void testCreateWithTilde() throws IOException { //If the statement parses it passes. To test expressions in dsl with a ~ try{ DSLMappingEntry entry1 = this.createEntry( "the benefit HAS an EXACT message of {ALLMSG}", "$benefit :Map(this['ALLMSG'] matches \"(?i).*~{ALLMSG}~.*\") from $benefits"); }catch(Exception e){ fail(e.getMessage()); } } }
@Test public void testExpandWithDots() throws IOException { DSLMappingEntry entry1 = this.createEntry( "- {prop} is not {val} ", "{prop} != {val}" ); DSLMappingEntry entry2 = this.createEntry( "- {prop} is {val} ", "{prop} == {val}" ); DSLMappingEntry entry3 = this.createEntry( "- {prop} is_not {val} ", "{prop} != {val}" ); DefaultExpander ex = makeExpander( entry1, entry2, entry3 ); StringBuilder sb = new StringBuilder( "rule x\n" ).append( "when\n" ); sb.append( "> Foo()").append( NL ); sb.append( "- type1 is ClientServiceType.TypeGOLD" ).append( NL ); sb.append( "- type2 is_not ClientServiceType.TypeGOLD" ).append( NL ); sb.append( "- type3 is not ClientServiceType.TypeGOLD" ).append( NL ); sb.append( "then\n" ).append( "end\n" ); String dslr = sb.toString(); String drl = ex.expand( dslr ); System.out.println( dslr ); System.out.println( drl ); assertTrue( "failure type1", drl.contains( "type1 == ClientServiceType.TypeGOLD" ) ); assertTrue( "failure type2", drl.contains( "type2 != ClientServiceType.TypeGOLD" ) ); assertTrue( "failure type3", drl.contains( "type3 != ClientServiceType.TypeGOLD" ) ); }
@Test public void testExpandWithBrackets() throws IOException { DSLMappingEntry entry1 = this.createEntry( "attr {attr_name} is in \\[ {values} \\]", "{attr_name} in ( {values} )" ); DSLMappingEntry entry2 = this.createEntry( "((H|h)e|(S|s)he) \\(is\\) (a|an) $xx {attribute} (man|woman)", "Person( attribute == \"{attribute}\" )" ); DSLMappingEntry entry3 = this.createEntry( "DSL sentence with {key1} {key2}", "Sentence( {key1} == {key2} )" ); DSLMappingEntry entry4 = this.createEntry( "When the credit rating is {rating:ENUM:Applicant.creditRating}", "applicant:Applicant(credit=={rating})" ); DSLMappingEntry entry5 = this.createEntry( "When the credit rating is {rating:regex:\\d{3}}", "applicant:Applicant(credit=={rating})" ); entry5.getValuePattern() ); DSLMappingEntry entry6 = this.createEntry( "This is a sentence with line breaks", "Cheese\\n(price == 10)" ); entry6.getValuePattern()); DSLMappingEntry entry7 = this.createEntry( "Bedingung-\\#19-MKM4", "eval ( $p.getTempVal(\"\\#UML-ATZ-1\") < $p.getZvUmlStfr() )" );
@Test public void testPatternCalculation() throws IOException { final String inputKey = "The Customer name is {name} and surname is {surname} and it has US$ 50,00 on his {pocket}"; final String inputValue = "Customer( name == \"{name}\", surname == \"{surname}\", money > $money )"; final String expectedKeyP = lookbehind + "The\\s+Customer\\s+name\\s+is\\s+(.*?)\\s+and\\s+surname\\s+is\\s+(.*?)\\s+and\\s+it\\s+has\\s+US\\$\\s+50,00\\s+on\\s+his\\s+(.*?)$"; final String expectedValP = "Customer( name == \"{name}\", surname == \"{surname}\", money > $money )"; final DSLMappingEntry entry = createEntry( inputKey, inputValue ); assertEquals( inputKey, entry.getMappingKey() ); assertEquals( expectedKeyP, entry.getKeyPattern().pattern() ); assertEquals( inputValue, entry.getMappingValue() ); assertEquals( expectedValP, entry.getValuePattern() ); }
@Test public void testPatternCalculation3() throws IOException { final String inputKey = "- name is {name}"; final String inputValue = "name == \"{name}\""; final String expectedKeyP = lookbehind + "-\\s*name\\s+is\\s+(.*?)$"; final String expectedValP = "name == \"{name}\""; final DSLMappingEntry entry = createEntry( inputKey, inputValue ); assertEquals( inputKey, entry.getMappingKey() ); assertEquals( entry.getKeyPattern().pattern(), expectedKeyP, entry.getKeyPattern().pattern() ); assertEquals( inputValue, entry.getMappingValue() ); assertEquals( expectedValP, entry.getValuePattern() ); }
@Test public void testPatternCalculation2() throws IOException { final String inputKey = "-name is {name}"; final String inputValue = "name == \"{name}\""; final String expectedKeyP = lookbehind + "-\\s*name\\s+is\\s+(.*?)$"; final String expectedValP = "name == \"{name}\""; final DSLMappingEntry entry = createEntry( inputKey, inputValue ); assertEquals( inputKey, entry.getMappingKey() ); assertEquals( expectedKeyP, entry.getKeyPattern().pattern() ); assertEquals( inputValue, entry.getMappingValue() ); assertEquals( expectedValP, entry.getValuePattern() ); }