directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1082748 - in /directory/shared/trunk/ldap/model/src: main/java/org/apache/directory/shared/ldap/model/ldif/ test/java/org/apache/directory/shared/ldap/model/ldif/
Date Thu, 17 Mar 2011 23:39:24 GMT
Author: elecharny
Date: Thu Mar 17 23:39:23 2011
New Revision: 1082748

URL: http://svn.apache.org/viewvc?rev=1082748&view=rev
Log:
o Added a LdifControlSerializer test
o Added a LdifEntrySerializer test
o Fixed a NPE in LdifEntry.equals() method

Added:
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializationTest.java
Modified:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifControlSerializer.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifControlSerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifControlSerializer.java?rev=1082748&r1=1082747&r2=1082748&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifControlSerializer.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifControlSerializer.java
Thu Mar 17 23:39:23 2011
@@ -53,22 +53,7 @@ public class LdifControlSerializer
      */
     public static void serialize( LdifControl ldifControl, ObjectOutput out ) throws IOException
     {
-        // The OID
-        out.writeUTF( ldifControl.getOid() );
-        
-        // The criticality
-        out.writeBoolean( ldifControl.isCritical() );
-        
-        // The value if any
-        if ( ldifControl.hasValue() )
-        {
-            out.writeInt( ldifControl.getValue().length );
-            out.write( ldifControl.getValue() );
-        }
-        else
-        {
-            out.writeInt( -1 );
-        }
+        ldifControl.writeExternal( out );
         
         out.flush();
     }
