You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2006/08/08 07:11:18 UTC
svn commit: r429581 - in /directory/trunks/apacheds:
core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
server-unit/src/test/java/org/apache/directory/server/ModifyRemoveTest.java
Author: akarasulu
Date: Mon Aug 7 22:11:18 2006
New Revision: 429581
URL: http://svn.apache.org/viewvc?rev=429581&view=rev
Log:
Fix for DIRSERVER-701: Replacing existing attr w/ attr w/o values lead to empty attribute
Modified:
directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/ModifyRemoveTest.java
Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java?rev=429581&r1=429580&r2=429581&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java Mon Aug 7 22:11:18 2006
@@ -1210,10 +1210,17 @@
dropAliasIndices( id );
}
- // Automatically replaces old attributes with new modified ones
- entry.put( mods );
+ // replaces old attributes with new modified ones if they exist
+ if ( mods.size() > 0 )
+ {
+ entry.put( mods );
+ }
+ else // removes old attributes if new replacements do not exist
+ {
+ entry.remove( mods.getID() );
+ }
- if ( modsOid.equals( aliasAttributeOid ) )
+ if ( modsOid.equals( aliasAttributeOid ) && mods.size() > 0 )
{
String ndnStr = ( String ) ndnIdx.reverseLookup( id );
addAliasIndices( id, new LdapDN( ndnStr ), ( String ) mods.get() );
Modified: directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/ModifyRemoveTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/ModifyRemoveTest.java?rev=429581&r1=429580&r2=429581&view=diff
==============================================================================
--- directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/ModifyRemoveTest.java (original)
+++ directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/ModifyRemoveTest.java Mon Aug 7 22:11:18 2006
@@ -19,6 +19,7 @@
import java.util.Hashtable;
+import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
@@ -26,8 +27,11 @@
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InvalidAttributeIdentifierException;
+import javax.naming.directory.ModificationItem;
import javax.naming.directory.NoSuchAttributeException;
import javax.naming.directory.SchemaViolationException;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
@@ -67,6 +71,25 @@
/**
+ * Creation of required attributes of an inetOrgPerson entry.
+ */
+ protected Attributes getInetOrgPersonAttributes( String sn, String cn )
+ {
+ Attributes attrs = new BasicAttributes();
+ 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;
+ }
+
+
+ /**
* Create context and a person entry.
*/
public void setUp() throws Exception
@@ -148,7 +171,6 @@
*/
public void testRemoveTwoNotRequiredAttributes() throws NamingException
{
-
// add telephoneNumber to entry
Attributes tn = new BasicAttributes( "telephoneNumber", "12345678" );
ctx.modifyAttributes( RDN, DirContext.ADD_ATTRIBUTE, tn );
@@ -178,7 +200,6 @@
*/
public void testRemoveRequiredAttribute() throws NamingException
{
-
// Remove sn attribute
Attribute attr = new BasicAttribute( "sn" );
Attributes attrs = new BasicAttributes();
@@ -205,7 +226,6 @@
*/
public void testRemovePartOfRdn() throws NamingException
{
-
// Remove sn attribute
Attribute attr = new BasicAttribute( "cn" );
Attributes attrs = new BasicAttributes();
@@ -232,7 +252,6 @@
*/
public void testRemovePartOfRdnNotRequired() throws NamingException
{
-
// Change RDN to another attribute
String newRdn = "description=an American singer-songwriter";
ctx.addToEnvironment( "java.naming.ldap.deleteRDN", "false" );
@@ -269,7 +288,6 @@
*/
public void testRemoveAttributeNotPresent() throws NamingException
{
-
// Remove telephoneNumber Attribute
Attribute attr = new BasicAttribute( "telephoneNumber" );
Attributes attrs = new BasicAttributes();
@@ -296,7 +314,6 @@
*/
public void testRemoveAttributeNotValid() throws NamingException
{
-
// Remove phantasy attribute
Attribute attr = new BasicAttribute( "XXX" );
Attributes attrs = new BasicAttributes();
@@ -317,4 +334,45 @@
}
}
+
+ /**
+ * Create a person entry and try to remove an attribute value
+ */
+ public void testReplaceNonExistingAttribute() throws NamingException
+ {
+ // 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 enm = ctx.search( base, filter, sctls );
+ if ( enm.hasMore() )
+ {
+ SearchResult sr = ( SearchResult ) 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 );
+ }
}