directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 37084 - in incubator/directory/ldap/trunk/common/src: java/org/apache/ldap/common/message test/org/apache/ldap/common/message
Date Thu, 26 Aug 2004 15:27:54 GMT
Author: akarasulu
Date: Thu Aug 26 08:27:52 2004
New Revision: 37084

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

 o added equals() override that also takes the LDAPOID and payload into account
   for extended requests
 o added and passed test cases for ExtendedRequest equality tests
 


Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/ExtendedRequestImpl.java
==============================================================================
--- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/ExtendedRequestImpl.java
(original)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/ExtendedRequestImpl.java
Thu Aug 26 08:27:52 2004
@@ -1,36 +1,36 @@
-/*
- *   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 ;
+/*
+ *   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;
 
 
 /**
  * Lockable ExtendedRequest implementation.
  * 
- * @author <a href="mailto:directory-dev@incubator.apache.org">
- * Apache Directory Project</a>
- * @version $Rev$
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
+ * @version $Rev$
  */
 public class ExtendedRequestImpl
     extends AbstractRequest implements ExtendedRequest
 {
     /** Extended request's Object Identifier or <b>requestName</b> */
-    private String m_oid ;
+    private String oid;
     /** Extended request's payload or <b>requestValue</b> */
-    private byte [] m_payload ;
+    private byte [] payload;
 
 
     // -----------------------------------------------------------------------
@@ -46,7 +46,7 @@
      */
     public ExtendedRequestImpl( final int id )
     {
-        super( id, TYPE, true ) ;
+        super( id, TYPE, true );
     }
 
 
@@ -63,7 +63,7 @@
      */
     public String getOid()
     {
-        return m_oid ;
+        return oid;
     }
 
 
@@ -74,8 +74,8 @@
      */
     public void setOid( String oid )
     {
-        lockCheck( "Attempt to alter OID of locked ExtendedRequest!" ) ;
-        m_oid = oid ;
+        lockCheck( "Attempt to alter OID of locked ExtendedRequest!" );
+        this.oid = oid;
     }
 
 
@@ -88,7 +88,7 @@
      */
     public byte [] getPayload()
     {
-        return m_payload ;
+        return payload;
     }
 
 
@@ -99,8 +99,8 @@
      */
     public void setPayload( byte [] payload )
     {
-        lockCheck( "Attempt to alter payload of locked ExtendedRequest!" ) ;
-        m_payload = payload ;
+        lockCheck( "Attempt to alter payload of locked ExtendedRequest!" );
+        this.payload = payload;
     }
 
 
@@ -117,6 +117,52 @@
      */
     public MessageTypeEnum getResponseType()
     {
-        return RESP_TYPE ;
+        return RESP_TYPE;
+    }
+
+
+    /**
+     * Checks to see if an object equals this ExtendedRequest.
+     *
+     * @param obj the object to be checked for equality
+     * @return true if the obj equals this ExtendedRequest, false otherwise
+     */
+    public boolean equals( Object obj )
+    {
+        if ( obj == this )
+        {
+            return true;
+        }
+
+        if ( ! super.equals( obj ) )
+        {
+            return false;
+        }
+
+        ExtendedRequest req = ( ExtendedRequest ) obj;
+        if ( ! oid.equals( req.getOid() ) )
+        {
+            return false;
+        }
+
+        if ( payload != null && req.getPayload() == null )
+        {
+            return false;
+        }
+
+        if ( payload == null && req.getPayload() != null )
+        {
+            return false;
+        }
+
+        if ( payload != null && req.getPayload() != null )
+        {
+            if ( ! payload.equals( req.getPayload() ) )
+            {
+                return false;
+            }
+        }
+
+        return true;
     }
 }

