directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r609459 [2/4] - in /directory: apacheds/branches/bigbang/bootstrap-plugin/ apacheds/branches/bigbang/bootstrap-plugin/src/main/java/org/apache/directory/server/core/bootstrap/plugin/ apacheds/branches/bigbang/core-entry/src/main/java/org/ap...
Date Sun, 06 Jan 2008 22:58:16 GMT
Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerValue.java Sun Jan  6 14:58:12 2008
@@ -82,4 +82,6 @@
 
     
     boolean instanceOf( AttributeType attributeType ) throws NamingException;
+    
+    ServerValue<T> clone();
 }

Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java Sun Jan  6 14:58:12 2008
@@ -19,7 +19,10 @@
  */
 package org.apache.directory.server.core.entry;
 
+import java.util.Arrays;
+import java.util.Comparator;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import javax.naming.InvalidNameException;
@@ -40,13 +43,23 @@
 import org.apache.directory.server.schema.registries.DefaultRegistries;
 import org.apache.directory.server.schema.registries.OidRegistry;
 import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.Syntax;
+import org.apache.directory.shared.ldap.schema.UsageEnum;
+import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
 
 
 /**
@@ -60,6 +73,7 @@
     private static BootstrapSchemaLoader loader;
     private static Registries registries;
     private static OidRegistry oidRegistry;
+    private static AttributeType AT;
     
     /**
      * Initialize the registries once for the whole test suite
@@ -80,22 +94,300 @@
         bootstrapSchemas.add( new InetorgpersonSchema() );
         bootstrapSchemas.add( new CosineSchema() );
         loader.loadWithDependencies( bootstrapSchemas, registries );
+        
+        AT = new AttributeType()
+        {
+            private static final long serialVersionUID = 1L;
+
+            public boolean isSingleValue()
+            {
+                return false;
+            }
+
+
+            public boolean isCanUserModify()
+            {
+                return true;
+            }
+
+
+            public boolean isCollective()
+            {
+                return false;
+            }
+
+
+            public UsageEnum getUsage()
+            {
+                return null;
+            }
+
+
+            public AttributeType getSuperior() throws NamingException
+            {
+                return null;
+            }
+
+
+            public Syntax getSyntax() throws NamingException
+            {
+                return new Syntax()
+                {
+
+                    private static final long serialVersionUID = 1L;
+
+                    public boolean isHumanReadable()
+                    {
+                        return true;
+                    }
+
+                    public SyntaxChecker getSyntaxChecker() throws NamingException
+                    {
+                        return null;
+                    }
+
+                    public boolean isObsolete()
+                    {
+                        return false;
+                    }
+
+                    public String getOid()
+                    {
+                        return null;
+                    }
+
+                    public String[] getNames()
+                    {
+                        return null;
+                    }
+
+                    public String getName()
+                    {
+                        return null;
+                    }
+
+                    public String getDescription()
+                    {
+                        return null;
+                    }
+
+                    public String getSchema()
+                    {
+                        return null;
+                    }
+
+                    public void setSchema( String schemaName )
+                    {
+                    }
+                };
+            }
+
+
+            public int getLength()
+            {
+                return 0;
+            }
+
+
+            public MatchingRule getEquality() throws NamingException
+            {
+                return new MatchingRule()
+                {
+                    private static final long serialVersionUID = 1L;
+
+                    public Syntax getSyntax() throws NamingException
+                    {
+                        return new Syntax()
+                        {
+                            private static final long serialVersionUID = 1L;
+
+
+                            public boolean isHumanReadable()
+                            {
+                                return true;
+                            }
+
+                            public SyntaxChecker getSyntaxChecker() throws NamingException
+                            {
+                                return null;
+                            }
+
+                            public boolean isObsolete()
+                            {
+                                return false;
+                            }
+
+                            public String getOid()
+                            {
+                                return null;
+                            }
+
+                            public String[] getNames()
+                            {
+                                return null;
+                            }
+
+                            public String getName()
+                            {
+                                return null;
+                            }
+
+                            public String getDescription()
+                            {
+                                return null;
+                            }
+
+                            public String getSchema()
+                            {
+                                return null;
+                            }
+
+                            public void setSchema( String schemaName )
+                            {
+                            }
+                        };
+                    }
+
+                    public Comparator getComparator() throws NamingException
+                    {
+                        return null;
+                    }
+
+                    public Normalizer getNormalizer() throws NamingException
+                    {
+                        return new Normalizer()
+                        {
+                            private static final long serialVersionUID = 1L;
+
+                            public Object normalize( Object value ) throws NamingException
+                            {
+                                return StringTools.deepTrimToLower( value.toString() );
+                            }
+                        };
+                    }
+
+                    public boolean isObsolete()
+                    {
+                        return false;
+                    }
+
+                    public String getOid()
+                    {
+                        return null;
+                    }
+
+                    public String[] getNames()
+                    {
+                        return null;
+                    }
+
+                    public String getName()
+                    {
+                        return null;
+                    }
+
+                    public String getDescription()
+                    {
+                        return null;
+                    }
+
+                    public String getSchema()
+                    {
+                        return null;
+                    }
+
+                    public void setSchema( String schemaName )
+                    {
+                    }
+                };
+            }
+
+
+            public MatchingRule getOrdering() throws NamingException
+            {
+                return null;
+            }
+
+
+            public MatchingRule getSubstr() throws NamingException
+            {
+                return null;
+            }
+
+
+            public boolean isAncestorOf( AttributeType descendant ) throws NamingException
+            {
+                return false;
+            }
+
+
+            public boolean isDescentantOf( AttributeType ancestor ) throws NamingException
+            {
+                return false;
+            }
+
+
+            public boolean isObsolete()
+            {
+                return false;
+            }
+
+
+            public String getOid()
+            {
+                return "1.2.3";
+            }
+
+
+            public String[] getNames()
+            {
+                return new String[]
+                    { "test" };
+            }
+
+
+            public String getName()
+            {
+                return "test";
+            }
+
+
+            public String getDescription()
+            {
+                return "test";
+            }
+
+
+            public String getSchema()
+            {
+                return null;
+            }
+
+
+            public void setSchema( String schemaName )
+            {
+            }
+        };
     }
 
 
+    //-------------------------------------------------------------------------
+    // Test the constructors
+    //-------------------------------------------------------------------------
+    
     /**
      * Test a conversion from a ServerEntry to an AttributesImpl
      */
     @Test public void testToAttributesImpl() throws InvalidNameException, NamingException
     {
         LdapDN dn = new LdapDN( "cn=test" );
-        DefaultServerEntry entry = new DefaultServerEntry( dn, registries );
+        DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
         
         ObjectClassAttribute oc = new ObjectClassAttribute( registries );
         oc.add( "top", "person", "inetOrgPerson" );
         
         entry.addObjectClass( oc );
-        entry.put( "cn", registries.getAttributeTypeRegistry().lookup( "cn" ), "test" );
+        //entry.put( "cn", registries.getAttributeTypeRegistry().lookup( "cn" ), "test" );
         
         Attributes attributes = ServerEntryUtils.toAttributesImpl( entry );
         
@@ -115,7 +407,8 @@
             
         }
 
