entry5.getKeyPattern().toString() ); assertEquals( "applicant:Applicant(credit=={rating})", entry5.getValuePattern() ); entry6.getKeyPattern().toString() ); assertEquals( "Cheese\n(price == 10)", entry6.getValuePattern()); entry7.getKeyPattern().toString() ); assertEquals( "eval ( $p.getTempVal(\"#UML-ATZ-1\") < $p.getZvUmlStfr() )", entry7.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 testParseFileWithBrackets() { 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( lookbehind + "ATTRIBUTE\\s+\"(.*?)\"\\s+IS\\s+IN\\s+[(.*?)](?=\\W|$)", entry.getKeyPattern().toString() ); //Attribute( {attr} in ({list}) ) assertEquals( "Attribute( {attr} in ({list}) )", entry.getValuePattern() ); } catch ( final IOException e ) { e.printStackTrace(); fail( "Should not raise exception " ); } }
entry.getMetaData() ); assertEquals( lookbehind + "something:\\=(.*?)$", entry.getKeyPattern().toString() ); assertEquals( "Attribute( something == \"{value}\" )", 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( lookbehind + "ATTRIBUTE\\s+\"(.*?)\"\\s+IS\\s+IN\\s+\\[(.*?)\\](?=\\W|$)", entry.getKeyPattern().toString() ); //Attribute( {attr} in ({list}) ) assertEquals( "Attribute( {attr} in ({list}) )", entry.getValuePattern() ); } catch ( final IOException e ) { e.printStackTrace(); fail( "Should not raise exception " ); } }
entry.getKeyPattern().toString() );
@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 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() ); }