directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1334639 [3/5] - in /directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server: operations/add/ operations/bind/ operations/compare/ operations/delete/ operations/extended/ operations/ldapsdk/ operations/lookup/ operat...
Date Sun, 06 May 2012 14:25:20 GMT
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=1334639&r1=1334638&r2=1334639&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 Sun May  6 14:25:18 2012
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.operations.modify;
 
@@ -42,12 +42,14 @@ import javax.naming.directory.SchemaViol
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 
+import org.apache.directory.junit.tools.MultiThreadedMultiInvoker;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.annotations.ApplyLdifs;
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -77,621 +79,623 @@ import org.junit.runner.RunWith;
 })
 public class ModifyRemoveIT extends AbstractLdapTestUnit
 {
-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
-    {
+    @Rule
+    public MultiThreadedMultiInvoker i = new MultiThreadedMultiInvoker( MultiThreadedMultiInvoker.NOT_THREADSAFE );
+    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 } );
-        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 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" ) );
-}
-
-
-/**
- * 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
-    {
+        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 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 );
-        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 sn attribute
-    Attribute attr = new BasicAttribute( "cn" );
-    Attributes attrs = new BasicAttributes( true );
-    attrs.put( attr );
-
-    try
-    {
+    
+        // 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 );
-        fail( "Deletion of Rdn attribute should fail." );
-    }
-    catch ( SchemaViolationException e )
-    {
-        // expected behaviour
-    }
-}
-
-
-/**
- * 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 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
-    }
-}
-
-
-/**
- * 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 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
-    }
-}
-
-
-/**
- * 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" );
-    }
-
-    ctx.destroySubcontext( rdn );
-}
-
-
-/**
- * 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" );
+    
+        // 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" ) );
+    }
+    
+    
+    /**
+     * 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
+        }
     }
-    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 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
+        }
     }
-
-    ctx.destroySubcontext( rdn );
-}
-
-
-/**
- * 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 );
-
-    // 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" );
+    
+    
+    /**
+     * 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 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
+        }
+    }
+    
+    
+    /**
+     * 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 );
+        }
     }
-    catch ( SchemaViolationException e )
-    {
-        // Expected behaviour
+    
+    
+    /**
+     * 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
+        }
     }
-
-    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 );
-
-    try
-    {
+    
+    
+    /**
+     * 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 } );
-        fail( "modify should fail" );
-    }
-    catch ( SchemaViolationException e )
-    {
-        // Expected behaviour
-    }
-
-    ctx.destroySubcontext( rdn );
-}
-
-
-/**
- * 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
+    
+        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 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 )
+        {
+            // Expected behaviour
+        }
+    
+        ctx.destroySubcontext( rdn );
+    }
+    
+    
+    /**
+     * 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 );
+    
+        // 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 );
+    
+        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 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 );
+    
+        // 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" ) );
     }
-
-    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=1334639&r1=1334638&r2=1334639&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 Sun May  6 14:25:18 2012
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.operations.modify;
 
@@ -39,12 +39,14 @@ import javax.naming.directory.SchemaViol
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 
+import org.apache.directory.junit.tools.MultiThreadedMultiInvoker;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.annotations.ApplyLdifs;
 import org.apache.directory.server.core.annotations.CreateDS;
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -83,245 +85,247 @@ import org.junit.runner.RunWith;
 })
 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 );
-    }
-}
-
-
-/**
- * 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";
-
-    Attribute attr = new BasicAttribute( "numberOfOctaves" );
-    ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
-
-    try
-    {
+    @Rule
+    public MultiThreadedMultiInvoker i = new MultiThreadedMultiInvoker( MultiThreadedMultiInvoker.NOT_THREADSAFE );
+    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 } );
-        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 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 );
-
-    try
-    {
+    
+        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" ) );
+            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, 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
-    {
+            { 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 = 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";
+    
+        Attribute attr = new BasicAttribute( "numberOfOctaves" );
+        ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+    
+        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 );
+    
+        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 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 );
+    
+        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 );
-        fail( "Should get a SchemaViolationException" );
-    }
-    catch ( SchemaViolationException sve )
-    {
-        assertTrue( true );
+    
+        // 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=1334639&r1=1334638&r2=1334639&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 Sun May  6 14:25:18 2012
@@ -30,6 +30,7 @@ import static org.junit.Assert.fail;
 import javax.naming.ReferralException;
 import javax.naming.ldap.LdapContext;
 
+import org.apache.directory.junit.tools.MultiThreadedMultiInvoker;
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
@@ -47,6 +48,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.controls.ManageDsaITImpl;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.name.Rdn;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.slf4j.Logger;
@@ -104,204 +106,206 @@ import org.slf4j.LoggerFactory;
 })
 public class ModifyDnReferralIT extends AbstractLdapTestUnit
 {
-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
+    @Rule
+    public MultiThreadedMultiInvoker i = new MultiThreadedMultiInvoker( MultiThreadedMultiInvoker.NOT_THREADSAFE );
+    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();
     }
-    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
+    
+    
+    /**
+     * Tests ModifyDN operation with newSuperior on referral entry with the
+     * ManageDsaIT control.
+     */
+    @Test
+    public void testNewSuperiorOnReferralWithManageDsaITControl() throws Exception
     {
-        conn.moveAndRename( "uid=elecharny,ou=users,ou=system", "uid=ref,uid=akarasuluref,ou=users,ou=system", true );
+        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();
     }
