AttributeType ouAt = registries.getAttributeTypeRegistry().lookup( "ou" );
AttributeType snAt = registries.getAttributeTypeRegistry().lookup( "sn" );
// postive test which should pass
SchemaChecker.preventRdnChangeOnModifyRemove( name, mod,
new DefaultServerAttribute( "cn", cnAt, "does not matter" ), registry );
// test should fail since we are removing the ou attribute
try
{
SchemaChecker.preventRdnChangeOnModifyRemove( name, mod,
new DefaultServerAttribute( "ou", ouAt ), registry );
fail( "should never get here due to a LdapSchemaViolationException being thrown" );
}
catch ( LdapSchemaViolationException e )
{
assertEquals( ResultCodeEnum.NOT_ALLOWED_ON_RDN, e.getResultCode() );
}
// test success using more than one attribute for the Rdn but not modifying rdn attribute
name = new LdapDN( "ou=users+cn=system users,dc=example,dc=com" );
SchemaChecker.preventRdnChangeOnModifyRemove( name, mod,
new DefaultServerAttribute( "sn", snAt, "does not matter" ), registry );
// test for failure when modifying Rdn attribute in multi attribute Rdn
try
{
SchemaChecker.preventRdnChangeOnModifyRemove( name, mod,
new DefaultServerAttribute( "cn", cnAt ), registry );
fail( "should never get here due to a LdapSchemaViolationException being thrown" );
}
catch ( LdapSchemaViolationException e )
{
assertEquals( ResultCodeEnum.NOT_ALLOWED_ON_RDN, e.getResultCode() );
}
// should succeed since the value being deleted from the rdn attribute is
// is not used when composing the Rdn
SchemaChecker.preventRdnChangeOnModifyRemove( name, mod,
new DefaultServerAttribute( "ou", ouAt, "container" ), registry );
// now let's make it fail again just by providing the right value for ou (users)
try
{
SchemaChecker.preventRdnChangeOnModifyRemove( name, mod,
new DefaultServerAttribute( "ou", ouAt, "users" ), registry );
fail( "should never get here due to a LdapSchemaViolationException being thrown" );
}
catch ( LdapSchemaViolationException e )
{
assertEquals( ResultCodeEnum.NOT_ALLOWED_ON_RDN, e.getResultCode() );