@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() ); }
System.out.println( entry.getVariables() ); assertEquals( "ATTRIBUTE {attr:ENUM:Attribute.value} in {list}", entry.getMappingKey() ); assertEquals( "Attribute( {attr} in ({list}) )", entry.getMappingValue() );
@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 testParseFileWithEscaptedBrackets() { String file = "[when][]ATTRIBUTE \"{attr}\" IS IN \\[{list}\\]=Attribute( {attr} in ({list}) )"; 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( "ATTRIBUTE \"{attr}\" IS IN \\[{list}\\]", entry.getMappingKey() ); assertEquals( "Attribute( {attr} in ({list}) )", entry.getMappingValue() ); } catch ( final IOException e ) { e.printStackTrace(); fail( "Should not raise exception " ); } }
@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() ); }
@Test @Ignore 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( "something:={value}", entry.getMappingKey() ); assertEquals( "Attribute( something == \"{value}\" )", entry.getMappingValue() ); } catch ( final IOException e ) { e.printStackTrace(); fail( "Should not raise exception " ); } }
entry.getMetaData().toString() ); assertEquals( "Add surcharge {surcharge} to Policy", entry.getMappingKey() ); assertEquals( "modify(policy) \\{price = {surcharge}\\}", entry.getMappingValue() );
private void populateDSLSentences( final DSLTokenizedMappingFile dslLoader ) { for ( DSLMappingEntry entry : dslLoader.getMapping().getEntries() ) { if ( entry.getSection() == DSLMappingEntry.CONDITION ) { addDSLConditionSentence( entry.getMappingKey() ); } else if ( entry.getSection() == DSLMappingEntry.CONSEQUENCE ) { addDSLActionSentence( entry.getMappingKey() ); } else if ( entry.getSection() == DSLMappingEntry.KEYWORD ) { addDSLKeywordMapping( entry.getMappingKey() ); } else if ( entry.getSection() == DSLMappingEntry.ANY ) { addDSLAnyScopeMapping( entry.getMappingKey() ); } } }
final DSLSentence sentence = new DSLSentence(); sentence.setDrl(definition.getMappingValue()); sentence.setDefinition(definition.getMappingKey()); conditionSentences.add(sentence); } else if (entry.getSection() == DSLMappingEntry.CONSEQUENCE) { final DSLSentence sentence = new DSLSentence(); sentence.setDrl(definition.getMappingValue()); sentence.setDefinition(definition.getMappingKey()); actionSentences.add(sentence);