directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r111633 - in incubator/directory/eve/trunk: . dib/src/java/org/apache/eve dib/src/java/org/apache/eve/jndi/ibs dib/src/test/org/apache/eve/jndi/ibs
Date Sun, 12 Dec 2004 04:25:08 GMT
Author: akarasulu
Date: Sat Dec 11 20:25:07 2004
New Revision: 111633

URL: http://svn.apache.org/viewcvs?view=rev&rev=111633
Log:
Changes ...

 o added checks for entry existance and other things to make sure operations
   can proceed or throw the right exception within the exception interceptor
 o added property to prevent junit test forks to see if that lowers test time
   but it had no effect
 o added some serious amounts of tests to make sure everything worked as it
   should for exception generation

Note ...

 o there are several other checks that need to go in here such as checking to
   see if a target entry on a move exists and denying operation because move
   to existing entry name is not possible et. cetera.


Added:
   incubator/directory/eve/trunk/dib/src/test/org/apache/eve/jndi/ibs/EveExceptionServiceTest.java
Modified:
   incubator/directory/eve/trunk/dib/src/java/org/apache/eve/RootNexus.java
   incubator/directory/eve/trunk/dib/src/java/org/apache/eve/jndi/ibs/EveExceptionService.java
   incubator/directory/eve/trunk/project.properties

Modified: incubator/directory/eve/trunk/dib/src/java/org/apache/eve/RootNexus.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/dib/src/java/org/apache/eve/RootNexus.java?view=diff&rev=111633&p1=incubator/directory/eve/trunk/dib/src/java/org/apache/eve/RootNexus.java&r1=111632&p2=incubator/directory/eve/trunk/dib/src/java/org/apache/eve/RootNexus.java&r2=111633
==============================================================================
--- incubator/directory/eve/trunk/dib/src/java/org/apache/eve/RootNexus.java	(original)
+++ incubator/directory/eve/trunk/dib/src/java/org/apache/eve/RootNexus.java	Sat Dec 11 20:25:07
2004
@@ -143,7 +143,19 @@
      */
     public Name getMatchedDn( Name dn, boolean normalized ) throws NamingException
     {
-        throw new NotImplementedException();
+        dn = ( Name ) dn.clone();
+
+        while ( dn.size() > 0 )
+        {
+            if ( hasEntry( dn ) )
+            {
+                return dn;
+            }
+
+            dn = dn.getSuffix( 1 );
+        }
+
+        return dn;
     }
 
 

Modified: incubator/directory/eve/trunk/dib/src/java/org/apache/eve/jndi/ibs/EveExceptionService.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/dib/src/java/org/apache/eve/jndi/ibs/EveExceptionService.java?view=diff&rev=111633&p1=incubator/directory/eve/trunk/dib/src/java/org/apache/eve/jndi/ibs/EveExceptionService.java&r1=111632&p2=incubator/directory/eve/trunk/dib/src/java/org/apache/eve/jndi/ibs/EveExceptionService.java&r2=111633
==============================================================================
--- incubator/directory/eve/trunk/dib/src/java/org/apache/eve/jndi/ibs/EveExceptionService.java
(original)
+++ incubator/directory/eve/trunk/dib/src/java/org/apache/eve/jndi/ibs/EveExceptionService.java
Sat Dec 11 20:25:07 2004
@@ -17,9 +17,14 @@
 package org.apache.eve.jndi.ibs;
 
 
+import java.util.Map;
 import javax.naming.Name;
 import javax.naming.NamingException;
+import javax.naming.NamingEnumeration;
 import javax.naming.directory.Attributes;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.Attribute;
 
 import org.apache.eve.jndi.*;
 
@@ -27,6 +32,9 @@
 import org.apache.eve.exception.EveInterceptorException;
 import org.apache.ldap.common.exception.LdapException;
 import org.apache.ldap.common.exception.*;
