@Test
public void testActionSetField() {
RuleModel model = new RuleModel();
model.rhs = new IAction[2];
ActionSetField asf0 = new ActionSetField( "ASF0" );
asf0.variable = "$t0";
ActionFieldValue asf0f0 = new ActionFieldValue( "ASF0F0",
"ASF0F0Value",
SuggestionCompletionEngine.TYPE_STRING );
asf0f0.setNature( BaseSingleFieldConstraint.TYPE_LITERAL );
asf0.addFieldValue( asf0f0 );
ActionFieldValue asf0f1 = new ActionFieldValue( "ASF0F1",
"ASF0F1Value",
SuggestionCompletionEngine.TYPE_STRING );
asf0f0.setNature( BaseSingleFieldConstraint.TYPE_LITERAL );
asf0.addFieldValue( asf0f1 );
model.rhs[0] = asf0;
ActionSetField asf1 = new ActionSetField( "ASF1" );
asf1.variable = "$t1";
ActionFieldValue asf1f0 = new ActionFieldValue( "ASF1F0",
"ASF1F0Value",
SuggestionCompletionEngine.TYPE_STRING );
asf1f0.setNature( BaseSingleFieldConstraint.TYPE_LITERAL );
asf1.addFieldValue( asf1f0 );
ActionFieldValue asf1f1 = new ActionFieldValue( "ASF1F1",
"ASF1F1Value",
SuggestionCompletionEngine.TYPE_STRING );
asf1f1.setNature( BaseSingleFieldConstraint.TYPE_LITERAL );
asf1.addFieldValue( asf1f1 );
model.rhs[1] = asf1;
RuleModelCloneVisitor cloneVisitor = new RuleModelCloneVisitor();
RuleModel clone = cloneVisitor.visitRuleModel( model );
assertEquals( 2,
clone.rhs.length );
assertNotSame( model.rhs[0],
clone.rhs[0] );
assertNotNull( clone.rhs[0] );
assertTrue( clone.rhs[0] instanceof ActionSetField );
ActionSetField asf0Clone = (ActionSetField) clone.rhs[0];
assertEquals( "$t0",
asf0Clone.variable );
assertEquals( 2,
asf0Clone.fieldValues.length );
assertNotSame( asf0.fieldValues[0],
asf0Clone.fieldValues[0] );
assertNotNull( asf0Clone.fieldValues[0] );
assertTrue( asf0Clone.fieldValues[0] instanceof ActionFieldValue );
ActionFieldValue asf0f0Clone = (ActionFieldValue) asf0Clone.fieldValues[0];
assertEquals( asf0f0.field,
asf0f0Clone.field );
assertEquals( asf0f0.nature,
asf0f0Clone.nature );
assertEquals( asf0f0.type,
asf0f0Clone.type );
assertEquals( asf0f0.value,
asf0f0Clone.value );
assertNotSame( asf0.fieldValues[1],
asf0Clone.fieldValues[1] );
assertNotNull( asf0Clone.fieldValues[1] );
assertTrue( asf0Clone.fieldValues[1] instanceof ActionFieldValue );
ActionFieldValue asf0f1Clone = (ActionFieldValue) asf0Clone.fieldValues[1];
assertEquals( asf0f1.field,
asf0f1Clone.field );
assertEquals( asf0f1.nature,
asf0f1Clone.nature );
assertEquals( asf0f1.type,
asf0f1Clone.type );
assertEquals( asf0f1.value,
asf0f1Clone.value );
assertNotSame( model.rhs[1],
clone.rhs[1] );
assertNotNull( clone.rhs[1] );
assertTrue( clone.rhs[1] instanceof ActionSetField );
ActionSetField asf1Clone = (ActionSetField) clone.rhs[1];
assertEquals( "$t1",
asf1Clone.variable );
assertEquals( 2,
asf1Clone.fieldValues.length );