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 2005/12/28 14:42:59 UTC

svn commit: r359517 - /directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapDNTest.java

Author: elecharny
Date: Wed Dec 28 05:42:56 2005
New Revision: 359517

URL: http://svn.apache.org/viewcvs?rev=359517&view=rev
Log:
Added a serialization test

Modified:
    directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapDNTest.java

Modified: directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapDNTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapDNTest.java?rev=359517&r1=359516&r2=359517&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapDNTest.java (original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapDNTest.java Wed Dec 28 05:42:56 2005
@@ -16,6 +16,12 @@
  */
 package org.apache.ldap.common.name;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -2070,5 +2076,70 @@
         assertTrue( result.toString().equals( 
             "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) ) ;
         assertTrue( ( (LdapDN)result).toUpName().equals( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" ) );
+    }
+    
+    /**
+     * Test the serialization of a DN
+     * @throws Exception
+     */
+    public void testNameSerialization() throws Exception
+    {
+        Name name = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" ) ;
+
+        FileOutputStream fOut = null;
+    	ObjectOutputStream oOut = null;
+    	File file = new File( "LdapDN.ser" );
+
+    	try
+    	{
+    		fOut= new FileOutputStream( file);
+    		oOut = new ObjectOutputStream( fOut );
+    		oOut.writeObject( name );
+    	}
+    	catch ( IOException ioe )
+    	{
+    		throw ioe;
+    	}
+    	finally{
+	    	try {
+	    		oOut.flush();
+	    		oOut.close();
+	    		fOut.close();
+	    	} 
+	    	catch ( IOException ioe ) 
+	    	{
+	    		throw ioe;
+	    	}
+    	}
+
+    	FileInputStream fIn = null;
+    	ObjectInputStream oIn = null;
+
+    	try
+    	{
+    		fIn= new FileInputStream( file );
+    		oIn = new ObjectInputStream( fIn );
+
+    		LdapDN nameSer = (LdapDN)oIn.readObject();
+    		
+    		Assert.assertEquals( 0, nameSer.compareTo( name ) );
+    	}
+    	catch ( IOException ioe )
+    	{
+    		throw ioe;
+    	}
+    	finally
+    	{
+    		try 
+    		{
+    			oIn.close();
+    			fIn.close();
+    			file.delete();
+    		} 
+    		catch ( IOException ioe) 
+    		{
+    			throw ioe;
+    		}
+    	}
     }
 }