directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 37062 - in incubator/directory/ldap/trunk/common/src: java/org/apache/ldap/common/message test/org/apache/ldap/common/message
Date Thu, 26 Aug 2004 07:17:43 GMT
Author: akarasulu
Date: Thu Aug 26 00:17:42 2004
New Revision: 37062

Added:
   incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/AddRequestImplTest.java
   incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/DeleteRequestImplTest.java
Modified:
   incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/AddRequestImpl.java
   incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/AddResponseImpl.java
   incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/DeleteRequestImpl.java
   incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/DeleteResponseImpl.java
Log:
Commit changes ...

 o code conventions: removed m_, a_ and space before ;
 o added equals override to AddRequestImpl
 o added equals override to DeleteRequestImpl
 o added and passed test cases for both Add and Delete request impls
 


Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/AddRequestImpl.java
==============================================================================
--- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/AddRequestImpl.java
(original)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/AddRequestImpl.java
Thu Aug 26 00:17:42 2004
@@ -14,10 +14,10 @@
  *   limitations under the License.
  *
  */
-package org.apache.ldap.common.message ;
+package org.apache.ldap.common.message;
 
 
-import javax.naming.directory.Attributes ;
+import javax.naming.directory.Attributes;
 
 
 /**
@@ -31,9 +31,9 @@
     extends AbstractRequest implements AddRequest
 {
     /** Distinguished name of the new entry. */
-    private String m_name ;
+    private String name;
     /** A MultiMap of the new entry's attributes and their values */
-    private Attributes m_entry ;
+    private Attributes entry;
 
 
     // ------------------------------------------------------------------------
@@ -48,7 +48,7 @@
      */
     public AddRequestImpl( final int id )
     {
-        super( id, TYPE, true ) ;
+        super( id, TYPE, true );
     }
 
 
@@ -64,7 +64,7 @@
      */
     public String getName()
     {
-        return m_name ;
+        return name;
     }
 
 
@@ -75,8 +75,8 @@
      */
     public void setName( String name )
     {
-        lockCheck( "Attempt to alter new entry name of locked AddRequest!" ) ;
-        m_name = name ;
+        lockCheck( "Attempt to alter new entry name of locked AddRequest!" );
+        this.name = name;
     }
 
 
@@ -87,7 +87,7 @@
      */
     public Attributes getEntry()
     {
-        return m_entry ;
+        return entry;
     }
 
 
@@ -99,8 +99,8 @@
      */
     public void setEntry( Attributes entry )
     {
-        lockCheck( "Attempt to alter entry of locked AddRequest!" ) ;
-        m_entry = entry ;
+        lockCheck( "Attempt to alter entry of locked AddRequest!" );
+        this.entry = entry;
     }
 
 
@@ -117,6 +117,72 @@
      */
     public MessageTypeEnum getResponseType()
     {
-        return RESP_TYPE ;
+        return RESP_TYPE;
+    }
+
+
+    /**
+     * Checks to see if an object is equivalent to this AddRequest.  First
+     * there's a quick test to see if the obj is the same object as this
+     * one - if so true is returned. Next if the super method fails false is
+     * returned.  Then the name of the entry is compared - if not the same false
+     * is returned.  Lastly the attributes of the entry are compared.  If they
+     * are not the same false is returned otherwise the method exists returning
+     * true.
+     *
+     * @param obj the object to test for equality to this
+     * @return true if the obj is equal to this AddRequest, false otherwise
+     */
+    public boolean equals( Object obj )
+    {
+        if ( this == obj )
+        {
+            return true;
+        }
+
+        if ( ! super.equals( obj ) )
+        {
+            return false;
+        }
+
+        AddRequest req = ( AddRequest ) obj;
+
+        if ( name != null && req.getName() == null )
+        {
+            return false;
+        }
+
+        if ( name == null && req.getName() != null )
+        {
+            return false;
+        }
+
+        if ( name != null && req.getName() != null )
+        {
+            if ( ! name.equals( req.getName() ) )
+            {
+                return false;
+            }
+        }
+
+        if ( entry != null && req.getEntry() == null )
+        {
+            return false;
+        }
+
+        if ( entry == null && req.getEntry() != null )
+        {
+            return false;
+        }
+
+        if ( entry != null && req.getEntry() != null )
+        {
+            if ( ! entry.equals( req.getEntry() ) )
+            {
+                return false;
+            }
+        }
+
+        return true;
     }
 }

Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/AddResponseImpl.java
==============================================================================
--- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/AddResponseImpl.java
(original)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/AddResponseImpl.java
Thu Aug 26 00:17:42 2004
@@ -14,7 +14,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.ldap.common.message ;
+package org.apache.ldap.common.message;
 
 
 /**

Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/DeleteRequestImpl.java
==============================================================================
--- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/DeleteRequestImpl.java
(original)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/DeleteRequestImpl.java
Thu Aug 26 00:17:42 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 AbstractRequest implements DeleteRequest
 {
     /** The distinguished name of the entry to delete */
