From directory-cvs-return-1378-apmail-incubator-directory-cvs-archive=incubator.apache.org@incubator.apache.org Thu Aug 26 15:28:18 2004 Return-Path: Delivered-To: apmail-incubator-directory-cvs-archive@www.apache.org Received: (qmail 63599 invoked from network); 26 Aug 2004 15:28:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 26 Aug 2004 15:28:14 -0000 Received: (qmail 64187 invoked by uid 500); 26 Aug 2004 15:27:58 -0000 Delivered-To: apmail-incubator-directory-cvs-archive@incubator.apache.org Received: (qmail 64036 invoked by uid 500); 26 Aug 2004 15:27:56 -0000 Mailing-List: contact directory-cvs-help@incubator.apache.org; run by ezmlm Precedence: bulk Reply-To: directory-dev@incubator.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list directory-cvs@incubator.apache.org Received: (qmail 63922 invoked by uid 99); 26 Aug 2004 15:27:56 -0000 X-ASF-Spam-Status: No, hits=-2.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Thu, 26 Aug 2004 08:27:55 -0700 Received: (qmail 63172 invoked by uid 65534); 26 Aug 2004 15:27:54 -0000 Date: 26 Aug 2004 15:27:54 -0000 Message-ID: <20040826152754.63160.qmail@minotaur.apache.org> From: akarasulu@apache.org To: directory-cvs@incubator.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 X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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 - * Apache Directory Project - * @version $Rev$ + * @author + * Apache Directory Project + * @version $Rev$ */ public class ExtendedRequestImpl extends AbstractRequest implements ExtendedRequest { /** Extended request's Object Identifier or requestName */ - private String m_oid ; + private String oid; /** Extended request's payload or requestValue */ - 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 Apache Directory + * Project + * @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 ) ); + } +}