+import org.apache.ldap.common.filter.ExprNode;
+import org.apache.ldap.common.name.LdapName;
+import org.apache.ldap.common.message.ResultCodeEnum;
 
 
 /**
@@ -59,6 +67,12 @@
     }
 
 
+    /**
+     * Before calling super method which delegates to specific method invocation
+     * analogs we make sure the exception for the before failure or after
+     * failure states is one that implements LdapException interface so we
+     * have something that associates an LDAP error code.
+     */
     public void invoke( Invocation invocation ) throws NamingException
     {
         if ( invocation.getState() == InvocationStateEnum.FAILUREHANDLING )
@@ -122,17 +136,93 @@
 
         if ( invocation.getState() == InvocationStateEnum.PREINVOCATION )
         {
+            // check if the entry already exists
             if ( nexus.hasEntry( normName ) )
             {
                 NamingException ne = new LdapNameAlreadyBoundException();
                 invocation.setBeforeFailure( ne );
+                ne.setResolvedName( new LdapName( upName ) );
                 throw ne;
             }
+
+            Name parentDn = new LdapName( upName );
+            parentDn = parentDn.getSuffix( 1 );
+
+            // check if we don't have the parent to add to
+            assertHasEntry( "Attempt to add under non-existant parent: ", parentDn, invocation
);
+
+            // check if we're trying to add to a parent that is an alias
+            Attributes attrs = nexus.lookup( normName.getSuffix( 1 ) );
+            Attribute objectClass = attrs.get( "objectClass" );
+            if ( objectClass.contains( "alias" ) )
+            {
+                String msg = "Attempt to add entry to alias '" + upName
+                        + "' not allowed.";
+                ResultCodeEnum rc = ResultCodeEnum.ALIASPROBLEM;
+                NamingException e = new LdapNamingException( msg, rc );
+                e.setResolvedName( parentDn );
+                invocation.setBeforeFailure( e );
+                throw e;
+            }
+        }
+    }
+
+
+    /**
+     * Checks to make sure the entry being deleted exists, and has no children,
+     * otherwise throws the appropriate LdapException.
+     */
+    protected void delete( Name name ) throws NamingException
+    {
+        Invocation invocation = getInvocation();
+
+        if ( invocation.getState() == InvocationStateEnum.PREINVOCATION )
+        {
+            // check if entry to delete exists
+            String msg = "Attempt to delete non-existant entry: ";
+            assertHasEntry( msg, name, invocation );
+
+            // check if entry to delete has children (only leaves can be deleted)
+            boolean hasChildren = false;
+            NamingEnumeration list = nexus.list( name );
+            if ( list.hasMore() )
+            {
+                hasChildren = true;
+            }
+
+            list.close();
+            if ( hasChildren )
+            {
+                LdapContextNotEmptyException e = new LdapContextNotEmptyException();
+                e.setResolvedName( name );
+                invocation.setBeforeFailure( e );
+                throw e;
+            }
+        }
+    }
+
+
+    /**
+     * Checks to see the base being searched exists, otherwise throws the
+     * appropriate LdapException.
+     */
+    protected void list( Name base ) throws NamingException
+    {
+        Invocation invocation = getInvocation();
+
+        if ( invocation.getState() == InvocationStateEnum.PREINVOCATION )
+        {
+            // check if entry to search exists
+            String msg = "Attempt to search under non-existant entry: ";
+            assertHasEntry( msg, base, invocation );
         }
     }
 
 
     /**
+     * Checks to make sure the entry being looked up exists other wise throws
+     * the appropriate LdapException.
+     *
      * @see BaseInterceptor#lookup(javax.naming.Name)
      */
     protected void lookup( Name dn ) throws NamingException
