You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2007/11/25 03:55:46 UTC

svn commit: r597949 - in /directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap: ldif/LdifReaderTest.java ldif/LdifUtilsTest.java message/AttributeImplTest.java message/ModificationItemImplTest.java

Author: elecharny
Date: Sat Nov 24 18:55:45 2007
New Revision: 597949

URL: http://svn.apache.org/viewvc?rev=597949&view=rev
Log:
Added the ModificationItemImmplTest case
Added some tests for multiple modifications
Fixed some wrong tests

Added:
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModificationItemImplTest.java
Modified:
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/message/AttributeImplTest.java

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java?rev=597949&r1=597948&r2=597949&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java (original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java Sat Nov 24 18:55:45 2007
@@ -242,7 +242,8 @@
                 "dn: dc=example,dc=com\n" +
                 "changetype: modify\n" +
                 "add: administrativeRole\n" +
-                "administrativeRole: accessControlSpecificArea";
+                "administrativeRole: accessControlSpecificArea\n" +
+                "-";
 
         testReaderAttrIdCaseInsensitive( ldif );
         // test that attr id comparisons are case insensitive and that the version in the add: line is used.
@@ -252,7 +253,8 @@
                 "dn: dc=example,dc=com\n" +
                 "changetype: modify\n" +
                 "add: administrativeRole\n" +
-                "administrativerole: accessControlSpecificArea";
+                "administrativerole: accessControlSpecificArea\n" +
+                "-";
 
         testReaderAttrIdCaseInsensitive( ldif );
     }
@@ -1465,37 +1467,7 @@
         }
     }
 
