{
DN name = new DN( "uid=akarasulu,ou=users,dc=example,dc=com" );
ModificationOperation mod = ModificationOperation.REPLACE_ATTRIBUTE;
ServerEntry modifyAttributes = new DefaultServerEntry( schemaManager );
AttributeType atCN = schemaManager.lookupAttributeTypeRegistry( "cn" );
modifyAttributes.put( new DefaultServerAttribute( atCN ) );
// this should pass
SchemaChecker.preventStructuralClassRemovalOnModifyReplace( schemaManager.getObjectClassRegistry(), name, mod, modifyAttributes );
// this should succeed since person is still in replaced set and is structural
modifyAttributes.removeAttributes( atCN );
AttributeType atOC = schemaManager.lookupAttributeTypeRegistry( "objectClass" );
EntryAttribute objectClassesReplaced = new DefaultServerAttribute( atOC );
objectClassesReplaced.add( "top" );
objectClassesReplaced.add( "person" );
modifyAttributes.put( objectClassesReplaced );
SchemaChecker.preventStructuralClassRemovalOnModifyReplace( schemaManager.getObjectClassRegistry(), name, mod, modifyAttributes );
// this should fail since only top is left
objectClassesReplaced = new DefaultServerAttribute( atOC );
objectClassesReplaced.add( "top" );
modifyAttributes.put( objectClassesReplaced );
try
{
SchemaChecker.preventStructuralClassRemovalOnModifyReplace( schemaManager.getObjectClassRegistry(), name, mod, modifyAttributes );
fail( "should never get here due to an LdapSchemaViolationException" );
}
catch ( LdapSchemaViolationException e )
{
assertEquals( e.getResultCode(), ResultCodeEnum.OBJECT_CLASS_MODS_PROHIBITED );
}
// this should fail since the modify operation tries to delete all
// objectClass attribute values
modifyAttributes.removeAttributes( "cn" );
objectClassesReplaced = new DefaultServerAttribute( atOC );
modifyAttributes.put( objectClassesReplaced );
try
{
SchemaChecker.preventStructuralClassRemovalOnModifyReplace( schemaManager.getObjectClassRegistry(), name, mod, modifyAttributes );
fail( "should never get here due to an LdapSchemaViolationException" );