-    catch ( LdapOperationException e )
+    
+    
+    /**
+     * 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
     {
-        assertEquals( ResultCodeEnum.AFFECTS_MULTIPLE_DSAS, e.getResultCode() );
+        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();
     }
-
-    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
+    
+    
+    /**
+     * 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
     {
-        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" );
+        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() );
+        }
+    
+        conn.close();
     }
-    catch ( ReferralException e )
+    
+    
+    /**
+     * 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
     {
-        // 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() );
+        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();
     }
-
-    ctx.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
+    
+    
+    /**
+     * Tests referral handling when an ancestor is a referral.
+     */
+    @Test
+    public void testAncestorReferral() throws Exception
     {
-        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" );
+        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();
     }
-    catch ( LdapOperationException e )
+    
+    
+    /**
+     * Tests referral handling when an ancestor is a referral.
+     */
+    @Test
+    public void testNewSuperiorAncestorReferral() throws Exception
     {
-        assertEquals( ResultCodeEnum.AFFECTS_MULTIPLE_DSAS, e.getResultCode() );
+        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();
     }
-
-    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=1334639&r1=1334638&r2=1334639&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 Sun May  6 14:25:18 2012
@@ -38,6 +38,7 @@ import javax.naming.directory.SchemaViol
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 
+import org.apache.directory.junit.tools.MultiThreadedMultiInvoker;
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
@@ -49,6 +50,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
 import org.junit.Ignore;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -68,6 +70,8 @@ import org.junit.runner.RunWith;
     })
 public class ModifyRdnIT extends AbstractLdapTestUnit
 {
+    @Rule
+    public MultiThreadedMultiInvoker i = new MultiThreadedMultiInvoker( MultiThreadedMultiInvoker.NOT_THREADSAFE );
     private static final String BASE = "ou=system";
 
 

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=1334639&r1=1334638&r2=1334639&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 Sun May  6 14:25:18 2012
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server.operations.modifydn;
 
@@ -32,6 +32,7 @@ import javax.naming.directory.SearchCont
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.LdapContext;
 
+import org.apache.directory.junit.tools.MultiThreadedMultiInvoker;
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
@@ -39,6 +40,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.apache.directory.shared.ldap.model.exception.LdapUnwillingToPerformException;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -81,6 +83,8 @@ import org.junit.runner.RunWith;
         "ou: child" })
 public class MoveIT extends AbstractLdapTestUnit
 {
+    @Rule
+    public MultiThreadedMultiInvoker i = new MultiThreadedMultiInvoker( MultiThreadedMultiInvoker.NOT_THREADSAFE );
     private static final String DN = "uid=akarasulu,ou=users,ou=system";
     private static final String NEW_DN = "uid=akarasulu,ou=NewSuperior,ou=system";
     private static final String NEW_DN2 = "uid=elecharny,ou=NewSuperior,ou=system";
@@ -134,7 +138,7 @@ public class MoveIT extends AbstractLdap
 
         LdapConnection con = getAdminConnection( getLdapServer() );
 
-        //now do something bad: make the parent a child of its own child 
+        //now do something bad: make the parent a child of its own child
         try
         {
             con.move( "ou=parent,ou=system", "ou=child,ou=parent,ou=system" );



Mime
View raw message