-    private String m_name ;
+    private String name;
 
 
     // ------------------------------------------------------------------------
@@ -44,7 +44,7 @@
      */
     public DeleteRequestImpl( final int id )
     {
-        super( id, TYPE, true ) ;
+        super( id, TYPE, true );
     }
 
 
@@ -61,7 +61,7 @@
      */
     public String getName()
     {
-        return m_name ;
+        return name;
     }
 
 
@@ -73,8 +73,8 @@
      */
     public void setName( String name )
     {
-        lockCheck( "Attempt to alter entry name of locked DeleteRequest!" ) ;
-        m_name = name ;
+        lockCheck( "Attempt to alter entry name of locked DeleteRequest!" );
+        this.name = name;
     }
 
 
@@ -91,6 +91,52 @@
      */
     public MessageTypeEnum getResponseType()
     {
-        return RESP_TYPE ;
+        return RESP_TYPE;
+    }
+
+
+    /**
+     * Checks to see if an object is equivalent to this DeleteRequest.  First
+     * there's a quick test to see if the obj is the same object as this
+     * one - if so true is returned. Next if the super method fails false is
+     * returned.  Then the name of the entry is compared - if not the same false
+     * is returned.  Finally the method exists returning true.
+     *
+     * @param obj the object to test for equality to this
+     * @return true if the obj is equal to this DeleteRequest, false otherwise
+     */
+    public boolean equals( Object obj )
+    {
+        if ( this == obj )
+        {
+            return true;
+        }
+
+        if ( ! super.equals( obj ) )
+        {
+            return false;
+        }
+
+        DeleteRequest req = ( DeleteRequest ) obj;
+
+        if ( name != null && req.getName() == null )
+        {
+            return false;
+        }
+
+        if ( name == null && req.getName() != null )
+        {
+            return false;
+        }
+
+        if ( name != null && req.getName() != null )
+        {
+            if ( ! name.equals( req.getName() ) )
+            {
+                return false;
+            }
+        }
+
+        return true;
     }
 }

Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/DeleteResponseImpl.java
==============================================================================
--- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/DeleteResponseImpl.java
(original)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/DeleteResponseImpl.java
Thu Aug 26 00:17:42 2004
@@ -1,27 +1,27 @@
-/*
- *   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 DeleteResponse implementation
  * 
- * @author <a href="mailto:directory-dev@incubator.apache.org">
- * Apache Directory Project</a>
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
  * @version $Rev$
  */
 public class DeleteResponseImpl

