hiding message implementations
git-svn-id: https://svn.apache.org/repos/asf/directory/shared/branches/alex_refactoring@1056057 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/AddRequestImplTest.java b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/AddRequestImplTest.java
new file mode 100644
index 0000000..fd54fb5
--- /dev/null
+++ b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/AddRequestImplTest.java
@@ -0,0 +1,377 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.*;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * TestCase for the AddRequestImpl class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class AddRequestImplTest
+{
+ private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
+
+ /**
+ * Creates and populates a AttributeImpl with a specific id.
+ *
+ * @param id
+ * the id for the attribute
+ * @return the AttributeImpl assembled for testing
+ */
+ private EntryAttribute getAttribute( String id )
+ {
+ EntryAttribute attr = new DefaultEntryAttribute( id );
+ attr.add( "value0" );
+ attr.add( "value1" );
+ attr.add( "value2" );
+ return attr;
+ }
+
+
+ /**
+ * Creates and populates a LockableAttributes object
+ *
+ * @return
+ */
+ private Entry getEntry()
+ {
+ Entry entry = new DefaultEntry();
+
+ try
+ {
+ entry.put( getAttribute( "attr0" ) );
+ entry.put( getAttribute( "attr1" ) );
+ entry.put( getAttribute( "attr2" ) );
+ }
+ catch ( LdapException ne )
+ {
+ // Do nothing
+ }
+
+ return entry;
+ }
+
+
+ /**
+ * Tests the same object referrence for equality.
+ */
+ @Test
+ public void testEqualsSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.AddRequestImpl req = new org.apache.directory.shared.ldap.codec.message.AddRequestImpl( 5 );
+ assertTrue( req.equals( req ) );
+ }
+
+
+ /**
+ * Tests for equality using exact copies.
+ */
+ @Test
+ public void testEqualsExactCopy() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.AddRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.AddRequestImpl( 5 );
+ req0.setEntryDn( new DN( "cn=admin,dc=example,dc=com" ) );
+ req0.setEntry( getEntry() );
+
+ org.apache.directory.shared.ldap.codec.message.AddRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.AddRequestImpl( 5 );
+ req1.setEntryDn( new DN( "cn=admin,dc=example,dc=com" ) );
+ req1.setEntry( getEntry() );
+
+ assertTrue( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the IDs are different.
+ */
+ @Test
+ public void testNotEqualDiffId() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.AddRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.AddRequestImpl( 7 );
+ req0.setEntryDn( new DN( "cn=admin,dc=example,dc=com" ) );
+ req0.setEntry( getEntry() );
+
+ org.apache.directory.shared.ldap.codec.message.AddRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.AddRequestImpl( 5 );
+ req1.setEntryDn( new DN( "cn=admin,dc=example,dc=com" ) );
+ req1.setEntry( getEntry() );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the DN names are different.
+ */
+ @Test
+ public void testNotEqualDiffName() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.AddRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.AddRequestImpl( 5 );
+ req0.setEntry( getEntry() );
+ req0.setEntryDn( new DN( "cn=admin,dc=example,dc=com" ) );
+
+ org.apache.directory.shared.ldap.codec.message.AddRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.AddRequestImpl( 5 );
+ req1.setEntry( getEntry() );
+ req1.setEntryDn( new DN( "cn=admin,dc=apache,dc=org" ) );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the DN names are different.
+ */
+ @Test
+ public void testNotEqualDiffAttributes() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.AddRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.AddRequestImpl( 5 );
+ Entry entry0 = getEntry();
+ entry0.setDn( new DN( "cn=admin,dc=apache,dc=org" ) );
+ req0.setEntry( entry0 );
+
+ org.apache.directory.shared.ldap.codec.message.AddRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.AddRequestImpl( 5 );
+ req1.setEntryDn( new DN( "cn=admin,dc=apache,dc=org" ) );
+
+ assertTrue( req0.equals( req1 ) );
+ assertTrue( req1.equals( req0 ) );
+
+ Entry entry1 = getEntry();
+ entry1.setDn( new DN( "cn=admin,dc=apache,dc=org" ) );
+ req1.setEntry( entry1 );
+
+ assertTrue( req0.equals( req1 ) );
+ assertTrue( req1.equals( req0 ) );
+
+ req1.getEntry().put( "asdf", "asdf" );
+
+ assertTrue( req0.equals( req1 ) );
+ assertTrue( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Tests for equality even when another BindRequest implementation is used.
+ */
+ @Test
+ public void testEqualsDiffImpl()
+ {
+ AddRequest req0 = new AddRequest()
+ {
+ public Entry getEntry()
+ {
+ return AddRequestImplTest.this.getEntry();
+ }
+
+
+ public void setEntry( Entry entry )
+ {
+ }
+
+
+ public DN getEntryDn()
+ {
+ return null;
+ }
+
+
+ public void setEntryDn( DN entryDn )
+ {
+ }
+
+
+ public MessageTypeEnum getResponseType()
+ {
+ return MessageTypeEnum.ADD_RESPONSE;
+ }
+
+
+ public boolean hasResponse()
+ {
+ return true;
+ }
+
+
+ public MessageTypeEnum getType()
+ {
+ return MessageTypeEnum.ADD_REQUEST;
+ }
+
+
+ public Map<String, Control> getControls()
+ {
+ return EMPTY_CONTROL_MAP;
+ }
+
+
+ public void addControl( Control control ) throws MessageException
+ {
+ }
+
+
+ public void removeControl( 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 void abandon()
+ {
+ }
+
+
+ public boolean isAbandoned()
+ {
+ return false;
+ }
+
+
+ public void addAbandonListener( AbandonListener listener )
+ {
+ }
+
+
+ public ResultResponse getResultResponse()
+ {
+ return null;
+ }
+
+
+ public void addAllControls( Control[] controls ) throws MessageException
+ {
+ }
+
+
+ public boolean hasControl( String oid )
+ {
+ return false;
+ }
+
+
+ public void addAttributeType( String type ) throws LdapException
+ {
+ }
+
+
+ public void addAttributeValue( String value )
+ {
+ }
+
+
+ public void addAttributeValue( Value<?> value )
+ {
+ }
+
+
+ public void addAttributeValue( byte[] value )
+ {
+ }
+
+
+ public String getCurrentAttributeType()
+ {
+ return null;
+ }
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
+
+
+ public int getControlsLength()
+ {
+ return 0;
+ }
+
+
+ public void setControlsLength( int controlsLength )
+ {
+ }
+
+
+ public int getMessageLength()
+ {
+ return 0;
+ }
+
+
+ public void setMessageLength( int messageLength )
+ {
+ }
+
+
+ public Control getControl( String oid )
+ {
+ return null;
+ }
+
+
+ public void setMessageId( int messageId )
+ {
+ }
+ };
+
+ org.apache.directory.shared.ldap.codec.message.AddRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.AddRequestImpl( 5 );
+ req1.setEntry( getEntry() );
+ assertTrue( req1.equals( req0 ) );
+ }
+}
diff --git a/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/BindRequestImplTest.java b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/BindRequestImplTest.java
new file mode 100644
index 0000000..f23b697
--- /dev/null
+++ b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/BindRequestImplTest.java
@@ -0,0 +1,402 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.*;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * TestCases for the methods of the BindRequestImpl class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ * $Rev: 923524 $
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class BindRequestImplTest
+{
+ private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
+
+ /**
+ * Tests the same object referrence for equality.
+ */
+ @Test
+ public void testEqualsSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.BindRequestImpl req = new org.apache.directory.shared.ldap.codec.message.BindRequestImpl( 5 );
+ assertTrue( req.equals( req ) );
+ }
+
+
+ /**
+ * Tests for equality using exact copies.
+ */
+ @Test
+ public void testEqualsExactCopy() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.BindRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.BindRequestImpl( 5 );
+ req0.setCredentials( "password".getBytes() );
+ req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req0.setSimple( true );
+ req0.setVersion3( true );
+
+ org.apache.directory.shared.ldap.codec.message.BindRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.BindRequestImpl( 5 );
+ req1.setCredentials( "password".getBytes() );
+ req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req1.setSimple( true );
+ req1.setVersion3( true );
+
+ assertTrue( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the IDs are different.
+ */
+ @Test
+ public void testNotEqualDiffId() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.BindRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.BindRequestImpl( 7 );
+ req0.setCredentials( "password".getBytes() );
+ req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req0.setSimple( true );
+ req0.setVersion3( true );
+
+ org.apache.directory.shared.ldap.codec.message.BindRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.BindRequestImpl( 5 );
+ req1.setCredentials( "password".getBytes() );
+ req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req1.setSimple( true );
+ req1.setVersion3( true );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the credentials are different.
+ */
+ @Test
+ public void testNotEqualDiffCreds() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.BindRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.BindRequestImpl( 5 );
+ req0.setCredentials( "abcdefg".getBytes() );
+ req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req0.setSimple( true );
+ req0.setVersion3( true );
+
+ org.apache.directory.shared.ldap.codec.message.BindRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.BindRequestImpl( 5 );
+ req1.setCredentials( "password".getBytes() );
+ req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req1.setSimple( true );
+ req1.setVersion3( true );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the DN names are different.
+ */
+ @Test
+ public void testNotEqualDiffName() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.BindRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.BindRequestImpl( 5 );
+ req0.setCredentials( "password".getBytes() );
+ req0.setName( new DN( "uid=akarasulu,dc=example,dc=com" ) );
+ req0.setSimple( true );
+ req0.setVersion3( true );
+
+ org.apache.directory.shared.ldap.codec.message.BindRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.BindRequestImpl( 5 );
+ req1.setCredentials( "password".getBytes() );
+ req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req1.setSimple( true );
+ req1.setVersion3( true );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the auth mechanisms are different.
+ */
+ @Test
+ public void testNotEqualDiffSimple() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.BindRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.BindRequestImpl( 5 );
+ req0.setCredentials( "password".getBytes() );
+ req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req0.setSimple( false );
+ req0.setVersion3( true );
+
+ org.apache.directory.shared.ldap.codec.message.BindRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.BindRequestImpl( 5 );
+ req1.setCredentials( "password".getBytes() );
+ req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req1.setSimple( true );
+ req1.setVersion3( true );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the bind LDAP versions are different.
+ */
+ @Test
+ public void testNotEqualDiffVersion() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.BindRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.BindRequestImpl( 5 );
+ req0.setCredentials( "password".getBytes() );
+ req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req0.setSimple( true );
+ req0.setVersion3( false );
+
+ org.apache.directory.shared.ldap.codec.message.BindRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.BindRequestImpl( 5 );
+ req1.setCredentials( "password".getBytes() );
+ req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req1.setSimple( true );
+ req1.setVersion3( true );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Tests for equality even when another BindRequest implementation is used.
+ */
+ @Test
+ public void testEqualsDiffImpl()
+ {
+ BindRequest req0 = new BindRequest()
+ {
+ public boolean isSimple()
+ {
+ return true;
+ }
+
+
+ public boolean getSimple()
+ {
+ return true;
+ }
+
+
+ public void setSimple( boolean a_isSimple )
+ {
+ }
+
+
+ public byte[] getCredentials()
+ {
+ return null;
+ }
+
+
+ public void setCredentials( String credentials )
+ {
+ }
+
+
+ public void setCredentials( byte[] credentials )
+ {
+ }
+
+
+ public DN getName()
+ {
+ return null;
+ }
+
+
+ public void setName( DN name )
+ {
+ }
+
+
+ public boolean isVersion3()
+ {
+ return true;
+ }
+
+
+ public boolean getVersion3()
+ {
+ return true;
+ }
+
+
+ public void setVersion3( boolean a_isVersion3 )
+ {
+ }
+
+
+ public MessageTypeEnum getResponseType()
+ {
+ return MessageTypeEnum.BIND_REQUEST;
+ }
+
+
+ public boolean hasResponse()
+ {
+ return true;
+ }
+
+
+ public MessageTypeEnum getType()
+ {
+ return MessageTypeEnum.BIND_REQUEST;
+ }
+
+
+ public Map<String, Control> getControls()
+ {
+ return EMPTY_CONTROL_MAP;
+ }
+
+
+ public void addControl( Control control ) throws MessageException
+ {
+ }
+
+
+ public void removeControl( Control 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 String getSaslMechanism()
+ {
+ return null;
+ }
+
+
+ public void setSaslMechanism( String saslMechanism )
+ {
+ }
+
+
+ public ResultResponse getResultResponse()
+ {
+ return null;
+ }
+
+
+ public void addAllControls( Control[] controls ) throws MessageException
+ {
+ }
+
+
+ public boolean hasControl( String oid )
+ {
+ return false;
+ }
+
+
+ public void abandon()
+ {
+ }
+
+
+ public void addAbandonListener( AbandonListener listener )
+ {
+ }
+
+
+ public boolean isAbandoned()
+ {
+ return false;
+ }
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
+
+
+ public int getControlsLength()
+ {
+ return 0;
+ }
+
+
+ public void setControlsLength( int controlsLength )
+ {
+ }
+
+
+ public int getMessageLength()
+ {
+ return 0;
+ }
+
+
+ public void setMessageLength( int messageLength )
+ {
+ }
+
+
+ public Control getControl( String oid )
+ {
+ return null;
+ }
+
+
+ public void setMessageId( int messageId )
+ {
+ }
+ };
+
+ org.apache.directory.shared.ldap.codec.message.BindRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.BindRequestImpl( 5 );
+ assertTrue( req1.equals( req0 ) );
+ }
+}
diff --git a/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/BindResponseImplTest.java b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/BindResponseImplTest.java
new file mode 100644
index 0000000..b54f98c
--- /dev/null
+++ b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/BindResponseImplTest.java
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.message;
+
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.codec.message.BindResponseImpl;
+import org.apache.directory.shared.ldap.codec.message.LdapResultImpl;
+import org.apache.directory.shared.ldap.codec.message.ReferralImpl;
+import org.apache.directory.shared.ldap.message.Referral;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+
+/**
+ * Tests the methods of the BindResponseImpl class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ * $Rev: 946353 $
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class BindResponseImplTest
+
+{
+ /**
+ * Tests to make sure the same object returns true with equals().
+ */
+ @Test
+ public void testEqualsSameObj()
+ {
+ BindResponseImpl resp = new BindResponseImpl( 1 );
+ assertTrue( "same object should be equal", resp.equals( resp ) );
+ }
+
+
+ /**
+ * Tests to make sure newly created objects with same id are equal.
+ */
+ @Test
+ public void testEqualsNewWithSameId()
+ {
+ BindResponseImpl resp0 = new BindResponseImpl( 1 );
+ BindResponseImpl resp1 = new BindResponseImpl( 1 );
+ assertTrue( "default copy with same id should be equal", resp0.equals( resp1 ) );
+ assertTrue( "default copy with same id should be equal", resp1.equals( resp0 ) );
+ }
+
+
+ /**
+ * Tests to make sure the same object has the same hashCode.
+ */
+ @Test
+ public void testHashCodeSameObj()
+ {
+ BindResponseImpl resp = new BindResponseImpl( 1 );
+ assertTrue( resp.hashCode() == resp.hashCode() );
+ }
+
+
+ /**
+ * Tests to make sure newly created objects with same id have the same hashCode.
+ */
+ @Test
+ public void testHashCodeNewWithSameId()
+ {
+ BindResponseImpl resp0 = new BindResponseImpl( 1 );
+ BindResponseImpl resp1 = new BindResponseImpl( 1 );
+ assertTrue( resp1.hashCode() == resp0.hashCode() );
+ }
+
+
+ /**
+ * Tests to make sure newly created objects with same different id are not
+ * equal.
+ */
+ @Test
+ public void testNotEqualsNewWithDiffId()
+ {
+ BindResponseImpl resp0 = new BindResponseImpl( 1 );
+ BindResponseImpl resp1 = new org.apache.directory.shared.ldap.codec.message.BindResponseImpl( 2 );
+ assertFalse( "different id objects should not be equal", resp0.equals( resp1 ) );
+ assertFalse( "different id objects should not be equal", resp1.equals( resp0 ) );
+ }
+
+
+ /**
+ * Tests to make sure newly created objects with same different saslCreds
+ * are not equal.
+ */
+ @Test
+ public void testNotEqualsNewWithDiffSaslCreds()
+ {
+ BindResponseImpl resp0 = new BindResponseImpl( 1 );
+ resp0.setServerSaslCreds( new byte[2] );
+ BindResponseImpl resp1 = new BindResponseImpl( 1 );
+ resp1.setServerSaslCreds( new byte[3] );
+ assertFalse( "different serverSaslCreds objects should not be equal", resp0.equals( resp1 ) );
+ assertFalse( "different serverSaslCreds objects should not be equal", resp1.equals( resp0 ) );
+ }
+
+
+ /**
+ * Tests for equality of two fully loaded identical BindResponse PDUs.
+ */
+ @Test
+ public void testEqualsWithTheWorks() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+ LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ r0.setErrorMessage( "blah blah blah" );
+ r1.setErrorMessage( "blah blah blah" );
+
+ r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+ r1.setMatchedDn( new DN( "dc=example,dc=com" ) );
+
+ r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+ r1.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+
+ Referral refs0 = new ReferralImpl();
+ refs0.addLdapUrl( "ldap://someserver.com" );
+ refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+ Referral refs1 = new ReferralImpl();
+ refs1.addLdapUrl( "ldap://someserver.com" );
+ refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+ BindResponseImpl resp0 = new BindResponseImpl( 1 );
+ BindResponseImpl resp1 = new BindResponseImpl( 1 );
+
+ resp0.setServerSaslCreds( "password".getBytes() );
+ resp1.setServerSaslCreds( "password".getBytes() );
+
+ assertTrue( "loaded carbon copies should be equal", resp0.equals( resp1 ) );
+ assertTrue( "loaded carbon copies should be equal", resp1.equals( resp0 ) );
+ }
+
+
+ /**
+ * Tests for equal hashCode of two fully loaded identical BindResponse PDUs.
+ */
+ @Test
+ public void testHashCodeWithTheWorks() throws LdapException
+ {
+ LdapResultImpl r0 = new LdapResultImpl();
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ r0.setErrorMessage( "blah blah blah" );
+ r1.setErrorMessage( "blah blah blah" );
+
+ r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+ r1.setMatchedDn( new DN( "dc=example,dc=com" ) );
+
+ r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+ r1.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+
+ Referral refs0 = new ReferralImpl();
+ refs0.addLdapUrl( "ldap://someserver.com" );
+ refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+ Referral refs1 = new ReferralImpl();
+ refs1.addLdapUrl( "ldap://someserver.com" );
+ refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+ BindResponseImpl resp0 = new BindResponseImpl( 1 );
+ BindResponseImpl resp1 = new BindResponseImpl( 1 );
+
+ resp0.setServerSaslCreds( "password".getBytes() );
+ resp1.setServerSaslCreds( "password".getBytes() );
+
+ assertTrue( resp0.hashCode() == resp1.hashCode() );
+ }
+}
diff --git a/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/CompareRequestImplTest.java b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/CompareRequestImplTest.java
new file mode 100644
index 0000000..28d0410
--- /dev/null
+++ b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/CompareRequestImplTest.java
@@ -0,0 +1,352 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.*;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * TestCase for the CompareRequestImpl class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class CompareRequestImplTest
+{
+ private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
+
+ /**
+ * Tests the same object reference for equality.
+ */
+ @Test
+ public void testEqualsSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.CompareRequestImpl req = new org.apache.directory.shared.ldap.codec.message.CompareRequestImpl( 5 );
+ assertTrue( req.equals( req ) );
+ }
+
+
+ /**
+ * Tests for equality using exact copies.
+ */
+ @Test
+ public void testEqualsExactCopy() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.CompareRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.CompareRequestImpl( 5 );
+ req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req0.setAttributeId( "objectClass" );
+ req0.setAssertionValue( "top" );
+
+ org.apache.directory.shared.ldap.codec.message.CompareRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.CompareRequestImpl( 5 );
+ req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req1.setAttributeId( "objectClass" );
+ req1.setAssertionValue( "top" );
+
+ assertTrue( req0.equals( req1 ) );
+ assertTrue( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Tests the same object reference for equal hashCode.
+ */
+ @Test
+ public void testHashCodeSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.CompareRequestImpl req = new org.apache.directory.shared.ldap.codec.message.CompareRequestImpl( 5 );
+ assertTrue( req.hashCode() == req.hashCode() );
+ }
+
+
+ /**
+ * Tests for equal hashCode using exact copies.
+ */
+ @Test
+ public void testHashCodeExactCopy() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.CompareRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.CompareRequestImpl( 5 );
+ req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req0.setAttributeId( "objectClass" );
+ req0.setAssertionValue( "top" );
+
+ org.apache.directory.shared.ldap.codec.message.CompareRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.CompareRequestImpl( 5 );
+ req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ req1.setAttributeId( "objectClass" );
+ req1.setAssertionValue( "top" );
+
+ assertTrue( req0.hashCode() == req1.hashCode() );
+ }
+
+
+ /**
+ * Test for inequality when only the IDs are different.
+ */
+ @Test
+ public void testNotEqualDiffId() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.CompareRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.CompareRequestImpl( 7 );
+ req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+
+ org.apache.directory.shared.ldap.codec.message.CompareRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.CompareRequestImpl( 5 );
+ req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+
+ assertFalse( req0.equals( req1 ) );
+ assertFalse( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the attributeIds are different.
+ */
+ @Test
+ public void testNotEqualDiffAttributeIds() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.CompareRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.CompareRequestImpl( 5 );
+ req0.setName( new DN( "cn=admin,dc=apache,dc=org" ) );
+ req0.setAttributeId( "dc" );
+ req0.setAssertionValue( "apache.org" );
+
+ org.apache.directory.shared.ldap.codec.message.CompareRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.CompareRequestImpl( 5 );
+ req1.setName( new DN( "cn=admin,dc=apache,dc=org" ) );
+ req1.setAttributeId( "nisDomain" );
+ req1.setAssertionValue( "apache.org" );
+
+ assertFalse( req0.equals( req1 ) );
+ assertFalse( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the Assertion values are different.
+ */
+ @Test
+ public void testNotEqualDiffValue() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.CompareRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.CompareRequestImpl( 5 );
+ req0.setName( new DN( "cn=admin,dc=apache,dc=org" ) );
+ req0.setAttributeId( "dc" );
+ req0.setAssertionValue( "apache.org" );
+
+ org.apache.directory.shared.ldap.codec.message.CompareRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.CompareRequestImpl( 5 );
+ req1.setName( new DN( "cn=admin,dc=apache,dc=org" ) );
+ req1.setAttributeId( "dc" );
+ req1.setAssertionValue( "nagoya.apache.org" );
+
+ assertFalse( req0.equals( req1 ) );
+ assertFalse( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Tests for equality even when another CompareRequest implementation is
+ * used.
+ */
+ @Test
+ public void testEqualsDiffImpl()
+ {
+ CompareRequest req0 = new CompareRequest()
+ {
+ public Value<?> getAssertionValue()
+ {
+ return null;
+ }
+
+
+ public void setAssertionValue( String value )
+ {
+
+ }
+
+
+ public void setAssertionValue( byte[] value )
+ {
+
+ }
+
+
+ public String getAttributeId()
+ {
+ return null;
+ }
+
+
+ public void setAttributeId( String attrId )
+ {
+
+ }
+
+
+ public DN getName()
+ {
+ return null;
+ }
+
+
+ public void setName( DN name )
+ {
+ }
+
+
+ public MessageTypeEnum getResponseType()
+ {
+ return MessageTypeEnum.COMPARE_RESPONSE;
+ }
+
+
+ public boolean hasResponse()
+ {
+ return true;
+ }
+
+
+ public MessageTypeEnum getType()
+ {
+ return MessageTypeEnum.COMPARE_REQUEST;
+ }
+
+
+ public Map<String, Control> getControls()
+ {
+ return EMPTY_CONTROL_MAP;
+ }
+
+
+ public void addControl( Control a_control ) throws MessageException
+ {
+ }
+
+
+ public void removeControl( 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 void abandon()
+ {
+ }
+
+
+ public boolean isAbandoned()
+ {
+ return false;
+ }
+
+
+ public void addAbandonListener( AbandonListener listener )
+ {
+ }
+
+
+ public ResultResponse getResultResponse()
+ {
+ return null;
+ }
+
+
+ public void addAllControls( Control[] controls ) throws MessageException
+ {
+ }
+
+
+ public boolean hasControl( String oid )
+ {
+ return false;
+ }
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
+
+
+ public int getControlsLength()
+ {
+ return 0;
+ }
+
+
+ public void setControlsLength( int controlsLength )
+ {
+ }
+
+
+ public int getMessageLength()
+ {
+ return 0;
+ }
+
+
+ public void setMessageLength( int messageLength )
+ {
+ }
+
+
+ public Control getControl( String oid )
+ {
+ return null;
+ }
+
+
+ public void setMessageId( int messageId )
+ {
+ }
+ };
+
+ org.apache.directory.shared.ldap.codec.message.CompareRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.CompareRequestImpl( 5 );
+ assertTrue( req1.equals( req0 ) );
+ assertFalse( req0.equals( req1 ) );
+ }
+}
diff --git a/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/DeleteRequestImplTest.java b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/DeleteRequestImplTest.java
new file mode 100644
index 0000000..83b60e8
--- /dev/null
+++ b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/DeleteRequestImplTest.java
@@ -0,0 +1,284 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.*;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * TestCase for the methods of the DeleteRequestImpl class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class DeleteRequestImplTest
+{
+ private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
+
+ /**
+ * Tests the same object reference for equality.
+ */
+ @Test
+ public void testEqualsSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl req = new org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl( 5 );
+ assertTrue( req.equals( req ) );
+ }
+
+
+ /**
+ * Tests for equality using exact copies.
+ */
+ @Test
+ public void testEqualsExactCopy() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl( 5 );
+ req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+
+ org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl( 5 );
+ req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+
+ assertTrue( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Tests the same object reference for equal hashCode.
+ */
+ @Test
+ public void testHashCodeSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl req = new org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl( 5 );
+ assertTrue( req.hashCode() == req.hashCode() );
+ }
+
+
+ /**
+ * Tests for equal hashCode using exact copies.
+ */
+ @Test
+ public void testHashCodeExactCopy() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl( 5 );
+ req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+
+ org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl( 5 );
+ req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+
+ assertTrue( req0.hashCode() == req1.hashCode() );
+ }
+
+
+ /**
+ * Test for inequality when only the IDs are different.
+ */
+ @Test
+ public void testNotEqualDiffId() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl( 7 );
+ req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+
+ org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl( 5 );
+ req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the DN names are different.
+ */
+ @Test
+ public void testNotEqualDiffName() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl( 5 );
+ req0.setName( new DN( "uid=akarasulu,dc=example,dc=com" ) );
+
+ org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl( 5 );
+ req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Tests for equality even when another DeleteRequest implementation is
+ * used.
+ */
+ @Test
+ public void testEqualsDiffImpl()
+ {
+ DeleteRequest req0 = new DeleteRequest()
+ {
+ public DN getName()
+ {
+ return null;
+ }
+
+
+ public void setName( DN name )
+ {
+ }
+
+
+ public MessageTypeEnum getResponseType()
+ {
+ return MessageTypeEnum.DEL_RESPONSE;
+ }
+
+
+ public boolean hasResponse()
+ {
+ return true;
+ }
+
+
+ public MessageTypeEnum getType()
+ {
+ return MessageTypeEnum.DEL_REQUEST;
+ }
+
+
+ public Map<String, Control> getControls()
+ {
+ return EMPTY_CONTROL_MAP;
+ }
+
+
+ public void addControl( Control control ) throws MessageException
+ {
+ }
+
+
+ public void removeControl( 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 void abandon()
+ {
+ }
+
+
+ public boolean isAbandoned()
+ {
+ return false;
+ }
+
+
+ public void addAbandonListener( AbandonListener listener )
+ {
+ }
+
+
+ public ResultResponse getResultResponse()
+ {
+ return null;
+ }
+
+
+ public void addAllControls( Control[] controls ) throws MessageException
+ {
+ }
+
+
+ public boolean hasControl( String oid )
+ {
+ return false;
+ }
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
+
+
+ public int getControlsLength()
+ {
+ return 0;
+ }
+
+
+ public void setControlsLength( int controlsLength )
+ {
+ }
+
+
+ public int getMessageLength()
+ {
+ return 0;
+ }
+
+
+ public void setMessageLength( int messageLength )
+ {
+ }
+
+
+ public Control getControl( String oid )
+ {
+ return null;
+ }
+
+
+ public void setMessageId( int messageId )
+ {
+ }
+ };
+
+ org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.DeleteRequestImpl( 5 );
+ assertTrue( req1.equals( req0 ) );
+ }
+}
diff --git a/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ExtendedRequestImplTest.java b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ExtendedRequestImplTest.java
new file mode 100644
index 0000000..c4a4681
--- /dev/null
+++ b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ExtendedRequestImplTest.java
@@ -0,0 +1,319 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.ExtendedResponse;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.message.ExtendedRequest;
+import org.apache.directory.shared.ldap.message.MessageException;
+import org.apache.directory.shared.ldap.message.MessageTypeEnum;
+import org.apache.directory.shared.ldap.message.ResultResponse;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * TestCase for the ExtendedRequestImpl class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class ExtendedRequestImplTest
+{
+ private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
+
+ /**
+ * Tests the same object reference for equality.
+ */
+ @Test
+ public void testEqualsSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl req = new org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl( 5 );
+ assertTrue( req.equals( req ) );
+ }
+
+
+ /**
+ * Tests for equality using exact copies.
+ */
+ @Test
+ public void testEqualsExactCopy()
+ {
+ org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl( 5 );
+ req0.setRequestName( "1.1.1.1" );
+ req0.setRequestValue( "Hello World!".getBytes() );
+
+ org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl( 5 );
+ req1.setRequestName( "1.1.1.1" );
+ req1.setRequestValue( "Hello World!".getBytes() );
+
+ assertTrue( req0.equals( req1 ) );
+ assertTrue( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Tests the same object reference for equal hashCode.
+ */
+ @Test
+ public void testHashCodeSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl req = new org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl( 5 );
+ assertTrue( req.hashCode() == req.hashCode() );
+ }
+
+
+ /**
+ * Tests for equal hashCode using exact copies.
+ */
+ @Test
+ public void testHashCodeExactCopy()
+ {
+ org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl( 5 );
+ req0.setRequestName( "1.1.1.1" );
+ req0.setRequestValue( "Hello World!".getBytes() );
+
+ org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl( 5 );
+ req1.setRequestName( "1.1.1.1" );
+ req1.setRequestValue( "Hello World!".getBytes() );
+
+ assertTrue( req0.hashCode() == req1.hashCode() );
+ }
+
+
+ /**
+ * Test for inequality when only the IDs are different.
+ */
+ @Test
+ public void testNotEqualDiffId()
+ {
+ org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl( 7 );
+ org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl( 5 );
+
+ assertFalse( req0.equals( req1 ) );
+ assertFalse( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the OID is different.
+ */
+ @Test
+ public void testNotEqualDiffOID()
+ {
+ org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl( 5 );
+ req0.setRequestName( "1.1.1.1" );
+ req0.setRequestValue( "Hello World!".getBytes() );
+
+ org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl( 5 );
+ req0.setRequestName( "1.2.2.1" );
+ req0.setRequestValue( "Hello World!".getBytes() );
+
+ assertFalse( req0.equals( req1 ) );
+ assertFalse( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the Assertion values are different.
+ */
+ @Test
+ public void testNotEqualDiffValue()
+ {
+ org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl( 5 );
+ req0.setRequestName( "1.1.1.1" );
+ req0.setRequestValue( "Hello ".getBytes() );
+
+ org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl( 5 );
+ req0.setRequestName( "1.1.1.1" );
+ req0.setRequestValue( "World!".getBytes() );
+
+ assertFalse( req0.equals( req1 ) );
+ assertFalse( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Tests for equality even when another ExtendedRequest implementation is
+ * used.
+ */
+ @Test
+ public void testEqualsDiffImpl()
+ {
+ ExtendedRequest req0 = new ExtendedRequest()
+ {
+ private static final long serialVersionUID = 1L;
+
+
+ public void setRequestName( String oid )
+ {
+ }
+
+
+ public byte[] getRequestValue()
+ {
+ return null;
+ }
+
+
+ public void setRequestValue( byte[] payload )
+ {
+ }
+
+
+ public MessageTypeEnum getResponseType()
+ {
+ return MessageTypeEnum.EXTENDED_RESPONSE;
+ }
+
+
+ public boolean hasResponse()
+ {
+ return true;
+ }
+
+
+ public MessageTypeEnum getType()
+ {
+ return MessageTypeEnum.EXTENDED_REQUEST;
+ }
+
+
+ public Map<String, Control> getControls()
+ {
+ return EMPTY_CONTROL_MAP;
+ }
+
+
+ public void addControl( Control control ) throws MessageException
+ {
+ }
+
+
+ public void removeControl( 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 ResultResponse getResultResponse()
+ {
+ return null;
+ }
+
+
+ public String getRequestName()
+ {
+ return null;
+ }
+
+
+ public ExtendedResponse createExtendedResponse( String id, byte[] berValue, int offset, int length )
+ throws NamingException
+ {
+ return null;
+ }
+
+
+ public void addAllControls( Control[] controls ) throws MessageException
+ {
+ }
+
+
+ public boolean hasControl( String oid )
+ {
+ return false;
+ }
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
+
+
+ public int getControlsLength()
+ {
+ return 0;
+ }
+
+
+ public void setControlsLength( int controlsLength )
+ {
+ }
+
+
+ public int getMessageLength()
+ {
+ return 0;
+ }
+
+
+ public void setMessageLength( int messageLength )
+ {
+ }
+
+
+ public Control getControl( String oid )
+ {
+ return null;
+ }
+
+
+ public void setMessageId( int messageId )
+ {
+ }
+ };
+
+ org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.ExtendedRequestImpl( 5 );
+ assertTrue( req1.equals( req0 ) );
+ assertFalse( req0.equals( req1 ) );
+ }
+}
diff --git a/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ExtendedResponseImplTest.java b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ExtendedResponseImplTest.java
new file mode 100644
index 0000000..4b68f1e
--- /dev/null
+++ b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ExtendedResponseImplTest.java
@@ -0,0 +1,341 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl;
+import org.apache.directory.shared.ldap.codec.message.ReferralImpl;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.*;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * TestCase for the ExtendedResponseImpl class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class ExtendedResponseImplTest
+{
+ private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
+
+ /**
+ * Creates and populates a ExtendedResponseImpl stub for testing purposes.
+ *
+ * @return a populated ExtendedResponseImpl stub
+ */
+ private org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl createStub()
+ {
+ // Construct the Search response to test with results and referrals
+ org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl response = new org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl( 45 );
+ response.setResponseValue( "Hello World!".getBytes() );
+ response.setResponseName( "1.1.1.1" );
+ LdapResult result = response.getLdapResult();
+
+ try
+ {
+ result.setMatchedDn( new DN( "dc=example,dc=com" ) );
+ }
+ catch ( LdapException ine )
+ {
+ // Do nothing
+ }
+
+ result.setResultCode( ResultCodeEnum.SUCCESS );
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs = new ReferralImpl();
+ refs.addLdapUrl( "ldap://someserver.com" );
+ refs.addLdapUrl( "ldap://apache.org" );
+ refs.addLdapUrl( "ldap://another.net" );
+ result.setReferral( refs );
+ return response;
+ }
+
+
+ /**
+ * Tests for equality using the same object.
+ */
+ @Test
+ public void testEqualsSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl resp = createStub();
+ assertTrue( resp.equals( resp ) );
+ }
+
+
+ /**
+ * Tests for equality using an exact copy.
+ */
+ @Test
+ public void testEqualsExactCopy()
+ {
+ ExtendedResponseImpl resp0 = createStub();
+ org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl resp1 = createStub();
+ assertTrue( resp0.equals( resp1 ) );
+ assertTrue( resp1.equals( resp0 ) );
+ }
+
+
+ /**
+ * Tests for equality using different stub implementations.
+ */
+ @Test
+ public void testEqualsDiffImpl()
+ {
+ org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl resp0 = createStub();
+ ExtendedResponse resp1 = new ExtendedResponse()
+ {
+ private static final long serialVersionUID = 5297000474419901408L;
+
+
+ public String getID()
+ {
+ return "1.1.1.1";
+ }
+
+
+ public String getResponseName()
+ {
+ return "1.1.1.1";
+ }
+
+
+ public void setResponseName( String oid )
+ {
+ }
+
+
+ public byte[] getEncodedValue()
+ {
+ return "Hello World!".getBytes();
+ }
+
+
+ public byte[] getResponseValue()
+ {
+ return "Hello World!".getBytes();
+ }
+
+
+ public void setResponseValue( byte[] value )
+ {
+ }
+
+
+ public LdapResult getLdapResult()
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl result = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ try
+ {
+ result.setMatchedDn( new DN( "dc=example,dc=com" ) );
+ }
+ catch ( LdapException ine )
+ {
+ // do nothing
+ }
+
+ result.setResultCode( ResultCodeEnum.SUCCESS );
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs.addLdapUrl( "ldap://someserver.com" );
+ refs.addLdapUrl( "ldap://apache.org" );
+ refs.addLdapUrl( "ldap://another.net" );
+ result.setReferral( refs );
+
+ return result;
+ }
+
+
+ public MessageTypeEnum getType()
+ {
+ return MessageTypeEnum.EXTENDED_RESPONSE;
+ }
+
+
+ public Map<String, Control> getControls()
+ {
+ return EMPTY_CONTROL_MAP;
+ }
+
+
+ public void addControl( Control a_control ) throws MessageException
+ {
+ }
+
+
+ public void removeControl( 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 void addAllControls( Control[] controls ) throws MessageException
+ {
+ }
+
+
+ public boolean hasControl( String oid )
+ {
+ return false;
+ }
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
+
+
+ public int getControlsLength()
+ {
+ return 0;
+ }
+
+
+ public void setControlsLength( int controlsLength )
+ {
+ }
+
+
+ public int getMessageLength()
+ {
+ return 0;
+ }
+
+
+ public void setMessageLength( int messageLength )
+ {
+ }
+
+
+ public Control getControl( String oid )
+ {
+ return null;
+ }
+
+
+ public void setMessageId( int messageId )
+ {
+ }
+ };
+
+ assertTrue( resp0.equals( resp1 ) );
+ assertFalse( resp1.equals( resp0 ) );
+ }
+
+
+ /**
+ * Tests for equal hashCode using the same object.
+ */
+ @Test
+ public void testHashCodeSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl resp = createStub();
+ assertTrue( resp.hashCode() == resp.hashCode() );
+ }
+
+
+ /**
+ * Tests for equal hashCode using an exact copy.
+ */
+ @Test
+ public void testHashCodeExactCopy()
+ {
+ org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl resp0 = createStub();
+ org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl resp1 = createStub();
+ assertTrue( resp0.hashCode() == resp1.hashCode() );
+ }
+
+
+ /**
+ * Tests inequality when messageIds are different.
+ */
+ @Test
+ public void testNotEqualsDiffIds()
+ {
+ org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl resp0 = new org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl( 3 );
+ org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl resp1 = new org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl( 4 );
+
+ assertFalse( resp0.equals( resp1 ) );
+ assertFalse( resp1.equals( resp0 ) );
+ }
+
+
+ /**
+ * Tests inequality when responseNames are different.
+ */
+ @Test
+ public void testNotEqualsDiffNames()
+ {
+ org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl resp0 = createStub();
+ resp0.setResponseName( "1.2.3.4" );
+ org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl resp1 = createStub();
+ resp1.setResponseName( "1.2.3.4.5" );
+
+ assertFalse( resp0.equals( resp1 ) );
+ assertFalse( resp1.equals( resp0 ) );
+ }
+
+
+ /**
+ * Tests inequality when responses are different.
+ */
+ @Test
+ public void testNotEqualsDiffResponses()
+ {
+ org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl resp0 = createStub();
+ resp0.setResponseValue( "abc".getBytes() );
+ org.apache.directory.shared.ldap.codec.message.ExtendedResponseImpl resp1 = createStub();
+ resp1.setResponseValue( "123".getBytes() );
+
+ assertFalse( resp0.equals( resp1 ) );
+ assertFalse( resp1.equals( resp0 ) );
+ }
+}
diff --git a/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/LdapResultImplTest.java b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/LdapResultImplTest.java
new file mode 100644
index 0000000..c6e5aa7
--- /dev/null
+++ b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/LdapResultImplTest.java
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.codec.message.ReferralImpl;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.LdapResult;
+import org.apache.directory.shared.ldap.message.Referral;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Tests the methods of the LdapResultImpl class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * $Rev: 946251 $
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class LdapResultImplTest
+{
+ /**
+ * Tests to make sure the two same objects are seen as equal.
+ */
+ @Test
+ public void testEqualsSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+ assertTrue( "same object should be equal", r0.equals( r0 ) );
+ }
+
+
+ /**
+ * Tests to make sure a default LdapResultImpl equals another one just
+ * created.
+ */
+ @Test
+ public void testEqualsDefaultCopy()
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ assertTrue( "default copy should be equal", r0.equals( r1 ) );
+ assertTrue( "default copy should be equal", r1.equals( r0 ) );
+ }
+
+
+ /**
+ * Tests for equality when the lockable parent is not the same.
+ */
+ @Test
+ public void testEqualsDiffLockableParent()
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ assertTrue( "default copy with different lockable parents " + "should be equal", r0.equals( r1 ) );
+ assertTrue( "default copy with different lockable parents " + "should be equal", r1.equals( r0 ) );
+ }
+
+
+ /**
+ * Tests for equality when the lockable parent is the same.
+ */
+ @Test
+ public void testEqualsDiffImpl()
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ LdapResult r1 = new LdapResult()
+ {
+ public ResultCodeEnum getResultCode()
+ {
+ return ResultCodeEnum.SUCCESS;
+ }
+
+
+ public void setResultCode( ResultCodeEnum a_resultCode )
+ {
+ }
+
+
+ public DN getMatchedDn()
+ {
+ return null;
+ }
+
+
+ public void setMatchedDn( DN dn )
+ {
+ }
+
+
+ public String getErrorMessage()
+ {
+ return null;
+ }
+
+
+ public void setErrorMessage( String a_errorMessage )
+ {
+ }
+
+
+ public boolean isReferral()
+ {
+ return false;
+ }
+
+
+ public Referral getReferral()
+ {
+ return null;
+ }
+
+
+ public void setReferral( Referral referral )
+ {
+ }
+ };
+
+ assertTrue( "r0 equals should see other impl r1 as equal", r0.equals( r1 ) );
+ assertFalse( "r1 impl uses Object.equals() so it should not see " + "r0 as the same object", r1.equals( r0 ) );
+ }
+
+
+ /**
+ * Tests two non default carbon copies for equality.
+ */
+ @Test
+ public void testEqualsCarbonCopy() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ r0.setErrorMessage( "blah blah blah" );
+ r1.setErrorMessage( "blah blah blah" );
+
+ r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+ r1.setMatchedDn( new DN( "dc=example,dc=com" ) );
+
+ r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+ r1.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+
+ Referral refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs0.addLdapUrl( "ldap://someserver.com" );
+ refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+ Referral refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs1.addLdapUrl( "ldap://someserver.com" );
+ refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+ assertTrue( "exact copy should be equal", r0.equals( r1 ) );
+ assertTrue( "exact copy should be equal", r1.equals( r0 ) );
+ }
+
+
+ /**
+ * Tests to make sure the two same objects have equal HashCode.
+ */
+ @Test
+ public void testHashCodeSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+ assertTrue( r0.hashCode() == r0.hashCode() );
+ }
+
+
+ /**
+ * Tests to make sure a default LdapResultImpl has equal hashCode another one just
+ * created.
+ */
+ @Test
+ public void testHashCodeDefaultCopy()
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ assertTrue( r0.hashCode() == r1.hashCode() );
+ }
+
+
+ /**
+ * Tests for equal hashCode when the lockable parent is not the same.
+ */
+ @Test
+ public void testHashCodeDiffLockableParent()
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ assertTrue( r0.hashCode() == r1.hashCode() );
+ }
+
+
+ /**
+ * Tests two non default carbon copies for equal hashCode.
+ */
+ @Test
+ public void testHashCodeCarbonCopy() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ r0.setErrorMessage( "blah blah blah" );
+ r1.setErrorMessage( "blah blah blah" );
+
+ r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+ r1.setMatchedDn( new DN( "dc=example,dc=com" ) );
+
+ r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+ r1.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+
+ Referral refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs0.addLdapUrl( "ldap://someserver.com" );
+ refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+ Referral refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs1.addLdapUrl( "ldap://someserver.com" );
+ refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+ assertTrue( r0.hashCode() == r1.hashCode() );
+ }
+
+
+ /**
+ * Tests for inequality when the error message is different.
+ */
+ @Test
+ public void testNotEqualsDiffErrorMessage() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ r0.setErrorMessage( "blah blah blah" );
+ r1.setErrorMessage( "blah" );
+
+ r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+ r1.setMatchedDn( new DN( "dc=example,dc=com" ) );
+
+ r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+ r1.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+
+ Referral refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs0.addLdapUrl( "ldap://someserver.com" );
+ refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+ Referral refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs1.addLdapUrl( "ldap://someserver.com" );
+ refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+ assertFalse( "results with different error messages should " + "not be equal", r0.equals( r1 ) );
+ assertFalse( "results with different error messages should " + "not be equal", r1.equals( r0 ) );
+ }
+
+
+ /**
+ * Tests for inequality when the matchedDn properties are not the same.
+ */
+ @Test
+ public void testNotEqualsDiffMatchedDn() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ r0.setErrorMessage( "blah blah blah" );
+ r1.setErrorMessage( "blah blah blah" );
+
+ r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+ r1.setMatchedDn( new DN( "dc=apache,dc=org" ) );
+
+ r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+ r1.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+
+ Referral refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs0.addLdapUrl( "ldap://someserver.com" );
+ refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+ Referral refs1 = new ReferralImpl();
+ refs1.addLdapUrl( "ldap://someserver.com" );
+ refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+ assertFalse( "results with different matchedDn properties " + "should not be equal", r0.equals( r1 ) );
+ assertFalse( "results with different matchedDn properties " + "should not be equal", r1.equals( r0 ) );
+ }
+
+
+ /**
+ * Tests for inequality when the resultCode properties are not the same.
+ */
+ @Test
+ public void testNotEqualsDiffResultCode() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ r0.setErrorMessage( "blah blah blah" );
+ r1.setErrorMessage( "blah blah blah" );
+
+ r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+ r1.setMatchedDn( new DN( "dc=example,dc=com" ) );
+
+ r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+ r1.setResultCode( ResultCodeEnum.SIZE_LIMIT_EXCEEDED );
+
+ Referral refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs0.addLdapUrl( "ldap://someserver.com" );
+ refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+ Referral refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs1.addLdapUrl( "ldap://someserver.com" );
+ refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+ assertFalse( "results with different result codes should not be equal", r0.equals( r1 ) );
+ assertFalse( "results with different result codes should not be equal", r1.equals( r0 ) );
+ }
+
+
+ /**
+ * Tests for inequality when the referrals are not the same.
+ */
+ @Test
+ public void testNotEqualsDiffReferrals() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r0 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl r1 = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ r0.setErrorMessage( "blah blah blah" );
+ r1.setErrorMessage( "blah blah blah" );
+
+ r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+ r1.setMatchedDn( new DN( "dc=example,dc=com" ) );
+
+ r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+ r1.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+
+ Referral refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ r0.setReferral( refs0 );
+ refs0.addLdapUrl( "ldap://someserver.com" );
+ refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+ Referral refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ r1.setReferral( refs1 );
+ refs1.addLdapUrl( "ldap://abc.com" );
+ refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+ assertFalse( "results with different referrals should not be equal", r0.equals( r1 ) );
+ assertFalse( "results with different referrals should not be equal", r1.equals( r0 ) );
+ }
+}
diff --git a/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ModifyDnRequestImplTest.java b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ModifyDnRequestImplTest.java
new file mode 100644
index 0000000..52ff518
--- /dev/null
+++ b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ModifyDnRequestImplTest.java
@@ -0,0 +1,443 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.*;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.name.RDN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * TestCase for the ModifyDnRequestImpl class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class ModifyDnRequestImplTest
+{
+ private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
+
+ /**
+ * Constructs a ModifyDnrequest to test.
+ *
+ * @return the request
+ */
+ private org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl getRequest()
+ {
+ // Construct the ModifyDn request to test
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl request = new org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl( 45 );
+ request.setDeleteOldRdn( true );
+
+ try
+ {
+ request.setName( new DN( "dc=admins,dc=apache,dc=org" ) );
+ request.setNewRdn( new RDN( "dc=administrators" ) );
+ request.setNewSuperior( new DN( "dc=groups,dc=apache,dc=org" ) );
+ }
+ catch ( LdapException ine )
+ {
+ // do nothing
+ }
+
+ return request;
+ }
+
+
+ /**
+ * Tests the same object reference for equality.
+ */
+ @Test
+ public void testEqualsSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req = new org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl( 5 );
+ assertTrue( req.equals( req ) );
+ }
+
+
+ /**
+ * Tests for equality using exact copies.
+ */
+ @Test
+ public void testEqualsExactCopy0()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+
+ assertTrue( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Tests for equality using exact copies.
+ */
+ @Test
+ public void testEqualsExactCopy1()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+ req0.setNewSuperior( null );
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+ req1.setNewSuperior( null );
+
+ assertTrue( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Tests the same object reference for equal hashCode
+ */
+ @Test
+ public void testHashCodeSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req = new org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl( 5 );
+ assertTrue( req.hashCode() == req.hashCode() );
+ }
+
+
+ /**
+ * Tests for equal hashCode using exact copies.
+ */
+ @Test
+ public void testHashCodeExactCopy0()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+
+ assertTrue( req0.hashCode() == req1.hashCode() );
+ }
+
+
+ /**
+ * Tests for equal hashCode using exact copies.
+ */
+ @Test
+ public void testHashCodeExactCopy1()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+ req0.setNewSuperior( null );
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+ req1.setNewSuperior( null );
+
+ assertTrue( req0.hashCode() == req1.hashCode() );
+ }
+
+
+ /**
+ * Test for inequality when only the IDs are different.
+ */
+ @Test
+ public void testNotEqualDiffId()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl( 4 );
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl( 5 );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the DN names are different.
+ */
+ @Test
+ public void testNotEqualDiffName() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+ req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+ req1.setName( new DN( "cn=admin,dc=apache,dc=org" ) );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the newSuperior DNs are different.
+ */
+ @Test
+ public void testNotEqualDiffNewSuperior() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+ req0.setNewSuperior( new DN( "cn=admin,dc=example,dc=com" ) );
+
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+ req1.setNewSuperior( new DN( "cn=admin,dc=apache,dc=org" ) );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the delete old Rdn properties is different.
+ */
+ @Test
+ public void testNotEqualDiffDeleteOldRdn()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+ req0.setDeleteOldRdn( true );
+
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+ req1.setDeleteOldRdn( false );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the new Rdn properties are different.
+ */
+ @Test
+ public void testNotEqualDiffNewRdn() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req0 = getRequest();
+ req0.setNewRdn( new RDN( "cn=admin0" ) );
+
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+ req1.setNewRdn( new RDN( "cn=admin1" ) );
+
+ assertFalse( req0.equals( req1 ) );
+ assertFalse( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Tests for equality even when another BindRequest implementation is used.
+ */
+ @Test
+ public void testEqualsDiffImpl()
+ {
+ ModifyDnRequest req0 = new ModifyDnRequest()
+ {
+ public DN getName()
+ {
+ try
+ {
+ return new DN( "dc=admins,dc=apache,dc=org" );
+ }
+ catch ( LdapException ine )
+ {
+ // do nothing
+ return null;
+ }
+ }
+
+
+ public void setName( DN name )
+ {
+ }
+
+
+ public RDN getNewRdn()
+ {
+ try
+ {
+ return new RDN( "dc=administrators" );
+ }
+ catch ( LdapException ine )
+ {
+ // do nothing
+ return null;
+ }
+ }
+
+
+ public void setNewRdn( RDN newRdn )
+ {
+ }
+
+
+ public boolean getDeleteOldRdn()
+ {
+ return true;
+ }
+
+
+ public void setDeleteOldRdn( boolean deleteOldRdn )
+ {
+ }
+
+
+ public DN getNewSuperior()
+ {
+ try
+ {
+ return new DN( "dc=groups,dc=apache,dc=org" );
+ }
+ catch ( LdapException ine )
+ {
+ // do nothing
+ return null;
+ }
+ }
+
+
+ public void setNewSuperior( DN newSuperior )
+ {
+ }
+
+
+ public boolean isMove()
+ {
+ return false;
+ }
+
+
+ public MessageTypeEnum getResponseType()
+ {
+ return MessageTypeEnum.MODIFYDN_RESPONSE;
+ }
+
+
+ public boolean hasResponse()
+ {
+ return true;
+ }
+
+
+ public MessageTypeEnum getType()
+ {
+ return MessageTypeEnum.MODIFYDN_REQUEST;
+ }
+
+
+ public Map<String, Control> getControls()
+ {
+ return EMPTY_CONTROL_MAP;
+ }
+
+
+ public void addControl( Control a_control ) throws MessageException
+ {
+ }
+
+
+ public void removeControl( 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 void abandon()
+ {
+ }
+
+
+ public boolean isAbandoned()
+ {
+ return false;
+ }
+
+
+ public void addAbandonListener( AbandonListener listener )
+ {
+ }
+
+
+ public ResultResponse getResultResponse()
+ {
+ return null;
+ }
+
+
+ public void addAllControls( Control[] controls ) throws MessageException
+ {
+ }
+
+
+ public boolean hasControl( String oid )
+ {
+ return false;
+ }
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
+
+
+ public int getControlsLength()
+ {
+ return 0;
+ }
+
+
+ public void setControlsLength( int controlsLength )
+ {
+ }
+
+
+ public int getMessageLength()
+ {
+ return 0;
+ }
+
+
+ public void setMessageLength( int messageLength )
+ {
+ }
+
+
+ public Control getControl( String oid )
+ {
+ return null;
+ }
+
+
+ public void setMessageId( int messageId )
+ {
+ }
+ };
+
+ org.apache.directory.shared.ldap.codec.message.ModifyDnRequestImpl req1 = getRequest();
+ assertTrue( req1.equals( req0 ) );
+ }
+}
diff --git a/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ModifyRequestImplTest.java b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ModifyRequestImplTest.java
new file mode 100644
index 0000000..306a7ef
--- /dev/null
+++ b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ModifyRequestImplTest.java
@@ -0,0 +1,539 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
+import org.apache.directory.shared.ldap.entry.DefaultModification;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.*;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test case for the ModifyRequestImpl class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class ModifyRequestImplTest
+{
+ private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
+
+ /**
+ * Builds a ModifyRequest for testing purposes.
+ *
+ * @return the ModifyRequest to use for tests
+ */
+ private org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl getRequest()
+ {
+ // Construct the Modify request to test
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req = new org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl( 45 );
+
+ try
+ {
+ req.setName( new DN( "cn=admin,dc=apache,dc=org" ) );
+ }
+ catch ( LdapException ne )
+ {
+ // do nothing
+ }
+
+ EntryAttribute attr = new DefaultEntryAttribute( "attr0" );
+ attr.add( "val0" );
+ attr.add( "val1" );
+ attr.add( "val2" );
+ Modification item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+ req.addModification( item );
+
+ attr = new DefaultEntryAttribute( "attr1" );
+ attr.add( "val3" );
+ item = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attr );
+ req.addModification( item );
+
+ attr = new DefaultEntryAttribute( "attr2" );
+ attr.add( "val4" );
+ attr.add( "val5" );
+ item = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attr );
+ req.addModification( item );
+
+ return req;
+ }
+
+
+ /**
+ * Tests the same object reference for equality.
+ */
+ @Test
+ public void testEqualsSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req = getRequest();
+ assertTrue( req.equals( req ) );
+ }
+
+
+ /**
+ * Tests for equality using exact copies.
+ */
+ @Test
+ public void testEqualsExactCopy()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = getRequest();
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+ assertTrue( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Tests the same object reference for equal hashCode.
+ */
+ @Test
+ public void testHashCodeSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req = getRequest();
+ assertTrue( req.hashCode() == req.hashCode() );
+ }
+
+
+ /**
+ * Tests for equal hashCode using exact copies.
+ */
+ @Test
+ public void testHashCodeExactCopy()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = getRequest();
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+ assertTrue( req0.hashCode() == req1.hashCode() );
+ }
+
+
+ /**
+ * Test for inequality when only the IDs are different.
+ */
+ @Test
+ public void testNotEqualDiffId()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = new org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl( 7 );
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = new org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl( 5 );
+ assertFalse( req0.equals( req1 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the DN names are different.
+ */
+ @Test
+ public void testNotEqualDiffName()
+ {
+ try
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = getRequest();
+ req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+ req1.setName( new DN( "cn=admin,dc=apache,dc=org" ) );
+
+ assertFalse( req0.equals( req1 ) );
+ }
+ catch ( LdapException ine )
+ {
+ // do nothing
+ }
+ }
+
+
+ /**
+ * Test for inequality when only the mods ops are different.
+ */
+ @Test
+ public void testNotEqualDiffModOps()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = getRequest();
+ EntryAttribute attr = new DefaultEntryAttribute( "attr3" );
+ attr.add( "val0" );
+ attr.add( "val1" );
+ attr.add( "val2" );
+ Modification item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+ req0.addModification( item );
+
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+ attr = new DefaultEntryAttribute( "attr3" );
+ attr.add( "val0" );
+ attr.add( "val1" );
+ attr.add( "val2" );
+ item = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attr );
+ req0.addModification( item );
+
+ assertFalse( req0.equals( req1 ) );
+ assertFalse( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the number of mods are different.
+ */
+ @Test
+ public void testNotEqualDiffModCount()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = getRequest();
+ EntryAttribute attr = new DefaultEntryAttribute( "attr3" );
+ attr.add( "val0" );
+ attr.add( "val1" );
+ attr.add( "val2" );
+ Modification item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+ req0.addModification( item );
+
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+
+ assertFalse( req0.equals( req1 ) );
+ assertFalse( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the mods attribute Id's are different.
+ */
+ @Test
+ public void testNotEqualDiffModIds()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = getRequest();
+ EntryAttribute attr = new DefaultEntryAttribute( "attr3" );
+ attr.add( "val0" );
+ attr.add( "val1" );
+ attr.add( "val2" );
+ Modification item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+ req0.addModification( item );
+
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+ attr = new DefaultEntryAttribute( "attr4" );
+ attr.add( "val0" );
+ attr.add( "val1" );
+ attr.add( "val2" );
+ item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+ req0.addModification( item );
+
+ assertFalse( req0.equals( req1 ) );
+ assertFalse( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Test for inequality when only the mods attribute values are different.
+ */
+ @Test
+ public void testNotEqualDiffModValues()
+ {
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req0 = getRequest();
+ EntryAttribute attr = new DefaultEntryAttribute( "attr3" );
+ attr.add( "val0" );
+ attr.add( "val1" );
+ attr.add( "val2" );
+ Modification item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+ req0.addModification( item );
+
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+ attr = new DefaultEntryAttribute( "attr3" );
+ attr.add( "val0" );
+ attr.add( "val1" );
+ attr.add( "val2" );
+ attr.add( "val3" );
+ item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+ req0.addModification( item );
+
+ assertFalse( req0.equals( req1 ) );
+ assertFalse( req1.equals( req0 ) );
+ }
+
+
+ /**
+ * Tests for equality even when another BindRequest implementation is used.
+ */
+ @Test
+ public void testEqualsDiffImpl()
+ {
+ ModifyRequest req0 = new ModifyRequest()
+ {
+ public Collection<Modification> getModifications()
+ {
+ List<Modification> list = new ArrayList<Modification>();
+ EntryAttribute attr = new DefaultEntryAttribute( "attr0" );
+ attr.add( "val0" );
+ attr.add( "val1" );
+ attr.add( "val2" );
+ Modification item = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr );
+ list.add( item );
+
+ attr = new DefaultEntryAttribute( "attr1" );
+ attr.add( "val3" );
+ item = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attr );
+ list.add( item );
+
+ attr = new DefaultEntryAttribute( "attr2" );
+ attr.add( "val4" );
+ attr.add( "val5" );
+ item = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attr );
+ list.add( item );
+
+ return list;
+ }
+
+
+ public void addModification( Modification mod )
+ {
+ }
+
+
+ public void removeModification( Modification mod )
+ {
+ }
+
+
+ public DN getName()
+ {
+ try
+ {
+ return new DN( "cn=admin,dc=apache,dc=org" );
+ }
+ catch ( Exception e )
+ {
+ //do nothing
+ return null;
+ }
+ }
+
+
+ public void setName( DN name )
+ {
+ }
+
+
+ public MessageTypeEnum getResponseType()
+ {
+ return MessageTypeEnum.MODIFY_RESPONSE;
+ }
+
+
+ public boolean hasResponse()
+ {
+ return true;
+ }
+
+
+ public MessageTypeEnum getType()
+ {
+ return MessageTypeEnum.MODIFY_REQUEST;
+ }
+
+
+ public Map<String, Control> getControls()
+ {
+ return EMPTY_CONTROL_MAP;
+ }
+
+
+ public void addControl( Control a_control ) throws MessageException
+ {
+ }
+
+
+ public void removeControl( 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 void abandon()
+ {
+ }
+
+
+ public boolean isAbandoned()
+ {
+ return false;
+ }
+
+
+ public void addAbandonListener( AbandonListener listener )
+ {
+ }
+
+
+ public ResultResponse getResultResponse()
+ {
+ return null;
+ }
+
+
+ public void addAllControls( Control[] controls ) throws MessageException
+ {
+ }
+
+
+ public boolean hasControl( String oid )
+ {
+ return false;
+ }
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
+
+
+ public int getControlsLength()
+ {
+ return 0;
+ }
+
+
+ public void setControlsLength( int controlsLength )
+ {
+ }
+
+
+ public int getMessageLength()
+ {
+ return 0;
+ }
+
+
+ public void setMessageLength( int messageLength )
+ {
+ }
+
+
+ public Control getControl( String oid )
+ {
+ return null;
+ }
+
+
+ public void setMessageId( int messageId )
+ {
+ }
+
+
+ public void addModification( EntryAttribute attr, ModificationOperation modOp )
+ {
+ }
+
+
+ public void replace( String attributeName )
+ {
+ }
+
+
+ public void replace( String attributeName, String... attributeValue )
+ {
+ }
+
+
+ public void replace( String attributeName, byte[]... attributeValue )
+ {
+ }
+
+
+ public void replace( EntryAttribute attr )
+ {
+ }
+
+
+ public void add( String attributeName, String... attributeValue )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ public void add( String attributeName, byte[]... attributeValue )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ public void add( EntryAttribute attr )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ public void remove( String attributeName, String... attributeValue )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ public void remove( String attributeName, byte[]... attributeValue )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ public void remove( EntryAttribute attr )
+ {
+ // TODO Auto-generated method stub
+
+ }
+ };
+
+ org.apache.directory.shared.ldap.codec.message.ModifyRequestImpl req1 = getRequest();
+ assertTrue( req1.equals( req0 ) );
+ }
+}
diff --git a/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ReferralImplTest.java b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ReferralImplTest.java
new file mode 100644
index 0000000..6c70f56
--- /dev/null
+++ b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/ReferralImplTest.java
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.message.Referral;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Tests the ReferralImpl class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ * $Rev: 946251 $
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class ReferralImplTest
+{
+ /**
+ * Tests to make sure the equals method works for the same exact object.
+ */
+ @Test
+ public void testEqualsSameObject()
+ {
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ assertTrue( "equals method should work for the same object", refs.equals( refs ) );
+ }
+
+
+ /**
+ * Tests to make sure the equals method works for two objects that are the
+ * same exact copy of one another.
+ */
+ @Test
+ public void testEqualsExactCopy()
+ {
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs0.addLdapUrl( "ldap://blah0" );
+ refs0.addLdapUrl( "ldap://blah1" );
+ refs0.addLdapUrl( "ldap://blah2" );
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs1.addLdapUrl( "ldap://blah0" );
+ refs1.addLdapUrl( "ldap://blah1" );
+ refs1.addLdapUrl( "ldap://blah2" );
+ assertTrue( "exact copies of Referrals should be equal", refs0.equals( refs1 ) );
+ assertTrue( "exact copies of Referrals should be equal", refs1.equals( refs0 ) );
+ }
+
+
+ /**
+ * Tests to make sure the equals method works for two objects that are the
+ * same exact copy of one another but there are redundant entries.
+ */
+ @Test
+ public void testEqualsExactCopyWithRedundancy()
+ {
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs0.addLdapUrl( "ldap://blah0" );
+ refs0.addLdapUrl( "ldap://blah1" );
+ refs0.addLdapUrl( "ldap://blah2" );
+ refs0.addLdapUrl( "ldap://blah2" );
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs1.addLdapUrl( "ldap://blah0" );
+ refs1.addLdapUrl( "ldap://blah1" );
+ refs1.addLdapUrl( "ldap://blah2" );
+ refs1.addLdapUrl( "ldap://blah2" );
+ assertTrue( "exact copies of Referrals should be equal", refs0.equals( refs1 ) );
+ assertTrue( "exact copies of Referrals should be equal", refs1.equals( refs0 ) );
+ }
+
+
+ /**
+ * Tests to make sure to get equal hashCode for the same exact object.
+ */
+ @Test
+ public void testHashCodeSameObject()
+ {
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ assertTrue( refs.hashCode() == refs.hashCode() );
+ }
+
+
+ /**
+ * Tests to make sure to get equal hashCode for two objects that are the
+ * same exact copy of one another.
+ */
+ @Test
+ public void testHashCodeExactCopy()
+ {
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs0.addLdapUrl( "ldap://blah0" );
+ refs0.addLdapUrl( "ldap://blah1" );
+ refs0.addLdapUrl( "ldap://blah2" );
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs1.addLdapUrl( "ldap://blah0" );
+ refs1.addLdapUrl( "ldap://blah1" );
+ refs1.addLdapUrl( "ldap://blah2" );
+ assertTrue( refs0.hashCode() == refs1.hashCode() );
+ }
+
+
+ /**
+ * Tests to make sure to get equal hashCode for two objects that are the
+ * same exact copy of one another but there are redundant entries.
+ */
+ @Test
+ public void testHashCodeExactCopyWithRedundancy()
+ {
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs0.addLdapUrl( "ldap://blah0" );
+ refs0.addLdapUrl( "ldap://blah1" );
+ refs0.addLdapUrl( "ldap://blah2" );
+ refs0.addLdapUrl( "ldap://blah2" );
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs1.addLdapUrl( "ldap://blah0" );
+ refs1.addLdapUrl( "ldap://blah1" );
+ refs1.addLdapUrl( "ldap://blah2" );
+ refs1.addLdapUrl( "ldap://blah2" );
+ assertTrue( refs0.hashCode() == refs1.hashCode() );
+ }
+
+
+ /**
+ * Tests to make sure the equals method works for two objects that are the
+ * not exact copies of one another but have the same number of URLs.
+ */
+ @Test
+ public void testEqualsSameNumberButDifferentUrls()
+ {
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs0.addLdapUrl( "ldap://blah0" );
+ refs0.addLdapUrl( "ldap://blah1" );
+ refs0.addLdapUrl( "ldap://blah2" );
+ refs0.addLdapUrl( "ldap://blah3" );
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs1.addLdapUrl( "ldap://blah0" );
+ refs1.addLdapUrl( "ldap://blah1" );
+ refs1.addLdapUrl( "ldap://blah2" );
+ refs1.addLdapUrl( "ldap://blah4" );
+ assertFalse( "Referrals should not be equal", refs0.equals( refs1 ) );
+ assertFalse( "Referrals should not be equal", refs1.equals( refs0 ) );
+ }
+
+
+ /**
+ * Tests to make sure the equals method works for two objects that are the
+ * not exact copies of one another and one has a subset of the urls of the
+ * other.
+ */
+ @Test
+ public void testEqualsSubset()
+ {
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs0 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs0.addLdapUrl( "ldap://blah0" );
+ refs0.addLdapUrl( "ldap://blah1" );
+ refs0.addLdapUrl( "ldap://blah2" );
+ refs0.addLdapUrl( "ldap://blah3" );
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs1.addLdapUrl( "ldap://blah0" );
+ refs1.addLdapUrl( "ldap://blah1" );
+ assertFalse( "Referrals should not be equal", refs0.equals( refs1 ) );
+ assertFalse( "Referrals should not be equal", refs1.equals( refs0 ) );
+ }
+
+
+ @Test
+ public void testEqualsDifferentImpls()
+ {
+ Referral refs0 = new Referral()
+ {
+ public Collection<String> getLdapUrls()
+ {
+ return Collections.EMPTY_LIST;
+ }
+
+
+ public void addLdapUrl( String url )
+ {
+ }
+
+
+ public void removeLdapUrl( String url )
+ {
+ }
+
+
+ public void addLdapUrlBytes( byte[] urlBytes )
+ {
+ }
+
+
+ public Collection<byte[]> getLdapUrlsBytes()
+ {
+ return null;
+ }
+
+
+ public int getReferralLength()
+ {
+ return 0;
+ }
+
+
+ public void setReferralLength( int referralLength )
+ {
+ }
+ };
+
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs1 = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+
+ assertFalse( "Object.equals() in effect because we did not redefine " + " equals for the new impl above", refs0
+ .equals( refs1 ) );
+ assertTrue( "Empty Referrals should be equal even if they are different" + " implementation classes", refs1
+ .equals( refs0 ) );
+ }
+}
diff --git a/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseDoneImplTest.java b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseDoneImplTest.java
new file mode 100644
index 0000000..3a52e0a
--- /dev/null
+++ b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseDoneImplTest.java
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.codec.message.ReferralImpl;
+import org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.*;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * TestCases for the SearchResponseImpl class methods.
+ *
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ * $Rev: 946251 $
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class SearchResponseDoneImplTest
+{
+ private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
+
+ /**
+ * Creates and populates a SearchResponseDoneImpl stub for testing purposes.
+ *
+ * @return a populated SearchResponseDoneImpl stub
+ */
+ private org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl createStub()
+ {
+ // Construct the Search response to test with results and referrals
+ org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl response = new org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl( 45 );
+ LdapResult result = response.getLdapResult();
+
+ try
+ {
+ result.setMatchedDn( new DN( "dc=example,dc=com" ) );
+ }
+ catch ( LdapException ine )
+ {
+ // do nothing
+ }
+
+ result.setResultCode( ResultCodeEnum.SUCCESS );
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl refs = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs.addLdapUrl( "ldap://someserver.com" );
+ refs.addLdapUrl( "ldap://apache.org" );
+ refs.addLdapUrl( "ldap://another.net" );
+ result.setReferral( refs );
+ return response;
+ }
+
+
+ /**
+ * Tests for equality using the same object.
+ */
+ @Test
+ public void testEqualsSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp = createStub();
+ assertTrue( resp.equals( resp ) );
+ }
+
+
+ /**
+ * Tests for equality using an exact copy.
+ */
+ @Test
+ public void testEqualsExactCopy()
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp0 = createStub();
+ org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp1 = createStub();
+ assertTrue( resp0.equals( resp1 ) );
+ assertTrue( resp1.equals( resp0 ) );
+ }
+
+
+ /**
+ * Tests for equality using different stub implementations.
+ */
+ @Test
+ public void testEqualsDiffImpl()
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp0 = createStub();
+ SearchResultDone resp1 = new SearchResultDone()
+ {
+ public LdapResult getLdapResult()
+ {
+ org.apache.directory.shared.ldap.codec.message.LdapResultImpl result = new org.apache.directory.shared.ldap.codec.message.LdapResultImpl();
+
+ try
+ {
+ result.setMatchedDn( new DN( "dc=example,dc=com" ) );
+ }
+ catch ( Exception e )
+ {
+ // Do nothing
+ }
+ result.setResultCode( ResultCodeEnum.SUCCESS );
+ ReferralImpl refs = new org.apache.directory.shared.ldap.codec.message.ReferralImpl();
+ refs.addLdapUrl( "ldap://someserver.com" );
+ refs.addLdapUrl( "ldap://apache.org" );
+ refs.addLdapUrl( "ldap://another.net" );
+ result.setReferral( refs );
+
+ return result;
+ }
+
+
+ public MessageTypeEnum getType()
+ {
+ return MessageTypeEnum.SEARCH_RESULT_DONE;
+ }
+
+
+ public Map<String, Control> getControls()
+ {
+ return EMPTY_CONTROL_MAP;
+ }
+
+
+ public void addControl( Control a_control ) throws MessageException
+ {
+ }
+
+
+ public void removeControl( 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 void addAllControls( Control[] controls ) throws MessageException
+ {
+ }
+
+
+ public boolean hasControl( String oid )
+ {
+ return false;
+ }
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
+
+
+ public int getControlsLength()
+ {
+ return 0;
+ }
+
+
+ public void setControlsLength( int controlsLength )
+ {
+ }
+
+
+ public int getMessageLength()
+ {
+ return 0;
+ }
+
+
+ public void setMessageLength( int messageLength )
+ {
+ }
+
+
+ public Control getControl( String oid )
+ {
+ return null;
+ }
+
+
+ public void setMessageId( int messageId )
+ {
+ }
+ };
+
+ assertTrue( resp0.equals( resp1 ) );
+ assertFalse( resp1.equals( resp0 ) );
+ }
+
+
+ /**
+ * Tests for equal hashCode using the same object.
+ */
+ @Test
+ public void testHashCodeSameObj()
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp = createStub();
+ assertTrue( resp.hashCode() == resp.hashCode() );
+ }
+
+
+ /**
+ * Tests for equal hashCode using an exact copy.
+ */
+ @Test
+ public void testHashCodeExactCopy()
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp0 = createStub();
+ org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp1 = createStub();
+ assertTrue( resp0.hashCode() == resp1.hashCode() );
+ }
+
+
+ /**
+ * Tests inequality when messageIds are different.
+ */
+ @Test
+ public void testNotEqualsDiffIds()
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl resp0 = new org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl( 3 );
+ SearchResultDoneImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultDoneImpl( 4 );
+
+ assertFalse( resp0.equals( resp1 ) );
+ assertFalse( resp1.equals( resp0 ) );
+ }
+}
diff --git a/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseEntryImplTest.java b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseEntryImplTest.java
new file mode 100644
index 0000000..b585e5c
--- /dev/null
+++ b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseEntryImplTest.java
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Test cases for the methods of the SearchResponseEntryImpl class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ * $Rev: 946251 $
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class SearchResponseEntryImplTest
+{
+ /**
+ * Creates and populates an EntryAttribute with a specific id.
+ *
+ * @param id the id for the attribute
+ * @return the EntryAttribute assembled for testing
+ */
+ private EntryAttribute getEntry( String id )
+ {
+ EntryAttribute attr = new DefaultEntryAttribute( id );
+ attr.add( "value0" );
+ attr.add( "value1" );
+ attr.add( "value2" );
+ return attr;
+ }
+
+
+ /**
+ * Creates and populates an Entry object
+ *
+ * @return The populated Entry object
+ */
+ private Entry getEntry() throws LdapException
+ {
+ Entry attrs = new DefaultEntry();
+ attrs.put( getEntry( "attr0" ) );
+ attrs.put( getEntry( "attr1" ) );
+ attrs.put( getEntry( "attr2" ) );
+ return attrs;
+ }
+
+
+ /**
+ * Tests for equality when the same object reference is used.
+ */
+ @Test
+ public void testEqualsSameObject()
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+ assertTrue( "the same object should be equal", resp.equals( resp ) );
+ }
+
+
+ /**
+ * Tests for equality when an exact copy is compared.
+ */
+ @Test
+ public void testEqualsExactCopy() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp0 = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+ resp0.setEntry( getEntry() );
+ resp0.setObjectName( new DN( "dc=example,dc=com" ) );
+
+ org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+ resp1.setEntry( getEntry() );
+ resp1.setObjectName( new DN( "dc=example,dc=com" ) );
+
+ assertTrue( "exact copies should be equal", resp0.equals( resp1 ) );
+ assertTrue( "exact copies should be equal", resp1.equals( resp0 ) );
+ }
+
+
+ /**
+ * Tests for equal hashCode when the same object reference is used.
+ */
+ @Test
+ public void testHashCodeSameObject()
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+ assertTrue( resp.hashCode() == resp.hashCode() );
+ }
+
+
+ /**
+ * Tests for equal hashCode when an exact copy is compared.
+ */
+ @Test
+ public void testHashCodeExactCopy() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp0 = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+ resp0.setEntry( getEntry() );
+ resp0.setObjectName( new DN( "dc=example,dc=com" ) );
+
+ org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+ resp1.setEntry( getEntry() );
+ resp1.setObjectName( new DN( "dc=example,dc=com" ) );
+
+ assertTrue( resp0.hashCode() == resp1.hashCode() );
+ }
+
+
+ /**
+ * Tests for inequality when the objectName dn is not the same.
+ */
+ @Test
+ public void testNotEqualDiffObjectName() throws LdapException
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp0 = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+ resp0.setEntry( getEntry() );
+ resp0.setObjectName( new DN( "dc=apache,dc=org" ) );
+
+ org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultEntryImpl( 5 );
+ resp1.setEntry( getEntry() );
+ resp1.setObjectName( new DN( "dc=example,dc=com" ) );
+
+ assertFalse( "different object names should not be equal", resp1.equals( resp0 ) );
+ assertFalse( "different object names should not be equal", resp0.equals( resp1 ) );
+ }
+}
diff --git a/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseReferenceImplTest.java b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseReferenceImplTest.java
new file mode 100644
index 0000000..1022c0a
--- /dev/null
+++ b/ldap/src/test/java/org/apache/directory/shared/ldap/codec/message/SearchResponseReferenceImplTest.java
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.message;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.message.MessageException;
+import org.apache.directory.shared.ldap.message.MessageTypeEnum;
+import org.apache.directory.shared.ldap.message.Referral;
+import org.apache.directory.shared.ldap.message.SearchResultReference;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * TestCase for the SearchResponseReferenceImpl class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class SearchResponseReferenceImplTest
+{
+ private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
+
+ /**
+ * Creates a baseline referral to test with and adds it to the supplied
+ * response object.
+ *
+ * @param resp
+ * the parent lockable
+ * @return the newly created referral for testing
+ */
+ private Referral getReferral( SearchResultReference resp )
+ {
+ org.apache.directory.shared.ldap.codec.message.ReferralImpl ref = new ReferralImpl();
+ resp.setReferral( ref );
+ ref.addLdapUrl( "http://apache.org???" );
+ ref.addLdapUrl( "http://mit.edu???" );
+ ref.addLdapUrl( "http://abc.com???" );
+ return ref;
+ }
+
+
+ /**
+ * Tests for equality when the same object reference is used.
+ */
+ @Test
+ public void testEqualsSameObject()
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+ getReferral( resp );
+ assertTrue( "the same object should be equal", resp.equals( resp ) );
+ }
+
+
+ /**
+ * Tests for equality when an exact copy is compared.
+ */
+ @Test
+ public void testEqualsExactCopy()
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp0 = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+ getReferral( resp0 );
+ org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+ getReferral( resp1 );
+
+ assertTrue( "exact copies should be equal", resp0.equals( resp1 ) );
+ assertTrue( "exact copies should be equal", resp1.equals( resp0 ) );
+ }
+
+
+ /**
+ * Tests for equality when a different implementation is used.
+ */
+ @Test
+ public void testEqualsDiffImpl()
+ {
+ SearchResultReference resp0 = new SearchResultReference()
+ {
+ public Referral getReferral()
+ {
+ return SearchResponseReferenceImplTest.this.getReferral( this );
+ }
+
+
+ public void setReferral( Referral referral )
+ {
+ }
+
+
+ public MessageTypeEnum getType()
+ {
+ return MessageTypeEnum.SEARCH_RESULT_REFERENCE;
+ }
+
+
+ public Map<String, Control> getControls()
+ {
+ return EMPTY_CONTROL_MAP;
+ }
+
+
+ public void addControl( Control control ) throws MessageException
+ {
+ }
+
+
+ public void removeControl( 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 void addAllControls( Control[] controls ) throws MessageException
+ {
+ }
+
+
+ public boolean hasControl( String oid )
+ {
+ return false;
+ }
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
+
+
+ public int getControlsLength()
+ {
+ return 0;
+ }
+
+
+ public void setControlsLength( int controlsLength )
+ {
+ }
+
+
+ public int getMessageLength()
+ {
+ return 0;
+ }
+
+
+ public void setMessageLength( int messageLength )
+ {
+ }
+
+
+ public Control getControl( String oid )
+ {
+ return null;
+ }
+
+
+ public void setMessageId( int messageId )
+ {
+ }
+ };
+
+ org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+ getReferral( resp1 );
+
+ assertFalse( "using Object.equal() should NOT be equal", resp0.equals( resp1 ) );
+ assertTrue( "same but different implementations should be equal", resp1.equals( resp0 ) );
+ }
+
+
+ /**
+ * Tests for equal hashCode when the same object reference is used.
+ */
+ @Test
+ public void testHashCodeSameObject()
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+ getReferral( resp );
+ assertTrue( resp.hashCode() == resp.hashCode() );
+ }
+
+
+ /**
+ * Tests for equal hashCode when an exact copy is compared.
+ */
+ @Test
+ public void testHashCodeExactCopy()
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp0 = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+ getReferral( resp0 );
+ org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+ getReferral( resp1 );
+
+ assertTrue( resp0.hashCode() == resp1.hashCode() );
+ }
+
+
+ /**
+ * Tests for inequality when the urls are not the same.
+ */
+ @Test
+ public void testNotEqualDiffUrls()
+ {
+ org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp0 = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+ getReferral( resp0 );
+ org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl resp1 = new org.apache.directory.shared.ldap.codec.message.SearchResultReferenceImpl( 5 );
+ getReferral( resp1 );
+ resp1.getReferral().addLdapUrl( "ldap://asdf.com???" );
+
+ assertFalse( "different urls should not be equal", resp1.equals( resp0 ) );
+ assertFalse( "different urls should not be equal", resp0.equals( resp1 ) );
+ }
+
+}