Author: akarasulu
Date: Fri Aug 27 21:58:50 2004
New Revision: 37156
Added:
incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/ModifyDnRequestImplTest.java
Modified:
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/ModifyDnRequestImpl.java
Log:
Commit changes ...
o added ModifyDnRequestImpl equals() override
o added unit test case for ModifyDnRequestImpl
Modified:
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/ModifyDnRequestImpl.java
==============================================================================
---
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/ModifyDnRequestImpl.java
(original)
+++
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/ModifyDnRequestImpl.java
Fri Aug 27 21:58:50 2004
@@ -1,28 +1,28 @@
-/*
- * 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.
- *
- */
+/*
+ * 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 ModifyDNRequest implementation.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">
- * Apache Directory Project</a>
- * @version $Rev$
+ * @author <a href="mailto:[EMAIL PROTECTED]">
+ * Apache Directory Project</a>
+ * @version $Rev$
*/
public class ModifyDnRequestImpl
extends AbstractRequest implements ModifyDnRequest
@@ -196,5 +196,89 @@
public MessageTypeEnum getResponseType()
{
return RESP_TYPE ;
+ }
+
+
+ /**
+ * Checks to see of an object equals this ModifyDnRequest stub. The
+ * equality presumes all ModifyDnRequest specific properties are the same.
+ *
+ * @param obj the object to compare with this stub
+ * @return true if the obj is equal to this stub, false otherwise
+ */
+ public boolean equals( Object obj )
+ {
+ if ( obj == this )
+ {
+ return true;
+ }
+
+ if ( ! super.equals( obj ) )
+ {
+ return false;
+ }
+
+ ModifyDnRequest req = ( ModifyDnRequest ) obj;
+
+ if ( m_name != null && req.getName() == null )
+ {
+ return false;
+ }
+
+ if ( m_name == null && req.getName() != null )
+ {
+ return false;
+ }
+
+ if ( m_name != null && req.getName() != null )
+ {
+ if ( ! m_name.equals( req.getName() ) )
+ {
+ return false;
+ }
+ }
+
+ if ( m_deleteOldRdn != req.getDeleteOldRdn() )
+ {
+ return false;
+ }
+
+ if ( m_newRdn != null && req.getNewRdn() == null )
+ {
+ return false;
+ }
+
+ if ( m_newRdn == null && req.getNewRdn() != null )
+ {
+ return false;
+ }
+
+ if ( m_newRdn != null && req.getNewRdn() != null )
+ {
+ if ( ! m_newRdn.equals( req.getNewRdn() ) )
+ {
+ return false;
+ }
+ }
+
+ if ( m_newSuperior != null && req.getNewSuperior() == null )
+ {
+ return false;
+ }
+
+ if ( m_newSuperior == null && req.getNewSuperior() != null )
+ {
+ return false;
+ }
+
+ if ( m_newSuperior != null && req.getNewSuperior() != null )
+ {
+ if ( ! m_newSuperior.equals( req.getNewSuperior() ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
}
}
Added:
incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/ModifyDnRequestImplTest.java
==============================================================================
--- (empty file)
+++
incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/message/ModifyDnRequestImplTest.java
Fri Aug 27 21:58:50 2004
@@ -0,0 +1,283 @@
+/*
+ * 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 ModifyDnRequestImpl class.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]"> Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class ModifyDnRequestImplTest extends TestCase
+{
+ /**
+ * Constructs a ModifyDnrequest to test.
+ *
+ * @return the request
+ */
+ public ModifyDnRequestImpl getRequest()
+ {
+ // Construct the ModifyDn request to test
+ ModifyDnRequestImpl request = new ModifyDnRequestImpl( 45 );
+ request.setDeleteOldRdn( true );
+ request.setName( "dc=admins,dc=apache,dc=org" );
+ request.setNewRdn( "dc=administrators" );
+ request.setNewSuperior( "dc=groups,dc=apache,dc=org" );
+ return request;
+ }
+
+
+ /**
+ * Tests the same object referrence for equality.
+ */
+ public void testEqualsSameObj()
+ {
+ ModifyDnRequestImpl req = new ModifyDnRequestImpl( 5 );
+ assertTrue( req.equals( req ) );
+ }
+
+
+ /**
+ * Tests for equality using exact copies.
+ */
+ public void testEqualsExactCopy0()
+ {
+ ModifyDnRequestImpl req0 = getRequest();
+ ModifyDnRequestImpl req1 = getRequest();
+
+ assertTrue( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Tests for equality using exact copies.
+ */
+ public void testEqualsExactCopy1()
+ {
+ ModifyDnRequestImpl req0 = getRequest();
+ req0.setNewSuperior( null );
+ ModifyDnRequestImpl req1 = getRequest();
+ req1.setNewSuperior( null );
+
+ assertTrue( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the IDs are different.
+ */
+ public void testNotEqualDiffId()
+ {
+ ModifyDnRequestImpl req0 = new ModifyDnRequestImpl( 4 );
+ ModifyDnRequestImpl req1 = new ModifyDnRequestImpl( 5 );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the DN names are different.
+ */
+ public void testNotEqualDiffName()
+ {
+ ModifyDnRequestImpl req0 = getRequest();
+ req0.setName( "cn=admin,dc=example,dc=com" );
+
+ ModifyDnRequestImpl req1 = getRequest();
+ req1.setName( "cn=admin,dc=apache,dc=org" );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the newSuperior DNs are different.
+ */
+ public void testNotEqualDiffNewSuperior()
+ {
+ ModifyDnRequestImpl req0 = getRequest();
+ req0.setNewSuperior( "cn=admin,dc=example,dc=com" );
+
+ ModifyDnRequestImpl req1 = getRequest();
+ req1.setNewSuperior( "cn=admin,dc=apache,dc=org" );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the delete old Rdn properties is
different.
+ */
+ public void testNotEqualDiffDeleteOldRdn()
+ {
+ ModifyDnRequestImpl req0 = getRequest();
+ req0.setDeleteOldRdn( true );
+
+ ModifyDnRequestImpl req1 = getRequest();
+ req1.setDeleteOldRdn( false );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the new Rdn properties are different.
+ */
+ public void testNotEqualDiffNewRdn()
+ {
+ ModifyDnRequestImpl req0 = getRequest();
+ req0.setNewRdn( "cn=admin0" );
+
+ ModifyDnRequestImpl req1 = getRequest();
+ req1.setNewRdn( "cn=admin1" );
+
+ assertFalse( req0.equals( req1 ) );
+ assertFalse( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Tests for equality even when another BindRequest implementation is used.
+ */
+ public void testEqualsDiffImpl()
+ {
+ ModifyDnRequest req0 = new ModifyDnRequest()
+ {
+ public String getName()
+ {
+ return "dc=admins,dc=apache,dc=org";
+ }
+
+ public void setName( String a_name )
+ {
+ }
+
+ public String getNewRdn()
+ {
+ return "dc=administrators";
+ }
+
+ public void setNewRdn( String a_newRdn )
+ {
+ }
+
+ public boolean getDeleteOldRdn()
+ {
+ return true;
+ }
+
+ public void setDeleteOldRdn( boolean a_deleteOldRdn )
+ {
+ }
+
+ public String getNewSuperior()
+ {
+ return "dc=groups,dc=apache,dc=org";
+ }
+
+ public void setNewSuperior( String a_newSuperior )
+ {
+ }
+
+ public boolean isMove()
+ {
+ return false;
+ }
+
+ public MessageTypeEnum getResponseType()
+ {
+ return MessageTypeEnum.MODDNRESPONSE;
+ }
+
+ public boolean hasResponse()
+ {
+ return true;
+ }
+
+ public MessageTypeEnum getType()
+ {
+ return MessageTypeEnum.MODDNREQUEST;
+ }
+
+ 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 45;
+ }
+
+ 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;
+ }
+ };
+
+ ModifyDnRequestImpl req1 = getRequest();
+ assertTrue( req1.equals( req0 ) );
+ }
+}