You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2012/01/24 17:22:36 UTC

svn commit: r1235328 [6/12] - in /directory/apacheds/trunk: server-annotations/src/main/java/org/apache/directory/server/annotations/ server-annotations/src/main/java/org/apache/directory/server/factory/ server-annotations/src/test/java/org/apache/dire...

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyRemoveIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyRemoveIT.java?rev=1235328&r1=1235327&r2=1235328&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyRemoveIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyRemoveIT.java Tue Jan 24 16:22:33 2012
@@ -58,619 +58,640 @@ import org.junit.runner.RunWith;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-@RunWith ( FrameworkRunner.class ) 
+@RunWith(FrameworkRunner.class)
 //@CreateDS( name="ModifyRemoveIT-class", enableChangeLog=false )
-@CreateLdapServer ( 
-    transports = 
-    {
-        @CreateTransport( protocol = "LDAP" )
+@CreateLdapServer(
+    transports =
+        {
+            @CreateTransport(protocol = "LDAP")
     })
-@ApplyLdifs( {
-    // Entry # 1
-    "dn: cn=Tori Amos,ou=system",
-    "objectClass: person",
-    "objectClass: top",
-    "description: an American singer-songwriter",
-    "cn: Tori Amos",
-    "sn: Amos"
-    }
-)
+@ApplyLdifs(
+    {
+        // Entry # 1
+        "dn: cn=Tori Amos,ou=system",
+        "objectClass: person",
+        "objectClass: top",
+        "description: an American singer-songwriter",
+        "cn: Tori Amos",
+        "sn: Amos"
+})
 public class ModifyRemoveIT extends AbstractLdapTestUnit
 {
-    private static final String BASE = "ou=system";
-    private static final String RDN = "cn=Tori Amos";
+private static final String BASE = "ou=system";
+private static final String RDN = "cn=Tori Amos";
 
-    /**
-     * Enable the krb5kdc schema.
-     */
-     @Before
-    public void setUp() throws Exception
-    {
-        DirContext schemaRoot = ( DirContext ) getWiredContext( getLdapServer() ).lookup( "ou=schema" );
-
-        // -------------------------------------------------------------------
-        // Enable the krb5kdc schema
-        // -------------------------------------------------------------------
-
-        // check if krb5kdc is disabled
-        Attributes krb5kdcAttrs = schemaRoot.getAttributes( "cn=Krb5kdc" );
-        boolean isKrb5KdcDisabled = false;
-        
-        if ( krb5kdcAttrs.get( "m-disabled" ) != null )
-        {
-            isKrb5KdcDisabled = ( ( String ) krb5kdcAttrs.get( "m-disabled" ).get() ).equalsIgnoreCase( "TRUE" );
-        }
 
-        // if krb5kdc is disabled then enable it
-        if ( isKrb5KdcDisabled )
-        {
-            Attribute disabled = new BasicAttribute( "m-disabled" );
-            ModificationItem[] mods = new ModificationItem[]
-                { new ModificationItem( DirContext.REMOVE_ATTRIBUTE, disabled ) };
-            schemaRoot.modifyAttributes( "cn=Krb5kdc", mods );
-        }
-    }
-
-    /**
-     * Creation of required attributes of a person entry.
-     */
-    protected Attributes getPersonAttributes( String sn, String cn )
-    {
-        Attributes attributes = new BasicAttributes( true );
-        Attribute attribute = new BasicAttribute( "objectClass" );
-        attribute.add( "top" );
-        attribute.add( "person" );
-        attributes.put( attribute );
-        attributes.put( "cn", cn );
-        attributes.put( "sn", sn );
-
-        return attributes;
-    }
-
-
-    /**
-     * Creation of required attributes of an inetOrgPerson entry.
-     */
-    protected Attributes getInetOrgPersonAttributes( String sn, String cn )
-    {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute ocls = new BasicAttribute( "objectClass" );
-        ocls.add( "top" );
-        ocls.add( "person" );
-        ocls.add( "organizationalPerson" );
-        ocls.add( "inetOrgPerson" );
-        attrs.put( ocls );
-        attrs.put( "cn", cn );
-        attrs.put( "sn", sn );
-
-        return attrs;
-    }
-
-
-    /**
-     * Remove a value which does not exist in an attribute making sure  
-     * it does not remove other values in that attribute.  Tests if the 
-     * following JIRA issue is still valid:
-     * 
-     *    https://issues.apache.org/jira/browse/DIRSERVER-1149
-     */
-    @Test
-    public void testRemoveAttemptWithoutChange() throws Exception
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // Get the attributes and check the contents
-        Attributes tori = ctx.getAttributes( RDN );
-        assertNotNull( tori.get( "objectClass" ) );
-        assertNotNull( tori.get( "cn" ) );
-        assertEquals( 1, tori.get( "cn" ).size() );
-        assertEquals( "Tori Amos", tori.get( "cn" ).get() );
-        assertNotNull( tori.get( "sn" ) );
-        
-        // Test an add operation first
-        ModificationItem mod = new ModificationItem( DirContext.ADD_ATTRIBUTE, new BasicAttribute( "cn", "foo" ) );
-        ctx.modifyAttributes( RDN, new ModificationItem[] { mod } );
-        tori = ctx.getAttributes( RDN );
-        assertNotNull( tori.get( "objectClass" ) );
-        assertNotNull( tori.get( "cn" ) );
-        assertEquals( 2, tori.get( "cn" ).size() );
-        assertEquals( "Tori Amos", tori.get( "cn" ).get( 0 ) );
-        assertEquals( "foo", tori.get( "cn" ).get( 1 ) );
-        assertNotNull( tori.get( "sn" ) );
-        
-        // Now test remove of value ( bar ) that does not exist in cn
-        mod = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, new BasicAttribute( "cn", "bar" ) );
-        try
-        {
-            ctx.modifyAttributes( RDN, new ModificationItem[] { mod } );
-            fail();
-        }
-        catch ( NoSuchAttributeException nsae )
-        {
-            assertTrue( true );
-        }
-        
-        tori = ctx.getAttributes( RDN );
-        assertNotNull( tori.get( "objectClass" ) );
-        assertNotNull( tori.get( "cn" ) );
-        assertEquals( 2, tori.get( "cn" ).size() );
-        assertEquals( "Tori Amos", tori.get( "cn" ).get( 0 ) );
-        assertEquals( "foo", tori.get( "cn" ).get( 1 ) );
-        assertNotNull( tori.get( "sn" ) );
-    }
+/**
+ * Enable the krb5kdc schema.
+ */
+@Before
+public void setUp() throws Exception
+{
+    DirContext schemaRoot = ( DirContext ) getWiredContext( getLdapServer() ).lookup( "ou=schema" );
 
+    // -------------------------------------------------------------------
+    // Enable the krb5kdc schema
+    // -------------------------------------------------------------------
 
-    /**
-     * Remove an attribute, which is not required.
-     * 
-     * Expected result: After successful deletion, attribute is not present in
-     * entry.
-     */
-    @Test
-    public void testRemoveNotRequiredAttribute() throws Exception
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // Remove description Attribute
-        Attribute attr = new BasicAttribute( "description" );
-        Attributes attrs = new BasicAttributes( true );
-        attrs.put( attr );
-        ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
+    // check if krb5kdc is disabled
+    Attributes krb5kdcAttrs = schemaRoot.getAttributes( "cn=Krb5kdc" );
+    boolean isKrb5KdcDisabled = false;
 
-        // Verify, that attribute is deleted
-        attrs = ctx.getAttributes( RDN );
-        attr = attrs.get( "description" );
-        assertNull( attr );
+    if ( krb5kdcAttrs.get( "m-disabled" ) != null )
+    {
+        isKrb5KdcDisabled = ( ( String ) krb5kdcAttrs.get( "m-disabled" ).get() ).equalsIgnoreCase( "TRUE" );
     }
 
+    // if krb5kdc is disabled then enable it
+    if ( isKrb5KdcDisabled )
+    {
+        Attribute disabled = new BasicAttribute( "m-disabled" );
+        ModificationItem[] mods = new ModificationItem[]
+            { new ModificationItem( DirContext.REMOVE_ATTRIBUTE, disabled ) };
+        schemaRoot.modifyAttributes( "cn=Krb5kdc", mods );
+    }
+}
 
-    /**
-     * Remove two not required attributes.
-     * 
-     * Expected result: After successful deletion, both attributes ar not
-     * present in entry.
-     */
-    @Test
-    public void testRemoveTwoNotRequiredAttributes() throws Exception
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // add telephoneNumber to entry
-        Attributes tn = new BasicAttributes( "telephoneNumber", "12345678", true );
-        ctx.modifyAttributes( RDN, DirContext.ADD_ATTRIBUTE, tn );
-
-        // Remove description and telephoneNumber to Attribute
-        Attributes attrs = new BasicAttributes( true );
-        attrs.put( new BasicAttribute( "description" ) );
-        attrs.put( new BasicAttribute( "telephoneNumber" ) );
-        ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
 
-        // Verify, that attributes are deleted
-        attrs = ctx.getAttributes( RDN );
-        assertNull( attrs.get( "description" ) );
-        assertNull( attrs.get( "telephoneNumber" ) );
-        assertNotNull( attrs.get( "cn" ) );
-        assertNotNull( attrs.get( "sn" ) );
-    }
+/**
+ * Creation of required attributes of a person entry.
+ */
+protected Attributes getPersonAttributes( String sn, String cn )
+{
+    Attributes attributes = new BasicAttributes( true );
+    Attribute attribute = new BasicAttribute( "objectClass" );
+    attribute.add( "top" );
+    attribute.add( "person" );
+    attributes.put( attribute );
+    attributes.put( "cn", cn );
+    attributes.put( "sn", sn );
 
+    return attributes;
+}
 
-    /**
-     * Remove a required attribute. The sn attribute of the person entry is used
-     * here.
-     * 
-     * Expected Result: Deletion fails with NamingException (Schema Violation).
-     */
-    @Test
-    public void testRemoveRequiredAttribute() throws Exception
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // Remove sn attribute
-        Attribute attr = new BasicAttribute( "sn" );
-        Attributes attrs = new BasicAttributes( true );
-        attrs.put( attr );
 
