You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/08/23 04:59:52 UTC

svn commit: rev 36745 - in incubator/directory/ldap/trunk/common/src: java/org/apache/ldap/common/message test/org/apache/ldap/common/message

Author: akarasulu
Date: Sun Aug 22 19:59:51 2004
New Revision: 36745

Added:
   incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/LdapResultImplTest.java
Modified:
   incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/LdapResultImpl.java
Log:
Commit changes ...

 o added test cases for equals() implementation in LdapResultImpl
 o fixed NullPointerException due to handling of null Referral objects
 o added check for errorMessage differences which we missed before
 


Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/LdapResultImpl.java
==============================================================================
--- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/LdapResultImpl.java	(original)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/LdapResultImpl.java	Sun Aug 22 19:59:51 2004
@@ -404,12 +404,31 @@
 
         // compare all the like elements of the two LdapResult objects
         LdapResult result = ( LdapResult ) obj;
-        if ( ! referral.equals( result.getReferral() ) )
+
+        if ( referral == null && result.getReferral() != null )
+        {
+            return false;
+        }
+
+        if ( result.getReferral() == null && referral != null )
         {
             return false;
         }
 
+        if ( referral != null && result.getReferral() != null )
+        {
+            if ( ! referral.equals( result.getReferral() ) )
+            {
+                return false;
+            }
+        }
+
         if ( ! resultCode.equals( result.getResultCode() ) )
+        {
+            return false;
+        }
+
+        if ( ! errorMessage.equals( result.getErrorMessage() ) )
         {
             return false;
         }