Added: incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/AddRequestImplTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/AddRequestImplTest.java
Thu Aug 26 00:17:42 2004
@@ -0,0 +1,257 @@
+/*
+ *   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;
+
+import javax.naming.directory.Attributes;
+
+
+/**
+ * TestCase for the AddRequestImpl class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class AddRequestImplTest extends TestCase
+{
+    /**
+     * Creates and populates a LockableAttributeImpl with a specific id.
+     *
+     * @param id the id for the attribute
+     * @return the LockableAttributeImpl assembled for testing
+     */
+    private LockableAttributeImpl getAttribute( String id )
+    {
+        LockableAttributeImpl attr = new LockableAttributeImpl( id );
+        attr.add( "value0" );
+        attr.add( "value1" );
+        attr.add( "value2" );
+        return attr;
+    }
+
+
+    /**
+     * Creates and populates a LockableAttributes object
+     *
+     * @return
+     */
+    private LockableAttributesImpl getAttributes()
+    {
+        LockableAttributesImpl attrs = new LockableAttributesImpl();
+        attrs.put( getAttribute( "attr0" ) );
+        attrs.put( getAttribute( "attr1" ) );
+        attrs.put( getAttribute( "attr2" ) );
+        return attrs;
+    }
+
+
+    /**
+     * Tests the same object referrence for equality.
+     */
+    public void testEqualsSameObj()
+    {
+        AddRequestImpl req = new AddRequestImpl( 5 );
+        assertTrue( req.equals( req ) );
+    }
+
+
+    /**
+     * Tests for equality using exact copies.
+     */
+    public void testEqualsExactCopy()
+    {
+        AddRequestImpl req0 = new AddRequestImpl( 5 );
+        req0.setName( "cn=admin,dc=example,dc=com" );
+        req0.setEntry( getAttributes() );
+
+        AddRequestImpl req1 = new AddRequestImpl( 5 );
+        req1.setName( "cn=admin,dc=example,dc=com" );
+        req1.setEntry( getAttributes() );
+
+        assertTrue( req0.equals( req1 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the IDs are different.
+     */
+    public void testNotEqualDiffId()
+    {
+        AddRequestImpl req0 = new AddRequestImpl( 7 );
+        req0.setName( "cn=admin,dc=example,dc=com" );
+        req0.setEntry( getAttributes() );
+
+        AddRequestImpl req1 = new AddRequestImpl( 5 );
+        req1.setName( "cn=admin,dc=example,dc=com" );
+        req1.setEntry( getAttributes() );
+
+        assertFalse( req0.equals( req1 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the DN names are different.
+     */
+    public void testNotEqualDiffName()
+    {
+        AddRequestImpl req0 = new AddRequestImpl( 5 );
+        req0.setName( "cn=admin,dc=example,dc=com" );
+        req0.setEntry( getAttributes() );
+
+        AddRequestImpl req1 = new AddRequestImpl( 5 );
+        req1.setName( "cn=admin,dc=apache,dc=org" );
+        req1.setEntry( getAttributes() );
+
+
+        assertFalse( req0.equals( req1 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the DN names are different.
+     */
+    public void testNotEqualDiffAttributes()
+    {
+        AddRequestImpl req0 = new AddRequestImpl( 5 );
+        req0.setName( "cn=admin,dc=apache,dc=org" );
+        req0.setEntry( getAttributes() );
+
+        AddRequestImpl req1 = new AddRequestImpl( 5 );
+        req1.setName( "cn=admin,dc=apache,dc=org" );
+
+        assertFalse( req0.equals( req1 ) );
+        assertFalse( req1.equals( req0 ) );
+
+        req1.setEntry( getAttributes() );
+
+        assertTrue( req0.equals( req1 ) );
+        assertTrue( req1.equals( req0 ) );
+
+        req1.getEntry().put( "asdf", "asdf" );
+
+        assertFalse( req0.equals( req1 ) );
+        assertFalse( req1.equals( req0 ) );
+    }
+
+
+    /**
+     * Tests for equality even when another BindRequest implementation is used.
+     */
+    public void testEqualsDiffImpl()
+    {
+        AddRequest req0 = new AddRequest()
+        {
+            public Attributes getEntry()
+            {
+                return AddRequestImplTest.this.getAttributes();
+            }
+
+            public void setEntry( Attributes a_entry )
+            {
+            }
+
+            public String getName()
+            {
+                return null;
+            }
+
+            public void setName( String a_name )
+            {
+            }
+
+            public MessageTypeEnum getResponseType()
+            {
+                return MessageTypeEnum.ADDRESPONSE;
+            }
+
+            public boolean hasResponse()
+            {
+                return true;
+            }
+
+            public MessageTypeEnum getType()
+            {
+                return MessageTypeEnum.ADDREQUEST;
+            }
+
+            public Collection getControls()
+            {
+                return Collections.EMPTY_LIST;
+            }
+
+            public void add( Control a_control ) throws MessageException
+            {
+            }
+
+            public void remove( Control a_control ) throws MessageException
+            {
+            }
+
+            public int getMessageId()
+            {
+                return 5;
+            }
+
+            public Object get( Object a_key )
+            {
+                return null;
+            }
+
+            public Object put( Object a_key, Object a_value )
+            {
+                return null;
+            }
+
+            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;
+            }
+        };
+
+        AddRequestImpl req1 = new AddRequestImpl( 5 );
+        req1.setEntry( getAttributes() );
+        assertTrue( req1.equals( req0 ) );
+    }
+}

Added: incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/DeleteRequestImplTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/DeleteRequestImplTest.java
Thu Aug 26 00:17:42 2004
@@ -0,0 +1,180 @@
+/*
+ *   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 methods of the DeleteRequestImpl class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class DeleteRequestImplTest extends TestCase
+{
+    /**
+     * Tests the same object referrence for equality.
+     */
+    public void testEqualsSameObj()
+    {
+        DeleteRequestImpl req = new DeleteRequestImpl( 5 );
+        assertTrue( req.equals( req ) );
+    }
+
+
+    /**
+     * Tests for equality using exact copies.
+     */
+    public void testEqualsExactCopy()
+    {
+        DeleteRequestImpl req0 = new DeleteRequestImpl( 5 );
+        req0.setName( "cn=admin,dc=example,dc=com" );
+
+        DeleteRequestImpl req1 = new DeleteRequestImpl( 5 );
+        req1.setName( "cn=admin,dc=example,dc=com" );
+
+        assertTrue( req0.equals( req1 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the IDs are different.
+     */
+    public void testNotEqualDiffId()
+    {
+        DeleteRequestImpl req0 = new DeleteRequestImpl( 7 );
+        req0.setName( "cn=admin,dc=example,dc=com" );
+
+        DeleteRequestImpl req1 = new DeleteRequestImpl( 5 );
+        req1.setName( "cn=admin,dc=example,dc=com" );
+
+        assertFalse( req0.equals( req1 ) );
+    }
+
+
+    /**
+     * Test for inequality when only the DN names are different.
+     */
+    public void testNotEqualDiffName()
+    {
+        DeleteRequestImpl req0 = new DeleteRequestImpl( 5 );
+        req0.setName( "uid=akarasulu,dc=example,dc=com" );
+
+        DeleteRequestImpl req1 = new DeleteRequestImpl( 5 );
+        req1.setName( "cn=admin,dc=example,dc=com" );
+
+        assertFalse( req0.equals( req1 ) );
+    }
+
+
+    /**
+     * Tests for equality even when another DeleteRequest implementation is used.
+     */
+    public void testEqualsDiffImpl()
+    {
+        DeleteRequest req0 = new DeleteRequest()
+        {
+            public String getName()
+            {
+                return null;
+            }
+
+            public void setName( String a_name )
+            {
+            }
+
+            public MessageTypeEnum getResponseType()
+            {
+                return MessageTypeEnum.DELRESPONSE;
+            }
+
+            public boolean hasResponse()
+            {
+                return true;
+            }
+
+            public MessageTypeEnum getType()
+            {
+                return MessageTypeEnum.DELREQUEST;
+            }
+
+            public Collection getControls()
+            {
+                return Collections.EMPTY_LIST;
+            }
+
+            public void add( Control a_control ) throws MessageException
+            {
+            }
+
+            public void remove( Control a_control ) throws MessageException
+            {
+            }
+
+            public int getMessageId()
+            {
+                return 5;
+            }
+
+            public Object get( Object a_key )
+            {
+                return null;
+            }
+
+            public Object put( Object a_key, Object a_value )
+            {
+                return null;
+            }
+
+            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;
+            }
+        };
+
+        DeleteRequestImpl req1 = new DeleteRequestImpl( 5 );
+        assertTrue( req1.equals( req0 ) );
+    }
+}

Mime
View raw message