use of org.drools.compiler.lang.dsl.DSLMappingEntry in project drools by kiegroup.
the class DSLMappingEntryTest method testPatternCalculation.
@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());
}
use of org.drools.compiler.lang.dsl.DSLMappingEntry in project drools by kiegroup.
the class DSLMappingEntryTest method testExpandWithDots.
@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"));
}
use of org.drools.compiler.lang.dsl.DSLMappingEntry in project drools by kiegroup.
the class DSLTokenizedMappingFileTest method testParseFileWithBrackets.
@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 ");
}
}
use of org.drools.compiler.lang.dsl.DSLMappingEntry in project drools by kiegroup.
the class DSLTokenizedMappingFileTest method testParseFileWithEscaptedBrackets.
@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 ");
}
}
use of org.drools.compiler.lang.dsl.DSLMappingEntry in project drools by kiegroup.
the class DSLTokenizedMappingFileTest method testParseFileWithEscaptedEquals.
@Test
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(lookbehind + "something:\\=(.*?)$", entry.getKeyPattern().toString());
assertEquals("Attribute( something == \"{value}\" )", entry.getValuePattern());
} catch (final IOException e) {
e.printStackTrace();
fail("Should not raise exception ");
}
}
Aggregations