@@ -83,20 +68,15 @@ public class LdifControlSerializer
      */
     public static LdifControl deserialize( ObjectInput in ) throws IOException
     {
-        // The OID
-        String oid = in.readUTF();
-        LdifControl ldifControl = new LdifControl( oid );
-        
-        // The criticality
-        ldifControl.setCritical( in.readBoolean() );
-        
-        int valueSize = in.readInt();
+        LdifControl ldifControl = new LdifControl();
         
-        if ( valueSize >=0 )
+        try
+        {
+            ldifControl.readExternal( in );
+        }
+        catch ( ClassNotFoundException cnfe )
         {
-            byte[] value = new byte[ valueSize ];
-            in.read( value );
-            ldifControl.setValue( value );
+            throw new IOException( cnfe.getMessage() );
         }
 
         return ldifControl;

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java?rev=1082748&r1=1082747&r2=1082748&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java
Thu Mar 17 23:39:23 2011
@@ -956,7 +956,7 @@ public class LdifEntry implements Clonea
         LdifEntry otherEntry = ( LdifEntry ) o;
 
         // Check the Dn
-        Dn thisDn = entry.getDn();
+        Dn thisDn = entryDn;
         Dn dnEntry = otherEntry.getDn();
 
         if ( !thisDn.equals( dnEntry ) )

Added: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializationTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializationTest.java?rev=1082748&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializationTest.java
(added)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializationTest.java
Thu Mar 17 23:39:23 2011
@@ -0,0 +1,526 @@
+/*
+ *  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.model.ldif;
+
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+
+/**
+ * Test the LdifEntry class
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class LdifEntrySerializationTest
+{
+    @Test
+    public void testLdifEntrySimple() throws Exception
+    {
+        String ldif = 
+            "cn: app1\n" + 
+            "objectClass: top\n" + 
+            "objectClass: apApplication\n" + 
+            "displayName:   app1   \n" +
+            "dependencies:\n" + 
+            "envVars:";
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+
+
+    /**
+     * Test a simple LdifEntry
+     * @throws Exception
+     */
+    @Test
+    public void testSimpleLdifEntry() throws Exception
+    {
+        String ldif = 
+            "cn: app1\n" + 
+            "objectClass: top\n" + 
+            "objectClass: apApplication\n" + 
+            "displayName:   app1   \n" +
+            "dependencies:\n" + 
+            "envVars:";
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+    
+    
+    /**
+     * Test a Delete changeType LdifEntry with no control
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void testLdifParserChangeTypeDeleteNoControl() throws Exception
+    {
+        String ldif = 
+            "# Delete an entry. The operation will attach the LDAPv3\n" +
+            "# Tree Delete Control defined in [9]. The criticality\n" +
+            "# field is \"true\" and the controlValue field is\n" + 
+            "# absent, as required by [9].\n" +
+            "changetype: delete\n";
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+    
+    
+    /**
+     * Test a Delete changeType LdifEntry with one control
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void testLdifParserChangeTypeDeleteWithControl() throws Exception
+    {
+        String ldif = 
+            "# Delete an entry. The operation will attach the LDAPv3\n" +
+            "# Tree Delete Control defined in [9]. The criticality\n" +
+            "# field is \"true\" and the controlValue field is\n" + 
+            "# absent, as required by [9].\n" +
+            "control: 1.2.840.113556.1.4.805 true\n" +
+            "changetype: delete\n";
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+    
+
+    /**
+     * Test a Delete changeType LdifEntry with controls
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void testLdifParserChangeTypeDeleteWithControls() throws Exception
+    {
+        String ldif = 
+            "# Delete an entry. The operation will attach the LDAPv3\n" +
+            "# Tree Delete Control defined in [9]. The criticality\n" +
+            "# field is \"true\" and the controlValue field is\n" + 
+            "# absent, as required by [9].\n" +
+            "control: 1.2.840.113556.1.4.805 true\n" +
+            "control: 1.2.840.113556.1.4.806 false: test\n" +
+            "changetype: delete\n";
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+
+
+    /**
+     * Test a Add changeType LdifEntry with no control
+     * @throws Exception
+     */
+    @Test
+    public void testLdifEntryChangeTypeAddNoControl() throws Exception
+    {
+        String ldif = 
+            "changetype: add\n" +
+            "cn: app1\n" + 
+            "objectClass: top\n" + 
+            "objectClass: apApplication\n" + 
+            "displayName:   app1   \n" +
+            "dependencies:\n" + 
+            "envVars:";
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+    
+    
+    /**
+     * Test a Add changeType LdifEntry with a control
+     * @throws Exception
+     */
+    @Test
+    public void testLdifEntryChangeTypeAddWithControl() throws Exception
+    {
+        String ldif = 
+            "control: 1.2.840.113556.1.4.805 true\n" +
+            "changetype: add\n" +
+            "cn: app1\n" + 
+            "objectClass: top\n" + 
+            "objectClass: apApplication\n" + 
+            "displayName:   app1   \n" +
+            "dependencies:\n" + 
+            "envVars:";
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+    
+    
+    /**
+     * Test a Add changeType LdifEntry with controls
+     * @throws Exception
+     */
+    @Test
+    public void testLdifEntryChangeTypeAddWithControls() throws Exception
+    {
+        String ldif = 
+            "control: 1.2.840.113556.1.4.805 true\n" +
+            "control: 1.2.840.113556.1.4.806 false: test\n" +
+            "changetype: add\n" +
+            "cn: app1\n" + 
+            "objectClass: top\n" + 
+            "objectClass: apApplication\n" + 
+            "displayName:   app1   \n" +
+            "dependencies:\n" + 
+            "envVars:";
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+
+
+    /**
+     * Test a ModDn changeType LdifEntry with no control
+     */
+    @Test
+    public void testLdifEntryChangeTypeModDnNoControl() throws Exception
+    {
+        String ldif = 
+            "changetype: moddn\n" +
+            "newrdn: cn=app2\n" + 
+            "deleteoldrdn: 1\n"; 
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+
+
+    /**
+     * Test a ModDn changeType LdifEntry with no control and a newSuperior
+     */
+    @Test
+    public void testLdifEntryChangeTypeModDnRenameNoControlNewSuperior() throws Exception
+    {
+        String ldif = 
+            "changetype: moddn\n" +
+            "newrdn: cn=app2\n" + 
+            "deleteoldrdn: 1\n" +
+            "newsuperior: dc=example, dc=com"; 
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+
+    
+    /**
+     * Test a ModDn changeType LdifEntry with a control
+     * @throws Exception
+     */
+    @Test
+    public void testLdifEntryChangeTypeModdnWithControl() throws Exception
+    {
+        String ldif = 
+            "control: 1.2.840.113556.1.4.805 true\n" +
+            "changetype: moddn\n" +
+            "newrdn: cn=app2\n" + 
+            "deleteoldrdn: 1\n"; 
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+    
+    
+    /**
+     * Test a ModDN changeType LdifEntry with controls
+     * @throws Exception
+     */
+    @Test
+    public void testLdifEntryChangeTypeModddnWithControls() throws Exception
+    {
+        String ldif = 
+            "control: 1.2.840.113556.1.4.805 true\n" +
+            "control: 1.2.840.113556.1.4.806 false: test\n" +
+            "changetype: moddn\n" +
+            "newrdn: cn=app2\n" + 
+            "deleteoldrdn: 1\n"; 
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+    
+    
+    /**
+     * Test a Modify changeType LdifEntry with no control
+     */
+    @Test
+    public void testLdifEntryChangeTypeModifySimple() throws Exception
+    {
+        String ldif = 
+            "changetype: modify\n" +
+            "add: cn\n" +
+            "cn: v1\n" + 
+            "cn: v2\n" +
+            "-"; 
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+    
+    
+    /**
+     * Test a Modify changeType LdifEntry with no attributes
+     */
+    @Test
+    public void testLdifEntryChangeTypeModifyNoAttribute() throws Exception
+    {
+        String ldif = 
+            "changetype: modify\n" +
+            "add: cn\n" +
+            "-"; 
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+    
+    
+    /**
+     * Test a Modify changeType LdifEntry with no attributes and controls
+     */
+    @Test
+    public void testLdifEntryChangeTypeModifyNoAttributeWithControls() throws Exception
+    {
+        String ldif = 
+            "control: 1.2.840.113556.1.4.805 true\n" +
+            "control: 1.2.840.113556.1.4.806 false: test\n" +
+            "changetype: modify\n" +
+            "add: cn\n" +
+            "-"; 
+
+        LdifEntry ldifEntry1 = new LdifEntry( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org",
ldif );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        LdifEntrySerializer.serialize( ldifEntry1, out );
+        
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        LdifEntry ldifEntry2 = LdifEntrySerializer.deserialize( null, in );
+
+        assertEquals( ldifEntry1, ldifEntry2 );
+    }
+}



Mime
View raw message