-        try
-        {
-            ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
-            fail( "Deletion of required attribute should fail." );
-        }
-        catch ( SchemaViolationException e )
-        {
-            // expected behaviour
-        }
-    }
+/**
+ * Creation of required attributes of an inetOrgPerson entry.
+ */
+protected Attributes getInetOrgPersonAttributes( String sn, String cn )
+{
+    Attributes attrs = new BasicAttributes( true );
+    Attribute ocls = new BasicAttribute( "objectClass" );
+    ocls.add( "top" );
+    ocls.add( "person" );
+    ocls.add( "organizationalPerson" );
+    ocls.add( "inetOrgPerson" );
+    attrs.put( ocls );
+    attrs.put( "cn", cn );
+    attrs.put( "sn", sn );
 
+    return attrs;
+}
 
-    /**
-     * Remove a required attribute from Rdn.
-     * 
-     * Expected Result: Deletion fails with SchemaViolationException.
-     */
-    @Test
-    public void testRemovePartOfRdn() throws Exception
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // Remove sn attribute
-        Attribute attr = new BasicAttribute( "cn" );
-        Attributes attrs = new BasicAttributes( true );
-        attrs.put( attr );
 
-        try
-        {
-            ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
-            fail( "Deletion of Rdn attribute should fail." );
-        }
-        catch ( SchemaViolationException e )
-        {
-            // expected behaviour
-        }
-    }
+/**
+ * Remove a value which does not exist in an attribute making sure  
+ * it does not remove other values in that attribute.  Tests if the 
+ * following JIRA issue is still valid:
+ * 
+ *    https://issues.apache.org/jira/browse/DIRSERVER-1149
+ */
+@Test
+public void testRemoveAttemptWithoutChange() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
 
+    // Get the attributes and check the contents
+    Attributes tori = ctx.getAttributes( RDN );
+    assertNotNull( tori.get( "objectClass" ) );
+    assertNotNull( tori.get( "cn" ) );
+    assertEquals( 1, tori.get( "cn" ).size() );
+    assertEquals( "Tori Amos", tori.get( "cn" ).get() );
+    assertNotNull( tori.get( "sn" ) );
+
+    // Test an add operation first
+    ModificationItem mod = new ModificationItem( DirContext.ADD_ATTRIBUTE, new BasicAttribute( "cn", "foo" ) );
+    ctx.modifyAttributes( RDN, new ModificationItem[]
+        { mod } );
+    tori = ctx.getAttributes( RDN );
+    assertNotNull( tori.get( "objectClass" ) );
+    assertNotNull( tori.get( "cn" ) );
+    assertEquals( 2, tori.get( "cn" ).size() );
+    assertEquals( "Tori Amos", tori.get( "cn" ).get( 0 ) );
+    assertEquals( "foo", tori.get( "cn" ).get( 1 ) );
+    assertNotNull( tori.get( "sn" ) );
+
+    // Now test remove of value ( bar ) that does not exist in cn
+    mod = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, new BasicAttribute( "cn", "bar" ) );
+    try
+    {
+        ctx.modifyAttributes( RDN, new ModificationItem[]
+            { mod } );
+        fail();
+    }
+    catch ( NoSuchAttributeException nsae )
+    {
+        assertTrue( true );
+    }
+
+    tori = ctx.getAttributes( RDN );
+    assertNotNull( tori.get( "objectClass" ) );
+    assertNotNull( tori.get( "cn" ) );
+    assertEquals( 2, tori.get( "cn" ).size() );
+    assertEquals( "Tori Amos", tori.get( "cn" ).get( 0 ) );
+    assertEquals( "foo", tori.get( "cn" ).get( 1 ) );
+    assertNotNull( tori.get( "sn" ) );
+}
 
-    /**
-     * Remove a not required attribute from Rdn.
-     * 
-     * Expected Result: Deletion fails with SchemaViolationException.
-     */
-    @Test
-    public void testRemovePartOfRdnNotRequired() throws Exception
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // Change Rdn to another attribute
-        String newRdn = "description=an American singer-songwriter";
-        ctx.addToEnvironment( "java.naming.ldap.deleteRDN", "false" );
-        ctx.rename( RDN, newRdn );
-
-        // Remove description, which is now Rdn attribute
-        Attribute attr = new BasicAttribute( "description" );
-        Attributes attrs = new BasicAttributes( true );
-        attrs.put( attr );
 
-        try
-        {
-            ctx.modifyAttributes( newRdn, DirContext.REMOVE_ATTRIBUTE, attrs );
-            fail( "Deletion of Rdn attribute should fail." );
-        }
-        catch ( SchemaViolationException e )
-        {
-            // expected behaviour
-        }
+/**
+ * Remove an attribute, which is not required.
+ * 
+ * Expected result: After successful deletion, attribute is not present in
+ * entry.
+ */
+@Test
+public void testRemoveNotRequiredAttribute() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+    // Remove description Attribute
+    Attribute attr = new BasicAttribute( "description" );
+    Attributes attrs = new BasicAttributes( true );
+    attrs.put( attr );
+    ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
+
+    // Verify, that attribute is deleted
+    attrs = ctx.getAttributes( RDN );
+    attr = attrs.get( "description" );
+    assertNull( attr );
+}
+
+
+/**
+ * Remove two not required attributes.
+ * 
+ * Expected result: After successful deletion, both attributes ar not
+ * present in entry.
+ */
+@Test
+public void testRemoveTwoNotRequiredAttributes() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+    // add telephoneNumber to entry
+    Attributes tn = new BasicAttributes( "telephoneNumber", "12345678", true );
+    ctx.modifyAttributes( RDN, DirContext.ADD_ATTRIBUTE, tn );
+
+    // Remove description and telephoneNumber to Attribute
+    Attributes attrs = new BasicAttributes( true );
+    attrs.put( new BasicAttribute( "description" ) );
+    attrs.put( new BasicAttribute( "telephoneNumber" ) );
+    ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
+
+    // Verify, that attributes are deleted
+    attrs = ctx.getAttributes( RDN );
+    assertNull( attrs.get( "description" ) );
+    assertNull( attrs.get( "telephoneNumber" ) );
+    assertNotNull( attrs.get( "cn" ) );
+    assertNotNull( attrs.get( "sn" ) );
+}
+
 
-        // Change Rdn back to original
-        ctx.addToEnvironment( "java.naming.ldap.deleteRDN", "false" );
-        ctx.rename( newRdn, RDN );
+/**
+ * Remove a required attribute. The sn attribute of the person entry is used
+ * here.
+ * 
+ * Expected Result: Deletion fails with NamingException (Schema Violation).
+ */
+@Test
+public void testRemoveRequiredAttribute() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+    // Remove sn attribute
+    Attribute attr = new BasicAttribute( "sn" );
+    Attributes attrs = new BasicAttributes( true );
+    attrs.put( attr );
+
+    try
+    {
+        ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
+        fail( "Deletion of required attribute should fail." );
+    }
+    catch ( SchemaViolationException e )
+    {
+        // expected behaviour
     }
+}
+
 
+/**
+ * Remove a required attribute from Rdn.
+ * 
+ * Expected Result: Deletion fails with SchemaViolationException.
+ */
+@Test
+public void testRemovePartOfRdn() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
 
-    /**
-     * Remove a an attribute which is not present on the entry, but in the
-     * schema.
-     * 
-     * Expected result: Deletion fails with NoSuchAttributeException
-     */
-    @Test
-    public void testRemoveAttributeNotPresent() throws Exception
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // Remove telephoneNumber Attribute
-        Attribute attr = new BasicAttribute( "telephoneNumber" );
-        Attributes attrs = new BasicAttributes( true );
-        attrs.put( attr );
+    // Remove sn attribute
+    Attribute attr = new BasicAttribute( "cn" );
+    Attributes attrs = new BasicAttributes( true );
+    attrs.put( attr );
 
-        try
-        {
-            ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
-            fail( "Deletion of attribute, which is not present in the entry, should fail." );
-        }
-        catch ( NoSuchAttributeException e )
-        {
-            assertTrue( true );
-            // expected behaviour
-        }
+    try
+    {
+        ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
+        fail( "Deletion of Rdn attribute should fail." );
     }
+    catch ( SchemaViolationException e )
+    {
+        // expected behaviour
+    }
+}
 
 
-    /**
-     * Remove a an attribute value which is not present in the entry
-     * 
-     * Expected result: Deletion fails with NoSuchAttributeException
-     */
-    @Test
-    public void testRemoveAttributeValueNotPresent() throws Exception
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // Remove telephoneNumber Attribute
-        Attribute attr = new BasicAttribute( "telephoneNumber", "12345" );
-        Attributes attrs = new BasicAttributes( true );
-        attrs.put( attr );
-        
-        // Inject the new attribute
-        ctx.modifyAttributes( RDN, DirContext.ADD_ATTRIBUTE, attrs );
-
-        // Now try to remove a value which is not present
-        Attribute attr2 = new BasicAttribute( "telephoneNumber", "7890" );
-        Attributes attrs2 = new BasicAttributes( true );
-        attrs2.put( attr2 );
-    
-        try
-        {
-            ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs2 );
-            // We should get an exception
-            fail();
-        }
-        catch( NoSuchAttributeException nsae )
-        {
-            assertTrue( true );
-        }
+/**
+ * Remove a not required attribute from Rdn.
+ * 
+ * Expected Result: Deletion fails with SchemaViolationException.
+ */
+@Test
+public void testRemovePartOfRdnNotRequired() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+    // Change Rdn to another attribute
+    String newRdn = "description=an American singer-songwriter";
+    ctx.addToEnvironment( "java.naming.ldap.deleteRDN", "false" );
+    ctx.rename( RDN, newRdn );
+
+    // Remove description, which is now Rdn attribute
+    Attribute attr = new BasicAttribute( "description" );
+    Attributes attrs = new BasicAttributes( true );
+    attrs.put( attr );
+
+    try
+    {
+        ctx.modifyAttributes( newRdn, DirContext.REMOVE_ATTRIBUTE, attrs );
+        fail( "Deletion of Rdn attribute should fail." );
+    }
+    catch ( SchemaViolationException e )
+    {
+        // expected behaviour
     }
 
+    // Change Rdn back to original
+    ctx.addToEnvironment( "java.naming.ldap.deleteRDN", "false" );
+    ctx.rename( newRdn, RDN );
+}
 