-    public void testLdifParserChangeModifyMultiAttrs() throws Exception
-    {
-        String ldif = 
-            "version: 1\n" + 
-            "dn: ou=Product Development, dc=airius, dc=com\n" + 
-            "changetype: modify\n" +
-            "add: postaladdress\n" +
-            "postaladdress: 123 Anystreet $ Sunnyvale, CA $ 94086\n" + 
-            "-\n" +
-            "delete: postaladdress\n" +
-            "-\n" + 
-            "replace: telephonenumber\n" +
-            "telephonenumber: +1 408 555 1234\n" +
-            "telephonenumber: +1 408 555 5678\n" +
-            "-\n" +
-            "delete: facsimiletelephonenumber\n" +
-            "facsimiletelephonenumber: +1 408 555 9876\n";
-
-        LdifReader reader = new LdifReader();
-
-        try
-        {
-            reader.parseLdif( ldif );
-            fail();
-        }
-        catch (NamingException ne)
-        {
-            assertTrue( true );
-        }
-    }
-
+    
     public void testLdifReaderDirServer() throws NamingException, Exception
     {
         String ldif = 

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java?rev=597949&r1=597948&r2=597949&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java (original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java Sat Nov 24 18:55:45 2007
@@ -22,11 +22,22 @@
 import org.apache.directory.shared.ldap.message.*;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 import org.junit.Test;
 
 import javax.naming.NamingException;
-import javax.naming.directory.*;
+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 java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -951,7 +962,8 @@
      *  dn: cn=test, ou=system
      *  changetype: modify
      *  replace: ou
-     *  ou: BigCompany
+     *  ou: apache
+     *  ou: acme corp
      *  -
      *  replace: l
      *  l: USA
@@ -970,16 +982,84 @@
     @Test
     public void testReverseMultipleModifications() throws NamingException
     {
-        // Create a 
-        ModifyRequest modify = new ModifyRequestImpl( 1 );
-        
+        String initialEntryLdif = 
+        		"dn: cn=test, ou=system\n" + 
+        		"objectclass: top\n" + 
+        		"objectclass: person\n" + 
+        		"cn: test\n" + 
+        		"sn: joe doe\n" + 
+        		"l: USA\n" + 
+        		"ou: apache\n" + 
+        		"ou: acme corp\n"; 
+        
+        LdifReader reader = new LdifReader();
+        List<Entry> entries = reader.parseLdif( initialEntryLdif );
+        
+        Entry initialEntry = entries.get( 0 );
+ 
+        // We will :
+        //   - add an 'ou' value 'BigCompany inc.'
+        //   - delete the 'l' attribute
+        //   - add the 'l=FR' attribute
+        //   - replace the 'l=FR' by a 'l=USA' attribute
+        //   - replace the 'ou' attribute with 'apache' value.
         LdapDN dn = new LdapDN( "cn=test, ou=system" );
         
-        ModificationItem mod = new ModificationItemImpl( 
-            DirContext.REPLACE_ATTRIBUTE, new AttributeImpl( "ou" ) );
+        List<ModificationItemImpl> modifications = new ArrayList<ModificationItemImpl>();
 
-        modify.setName( dn );
-        modify.addModification( mod );
+        // First, inject the 'ou'
+        
+        ModificationItemImpl mod = new ModificationItemImpl( 
+            DirContext.ADD_ATTRIBUTE, new AttributeImpl( "ou", "BigCompany inc." ) );
+        modifications.add( mod );
+
+        // Remove the 'l'
+        mod = new ModificationItemImpl(
+            DirContext.REMOVE_ATTRIBUTE, new AttributeImpl( "l" ) );
+        modifications.add( mod );
+        
+        // Add 'l=FR'
+        mod = new ModificationItemImpl( 
+            DirContext.ADD_ATTRIBUTE, new AttributeImpl( "l", "FR" ) );
+        modifications.add( mod );
+
+        // Replace it with 'l=USA'
+        mod = new ModificationItemImpl( 
+            DirContext.REPLACE_ATTRIBUTE, new AttributeImpl( "l", "USA" ) );
+        modifications.add( mod );
+
+        // Replace the ou value
+        mod = new ModificationItemImpl( 
+            DirContext.REPLACE_ATTRIBUTE, new AttributeImpl( "ou", "apache" ) );
+        modifications.add( mod );
+        
+        Entry reversedEntry = LdifUtils.reverseModify( dn, modifications, initialEntry.getAttributes() );
+
+        String expectedEntryLdif = 
+            "dn: cn=test, ou=system\n" +
+            "changetype: modify\n" +
+            "replace: ou\n" +
+            "ou: apache\n" +
+            "ou: acme corp\n" +
+            "-\n" +
+            "replace: l\n" +
+            "l: USA\n" +
+            "-\n" +
+            "delete: l\n" +
+            "l: FR\n" +
+            "-\n" +
+            "add: l\n" +
+            "l: USA\n" +
+            "-\n" +
+            "delete: ou\n" + 
+            "ou: BigCompany inc.\n" +
+            "-\n\n";
+    
+        reader = new LdifReader();
+        entries = reader.parseLdif( expectedEntryLdif );
+    
+        Entry expectedEntry = entries.get( 0 );
         
+        assertEquals( expectedEntry, reversedEntry );
     }
 }

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/message/AttributeImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/message/AttributeImplTest.java?rev=597949&r1=597948&r2=597949&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/message/AttributeImplTest.java (original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/message/AttributeImplTest.java Sat Nov 24 18:55:45 2007
@@ -92,15 +92,15 @@
     /**
      * Tests for inequality with different id with only case differences.
      */
-    public void testNotEqualDiffCasedId()
+    public void testEqualsDiffCasedId()
     {
         AttributeImpl attr0 = getAttribute();
         AttributeImpl attr1 = new AttributeImpl( "TEST-attr1" );
         attr1.add( "value0" );
         attr1.add( "value1" );
         attr1.add( "value2" );
-        assertFalse( "Attributes with different id case should not be equal", attr0.equals( attr1 ) );
-        assertFalse( "Attributes with different id case should not be equal", attr1.equals( attr0 ) );
+        assertTrue( "Attributes with different id case should not be equal", attr0.equals( attr1 ) );
+        assertTrue( "Attributes with different id case should not be equal", attr1.equals( attr0 ) );
     }
 
 
@@ -202,7 +202,7 @@
         assertEquals( "test", clone.getID() );
         
         // Now test the values
-        NamingEnumeration values = clone.getAll();
+        NamingEnumeration<?> values = clone.getAll();
         
         int i = 0;
         
@@ -281,7 +281,7 @@
         assertEquals( "test", clone.getID() );
         
         // Now test the values
-        NamingEnumeration values = clone.getAll();
+        NamingEnumeration<?> values = clone.getAll();
         
         int i = 0;
         
@@ -351,7 +351,7 @@
         assertEquals( "test", copy.getID() );
         
         // Now test the values
-        NamingEnumeration values = copy.getAll();
+        NamingEnumeration<?> values = copy.getAll();
         
         int i = 0;
         
@@ -430,7 +430,7 @@
         assertEquals( "test", copy.getID() );
         
         // Now test the values
-        NamingEnumeration values = copy.getAll();
+        NamingEnumeration<?> values = copy.getAll();
         
         int i = 0;
         

Added: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModificationItemImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModificationItemImplTest.java?rev=597949&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModificationItemImplTest.java (added)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModificationItemImplTest.java Sat Nov 24 18:55:45 2007
@@ -0,0 +1,75 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.message;
+
+import javax.naming.directory.Attribute;
+import javax.naming.directory.DirContext;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+
+/**
+ * Test the modificationItemImpl class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ModificationItemImplTest
+{
+    /**
+     * Test ModificationImpl equality
+     */
+    @Test
+    public void testEquals()
+    {
+        Attribute attr = new AttributeImpl( "cn", "value" );
+        attr.add( "another value" );
+        
+        ModificationItemImpl mod1 = new ModificationItemImpl( DirContext.ADD_ATTRIBUTE, attr );
+        ModificationItemImpl mod2 = new ModificationItemImpl( DirContext.ADD_ATTRIBUTE, attr );
+        
+        assertEquals( mod1, mod2 );
+        
+        assertEquals( mod1, mod1 );
+        assertEquals( mod2, mod1 );
+        
+        ModificationItemImpl mod3 = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, new AttributeImpl( "cn" ) );  
+        ModificationItemImpl mod4 = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, new AttributeImpl( "cn" ) );
+        
+        assertEquals( mod3, mod4 );
+    }
+    
+    /**
+     * Test ModificationImpl difference
+     */
+    @Test
+    public void testDifferentModificationItemImpl()
+    {
+        Attribute attr = new AttributeImpl( "cn", "value" );
+        Attribute attr2 = new AttributeImpl( "cn", "value" );
+        attr.add( "yet another value" );
+        
+        ModificationItemImpl mod1 = new ModificationItemImpl( DirContext.ADD_ATTRIBUTE, attr );
+        ModificationItemImpl mod2= new ModificationItemImpl( DirContext.ADD_ATTRIBUTE, attr2 );
+        
+        assertNotSame( mod1, mod2 );
+    }
+}