"\t\tThe credit rating is AA\n" +
"\tthen\n" +
"end\n";
final String dslDefinition = "The credit rating is {rating:ENUM:Applicant.creditRating}";
final DSLSentence dsl = new DSLSentence();
dsl.setDefinition( dslDefinition );
//Check values are correctly parsed
final List<DSLVariableValue> values = dsl.getValues();
assertEquals( 1,
values.size() );
assertTrue( values.get( 0 ) instanceof DSLComplexVariableValue );
assertEquals( "rating",
values.get( 0 ).getValue() );
assertEquals( "ENUM:Applicant.creditRating",
( (DSLComplexVariableValue) values.get( 0 ) ).getId() );
//The following line is normally performed by the UI when the user sets values
dsl.getValues().get( 0 ).setValue( "AA" );
//Check interpolation
final String expansion = dsl.interpolate();
assertEquals( "The credit rating is AA",
expansion );
assertEquals( dsl.getDefinition(),
dslDefinition );
final RuleModel m = new RuleModel();
m.name = "Rule With DSL";
m.addLhsItem( dsl );
String drl = brlPersistence.marshal( m );
assertEqualsIgnoreWhitespace( expected, drl );
String dslFile = "[when]" + dslDefinition + "=Credit( rating == {rating} )";
RuleModel unmarshalledModel = brlPersistence.unmarshalUsingDSL( drl,
null,
dslFile );
DSLSentence dslSentence = (DSLSentence) unmarshalledModel.lhs[ 0 ];
assertEquals( dslDefinition,
dslSentence.getDefinition() );
assertEquals( 1,
dslSentence.getValues().size() );
assertTrue( dslSentence.getValues().get( 0 ) instanceof DSLComplexVariableValue );
DSLComplexVariableValue dslComplexVariableValue = (DSLComplexVariableValue) dslSentence.getValues().get( 0 );
assertEquals( "AA",
dslComplexVariableValue.getValue() );
assertEquals( "ENUM:Applicant.creditRating",
dslComplexVariableValue.getId() );