Skip to content

Commit

Permalink
BZ-1079372 - DSL sentence field loses edit ability when reopened
Browse files Browse the repository at this point in the history
  • Loading branch information
Rikkola committed Mar 21, 2014
1 parent e961107 commit 339cdcb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2405,10 +2405,13 @@ private DSLSentence toDSLSentence( List<String> dslPatterns,
String dslLine ) {
DSLSentence dslSentence = new DSLSentence();
for ( String dslPattern : dslPatterns ) {
// Dollar breaks the matcher, need to escape them.
dslPattern=dslPattern.replace("$","\\$");
//A DSL Pattern can contain Regex itself, for example "When the ages is less than {num:1?[0-9]?[0-9]}"
String regex = dslPattern.replaceAll( "\\{.*?\\}", "(.*)" );
Matcher matcher = Pattern.compile( regex ).matcher( dslLine );
if ( matcher.matches() ) {
dslPattern=dslPattern.replace("\\$","$");
dslSentence.setDefinition( dslPattern );
for ( int i = 0; i < matcher.groupCount(); i++ ) {
dslSentence.getValues().get( i ).setValue( matcher.group( i + 1 ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3226,6 +3226,34 @@ public void testDSL() {

}

@Test
public void testDSLDollar() {
String drl = "package org.mortgages;\n" +
"rule \"testdsl\"\n" +
" dialect \"mvel\"\n" +
" when\n" +
" Price is $111\n" +
" then\n" +
"end";

String dslDefinition = "Price is ${p}";
String dslFile = "[when]" + dslDefinition + "= Item( price == \"{p}\" )";

when( dmo.getPackageName() ).thenReturn( "org.mortgages");

final RuleModel model = RuleModelDRLPersistenceImpl.getInstance().unmarshalUsingDSL(drl,
new ArrayList<String>(),
dmo,
new String[]{dslFile});

assertEquals(1, model.lhs.length);
DSLSentence dslSentence = (DSLSentence)model.lhs[0];

assertEquals("Price is ${p}", dslSentence.getDefinition());
assertEquals("111", dslSentence.getValues().get(0).getValue());

}

@Test
public void testDSLExpansionLHS() {
String drl = "rule \"rule1\"\n"
Expand Down

0 comments on commit 339cdcb

Please sign in to comment.