-    /**
-     * Remove a an attribute which is not present in the schema.
-     * 
-     * Expected result: Deletion fails with NoSuchAttributeException
-     */
-    @Test
-    public void testRemoveAttributeNotValid() throws Exception
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // Remove phantasy attribute
-        Attribute attr = new BasicAttribute( "XXX" );
-        Attributes attrs = new BasicAttributes( true );
-        attrs.put( attr );
 
-        try
-        {
-            ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
-            fail( "Deletion of an invalid attribute should fail." );
-        }
-        catch ( NoSuchAttributeException e )
-        {
-            // expected behaviour
-        }
-        catch ( InvalidAttributeIdentifierException e )
-        {
-            // expected behaviour
-        }
+/**
+ * Remove a an attribute which is not present on the entry, but in the
+ * schema.
+ * 
+ * Expected result: Deletion fails with NoSuchAttributeException
+ */
+@Test
+public void testRemoveAttributeNotPresent() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+    // Remove telephoneNumber Attribute
+    Attribute attr = new BasicAttribute( "telephoneNumber" );
+    Attributes attrs = new BasicAttributes( true );
+    attrs.put( attr );
+
+    try
+    {
+        ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
+        fail( "Deletion of attribute, which is not present in the entry, should fail." );
+    }
+    catch ( NoSuchAttributeException e )
+    {
+        assertTrue( true );
+        // expected behaviour
     }
+}
 
 
-    /**
-     * Create a person entry and try to remove an attribute value
-     */
-    @Test
-    public void testReplaceNonExistingAttribute() throws Exception
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // Create an entry
-        Attributes attrs = getInetOrgPersonAttributes( "Bush", "Kate Bush" );
-        attrs.put( "givenname", "Kate" );
-        String rdn = "cn=Kate Bush";
-        ctx.createSubcontext( rdn, attrs );
-
-        // replace attribute givenName with empty value (=> deletion)
-        Attribute attr = new BasicAttribute( "givenname" );
-        ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
-        ctx.modifyAttributes( rdn, new ModificationItem[] { item } );
-
-        SearchControls sctls = new SearchControls();
-        sctls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        String filter = "(cn=Kate Bush)";
-        String base = "";
-        NamingEnumeration<SearchResult> enm = ctx.search( base, filter, sctls );
-        if ( enm.hasMore() )
-        {
-            SearchResult sr = enm.next();
-            attrs = sr.getAttributes();
-            Attribute cn = sr.getAttributes().get( "cn" );
-            assertNotNull( cn );
-            assertTrue( cn.contains( "Kate Bush" ) );
-
-            // Check whether attribute has been removed
-            Attribute givenName = sr.getAttributes().get( "givenname" );
-            assertNull( givenName );
-        }
-        else
-        {
-            fail( "entry not found" );
-        }
+/**
+ * Remove a an attribute value which is not present in the entry
+ * 
+ * Expected result: Deletion fails with NoSuchAttributeException
+ */
+@Test
+public void testRemoveAttributeValueNotPresent() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+    // Remove telephoneNumber Attribute
+    Attribute attr = new BasicAttribute( "telephoneNumber", "12345" );
+    Attributes attrs = new BasicAttributes( true );
+    attrs.put( attr );
+
+    // Inject the new attribute
+    ctx.modifyAttributes( RDN, DirContext.ADD_ATTRIBUTE, attrs );
+
+    // Now try to remove a value which is not present
+    Attribute attr2 = new BasicAttribute( "telephoneNumber", "7890" );
+    Attributes attrs2 = new BasicAttributes( true );
+    attrs2.put( attr2 );
 
-        ctx.destroySubcontext( rdn );
+    try
+    {
+        ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs2 );
+        // We should get an exception
+        fail();
+    }
+    catch ( NoSuchAttributeException nsae )
+    {
+        assertTrue( true );
     }
+}
+
+
+/**
+ * Remove a an attribute which is not present in the schema.
+ * 
+ * Expected result: Deletion fails with NoSuchAttributeException
+ */
+@Test
+public void testRemoveAttributeNotValid() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
 
+    // Remove phantasy attribute
+    Attribute attr = new BasicAttribute( "XXX" );
+    Attributes attrs = new BasicAttributes( true );
+    attrs.put( attr );
 
-    /**
-     * Create a person entry and try to remove an attribute value from the Rdn
-     * by Replacement
-     */
-    @Test
-    public void testReplaceRdnByEmptyValueAttribute() throws Exception
+    try
+    {
+        ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
+        fail( "Deletion of an invalid attribute should fail." );
+    }
+    catch ( NoSuchAttributeException e )
     {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // Create an entry
-        Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
-        String rdn = "cn=Kate Bush";
-        ctx.createSubcontext( rdn, attrs );
+        // expected behaviour
+    }
+    catch ( InvalidAttributeIdentifierException e )
+    {
+        // expected behaviour
+    }
+}
 
-        // replace attribute cn with empty value (=> deletion)
-        Attribute attr = new BasicAttribute( "cn" );
-        ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
 
-        try
-        {
-            ctx.modifyAttributes( rdn, new ModificationItem[]
-                { item } );
-            fail( "modify should fail" );
-        }
-        catch ( SchemaViolationException e )
-        {
-            // Expected behaviour
-        }
+/**
+ * Create a person entry and try to remove an attribute value
+ */
+@Test
+public void testReplaceNonExistingAttribute() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
 
-        ctx.destroySubcontext( rdn );
+    // Create an entry
+    Attributes attrs = getInetOrgPersonAttributes( "Bush", "Kate Bush" );
+    attrs.put( "givenname", "Kate" );
+    String rdn = "cn=Kate Bush";
+    ctx.createSubcontext( rdn, attrs );
+
+    // replace attribute givenName with empty value (=> deletion)
+    Attribute attr = new BasicAttribute( "givenname" );
+    ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+    ctx.modifyAttributes( rdn, new ModificationItem[]
+        { item } );
+
+    SearchControls sctls = new SearchControls();
+    sctls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+    String filter = "(cn=Kate Bush)";
+    String base = "";
+    NamingEnumeration<SearchResult> enm = ctx.search( base, filter, sctls );
+    if ( enm.hasMore() )
+    {
+        SearchResult sr = enm.next();
+        attrs = sr.getAttributes();
+        Attribute cn = sr.getAttributes().get( "cn" );
+        assertNotNull( cn );
+        assertTrue( cn.contains( "Kate Bush" ) );
+
+        // Check whether attribute has been removed
+        Attribute givenName = sr.getAttributes().get( "givenname" );
+        assertNull( givenName );
+    }
+    else
+    {
+        fail( "entry not found" );
     }
 
+    ctx.destroySubcontext( rdn );
+}
+
 
-    /**
-     * Create a person entry and try to remove an attribute from the Rdn
-     */
-    @Test
-    public void testRemoveRdnAttribute() throws Exception
+/**
+ * Create a person entry and try to remove an attribute value from the Rdn
+ * by Replacement
+ */
+@Test
+public void testReplaceRdnByEmptyValueAttribute() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+    // Create an entry
+    Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
+    String rdn = "cn=Kate Bush";
+    ctx.createSubcontext( rdn, attrs );
+
+    // replace attribute cn with empty value (=> deletion)
+    Attribute attr = new BasicAttribute( "cn" );
+    ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+
+    try
+    {
+        ctx.modifyAttributes( rdn, new ModificationItem[]
+            { item } );
+        fail( "modify should fail" );
+    }
+    catch ( SchemaViolationException e )
     {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // Create an entry
-        Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
-        String rdn = "cn=Kate Bush";
-        ctx.createSubcontext( rdn, attrs );
+        // Expected behaviour
+    }
+
+    ctx.destroySubcontext( rdn );
+}
 
-        // replace attribute cn with empty value (=> deletion)
-        Attribute attr = new BasicAttribute( "cn" );
-        ModificationItem item = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attr );
 
-        try
-        {
-            ctx.modifyAttributes( rdn, new ModificationItem[]
-                { item } );
-            fail( "modify should fail" );
-        }
-        catch ( SchemaViolationException e )
-        {
-            // Expected behaviour
-        }
+/**
+ * Create a person entry and try to remove an attribute from the Rdn
+ */
+@Test
+public void testRemoveRdnAttribute() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+    // Create an entry
+    Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
+    String rdn = "cn=Kate Bush";
+    ctx.createSubcontext( rdn, attrs );
 
-        ctx.destroySubcontext( rdn );
+    // replace attribute cn with empty value (=> deletion)
+    Attribute attr = new BasicAttribute( "cn" );
+    ModificationItem item = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attr );
+
+    try
+    {
+        ctx.modifyAttributes( rdn, new ModificationItem[]
+            { item } );
+        fail( "modify should fail" );
+    }
+    catch ( SchemaViolationException e )
+    {
+        // Expected behaviour
     }
 
+    ctx.destroySubcontext( rdn );
+}
+
+
+/**
+ * Create a person entry and try to remove an attribute from the Rdn
+ */
+@Test
+public void testRemoveRdnAttributeValue() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+    // Create an entry
+    Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
+    String rdn = "cn=Kate Bush";
+    ctx.createSubcontext( rdn, attrs );
+
+    // replace attribute cn with empty value (=> deletion)
+    Attribute attr = new BasicAttribute( "cn", "Kate Bush" );
+    ModificationItem item = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attr );
 
-    /**
-     * Create a person entry and try to remove an attribute from the Rdn
-     */
-    @Test
-    public void testRemoveRdnAttributeValue() throws Exception
+    try
+    {
+        ctx.modifyAttributes( rdn, new ModificationItem[]
+            { item } );
+        fail( "modify should fail" );
+    }
+    catch ( SchemaViolationException e )
     {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // Create an entry
-        Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
-        String rdn = "cn=Kate Bush";
-        ctx.createSubcontext( rdn, attrs );
+        // Expected behaviour
+    }
+
+    ctx.destroySubcontext( rdn );
+}
 
-        // replace attribute cn with empty value (=> deletion)
-        Attribute attr = new BasicAttribute( "cn", "Kate Bush" );
-        ModificationItem item = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attr );
 