Added: incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/ExtendedRequestImplTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/ExtendedRequestImplTest.java
Thu Aug 26 08:27:52 2004
@@ -0,0 +1,212 @@
+/*
+ *   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 java.util.Collection;
+import java.util.Collections;
+
+import org.apache.ldap.common.Lockable;
+import org.apache.ldap.common.LockException;
+
+
+/**
+ * TestCase for the ExtendedRequestImpl class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class ExtendedRequestImplTest extends TestCase
+{
+    /**
+     * Tests the same object referrence for equality.
+     */
+    public void testEqualsSameObj()
+    {
+        ExtendedRequestImpl req = new ExtendedRequestImpl( 5 );
+        assertTrue( req.equals( req ) );
+    }
+
+
+    /**
+     * Tests for equality using exact copies.
+     */
+    public void testEqualsExactCopy()
+    {
+        ExtendedRequestImpl req0 = new ExtendedRequestImpl( 5 );
+        req0.setOid( "1.1.1.1" );
+        req0.setPayload( "Hello World!".getBytes() );
+
+        ExtendedRequestImpl req1 = new ExtendedRequestImpl( 5 );
+        req0.setOid( "1.1.1.1" );
+        req0.setPayload( "Hello World!".getBytes() );
+
+        assertTrue( req0.equals( req1 ) );
+        assertTrue( req1.equals( req0 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the IDs are different.
+     */
+    public void testNotEqualDiffId()
+    {
+        ExtendedRequestImpl req0 = new ExtendedRequestImpl( 7 );
+        ExtendedRequestImpl req1 = new ExtendedRequestImpl( 5 );
+
+        assertFalse( req0.equals( req1 ) );
+        assertFalse( req1.equals( req0 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the OID is different.
+     */
+    public void testNotEqualDiffOID()
+    {
+        ExtendedRequestImpl req0 = new ExtendedRequestImpl( 5 );
+        req0.setOid( "1.1.1.1" );
+        req0.setPayload( "Hello World!".getBytes() );
+
+        ExtendedRequestImpl req1 = new ExtendedRequestImpl( 5 );
+        req0.setOid( "1.2.2.1" );
+        req0.setPayload( "Hello World!".getBytes() );
+
+        assertFalse( req0.equals( req1 ) );
+        assertFalse( req1.equals( req0 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the Assertion values are different.
+     */
+    public void testNotEqualDiffValue()
+    {
+        ExtendedRequestImpl req0 = new ExtendedRequestImpl( 5 );
+        req0.setOid( "1.1.1.1" );
+        req0.setPayload( "Hello ".getBytes() );
+
+        ExtendedRequestImpl req1 = new ExtendedRequestImpl( 5 );
+        req0.setOid( "1.1.1.1" );
+        req0.setPayload( "World!".getBytes() );
+
+        assertFalse( req0.equals( req1 ) );
+        assertFalse( req1.equals( req0 ) );
+    }
+
+
+    /**
+     * Tests for equality even when another ExtendedRequest implementation is used.
+     */
+    public void testEqualsDiffImpl()
+    {
+        ExtendedRequest req0 = new ExtendedRequest()
+        {
+            public String getOid()
+            {
+                return null;
+            }
+
+            public void setOid( String oid )
+            {
+            }
+
+            public byte[] getPayload()
+            {
+                return new byte[0];
+            }
+
+            public void setPayload( byte[] payload )
+            {
+            }
+
+            public MessageTypeEnum getResponseType()
+            {
+                return MessageTypeEnum.COMPARERESPONSE;
+            }
+
+            public boolean hasResponse()
+            {
+                return true;
+            }
+
+            public MessageTypeEnum getType()
+            {
+                return MessageTypeEnum.COMPAREREQUEST;
+            }
+
+            public Collection getControls()
+            {
+                return Collections.EMPTY_LIST;
+            }
+
+            public void add( Control control ) throws MessageException
+            {
+            }
+
+            public void remove( 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 Lockable getParent()
+            {
+                return null;
+            }
+
+            public boolean isLocked()
+            {
+                return false;
+            }
+
+            public boolean getLocked()
+            {
+                return false;
+            }
+
+            public void setLocked( boolean isLocked ) throws LockException
+            {
+            }
+
+            public boolean isUnlockable()
+            {
+                return false;
+            }
+        };
+
+        ExtendedRequestImpl req1 = new ExtendedRequestImpl( 5 );
+        assertTrue( req1.equals( req0 ) );
+        assertFalse( req0.equals( req1 ) );
+    }
+}

Mime
View raw message