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/26 08:24:38 UTC

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

Author: akarasulu
Date: Wed Aug 25 23:24:36 2004
New Revision: 37060

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

 o added AbstractMessage.equals() override to take LdapResult into account
 o added TestCase for AbstractResultResponse which passed to test equals method
 o formatting & conv: removed m_, a_ and space between ;
 


Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/AbstractResultResponse.java
==============================================================================
--- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/AbstractResultResponse.java	(original)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/AbstractResultResponse.java	Wed Aug 25 23:24:36 2004
@@ -14,7 +14,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.ldap.common.message ;
+package org.apache.ldap.common.message;
 
 
 /**
@@ -28,7 +28,7 @@
     extends AbstractResponse implements ResultResponse
 {
     /** Response result components */
-    private LdapResult m_result ;
+    private LdapResult result;
 
 
     // ------------------------------------------------------------------------
@@ -40,13 +40,13 @@
      * Allows subclasses based on the abstract type to create a response to a
      * request.
      *
-     * @param a_id the response eliciting this Request
-     * @param a_type the message type of the response
+     * @param id the response eliciting this Request
+     * @param type the message type of the response
      */
-    protected AbstractResultResponse( final int a_id,
-        final MessageTypeEnum a_type )
+    protected AbstractResultResponse( final int id,
+        final MessageTypeEnum type )
     {
-        super( a_id, a_type ) ;
+        super( id, type );
     }
 
 
@@ -62,18 +62,56 @@
      */
     public LdapResult getLdapResult()
     {
-        return m_result ;
+        return result;
     }
 
 
     /**
      * Sets the LdapResult components of this Response.
      *
-     * @param a_ldapResult the LdapResult for this Response.
+     * @param ldapResult the LdapResult for this Response.
      */
-    public void setLdapResult( LdapResult a_ldapResult )
+    public void setLdapResult( LdapResult ldapResult )
     {
-        lockCheck( "Attempt to alter the LdapResult for a locked Response!" ) ;
-        m_result = a_ldapResult ;
+        lockCheck( "Attempt to alter the LdapResult for a locked Response!" );
+        result = ldapResult;
+    }
+
+
+    /**
+     * Checks to see if an object is equal to this AbstractResultResponse.
+     * First the object is checked to see if it is this AbstractResultResponse
+     * instance if so it returns true.  Next it checks if the super method
+     * returns false and if it does false is returned.  It then checks if the
+     * LDAPResult's are equal.  If not false is returned and if they match
+     * true is returned.
+     *
+     * @param obj the object to compare to this LdapResult containing response
+     * @return true if they objects are equivalent false otherwise
+     */
+    public boolean equals( Object obj )
+    {
+        if ( obj == this )
+        {
+            return true;
+        }
+
+        if ( ! super.equals( obj ) )
+        {
+            return false;
+        }
+
+        if ( ! ( obj instanceof ResultResponse ) )
+        {
+            return false;
+        }
+
+        ResultResponse resp = ( ResultResponse ) obj;
+        if ( ! resp.getLdapResult().equals( result ) )
+        {
+            return false;
+        }
+
+        return true;
     }
 }

Added: incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/AbstractResultResponseTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/AbstractResultResponseTest.java	Wed Aug 25 23:24:36 2004
@@ -0,0 +1,209 @@
+/*
+ *   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.Lockable;
+import org.apache.ldap.common.LockException;
+
+
+/**
+ * TestCase for the methods of the AbstractResultResponse class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class AbstractResultResponseTest extends TestCase
+{
+    /**
+     * Tests to see the same object returns true.
+     */
+    public void testEqualsSameObj()
+    {
+        AbstractResultResponse msg;
+        msg = new AbstractResultResponse( 5, MessageTypeEnum.BINDREQUEST ) {};
+        assertTrue( msg.equals( msg ) );
+    }
+
+
+    /**
+     * Tests to see the same exact copy returns true.
+     */
+    public void testEqualsExactCopy()
+    {
+        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" );
+
+        AbstractResultResponse msg0;
+        AbstractResultResponse msg1;
+        msg0 = new AbstractResultResponse( 5, MessageTypeEnum.BINDREQUEST ) {};
+        msg0.setLdapResult( r0 );
+        msg1 = new AbstractResultResponse( 5, MessageTypeEnum.BINDREQUEST ) {};
+        msg1.setLdapResult( r1 );
+        assertTrue( msg0.equals( msg1 ) );
+        assertTrue( msg1.equals( msg0 ) );
+    }
+
+
+    /**
+     * Tests to see the same exact copy returns true.
+     */
+    public void testNotEqualsDiffResult()
+    {
+        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" );
+
+        AbstractResultResponse msg0;
+        AbstractResultResponse msg1;
+        msg0 = new AbstractResultResponse( 5, MessageTypeEnum.BINDREQUEST ) {};
+        msg0.setLdapResult( r0 );
+        msg1 = new AbstractResultResponse( 5, MessageTypeEnum.BINDREQUEST ) {};
+        msg1.setLdapResult( r1 );
+        assertFalse( msg0.equals( msg1 ) );
+        assertFalse( msg1.equals( msg0 ) );
+    }
+
+
+    /**
+     * Tests to make sure changes in the id result in inequality.
+     */
+    public void testNotEqualsDiffId()
+    {
+        AbstractResultResponse msg0;
+        AbstractResultResponse msg1;
+        msg0 = new AbstractResultResponse( 5, MessageTypeEnum.BINDREQUEST ) {};
+        msg1 = new AbstractResultResponse( 6, MessageTypeEnum.BINDREQUEST ) {};
+        assertFalse( msg0.equals( msg1 ) );
+        assertFalse( msg1.equals( msg0 ) );
+    }
+
+
+    /**
+     * Tests to make sure changes in the type result in inequality.
+     */
+    public void testNotEqualsDiffType()
+    {
+        AbstractResultResponse msg0;
+        AbstractResultResponse msg1;
+        msg0 = new AbstractResultResponse( 5, MessageTypeEnum.BINDREQUEST ) {};
+        msg1 = new AbstractResultResponse( 5, MessageTypeEnum.UNBINDREQUEST ) {};
+        assertFalse( msg0.equals( msg1 ) );
+        assertFalse( msg1.equals( msg0 ) );
+    }
+
+
+    /**
+     * Tests to make sure changes in the controls result in inequality.
+     */
+    public void testNotEqualsDiffControls()
+    {
+        AbstractResultResponse msg0;
+        AbstractResultResponse msg1;
+        msg0 = new AbstractResultResponse( 5, MessageTypeEnum.BINDREQUEST ) {};
+        msg0.add( new Control() {
+            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;
+            }
+
+            public String getType()
+            {
+                return null;
+            }
+
+            public void setType( String a_oid )
+            {
+            }
+
+            public byte[] getValue()
+            {
+                return new byte[0];
+            }
+
+            public void setValue( byte[] a_value )
+            {
+            }
+
+            public boolean isCritical()
+            {
+                return false;
+            }
+
+            public void setCritical( boolean a_isCritical )
+            {
+            }
+        });
+        msg1 = new AbstractResultResponse( 5, MessageTypeEnum.BINDREQUEST ) {};
+        assertFalse( msg0.equals( msg1 ) );
+        assertFalse( msg1.equals( msg0 ) );
+    }
+}