-        try
-        {
-            ctx.modifyAttributes( rdn, new ModificationItem[]
-                { item } );
-            fail( "modify should fail" );
-        }
-        catch ( SchemaViolationException e )
-        {
-            // Expected behaviour
-        }
+/**
+ * Create a person entry and try to remove objectClass attribute
+ */
+@Test
+public void testDeleteOclAttrWithTopPersonOrganizationalpersonInetorgperson() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+    // Create an entry
+    Attributes attrs = getInetOrgPersonAttributes( "Bush", "Kate Bush" );
+    String rdn = "cn=Kate Bush";
+    ctx.createSubcontext( rdn, attrs );
 
-        ctx.destroySubcontext( rdn );
+    ModificationItem delModOp = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, new BasicAttribute( "objectclass",
+        "" ) );
+
+    try
+    {
+        ctx.modifyAttributes( rdn, new ModificationItem[]
+            { delModOp } );
+        fail( "deletion of objectclass should fail" );
+    }
+    catch ( SchemaViolationException e )
+    {
+        // expected
+    }
+    catch ( NoSuchAttributeException e )
+    {
+        // expected
+    }
+    catch ( InvalidAttributeValueException e )
+    {
+        // expected
+    }
+    catch ( Exception e )
+    {
+        e.printStackTrace();
     }
 
-    
-    /**
-     * Create a person entry and try to remove objectClass attribute
-     */
-    @Test
-    public void testDeleteOclAttrWithTopPersonOrganizationalpersonInetorgperson() throws Exception 
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // Create an entry
-        Attributes attrs = getInetOrgPersonAttributes("Bush", "Kate Bush");
-        String rdn = "cn=Kate Bush";
-        ctx.createSubcontext(rdn, attrs);
-
-        ModificationItem delModOp = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("objectclass", ""));
-
-        try {
-            ctx.modifyAttributes(rdn, new ModificationItem[] { delModOp });
-            fail("deletion of objectclass should fail");
-        } catch (SchemaViolationException e) {
-            // expected
-        } catch (NoSuchAttributeException e) {
-            // expected
-        } catch (InvalidAttributeValueException e) {
-            // expected
-        } catch ( Exception e ) {
-            e.printStackTrace();
-        }
-
-        ctx.destroySubcontext(rdn);
-    }
-
-    
-    /**
-     * Create a person entry and try to remove objectClass attribute. A variant
-     * which works.
-     */
-    @Test
-    public void testDeleteOclAttrWithTopPersonOrganizationalpersonInetorgpersonVariant() throws Exception 
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // Create an entry
-        Attributes attrs = getInetOrgPersonAttributes("Bush", "Kate Bush");
-        String rdn = "cn=Kate Bush";
-        ctx.createSubcontext(rdn, attrs);
-
-        ModificationItem delModOp = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("objectclass"));
-
-        try {
-            ctx.modifyAttributes(rdn, new ModificationItem[] { delModOp });
-            fail("deletion of objectclass should fail");
-        } catch (SchemaViolationException e) {
-            // expected
-        }
-
-        ctx.destroySubcontext(rdn);
-    }
-    
-    /**
-     * Test for DIRSERVER-1308:
-     * Remove an objectClass and a mandatory attribute.
-     * 
-     * Expected result: After successful deletion, both the objectClass
-     * and the attribute are not present in entry.
-     */
-    @Test
-    public void testRemoveObjectClassAndMandatoryAttribute() throws Exception
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        // add objectClass:krb5Principal and krb5PrincipalName:test to entry
-        Attributes tn = new BasicAttributes( true );
-        tn.put( new BasicAttribute( "objectClass", "krb5Principal", true ) );
-        tn.put( new BasicAttribute( "krb5PrincipalName", "test", true ) );
-        ctx.modifyAttributes( RDN, DirContext.ADD_ATTRIBUTE, tn );
-
-        // remove objectClass:krb5Principal and krb5PrincipalName
-        Attributes attrs = new BasicAttributes( true );
-        attrs.put( new BasicAttribute( "objectClass", "krb5Principal", true ) );
-        attrs.put( new BasicAttribute( "krb5PrincipalName" ) );
-        ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
+    ctx.destroySubcontext( rdn );
+}
+
+
+/**
+ * Create a person entry and try to remove objectClass attribute. A variant
+ * which works.
+ */
+@Test
+public void testDeleteOclAttrWithTopPersonOrganizationalpersonInetorgpersonVariant() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+    // Create an entry
+    Attributes attrs = getInetOrgPersonAttributes( "Bush", "Kate Bush" );
+    String rdn = "cn=Kate Bush";
+    ctx.createSubcontext( rdn, attrs );
+
+    ModificationItem delModOp = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, new BasicAttribute( "objectclass" ) );
 
-        // Verify, that attributes are deleted
-        attrs = ctx.getAttributes( RDN );
-        assertNotNull( attrs.get( "objectClass" ) );
-        assertFalse( attrs.get( "objectClass" ).contains( "krb5Principal" ) );
-        assertNull( attrs.get( "krb5PrincipalName" ) );
-        assertNotNull( attrs.get( "cn" ) );
-        assertNotNull( attrs.get( "sn" ) );
+    try
+    {
+        ctx.modifyAttributes( rdn, new ModificationItem[]
+            { delModOp } );
+        fail( "deletion of objectclass should fail" );
+    }
+    catch ( SchemaViolationException e )
+    {
+        // expected
     }