@@ -141,12 +231,167 @@
 
         if ( invocation.getState() == InvocationStateEnum.PREINVOCATION )
         {
-            if ( ! nexus.hasEntry( dn ) )
+            String msg = "Attempt to lookup non-existant entry: ";
+            assertHasEntry( msg, dn, invocation );
+        }
+    }
+
+
+    /**
+     * Checks to see the base being searched exists, otherwise throws the
+     * appropriate LdapException.
+     */
+    protected void lookup( Name dn, String[] attrIds ) throws NamingException
+    {
+        Invocation invocation = getInvocation();
+
+        if ( invocation.getState() == InvocationStateEnum.PREINVOCATION )
+        {
+            // check if entry to lookup exists
+            String msg = "Attempt to lookup non-existant entry: ";
+            assertHasEntry( msg, dn, invocation );
+        }
+    }
+
+
+    /**
+     * Checks to see the entry being modified exists, otherwise throws the
+     * appropriate LdapException.
+     */
+    protected void modify( Name dn, int modOp, Attributes mods ) throws NamingException
+    {
+        Invocation invocation = getInvocation();
+
+        if ( invocation.getState() == InvocationStateEnum.PREINVOCATION )
+        {
+            // check if entry to modify exists
+            String msg = "Attempt to modify non-existant entry: ";
+            assertHasEntry( msg, dn, invocation );
+        }
+    }
+
+
+    /**
+     * Checks to see the entry being modified exists, otherwise throws the
+     * appropriate LdapException.
+     */
+    protected void modify( Name dn, ModificationItem[] mods ) throws NamingException
+    {
+        Invocation invocation = getInvocation();
+
+        if ( invocation.getState() == InvocationStateEnum.PREINVOCATION )
+        {
+            // check if entry to modify exists
+            String msg = "Attempt to modify non-existant entry: ";
+            assertHasEntry( msg, dn, invocation );
+        }
+    }
+
+
+    /**
+     * Checks to see the entry being renamed exists, otherwise throws the
+     * appropriate LdapException.
+     */
+    protected void modifyRdn( Name dn, String newRdn, boolean deleteOldRdn ) throws NamingException
+    {
+        Invocation invocation = getInvocation();
+
+        if ( invocation.getState() == InvocationStateEnum.PREINVOCATION )
+        {
+            // check if entry to rename exists
+            String msg = "Attempt to rename non-existant entry: ";
+            assertHasEntry( msg, dn, invocation );
+        }
+    }
+
+
+    /**
+     * Checks to see the entry being moved exists, and so does its parent,
+     * otherwise throws the appropriate LdapException.
+     */
+    protected void move( Name oriChildName, Name newParentName ) throws NamingException
+    {
+        Invocation invocation = getInvocation();
+
+        if ( invocation.getState() == InvocationStateEnum.PREINVOCATION )
+        {
+            // check if child to move exists
+            String msg = "Attempt to move to non-existant parent: ";
+            assertHasEntry( msg, oriChildName, invocation );
+
+            // check if parent to move to exists
+            msg = "Attempt to move to non-existant parent: ";
+            assertHasEntry( msg, newParentName, invocation );
+        }
+    }
+
+
+    /**
+     * Checks to see the entry being moved exists, and so does its parent,
+     * otherwise throws the appropriate LdapException.
+     */
+    protected void move( Name oriChildName, Name newParentName, String newRdn, boolean deleteOldRdn
) throws NamingException
+    {
+        Invocation invocation = getInvocation();
+
+        if ( invocation.getState() == InvocationStateEnum.PREINVOCATION )
+        {
+            // check if child to move exists
+            String msg = "Attempt to move to non-existant parent: ";
+            assertHasEntry( msg, oriChildName, invocation );
+
+            // check if parent to move to exists
+            msg = "Attempt to move to non-existant parent: ";
+            assertHasEntry( msg, newParentName, invocation );
+        }
+    }
+
+
+    /**
+     * Checks to see the entry being searched exists, otherwise throws the
+     * appropriate LdapException.
+     */
+    protected void search( Name base, Map env, ExprNode filter,
+                           SearchControls searchControls ) throws NamingException
+    {
+        Invocation invocation = getInvocation();
+
+        if ( invocation.getState() == InvocationStateEnum.PREINVOCATION )
+        {
+            String msg = "Attempt to search under non-existant entry: ";
+            assertHasEntry( msg, base, invocation );
+        }
+    }
+
+
+    /**
+     * Asserts that an entry is present and as a side effect if it is not,
+     * creates a LdapNameNotFoundException, which is used to set the before
+     * exception on the invocation - eventually the exception is thrown.
+     *
+     * @param msg the message to prefix to the distinguished name for explanation
+     * @param dn the distinguished name of the entry that is asserted
+     * @param invocation the invocation object to alter if the entry does not exist
+     * @throws NamingException if the entry does not exist
+     */
+    private void assertHasEntry( String msg, Name dn, Invocation invocation ) throws NamingException
+    {
+        if ( ! nexus.hasEntry( dn ) )
+        {
+            LdapNameNotFoundException e = null;
+
+            if ( msg != null )
             {
-                NamingException ne = new LdapNameNotFoundException();
-                invocation.setBeforeFailure( ne );
-                throw ne;
+                e = new LdapNameNotFoundException( msg + dn );
             }
+            else
+            {
+                e = new LdapNameNotFoundException( dn.toString() );
+            }
+
+            e.setResolvedName( nexus.getMatchedDn( dn, false ) );
+            invocation.setBeforeFailure( e );
+            throw e;
         }
     }
 }