-        assertEquals( 0, expected.size() );
+        // We should still have the ObjectClass Attribute
+        assertEquals( 1, expected.size() );
     }
 
 
@@ -125,13 +418,13 @@
     @Test public void testToBasicAttributes() throws InvalidNameException, NamingException
     {
         LdapDN dn = new LdapDN( "cn=test" );
-        DefaultServerEntry entry = new DefaultServerEntry( dn, registries );
+        DefaultServerEntry entry = new DefaultServerEntry( registries,dn );
         
         ObjectClassAttribute oc = new ObjectClassAttribute( registries );
         oc.add( "top", "person", "inetOrgPerson" );
         
         entry.addObjectClass( oc );
-        entry.put( "cn", registries.getAttributeTypeRegistry().lookup( "cn" ), "test" );
+        //entry.put( "cn", registries.getAttributeTypeRegistry().lookup( "cn" ), "test" );
         
         Attributes attributes = ServerEntryUtils.toBasicAttributes( entry );
         
@@ -151,6 +444,847 @@
             
         }
 
-        assertEquals( 0, expected.size() );
+        // We should still have the ObjectClass Attribute
+        assertEquals( 1, expected.size() );
+    }
+    
+    //-------------------------------------------------------------------------
+    // Test the put methods
+    //-------------------------------------------------------------------------
+    /**
+     * Test the set(AT...) method
+     */
+    @Test public void tesSetATElipsis() throws NamingException
+    {
+        LdapDN dn = new LdapDN( "cn=test" );
+        DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+        
+        List<ServerAttribute> result = null;
+        
+        // First check that this method fails if we pass an empty list of ATs
+        try
+        {
+            result = entry.set( (AttributeType)null);
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        // Now, check what we get when adding one existing AT
+        AttributeType atSN = registries.getAttributeTypeRegistry().lookup( "sn" );
+        result = entry.set( atSN );
+        
+        assertNotNull( result );
+        assertEquals( 0, result.size() );
+        ServerAttribute sa = entry.get( "sn" );
+        assertNotNull( sa );
+        assertEquals( atSN, sa.getType() );
+        assertEquals( "sn", sa.getType().getName() );
+        
+        // Add two AT now
+        AttributeType atL = registries.getAttributeTypeRegistry().lookup( "localityName" );
+        AttributeType atC = registries.getAttributeTypeRegistry().lookup( "countryName" );
+        AttributeType atGN = registries.getAttributeTypeRegistry().lookup( "givenname" );
+        AttributeType atStreet = registries.getAttributeTypeRegistry().lookup( "2.5.4.9" );
+        result = entry.set( atL, atC, atGN, atStreet );
+        
+        assertNotNull( result );
+        
+        assertEquals( 0, result.size() );
+        sa = entry.get( "l" );
+        assertNotNull( sa );
+        assertEquals( atL, sa.getType() );
+        assertEquals( "l", sa.getType().getName() );
+
+        sa = entry.get( "c" );
+        assertNotNull( sa );
+        assertEquals( atC, sa.getType() );
+        assertEquals( "c", sa.getType().getName() );
+
+        sa = entry.get( "2.5.4.9" );
+        assertNotNull( sa );
+        assertEquals( atStreet, sa.getType() );
+        assertEquals( "street", sa.getType().getName() );
+
+        sa = entry.get( "givenName" );
+        assertNotNull( sa );
+        assertEquals( atGN, sa.getType() );
+        assertEquals( "givenName", sa.getType().getName() );
+        
+        // Now try to add existing ATs
+        // First, set some value to the modified AT
+        sa = entry.get( "sn" );
+        sa.add( "test" );
+        
+        // Check that the value has been added to the entry
+        assertEquals( "test", entry.get( "sn" ).get().get() ); 
+        
+        // Now add a new SN empty AT : it should replace the existing one.
+        AttributeType atSNEmpty = registries.getAttributeTypeRegistry().lookup( "sn" );
+        sa = entry.set( atSNEmpty ).get( 0 );
+        assertEquals( "test", sa.get().get() ); 
+        assertNotNull( entry.get(  "sn" ) );
+        assertNull( entry.get(  "sn" ).get() );
+        
+        // Last, not least, put an ObjectClass AT
+        AttributeType OBJECT_CLASS_AT = registries.getAttributeTypeRegistry().lookup( SchemaConstants.OBJECT_CLASS_AT );
+        
+        entry.set( OBJECT_CLASS_AT );
+        
+        assertNotNull( entry.get( "objectClass" ) );
+
+        ServerAttribute oc = entry.get( "objectClass" );
+        
+        assertEquals( OBJECT_CLASS_AT, oc.getType() );
+        assertNull( oc.get() );
+    }
+
+    /**
+     * Test the set( upId ) method
+     */
+    @Test public void tesSetUpID() throws NamingException
+    {
+        LdapDN dn = new LdapDN( "cn=test" );
+        DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+        
+        // First check that this method fails if we pass a null or empty ID
+        try
+        {
+            entry.set( (String)null );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        try
+        {
+            entry.set( "  " );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        // Now check that we can't put invalid IDs
+        try
+        {
+            entry.set( "ThisIsNotAnAttributeType" );
+            fail();
+        }
+        catch ( NamingException ne )
+        {
+            assertTrue( true );
+        }
+        
+        // Now, check what we get when adding one existing AT
+        List<ServerAttribute> result = entry.set( "sn" );
+        
+        assertNull( result );
+
+        ServerAttribute sa = entry.get( "sn" );
+        assertNotNull( sa );
+        assertEquals( "sn", sa.getType().getName() );
+        
+        // Add different upIds now
+        AttributeType atL = registries.getAttributeTypeRegistry().lookup( "localityName" );
+        AttributeType atC = registries.getAttributeTypeRegistry().lookup( "countryName" );
+        AttributeType atGN = registries.getAttributeTypeRegistry().lookup( "givenname" );
+        AttributeType atStreet = registries.getAttributeTypeRegistry().lookup( "2.5.4.9" );
+        
+        entry.set( "L" );
+        entry.set( "CountryName" );
+        entry.set( "gn" );
+        entry.set( "2.5.4.9" );
+        
+
+        sa = entry.get( "l" );
+        assertNotNull( sa );
+        assertEquals( atL, sa.getType() );
+        assertEquals( "l", sa.getType().getName() );
+        assertEquals( "L", sa.getUpId() );
+
+        sa = entry.get( "c" );
+        assertNotNull( sa );
+        assertEquals( atC, sa.getType() );
+        assertEquals( "c", sa.getType().getName() );
+        assertEquals( "CountryName", sa.getUpId() );
+
+        sa = entry.get( "2.5.4.9" );
+        assertNotNull( sa );
+        assertEquals( atStreet, sa.getType() );
+        assertEquals( "street", sa.getType().getName() );
+        assertEquals( "2.5.4.9", sa.getUpId() );
+
+        sa = entry.get( "givenName" );
+        assertNotNull( sa );
+        assertEquals( atGN, sa.getType() );
+        assertEquals( "givenName", sa.getType().getName() );
+        assertEquals( "gn", sa.getUpId() );
+        
+        // Now try to add existing ATs
+        // First, set some value to the modified AT
+        sa = entry.get( "sn" );
+        sa.add( "test" );
+        
+        // Check that the value has been added to the entry
+        assertEquals( "test", entry.get( "sn" ).get().get() ); 
+        
+        // Now add a new SN empty AT : it should replace the existing one.
+        AttributeType atSNEmpty = registries.getAttributeTypeRegistry().lookup( "sn" );
+        sa = entry.set( atSNEmpty ).get( 0 );
+        assertEquals( "test", sa.get().get() ); 
+        assertNotNull( entry.get(  "sn" ) );
+        assertNull( entry.get(  "sn" ).get() );
+    }
+
+    
+    /**
+     * Test the put( SA... ) method
+     */
+    @Test public void tesPutServerAttributeElipsis() throws NamingException
+    {
+        LdapDN dn = new LdapDN( "cn=test" );
+        DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+
+        // first test a null SA addition. It should be allowed.
+        try
+        {
+            entry.put( (ServerAttribute)null );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        // Ajout de serverAttributes
+        AttributeType atL = registries.getAttributeTypeRegistry().lookup( "localityName" );
+        AttributeType atC = registries.getAttributeTypeRegistry().lookup( "countryName" );
+        AttributeType atGN = registries.getAttributeTypeRegistry().lookup( "givenname" );
+        AttributeType atStreet = registries.getAttributeTypeRegistry().lookup( "2.5.4.9" );
+
+        ServerAttribute sa = new DefaultServerAttribute( atL, "france" );
+        entry.put( sa );
+        
+        assertEquals( 2, entry.size() );
+        assertNotNull( entry.get( "l" ) );
+        assertEquals( "france", entry.get( "l" ).get().get() );
+        
+        ServerAttribute sb = new DefaultServerAttribute( atC, "countryTest" );
+        ServerAttribute sc = new DefaultServerAttribute( atGN, "test" );
+        ServerAttribute sd = new DefaultServerAttribute( atStreet, "testStreet" );
+        entry.put( sb, sc, sd );
+
+        assertEquals( 5, entry.size() );
+        assertNotNull( entry.get( atC ) );
+        assertEquals( "countryTest", entry.get( atC ).get().get() );
+        assertNotNull( entry.get( atGN ) );
+        assertEquals( "test", entry.get( atGN ).get().get() );
+        assertNotNull( entry.get( atStreet) );
+        assertEquals( "testStreet", entry.get( atStreet ).get().get() );
+        
+        // Test a replacement
+        ServerAttribute sbb = new DefaultServerAttribute( atC, "countryTestTest" );
+        ServerAttribute scc = new DefaultServerAttribute( atGN, "testtest" );
+        List<ServerAttribute> result = entry.put( sbb, scc );
+        
+        assertEquals( 2, result.size() );
+        assertEquals( "countryTest", result.get(0).get().get() );
+        assertEquals( "test", result.get(1).get().get() );
+        assertEquals( 5, entry.size() );
+        assertNotNull( entry.get( atC ) );
+        assertEquals( "countryTestTest", entry.get( atC ).get().get() );
+        assertNotNull( entry.get( atGN ) );
+        assertEquals( "testtest", entry.get( atGN ).get().get() );
+        assertNotNull( entry.get( atStreet) );
+        assertEquals( "testStreet", entry.get( atStreet ).get().get() );
+        
+        // test an ObjectClass replacement
+        AttributeType OBJECT_CLASS_AT = registries.getAttributeTypeRegistry().lookup( SchemaConstants.OBJECT_CLASS_AT );
+        ServerAttribute oc = new ObjectClassAttribute( registries, "OBJECTCLASS", "person", "inetorgperson" );
+        List<ServerAttribute> oldOc = entry.put( oc );
+        
+        assertNotNull( oldOc );
+        assertEquals( 1, oldOc.size() );
+        assertEquals( "top", oldOc.get( 0 ).get().get() );
+        
+        assertNotNull( entry.get( "objectClass" ) );
+
+        ServerAttribute newOc = entry.get( "objectClass" );
+        
+        assertNotNull( newOc );
+        assertEquals( OBJECT_CLASS_AT, newOc.getType() );
+        assertEquals( 2, newOc.size() );
+        assertEquals( "OBJECTCLASS", newOc.getUpId() );
+        assertTrue( newOc.contains( "person", "inetOrgPerson" ) );
+    }
+
+    
+    /**
+     * Test the put( AT, String... ) method
+     */
+    @Test public void tesPutAtStringElipsis() throws NamingException
+    {
+        LdapDN dn = new LdapDN( "cn=test" );
+        DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+        
+        AttributeType atCN = registries.getAttributeTypeRegistry().lookup( "cn" );
+
+        // Test an empty AT
+        entry.put( atCN, (String)null );
+        assertEquals( 2, entry.size() );
+        assertEquals( "cn", entry.get( atCN ).getUpId() );
+        assertNull( entry.get( atCN ).get().get() );
+        
+        // Check that we can't use invalid arguments
+        try
+        {
+            entry.put( (AttributeType)null, (String)null );
+            fail();
+        }
+        catch( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        // Add a single value
+        atCN = registries.getAttributeTypeRegistry().lookup( "cn" );
+        entry.put( atCN, "test" );
+        
+        assertEquals( 2, entry.size() );
+        assertEquals( "cn", entry.get( atCN ).getUpId() );
+        assertEquals( 1, entry.get( atCN ).size() );
+        assertEquals( "test", entry.get( atCN ).get().get() );
+        
+        // Add more than one value
+        entry.put( atCN, "test1", "test2", "test3" );
+        
+        assertEquals( 2, entry.size() );
+        assertEquals( "cn", entry.get( atCN ).getUpId() );
+        assertEquals( 3, entry.get( atCN ).size() );
+        assertTrue( entry.contains( "cn", "test1" ) );
+        assertTrue( entry.contains( "cn", "test2" ) );
+        assertTrue( entry.contains( "cn", "test3" ) );
+        
+        // Add twice the same value
+        ServerAttribute sa = entry.put( atCN, "test1", "test2", "test1" );
+        
+        assertEquals( 3, sa.size() );
+        assertTrue( sa.contains( "test1", "test2", "test3" ) );
+        assertEquals( 2, entry.size() );
+        assertEquals( "cn", entry.get( atCN ).getUpId() );
+        assertEquals( 2, entry.get( atCN ).size() );
+        assertTrue( entry.contains( "cn", "test1" ) );
+        assertTrue( entry.contains( "cn", "test2" ) );
+    }
+    
+
+    /**
+     * Test the put( AT, Byte[]... ) method
+     */
+    @Test public void tesPutAtByteElipsis() throws NamingException
+    {
+        LdapDN dn = new LdapDN( "cn=test" );
+        DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+        
+        AttributeType atPwd = registries.getAttributeTypeRegistry().lookup( "userPassword" );
+
+        // Test an empty AT
+        entry.put( atPwd, (byte[])null );
+        assertEquals( 2, entry.size() );
+        assertEquals( "userPassword", entry.get( atPwd ).getUpId() );
+        assertNull( entry.get( atPwd ).get().get() );
+        
+        // Check that we can't use invalid arguments
+        try
+        {
+            entry.put( (AttributeType)null, (byte[])null );
+            fail();
+        }
+        catch( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        byte[] password = StringTools.getBytesUtf8( "test" );
+        byte[] test1 = StringTools.getBytesUtf8( "test1" );
+        byte[] test2 = StringTools.getBytesUtf8( "test2" );
+        byte[] test3 = StringTools.getBytesUtf8( "test3" );
+        
+        // Add a single value
+        atPwd = registries.getAttributeTypeRegistry().lookup( "userPassword" );
+        entry.put( atPwd, password );
+        
+        assertEquals( 2, entry.size() );
+        assertEquals( "userPassword", entry.get( atPwd ).getUpId() );
+        assertEquals( 1, entry.get( atPwd ).size() );
+        assertTrue( Arrays.equals( password, (byte[])entry.get( atPwd ).get().get() ) );
+        
+        // Add more than one value
+        entry.put( atPwd, test1, test2, test3 );
+        
+        assertEquals( 2, entry.size() );
+        assertEquals( "userPassword", entry.get( atPwd ).getUpId() );
+        assertEquals( 3, entry.get( atPwd ).size() );
+        assertTrue( entry.contains( "userpassword", test1 ) );
+        assertTrue( entry.contains( "userpassword", test2 ) );
+        assertTrue( entry.contains( "userpassword", test3 ) );
+        
+        // Add twice the same value
+        ServerAttribute sa = entry.put( atPwd, test1, test2, test1 );
+        
+        assertEquals( 3, sa.size() );
+        assertTrue( sa.contains( test1, test2, test3 ) );
+        assertEquals( 2, entry.size() );
+        assertEquals( "userPassword", entry.get( atPwd ).getUpId() );
+        assertEquals( 2, entry.get( atPwd ).size() );
+        assertTrue( entry.contains( "userpassword", test1 ) );
+        assertTrue( entry.contains( "userpassword", test2 ) );
+    }
+    
+
+    /**
+     * Test the put( AT, ServerValue... ) method
+     */
+    @Test public void tesPutAtSVs() throws NamingException
+    {
+        LdapDN dn = new LdapDN( "cn=test" );
+        DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+        
+        // Adding a null value to an attribute
+        AttributeType atCN = registries.getAttributeTypeRegistry().lookup( "cn" );
+        entry.put( atCN, (ServerValue<?>)null );
+        
+        assertEquals( 2, entry.size() );
+        assertEquals( "cn", entry.get( atCN ).getUpId() );
+        
+        // Check that we can't use invalid arguments
+        try
+        {
+            entry.put( (AttributeType)null, (ServerValue<?>)null );
+            fail();
+        }
+        catch( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        // Add a single value
+        atCN = registries.getAttributeTypeRegistry().lookup( "cn" );
+        ServerValue<?> ssv = new ServerStringValue( atCN, "test" );
+        entry.put( atCN, ssv );
+        
+        assertEquals( 2, entry.size() );
+        assertEquals( "cn", entry.get( atCN ).getUpId() );
+        assertEquals( 1, entry.get( atCN ).size() );
+        assertEquals( "test", entry.get( atCN ).get().get() );
+        
+        // Add more than one value
+        entry.put( atCN, new ServerStringValue( atCN, "test1" ),
+                         new ServerStringValue( atCN, "test2" ), 
+                         new ServerStringValue( atCN, "test3" ));
+        
+        assertEquals( 2, entry.size() );
+        assertEquals( "cn", entry.get( atCN ).getUpId() );
+        assertEquals( 3, entry.get( atCN ).size() );
+        assertTrue( entry.contains( "cn", "test1" ) );
+        assertTrue( entry.contains( "cn", "test2" ) );
+        assertTrue( entry.contains( "cn", "test3" ) );
+        
+        // Add twice the same value
+        ServerAttribute sa = entry.put( atCN, new ServerStringValue( atCN, "test1" ),
+                         new ServerStringValue( atCN, "test2" ), 
+                         new ServerStringValue( atCN, "test1" ));
+        
+        assertEquals( 3, sa.size() );
+        assertTrue( sa.contains( "test1", "test2", "test3" ) );
+        assertEquals( 2, entry.size() );
+        assertEquals( "cn", entry.get( atCN ).getUpId() );
+        assertEquals( 2, entry.get( atCN ).size() );
+        assertTrue( entry.contains( "cn", "test1" ) );
+        assertTrue( entry.contains( "cn", "test2" ) );
+    }
+
+
+    /**
+     * Test the put( upId, String... ) method
+     */
+    @Test public void tesPutUpIdStringElipsis() throws NamingException
+    {
+        LdapDN dn = new LdapDN( "cn=test" );
+        DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+        
+        AttributeType atCN = registries.getAttributeTypeRegistry().lookup( "cn" );
+        
+        // Adding a null value should be possible
+        entry.put( "cn", (String)null );
+        
+        assertEquals( 2, entry.size() );
+        assertEquals( "cn", entry.get( atCN ).getUpId() );
+        assertNull( entry.get( atCN ).get().get() );
+        
+        // Check that we can't use invalid arguments
+        try
+        {
+            entry.put( (String)null, (String)null );
+            fail();
+        }
+        catch( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        // Add a single value
+        atCN = registries.getAttributeTypeRegistry().lookup( "cn" );
+        entry.put( "cn", "test" );
+        
+        assertEquals( 2, entry.size() );
+        assertEquals( "cn", entry.get( atCN ).getUpId() );
+        assertEquals( 1, entry.get( atCN ).size() );
+        assertEquals( "test", entry.get( atCN ).get().get() );
+        
+        // Add more than one value
+        entry.put( "cn", "test1", "test2", "test3" );
+        
+        assertEquals( 2, entry.size() );
+        assertEquals( "cn", entry.get( atCN ).getUpId() );
+        assertEquals( 3, entry.get( atCN ).size() );
+        assertTrue( entry.contains( "cn", "test1" ) );
+        assertTrue( entry.contains( "cn", "test2" ) );
+        assertTrue( entry.contains( "cn", "test3" ) );
+        
+        // Add twice the same value
+        ServerAttribute sa = entry.put( "cn", "test1", "test2", "test1" );
+        
+        assertEquals( 3, sa.size() );
+        assertTrue( sa.contains( "test1", "test2", "test3" ) );
+        assertEquals( 2, entry.size() );
+        assertEquals( "cn", entry.get( atCN ).getUpId() );
+        assertEquals( 2, entry.get( atCN ).size() );
+        assertTrue( entry.contains( "cn", "test1" ) );
+        assertTrue( entry.contains( "cn", "test2" ) );
+    }
+    
+
+    /**
+     * Test the put( upId, byte[]... ) method
+     */
+    @Test public void tesPutUpIdBytesElipsis() throws NamingException
+    {
+        LdapDN dn = new LdapDN( "cn=test" );
+        DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+        
+        AttributeType atPassword = registries.getAttributeTypeRegistry().lookup( "userPassword" );
+        
+        // Adding a null value should be possible
+        entry.put( "userPassword", (byte[])null );
+        assertEquals( 2, entry.size() );
+        assertEquals( "userPassword", entry.get( atPassword ).getUpId() );
+        assertNull( entry.get( atPassword ).get().get() );
+        
+        // Check that we can't use invalid arguments
+        try
+        {
+            entry.put( (String)null, (String)null );
+            fail();
+        }
+        catch( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        // Add a single value
+        byte[] test = StringTools.getBytesUtf8( "test" );
+        byte[] test1 = StringTools.getBytesUtf8( "test1" );
+        byte[] test2 = StringTools.getBytesUtf8( "test2" );
+        byte[] test3 = StringTools.getBytesUtf8( "test3" );
+        
+        entry.put( "userPassword", test );
+        
+        assertEquals( 2, entry.size() );
+        assertEquals( "userPassword", entry.get( atPassword ).getUpId() );
+        assertEquals( 1, entry.get( atPassword ).size() );
+        assertTrue( Arrays.equals( test, (byte[])entry.get( atPassword ).get().get() ) );
+        
+        // Add more than one value
+        entry.put( "userPassword", test1, test2, test3 );
+        
+        assertEquals( 2, entry.size() );
+        assertEquals( "userPassword", entry.get( atPassword ).getUpId() );
+        assertEquals( 3, entry.get( atPassword ).size() );
+        assertTrue( entry.contains( "userPassword", test1 ) );
+        assertTrue( entry.contains( "userPassword", test2 ) );
+        assertTrue( entry.contains( "userPassword", test3 ) );
+        
+        // Add twice the same value
+        ServerAttribute sa = entry.put( "userPassword", test1, test2, test1 );
+        
+        assertEquals( 3, sa.size() );
+        assertTrue( sa.contains( test1, test2, test3 ) );
+        assertEquals( 2, entry.size() );
+        assertEquals( "userPassword", entry.get( atPassword ).getUpId() );
+        assertEquals( 2, entry.get( atPassword ).size() );
+        assertTrue( entry.contains( "userPassword", test1 ) );
+        assertTrue( entry.contains( "userPassword", test2 ) );
+    }
+
+
+    /**
+     * Test the put( upId, AT, String... ) method
+     */
+    @Test public void tesPutUpIDAtStringElipsis() throws NamingException
+    {
+        LdapDN dn = new LdapDN( "cn=test" );
+        DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+        
+        AttributeType atCN = registries.getAttributeTypeRegistry().lookup( "cn" );
+        
+        // Test that we get an error when the ID or AT are null
+        try
+        {
+            entry.put( null, (AttributeType)null, (String)null );
+            fail();
+        }
+        catch( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        // Test an empty AT
+        entry.put( "commonName", atCN, (String)null );
+        assertEquals( 2, entry.size() );
+        assertEquals( "commonName", entry.get( atCN ).getUpId() );
+        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertNull( entry.get( atCN ).get().get() );
+        
+        // Check that we can use a null AttributeType
+        entry.put( "commonName", (AttributeType)null, (String)null );
+        assertEquals( 2, entry.size() );
+        assertEquals( "commonName", entry.get( atCN ).getUpId() );
+        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertNull( entry.get( atCN ).get().get() );
+        
+        // Test that we can use a null upId
+        entry.put( null, atCN, (String)null );
+        assertEquals( 2, entry.size() );
+        assertEquals( "cn", entry.get( atCN ).getUpId() );
+        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertNull( entry.get( atCN ).get().get() );
+        
+        // Test that we can't use an upId which is not compatible
+        // with the AT
+        try
+        {
+            entry.put( "sn", atCN, (String)null );
+            fail();
+        }
+        catch( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        // Test that we can add some new attributes with values
+        ServerAttribute result = entry.put( "CN", atCN, "test1", "test2", "test3" );
+        assertNotNull( result );
+        assertEquals( "cn", result.getUpId() );
+        assertEquals( 2, entry.size() );
+        assertEquals( "CN", entry.get( atCN ).getUpId() );
+        assertNotNull( entry.get( atCN ).get() );
+        assertTrue( entry.contains( "cn", "test1" ) );
+        assertTrue( entry.contains( "CN", "test2" ) );
+        assertTrue( entry.contains( "commonName", "test3" ) );
+    }
+
+
+    /**
+     * Test the put( upId, AT, byte[]... ) method
+     */
+    @Test public void tesPutUpIDAtBytesElipsis() throws NamingException
+    {
+        LdapDN dn = new LdapDN( "cn=test" );
+        DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+        
+        AttributeType atPassword = registries.getAttributeTypeRegistry().lookup( "userPassword" );
+        
+        // Test that we get an error when the ID or AT are null
+        try
+        {
+            entry.put( null, (AttributeType)null, (String)null );
+            fail();
+        }
+        catch( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        // Test an empty AT
+        entry.put( "userPassword", atPassword, (byte[])null );
+        assertEquals( 2, entry.size() );
+        assertEquals( "userPassword", entry.get( atPassword ).getUpId() );
+        assertEquals( "userPassword", entry.get( atPassword ).getType().getName() );
+        assertNull( entry.get( atPassword ).get().get() );
+        
+        // Check that we can use a null AttributeType
+        entry.put( "userPassword", (AttributeType)null, (byte[])null );
+        assertEquals( 2, entry.size() );
+        assertEquals( "userPassword", entry.get( atPassword ).getUpId() );
+        assertEquals( "userPassword", entry.get( atPassword ).getType().getName() );
+        assertNull( entry.get( atPassword ).get().get() );
+        
+        // Test that we can use a null upId
+        entry.put( null, atPassword, (byte[])null );
+        assertEquals( 2, entry.size() );
+        assertEquals( "userPassword", entry.get( atPassword ).getUpId() );
+        assertEquals( "userPassword", entry.get( atPassword ).getType().getName() );
+        assertNull( entry.get( atPassword ).get().get() );
+        
+        // Test that we can't use an upId which is not compatible
+        // with the AT
+        try
+        {
+            entry.put( "sn", atPassword, (byte[])null );
+            fail();
+        }
+        catch( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        // Test that we can add some new attributes with values
+        byte[] test1 = StringTools.getBytesUtf8( "test1" );
+        byte[] test2 = StringTools.getBytesUtf8( "test2" );
+        byte[] test3 = StringTools.getBytesUtf8( "test3" );
+
+        ServerAttribute result = entry.put( "UserPassword", atPassword, test1, test2, test3 );
+        assertNotNull( result );
+        assertEquals( "userPassword", result.getUpId() );
+        assertEquals( 2, entry.size() );
+        assertEquals( "UserPassword", entry.get( atPassword ).getUpId() );
+        assertNotNull( entry.get( atPassword ).get() );
+        assertEquals( 3, entry.get( atPassword ).size() );
+        assertTrue( entry.contains( "UserPassword", test1 ) );
+        assertTrue( entry.contains( "userPassword", test2 ) );
+        assertTrue( entry.contains( "2.5.4.35", test3 ) );
+    }
+
+
+    /**
+     * Test the put( upId, AT, SV... ) method
+     */
+    @Test public void tesPutUpIDAtSVElipsis() throws NamingException
+    {
+        LdapDN dn = new LdapDN( "cn=test" );
+        DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+        
+        AttributeType atCN = registries.getAttributeTypeRegistry().lookup( "cn" );
+        
+        // Test that we get an error when the ID or AT are null
+        try
+        {
+            entry.put( null, (AttributeType)null, (ServerValue<?>)null );
+            fail();
+        }
+        catch( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        // Test an empty AT
+        entry.put( "commonName", atCN, (ServerValue<?>)null );
+        assertEquals( 2, entry.size() );
+        assertEquals( "commonName", entry.get( atCN ).getUpId() );
+        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertNull( entry.get( atCN ).get().get() );
+        
+        // Check that we can use a null AttributeType
+        entry.put( "commonName", (AttributeType)null, (ServerValue<?>)null );
+        assertEquals( 2, entry.size() );
+        assertEquals( "commonName", entry.get( atCN ).getUpId() );
+        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertNull( entry.get( atCN ).get().get() );
+        
+        // Test that we can use a null upId
+        entry.put( null, atCN, (ServerValue<?>)null );
+        assertEquals( 2, entry.size() );
+        assertEquals( "cn", entry.get( atCN ).getUpId() );
+        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertNull( entry.get( atCN ).get().get() );
+        
+        // Test that we can't use an upId which is not compatible
+        // with the AT
+        try
+        {
+            entry.put( "sn", atCN, (ServerValue<?>)null );
+            fail();
+        }
+        catch( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        // Test that we can add some new attributes with values
+        ServerValue<String> test1 = new ServerStringValue( atCN, "test1" );
+        ServerValue<String> test2 = new ServerStringValue( atCN, "test2" );
+        ServerValue<String> test3 = new ServerStringValue( atCN, "test3" );
+
+        ServerAttribute result = entry.put( "CN", atCN, test1, test2, test3 );
+        assertNotNull( result );
+        assertEquals( "cn", result.getUpId() );
+        assertEquals( 2, entry.size() );
+        assertEquals( "CN", entry.get( atCN ).getUpId() );
+        assertNotNull( entry.get( atCN ).get() );
+        assertTrue( entry.contains( "cn", "test1" ) );
+        assertTrue( entry.contains( "CN", "test2" ) );
+        assertTrue( entry.contains( "commonName", "test3" ) );
+    }
+
+
+    /**
+     * Test the put( upId, SV... ) method
+     */
+    @Test public void tesPutUpIDSVElipsis() throws NamingException
+    {
+        LdapDN dn = new LdapDN( "cn=test" );
+        DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
+        
+        AttributeType atCN = registries.getAttributeTypeRegistry().lookup( "cn" );
+        
+        // Test that we get an error when the ID or AT are null
+        try
+        {
+            entry.put( (String)null, (ServerValue<?>)null );
+            fail();
+        }
+        catch( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        // Test an null valued AT
+        entry.put( "commonName", (ServerValue<?>)null );
+        assertEquals( 2, entry.size() );
+        assertEquals( "commonName", entry.get( atCN ).getUpId() );
+        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertNull( entry.get( atCN ).get().get() );
+
+        // Test that we can add some new attributes with values
+        ServerValue<String> test1 = new ServerStringValue( atCN, "test1" );
+        ServerValue<String> test2 = new ServerStringValue( atCN, "test2" );
+        ServerValue<String> test3 = new ServerStringValue( atCN, "test3" );
+
+        ServerAttribute result = entry.put( "CN", test1, test2, test3 );
+        assertNotNull( result );
+        assertEquals( "commonName", result.getUpId() );
+        assertEquals( 2, entry.size() );
+        assertEquals( "CN", entry.get( atCN ).getUpId() );
+        assertNotNull( entry.get( atCN ).get() );
+        assertTrue( entry.contains( "cn", "test1" ) );
+        assertTrue( entry.contains( "CN", "test2" ) );
+        assertTrue( entry.contains( "commonName", "test3" ) );
     }
 }

Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/configuration/PartitionConfigurationIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/configuration/PartitionConfigurationIT.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/configuration/PartitionConfigurationIT.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/configuration/PartitionConfigurationIT.java Sun Jan  6 14:58:12 2008
@@ -22,18 +22,19 @@
 
 import junit.framework.Assert;
 import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.integ.CiRunner;
 import org.apache.directory.server.core.jndi.CoreContextFactory;
 import org.apache.directory.server.core.partition.Partition;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
-import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NameNotFoundException;
-import javax.naming.directory.Attributes;
 import java.util.Hashtable;
 
 
@@ -55,7 +56,8 @@
         Partition partition = new JdbmPartition();
         partition.setId( "removable" );
         partition.setSuffix( "ou=removable" );
-        Attributes ctxEntry = new AttributesImpl( true );
+        
+        ServerEntry ctxEntry = new DefaultServerEntry( service.getRegistries(), new LdapDN( "ou=removable" ) );
         ctxEntry.put( "objectClass", "top" );
         ctxEntry.get( "objectClass" ).add( "organizationalUnit" );
         ctxEntry.put( "ou", "removable" );

Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/MixedCaseITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/MixedCaseITest.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/MixedCaseITest.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/MixedCaseITest.java Sun Jan  6 14:58:12 2008
@@ -36,6 +36,7 @@
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;

Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchWithIndicesITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchWithIndicesITest.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchWithIndicesITest.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchWithIndicesITest.java Sun Jan  6 14:58:12 2008
@@ -22,6 +22,8 @@
 
 import org.apache.directory.server.core.DefaultDirectoryService;
 import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.integ.CiRunner;
 import org.apache.directory.server.core.integ.DirectoryServiceFactory;
 import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
@@ -35,6 +37,8 @@
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import org.apache.directory.shared.ldap.name.LdapDN;
+
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import org.junit.Test;
@@ -126,11 +130,21 @@
 
             JdbmPartition partition = new JdbmPartition();
             partition.setId( "system" );
+            
+            /*
+            ServerEntry serverEntry = new DefaultServerEntry( new LdapDN( "ou=system" ), service.getRegistries() );
+            serverEntry.put( "objectClass", "top", "organizationalUnit" );
+            serverEntry.put( "ou", "system" );
+            partition.setContextEntry( serverEntry );
+            partition.setSuffix( "ou=system" );
+            */
+            
             Attributes attrs = new AttributesImpl( "objectClass", "top", true );
             attrs.get( "objectClass" ).add( "organizationalUnit" );
             attrs.put( "ou", "system" );
             partition.setContextEntry( attrs );
             partition.setSuffix( "ou=system" );
+            
 
             Set<Index> indices = new HashSet<Index>();
             indices.addAll( partition.getIndexedAttributes() );

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java Sun Jan  6 14:58:12 2008
@@ -85,12 +85,14 @@
 import org.apache.directory.shared.ldap.exception.LdapNoPermissionException;
 import org.apache.directory.shared.ldap.ldif.ChangeType;
 import org.apache.directory.shared.ldap.ldif.Entry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.schema.OidNormalizer;
 import org.apache.directory.shared.ldap.util.DateUtils;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -100,8 +102,11 @@
 import javax.naming.directory.Attributes;
 import javax.naming.directory.DirContext;
 import javax.naming.ldap.LdapContext;
+
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
+import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Hashtable;
@@ -695,6 +700,7 @@
                 switch( reverse.getChangeType().getChangeType() )
                 {
                     case( ChangeType.ADD_ORDINAL ):
+                        System.out.println( "Reverted attributes : --> " + reverse.getAttributes() );
                         ctx.createSubcontext( reverse.getDn(), reverse.getAttributes() );
                         break;
                     case( ChangeType.DELETE_ORDINAL ):
@@ -864,7 +870,7 @@
 
     public ServerEntry newEntry( LdapDN dn ) throws NamingException
     {
-        return new DefaultServerEntry( dn, registries );
+        return new DefaultServerEntry( registries, dn );
     }
     
     
@@ -1350,9 +1356,10 @@
         schemaPartition.setIndexedAttributes( indexedAttributes );
         schemaPartition.setSuffix( ServerDNConstants.OU_SCHEMA_DN );
         
-        Attributes entry = new AttributesImpl();
-        entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC );
-        entry.get( SchemaConstants.OBJECT_CLASS_AT ).add( SchemaConstants.ORGANIZATIONAL_UNIT_OC );
+        ServerEntry entry = new DefaultServerEntry( registries, new LdapDN( ServerDNConstants.OU_SCHEMA_DN ) );
+        entry.put( SchemaConstants.OBJECT_CLASS_AT, 
+                SchemaConstants.TOP_OC, 
+                SchemaConstants.ORGANIZATIONAL_UNIT_OC );
         entry.put( SchemaConstants.OU_AT, "schema" );
         schemaPartition.setContextEntry( entry );
         schemaPartition.init( this );
@@ -1412,7 +1419,7 @@
         schemaService = new SchemaService( registries, schemaPartition, schemaControl );
 
 
-        partitionNexus = new DefaultPartitionNexus( new AttributesImpl() );
+        partitionNexus = new DefaultPartitionNexus( new DefaultServerEntry( registries, LdapDN.EMPTY_LDAPDN ) );
         partitionNexus.init( this );
         partitionNexus.addContextPartition( new AddContextPartitionOperationContext( registries, schemaPartition ) );
 
@@ -1429,4 +1436,86 @@
             LOG.debug( "<--- DefaultDirectoryService initialized" );
         }
     }
+    
+    /**
+     * Read an entry (without DN)
+     * 
+     * @param text The ldif format file
+     * @return An Attributes.
+     */
+    private Attributes readEntry( String text )
+    {
+        StringReader strIn = new StringReader( text );
+        BufferedReader in = new BufferedReader( strIn );
+
+        String line = null;
+        Attributes attributes = new AttributesImpl( true );
+
+        try
+        {
+            while ( ( line = in.readLine() ) != null )
+            {
+                if ( line.length() == 0 )
+                {
+                    continue;
+                }
+
+                String addedLine = line.trim();
+
+                if ( StringTools.isEmpty( addedLine ) )
+                {
+                    continue;
+                }
+
+                Attribute attribute = LdifReader.parseAttributeValue( addedLine );
+                Attribute oldAttribute = attributes.get( attribute.getID() );
+
+                if ( oldAttribute != null )
+                {
+                    try
+                    {
+                        oldAttribute.add( attribute.get() );
+                        attributes.put( oldAttribute );
+                    }
+                    catch (NamingException ne)
+                    {
+                        // Do nothing
+                    }
+                }
+                else
+                {
+                    attributes.put( attribute );
+                }
+            }
+        }
+        catch (IOException ioe)
+        {
+            // Do nothing : we can't reach this point !
+        }
+
+        return attributes;
+    }
+
+    
+    /**
+     * Create a new ServerEntry
+     * 
+     * @param dn The DN for this new entry
+     * @param ldif The String representing the attributes, as a LDIF file
+     */
+    public ServerEntry newEntry( String dn, String ldif )
+    {
+        try
+        {
+            Attributes entry = readEntry( ldif );
+            
+            return new DefaultServerEntry( registries, new LdapDN( dn) );
+        }
+        catch ( Exception e )
+        {
+            // do nothing
+            return null;
+        }
+    }
+    
 }

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DirectoryService.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DirectoryService.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DirectoryService.java Sun Jan  6 14:58:12 2008
@@ -22,6 +22,7 @@
 
 import org.apache.directory.server.core.authn.LdapPrincipal;
 import org.apache.directory.server.core.changelog.ChangeLog;
+import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.entry.ServerEntryFactory;
 import org.apache.directory.server.core.interceptor.Interceptor;
 import org.apache.directory.server.core.interceptor.InterceptorChain;
@@ -380,4 +381,13 @@
      * @param changeLog the change log service to set
      */
     void setChangeLog( ChangeLog changeLog );
+    
+
+    /**
+     * Create a new ServerEntry
+     * 
+     * @param dn The DN for this new entry
+     * @param ldif The String representing the attributes, as a LDIF file
+     */
+    ServerEntry newEntry( String dn, String ldif );
 }

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java Sun Jan  6 14:58:12 2008
@@ -30,6 +30,7 @@
 import java.util.Set;
 
 import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.interceptor.BaseInterceptor;
 import org.apache.directory.server.core.interceptor.Interceptor;
 import org.apache.directory.server.core.interceptor.NextInterceptor;
@@ -230,7 +231,7 @@
     }
 
 
-    public Attributes getRootDSE( NextInterceptor next, GetRootDSEOperationContext opContext ) throws NamingException
+    public ServerEntry getRootDSE( NextInterceptor next, GetRootDSEOperationContext opContext ) throws NamingException
     {
         if ( IS_DEBUG )
         {

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/authz/AciAuthorizationInterceptor.java Sun Jan  6 14:58:12 2008
@@ -26,6 +26,7 @@
 import org.apache.directory.server.core.authz.support.ACDFEngine;
 import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.entry.ServerEntryUtils;
+import org.apache.directory.server.core.entry.ServerValue;
 import org.apache.directory.server.core.enumeration.SearchResultFilter;
 import org.apache.directory.server.core.enumeration.SearchResultFilteringEnumeration;
 import org.apache.directory.server.core.interceptor.BaseInterceptor;
@@ -226,10 +227,10 @@
         enabled = directoryService.isAccessControlEnabled();
 
         // stuff for dealing with subentries (garbage for now)
-        String subschemaSubentry = 
-        	( String ) directoryService.getPartitionNexus().getRootDSE( null ).
+        ServerValue<?> subschemaSubentry = 
+        	directoryService.getPartitionNexus().getRootDSE( null ).
         		get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
-        LdapDN subschemaSubentryDnName = new LdapDN( subschemaSubentry );
+        LdapDN subschemaSubentryDnName = new LdapDN( (String)(subschemaSubentry.get()) );
         subschemaSubentryDnName.normalize( atRegistry.getNormalizerMapping() );
         subschemaSubentryDn = subschemaSubentryDnName.toNormName();
     }

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java Sun Jan  6 14:58:12 2008
@@ -21,6 +21,8 @@
 
 import org.apache.commons.collections.map.LRUMap;
 import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.ServerEntryUtils;
+import org.apache.directory.server.core.entry.ServerValue;
 import org.apache.directory.server.core.interceptor.BaseInterceptor;
 import org.apache.directory.server.core.interceptor.NextInterceptor;
 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
@@ -125,7 +127,7 @@
     {
         nexus = directoryService.getPartitionNexus();
         normalizerMap = directoryService.getRegistries().getAttributeTypeRegistry().getNormalizerMapping();
-        Attribute attr = nexus.getRootDSE( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT );
+        ServerValue<?> attr = nexus.getRootDSE( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
         subschemSubentryDn = new LdapDN( ( String ) attr.get() );
         subschemSubentryDn.normalize( normalizerMap );
         registries = directoryService.getRegistries();
@@ -287,7 +289,7 @@
     {
         if ( opContext.getDn().getNormName().equals( subschemSubentryDn.getNormName() ) )
         {
-            return nexus.getRootDSE( null );
+            return ServerEntryUtils.toAttributesImpl( nexus.getRootDSE( null ) );
         }
         
         // check if entry to lookup exists

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java Sun Jan  6 14:58:12 2008
@@ -22,6 +22,7 @@
 
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.authn.LdapPrincipal;
+import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.interceptor.context.AddContextPartitionOperationContext;
 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
 import org.apache.directory.server.core.interceptor.context.BindOperationContext;
@@ -143,7 +144,7 @@
     }
 
 
-    public Attributes getRootDSE( NextInterceptor next, GetRootDSEOperationContext opContext ) throws NamingException
+    public ServerEntry getRootDSE( NextInterceptor next, GetRootDSEOperationContext opContext ) throws NamingException
     {
         return next.getRootDSE( opContext );
     }

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/Interceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/Interceptor.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/Interceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/Interceptor.java Sun Jan  6 14:58:12 2008
@@ -21,6 +21,7 @@
 
 
 import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.interceptor.context.AddContextPartitionOperationContext;
 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
 import org.apache.directory.server.core.interceptor.context.BindOperationContext;
@@ -139,7 +140,7 @@
     /**
      * Filters {@link PartitionNexus#getRootDSE( GetRootDSEOperationContext )} call.
      */
-    Attributes getRootDSE( NextInterceptor next, GetRootDSEOperationContext  opContext ) throws NamingException;
+    ServerEntry getRootDSE( NextInterceptor next, GetRootDSEOperationContext  opContext ) throws NamingException;
 
 
     /**

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java Sun Jan  6 14:58:12 2008
@@ -27,6 +27,7 @@
 import java.util.Map;
 
 import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.interceptor.context.AddContextPartitionOperationContext;
 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
 import org.apache.directory.server.core.interceptor.context.BindOperationContext;
@@ -102,7 +103,7 @@
         }
 
 
-        public Attributes getRootDSE( NextInterceptor next, GetRootDSEOperationContext opContext ) throws NamingException
+        public ServerEntry getRootDSE( NextInterceptor next, GetRootDSEOperationContext opContext ) throws NamingException
         {
             return nexus.getRootDSE( opContext );
         }
@@ -536,7 +537,7 @@
     }
 
 
-    public Attributes getRootDSE( GetRootDSEOperationContext opContext ) throws NamingException
+    public ServerEntry getRootDSE( GetRootDSEOperationContext opContext ) throws NamingException
     {
         Entry entry = getStartingEntry();
         Interceptor head = entry.interceptor;
@@ -1041,7 +1042,7 @@
                 }
 
 
-                public Attributes getRootDSE( GetRootDSEOperationContext opContext ) throws NamingException
+                public ServerEntry getRootDSE( GetRootDSEOperationContext opContext ) throws NamingException
                 {
                     Entry next = getNextEntry();
                     Interceptor interceptor = next.interceptor;

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/NextInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/NextInterceptor.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/NextInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/NextInterceptor.java Sun Jan  6 14:58:12 2008
@@ -27,6 +27,7 @@
 import javax.naming.directory.Attributes;
 import javax.naming.directory.SearchResult;
 
+import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.interceptor.context.AddContextPartitionOperationContext;
 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
 import org.apache.directory.server.core.interceptor.context.BindOperationContext;
@@ -69,7 +70,7 @@
     /**
      * Calls the next interceptor's {@link Interceptor#getRootDSE( NextInterceptor, GetRootDSEOperationContext )}.
      */
-    Attributes getRootDSE( GetRootDSEOperationContext opContext ) throws NamingException;
+    ServerEntry getRootDSE( GetRootDSEOperationContext opContext ) throws NamingException;
 
 
     /**

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java Sun Jan  6 14:58:12 2008
@@ -297,7 +297,7 @@
     }
     
     
-    protected Attributes doGetRootDSEOperation( LdapDN target ) throws NamingException
+    protected ServerEntry doGetRootDSEOperation( LdapDN target ) throws NamingException
     {
         GetRootDSEOperationContext opCtx = new GetRootDSEOperationContext( registries, target );
         opCtx.addRequestControls( requestControls );
@@ -915,7 +915,7 @@
         
         if ( name.size() == 0 )
         {
-            attributes = doGetRootDSEOperation( target );
+            attributes = ServerEntryUtils.toAttributesImpl( doGetRootDSEOperation( target ) );
         }
         else
         {

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java?rev=609459&r1=609458&r2=609459&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java Sun Jan  6 14:58:12 2008
@@ -28,6 +28,7 @@
 import org.apache.directory.server.constants.ApacheSchemaConstants;
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.entry.ServerValue;
 import org.apache.directory.server.core.enumeration.SearchResultFilter;
 import org.apache.directory.server.core.enumeration.SearchResultFilteringEnumeration;
 import org.apache.directory.server.core.interceptor.BaseInterceptor;
@@ -127,9 +128,9 @@
         atRegistry = registries.getAttributeTypeRegistry();
 
         // stuff for dealing with subentries (garbage for now)
-        String subschemaSubentry = ( String ) service.getPartitionNexus()
+        ServerValue<?> subschemaSubentry = service.getPartitionNexus()
                 .getRootDSE( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
-        subschemaSubentryDn = new LdapDN( subschemaSubentry );
+        subschemaSubentryDn = new LdapDN( (String)subschemaSubentry.get() );
         subschemaSubentryDn.normalize( directoryService.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
     }
 



Mime
View raw message