directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r1056057 [2/2] - /directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/
Date Thu, 06 Jan 2011 20:24:42 GMT
Added: directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/LdapResultImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/LdapResultImplTest.java?rev=1056057&view=auto
==============================================================================
--- directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/LdapResultImplTest.java (added)
+++ directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/LdapResultImplTest.java Thu Jan  6 20:24:41 2011
@@ -0,0 +1,376 @@
+/*
+ *  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.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.codec.message.ReferralImpl;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.LdapResult;
+import org.apache.directory.shared.ldap.message.Referral;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Tests the methods of the LdapResultImpl class.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ *         $Rev: 946251 $
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class LdapResultImplTest
+{
+    /**
+     * Tests to make sure the two same objects are seen as equal.
+     */
+    @Test
+    public void testEqualsSameObj()
+    {
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+        assertTrue( "same object should be equal", r0.equals( r0 ) );
+    }
+
+
+    /**
+     * Tests to make sure a default LdapResultImpl equals another one just
+     * created.
+     */
+    @Test
+    public void testEqualsDefaultCopy()
+    {
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+        assertTrue( "default copy should be equal", r0.equals( r1 ) );
+        assertTrue( "default copy should be equal", r1.equals( r0 ) );
+    }
+
+
+    /**
+     * Tests for equality when the lockable parent is not the same.
+     */
+    @Test
+    public void testEqualsDiffLockableParent()
+    {
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+        assertTrue( "default copy with different lockable parents " + "should be equal", r0.equals( r1 ) );
+        assertTrue( "default copy with different lockable parents " + "should be equal", r1.equals( r0 ) );
+    }
+
+
+    /**
+     * Tests for equality when the lockable parent is the same.
+     */
+    @Test
+    public void testEqualsDiffImpl()
+    {
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+        LdapResult r1 = new LdapResult()
+        {
+            public ResultCodeEnum getResultCode()
+            {
+                return ResultCodeEnum.SUCCESS;
+            }
+
+
+            public void setResultCode( ResultCodeEnum a_resultCode )
+            {
+            }
+
+
+            public DN getMatchedDn()
+            {
+                return null;
+            }
+
+
+            public void setMatchedDn( DN dn )
+            {
+            }
+
+
+            public String getErrorMessage()
+            {
+                return null;
+            }
+
+
+            public void setErrorMessage( String a_errorMessage )
+            {
+            }
+
+
+            public boolean isReferral()
+            {
+                return false;
+            }
+
+
+            public Referral getReferral()
+            {
+                return null;
+            }
+
+
+            public void setReferral( Referral referral )
+            {
+            }
+        };
+
+        assertTrue( "r0 equals should see other impl r1 as equal", r0.equals( r1 ) );
+        assertFalse( "r1 impl uses Object.equals() so it should not see " + "r0 as the same object", r1.equals( r0 ) );
+    }
+
+
+    /**
+     * Tests two non default carbon copies for equality.
+     */
+    @Test
+    public void testEqualsCarbonCopy() throws LdapException
+    {
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+        r0.setErrorMessage( "blah blah blah" );
+        r1.setErrorMessage( "blah blah blah" );
+
+        r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+        r1.setMatchedDn( new DN( "dc=example,dc=com" ) );
+
+        r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+        r1.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+
+        Referral refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs0.addLdapUrl( "ldap://someserver.com" );
+        refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+        Referral refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs1.addLdapUrl( "ldap://someserver.com" );
+        refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+        assertTrue( "exact copy should be equal", r0.equals( r1 ) );
+        assertTrue( "exact copy should be equal", r1.equals( r0 ) );
+    }
+
+
+    /**
+     * Tests to make sure the two same objects have equal HashCode.
+     */
+    @Test
+    public void testHashCodeSameObj()
+    {
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+        assertTrue( r0.hashCode() == r0.hashCode() );
+    }
+
+
+    /**
+     * Tests to make sure a default LdapResultImpl has equal hashCode another one just
+     * created.
+     */
+    @Test
+    public void testHashCodeDefaultCopy()
+    {
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+        assertTrue( r0.hashCode() == r1.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode when the lockable parent is not the same.
+     */
+    @Test
+    public void testHashCodeDiffLockableParent()
+    {
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+        assertTrue( r0.hashCode() == r1.hashCode() );
+    }
+
+
+    /**
+     * Tests two non default carbon copies for equal hashCode.
+     */
+    @Test
+    public void testHashCodeCarbonCopy() throws LdapException
+    {
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+        r0.setErrorMessage( "blah blah blah" );
+        r1.setErrorMessage( "blah blah blah" );
+
+        r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+        r1.setMatchedDn( new DN( "dc=example,dc=com" ) );
+
+        r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+        r1.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+
+        Referral refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs0.addLdapUrl( "ldap://someserver.com" );
+        refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+        Referral refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs1.addLdapUrl( "ldap://someserver.com" );
+        refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+        assertTrue( r0.hashCode() == r1.hashCode() );
+    }
+
+
+    /**
+     * Tests for inequality when the error message is different.
+     */
+    @Test
+    public void testNotEqualsDiffErrorMessage() throws LdapException
+    {
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+        r0.setErrorMessage( "blah blah blah" );
+        r1.setErrorMessage( "blah" );
+
+        r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+        r1.setMatchedDn( new DN( "dc=example,dc=com" ) );
+
+        r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+        r1.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+
+        Referral refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs0.addLdapUrl( "ldap://someserver.com" );
+        refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+        Referral refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs1.addLdapUrl( "ldap://someserver.com" );
+        refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+        assertFalse( "results with different error messages should " + "not be equal", r0.equals( r1 ) );
+        assertFalse( "results with different error messages should " + "not be equal", r1.equals( r0 ) );
+    }
+
+
+    /**
+     * Tests for inequality when the matchedDn properties are not the same.
+     */
+    @Test
+    public void testNotEqualsDiffMatchedDn() throws LdapException
+    {
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+        r0.setErrorMessage( "blah blah blah" );
+        r1.setErrorMessage( "blah blah blah" );
+
+        r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+        r1.setMatchedDn( new DN( "dc=apache,dc=org" ) );
+
+        r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+        r1.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+
+        Referral refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs0.addLdapUrl( "ldap://someserver.com" );
+        refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+        Referral refs1 = new ReferralImpl();
+        refs1.addLdapUrl( "ldap://someserver.com" );
+        refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+        assertFalse( "results with different matchedDn properties " + "should not be equal", r0.equals( r1 ) );
+        assertFalse( "results with different matchedDn properties " + "should not be equal", r1.equals( r0 ) );
+    }
+
+
+    /**
+     * Tests for inequality when the resultCode properties are not the same.
+     */
+    @Test
+    public void testNotEqualsDiffResultCode() throws LdapException
+    {
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+        r0.setErrorMessage( "blah blah blah" );
+        r1.setErrorMessage( "blah blah blah" );
+
+        r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+        r1.setMatchedDn( new DN( "dc=example,dc=com" ) );
+
+        r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+        r1.setResultCode( ResultCodeEnum.SIZE_LIMIT_EXCEEDED );
+
+        Referral refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs0.addLdapUrl( "ldap://someserver.com" );
+        refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+        Referral refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs1.addLdapUrl( "ldap://someserver.com" );
+        refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+        assertFalse( "results with different result codes should not be equal", r0.equals( r1 ) );
+        assertFalse( "results with different result codes should not be equal", r1.equals( r0 ) );
+    }
+
+
+    /**
+     * Tests for inequality when the referrals are not the same.
+     */
+    @Test
+    public void testNotEqualsDiffReferrals() throws LdapException
+    {
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+        org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+        r0.setErrorMessage( "blah blah blah" );
+        r1.setErrorMessage( "blah blah blah" );
+
+        r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+        r1.setMatchedDn( new DN( "dc=example,dc=com" ) );
+
+        r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+        r1.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+
+        Referral refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        r0.setReferral( refs0 );
+        refs0.addLdapUrl( "ldap://someserver.com" );
+        refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+        Referral refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        r1.setReferral( refs1 );
+        refs1.addLdapUrl( "ldap://abc.com" );
+        refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+        assertFalse( "results with different referrals should not be equal", r0.equals( r1 ) );
+        assertFalse( "results with different referrals should not be equal", r1.equals( r0 ) );
+    }
+}

Added: directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ModifyDnRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ModifyDnRequestImplTest.java?rev=1056057&view=auto
==============================================================================
--- directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ModifyDnRequestImplTest.java (added)
+++ directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ModifyDnRequestImplTest.java Thu Jan  6 20:24:41 2011
@@ -0,0 +1,443 @@
+/*
+ *  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.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.*;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.name.RDN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * TestCase for the ModifyDnRequestImpl class.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class ModifyDnRequestImplTest
+{
+    private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
+
+    /**
+     * Constructs a ModifyDnrequest to test.
+     * 
+     * @return the request
+     */
+    private org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl getRequest()
+    {
+        // Construct the ModifyDn request to test
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl request = new org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl( 45 );
+        request.setDeleteOldRdn( true );
+
+        try
+        {
+            request.setName( new DN( "dc=admins,dc=apache,dc=org" ) );
+            request.setNewRdn( new RDN( "dc=administrators" ) );
+            request.setNewSuperior( new DN( "dc=groups,dc=apache,dc=org" ) );
+        }
+        catch ( LdapException ine )
+        {
+            // do nothing
+        }
+
+        return request;
+    }
+
+
+    /**
+     * Tests the same object reference for equality.
+     */
+    @Test
+    public void testEqualsSameObj()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req = new org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl( 5 );
+        assertTrue( req.equals( req ) );
+    }
+
+
+    /**
+     * Tests for equality using exact copies.
+     */
+    @Test
+    public void testEqualsExactCopy0()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+
+        assertTrue( req0.equals( req1 ) );
+    }
+
+
+    /**
+     * Tests for equality using exact copies.
+     */
+    @Test
+    public void testEqualsExactCopy1()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+        req0.setNewSuperior( null );
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+        req1.setNewSuperior( null );
+
+        assertTrue( req0.equals( req1 ) );
+    }
+
+
+    /**
+    * Tests the same object reference for equal hashCode
+    */
+    @Test
+    public void testHashCodeSameObj()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req = new org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl( 5 );
+        assertTrue( req.hashCode() == req.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode using exact copies.
+     */
+    @Test
+    public void testHashCodeExactCopy0()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+
+        assertTrue( req0.hashCode() == req1.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode using exact copies.
+     */
+    @Test
+    public void testHashCodeExactCopy1()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+        req0.setNewSuperior( null );
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+        req1.setNewSuperior( null );
+
+        assertTrue( req0.hashCode() == req1.hashCode() );
+    }
+
+
+    /**
+     * Test for inequality when only the IDs are different.
+     */
+    @Test
+    public void testNotEqualDiffId()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl( 4 );
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl( 5 );
+
+        assertFalse( req0.equals( req1 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the DN names are different.
+     */
+    @Test
+    public void testNotEqualDiffName() throws LdapException
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+        req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+        req1.setName( new DN( "cn=admin,dc=apache,dc=org" ) );
+
+        assertFalse( req0.equals( req1 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the newSuperior DNs are different.
+     */
+    @Test
+    public void testNotEqualDiffNewSuperior() throws LdapException
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+        req0.setNewSuperior( new DN( "cn=admin,dc=example,dc=com" ) );
+
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+        req1.setNewSuperior( new DN( "cn=admin,dc=apache,dc=org" ) );
+
+        assertFalse( req0.equals( req1 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the delete old Rdn properties is different.
+     */
+    @Test
+    public void testNotEqualDiffDeleteOldRdn()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+        req0.setDeleteOldRdn( true );
+
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+        req1.setDeleteOldRdn( false );
+
+        assertFalse( req0.equals( req1 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the new Rdn properties are different.
+     */
+    @Test
+    public void testNotEqualDiffNewRdn() throws LdapException
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+        req0.setNewRdn( new RDN( "cn=admin0" ) );
+
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+        req1.setNewRdn( new RDN( "cn=admin1" ) );
+
+        assertFalse( req0.equals( req1 ) );
+        assertFalse( req1.equals( req0 ) );
+    }
+
+
+    /**
+     * Tests for equality even when another BindRequest implementation is used.
+     */
+    @Test
+    public void testEqualsDiffImpl()
+    {
+        ModifyDnRequest req0 = new ModifyDnRequest()
+        {
+            public DN getName()
+            {
+                try
+                {
+                    return new DN( "dc=admins,dc=apache,dc=org" );
+                }
+                catch ( LdapException ine )
+                {
+                    // do nothing
+                    return null;
+                }
+            }
+
+
+            public void setName( DN name )
+            {
+            }
+
+
+            public RDN getNewRdn()
+            {
+                try
+                {
+                    return new RDN( "dc=administrators" );
+                }
+                catch ( LdapException ine )
+                {
+                    // do nothing
+                    return null;
+                }
+            }
+
+
+            public void setNewRdn( RDN newRdn )
+            {
+            }
+
+
+            public boolean getDeleteOldRdn()
+            {
+                return true;
+            }
+
+
+            public void setDeleteOldRdn( boolean deleteOldRdn )
+            {
+            }
+
+
+            public DN getNewSuperior()
+            {
+                try
+                {
+                    return new DN( "dc=groups,dc=apache,dc=org" );
+                }
+                catch ( LdapException ine )
+                {
+                    // do nothing
+                    return null;
+                }
+            }
+
+
+            public void setNewSuperior( DN newSuperior )
+            {
+            }
+
+
+            public boolean isMove()
+            {
+                return false;
+            }
+
+
+            public MessageTypeEnum getResponseType()
+            {
+                return MessageTypeEnum.MODIFYDN_RESPONSE;
+            }
+
+
+            public boolean hasResponse()
+            {
+                return true;
+            }
+
+
+            public MessageTypeEnum getType()
+            {
+                return MessageTypeEnum.MODIFYDN_REQUEST;
+            }
+
+
+            public Map<String, Control> getControls()
+            {
+                return EMPTY_CONTROL_MAP;
+            }
+
+
+            public void addControl( Control a_control ) throws MessageException
+            {
+            }
+
+
+            public void removeControl( Control a_control ) throws MessageException
+            {
+            }
+
+
+            public int getMessageId()
+            {
+                return 45;
+            }
+
+
+            public Object get( Object a_key )
+            {
+                return null;
+            }
+
+
+            public Object put( Object a_key, Object a_value )
+            {
+                return null;
+            }
+
+
+            public void abandon()
+            {
+            }
+
+
+            public boolean isAbandoned()
+            {
+                return false;
+            }
+
+
+            public void addAbandonListener( AbandonListener listener )
+            {
+            }
+
+
+            public ResultResponse getResultResponse()
+            {
+                return null;
+            }
+
+
+            public void addAllControls( Control[] controls ) throws MessageException
+            {
+            }
+
+
+            public boolean hasControl( String oid )
+            {
+                return false;
+            }
+
+
+            public Control getCurrentControl()
+            {
+                return null;
+            }
+
+
+            public int getControlsLength()
+            {
+                return 0;
+            }
+
+
+            public void setControlsLength( int controlsLength )
+            {
+            }
+
+
+            public int getMessageLength()
+            {
+                return 0;
+            }
+
+
+            public void setMessageLength( int messageLength )
+            {
+            }
+
+
+            public Control getControl( String oid )
+            {
+                return null;
+            }
+
+
+            public void setMessageId( int messageId )
+            {
+            }
+        };
+
+        org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+        assertTrue( req1.equals( req0 ) );
+    }
+}

Added: directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ModifyRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ModifyRequestImplTest.java?rev=1056057&view=auto
==============================================================================
--- directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ModifyRequestImplTest.java (added)
+++ directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ModifyRequestImplTest.java Thu Jan  6 20:24:41 2011
@@ -0,0 +1,539 @@
+/*
+ *  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.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
+import org.apache.directory.shared.ldap.entry.DefaultModification;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.*;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test case for the ModifyRequestImpl class.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class ModifyRequestImplTest
+{
+    private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
+
+    /**
+     * Builds a ModifyRequest for testing purposes.
+     * 
+     * @return the ModifyRequest to use for tests
+     */
+    private org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl getRequest()
+    {
+        // Construct the Modify request to test
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req = new org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl( 45 );
+
+        try
+        {
+            req.setName( new DN( "cn=admin,dc=apache,dc=org" ) );
+        }
+        catch ( LdapException ne )
+        {
+            // do nothing
+        }
+
+        EntryAttribute attr = new DefaultEntryAttribute( "attr0" );
+        attr.add( "val0" );
+        attr.add( "val1" );
+        attr.add( "val2" );
+        Modification item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+        req.addModification( item );
+
+        attr = new DefaultEntryAttribute( "attr1" );
+        attr.add( "val3" );
+        item = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attr );
+        req.addModification( item );
+
+        attr = new DefaultEntryAttribute( "attr2" );
+        attr.add( "val4" );
+        attr.add( "val5" );
+        item = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attr );
+        req.addModification( item );
+
+        return req;
+    }
+
+
+    /**
+     * Tests the same object reference for equality.
+     */
+    @Test
+    public void testEqualsSameObj()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req = getRequest();
+        assertTrue( req.equals( req ) );
+    }
+
+
+    /**
+     * Tests for equality using exact copies.
+     */
+    @Test
+    public void testEqualsExactCopy()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = getRequest();
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+        assertTrue( req0.equals( req1 ) );
+    }
+
+
+    /**
+     * Tests the same object reference for equal hashCode.
+     */
+    @Test
+    public void testHashCodeSameObj()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req = getRequest();
+        assertTrue( req.hashCode() == req.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode using exact copies.
+     */
+    @Test
+    public void testHashCodeExactCopy()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = getRequest();
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+        assertTrue( req0.hashCode() == req1.hashCode() );
+    }
+
+
+    /**
+     * Test for inequality when only the IDs are different.
+     */
+    @Test
+    public void testNotEqualDiffId()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl( 7 );
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl( 5 );
+        assertFalse( req0.equals( req1 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the DN names are different.
+     */
+    @Test
+    public void testNotEqualDiffName()
+    {
+        try
+        {
+            org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = getRequest();
+            req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+            org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+            req1.setName( new DN( "cn=admin,dc=apache,dc=org" ) );
+
+            assertFalse( req0.equals( req1 ) );
+        }
+        catch ( LdapException ine )
+        {
+            // do nothing
+        }
+    }
+
+
+    /**
+     * Test for inequality when only the mods ops are different.
+     */
+    @Test
+    public void testNotEqualDiffModOps()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = getRequest();
+        EntryAttribute attr = new DefaultEntryAttribute( "attr3" );
+        attr.add( "val0" );
+        attr.add( "val1" );
+        attr.add( "val2" );
+        Modification item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+        req0.addModification( item );
+
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+        attr = new DefaultEntryAttribute( "attr3" );
+        attr.add( "val0" );
+        attr.add( "val1" );
+        attr.add( "val2" );
+        item = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attr );
+        req0.addModification( item );
+
+        assertFalse( req0.equals( req1 ) );
+        assertFalse( req1.equals( req0 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the number of mods are different.
+     */
+    @Test
+    public void testNotEqualDiffModCount()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = getRequest();
+        EntryAttribute attr = new DefaultEntryAttribute( "attr3" );
+        attr.add( "val0" );
+        attr.add( "val1" );
+        attr.add( "val2" );
+        Modification item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+        req0.addModification( item );
+
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+
+        assertFalse( req0.equals( req1 ) );
+        assertFalse( req1.equals( req0 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the mods attribute Id's are different.
+     */
+    @Test
+    public void testNotEqualDiffModIds()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = getRequest();
+        EntryAttribute attr = new DefaultEntryAttribute( "attr3" );
+        attr.add( "val0" );
+        attr.add( "val1" );
+        attr.add( "val2" );
+        Modification item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+        req0.addModification( item );
+
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+        attr = new DefaultEntryAttribute( "attr4" );
+        attr.add( "val0" );
+        attr.add( "val1" );
+        attr.add( "val2" );
+        item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+        req0.addModification( item );
+
+        assertFalse( req0.equals( req1 ) );
+        assertFalse( req1.equals( req0 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the mods attribute values are different.
+     */
+    @Test
+    public void testNotEqualDiffModValues()
+    {
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = getRequest();
+        EntryAttribute attr = new DefaultEntryAttribute( "attr3" );
+        attr.add( "val0" );
+        attr.add( "val1" );
+        attr.add( "val2" );
+        Modification item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+        req0.addModification( item );
+
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+        attr = new DefaultEntryAttribute( "attr3" );
+        attr.add( "val0" );
+        attr.add( "val1" );
+        attr.add( "val2" );
+        attr.add( "val3" );
+        item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+        req0.addModification( item );
+
+        assertFalse( req0.equals( req1 ) );
+        assertFalse( req1.equals( req0 ) );
+    }
+
+
+    /**
+     * Tests for equality even when another BindRequest implementation is used.
+     */
+    @Test
+    public void testEqualsDiffImpl()
+    {
+        ModifyRequest req0 = new ModifyRequest()
+        {
+            public Collection<Modification> getModifications()
+            {
+                List<Modification> list = new ArrayList<Modification>();
+                EntryAttribute attr = new DefaultEntryAttribute( "attr0" );
+                attr.add( "val0" );
+                attr.add( "val1" );
+                attr.add( "val2" );
+                Modification item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+                list.add( item );
+
+                attr = new DefaultEntryAttribute( "attr1" );
+                attr.add( "val3" );
+                item = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attr );
+                list.add( item );
+
+                attr = new DefaultEntryAttribute( "attr2" );
+                attr.add( "val4" );
+                attr.add( "val5" );
+                item = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attr );
+                list.add( item );
+
+                return list;
+            }
+
+
+            public void addModification( Modification mod )
+            {
+            }
+
+
+            public void removeModification( Modification mod )
+            {
+            }
+
+
+            public DN getName()
+            {
+                try
+                {
+                    return new DN( "cn=admin,dc=apache,dc=org" );
+                }
+                catch ( Exception e )
+                {
+                    //do nothing
+                    return null;
+                }
+            }
+
+
+            public void setName( DN name )
+            {
+            }
+
+
+            public MessageTypeEnum getResponseType()
+            {
+                return MessageTypeEnum.MODIFY_RESPONSE;
+            }
+
+
+            public boolean hasResponse()
+            {
+                return true;
+            }
+
+
+            public MessageTypeEnum getType()
+            {
+                return MessageTypeEnum.MODIFY_REQUEST;
+            }
+
+
+            public Map<String, Control> getControls()
+            {
+                return EMPTY_CONTROL_MAP;
+            }
+
+
+            public void addControl( Control a_control ) throws MessageException
+            {
+            }
+
+
+            public void removeControl( Control a_control ) throws MessageException
+            {
+            }
+
+
+            public int getMessageId()
+            {
+                return 45;
+            }
+
+
+            public Object get( Object a_key )
+            {
+                return null;
+            }
+
+
+            public Object put( Object a_key, Object a_value )
+            {
+                return null;
+            }
+
+
+            public void abandon()
+            {
+            }
+
+
+            public boolean isAbandoned()
+            {
+                return false;
+            }
+
+
+            public void addAbandonListener( AbandonListener listener )
+            {
+            }
+
+
+            public ResultResponse getResultResponse()
+            {
+                return null;
+            }
+
+
+            public void addAllControls( Control[] controls ) throws MessageException
+            {
+            }
+
+
+            public boolean hasControl( String oid )
+            {
+                return false;
+            }
+
+
+            public Control getCurrentControl()
+            {
+                return null;
+            }
+
+
+            public int getControlsLength()
+            {
+                return 0;
+            }
+
+
+            public void setControlsLength( int controlsLength )
+            {
+            }
+
+
+            public int getMessageLength()
+            {
+                return 0;
+            }
+
+
+            public void setMessageLength( int messageLength )
+            {
+            }
+
+
+            public Control getControl( String oid )
+            {
+                return null;
+            }
+
+
+            public void setMessageId( int messageId )
+            {
+            }
+
+
+            public void addModification( EntryAttribute attr, ModificationOperation modOp )
+            {
+            }
+
+
+            public void replace( String attributeName )
+            {
+            }
+
+
+            public void replace( String attributeName, String... attributeValue )
+            {
+            }
+
+
+            public void replace( String attributeName, byte[]... attributeValue )
+            {
+            }
+
+
+            public void replace( EntryAttribute attr )
+            {
+            }
+
+
+            public void add( String attributeName, String... attributeValue )
+            {
+                // TODO Auto-generated method stub
+
+            }
+
+
+            public void add( String attributeName, byte[]... attributeValue )
+            {
+                // TODO Auto-generated method stub
+
+            }
+
+
+            public void add( EntryAttribute attr )
+            {
+                // TODO Auto-generated method stub
+
+            }
+
+
+            public void remove( String attributeName, String... attributeValue )
+            {
+                // TODO Auto-generated method stub
+
+            }
+
+
+            public void remove( String attributeName, byte[]... attributeValue )
+            {
+                // TODO Auto-generated method stub
+
+            }
+
+
+            public void remove( EntryAttribute attr )
+            {
+                // TODO Auto-generated method stub
+
+            }
+        };
+
+        org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+        assertTrue( req1.equals( req0 ) );
+    }
+}

Added: directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ReferralImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ReferralImplTest.java?rev=1056057&view=auto
==============================================================================
--- directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ReferralImplTest.java (added)
+++ directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ReferralImplTest.java Thu Jan  6 20:24:41 2011
@@ -0,0 +1,243 @@
+/*
+ *  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.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.message.Referral;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Tests the ReferralImpl class.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ *         $Rev: 946251 $
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class ReferralImplTest
+{
+    /**
+     * Tests to make sure the equals method works for the same exact object.
+     */
+    @Test
+    public void testEqualsSameObject()
+    {
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        assertTrue( "equals method should work for the same object", refs.equals( refs ) );
+    }
+
+
+    /**
+     * Tests to make sure the equals method works for two objects that are the
+     * same exact copy of one another.
+     */
+    @Test
+    public void testEqualsExactCopy()
+    {
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs0.addLdapUrl( "ldap://blah0" );
+        refs0.addLdapUrl( "ldap://blah1" );
+        refs0.addLdapUrl( "ldap://blah2" );
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs1.addLdapUrl( "ldap://blah0" );
+        refs1.addLdapUrl( "ldap://blah1" );
+        refs1.addLdapUrl( "ldap://blah2" );
+        assertTrue( "exact copies of Referrals should be equal", refs0.equals( refs1 ) );
+        assertTrue( "exact copies of Referrals should be equal", refs1.equals( refs0 ) );
+    }
+
+
+    /**
+     * Tests to make sure the equals method works for two objects that are the
+     * same exact copy of one another but there are redundant entries.
+     */
+    @Test
+    public void testEqualsExactCopyWithRedundancy()
+    {
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs0.addLdapUrl( "ldap://blah0" );
+        refs0.addLdapUrl( "ldap://blah1" );
+        refs0.addLdapUrl( "ldap://blah2" );
+        refs0.addLdapUrl( "ldap://blah2" );
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs1.addLdapUrl( "ldap://blah0" );
+        refs1.addLdapUrl( "ldap://blah1" );
+        refs1.addLdapUrl( "ldap://blah2" );
+        refs1.addLdapUrl( "ldap://blah2" );
+        assertTrue( "exact copies of Referrals should be equal", refs0.equals( refs1 ) );
+        assertTrue( "exact copies of Referrals should be equal", refs1.equals( refs0 ) );
+    }
+
+
+    /**
+     * Tests to make sure to get equal hashCode for the same exact object.
+     */
+    @Test
+    public void testHashCodeSameObject()
+    {
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        assertTrue( refs.hashCode() == refs.hashCode() );
+    }
+
+
+    /**
+     * Tests to make sure to get equal hashCode for two objects that are the
+     * same exact copy of one another.
+     */
+    @Test
+    public void testHashCodeExactCopy()
+    {
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs0.addLdapUrl( "ldap://blah0" );
+        refs0.addLdapUrl( "ldap://blah1" );
+        refs0.addLdapUrl( "ldap://blah2" );
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs1.addLdapUrl( "ldap://blah0" );
+        refs1.addLdapUrl( "ldap://blah1" );
+        refs1.addLdapUrl( "ldap://blah2" );
+        assertTrue( refs0.hashCode() == refs1.hashCode() );
+    }
+
+
+    /**
+     * Tests to make sure to get equal hashCode for two objects that are the
+     * same exact copy of one another but there are redundant entries.
+     */
+    @Test
+    public void testHashCodeExactCopyWithRedundancy()
+    {
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs0.addLdapUrl( "ldap://blah0" );
+        refs0.addLdapUrl( "ldap://blah1" );
+        refs0.addLdapUrl( "ldap://blah2" );
+        refs0.addLdapUrl( "ldap://blah2" );
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs1.addLdapUrl( "ldap://blah0" );
+        refs1.addLdapUrl( "ldap://blah1" );
+        refs1.addLdapUrl( "ldap://blah2" );
+        refs1.addLdapUrl( "ldap://blah2" );
+        assertTrue( refs0.hashCode() == refs1.hashCode() );
+    }
+
+
+    /**
+     * Tests to make sure the equals method works for two objects that are the
+     * not exact copies of one another but have the same number of URLs.
+     */
+    @Test
+    public void testEqualsSameNumberButDifferentUrls()
+    {
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs0.addLdapUrl( "ldap://blah0" );
+        refs0.addLdapUrl( "ldap://blah1" );
+        refs0.addLdapUrl( "ldap://blah2" );
+        refs0.addLdapUrl( "ldap://blah3" );
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs1.addLdapUrl( "ldap://blah0" );
+        refs1.addLdapUrl( "ldap://blah1" );
+        refs1.addLdapUrl( "ldap://blah2" );
+        refs1.addLdapUrl( "ldap://blah4" );
+        assertFalse( "Referrals should not be equal", refs0.equals( refs1 ) );
+        assertFalse( "Referrals should not be equal", refs1.equals( refs0 ) );
+    }
+
+
+    /**
+     * Tests to make sure the equals method works for two objects that are the
+     * not exact copies of one another and one has a subset of the urls of the
+     * other.
+     */
+    @Test
+    public void testEqualsSubset()
+    {
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs0.addLdapUrl( "ldap://blah0" );
+        refs0.addLdapUrl( "ldap://blah1" );
+        refs0.addLdapUrl( "ldap://blah2" );
+        refs0.addLdapUrl( "ldap://blah3" );
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs1.addLdapUrl( "ldap://blah0" );
+        refs1.addLdapUrl( "ldap://blah1" );
+        assertFalse( "Referrals should not be equal", refs0.equals( refs1 ) );
+        assertFalse( "Referrals should not be equal", refs1.equals( refs0 ) );
+    }
+
+
+    @Test
+    public void testEqualsDifferentImpls()
+    {
+        Referral refs0 = new Referral()
+        {
+            public Collection<String> getLdapUrls()
+            {
+                return Collections.EMPTY_LIST;
+            }
+
+
+            public void addLdapUrl( String url )
+            {
+            }
+
+
+            public void removeLdapUrl( String url )
+            {
+            }
+
+
+            public void addLdapUrlBytes( byte[] urlBytes )
+            {
+            }
+
+
+            public Collection<byte[]> getLdapUrlsBytes()
+            {
+                return null;
+            }
+
+
+            public int getReferralLength()
+            {
+                return 0;
+            }
+
+
+            public void setReferralLength( int referralLength )
+            {
+            }
+        };
+
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+
+        assertFalse( "Object.equals() in effect because we did not redefine " + " equals for the new impl above", refs0
+            .equals( refs1 ) );
+        assertTrue( "Empty Referrals should be equal even if they are different" + " implementation classes", refs1
+            .equals( refs0 ) );
+    }
+}

Added: directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseDoneImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseDoneImplTest.java?rev=1056057&view=auto
==============================================================================
--- directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseDoneImplTest.java (added)
+++ directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseDoneImplTest.java Thu Jan  6 20:24:41 2011
@@ -0,0 +1,270 @@
+/*
+ *  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.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.codec.message.ReferralImpl;
+import org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.*;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * TestCases for the SearchResponseImpl class methods.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ *         $Rev: 946251 $
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class SearchResponseDoneImplTest
+{
+    private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
+
+    /**
+     * Creates and populates a SearchResponseDoneImpl stub for testing purposes.
+     * 
+     * @return a populated SearchResponseDoneImpl stub
+     */
+    private org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl createStub()
+    {
+        // Construct the Search response to test with results and referrals
+        org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl response = new org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl( 45 );
+        LdapResult result = response.getLdapResult();
+
+        try
+        {
+            result.setMatchedDn( new DN( "dc=example,dc=com" ) );
+        }
+        catch ( LdapException ine )
+        {
+            // do nothing
+        }
+
+        result.setResultCode( ResultCodeEnum.SUCCESS );
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl refs = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+        refs.addLdapUrl( "ldap://someserver.com" );
+        refs.addLdapUrl( "ldap://apache.org" );
+        refs.addLdapUrl( "ldap://another.net" );
+        result.setReferral( refs );
+        return response;
+    }
+
+
+    /**
+     * Tests for equality using the same object.
+     */
+    @Test
+    public void testEqualsSameObj()
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp = createStub();
+        assertTrue( resp.equals( resp ) );
+    }
+
+
+    /**
+     * Tests for equality using an exact copy.
+     */
+    @Test
+    public void testEqualsExactCopy()
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp0 = createStub();
+        org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp1 = createStub();
+        assertTrue( resp0.equals( resp1 ) );
+        assertTrue( resp1.equals( resp0 ) );
+    }
+
+
+    /**
+     * Tests for equality using different stub implementations.
+     */
+    @Test
+    public void testEqualsDiffImpl()
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp0 = createStub();
+        SearchResultDone resp1 = new SearchResultDone()
+        {
+            public LdapResult getLdapResult()
+            {
+                org.apache.directory.shared.ldap.codec.message.LdapResultImpl result = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+                try
+                {
+                    result.setMatchedDn( new DN( "dc=example,dc=com" ) );
+                }
+                catch ( Exception e )
+                {
+                    // Do nothing
+                }
+                result.setResultCode( ResultCodeEnum.SUCCESS );
+                ReferralImpl refs = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+                refs.addLdapUrl( "ldap://someserver.com" );
+                refs.addLdapUrl( "ldap://apache.org" );
+                refs.addLdapUrl( "ldap://another.net" );
+                result.setReferral( refs );
+
+                return result;
+            }
+
+
+            public MessageTypeEnum getType()
+            {
+                return MessageTypeEnum.SEARCH_RESULT_DONE;
+            }
+
+
+            public Map<String, Control> getControls()
+            {
+                return EMPTY_CONTROL_MAP;
+            }
+
+
+            public void addControl( Control a_control ) throws MessageException
+            {
+            }
+
+
+            public void removeControl( Control a_control ) throws MessageException
+            {
+            }
+
+
+            public int getMessageId()
+            {
+                return 45;
+            }
+
+
+            public Object get( Object a_key )
+            {
+                return null;
+            }
+
+
+            public Object put( Object a_key, Object a_value )
+            {
+                return null;
+            }
+
+
+            public void addAllControls( Control[] controls ) throws MessageException
+            {
+            }
+
+
+            public boolean hasControl( String oid )
+            {
+                return false;
+            }
+
+
+            public Control getCurrentControl()
+            {
+                return null;
+            }
+
+
+            public int getControlsLength()
+            {
+                return 0;
+            }
+
+
+            public void setControlsLength( int controlsLength )
+            {
+            }
+
+
+            public int getMessageLength()
+            {
+                return 0;
+            }
+
+
+            public void setMessageLength( int messageLength )
+            {
+            }
+
+
+            public Control getControl( String oid )
+            {
+                return null;
+            }
+
+
+            public void setMessageId( int messageId )
+            {
+            }
+        };
+
+        assertTrue( resp0.equals( resp1 ) );
+        assertFalse( resp1.equals( resp0 ) );
+    }
+
+
+    /**
+     * Tests for equal hashCode using the same object.
+     */
+    @Test
+    public void testHashCodeSameObj()
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp = createStub();
+        assertTrue( resp.hashCode() == resp.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode using an exact copy.
+     */
+    @Test
+    public void testHashCodeExactCopy()
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp0 = createStub();
+        org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp1 = createStub();
+        assertTrue( resp0.hashCode() == resp1.hashCode() );
+    }
+
+
+    /**
+     * Tests inequality when messageIds are different.
+     */
+    @Test
+    public void testNotEqualsDiffIds()
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp0 = new org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl( 3 );
+        SearchResultDoneImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl( 4 );
+
+        assertFalse( resp0.equals( resp1 ) );
+        assertFalse( resp1.equals( resp0 ) );
+    }
+}

Added: directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseEntryImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseEntryImplTest.java?rev=1056057&view=auto
==============================================================================
--- directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseEntryImplTest.java (added)
+++ directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseEntryImplTest.java Thu Jan  6 20:24:41 2011
@@ -0,0 +1,155 @@
+/*
+ *  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.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test cases for the methods of the SearchResponseEntryImpl class.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ *         $Rev: 946251 $
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class SearchResponseEntryImplTest
+{
+    /**
+     * Creates and populates an EntryAttribute with a specific id.
+     * 
+     * @param id the id for the attribute
+     * @return the EntryAttribute assembled for testing
+     */
+    private EntryAttribute getEntry( String id )
+    {
+        EntryAttribute attr = new DefaultEntryAttribute( id );
+        attr.add( "value0" );
+        attr.add( "value1" );
+        attr.add( "value2" );
+        return attr;
+    }
+
+
+    /**
+     * Creates and populates an Entry object
+     * 
+     * @return The populated Entry object
+     */
+    private Entry getEntry() throws LdapException
+    {
+        Entry attrs = new DefaultEntry();
+        attrs.put( getEntry( "attr0" ) );
+        attrs.put( getEntry( "attr1" ) );
+        attrs.put( getEntry( "attr2" ) );
+        return attrs;
+    }
+
+
+    /**
+     * Tests for equality when the same object reference is used.
+     */
+    @Test
+    public void testEqualsSameObject()
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+        assertTrue( "the same object should be equal", resp.equals( resp ) );
+    }
+
+
+    /**
+     * Tests for equality when an exact copy is compared.
+     */
+    @Test
+    public void testEqualsExactCopy() throws LdapException
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp0 = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+        resp0.setEntry( getEntry() );
+        resp0.setObjectName( new DN( "dc=example,dc=com" ) );
+
+        org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+        resp1.setEntry( getEntry() );
+        resp1.setObjectName( new DN( "dc=example,dc=com" ) );
+
+        assertTrue( "exact copies should be equal", resp0.equals( resp1 ) );
+        assertTrue( "exact copies should be equal", resp1.equals( resp0 ) );
+    }
+
+
+    /**
+     * Tests for equal hashCode when the same object reference is used.
+     */
+    @Test
+    public void testHashCodeSameObject()
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+        assertTrue( resp.hashCode() == resp.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode when an exact copy is compared.
+     */
+    @Test
+    public void testHashCodeExactCopy() throws LdapException
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp0 = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+        resp0.setEntry( getEntry() );
+        resp0.setObjectName( new DN( "dc=example,dc=com" ) );
+
+        org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+        resp1.setEntry( getEntry() );
+        resp1.setObjectName( new DN( "dc=example,dc=com" ) );
+
+        assertTrue( resp0.hashCode() == resp1.hashCode() );
+    }
+
+
+    /**
+     * Tests for inequality when the objectName dn is not the same.
+     */
+    @Test
+    public void testNotEqualDiffObjectName() throws LdapException
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp0 = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+        resp0.setEntry( getEntry() );
+        resp0.setObjectName( new DN( "dc=apache,dc=org" ) );
+
+        org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+        resp1.setEntry( getEntry() );
+        resp1.setObjectName( new DN( "dc=example,dc=com" ) );
+
+        assertFalse( "different object names should not be equal", resp1.equals( resp0 ) );
+        assertFalse( "different object names should not be equal", resp0.equals( resp1 ) );
+    }
+}

