FactPattern fp0 = new FactPattern();
fp0.setBoundName( "$t0" );
fp0.setFactType( "FT0" );
fp0.setNegated( true );
SingleFieldConstraint fp0sfc0 = new SingleFieldConstraint();
fp0sfc0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
fp0sfc0.setFieldBinding( "$fp0sfc0" );
fp0sfc0.setFieldName( "fp0sfc0" );
fp0sfc0.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
fp0sfc0.setOperator( "==" );
fp0sfc0.setParameter( "fp0sfc0p0",
"fp0sfc0p0Value" );
fp0sfc0.setValue( "fp0sfc0Value" );
fp0.addConstraint( fp0sfc0 );
FactPattern fp1 = new FactPattern();
fp1.setBoundName( "$t1" );
fp1.setFactType( "FT1" );
fp1.setNegated( true );
SingleFieldConstraint fp1sfc0 = new SingleFieldConstraint();
fp1sfc0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
fp1sfc0.setFieldBinding( "$fp1sfc0" );
fp1sfc0.setFieldName( "fp1sfc0" );
fp1sfc0.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
fp1sfc0.setOperator( "==" );
fp1sfc0.setParameter( "fp1sfc0p0",
"fp1sfc0p0Value" );
fp1sfc0.setValue( "fp1sfc0Value" );
fp1.addConstraint( fp1sfc0 );
cfp0.addFactPattern( fp0 );
cfp0.addFactPattern( fp1 );
model.lhs[0] = cfp0;
RuleModelCloneVisitor cloneVisitor = new RuleModelCloneVisitor();
RuleModel clone = cloneVisitor.visitRuleModel( model );
assertEquals( 1,
clone.lhs.length );
assertNotSame( model.lhs[0],
clone.lhs[0] );
assertNotNull( clone.lhs[0] );
assertTrue( clone.lhs[0] instanceof CompositeFactPattern );
CompositeFactPattern cfp0Clone = (CompositeFactPattern) clone.lhs[0];
assertEquals( cfp0.type,
cfp0Clone.type );
assertEquals( cfp0.getPatterns().length,
cfp0Clone.getPatterns().length );
assertNotSame( cfp0.getPatterns()[0],
cfp0Clone.getPatterns()[0] );
assertNotNull( cfp0Clone.getPatterns()[0] );
assertTrue( cfp0Clone.getPatterns()[0] instanceof FactPattern );
FactPattern fp0Clone = (FactPattern) cfp0Clone.getPatterns()[0];
assertEquals( fp0.getBoundName(),
fp0Clone.getBoundName() );
assertEquals( fp0.getFactType(),
fp0Clone.getFactType() );
assertEquals( fp0.constraintList.constraints.length,
fp0Clone.constraintList.constraints.length );
assertNotSame( fp0.constraintList.constraints[0],
fp0Clone.constraintList.constraints[0] );
assertNotNull( fp0Clone.constraintList.constraints[0] );
assertTrue( fp0Clone.constraintList.constraints[0] instanceof SingleFieldConstraint );
SingleFieldConstraint fp0sfc0Clone = (SingleFieldConstraint) fp0Clone.constraintList.constraints[0];
assertEquals( fp0sfc0.getFieldBinding(),
fp0sfc0Clone.getFieldBinding() );
assertEquals( fp0sfc0.getFieldName(),
fp0sfc0Clone.getFieldName() );
assertEquals( fp0sfc0.getFieldType(),
fp0sfc0Clone.getFieldType() );
assertEquals( fp0sfc0.getOperator(),
fp0sfc0Clone.getOperator() );
assertNotNull( fp0sfc0Clone.getParameter( "fp0sfc0p0" ) );
assertEquals( fp0sfc0.getParameter( "fp0sfc0p0" ),
fp0sfc0Clone.getParameter( "fp0sfc0p0" ) );
assertEquals( fp0sfc0.getValue(),
fp0sfc0Clone.getValue() );
assertNotSame( cfp0.getPatterns()[1],
cfp0Clone.getPatterns()[1] );
assertNotNull( cfp0Clone.getPatterns()[1] );
assertTrue( cfp0Clone.getPatterns()[1] instanceof FactPattern );
FactPattern fp1Clone = (FactPattern) cfp0Clone.getPatterns()[1];
assertEquals( fp1.getBoundName(),
fp1Clone.getBoundName() );
assertEquals( fp1.getFactType(),
fp1Clone.getFactType() );
assertEquals( fp1.constraintList.constraints.length,
fp1Clone.constraintList.constraints.length );
assertNotSame( fp1.constraintList.constraints[0],
fp1Clone.constraintList.constraints[0] );
assertNotNull( fp1Clone.constraintList.constraints[0] );
assertTrue( fp1Clone.constraintList.constraints[0] instanceof SingleFieldConstraint );
SingleFieldConstraint fp1sfc0Clone = (SingleFieldConstraint) fp1Clone.constraintList.constraints[0];
assertEquals( fp1sfc0.getFieldBinding(),
fp1sfc0Clone.getFieldBinding() );
assertEquals( fp1sfc0.getFieldName(),
fp1sfc0Clone.getFieldName() );
assertEquals( fp1sfc0.getFieldType(),
fp1sfc0Clone.getFieldType() );
assertEquals( fp1sfc0.getOperator(),
fp1sfc0Clone.getOperator() );
assertNotNull( fp1sfc0Clone.getParameter( "fp1sfc0p0" ) );
assertEquals( fp1sfc0.getParameter( "fp1sfc0p0" ),
fp1sfc0Clone.getParameter( "fp1sfc0p0" ) );
assertEquals( fp1sfc0.getValue(),
fp1sfc0Clone.getValue() );
}