directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r642984 - in /directory/apacheds/branches/bigbang: core-entry/src/main/java/org/apache/directory/server/core/entry/ core/src/main/java/org/apache/directory/server/core/schema/ server-unit/src/test/java/org/apache/directory/server/
Date Mon, 31 Mar 2008 13:14:55 GMT
Author: akarasulu
Date: Mon Mar 31 06:14:52 2008
New Revision: 642984

URL: http://svn.apache.org/viewvc?rev=642984&view=rev
Log:
DIRSERVER-646 fix: moved changes in schema interceptor to new location where
we transform JNDI parameters into Server expected parameters based on 
ServerAttribute.  This stuff will need to be moved again.  Added additional test
to Stefan Zoerners test case to test for condition where multiple mods exist.

Modified:
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
    directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java?rev=642984&r1=642983&r2=642984&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java
(original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java
Mon Mar 31 06:14:52 2008
@@ -31,6 +31,7 @@
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
 import javax.naming.directory.InvalidAttributeIdentifierException;
 import javax.naming.directory.ModificationItem;
 import javax.naming.directory.SearchResult;
@@ -466,8 +467,8 @@
     }
     
     
-    public static List<Modification> toServerModification( ModificationItem[] modifications,
AttributeTypeRegistry atRegistry )
-    throws NamingException
+    public static List<Modification> toServerModification( ModificationItem[] modifications,

+        AttributeTypeRegistry atRegistry ) throws NamingException
     {
 	    if ( modifications != null )
 	    {
@@ -478,6 +479,27 @@
 	            String attributeId = modification.getAttribute().getID();
                 String id = stripOptions( attributeId );
 	            Set<String> options = getOptions( attributeId );
+
+	            // -------------------------------------------------------------------
+	            // DIRSERVER-646 Fix: Replacing an unknown attribute with no values 
+	            // (deletion) causes an error
+	            // -------------------------------------------------------------------
+	            
+                // TODO - after removing JNDI we need to make the server handle 
+	            // this in the codec
+                
+	            if ( ! atRegistry.hasAttributeType( id ) 
+	                 && modification.getAttribute().size() == 0 
+	                 && modification.getModificationOp() == DirContext.REPLACE_ATTRIBUTE
)
+	            {
+	                continue;
+	            }
+
+	            // -------------------------------------------------------------------
+	            // END DIRSERVER-646 Fix
+	            // -------------------------------------------------------------------
+	            
+	            
 	            // TODO : handle options
 	            AttributeType attributeType = atRegistry.lookup( id );
 	            modificationsList.add( toModification( (ModificationItemImpl)modification, attributeType
) );

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java?rev=642984&r1=642983&r2=642984&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
(original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
Mon Mar 31 06:14:52 2008
@@ -1236,19 +1236,6 @@
 
         ObjectClassRegistry ocRegistry = this.registries.getObjectClassRegistry();
 
-        // -------------------------------------------------------------------
-        // DIRSERVER-646 Fix: Replacing an unknown attribute with no values 
-        // (deletion) causes an error
-        // -------------------------------------------------------------------
-        
-        if ( ( mods.size() == 1 ) && 
-             ( mods.get( 0 ).getAttribute().size() == 0 ) && 
-             ( mods.get( 0 ).getOperation() == ModificationOperation.REPLACE_ATTRIBUTE )
&&
-             ! atRegistry.hasAttributeType( mods.get( 0 ).getAttribute().getId() ) )
-        {
-            return;
-        }
-        
         // Now, apply the modifications on the cloned entry before applying it on the
         // real object.
         for ( Modification mod:mods )

Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java?rev=642984&r1=642983&r2=642984&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java
(original)
+++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyReplaceITest.java
Mon Mar 31 06:14:52 2008
@@ -20,22 +20,18 @@
 package org.apache.directory.server;
 
 
-import java.util.Hashtable;
-
-import javax.naming.Context;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.ModificationItem;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 
 import org.apache.directory.server.unit.AbstractServerTest;
-import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.AttributesImpl;
-import org.apache.directory.shared.ldap.message.ModificationItemImpl;
 
 
 /**
@@ -46,69 +42,74 @@
  */
 public class ModifyReplaceITest extends AbstractServerTest
 {
-    DirContext ctx = null;
-
-
-    protected Attributes getPersonAttributes( String sn, String cn )
+    protected Attributes getPersonAttributes( String sn, String cn ) 
     {
-        Attributes attrs = new AttributesImpl();
-        Attribute ocls = new AttributeImpl( "objectClass" );
-        ocls.add( "top" );
-        ocls.add( "person" );
-        attrs.put( ocls );
-        attrs.put( "cn", cn );
-        attrs.put( "sn", sn );
+        Attributes attrs = new BasicAttributes();
+        Attribute ocls = new BasicAttribute("objectClass");
+        ocls.add("top");
+        ocls.add("person");
+        attrs.put(ocls);
+        attrs.put("cn", cn);
+        attrs.put("sn", sn);
 
         return attrs;
     }
 
-
-    protected void setUp() throws Exception
+    
+    /**
+     * Create a person entry and try to remove a not present attribute
+     */
+    public void testReplaceNotPresentAttribute() throws NamingException 
     {
-        super.setUp();
-        
-        Hashtable<String, Object> env = new Hashtable<String, Object>();
-        env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
-        env.put( Context.PROVIDER_URL, "ldap://localhost:" + super.port + "/ou=system" );
-        env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
-        env.put( Context.SECURITY_CREDENTIALS, "secret" );
-        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+        Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
+        String rdn = "cn=Kate Bush";
+        sysRoot.createSubcontext( rdn, attrs );
 
-        ctx = new InitialDirContext( env );
-    }
+        Attribute attr = new BasicAttribute( "description" );
+        ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr
);
 
+        sysRoot.modifyAttributes( rdn, new ModificationItem[] { item } );
 
-    protected void tearDown() throws Exception
-    {
-        ctx.close();
-        super.tearDown();
-    }
+        SearchControls sctls = new SearchControls();
+        sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        String filter = "(sn=Bush)";
+        String base = "";
 
+        NamingEnumeration enm = sysRoot.search( base, filter, sctls );
+        while ( enm.hasMore() ) 
+        {
+            SearchResult sr = ( SearchResult ) enm.next();
+            attrs = sr.getAttributes();
+            Attribute cn = sr.getAttributes().get( "cn" );
+            assertNotNull( cn );
+            assertTrue( cn.contains("Kate Bush") );
+        }
+
+        sysRoot.destroySubcontext( rdn );
+    }
 
+    
     /**
-     * Create a person entry and try to remove a not present attribute
-     * 
-     * @throws NamingException 
+     * Create a person entry and try to remove a non existing attribute
      */
-    public void testReplaceNotPresentAttribute() throws NamingException
+    public void testReplaceNonExistingAttribute() throws NamingException 
     {
         Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
         String rdn = "cn=Kate Bush";
-        ctx.createSubcontext( rdn, attrs );
+        sysRoot.createSubcontext( rdn, attrs );
 
-        Attribute attr = new AttributeImpl( "description" );
-        ModificationItemImpl item = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE,
attr );
+        Attribute attr = new BasicAttribute( "numberOfOctaves" );
+        ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr
);
 
-        ctx.modifyAttributes( rdn, new ModificationItemImpl[]
-            { item } );
+        sysRoot.modifyAttributes(rdn, new ModificationItem[] { item });
 
         SearchControls sctls = new SearchControls();
         sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         String filter = "(sn=Bush)";
         String base = "";
 
-        NamingEnumeration enm = ctx.search( base, filter, sctls );
-        while ( enm.hasMore() )
+        NamingEnumeration enm = sysRoot.search( base, filter, sctls );
+        while ( enm.hasMore() ) 
         {
             SearchResult sr = ( SearchResult ) enm.next();
             attrs = sr.getAttributes();
@@ -117,34 +118,33 @@
             assertTrue( cn.contains( "Kate Bush" ) );
         }
 
-        ctx.destroySubcontext( rdn );
+        sysRoot.destroySubcontext( rdn );
     }
 
 
     /**
      * Create a person entry and try to remove a non existing attribute
-     * 
-     * @throws NamingException 
      */