Added: incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/LdapResultImplTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/LdapResultImplTest.java	Sun Aug 22 19:59:51 2004
@@ -0,0 +1,312 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.common.message;
+
+
+import junit.framework.TestCase;
+import org.apache.ldap.common.AbstractLockable;
+import org.apache.ldap.common.Lockable;
+import org.apache.ldap.common.LockException;
+
+
+/**
+ * Tests the methods of the LdapResultImpl class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a> $Rev$
+ */
+public class LdapResultImplTest extends TestCase
+{
+    /**
+     * Tests to make sure the two same objects are seen as equal.
+     */
+    public void testEqualsSameObj()
+    {
+        LdapResultImpl r0 = new LdapResultImpl( null );
+        assertTrue( "same object should be equal", r0.equals( r0 ) );
+    }
+
+
+    /**
+     * Tests to make sure a default LdapResultImpl equals another one just
+     * created.
+     */
+    public void testEqualsDefaultCopy()
+    {
+        LdapResultImpl r0 = new LdapResultImpl( null );
+        LdapResultImpl r1 = new LdapResultImpl( null );
+
+        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.
+     */
+    public void testEqualsDiffLockableParent()
+    {
+        LdapResultImpl r0 = new LdapResultImpl( new AbstractLockable(){} );
+        LdapResultImpl r1 = new LdapResultImpl( null );
+
+        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.
+     */
+    public void testEqualsDiffImpl()
+    {
+        LdapResultImpl r0 = new LdapResultImpl( new AbstractLockable(){} );
+        LdapResult r1 = new LdapResult()
+        {
+            public ResultCodeEnum getResultCode()
+            {
+                return ResultCodeEnum.SUCCESS;
+            }
+
+            public void setResultCode( ResultCodeEnum a_resultCode )
+            {
+            }
+
+            public String getMatchedDn()
+            {
+                return "";
+            }
+
+            public void setMatchedDn( String a_dn )
+            {
+            }
+
+            public String getErrorMessage()
+            {
+                return "";
+            }
+
+            public void setErrorMessage( String a_errorMessage )
+            {
+            }
+
+            public boolean isReferral()
+            {
+                return false;
+            }
+
+            public Referral getReferral()
+            {
+                return null;
+            }
+
+            public void setReferral( Referral a_referral )
+            {
+            }
+
+            public Lockable getParent()
+            {
+                return null;
+            }
+
+            public boolean isLocked()
+            {
+                return false;
+            }
+
+            public boolean getLocked()
+            {
+                return false;
+            }
+
+            public void setLocked( boolean a_isLocked ) throws LockException
+            {
+            }
+
+            public boolean isUnlockable()
+            {
+                return false;
+            }
+        };
+
+        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.
+     */
+    public void testEqualsCarbonCopy()
+    {
+        LdapResultImpl r0 = new LdapResultImpl( null );
+        LdapResultImpl r1 = new LdapResultImpl( null );
+
+        r0.setErrorMessage( "blah blah blah" );
+        r1.setErrorMessage( "blah blah blah" );
+
+        r0.setMatchedDn( "dc=example,dc=com" );
+        r1.setMatchedDn( "dc=example,dc=com" );
+
+        r0.setResultCode( ResultCodeEnum.TIMELIMITEXCEEDED );
+        r1.setResultCode( ResultCodeEnum.TIMELIMITEXCEEDED );
+
+        Referral refs0 = new ReferralImpl( r0 );
+        refs0.addLdapUrl( "ldap://someserver.com" );
+        refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+        Referral refs1 = new ReferralImpl( r1 );
+        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 for inequality when the error message is different.
+     */
+    public void testNotEqualsDiffErrorMessage()
+    {
+        LdapResultImpl r0 = new LdapResultImpl( null );
+        LdapResultImpl r1 = new LdapResultImpl( null );
+
+        r0.setErrorMessage( "blah blah blah" );
+        r1.setErrorMessage( "blah" );
+
+        r0.setMatchedDn( "dc=example,dc=com" );
+        r1.setMatchedDn( "dc=example,dc=com" );
+
+        r0.setResultCode( ResultCodeEnum.TIMELIMITEXCEEDED );
+        r1.setResultCode( ResultCodeEnum.TIMELIMITEXCEEDED );
+
+        Referral refs0 = new ReferralImpl( r0 );
+        refs0.addLdapUrl( "ldap://someserver.com" );
+        refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+        Referral refs1 = new ReferralImpl( r1 );
+        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.
+     */
+    public void testNotEqualsDiffMatchedDn()
+    {
+        LdapResultImpl r0 = new LdapResultImpl( null );
+        LdapResultImpl r1 = new LdapResultImpl( null );
+
+        r0.setErrorMessage( "blah blah blah" );
+        r1.setErrorMessage( "blah blah blah" );
+
+        r0.setMatchedDn( "dc=example,dc=com" );
+        r1.setMatchedDn( "dc=apache,dc=org" );
+
+        r0.setResultCode( ResultCodeEnum.TIMELIMITEXCEEDED );
+        r1.setResultCode( ResultCodeEnum.TIMELIMITEXCEEDED );
+
+        Referral refs0 = new ReferralImpl( r0 );
+        refs0.addLdapUrl( "ldap://someserver.com" );
+        refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+        Referral refs1 = new ReferralImpl( r1 );
+        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.
+     */
+    public void testNotEqualsDiffResultCode()
+    {
+        LdapResultImpl r0 = new LdapResultImpl( null );
+        LdapResultImpl r1 = new LdapResultImpl( null );
+
+        r0.setErrorMessage( "blah blah blah" );
+        r1.setErrorMessage( "blah blah blah" );
+
+        r0.setMatchedDn( "dc=example,dc=com" );
+        r1.setMatchedDn( "dc=example,dc=com" );
+
+        r0.setResultCode( ResultCodeEnum.TIMELIMITEXCEEDED );
+        r1.setResultCode( ResultCodeEnum.SIZELIMITEXCEEDED );
+
+        Referral refs0 = new ReferralImpl( r0 );
+        refs0.addLdapUrl( "ldap://someserver.com" );
+        refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+        Referral refs1 = new ReferralImpl( r1 );
+        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.
+     */
+    public void testNotEqualsDiffReferrals()
+    {
+        LdapResultImpl r0 = new LdapResultImpl( null );
+        LdapResultImpl r1 = new LdapResultImpl( null );
+
+        r0.setErrorMessage( "blah blah blah" );
+        r1.setErrorMessage( "blah blah blah" );
+
+        r0.setMatchedDn( "dc=example,dc=com" );
+        r1.setMatchedDn( "dc=example,dc=com" );
+
+        r0.setResultCode( ResultCodeEnum.TIMELIMITEXCEEDED );
+        r1.setResultCode( ResultCodeEnum.TIMELIMITEXCEEDED );
+
+        Referral refs0 = new ReferralImpl( r0 );
+        r0.setReferral( refs0 );
+        refs0.addLdapUrl( "ldap://someserver.com" );
+        refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+        Referral refs1 = new ReferralImpl( r1 );
+        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 ) );
+    }
+}