Added: incubator/directory/eve/trunk/dib/src/test/org/apache/eve/jndi/ibs/EveExceptionServiceTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/dib/src/test/org/apache/eve/jndi/ibs/EveExceptionServiceTest.java?view=auto&rev=111633
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/dib/src/test/org/apache/eve/jndi/ibs/EveExceptionServiceTest.java
Sat Dec 11 20:25:07 2004
@@ -0,0 +1,485 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.
+ *
+ */
+package org.apache.eve.jndi.ibs;
+
+
+import javax.naming.NamingException;
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.ldap.LdapContext;
+import javax.naming.directory.*;
+
+import org.apache.eve.jndi.AbstractJndiTest;
+import org.apache.ldap.common.exception.LdapNameNotFoundException;
+import org.apache.ldap.common.exception.LdapContextNotEmptyException;
+import org.apache.ldap.common.exception.LdapNameAlreadyBoundException;
+import org.apache.ldap.common.exception.LdapNamingException;
+import org.apache.ldap.common.message.ResultCodeEnum;
+
+
+/**
+ * Tests the correct operation of the EveExceptionService.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class EveExceptionServiceTest extends AbstractJndiTest
+{
+    // ------------------------------------------------------------------------
+    // Search Operation Tests
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Test search operation failure when the search base is non-existant.
+     */
+    public void testFailSearchNoSuchObject() throws NamingException
+    {
+        SearchControls ctls = new SearchControls();
+        try
+        {
+            sysRoot.search( "ou=blah", "(objectClass=*)", ctls );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( LdapNameNotFoundException e )
+        {
+            assertEquals( "ou=system", e.getResolvedName().toString() );
+            assertEquals( ResultCodeEnum.NOSUCHOBJECT, e.getResultCode() );
+        }
+    }
+
+
+    /**
+     * Search operation control to test if normal search operations occur
+     * correctly.
+     */
+    public void testSearchControl() throws NamingException
+    {
+        SearchControls ctls = new SearchControls();
+        NamingEnumeration list = sysRoot.search( "ou=users", "(objectClass=*)", ctls );
+
+        if ( list.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) list.next();
+            assertNotNull( result.getAttributes() );
+            assertEquals( "uid=akarasulu,ou=users,ou=system", result.getName().toString()
);
+        }
+
+        assertFalse( list.hasMore() );
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Move Operation Tests
+    // ------------------------------------------------------------------------
+
+    /**
+     * Test move operation failure when the object moved is non-existant.
+     */
+    public void testFailMoveNoSuchObject() throws NamingException
+    {
+        try
+        {
+            sysRoot.rename( "ou=blah", "ou=blah,ou=groups" );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( LdapNameNotFoundException e )
+        {
+            assertEquals( "ou=system", e.getResolvedName().toString() );
+            assertEquals( ResultCodeEnum.NOSUCHOBJECT, e.getResultCode() );
+        }
+
+        try
+        {
+            sysRoot.addToEnvironment( "java.naming.ldap.deleteRDN", "false" );
+            sysRoot.rename( "ou=blah", "ou=blah2,ou=groups" );
+            sysRoot.removeFromEnvironment( "java.naming.ldap.deleteRDN" );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( LdapNameNotFoundException e )
+        {
+            assertEquals( "ou=system", e.getResolvedName().toString() );
+            assertEquals( ResultCodeEnum.NOSUCHOBJECT, e.getResultCode() );
+        }
+    }
+
+
+    /**
+     * Move operation control to test if normal move operations occur
+     * correctly.
+     */
+    public void testMoveControl() throws NamingException
+    {
+        sysRoot.rename( "ou=users", "ou=users,ou=groups" );
+        assertNotNull( sysRoot.lookup( "ou=users,ou=groups" ) );
+
+        try
+        {
+            sysRoot.lookup( "ou=users" );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( NamingException e )
+        {
+            assertEquals( "ou=system", e.getResolvedName().toString() );
+            assertTrue( e instanceof LdapNameNotFoundException );
+        }
+    }
+
+
+    // ------------------------------------------------------------------------
+    // ModifyRdn Operation Tests
+    // ------------------------------------------------------------------------
+
+    /**
+     * Test modifyRdn operation failure when the object renamed is non-existant.
+     */
+    public void testFailModifyRdnNoSuchObject() throws NamingException
+    {
+        try
+        {
+            sysRoot.rename( "ou=blah", "ou=asdf" );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( LdapNameNotFoundException e )
+        {
+            assertEquals( "ou=system", e.getResolvedName().toString() );
+            assertEquals( ResultCodeEnum.NOSUCHOBJECT, e.getResultCode() );
+        }
+    }
+
+
+    /**
+     * Modify operation control to test if normal modify operations occur
+     * correctly.
+     */
+    public void testModifyRdnControl() throws NamingException
+    {
+        sysRoot.rename( "ou=users", "ou=asdf" );
+        assertNotNull( sysRoot.lookup( "ou=asdf" ) );
+
+        try
+        {
+            sysRoot.lookup( "ou=users" );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( NamingException e )
+        {
+            assertEquals( "ou=system", e.getResolvedName().toString() );
+            assertTrue( e instanceof LdapNameNotFoundException );
+        }
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Modify Operation Tests
+    // ------------------------------------------------------------------------
+
+    /**
+     * Test modify operation failure when the object modified is non-existant.
+     */
+    public void testFailModifyNoSuchObject() throws NamingException
+    {
+        Attributes attrs = new BasicAttributes();
+        Attribute ou = new BasicAttribute( "ou" );
+        ou.add( "users" );
+        ou.add( "dummyValue" );
+        attrs.put( ou );
+
+        try
+        {
+            sysRoot.modifyAttributes( "ou=blah", DirContext.ADD_ATTRIBUTE, attrs );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( LdapNameNotFoundException e )
+        {
+            assertEquals( "ou=system", e.getResolvedName().toString() );
+            assertEquals( ResultCodeEnum.NOSUCHOBJECT, e.getResultCode() );
+        }
+
+
+        ModificationItem[] mods = new ModificationItem[] {
+            new ModificationItem( DirContext.ADD_ATTRIBUTE, ou )
+        };
+
+        try
+        {
+            sysRoot.modifyAttributes( "ou=blah", mods );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( LdapNameNotFoundException e )
+        {
+            assertEquals( "ou=system", e.getResolvedName().toString() );
+            assertEquals( ResultCodeEnum.NOSUCHOBJECT, e.getResultCode() );
+        }
+    }
+
+
+    /**
+     * Modify operation control to test if normal modify operations occur
+     * correctly.
+     */
+    public void testModifyControl() throws NamingException
+    {
+        Attributes attrs = new BasicAttributes();
+        Attribute attr = new BasicAttribute( "ou" );
+        attr.add( "users" );
+        attr.add( "dummyValue" );
+        attrs.put( attr );
+        sysRoot.modifyAttributes( "ou=users", DirContext.ADD_ATTRIBUTE, attrs );
+        Attribute ou = sysRoot.getAttributes( "ou=users" ).get( "ou" );
+        assertTrue( ou.contains( "users" ) );
+        assertTrue( ou.contains( "dummyValue" ) );
+
+        attr.add( "another" );
+        ModificationItem[] mods = new ModificationItem[] {
+            new ModificationItem( DirContext.ADD_ATTRIBUTE, attr )
+        };
+
+        sysRoot.modifyAttributes( "ou=users", mods );
+        ou = sysRoot.getAttributes( "ou=users" ).get( "ou" );
+        assertTrue( ou.contains( "users" ) );
+        assertTrue( ou.contains( "dummyValue" ) );
+        assertTrue( ou.contains( "another" ) );
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Lookup Operation Tests
+    // ------------------------------------------------------------------------
+
+    /**
+     * Test lookup operation failure when the object looked up is non-existant.
+     */
+    public void testFailLookupNoSuchObject() throws NamingException
+    {
+        try
+        {
+            sysRoot.lookup( "ou=blah" );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( LdapNameNotFoundException e )
+        {
+            assertEquals( "ou=system", e.getResolvedName().toString() );
+            assertEquals( ResultCodeEnum.NOSUCHOBJECT, e.getResultCode() );
+        }
+    }
+
+
+    /**
+     * Lookup operation control to test if normal lookup operations occur
+     * correctly.
+     */
+    public void testLookupControl() throws NamingException
+    {
+        LdapContext ctx = ( LdapContext ) sysRoot.lookup( "ou=users" );
+        assertNotNull( ctx );
+        assertEquals( "users", ctx.getAttributes("").get( "ou" ).get() );
+    }
+
+
+    // ------------------------------------------------------------------------
+    // List Operation Tests
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Test list operation failure when the base searched is non-existant.
+     */
+    public void testFailListNoSuchObject() throws NamingException
+    {
+        try
+        {
+            sysRoot.list( "ou=blah" );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( LdapNameNotFoundException e )
+        {
+            assertEquals( "ou=system", e.getResolvedName().toString() );
+            assertEquals( ResultCodeEnum.NOSUCHOBJECT, e.getResultCode() );
+        }
+    }
+
+
+    /**
+     * List operation control to test if normal list operations occur correctly.
+     */
+    public void testListControl() throws NamingException
+    {
+        NamingEnumeration list = sysRoot.list( "ou=users" );
+
+        if ( list.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) list.next();
+            assertNotNull( result.getAttributes() );
+            assertEquals( "uid=akarasulu,ou=users,ou=system", result.getName().toString()
);
+        }
+
+        assertFalse( list.hasMore() );
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Add Operation Tests
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Tests for add operation failure when the parent of the entry to add does
+     * not exist.
+     */
+    public void testFailAddOnAlias() throws NamingException
+    {
+        Attributes attrs = new BasicAttributes();
+        Attribute attr = new BasicAttribute( "objectClass" );
+        attr.add( "top" );
+        attr.add( "alias" );
+        attrs.put( attr );
+        attrs.put( "aliasedObjectName", "ou=users,ou=system" );
+
+        sysRoot.createSubcontext( "cn=toanother", attrs );
+
+        try
+        {
+            sysRoot.createSubcontext( "ou=blah,cn=toanother" );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( LdapNamingException e )
+        {
+            assertEquals( "cn=toanother,ou=system", e.getResolvedName().toString() );
+            assertEquals( ResultCodeEnum.ALIASPROBLEM, e.getResultCode() );
+        }
+    }
+
+
+    /**
+     * Tests for add operation failure when the parent of the entry to add does
+     * not exist.
+     */
+    public void testFailAddNoSuchEntry() throws NamingException
+    {
+        try
+        {
+            sysRoot.createSubcontext( "ou=blah,ou=abc" );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( LdapNameNotFoundException e )
+        {
+            assertEquals( "ou=system", e.getResolvedName().toString() );
+            assertEquals( ResultCodeEnum.NOSUCHOBJECT, e.getResultCode() );
+        }
+    }
+
+
+    /**
+     * Tests for add operation failure when the entry to add already exists.
+     */
+    public void testFailAddEntryAlreadyExists() throws NamingException
+    {
+        sysRoot.createSubcontext( "ou=blah" );
+
+        try
+        {
+            sysRoot.createSubcontext( "ou=blah" );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( LdapNameAlreadyBoundException e )
+        {
+            assertEquals( "ou=blah,ou=system", e.getResolvedName().toString() );
+            assertEquals( ResultCodeEnum.ENTRYALREADYEXISTS, e.getResultCode() );
+        }
+    }
+
+
+    /**
+     * Add operation control to test if normal add operations occur correctly.
+     */
+    public void testAddControl() throws NamingException
+    {
+        Context ctx = sysRoot.createSubcontext( "ou=blah" );
+        ctx.createSubcontext( "ou=subctx" );
+        Object obj = sysRoot.lookup( "ou=subctx,ou=blah" );
+        assertNotNull( obj );
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Delete Operation Tests
+    // ------------------------------------------------------------------------
+
+
+    /**
+     * Tests for delete failure when the entry to be deleted has child entires.
+     */
+    public void testFailDeleteNotAllowedOnNonLeaf() throws NamingException
+    {
+        Context ctx = sysRoot.createSubcontext( "ou=blah" );
+        ctx.createSubcontext( "ou=subctx" );
+
+        try
+        {
+            sysRoot.destroySubcontext( "ou=blah" );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( LdapContextNotEmptyException e )
+        {
+            assertEquals( "ou=blah,ou=system", e.getResolvedName().toString() );
+            assertEquals( ResultCodeEnum.NOTALLOWEDONNONLEAF, e.getResultCode() );
+        }
+    }
+
+
+    /**
+     * Tests delete to make sure it fails when we try to delete an entry that
+     * does not exist.
+     */
+    public void testFailDeleteNoSuchObject() throws NamingException
+    {
+        try
+        {
+            sysRoot.destroySubcontext( "ou=blah" );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( LdapNameNotFoundException e )
+        {
+            assertEquals( "ou=system", e.getResolvedName().toString() );
+            assertEquals( ResultCodeEnum.NOSUCHOBJECT, e.getResultCode() );
+        }
+    }
+
+
+    /**
+     * Delete operation control to test if normal delete operations occur.
+     */
+    public void testDeleteControl() throws NamingException
+    {
+        sysRoot.createSubcontext( "ou=blah" );
+        Object obj = sysRoot.lookup( "ou=blah" );
+        assertNotNull( obj );
+        sysRoot.destroySubcontext( "ou=blah" );
+
+        try
+        {
+            sysRoot.lookup( "ou=blah" );
+            fail( "Execution should never get here due to exception!" );
+        }
+        catch( LdapNameNotFoundException e )
+        {
+            assertEquals( "ou=system", e.getResolvedName().toString() );
+            assertEquals( ResultCodeEnum.NOSUCHOBJECT, e.getResultCode() );
+        }
+    }
+}

Modified: incubator/directory/eve/trunk/project.properties
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/project.properties?view=diff&rev=111633&p1=incubator/directory/eve/trunk/project.properties&r1=111632&p2=incubator/directory/eve/trunk/project.properties&r2=111633
==============================================================================
--- incubator/directory/eve/trunk/project.properties	(original)
+++ incubator/directory/eve/trunk/project.properties	Sat Dec 11 20:25:07 2004
@@ -4,6 +4,7 @@
 maven.xdoc.date=left
 maven.xdoc.includeProjectDocumentation=yes
 maven.xdoc.poweredby.image=
+maven.junit.fork=false
 
 #
 # remote repository properties

Mime
View raw message