-    public void testReplaceNonExistingAttribute() throws NamingException
+    public void testReplaceNonExistingAttributeManyMods() throws NamingException 
     {
         Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
         String rdn = "cn=Kate Bush";
-        ctx.createSubcontext( rdn, attrs );
+        sysRoot.createSubcontext( rdn, attrs );
 
-        Attribute attr = new AttributeImpl( "l" );
-        ModificationItemImpl item = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE,
attr );
+        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 );
 
-        ctx.modifyAttributes( rdn, new ModificationItemImpl[]
-            { item } );
+        sysRoot.modifyAttributes(rdn, new ModificationItem[] { item, item2 });
 
         SearchControls sctls = new SearchControls();
         sctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
         String filter = "(sn=Bush)";
         String base = "";
 
-        NamingEnumeration enm = ctx.search( base, filter, sctls );
-        while ( enm.hasMore() )
+        NamingEnumeration enm = sysRoot.search( base, filter, sctls );
+        while ( enm.hasMore() ) 
         {
             SearchResult sr = ( SearchResult ) enm.next();
             attrs = sr.getAttributes();
@@ -153,6 +153,6 @@
             assertTrue( cn.contains( "Kate Bush" ) );
         }
 
-        ctx.destroySubcontext( rdn );
+        sysRoot.destroySubcontext( rdn );
     }
 }



Mime
View raw message