+
+    ctx.destroySubcontext( rdn );
+}
+
+
+/**
+ * Test for DIRSERVER-1308:
+ * Remove an objectClass and a mandatory attribute.
+ * 
+ * Expected result: After successful deletion, both the objectClass
+ * and the attribute are not present in entry.
+ */
+@Test
+public void testRemoveObjectClassAndMandatoryAttribute() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+    // add objectClass:krb5Principal and krb5PrincipalName:test to entry
+    Attributes tn = new BasicAttributes( true );
+    tn.put( new BasicAttribute( "objectClass", "krb5Principal", true ) );
+    tn.put( new BasicAttribute( "krb5PrincipalName", "test", true ) );
+    ctx.modifyAttributes( RDN, DirContext.ADD_ATTRIBUTE, tn );
+
+    // remove objectClass:krb5Principal and krb5PrincipalName
+    Attributes attrs = new BasicAttributes( true );
+    attrs.put( new BasicAttribute( "objectClass", "krb5Principal", true ) );
+    attrs.put( new BasicAttribute( "krb5PrincipalName" ) );
+    ctx.modifyAttributes( RDN, DirContext.REMOVE_ATTRIBUTE, attrs );
+
+    // Verify, that attributes are deleted
+    attrs = ctx.getAttributes( RDN );
+    assertNotNull( attrs.get( "objectClass" ) );
+    assertFalse( attrs.get( "objectClass" ).contains( "krb5Principal" ) );
+    assertNull( attrs.get( "krb5PrincipalName" ) );
+    assertNotNull( attrs.get( "cn" ) );
+    assertNotNull( attrs.get( "sn" ) );
+}
 }

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyReplaceIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyReplaceIT.java?rev=1235328&r1=1235327&r2=1235328&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyReplaceIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/ModifyReplaceIT.java Tue Jan 24 16:22:33 2012
@@ -55,267 +55,273 @@ import org.junit.runner.RunWith;
  * Demonstrates DIRSERVER-646 ("Replacing an unknown attribute with
  * no values (deletion) causes an error").
  */
-@RunWith ( FrameworkRunner.class ) 
-@CreateDS( enableChangeLog=true, name="ModifyReplaceIT-class" )
-@CreateLdapServer ( 
-    transports = 
-    {
-        @CreateTransport( protocol = "LDAP" ), 
-        @CreateTransport( protocol = "LDAPS" ) 
+@RunWith(FrameworkRunner.class)
+@CreateDS(enableChangeLog = true, name = "ModifyReplaceIT-class")
+@CreateLdapServer(
+    transports =
+        {
+            @CreateTransport(protocol = "LDAP"),
+            @CreateTransport(protocol = "LDAPS")
     })
-@ApplyLdifs( {
-    // Entry # 1
-    "dn: cn=Kate Bush,ou=system",
-    "objectClass: top",
-    "objectClass: person",
-    "sn: Bush",
-    "cn: Kate Bush",
-
-    // Entry # 2
-    "dn: cn=Kim Wilde,ou=system",
-    "objectClass: top",
-    "objectClass: person",
-    "objectClass: organizationalPerson ",
-    "objectClass: inetOrgPerson ",
-    "sn: Wilde",
-    "cn: Kim Wilde" 
+@ApplyLdifs(
+    {
+        // Entry # 1
+        "dn: cn=Kate Bush,ou=system",
+        "objectClass: top",
+        "objectClass: person",
+        "sn: Bush",
+        "cn: Kate Bush",
+
+        // Entry # 2
+        "dn: cn=Kim Wilde,ou=system",
+        "objectClass: top",
+        "objectClass: person",
+        "objectClass: organizationalPerson ",
+        "objectClass: inetOrgPerson ",
+        "sn: Wilde",
+        "cn: Kim Wilde"
+})
+public class ModifyReplaceIT extends AbstractLdapTestUnit
+{
+private static final String BASE = "ou=system";
+
+
+/**
+ * Create a person entry and try to remove a not present attribute
+ */
+@Test
+public void testReplaceToRemoveNotPresentAttribute() throws Exception
+{
+    DirContext sysRoot = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+    String rdn = "cn=Kate Bush";
+
+    Attribute attr = new BasicAttribute( "description" );
+    ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+
+    sysRoot.modifyAttributes( rdn, new ModificationItem[]
+        { item } );
+
+    SearchControls sctls = new SearchControls();
+    sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+    String filter = "(sn=Bush)";
+    String base = "";
+
+    NamingEnumeration<SearchResult> enm = sysRoot.search( base, filter, sctls );
+
+    while ( enm.hasMore() )
+    {
+        SearchResult sr = ( SearchResult ) enm.next();
+        Attribute cn = sr.getAttributes().get( "cn" );
+        assertNotNull( cn );
+        assertTrue( cn.contains( "Kate Bush" ) );
+        Attribute desc = sr.getAttributes().get( "description" );
+        assertNull( desc );
     }
-)
-public class ModifyReplaceIT extends AbstractLdapTestUnit 
+}
+
+
+/**
+ * Create a person entry and try to add a not present attribute via a REPLACE
+ */
+@Test
+public void testReplaceToAddNotPresentAttribute() throws Exception
 {
-    private static final String BASE = "ou=system";
-    
-    /**
-     * Create a person entry and try to remove a not present attribute
-     */
-    @Test
-    public void testReplaceToRemoveNotPresentAttribute() throws Exception
-    {
-        DirContext sysRoot = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        String rdn = "cn=Kate Bush";
-
-        Attribute attr = new BasicAttribute( "description" );
-        ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
-
-        sysRoot.modifyAttributes( rdn, new ModificationItem[] { item } );
-
-        SearchControls sctls = new SearchControls();
-        sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        String filter = "(sn=Bush)";
-        String base = "";
-
-        NamingEnumeration<SearchResult> enm = sysRoot.search( base, filter, sctls );
-        
-        while ( enm.hasMore() ) 
-        {
-            SearchResult sr = ( SearchResult ) enm.next();
-            Attribute cn = sr.getAttributes().get( "cn" );
-            assertNotNull( cn );
-            assertTrue( cn.contains( "Kate Bush") );
-            Attribute desc = sr.getAttributes().get( "description" );
-            assertNull( desc );
-        }
-    }
-    
-    
-    /**
-     * Create a person entry and try to add a not present attribute via a REPLACE
-     */
-    @Test
-    public void testReplaceToAddNotPresentAttribute() throws Exception 
-    {
-        DirContext sysRoot = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        String rdn = "cn=Kate Bush";
-
-        Attribute attr = new BasicAttribute( "description", "added description" );
-        ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
-
-        sysRoot.modifyAttributes( rdn, new ModificationItem[] { item } );
-
-        SearchControls sctls = new SearchControls();
-        sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        String filter = "(sn=Bush)";
-        String base = "";
-
-        NamingEnumeration<SearchResult> enm = sysRoot.search( base, filter, sctls );
-        
-        while ( enm.hasMore() ) 
-        {
-            SearchResult sr = ( SearchResult ) enm.next();
-            Attribute cn = sr.getAttributes().get( "cn" );
-            assertNotNull( cn );
-            assertTrue( cn.contains( "Kate Bush") );
-            Attribute desc = sr.getAttributes().get( "description" );
-            assertNotNull( desc );
-            assertTrue( desc.contains( "added description") );
-            assertEquals( 1, desc.size() );
-        }
-    }
-    
-    
-    /**
-     * Create a person entry and try to remove a non existing attribute
-     */
-    @Test
-    public void testReplaceNonExistingAttribute() throws Exception 
-    {
-        DirContext sysRoot = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        String rdn = "cn=Kate Bush";
+    DirContext sysRoot = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
 
-        Attribute attr = new BasicAttribute( "numberOfOctaves" );
-        ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+    String rdn = "cn=Kate Bush";
 
-        try
-        {
-            sysRoot.modifyAttributes( rdn, new ModificationItem[] { item } );
-            fail();
-        }
-        catch ( InvalidAttributeIdentifierException iaie )
-        {
-            assertTrue( true );
-        }
+    Attribute attr = new BasicAttribute( "description", "added description" );
+    ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
 
-        SearchControls sctls = new SearchControls();
-        sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        String filter = "(sn=Bush)";
-        String base = "";
-
-        NamingEnumeration<SearchResult> enm = sysRoot.search( base, filter, sctls );
-        
-        while ( enm.hasMore() ) 
-        {
-            SearchResult sr = enm.next();
-            Attribute cn = sr.getAttributes().get( "cn" );
-            assertNotNull( cn );
-            assertTrue( cn.contains( "Kate Bush" ) );
-        }
+    sysRoot.modifyAttributes( rdn, new ModificationItem[]
+        { item } );
+
+    SearchControls sctls = new SearchControls();
+    sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+    String filter = "(sn=Bush)";
+    String base = "";
+
+    NamingEnumeration<SearchResult> enm = sysRoot.search( base, filter, sctls );
+
+    while ( enm.hasMore() )
+    {
+        SearchResult sr = ( SearchResult ) enm.next();
+        Attribute cn = sr.getAttributes().get( "cn" );
+        assertNotNull( cn );
+        assertTrue( cn.contains( "Kate Bush" ) );
+        Attribute desc = sr.getAttributes().get( "description" );
+        assertNotNull( desc );
+        assertTrue( desc.contains( "added description" ) );
+        assertEquals( 1, desc.size() );
     }
+}
 
 
-    /**
-     * Create a person entry and try to remove a non existing attribute
-     */
-    @Test
-    public void testReplaceNonExistingAttributeManyMods() throws Exception 
-    {
-        DirContext sysRoot = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        String rdn = "cn=Kate Bush";
-
-        Attribute attr = new BasicAttribute( "numberOfOctaves" );
-        ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
-        Attribute attr2 = new BasicAttribute( "description", "blah blah blah" );
-        ModificationItem item2 = new ModificationItem( DirContext.ADD_ATTRIBUTE, attr2 );
+/**
+ * Create a person entry and try to remove a non existing attribute
+ */
+@Test
+public void testReplaceNonExistingAttribute() throws Exception
+{
+    DirContext sysRoot = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
 
-        try
-        {
-            sysRoot.modifyAttributes(rdn, new ModificationItem[] { item, item2 });
-            fail();
-        }
-        catch ( InvalidAttributeIdentifierException iaie )
-        {
-            assertTrue( true );
-        }
+    String rdn = "cn=Kate Bush";
 
-        SearchControls sctls = new SearchControls();
-        sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        String filter = "(sn=Bush)";
-        String base = "";
+    Attribute attr = new BasicAttribute( "numberOfOctaves" );
+    ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
 
-        NamingEnumeration<SearchResult> enm = sysRoot.search( base, filter, sctls );
-        while ( enm.hasMore() ) 
-        {
-            SearchResult sr = enm.next();
-            Attribute cn = sr.getAttributes().get( "cn" );
-            assertNotNull( cn );
-            assertTrue( cn.contains( "Kate Bush" ) );
-        }
+    try
+    {
+        sysRoot.modifyAttributes( rdn, new ModificationItem[]
+            { item } );
+        fail();
     }
+    catch ( InvalidAttributeIdentifierException iaie )
+    {
+        assertTrue( true );
+    }
+
+    SearchControls sctls = new SearchControls();
+    sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+    String filter = "(sn=Bush)";
+    String base = "";
 
+    NamingEnumeration<SearchResult> enm = sysRoot.search( base, filter, sctls );
 
-    /**
-     * Create a person entry and try to replace a non existing indexed attribute
-     */
-    @Test
-    public void testReplaceNonExistingIndexedAttribute() throws Exception 
+    while ( enm.hasMore() )
     {
-        DirContext sysRoot = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        String rdn = "cn=Kim Wilde";
+        SearchResult sr = enm.next();
+        Attribute cn = sr.getAttributes().get( "cn" );
+        assertNotNull( cn );
+        assertTrue( cn.contains( "Kate Bush" ) );
+    }
+}
 
-        Attribute attr = new BasicAttribute( "ou", "test" );
-        ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
 
-        sysRoot.modifyAttributes(rdn, new ModificationItem[] { item });
+/**
+ * Create a person entry and try to remove a non existing attribute
+ */
+@Test
+public void testReplaceNonExistingAttributeManyMods() throws Exception
+{
+    DirContext sysRoot = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
 
-        SearchControls sctls = new SearchControls();
-        sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        String filter = "(sn=Wilde)";
-        String base = "";
+    String rdn = "cn=Kate Bush";
 
-        NamingEnumeration<SearchResult> enm = sysRoot.search( base, filter, sctls );
-        
-        while ( enm.hasMore() ) 
-        {
-            SearchResult sr = enm.next();
-            Attribute ou = sr.getAttributes().get( "ou" );
-            assertNotNull( ou );
-            assertTrue( ou.contains( "test" ) );
-        }
-    }
-    
-    
-    /**
-     * Create a person entry, replace telephoneNumber, verify the 
-     * case of the attribute description attribute.
-     */
-    @Test
-    public void testReplaceCaseOfAttributeDescription() throws Exception
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        String rdn = "cn=Kate Bush";
-
-        // Replace telephoneNumber
-        String newValue = "2345678901";
-        Attributes attrs = new BasicAttributes( "telephoneNumber", newValue, false );
-        ctx.modifyAttributes( rdn, DirContext.REPLACE_ATTRIBUTE, attrs );
+    Attribute attr = new BasicAttribute( "numberOfOctaves" );
+    ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+    Attribute attr2 = new BasicAttribute( "description", "blah blah blah" );
+    ModificationItem item2 = new ModificationItem( DirContext.ADD_ATTRIBUTE, attr2 );
 
-        // Verify, that
-        // - case of attribute description is correct
-        // - attribute value is added 
-        attrs = ctx.getAttributes( rdn );
-        Attribute attr = attrs.get( "telephoneNumber" );
-        assertNotNull( attr );
-        assertEquals( "telephoneNumber", attr.getID() );
-        assertTrue( attr.contains( newValue ) );
-        assertEquals( 1, attr.size() );
-    }
-    
-    
-    /**
-     * Create a person entry, replace an attribute not present in the ObjectClasses
-     */
-    @Test
-    public void testReplaceAttributeNotInOC() throws Exception
-    {
-        DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        String rdn = "cn=Kate Bush";
-
-        // Replace ou
-        String newValue = "Test";
-        Attributes attrs = new BasicAttributes( "ou", newValue, false );
-        
-        try
-        {
-            ctx.modifyAttributes( rdn, DirContext.REPLACE_ATTRIBUTE, attrs );
-            fail( "Should get a SchemaViolationException" );
-        }
-        catch ( SchemaViolationException sve )
-        {
-            assertTrue( true );
-        }
+    try
+    {
+        sysRoot.modifyAttributes( rdn, new ModificationItem[]
+            { item, item2 } );
+        fail();
+    }
+    catch ( InvalidAttributeIdentifierException iaie )
+    {
+        assertTrue( true );
+    }
+
+    SearchControls sctls = new SearchControls();
+    sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+    String filter = "(sn=Bush)";
+    String base = "";
+
+    NamingEnumeration<SearchResult> enm = sysRoot.search( base, filter, sctls );
+    while ( enm.hasMore() )
+    {
+        SearchResult sr = enm.next();
+        Attribute cn = sr.getAttributes().get( "cn" );
+        assertNotNull( cn );
+        assertTrue( cn.contains( "Kate Bush" ) );
+    }
+}
+
+
+/**
+ * Create a person entry and try to replace a non existing indexed attribute
+ */
+@Test
+public void testReplaceNonExistingIndexedAttribute() throws Exception
+{
+    DirContext sysRoot = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+
+    String rdn = "cn=Kim Wilde";
+
+    Attribute attr = new BasicAttribute( "ou", "test" );
+    ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+
+    sysRoot.modifyAttributes( rdn, new ModificationItem[]
+        { item } );
+
+    SearchControls sctls = new SearchControls();
+    sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+    String filter = "(sn=Wilde)";
+    String base = "";
+
+    NamingEnumeration<SearchResult> enm = sysRoot.search( base, filter, sctls );
+
+    while ( enm.hasMore() )
+    {
+        SearchResult sr = enm.next();
+        Attribute ou = sr.getAttributes().get( "ou" );
+        assertNotNull( ou );
+        assertTrue( ou.contains( "test" ) );
     }
 }
+
+
+/**
+ * Create a person entry, replace telephoneNumber, verify the 
+ * case of the attribute description attribute.
+ */
+@Test
+public void testReplaceCaseOfAttributeDescription() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+    String rdn = "cn=Kate Bush";
+
+    // Replace telephoneNumber
+    String newValue = "2345678901";
+    Attributes attrs = new BasicAttributes( "telephoneNumber", newValue, false );
+    ctx.modifyAttributes( rdn, DirContext.REPLACE_ATTRIBUTE, attrs );
+
+    // Verify, that
+    // - case of attribute description is correct
+    // - attribute value is added 
+    attrs = ctx.getAttributes( rdn );
+    Attribute attr = attrs.get( "telephoneNumber" );
+    assertNotNull( attr );
+    assertEquals( "telephoneNumber", attr.getID() );
+    assertTrue( attr.contains( newValue ) );
+    assertEquals( 1, attr.size() );
+}
+
+
+/**
+ * Create a person entry, replace an attribute not present in the ObjectClasses
+ */
+@Test
+public void testReplaceAttributeNotInOC() throws Exception
+{
+    DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
+    String rdn = "cn=Kate Bush";
+
+    // Replace ou
+    String newValue = "Test";
+    Attributes attrs = new BasicAttributes( "ou", newValue, false );
+
+    try
+    {
+        ctx.modifyAttributes( rdn, DirContext.REPLACE_ATTRIBUTE, attrs );
+        fail( "Should get a SchemaViolationException" );
+    }
+    catch ( SchemaViolationException sve )
+    {
+        assertTrue( true );
+    }
+}
+}

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyDnReferralIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyDnReferralIT.java?rev=1235328&r1=1235327&r2=1235328&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyDnReferralIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyDnReferralIT.java Tue Jan 24 16:22:33 2012
@@ -58,242 +58,250 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-@RunWith ( FrameworkRunner.class ) 
-@CreateLdapServer ( 
-    transports = 
-    {
-        @CreateTransport( protocol = "LDAP" )
+@RunWith(FrameworkRunner.class)
+@CreateLdapServer(
+    transports =
+        {
+            @CreateTransport(protocol = "LDAP")
     })
-@ApplyLdifs( {
-    // Entry # 1
-    "dn: uid=akarasulu,ou=users,ou=system",
-    "objectClass: uidObject",
-    "objectClass: person",
-    "objectClass: top",
-    "uid: akarasulu",
-    "cn: Alex Karasulu",
-    "sn: karasulu", 
-    
-    // Entry # 2
-    "dn: ou=Computers,uid=akarasulu,ou=users,ou=system",
-    "objectClass: organizationalUnit",
-    "objectClass: top",
-    "ou: computers",
-    "description: Computers for Alex",
-    "seeAlso: ou=Machines,uid=akarasulu,ou=users,ou=system", 
-    
-    // Entry # 3
-    "dn: uid=akarasuluref,ou=users,ou=system",
-    "objectClass: uidObject",
-    "objectClass: referral",
-    "objectClass: top",
-    "uid: akarasuluref",
-    "ref: ldap://localhost:10389/uid=akarasulu,ou=users,ou=system", 
-    "ref: ldap://foo:10389/uid=akarasulu,ou=users,ou=system",
-    "ref: ldap://bar:10389/uid=akarasulu,ou=users,ou=system",
-    
-    // Entry # 4
-    "dn: uid=elecharny,ou=users,ou=system",
-    "objectClass: uidObject",
-    "objectClass: person",
-    "objectClass: top",
-    "uid: elecharny",
-    "cn: Emmanuel Lecharny",
-    "sn: lecharny"
-    }
-)
+@ApplyLdifs(
+    {
+        // Entry # 1
+        "dn: uid=akarasulu,ou=users,ou=system",
+        "objectClass: uidObject",
+        "objectClass: person",
+        "objectClass: top",
+        "uid: akarasulu",
+        "cn: Alex Karasulu",
+        "sn: karasulu",
+
+        // Entry # 2
+        "dn: ou=Computers,uid=akarasulu,ou=users,ou=system",
+        "objectClass: organizationalUnit",
+        "objectClass: top",
+        "ou: computers",
+        "description: Computers for Alex",
+        "seeAlso: ou=Machines,uid=akarasulu,ou=users,ou=system",
+
+        // Entry # 3
+        "dn: uid=akarasuluref,ou=users,ou=system",
+        "objectClass: uidObject",
+        "objectClass: referral",
+        "objectClass: top",
+        "uid: akarasuluref",
+        "ref: ldap://localhost:10389/uid=akarasulu,ou=users,ou=system",
+        "ref: ldap://foo:10389/uid=akarasulu,ou=users,ou=system",
+        "ref: ldap://bar:10389/uid=akarasulu,ou=users,ou=system",
+
+        // Entry # 4
+        "dn: uid=elecharny,ou=users,ou=system",
+        "objectClass: uidObject",
+        "objectClass: person",
+        "objectClass: top",
+        "uid: elecharny",
+        "cn: Emmanuel Lecharny",
+        "sn: lecharny"
+})
 public class ModifyDnReferralIT extends AbstractLdapTestUnit
 {
-    private static final Logger LOG = LoggerFactory.getLogger( ModifyDnReferralIT.class );
-    
+private static final Logger LOG = LoggerFactory.getLogger( ModifyDnReferralIT.class );
 
-    /**
-     * Tests ModifyDN operation on referral entry with the ManageDsaIT control.
-     */
-    @Test
-    public void testOnReferralWithManageDsaITControl() throws Exception
-    {
-        LdapConnection conn = getWiredConnection( getLdapServer() );
-        
-        ManageDsaIT manageDSAIT = new ManageDsaITImpl();
-        manageDSAIT.setCritical( true );
-        
-        // ModifyDN success
-        ModifyDnRequest modifyDnRequest = new ModifyDnRequestImpl();
-        modifyDnRequest.setName( new Dn( "uid=akarasuluref,ou=users,ou=system" ) );
-        modifyDnRequest.setNewRdn( new Rdn( "uid=ref" ) );
-        modifyDnRequest.setDeleteOldRdn( true );
-        modifyDnRequest.addControl( manageDSAIT );
-        
-        conn.modifyDn( modifyDnRequest );
-        Entry entry = conn.lookup( "uid=ref,ou=users,ou=system", new Control[]{ manageDSAIT } );
-        assertNotNull( entry );
-        assertEquals( "uid=ref,ou=users,ou=system", entry.getDn().getName() );
-        
-        conn.close();
-    }
-    
-    
-    /**
-     * Tests ModifyDN operation with newSuperior on referral entry with the 
-     * ManageDsaIT control.
-     */
-    @Test
-    public void testNewSuperiorOnReferralWithManageDsaITControl() throws Exception
-    {
-        LdapConnection conn = getWiredConnection( getLdapServer() );
-
-        ManageDsaIT manageDSAIT = new ManageDsaITImpl();
-        manageDSAIT.setCritical( true );
-        
-        ModifyDnRequest modifyDnRequest = new ModifyDnRequestImpl();
-        modifyDnRequest.setName( new Dn( "uid=elecharny,ou=users,ou=system" ) );
-        modifyDnRequest.setNewRdn( new Rdn( "uid=newuser" ) );
-        modifyDnRequest.setNewSuperior( new Dn( "uid=akarasuluref,ou=users,ou=system" ) );
-        modifyDnRequest.setDeleteOldRdn( true );
-        modifyDnRequest.addControl( manageDSAIT );
 
-        // ModifyDN success
-        try
-        {
-            conn.modifyDn( modifyDnRequest );
-        }
-        catch ( LdapOperationException le )
-        {
-            assertEquals ( ResultCodeEnum.AFFECTS_MULTIPLE_DSAS, le.getResultCode() );
-        }
-        
-        conn.close();
-    }
-    
-    
-    /**
-     * Tests ModifyDN operation on normal and referral entries without the 
-     * ManageDsaIT control. Referrals are sent back to the client with a
-     * non-success result code.
-     */
-    @Test
-    public void testOnReferral() throws Exception
-    {
-        LdapConnection conn = getWiredConnection( getLdapServer() );
-        
-        // referrals failure
-        ModifyDnRequest modifyDnRequest = new ModifyDnRequestImpl();
-        modifyDnRequest.setName( new Dn( "uid=akarasuluref,ou=users,ou=system" ) );
-        modifyDnRequest.setNewRdn( new Rdn( "uid=ref" ) );
-        modifyDnRequest.setDeleteOldRdn( true );
-
-        ModifyDnResponse modifyDnResponse = conn.modifyDn( modifyDnRequest );
-
-        assertEquals( ResultCodeEnum.REFERRAL, modifyDnResponse.getLdapResult().getResultCode() );
-
-        assertTrue( modifyDnResponse.getLdapResult().getReferral().getLdapUrls().contains( "ldap://localhost:10389/uid=akarasulu,ou=users,ou=system" ) );
-        assertTrue( modifyDnResponse.getLdapResult().getReferral().getLdapUrls().contains( "ldap://foo:10389/uid=akarasulu,ou=users,ou=system" ) );
-        assertTrue( modifyDnResponse.getLdapResult().getReferral().getLdapUrls().contains( "ldap://bar:10389/uid=akarasulu,ou=users,ou=system" ) );
-
-        conn.close();
-    }
-    
-    
-    /**
-     * Tests ModifyDN operation on normal and referral entries without the 
-     * ManageDsaIT control. Referrals are sent back to the client with a
-     * non-success result code.
-     */
-    @Test
-    public void testNewSuperiorOnReferral() throws Exception
-    {
-        LdapConnection conn = getWiredConnection( getLdapServer() );
-        
-        // referrals failure
-        try
-        {
-            conn.moveAndRename( "uid=elecharny,ou=users,ou=system", "uid=ref,uid=akarasuluref,ou=users,ou=system", true );
-        }
-        catch ( LdapOperationException e )
-        {
-            assertEquals( ResultCodeEnum.AFFECTS_MULTIPLE_DSAS, e.getResultCode() );
-        }
+/**
+ * Tests ModifyDN operation on referral entry with the ManageDsaIT control.
+ */
+@Test
+public void testOnReferralWithManageDsaITControl() throws Exception
+{
+    LdapConnection conn = getWiredConnection( getLdapServer() );
+
+    ManageDsaIT manageDSAIT = new ManageDsaITImpl();
+    manageDSAIT.setCritical( true );
+
+    // ModifyDN success
+    ModifyDnRequest modifyDnRequest = new ModifyDnRequestImpl();
+    modifyDnRequest.setName( new Dn( "uid=akarasuluref,ou=users,ou=system" ) );
+    modifyDnRequest.setNewRdn( new Rdn( "uid=ref" ) );
+    modifyDnRequest.setDeleteOldRdn( true );
+    modifyDnRequest.addControl( manageDSAIT );
+
+    conn.modifyDn( modifyDnRequest );
+    Entry entry = conn.lookup( "uid=ref,ou=users,ou=system", new Control[]
+        { manageDSAIT } );
+    assertNotNull( entry );
+    assertEquals( "uid=ref,ou=users,ou=system", entry.getDn().getName() );
+
+    conn.close();
+}
 
-        conn.close();
-    }
-    
-    
-    /**
-     * Tests ModifyDN operation on normal and referral entries without the 
-     * ManageDsaIT control using JNDI instead of the Netscape API. Referrals 
-     * are sent back to the client with a non-success result code.
-     */
-    @Test
-    public void testThrowOnReferralWithJndi() throws Exception
-    {
-        LdapContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
-        
-        // ModifyDN referrals failure
-        try
-        {
-            ctx.rename( "uid=akarasuluref,ou=users,ou=system", "uid=ref,ou=users,ou=system" ); 
-            fail( "Should never get here due to ModifyDN failure on ReferralException" );
-        }
-        catch ( ReferralException e )
-        {
-            // seems JNDI only returns the first referral URL and not all so we test for it
-            assertEquals( "ldap://localhost:10389/uid=akarasulu,ou=users,ou=system", e.getReferralInfo() );
-        }
 
-        ctx.close();
+/**
+ * Tests ModifyDN operation with newSuperior on referral entry with the 
+ * ManageDsaIT control.
+ */
+@Test
+public void testNewSuperiorOnReferralWithManageDsaITControl() throws Exception
+{
+    LdapConnection conn = getWiredConnection( getLdapServer() );
+
+    ManageDsaIT manageDSAIT = new ManageDsaITImpl();
+    manageDSAIT.setCritical( true );
+
+    ModifyDnRequest modifyDnRequest = new ModifyDnRequestImpl();
+    modifyDnRequest.setName( new Dn( "uid=elecharny,ou=users,ou=system" ) );
+    modifyDnRequest.setNewRdn( new Rdn( "uid=newuser" ) );
+    modifyDnRequest.setNewSuperior( new Dn( "uid=akarasuluref,ou=users,ou=system" ) );
+    modifyDnRequest.setDeleteOldRdn( true );
+    modifyDnRequest.addControl( manageDSAIT );
+
+    // ModifyDN success
+    try
+    {
+        conn.modifyDn( modifyDnRequest );
     }
-    
-    
-    /**
-     * Tests referral handling when an ancestor is a referral.
-     */
-    @Test 
-    public void testAncestorReferral() throws Exception
+    catch ( LdapOperationException le )
     {
-        LOG.debug( "" );
+        assertEquals( ResultCodeEnum.AFFECTS_MULTIPLE_DSAS, le.getResultCode() );
+    }
+
+    conn.close();
+}
+
+
+/**
+ * Tests ModifyDN operation on normal and referral entries without the 
+ * ManageDsaIT control. Referrals are sent back to the client with a
+ * non-success result code.
+ */
+@Test
+public void testOnReferral() throws Exception
+{
+    LdapConnection conn = getWiredConnection( getLdapServer() );
+
+    // referrals failure
+    ModifyDnRequest modifyDnRequest = new ModifyDnRequestImpl();
+    modifyDnRequest.setName( new Dn( "uid=akarasuluref,ou=users,ou=system" ) );
+    modifyDnRequest.setNewRdn( new Rdn( "uid=ref" ) );
+    modifyDnRequest.setDeleteOldRdn( true );
+
+    ModifyDnResponse modifyDnResponse = conn.modifyDn( modifyDnRequest );
+
+    assertEquals( ResultCodeEnum.REFERRAL, modifyDnResponse.getLdapResult().getResultCode() );
+
+    assertTrue( modifyDnResponse.getLdapResult().getReferral().getLdapUrls()
+        .contains( "ldap://localhost:10389/uid=akarasulu,ou=users,ou=system" ) );
+    assertTrue( modifyDnResponse.getLdapResult().getReferral().getLdapUrls()
+        .contains( "ldap://foo:10389/uid=akarasulu,ou=users,ou=system" ) );
+    assertTrue( modifyDnResponse.getLdapResult().getReferral().getLdapUrls()
+        .contains( "ldap://bar:10389/uid=akarasulu,ou=users,ou=system" ) );
+
+    conn.close();
+}
 
-        LdapConnection conn = getWiredConnection( getLdapServer() );
 
-        // referrals failure
-        ModifyDnRequest modifyDnRequest = new ModifyDnRequestImpl();
-        modifyDnRequest.setName( new Dn( "ou=Computers,uid=akarasuluref,ou=users,ou=system" ) );
-        modifyDnRequest.setNewRdn( new Rdn( "ou=Machines" ) );
-        modifyDnRequest.setDeleteOldRdn( true );
+/**
+ * Tests ModifyDN operation on normal and referral entries without the 
+ * ManageDsaIT control. Referrals are sent back to the client with a
+ * non-success result code.
+ */
+@Test
+public void testNewSuperiorOnReferral() throws Exception
+{
+    LdapConnection conn = getWiredConnection( getLdapServer() );
 
-        ModifyDnResponse modifyDnResponse = conn.modifyDn( modifyDnRequest );
+    // referrals failure
+    try
+    {
+        conn.moveAndRename( "uid=elecharny,ou=users,ou=system", "uid=ref,uid=akarasuluref,ou=users,ou=system", true );
+    }
+    catch ( LdapOperationException e )
+    {
+        assertEquals( ResultCodeEnum.AFFECTS_MULTIPLE_DSAS, e.getResultCode() );
+    }
+
+    conn.close();
+}
 
-        assertEquals( ResultCodeEnum.REFERRAL, modifyDnResponse.getLdapResult().getResultCode() );
 
-        assertTrue( modifyDnResponse.getLdapResult().getReferral().getLdapUrls().contains( "ldap://localhost:10389/ou=Computers,uid=akarasulu,ou=users,ou=system" ) );
-        assertTrue( modifyDnResponse.getLdapResult().getReferral().getLdapUrls().contains( "ldap://foo:10389/ou=Computers,uid=akarasulu,ou=users,ou=system" ) );
-        assertTrue( modifyDnResponse.getLdapResult().getReferral().getLdapUrls().contains( "ldap://bar:10389/ou=Computers,uid=akarasulu,ou=users,ou=system" ) );
+/**
+ * Tests ModifyDN operation on normal and referral entries without the 
+ * ManageDsaIT control using JNDI instead of the Netscape API. Referrals 
+ * are sent back to the client with a non-success result code.
+ */
+@Test
+public void testThrowOnReferralWithJndi() throws Exception
+{
+    LdapContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
 
-        conn.close();
+    // ModifyDN referrals failure
+    try
+    {
+        ctx.rename( "uid=akarasuluref,ou=users,ou=system", "uid=ref,ou=users,ou=system" );
+        fail( "Should never get here due to ModifyDN failure on ReferralException" );
     }
-    
-    
-    /**
-     * Tests referral handling when an ancestor is a referral.
-     */
-    @Test 
-    public void testNewSuperiorAncestorReferral() throws Exception
+    catch ( ReferralException e )
     {
-        LOG.debug( "" );
+        // seems JNDI only returns the first referral URL and not all so we test for it
+        assertEquals( "ldap://localhost:10389/uid=akarasulu,ou=users,ou=system", e.getReferralInfo() );
+    }
 
-        LdapConnection conn = getWiredConnection( getLdapServer() );
+    ctx.close();
+}
 
-        // referrals failure
-        try
-        {
-            conn.moveAndRename( "uid=elecharny,ou=users,ou=system", "ou=Machines,ou=Computers,uid=akarasuluref,ou=users,ou=system", true );
-            fail( "Should never get here to affectsMultipleDSA error result code" );
-        }
-        catch ( LdapOperationException e )
-        {
-            assertEquals( ResultCodeEnum.AFFECTS_MULTIPLE_DSAS, e.getResultCode() );
-        }
 
-        conn.close();
+/**
+ * Tests referral handling when an ancestor is a referral.
+ */
+@Test
+public void testAncestorReferral() throws Exception
+{
+    LOG.debug( "" );
+
+    LdapConnection conn = getWiredConnection( getLdapServer() );
+
+    // referrals failure
+    ModifyDnRequest modifyDnRequest = new ModifyDnRequestImpl();
+    modifyDnRequest.setName( new Dn( "ou=Computers,uid=akarasuluref,ou=users,ou=system" ) );
+    modifyDnRequest.setNewRdn( new Rdn( "ou=Machines" ) );
+    modifyDnRequest.setDeleteOldRdn( true );
+
+    ModifyDnResponse modifyDnResponse = conn.modifyDn( modifyDnRequest );
+
+    assertEquals( ResultCodeEnum.REFERRAL, modifyDnResponse.getLdapResult().getResultCode() );
+
+    assertTrue( modifyDnResponse.getLdapResult().getReferral().getLdapUrls()
+        .contains( "ldap://localhost:10389/ou=Computers,uid=akarasulu,ou=users,ou=system" ) );
+    assertTrue( modifyDnResponse.getLdapResult().getReferral().getLdapUrls()
+        .contains( "ldap://foo:10389/ou=Computers,uid=akarasulu,ou=users,ou=system" ) );
+    assertTrue( modifyDnResponse.getLdapResult().getReferral().getLdapUrls()
+        .contains( "ldap://bar:10389/ou=Computers,uid=akarasulu,ou=users,ou=system" ) );
+
+    conn.close();
+}
+
+
+/**
+ * Tests referral handling when an ancestor is a referral.
+ */
+@Test
+public void testNewSuperiorAncestorReferral() throws Exception
+{
+    LOG.debug( "" );
+
+    LdapConnection conn = getWiredConnection( getLdapServer() );
+
+    // referrals failure
+    try
+    {
+        conn.moveAndRename( "uid=elecharny,ou=users,ou=system",
+            "ou=Machines,ou=Computers,uid=akarasuluref,ou=users,ou=system", true );
+        fail( "Should never get here to affectsMultipleDSA error result code" );
     }
+    catch ( LdapOperationException e )
+    {
+        assertEquals( ResultCodeEnum.AFFECTS_MULTIPLE_DSAS, e.getResultCode() );
+    }
+
+    conn.close();
+}
 }

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyRdnIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyRdnIT.java?rev=1235328&r1=1235327&r2=1235328&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyRdnIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyRdnIT.java Tue Jan 24 16:22:33 2012
@@ -54,12 +54,12 @@ import org.junit.runner.RunWith;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-@RunWith ( FrameworkRunner.class )
-@CreateDS( name="ModifyRdnIT-class", enableChangeLog=false )
-@CreateLdapServer ( 
-    transports = 
-    {
-        @CreateTransport( protocol = "LDAP" )
+@RunWith(FrameworkRunner.class)
+@CreateDS(name = "ModifyRdnIT-class", enableChangeLog = false)
+@CreateLdapServer(
+    transports =
+        {
+            @CreateTransport(protocol = "LDAP")
     })
 public class ModifyRdnIT extends AbstractLdapTestUnit
 {
@@ -71,7 +71,7 @@ public class ModifyRdnIT extends Abstrac
      */
     private Attributes getPersonAttributes( String sn, String cn ) throws Exception
     {
-        Attributes attributes = LdifUtils.createJndiAttributes( 
+        Attributes attributes = LdifUtils.createJndiAttributes(
             "objectClass: top",
             "objectClass: person",
             "cn", cn,
@@ -88,10 +88,10 @@ public class ModifyRdnIT extends Abstrac
     private Attributes getOrganizationalUnitAttributes( String ou ) throws Exception
     {
         Attributes attributes = LdifUtils.createJndiAttributes(
-                "objectClass: top",
-                "objectClass: organizationalUnit",
-                "ou", ou,
-                "description", ou + " is an organizational unit.");
+            "objectClass: top",
+            "objectClass: organizationalUnit",
+            "ou", ou,
+            "description", ou + " is an organizational unit." );
 
         return attributes;
     }
@@ -104,7 +104,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyRdnAndDeleteOld() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         // Create a person, cn value is rdn
         String oldCn = "Myra Ellen Amos";
         String oldRdn = "cn=" + oldCn;
@@ -153,7 +153,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyRdnAndDontDeleteOldFalse() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         // Create a person, cn value is rdn
         String oldCn = "Myra Ellen Amos";
         String oldRdn = "cn=" + oldCn;
@@ -200,7 +200,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyRdnAndKeepOld() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         // Create a person, cn value is rdn
         String oldCn = "Myra Ellen Amos";
         String oldRdn = "cn=" + oldCn;
@@ -248,7 +248,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyRdnAndDeleteOldVariant() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         // Create a person, cn value is rdn
         String oldCn = "Myra Ellen Amos";
         String oldRdn = "cn=" + oldCn;
@@ -303,7 +303,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyRdnDifferentAttribute() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         // Create a person, cn value is rdn
         String cnVal = "Tori Amos";
         String snVal = "Amos";
@@ -353,7 +353,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyRdnDifferentAttributeDeleteOldFails() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         // Create a person, cn value is rdn
         String cnVal = "Tori Amos";
         String snVal = "Amos";
@@ -388,7 +388,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyRdnAndDeleteOldWithChild() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         // Create an organizational unit, ou value is rdn
         String oldOu = "Writers";
         String oldRdn = "ou=" + oldOu;
@@ -458,7 +458,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyRdnWithEncodedNewRdn() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         // Create a person "cn=Tori Amos", cn value is rdn
         String cnVal = "Tori Amos";
         String snVal = "Amos";
@@ -494,7 +494,8 @@ public class ModifyRdnIT extends Abstrac
         // Check that cn contains the unescaped value
         Attribute cn = newCtx.getAttributes( "" ).get( "cn" );
         assertEquals( "Number of cn occurences", 1, cn.size() );
-        String expectedCn = new String( new byte[] { ( byte ) 0xC3, ( byte ) 0xA4, '+' }, "UTF-8" );
+        String expectedCn = new String( new byte[]
+            { ( byte ) 0xC3, ( byte ) 0xA4, '+' }, "UTF-8" );
         assertTrue( cn.contains( expectedCn ) );
 
         // Remove entry (use new rdn)
@@ -511,7 +512,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyRdnWithEscapedPoundNewRdn() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         // Create a person "cn=Tori Amos", cn value is rdn
         String cnVal = "Tori Amos";
         String snVal = "Amos";
@@ -565,7 +566,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyMultiValuedRdnVariant1() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         Attributes attributes = createPerson( "cn" );
         String oldRdn = getRdn( attributes, "cn" );
         String newRdn = getRdn( attributes, "cn", "sn" );
@@ -645,7 +646,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyMultiValuedRdnVariant3() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         Attributes attributes = createPerson( "description" );
         String oldRdn = getRdn( attributes, "description" );
         String newRdn = getRdn( attributes, "cn", "sn" );
@@ -685,7 +686,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyMultiValuedRdnVariant4() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         Attributes attributes = createPerson( "description" );
         String oldRdn = getRdn( attributes, "description" );
         String newRdn = getRdn( attributes, "cn", "sn" );
@@ -727,7 +728,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyMultiValuedRdnVariant5() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         Attributes attributes = createPerson( "cn" );
         attributes.put( "telephoneNumber", "12345" );
         String oldRdn = getRdn( attributes, "cn" );
@@ -773,7 +774,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyMultiValuedRdnVariant6() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         Attributes attributes = createPerson( "cn" );
         attributes.put( "telephoneNumber", "12345" );
         String oldRdn = getRdn( attributes, "cn" );
@@ -833,7 +834,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyMultiValuedRdnVariant7() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         Attributes attributes = createPerson( "cn", "sn" );
         String oldRdn = getRdn( attributes, "cn", "sn" );
         String newRdn = getRdn( attributes, "cn" );
@@ -875,7 +876,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyMultiValuedRdnVariant8() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         Attributes attributes = createPerson( "cn", "sn" );
         String oldRdn = getRdn( attributes, "cn", "sn" );
         String newRdn = getRdn( attributes, "cn" );
@@ -932,7 +933,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyRdnOperationalAttribute() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         // create the entry
         Attributes attributes = createPerson( "cn" );
         String oldRdn = getRdn( attributes, "cn" );
@@ -977,7 +978,7 @@ public class ModifyRdnIT extends Abstrac
     public void testModifyRdnObjectClassAttribute() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
+
         // create the entry
         Attributes attributes = createPerson( "cn" );
         String oldRdn = getRdn( attributes, "cn" );
@@ -1008,7 +1009,7 @@ public class ModifyRdnIT extends Abstrac
     private String getRdn( Attributes attributes, String... rdnTypes ) throws Exception
     {
         String rdn = "";
-        
+
         for ( String type : rdnTypes )
         {
             rdn += type + "=" + attributes.get( type ).get() + "+";
@@ -1022,8 +1023,8 @@ public class ModifyRdnIT extends Abstrac
     private Attributes createPerson( String... rdnTypes ) throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
-        
-        Attributes attributes = LdifUtils.createJndiAttributes( 
+
+        Attributes attributes = LdifUtils.createJndiAttributes(
             "objectClass: top",
             "objectClass: person",
             "cn: Tori Amos",

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/MoveIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/MoveIT.java?rev=1235328&r1=1235327&r2=1235328&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/MoveIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/MoveIT.java Tue Jan 24 16:22:33 2012
@@ -55,16 +55,29 @@ import org.junit.runner.RunWith;
 @ApplyLdifs(
     {
         // Entry # 1
-        "dn: uid=akarasulu,ou=users,ou=system", "objectClass: uidObject", "objectClass: person", "objectClass: top",
-        "uid: akarasulu", "cn: Alex Karasulu",
+        "dn: uid=akarasulu,ou=users,ou=system",
+        "objectClass: uidObject",
+        "objectClass: person",
+        "objectClass: top",
+        "uid: akarasulu",
+        "cn: Alex Karasulu",
         "sn: karasulu",
         // Entry # 2
-        "dn: ou=NewSuperior,ou=system", "objectClass: organizationalUnit", "objectClass: top", "ou: NewSuperior",
-
-        "dn: ou=parent,ou=system", "changetype: add", "objectClass: organizationalUnit", "objectClass: top",
+        "dn: ou=NewSuperior,ou=system",
+        "objectClass: organizationalUnit",
+        "objectClass: top",
+        "ou: NewSuperior",
+
+        "dn: ou=parent,ou=system",
+        "changetype: add",
+        "objectClass: organizationalUnit",
+        "objectClass: top",
         "ou: parent",
 
-        "dn: ou=child,ou=parent,ou=system", "changetype: add", "objectClass: organizationalUnit", "objectClass: top",
+        "dn: ou=child,ou=parent,ou=system",
+        "changetype: add",
+        "objectClass: organizationalUnit",
+        "objectClass: top",
         "ou: child" })
 public class MoveIT extends AbstractLdapTestUnit
 {
@@ -131,7 +144,7 @@ public class MoveIT extends AbstractLdap
         {
             assertTrue( true );
         }
-        
+
         con.close();
     }