Added: directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseReferenceImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseReferenceImplTest.java?rev=1056057&view=auto
==============================================================================
--- directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseReferenceImplTest.java (added)
+++ directory/shared/branches/alex_refactoring/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseReferenceImplTest.java Thu Jan  6 20:24:41 2011
@@ -0,0 +1,259 @@
+/*
+ *  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.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.message.MessageException;
+import org.apache.directory.shared.ldap.message.MessageTypeEnum;
+import org.apache.directory.shared.ldap.message.Referral;
+import org.apache.directory.shared.ldap.message.SearchResultReference;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * TestCase for the SearchResponseReferenceImpl class.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class SearchResponseReferenceImplTest
+{
+    private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
+
+    /**
+     * Creates a baseline referral to test with and adds it to the supplied
+     * response object.
+     * 
+     * @param resp
+     *            the parent lockable
+     * @return the newly created referral for testing
+     */
+    private Referral getReferral( SearchResultReference resp )
+    {
+        org.apache.directory.shared.ldap.codec.message.ReferralImpl ref = new ReferralImpl();
+        resp.setReferral( ref );
+        ref.addLdapUrl( "http://apache.org???" );
+        ref.addLdapUrl( "http://mit.edu???" );
+        ref.addLdapUrl( "http://abc.com???" );
+        return ref;
+    }
+
+
+    /**
+     * Tests for equality when the same object reference is used.
+     */
+    @Test
+    public void testEqualsSameObject()
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+        getReferral( resp );
+        assertTrue( "the same object should be equal", resp.equals( resp ) );
+    }
+
+
+    /**
+     * Tests for equality when an exact copy is compared.
+     */
+    @Test
+    public void testEqualsExactCopy()
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp0 = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+        getReferral( resp0 );
+        org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+        getReferral( resp1 );
+
+        assertTrue( "exact copies should be equal", resp0.equals( resp1 ) );
+        assertTrue( "exact copies should be equal", resp1.equals( resp0 ) );
+    }
+
+
+    /**
+     * Tests for equality when a different implementation is used.
+     */
+    @Test
+    public void testEqualsDiffImpl()
+    {
+        SearchResultReference resp0 = new SearchResultReference()
+        {
+            public Referral getReferral()
+            {
+                return SearchResponseReferenceImplTest.this.getReferral( this );
+            }
+
+
+            public void setReferral( Referral referral )
+            {
+            }
+
+
+            public MessageTypeEnum getType()
+            {
+                return MessageTypeEnum.SEARCH_RESULT_REFERENCE;
+            }
+
+
+            public Map<String, Control> getControls()
+            {
+                return EMPTY_CONTROL_MAP;
+            }
+
+
+            public void addControl( Control control ) throws MessageException
+            {
+            }
+
+
+            public void removeControl( Control control ) throws MessageException
+            {
+            }
+
+
+            public int getMessageId()
+            {
+                return 5;
+            }
+
+
+            public Object get( Object key )
+            {
+                return null;
+            }
+
+
+            public Object put( Object key, Object value )
+            {
+                return null;
+            }
+
+
+            public void addAllControls( Control[] controls ) throws MessageException
+            {
+            }
+
+
+            public boolean hasControl( String oid )
+            {
+                return false;
+            }
+
+
+            public Control getCurrentControl()
+            {
+                return null;
+            }
+
+
+            public int getControlsLength()
+            {
+                return 0;
+            }
+
+
+            public void setControlsLength( int controlsLength )
+            {
+            }
+
+
+            public int getMessageLength()
+            {
+                return 0;
+            }
+
+
+            public void setMessageLength( int messageLength )
+            {
+            }
+
+
+            public Control getControl( String oid )
+            {
+                return null;
+            }
+
+
+            public void setMessageId( int messageId )
+            {
+            }
+        };
+
+        org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+        getReferral( resp1 );
+
+        assertFalse( "using Object.equal() should NOT be equal", resp0.equals( resp1 ) );
+        assertTrue( "same but different implementations should be equal", resp1.equals( resp0 ) );
+    }
+
+
+    /**
+     * Tests for equal hashCode when the same object reference is used.
+     */
+    @Test
+    public void testHashCodeSameObject()
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+        getReferral( resp );
+        assertTrue( resp.hashCode() == resp.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode when an exact copy is compared.
+     */
+    @Test
+    public void testHashCodeExactCopy()
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp0 = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+        getReferral( resp0 );
+        org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+        getReferral( resp1 );
+
+        assertTrue( resp0.hashCode() == resp1.hashCode() );
+    }
+
+
+    /**
+     * Tests for inequality when the urls are not the same.
+     */
+    @Test
+    public void testNotEqualDiffUrls()
+    {
+        org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp0 = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+        getReferral( resp0 );
+        org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+        getReferral( resp1 );
+        resp1.getReferral().addLdapUrl( "ldap://asdf.com???" );
+
+        assertFalse( "different urls should not be equal", resp1.equals( resp0 ) );
+        assertFalse( "different urls should not be equal", resp0.equals( resp1 ) );
+    }
+
+}



Mime
View raw message