You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/08/09 08:42:25 UTC
svn commit: r983534 [2/3] - in /directory:
apacheds/branches/apacheds-codec-merge/server-integ/src/test/java/org/apache/directory/server/operations/add/
shared/branches/shared-codec-merge/asn1/src/main/java/org/apache/directory/shared/asn1/codec/statef...
Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapControlTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapControlTest.java?rev=983534&r1=983533&r2=983534&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapControlTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapControlTest.java Mon Aug 9 06:41:54 2010
@@ -19,13 +19,14 @@
*/
package org.apache.directory.shared.ldap.codec;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Map;
import org.apache.directory.junit.tools.Concurrent;
import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -35,6 +36,7 @@ import org.apache.directory.shared.asn1.
import org.apache.directory.shared.asn1.codec.EncoderException;
import org.apache.directory.shared.ldap.codec.abandon.AbandonRequestCodec;
import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.message.internal.InternalAbandonRequest;
import org.apache.directory.shared.ldap.util.StringTools;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -54,37 +56,28 @@ public class LdapControlTest
ByteBuffer stream = ByteBuffer.allocate( 0x64 );
stream.put( new byte[]
- {
- 0x30, 0x62, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x03, // messageID MessageID
- 0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
- // AbandonRequest,...
- ( byte ) 0xA0, 0x5A, // controls [0] Controls OPTIONAL }
- 0x30, 0x1A, // Control ::= SEQUENCE {
- // controlType LDAPOID,
- 0x04, 0x0D,
- '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1',
- // criticality BOOLEAN DEFAULT FALSE,
- 0x01, 0x01, ( byte ) 0xFF,
- // controlValue OCTET STRING OPTIONAL }
- 0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f',
- 0x30, 0x17, // Control ::= SEQUENCE {
- // controlType LDAPOID,
- 0x04, 0x0D,
- '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
- // controlValue OCTET STRING OPTIONAL }
- 0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l',
- 0x30, 0x12, // Control ::= SEQUENCE {
- // controlType LDAPOID,
- 0x04, 0x0D,
- '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '3',
- // criticality BOOLEAN DEFAULT FALSE}
- 0x01, 0x01, ( byte ) 0xFF,
- 0x30, 0x0F, // Control ::= SEQUENCE {
- // controlType LDAPOID}
- 0x04, 0x0D,
- '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4'
- } );
+ { 0x30, 0x62, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x03, // messageID MessageID
+ 0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
+ // AbandonRequest,...
+ ( byte ) 0xA0, 0x5A, // controls [0] Controls OPTIONAL }
+ 0x30, 0x1A, // Control ::= SEQUENCE {
+ // controlType LDAPOID,
+ 0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1',
+ // criticality BOOLEAN DEFAULT FALSE,
+ 0x01, 0x01, ( byte ) 0xFF,
+ // controlValue OCTET STRING OPTIONAL }
+ 0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', 0x30, 0x17, // Control ::= SEQUENCE {
+ // controlType LDAPOID,
+ 0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+ // controlValue OCTET STRING OPTIONAL }
+ 0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l', 0x30, 0x12, // Control ::= SEQUENCE {
+ // controlType LDAPOID,
+ 0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '3',
+ // criticality BOOLEAN DEFAULT FALSE}
+ 0x01, 0x01, ( byte ) 0xFF, 0x30, 0x0F, // Control ::= SEQUENCE {
+ // controlType LDAPOID}
+ 0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4' } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -104,43 +97,53 @@ public class LdapControlTest
}
// Check that everything is OK
- AbandonRequestCodec abandonRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAbandonRequest();
+ InternalAbandonRequest abandonRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
+ .getInternalAbandonRequest();
+
+ // Copy the message
+ AbandonRequestCodec abandonRequestCodec = new AbandonRequestCodec();
+ abandonRequestCodec.setMessageId( abandonRequest.getMessageId() );
+ abandonRequestCodec.setAbandonedMessageId( abandonRequest.getAbandoned() );
assertEquals( 3, abandonRequest.getMessageId() );
- assertEquals( 2, abandonRequest.getAbandonedMessageId() );
+ assertEquals( 2, abandonRequest.getAbandoned() );
// Check the Controls
- List<Control> controls = abandonRequest.getControls();
+ Map<String, Control> controls = abandonRequest.getControls();
assertEquals( 4, controls.size() );
- Control control = abandonRequest.getControls( 0 );
+ Control control = controls.get( "1.3.6.1.5.5.1" );
assertEquals( "1.3.6.1.5.5.1", control.getOid() );
assertEquals( "0x61 0x62 0x63 0x64 0x65 0x66 ", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
assertTrue( control.isCritical() );
+ abandonRequestCodec.addControl( control );
- control = abandonRequest.getControls( 1 );
+ control = controls.get( "1.3.6.1.5.5.2" );
assertEquals( "1.3.6.1.5.5.2", control.getOid() );
assertEquals( "0x67 0x68 0x69 0x6A 0x6B 0x6C ", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
assertFalse( control.isCritical() );
+ abandonRequestCodec.addControl( control );
- control = abandonRequest.getControls( 2 );
+ control = controls.get( "1.3.6.1.5.5.3" );
assertEquals( "1.3.6.1.5.5.3", control.getOid() );
assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
assertTrue( control.isCritical() );
+ abandonRequestCodec.addControl( control );
- control = abandonRequest.getControls( 3 );
+ control = controls.get( "1.3.6.1.5.5.4" );
assertEquals( "1.3.6.1.5.5.4", control.getOid() );
assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
assertFalse( control.isCritical() );
+ abandonRequestCodec.addControl( control );
// Check the length
- assertEquals( 0x64, abandonRequest.computeLength() );
+ assertEquals( 0x64, abandonRequestCodec.computeLength() );
// Check the encoding
try
{
- ByteBuffer bb = abandonRequest.encode();
+ ByteBuffer bb = abandonRequestCodec.encode();
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -153,6 +156,7 @@ public class LdapControlTest
}
}
+
/**
* Test the decoding of a Request with null OID controls
*/
@@ -163,20 +167,18 @@ public class LdapControlTest
ByteBuffer stream = ByteBuffer.allocate( 0x19 );
stream.put( new byte[]
- {
- 0x30, 0x17, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x03, // messageID MessageID
- 0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
- // AbandonRequest,...
- ( byte ) 0xA0, 0x0F, // controls [0] Controls OPTIONAL }
- 0x30, 0x0D, // Control ::= SEQUENCE {
- // controlType LDAPOID,
- 0x04, 0x00,
- // criticality BOOLEAN DEFAULT FALSE,
- 0x01, 0x01, ( byte ) 0xFF,
- // controlValue OCTET STRING OPTIONAL }
- 0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f',
- } );
+ { 0x30, 0x17, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x03, // messageID MessageID
+ 0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
+ // AbandonRequest,...
+ ( byte ) 0xA0, 0x0F, // controls [0] Controls OPTIONAL }
+ 0x30, 0x0D, // Control ::= SEQUENCE {
+ // controlType LDAPOID,
+ 0x04, 0x00,
+ // criticality BOOLEAN DEFAULT FALSE,
+ 0x01, 0x01, ( byte ) 0xFF,
+ // controlValue OCTET STRING OPTIONAL }
+ 0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', } );
stream.flip();
@@ -197,6 +199,7 @@ public class LdapControlTest
fail( "We should not reach this point" );
}
+
/**
* Test the decoding of a Request with bad OID controls
*/
@@ -207,20 +210,18 @@ public class LdapControlTest
ByteBuffer stream = ByteBuffer.allocate( 0x20 );
stream.put( new byte[]
- {
- 0x30, 0x1E, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x03, // messageID MessageID
- 0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
- // AbandonRequest,...
- ( byte ) 0xA0, 0x16, // controls [0] Controls OPTIONAL }
- 0x30, 0x14, // Control ::= SEQUENCE {
- // controlType LDAPOID,
- 0x04, 0x07, 'b', 'a', 'd', ' ', 'o', 'i', 'd',
- // criticality BOOLEAN DEFAULT FALSE,
- 0x01, 0x01, ( byte ) 0xFF,
- // controlValue OCTET STRING OPTIONAL }
- 0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f',
- } );
+ { 0x30, 0x1E, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x03, // messageID MessageID
+ 0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
+ // AbandonRequest,...
+ ( byte ) 0xA0, 0x16, // controls [0] Controls OPTIONAL }
+ 0x30, 0x14, // Control ::= SEQUENCE {
+ // controlType LDAPOID,
+ 0x04, 0x07, 'b', 'a', 'd', ' ', 'o', 'i', 'd',
+ // criticality BOOLEAN DEFAULT FALSE,
+ 0x01, 0x01, ( byte ) 0xFF,
+ // controlValue OCTET STRING OPTIONAL }
+ 0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', } );
stream.flip();
@@ -241,6 +242,7 @@ public class LdapControlTest
fail( "We should not reach this point" );
}
+
/**
* Test the decoding of a Request with bad criticality
*/
@@ -251,21 +253,18 @@ public class LdapControlTest
ByteBuffer stream = ByteBuffer.allocate( 0x25 );
stream.put( new byte[]
- {
- 0x30, 0x23, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x03, // messageID MessageID
- 0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
- // AbandonRequest,...
- ( byte ) 0xA0, 0x1B, // controls [0] Controls OPTIONAL }
- 0x30, 0x19, // Control ::= SEQUENCE {
- // controlType LDAPOID,
- 0x04, 0x0D,
- '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1',
- // criticality BOOLEAN DEFAULT FALSE,
- 0x01, 0x00,
- // controlValue OCTET STRING OPTIONAL }
- 0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f',
- } );
+ { 0x30, 0x23, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x03, // messageID MessageID
+ 0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
+ // AbandonRequest,...
+ ( byte ) 0xA0, 0x1B, // controls [0] Controls OPTIONAL }
+ 0x30, 0x19, // Control ::= SEQUENCE {
+ // controlType LDAPOID,
+ 0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1',
+ // criticality BOOLEAN DEFAULT FALSE,
+ 0x01, 0x00,
+ // controlValue OCTET STRING OPTIONAL }
+ 0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', } );
stream.flip();
Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapMessageTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapMessageTest.java?rev=983534&r1=983533&r2=983534&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapMessageTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapMessageTest.java Mon Aug 9 06:41:54 2010
@@ -32,6 +32,8 @@ import org.apache.directory.shared.asn1.
import org.apache.directory.shared.asn1.ber.IAsn1Container;
import org.apache.directory.shared.asn1.codec.DecoderException;
import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.codec.unbind.UnBindRequestCodec;
+import org.apache.directory.shared.ldap.message.internal.InternalMessage;
import org.apache.directory.shared.ldap.util.StringTools;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -60,8 +62,7 @@ public class LdapMessageTest
ByteBuffer stream = ByteBuffer.allocate( 0x02 );
stream.put( new byte[]
- {
- 0x30, 0x00, // LDAPMessage ::=SEQUENCE {
+ { 0x30, 0x00, // LDAPMessage ::=SEQUENCE {
} );
stream.flip();
@@ -95,9 +96,8 @@ public class LdapMessageTest
ByteBuffer stream = ByteBuffer.allocate( 0x04 );
stream.put( new byte[]
- {
- 0x30, 0x02, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x00 // messageID MessageID
+ { 0x30, 0x02, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x00 // messageID MessageID
} );
stream.flip();
@@ -131,9 +131,8 @@ public class LdapMessageTest
ByteBuffer stream = ByteBuffer.allocate( 0x05 );
stream.put( new byte[]
- {
- 0x30, 0x03, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, ( byte ) 0xff // messageID MessageID = -1
+ { 0x30, 0x03, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, ( byte ) 0xff // messageID MessageID = -1
} );
stream.flip();
@@ -167,11 +166,9 @@ public class LdapMessageTest
ByteBuffer stream = ByteBuffer.allocate( 0x08 );
stream.put( new byte[]
- {
- 0x30, 0x06, // LDAPMessage ::=SEQUENCE {
- // messageID MessageID = -1
- 0x02, 0x04, ( byte ) 0x7f, ( byte ) 0xff, ( byte ) 0xff, ( byte ) 0xff
- } );
+ { 0x30, 0x06, // LDAPMessage ::=SEQUENCE {
+ // messageID MessageID = -1
+ 0x02, 0x04, ( byte ) 0x7f, ( byte ) 0xff, ( byte ) 0xff, ( byte ) 0xff } );
stream.flip();
@@ -201,10 +198,9 @@ public class LdapMessageTest
{
byte[] buffer = new byte[]
- {
- 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID = 1
- 0x42, 0x00 // ProtocolOp
+ { 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID = 1
+ 0x42, 0x00 // ProtocolOp
};
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -287,11 +283,10 @@ public class LdapMessageTest
ByteBuffer stream = ByteBuffer.allocate( 0x08 );
stream.put( new byte[]
- {
- 0x30, 0x06, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x02, 0x01, ( byte ) 0xF4, // messageID MessageID (500)
- 0x42, 0x00, // CHOICE { ..., unbindRequest UnbindRequest,...
- // UnbindRequest ::= [APPLICATION 2] NULL
+ { 0x30, 0x06, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x02, 0x01, ( byte ) 0xF4, // messageID MessageID (500)
+ 0x42, 0x00, // CHOICE { ..., unbindRequest UnbindRequest,...
+ // UnbindRequest ::= [APPLICATION 2] NULL
} );
String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -310,16 +305,19 @@ public class LdapMessageTest
fail( de.getMessage() );
}
- LdapMessageCodec message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ InternalMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getInternalMessage();
assertEquals( 500, message.getMessageId() );
// Check the length
- assertEquals( 8, message.computeLength() );
+ UnBindRequestCodec unbindRequestCodec = new UnBindRequestCodec();
+ unbindRequestCodec.setMessageId( message.getMessageId() );
+
+ assertEquals( 8, unbindRequestCodec.computeLength() );
try
{
- ByteBuffer bb = message.encode();
+ ByteBuffer bb = unbindRequestCodec.encode();
String encodedPdu = StringTools.dumpBytes( bb.array() );
Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/abandon/AbandonRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/abandon/AbandonRequestTest.java?rev=983534&r1=983533&r2=983534&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/abandon/AbandonRequestTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/abandon/AbandonRequestTest.java Mon Aug 9 06:41:54 2010
@@ -26,7 +26,7 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Map;
import org.apache.directory.junit.tools.Concurrent;
import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -36,6 +36,7 @@ import org.apache.directory.shared.asn1.
import org.apache.directory.shared.asn1.codec.EncoderException;
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.message.internal.InternalAbandonRequest;
import org.apache.directory.shared.ldap.util.StringTools;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -60,38 +61,28 @@ public class AbandonRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x64 );
stream.put( new byte[]
- {
- 0x30, 0x62, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x03, // messageID MessageID
- 0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
- // AbandonRequest,...
- ( byte ) 0xA0, 0x5A, // controls [0] Controls OPTIONAL }
- 0x30, 0x1A, // Control ::= SEQUENCE {
- // controlType LDAPOID,
- 0x04, 0x0D,
- '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1',
- // criticality BOOLEAN DEFAULT FALSE,
- 0x01, 0x01, ( byte ) 0xFF,
- // controlValue OCTET STRING OPTIONAL }
- 0x04, 0x06,
- 'a', 'b', 'c', 'd', 'e', 'f',
- 0x30, 0x17, // Control ::= SEQUENCE {
- // controlType LDAPOID,
- 0x04, 0x0D,
- '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
- // controlValue OCTET STRING OPTIONAL }
- 0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l',
- 0x30, 0x12, // Control ::= SEQUENCE {
- // controlType LDAPOID,
- 0x04, 0x0D,
- '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '3',
- // criticality BOOLEAN DEFAULT FALSE }
- 0x01, 0x01, ( byte ) 0xFF,
- 0x30, 0x0F, // Control ::= SEQUENCE {
- // controlType LDAPOID}
- 0x04, 0x0D,
- '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4'
- } );
+ { 0x30, 0x62, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x03, // messageID MessageID
+ 0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
+ // AbandonRequest,...
+ ( byte ) 0xA0, 0x5A, // controls [0] Controls OPTIONAL }
+ 0x30, 0x1A, // Control ::= SEQUENCE {
+ // controlType LDAPOID,
+ 0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1',
+ // criticality BOOLEAN DEFAULT FALSE,
+ 0x01, 0x01, ( byte ) 0xFF,
+ // controlValue OCTET STRING OPTIONAL }
+ 0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', 0x30, 0x17, // Control ::= SEQUENCE {
+ // controlType LDAPOID,
+ 0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+ // controlValue OCTET STRING OPTIONAL }
+ 0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l', 0x30, 0x12, // Control ::= SEQUENCE {
+ // controlType LDAPOID,
+ 0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '3',
+ // criticality BOOLEAN DEFAULT FALSE }
+ 0x01, 0x01, ( byte ) 0xFF, 0x30, 0x0F, // Control ::= SEQUENCE {
+ // controlType LDAPOID}
+ 0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4' } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -111,43 +102,53 @@ public class AbandonRequestTest
}
// Check that everything is OK
- AbandonRequestCodec abandonRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAbandonRequest();
+ InternalAbandonRequest abandonRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
+ .getInternalAbandonRequest();
+
+ // Copy the message
+ AbandonRequestCodec abandonRequestCodec = new AbandonRequestCodec();
+ abandonRequestCodec.setMessageId( abandonRequest.getMessageId() );
+ abandonRequestCodec.setAbandonedMessageId( abandonRequest.getAbandoned() );
assertEquals( 3, abandonRequest.getMessageId() );
- assertEquals( 2, abandonRequest.getAbandonedMessageId() );
+ assertEquals( 2, abandonRequest.getAbandoned() );
// Check the Controls
- List<Control> controls = abandonRequest.getControls();
+ Map<String, Control> controls = abandonRequest.getControls();
assertEquals( 4, controls.size() );
- Control control = abandonRequest.getControls( 0 );
+ Control control = controls.get( "1.3.6.1.5.5.1" );
assertEquals( "1.3.6.1.5.5.1", control.getOid() );
assertEquals( "0x61 0x62 0x63 0x64 0x65 0x66 ", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
assertTrue( control.isCritical() );
+ abandonRequestCodec.addControl( control );
- control = abandonRequest.getControls( 1 );
+ control = controls.get( "1.3.6.1.5.5.2" );
assertEquals( "1.3.6.1.5.5.2", control.getOid() );
assertEquals( "0x67 0x68 0x69 0x6A 0x6B 0x6C ", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
assertFalse( control.isCritical() );
+ abandonRequestCodec.addControl( control );
- control = abandonRequest.getControls( 2 );
+ control = controls.get( "1.3.6.1.5.5.3" );
assertEquals( "1.3.6.1.5.5.3", control.getOid() );
assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
assertTrue( control.isCritical() );
+ abandonRequestCodec.addControl( control );
- control = abandonRequest.getControls( 3 );
+ control = controls.get( "1.3.6.1.5.5.4" );
assertEquals( "1.3.6.1.5.5.4", control.getOid() );
assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
assertFalse( control.isCritical() );
+ abandonRequestCodec.addControl( control );
// Check the length
- assertEquals( 0x64, abandonRequest.computeLength() );
+ assertEquals( 0x64, abandonRequestCodec.computeLength() );
// Check the encoding
try
{
- ByteBuffer bb = abandonRequest.encode();
+ ByteBuffer bb = abandonRequestCodec.encode();
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -171,13 +172,11 @@ public class AbandonRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x0A );
stream.put( new byte[]
- {
- 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
- // messageID MessageID
- 0x02, 0x03, 0x00, ( byte ) 0x80, 0x13,
- 0x50, 0x01, 0x02 // CHOICE { ..., abandonRequest
- // AbandonRequest,...
- // AbandonRequest ::= [APPLICATION 16] MessageID
+ { 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
+ // messageID MessageID
+ 0x02, 0x03, 0x00, ( byte ) 0x80, 0x13, 0x50, 0x01, 0x02 // CHOICE { ..., abandonRequest
+ // AbandonRequest,...
+ // AbandonRequest ::= [APPLICATION 16] MessageID
} );
String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -198,18 +197,23 @@ public class AbandonRequestTest
}
// Check that everything is OK
- AbandonRequestCodec abandonRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAbandonRequest();
+ InternalAbandonRequest abandonRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
+ .getInternalAbandonRequest();
assertEquals( 32787, abandonRequest.getMessageId() );
- assertEquals( 2, abandonRequest.getAbandonedMessageId() );
+ assertEquals( 2, abandonRequest.getAbandoned() );
// Check the length
- assertEquals( 10, abandonRequest.computeLength() );
+ AbandonRequestCodec abandonRequestCodec = new AbandonRequestCodec();
+ abandonRequestCodec.setMessageId( abandonRequest.getMessageId() );
+ abandonRequestCodec.setAbandonedMessageId( abandonRequest.getAbandoned() );
+
+ assertEquals( 10, abandonRequestCodec.computeLength() );
// Check the encoding
try
{
- ByteBuffer bb = abandonRequest.encode();
+ ByteBuffer bb = abandonRequestCodec.encode();
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -233,11 +237,10 @@ public class AbandonRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x0A );
stream.put( new byte[]
- {
- 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x50, 0x00 // CHOICE { ..., abandonRequest AbandonRequest,...
- // AbandonRequest ::= [APPLICATION 16] MessageID
+ { 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x50, 0x00 // CHOICE { ..., abandonRequest AbandonRequest,...
+ // AbandonRequest ::= [APPLICATION 16] MessageID
} );
stream.flip();
@@ -259,6 +262,7 @@ public class AbandonRequestTest
fail( "We should not reach this point" );
}
+
/**
* Test the decoding of a AbandonRequest with a bad Message Id
*/
@@ -269,11 +273,10 @@ public class AbandonRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x0B );
stream.put( new byte[]
- {
- 0x30, 0x09, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x50, 0x01, (byte)0xFF // CHOICE { ..., abandonRequest AbandonRequest,...
- // AbandonRequest ::= [APPLICATION 16] MessageID
+ { 0x30, 0x09, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x50, 0x01, ( byte ) 0xFF // CHOICE { ..., abandonRequest AbandonRequest,...
+ // AbandonRequest ::= [APPLICATION 16] MessageID
} );
stream.flip();
Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java?rev=983534&r1=983533&r2=983534&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java Mon Aug 9 06:41:54 2010
@@ -37,6 +37,8 @@ import org.apache.directory.junit.tools.
import org.apache.directory.shared.asn1.ber.Asn1Decoder;
import org.apache.directory.shared.asn1.ber.IAsn1Container;
import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
import org.apache.directory.shared.ldap.entry.Entry;
@@ -48,7 +50,6 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.message.internal.InternalAddRequest;
import org.apache.directory.shared.ldap.message.internal.InternalMessage;
import org.apache.directory.shared.ldap.util.StringTools;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -179,7 +180,11 @@ public class AddRequestTest
}
// Check the length
- //assertEquals( 0x59, addRequest.computeLength() );
+ AddRequestCodec addRequestCodec = new AddRequestCodec();
+ addRequestCodec.setEntry( entry );
+ addRequestCodec.setMessageId( addRequest.getMessageId() );
+
+ assertEquals( 0x59, addRequestCodec.computeLength() );
}
@@ -657,14 +662,17 @@ public class AddRequestTest
assertEquals( "", value.getString() );
}
- /*
// Check the length
- assertEquals( 0x34, addRequest.computeLength() );
+ AddRequestCodec addRequestCodec = new AddRequestCodec();
+ addRequestCodec.setEntry( entry );
+ addRequestCodec.setMessageId( addRequest.getMessageId() );
+
+ assertEquals( 0x34, addRequestCodec.computeLength() );
// Check the encoding
try
{
- ByteBuffer bb = addRequest.encode();
+ ByteBuffer bb = addRequestCodec.encode();
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -675,7 +683,6 @@ public class AddRequestTest
ee.printStackTrace();
fail( ee.getMessage() );
}
- */
}
@@ -683,7 +690,6 @@ public class AddRequestTest
* Test the decoding of a AddRequest with a empty attributeList and a
* control
*/
- @Ignore
@Test
public void testDecodeAddRequestEmptyAttributeValueWithControl() throws NamingException
{
@@ -763,14 +769,18 @@ public class AddRequestTest
assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
- /*
// Check the length
- assertEquals( 0x51, addRequest.computeLength() );
+ AddRequestCodec addRequestCodec = new AddRequestCodec();
+ addRequestCodec.setEntry( entry );
+ addRequestCodec.setMessageId( addRequest.getMessageId() );
+ ( ( LdapMessageCodec ) addRequestCodec ).addControl( control );
+
+ assertEquals( 0x51, addRequestCodec.computeLength() );
// Check the encoding
try
{
- ByteBuffer bb = addRequest.encode();
+ ByteBuffer bb = addRequestCodec.encode();
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -781,6 +791,5 @@ public class AddRequestTest
ee.printStackTrace();
fail( ee.getMessage() );
}
- */
}
}
Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java?rev=983534&r1=983533&r2=983534&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java Mon Aug 9 06:41:54 2010
@@ -25,7 +25,7 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Map;
import org.apache.directory.junit.tools.Concurrent;
import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -38,6 +38,7 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.message.CompareResponseImpl;
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.message.internal.InternalCompareRequest;
import org.apache.directory.shared.ldap.message.internal.InternalMessage;
import org.apache.directory.shared.ldap.util.StringTools;
import org.junit.Test;
@@ -65,22 +66,22 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x38 );
stream.put( new byte[]
- {
- 0x30, 0x36, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x31, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
- // entry LDAPDN,
- 0x04, 0x20,
- 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
- // ava AttributeValueAssertion }
+ { 0x30,
+ 0x36, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E,
+ 0x31, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+ // ava AttributeValueAssertion }
0x30, 0x0D, // AttributeValueAssertion ::= SEQUENCE {
- // attributeDesc AttributeDescription,
- 0x04, 0x04, 't', 'e', 's', 't',
- // assertionValue AssertionValue }
- 0x04, 0x05, 'v', 'a', 'l', 'u', 'e'
- } );
+ // attributeDesc AttributeDescription,
+ 0x04, 0x04, 't', 'e', 's', 't',
+ // assertionValue AssertionValue }
+ 0x04, 0x05, 'v', 'a', 'l', 'u', 'e' } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -100,20 +101,27 @@ public class CompareRequestTest
}
// Ceck the decoded CompareRequest PDU
- CompareRequestCodec compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareRequest();
+ InternalCompareRequest compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
+ .getInternalCompareRequest();
assertEquals( 1, compareRequest.getMessageId() );
- assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getEntry().toString() );
- assertEquals( "test", compareRequest.getAttributeDesc() );
+ assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getName().toString() );
+ assertEquals( "test", compareRequest.getAttributeId() );
assertEquals( "value", compareRequest.getAssertionValue().toString() );
// Check the length
- assertEquals( 0x38, compareRequest.computeLength() );
+ CompareRequestCodec compareRequestCodec = new CompareRequestCodec();
+ compareRequestCodec.setMessageId( compareRequest.getMessageId() );
+ compareRequestCodec.setEntry( compareRequest.getName() );
+ compareRequestCodec.setAttributeDesc( compareRequest.getAttributeId() );
+ compareRequestCodec.setAssertionValue( compareRequest.getAssertionValue().get() );
+
+ assertEquals( 0x38, compareRequestCodec.computeLength() );
// Check the encoding
try
{
- ByteBuffer bb = compareRequest.encode();
+ ByteBuffer bb = compareRequestCodec.encode();
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -138,11 +146,10 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x07 );
stream.put( new byte[]
- {
- 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x00 // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ { 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E, 0x00 // CompareRequest ::= [APPLICATION 14] SEQUENCE {
} );
stream.flip();
@@ -174,19 +181,17 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x18 );
stream.put( new byte[]
- {
- 0x30, 0x16, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x11, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
- 0x04, 0x00, // entry LDAPDN,
- // ava AttributeValueAssertion }
- 0x30, 0x0D, // AttributeValueAssertion ::= SEQUENCE {
- // attributeDesc AttributeDescription,
- 0x04, 0x04, 't', 'e', 's', 't',
- // assertionValue AssertionValue }
- 0x04, 0x05, 'v', 'a', 'l', 'u', 'e'
- } );
+ { 0x30, 0x16, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E, 0x11, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ 0x04, 0x00, // entry LDAPDN,
+ // ava AttributeValueAssertion }
+ 0x30, 0x0D, // AttributeValueAssertion ::= SEQUENCE {
+ // attributeDesc AttributeDescription,
+ 0x04, 0x04, 't', 'e', 's', 't',
+ // assertionValue AssertionValue }
+ 0x04, 0x05, 'v', 'a', 'l', 'u', 'e' } );
stream.flip();
@@ -217,17 +222,18 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x2B );
stream.put( new byte[]
- {
- 0x30, 0x29, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x24, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
- // entry LDAPDN,
- 0x04, 0x20,
- 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
- // ava AttributeValueAssertion }
- 0x30, 0x00 // AttributeValueAssertion ::= SEQUENCE {
+ { 0x30,
+ 0x29, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E,
+ 0x24, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+ // ava AttributeValueAssertion }
+ 0x30, 0x00 // AttributeValueAssertion ::= SEQUENCE {
} );
stream.flip();
@@ -247,6 +253,7 @@ public class CompareRequestTest
}
}
+
/**
* Test the decoding of an empty ava
*/
@@ -258,17 +265,18 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x2B );
stream.put( new byte[]
- {
- 0x30, 0x29, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x24, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
- // entry LDAPDN,
- 0x04, 0x20,
- 'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
- // ava AttributeValueAssertion }
- 0x30, 0x00 // AttributeValueAssertion ::= SEQUENCE {
+ { 0x30,
+ 0x29, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E,
+ 0x24, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x20, 'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+ // ava AttributeValueAssertion }
+ 0x30, 0x00 // AttributeValueAssertion ::= SEQUENCE {
} );
stream.flip();
@@ -285,9 +293,10 @@ public class CompareRequestTest
catch ( DecoderException de )
{
assertTrue( de instanceof ResponseCarryingException );
- InternalMessage response = ((ResponseCarryingException)de).getResponse();
+ InternalMessage response = ( ( ResponseCarryingException ) de ).getResponse();
assertTrue( response instanceof CompareResponseImpl );
- assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ((CompareResponseImpl)response).getLdapResult().getResultCode() );
+ assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ( ( CompareResponseImpl ) response ).getLdapResult()
+ .getResultCode() );
return;
}
}
@@ -304,19 +313,19 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x2D );
stream.put( new byte[]
- {
- 0x30, 0x2B, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x26, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
- // entry LDAPDN,
- 0x04, 0x20,
- 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ { 0x30,
+ 0x2B, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E,
+ 0x26, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
- // ava AttributeValueAssertion }
- 0x30, 0x02, // AttributeValueAssertion ::= SEQUENCE {
- 0x04, 0x00
- } );
+ // ava AttributeValueAssertion }
+ 0x30, 0x02, // AttributeValueAssertion ::= SEQUENCE {
+ 0x04, 0x00 } );
stream.flip();
@@ -332,9 +341,10 @@ public class CompareRequestTest
catch ( DecoderException de )
{
assertTrue( de instanceof ResponseCarryingException );
- InternalMessage response = ((ResponseCarryingException)de).getResponse();
+ InternalMessage response = ( ( ResponseCarryingException ) de ).getResponse();
assertTrue( response instanceof CompareResponseImpl );
- assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ((CompareResponseImpl)response).getLdapResult().getResultCode() );
+ assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ( ( CompareResponseImpl ) response ).getLdapResult()
+ .getResultCode() );
return;
}
}
@@ -351,22 +361,22 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x33 );
stream.put( new byte[]
- {
- 0x30, 0x31, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x2C, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
- // entry LDAPDN,
- 0x04, 0x20,
- 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
- // ava AttributeValueAssertion }
- 0x30, 0x08, // AttributeValueAssertion ::= SEQUENCE {
- // attributeDesc AttributeDescription,
- 0x04, 0x04, 't', 'e', 's', 't',
- // assertionValue AssertionValue }
- 0x04, 0x00
- } );
+ { 0x30,
+ 0x31, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E,
+ 0x2C, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+ // ava AttributeValueAssertion }
+ 0x30, 0x08, // AttributeValueAssertion ::= SEQUENCE {
+ // attributeDesc AttributeDescription,
+ 0x04, 0x04, 't', 'e', 's', 't',
+ // assertionValue AssertionValue }
+ 0x04, 0x00 } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -386,20 +396,27 @@ public class CompareRequestTest
}
// Check the decoded CompareRequest PDU
- CompareRequestCodec compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareRequest();
+ InternalCompareRequest compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
+ .getInternalCompareRequest();
assertEquals( 1, compareRequest.getMessageId() );
- assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getEntry().toString() );
- assertEquals( "test", compareRequest.getAttributeDesc() );
+ assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getName().toString() );
+ assertEquals( "test", compareRequest.getAttributeId() );
assertEquals( "", compareRequest.getAssertionValue().toString() );
// Check the length
- assertEquals( 0x33, compareRequest.computeLength() );
+ CompareRequestCodec compareRequestCodec = new CompareRequestCodec();
+ compareRequestCodec.setMessageId( compareRequest.getMessageId() );
+ compareRequestCodec.setEntry( compareRequest.getName() );
+ compareRequestCodec.setAttributeDesc( compareRequest.getAttributeId() );
+ compareRequestCodec.setAssertionValue( compareRequest.getAssertionValue().get() );
+
+ assertEquals( 0x33, compareRequestCodec.computeLength() );
// Check the encoding
try
{
- ByteBuffer bb = compareRequest.encode();
+ ByteBuffer bb = compareRequestCodec.encode();
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -424,25 +441,28 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x55 );
stream.put( new byte[]
- {
- 0x30, 0x53, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x31, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
- // entry LDAPDN,
- 0x04, 0x20,
- 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
- // ava AttributeValueAssertion }
- 0x30, 0x0D, // AttributeValueAssertion ::= SEQUENCE {
- // attributeDesc AttributeDescription,
- 0x04, 0x04, 't', 'e', 's', 't',
- // assertionValue AssertionValue }
- 0x04, 0x05, 'v', 'a', 'l', 'u', 'e',
- ( byte ) 0xA0, 0x1B, // A control
+ {
+ 0x30,
+ 0x53, // LDAPMessage ::= SEQUENCE {
+ 0x02,
+ 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E,
+ 0x31, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+ // ava AttributeValueAssertion }
+ 0x30,
+ 0x0D, // AttributeValueAssertion ::= SEQUENCE {
+ // attributeDesc AttributeDescription,
+ 0x04, 0x04, 't', 'e', 's', 't',
+ // assertionValue AssertionValue }
+ 0x04, 0x05, 'v', 'a', 'l', 'u', 'e', ( byte ) 0xA0,
+ 0x1B, // A control
0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31,
- 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32
- } );
+ 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -462,29 +482,37 @@ public class CompareRequestTest
}
// Ceck the decoded CompareRequest PDU
- CompareRequestCodec compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareRequest();
+ InternalCompareRequest compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
+ .getInternalCompareRequest();
assertEquals( 1, compareRequest.getMessageId() );
- assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getEntry().toString() );
- assertEquals( "test", compareRequest.getAttributeDesc() );
+ assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getName().toString() );
+ assertEquals( "test", compareRequest.getAttributeId() );
assertEquals( "value", compareRequest.getAssertionValue().toString() );
// Check the Control
- List<Control> controls = compareRequest.getControls();
+ Map<String, Control> controls = compareRequest.getControls();
assertEquals( 1, controls.size() );
- Control control = compareRequest.getControls( 0 );
+ Control control = controls.get( "2.16.840.1.113730.3.4.2" );
assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
// Check the length
- assertEquals( 0x55, compareRequest.computeLength() );
+ CompareRequestCodec compareRequestCodec = new CompareRequestCodec();
+ compareRequestCodec.setMessageId( compareRequest.getMessageId() );
+ compareRequestCodec.setEntry( compareRequest.getName() );
+ compareRequestCodec.setAttributeDesc( compareRequest.getAttributeId() );
+ compareRequestCodec.setAssertionValue( compareRequest.getAssertionValue().get() );
+ compareRequestCodec.addControl( control );
+
+ assertEquals( 0x55, compareRequestCodec.computeLength() );
// Check the encoding
try
{
- ByteBuffer bb = compareRequest.encode();
+ ByteBuffer bb = compareRequestCodec.encode();
String encodedPdu = StringTools.dumpBytes( bb.array() );
Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java?rev=983534&r1=983533&r2=983534&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java Mon Aug 9 06:41:54 2010
@@ -25,7 +25,7 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Map;
import org.apache.directory.junit.tools.Concurrent;
import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -33,11 +33,13 @@ import org.apache.directory.shared.asn1.
import org.apache.directory.shared.asn1.ber.IAsn1Container;
import org.apache.directory.shared.asn1.codec.DecoderException;
import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
import org.apache.directory.shared.ldap.message.DeleteResponseImpl;
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.message.internal.InternalDeleteRequest;
import org.apache.directory.shared.ldap.message.internal.InternalMessage;
import org.apache.directory.shared.ldap.util.StringTools;
import org.junit.Test;
@@ -64,15 +66,15 @@ public class DelRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x27 );
stream.put( new byte[]
- {
- 0x30, 0x25, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., delRequest DelRequest, ...
- // DelRequest ::= [APPLICATION 10] LDAPDN;
- 0x4A, 0x20,
- 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm'
- } );
+ { 0x30,
+ 0x25, // LDAPMessage ::= SEQUENCE {
+ 0x02,
+ 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., delRequest DelRequest, ...
+ // DelRequest ::= [APPLICATION 10] LDAPDN;
+ 0x4A, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -92,18 +94,22 @@ public class DelRequestTest
}
// Check the decoded DelRequest PDU
- DelRequestCodec delRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getDelRequest();
+ InternalDeleteRequest delRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getInternalDeleteRequest();
assertEquals( 1, delRequest.getMessageId() );
- assertEquals( "cn=testModify,ou=users,ou=system", delRequest.getEntry().toString() );
+ assertEquals( "cn=testModify,ou=users,ou=system", delRequest.getName().toString() );
// Check the length
- assertEquals( 0x27, delRequest.computeLength() );
+ DelRequestCodec delRequestCodec = new DelRequestCodec();
+ delRequestCodec.setEntry( delRequest.getName() );
+ delRequestCodec.setMessageId( delRequest.getMessageId() );
+
+ assertEquals( 0x27, delRequestCodec.computeLength() );
// Check the encoding
try
{
- ByteBuffer bb = delRequest.encode();
+ ByteBuffer bb = delRequestCodec.encode();
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -116,6 +122,7 @@ public class DelRequestTest
}
}
+
/**
* Test the decoding of a full DelRequest
*/
@@ -127,15 +134,15 @@ public class DelRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x27 );
stream.put( new byte[]
- {
- 0x30, 0x25, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., delRequest DelRequest, ...
- // DelRequest ::= [APPLICATION 10] LDAPDN;
- 0x4A, 0x20,
- 'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm'
- } );
+ { 0x30,
+ 0x25, // LDAPMessage ::= SEQUENCE {
+ 0x02,
+ 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., delRequest DelRequest, ...
+ // DelRequest ::= [APPLICATION 10] LDAPDN;
+ 0x4A, 0x20, 'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' } );
stream.flip();
@@ -150,15 +157,17 @@ public class DelRequestTest
catch ( DecoderException de )
{
assertTrue( de instanceof ResponseCarryingException );
- InternalMessage response = ((ResponseCarryingException)de).getResponse();
+ InternalMessage response = ( ( ResponseCarryingException ) de ).getResponse();
assertTrue( response instanceof DeleteResponseImpl );
- assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ((DeleteResponseImpl)response).getLdapResult().getResultCode() );
+ assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ( ( DeleteResponseImpl ) response ).getLdapResult()
+ .getResultCode() );
return;
}
fail( "We should not reach this point" );
}
+
/**
* Test the decoding of an empty DelRequest
*/
@@ -170,12 +179,11 @@ public class DelRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x07 );
stream.put( new byte[]
- {
- 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., delRequest DelRequest, ...
- // DelRequest ::= [APPLICATION 10] LDAPDN;
- 0x4A, 0x00 // Empty DN
+ { 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., delRequest DelRequest, ...
+ // DelRequest ::= [APPLICATION 10] LDAPDN;
+ 0x4A, 0x00 // Empty DN
} );
stream.flip();
@@ -208,17 +216,18 @@ public class DelRequestTest
stream.put( new byte[]
{
- 0x30, 0x42, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., delRequest DelRequest, ...
- // DelRequest ::= [APPLICATION 10] LDAPDN;
- 0x4A, 0x20,
- 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
- ( byte ) 0xA0, 0x1B, // A control
+ 0x30,
+ 0x42, // LDAPMessage ::= SEQUENCE {
+ 0x02,
+ 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., delRequest DelRequest, ...
+ // DelRequest ::= [APPLICATION 10] LDAPDN;
+ 0x4A, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', ( byte ) 0xA0,
+ 0x1B, // A control
0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31,
- 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32
- } );
+ 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -238,27 +247,32 @@ public class DelRequestTest
}
// Check the decoded DelRequest PDU
- DelRequestCodec delRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getDelRequest();
+ InternalDeleteRequest delRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getInternalDeleteRequest();
assertEquals( 1, delRequest.getMessageId() );
- assertEquals( "cn=testModify,ou=users,ou=system", delRequest.getEntry().toString() );
-
- // Check the length
- assertEquals( 0x44, delRequest.computeLength() );
+ assertEquals( "cn=testModify,ou=users,ou=system", delRequest.getName().toString() );
// Check the Control
- List<Control> controls = delRequest.getControls();
+ Map<String, Control> controls = delRequest.getControls();
assertEquals( 1, controls.size() );
- Control control = delRequest.getControls( 0 );
+ Control control = controls.get( "2.16.840.1.113730.3.4.2" );
assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
+ // Check the length
+ DelRequestCodec delRequestCodec = new DelRequestCodec();
+ delRequestCodec.setEntry( delRequest.getName() );
+ delRequestCodec.setMessageId( delRequest.getMessageId() );
+ ( ( LdapMessageCodec ) delRequestCodec ).addControl( control );
+
+ assertEquals( 0x44, delRequestCodec.computeLength() );
+
// Check the encoding
try
{
- ByteBuffer bb = delRequest.encode();
+ ByteBuffer bb = delRequestCodec.encode();
String encodedPdu = StringTools.dumpBytes( bb.array() );
Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/unbind/UnBindRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/unbind/UnBindRequestTest.java?rev=983534&r1=983533&r2=983534&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/unbind/UnBindRequestTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/codec/unbind/UnBindRequestTest.java Mon Aug 9 06:41:54 2010
@@ -25,7 +25,7 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Map;
import org.apache.directory.junit.tools.Concurrent;
import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -33,9 +33,9 @@ import org.apache.directory.shared.asn1.
import org.apache.directory.shared.asn1.ber.IAsn1Container;
import org.apache.directory.shared.asn1.codec.DecoderException;
import org.apache.directory.shared.asn1.codec.EncoderException;
-import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.message.internal.InternalUnbindRequest;
import org.apache.directory.shared.ldap.util.StringTools;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,11 +58,10 @@ public class UnBindRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x07 );
stream.put( new byte[]
- {
- 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x42, 0x00, // CHOICE { ..., unbindRequest UnbindRequest,...
- // UnbindRequest ::= [APPLICATION 2] NULL
+ { 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x42, 0x00, // CHOICE { ..., unbindRequest UnbindRequest,...
+ // UnbindRequest ::= [APPLICATION 2] NULL
} );
String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -81,16 +80,20 @@ public class UnBindRequestTest
fail( de.getMessage() );
}
- LdapMessageCodec ldapMessage = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ InternalUnbindRequest unbindRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
+ .getInternalUnbindRequest();
- assertEquals( 1, ldapMessage.getMessageId() );
+ assertEquals( 1, unbindRequest.getMessageId() );
// Check the length
- assertEquals( 7, ldapMessage.computeLength() );
+ UnBindRequestCodec unbindRequestCodec = new UnBindRequestCodec();
+ unbindRequestCodec.setMessageId( unbindRequest.getMessageId() );
+
+ assertEquals( 7, unbindRequestCodec.computeLength() );
try
{
- ByteBuffer bb = ldapMessage.encode();
+ ByteBuffer bb = unbindRequestCodec.encode();
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -114,17 +117,17 @@ public class UnBindRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x24 );
stream.put( new byte[]
- {
- 0x30, 0x22, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x42, 0x00, // CHOICE { ..., unbindRequest UnbindRequest,...
- // UnbindRequest ::= [APPLICATION 2] NULL
- ( byte ) 0xA0, 0x1B, // A control
- 0x30, 0x19,
- 0x04, 0x17,
- '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7',
- '3', '0', '.', '3', '.', '4', '.', '2'
- } );
+ { 0x30,
+ 0x22, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ 0x42,
+ 0x00, // CHOICE { ..., unbindRequest UnbindRequest,...
+ // UnbindRequest ::= [APPLICATION 2] NULL
+ ( byte ) 0xA0,
+ 0x1B, // A control
+ 0x30, 0x19, 0x04, 0x17, '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3',
+ '0', '.', '3', '.', '4', '.', '2' } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -142,25 +145,30 @@ public class UnBindRequestTest
fail( de.getMessage() );
}
- LdapMessageCodec ldapMessage = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ InternalUnbindRequest unbindRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
+ .getInternalUnbindRequest();
- assertEquals( 1, ldapMessage.getMessageId() );
+ assertEquals( 1, unbindRequest.getMessageId() );
// Check the Control
- List<Control> controls = ldapMessage.getControls();
+ Map<String, Control> controls = unbindRequest.getControls();
assertEquals( 1, controls.size() );
- Control control = ldapMessage.getControls( 0 );
+ Control control = controls.get( "2.16.840.1.113730.3.4.2" );
assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
// Check the length
- assertEquals( 0x24, ldapMessage.computeLength() );
+ UnBindRequestCodec unbindRequestCodec = new UnBindRequestCodec();
+ unbindRequestCodec.setMessageId( unbindRequest.getMessageId() );
+ unbindRequestCodec.addControl( control );
+
+ assertEquals( 0x24, unbindRequestCodec.computeLength() );
try
{
- ByteBuffer bb = ldapMessage.encode();
+ ByteBuffer bb = unbindRequestCodec.encode();
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -184,11 +192,10 @@ public class UnBindRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x09 );
stream.put( new byte[]
- {
- 0x30, 0x07, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x42, 0x02, // CHOICE { ..., unbindRequest UnbindRequest,...
- 0x04, 0x00 // UnbindRequest ::= [APPLICATION 2] NULL
+ { 0x30, 0x07, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x42, 0x02, // CHOICE { ..., unbindRequest UnbindRequest,...
+ 0x04, 0x00 // UnbindRequest ::= [APPLICATION 2] NULL
} );
Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/AddRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/AddRequestImplTest.java?rev=983534&r1=983533&r2=983534&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/AddRequestImplTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/AddRequestImplTest.java Mon Aug 9 06:41:54 2010
@@ -331,6 +331,12 @@ public class AddRequestImplTest
{
return null;
}
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
};
AddRequestImpl req1 = new AddRequestImpl( 5 );
Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/BindRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/BindRequestImplTest.java?rev=983534&r1=983533&r2=983534&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/BindRequestImplTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/BindRequestImplTest.java Mon Aug 9 06:41:54 2010
@@ -50,6 +50,7 @@ public class BindRequestImplTest
{
private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
/**
* Tests the same object referrence for equality.
*/
@@ -351,6 +352,12 @@ public class BindRequestImplTest
{
return false;
}
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
};
BindRequestImpl req1 = new BindRequestImpl( 5 );
Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/CompareRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/CompareRequestImplTest.java?rev=983534&r1=983533&r2=983534&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/CompareRequestImplTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/CompareRequestImplTest.java Mon Aug 9 06:41:54 2010
@@ -50,6 +50,7 @@ public class CompareRequestImplTest
{
private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
/**
* Tests the same object reference for equality.
*/
@@ -305,6 +306,12 @@ public class CompareRequestImplTest
{
return false;
}
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
};
CompareRequestImpl req1 = new CompareRequestImpl( 5 );
Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/DeleteRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/DeleteRequestImplTest.java?rev=983534&r1=983533&r2=983534&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/DeleteRequestImplTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/DeleteRequestImplTest.java Mon Aug 9 06:41:54 2010
@@ -49,6 +49,7 @@ public class DeleteRequestImplTest
{
private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
/**
* Tests the same object reference for equality.
*/
@@ -238,6 +239,12 @@ public class DeleteRequestImplTest
{
return false;
}
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
};
DeleteRequestImpl req1 = new DeleteRequestImpl( 5 );
Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedRequestImplTest.java?rev=983534&r1=983533&r2=983534&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedRequestImplTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedRequestImplTest.java Mon Aug 9 06:41:54 2010
@@ -50,6 +50,7 @@ public class ExtendedRequestImplTest
{
private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
/**
* Tests the same object reference for equality.
*/
@@ -213,7 +214,7 @@ public class ExtendedRequestImplTest
}
- public Map<String,Control> getControls()
+ public Map<String, Control> getControls()
{
return EMPTY_CONTROL_MAP;
}
@@ -281,6 +282,12 @@ public class ExtendedRequestImplTest
{
return false;
}
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
};
ExtendedRequestImpl req1 = new ExtendedRequestImpl( 5 );
Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedResponseImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedResponseImplTest.java?rev=983534&r1=983533&r2=983534&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedResponseImplTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedResponseImplTest.java Mon Aug 9 06:41:54 2010
@@ -49,6 +49,7 @@ 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.
*
@@ -61,7 +62,7 @@ public class ExtendedResponseImplTest
response.setResponse( "Hello World!".getBytes() );
response.setResponseName( "1.1.1.1" );
InternalLdapResult result = response.getLdapResult();
-
+
try
{
result.setMatchedDn( new DN( "dc=example,dc=com" ) );
@@ -70,7 +71,7 @@ public class ExtendedResponseImplTest
{
// Do nothing
}
-
+
result.setResultCode( ResultCodeEnum.SUCCESS );
ReferralImpl refs = new ReferralImpl();
refs.addLdapUrl( "ldap://someserver.com" );
@@ -142,16 +143,16 @@ public class ExtendedResponseImplTest
public InternalLdapResult getLdapResult()
{
LdapResultImpl result = new LdapResultImpl();
-
- try
+
+ try
{
result.setMatchedDn( new DN( "dc=example,dc=com" ) );
}
- catch ( LdapException ine )
+ catch ( LdapException ine )
{
// do nothing
}
-
+
result.setResultCode( ResultCodeEnum.SUCCESS );
ReferralImpl refs = new ReferralImpl();
refs.addLdapUrl( "ldap://someserver.com" );
@@ -224,6 +225,12 @@ public class ExtendedResponseImplTest
{
return false;
}
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
};
assertTrue( resp0.equals( resp1 ) );
Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImplTest.java?rev=983534&r1=983533&r2=983534&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImplTest.java (original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImplTest.java Mon Aug 9 06:41:54 2010
@@ -50,6 +50,7 @@ public class ModifyDnRequestImplTest
{
private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String, Control>();
+
/**
* Constructs a ModifyDnrequest to test.
*
@@ -60,7 +61,7 @@ public class ModifyDnRequestImplTest
// Construct the ModifyDn request to test
ModifyDnRequestImpl request = new ModifyDnRequestImpl( 45 );
request.setDeleteOldRdn( true );
-
+
try
{
request.setName( new DN( "dc=admins,dc=apache,dc=org" ) );
@@ -71,7 +72,7 @@ public class ModifyDnRequestImplTest
{
// do nothing
}
-
+
return request;
}
@@ -118,40 +119,40 @@ public class ModifyDnRequestImplTest
/**
* Tests the same object reference for equal hashCode
*/
- @Test
- public void testHashCodeSameObj()
- {
- ModifyDnRequestImpl req = new ModifyDnRequestImpl( 5 );
- assertTrue( req.hashCode() == req.hashCode() );
- }
+ @Test
+ public void testHashCodeSameObj()
+ {
+ ModifyDnRequestImpl req = new ModifyDnRequestImpl( 5 );
+ assertTrue( req.hashCode() == req.hashCode() );
+ }
- /**
- * Tests for equal hashCode using exact copies.
- */
- @Test
- public void testHashCodeExactCopy0()
- {
- ModifyDnRequestImpl req0 = getRequest();
- ModifyDnRequestImpl req1 = getRequest();
+ /**
+ * Tests for equal hashCode using exact copies.
+ */
+ @Test
+ public void testHashCodeExactCopy0()
+ {
+ ModifyDnRequestImpl req0 = getRequest();
+ ModifyDnRequestImpl req1 = getRequest();
- assertTrue( req0.hashCode() == req1.hashCode() );
- }
+ assertTrue( req0.hashCode() == req1.hashCode() );
+ }
- /**
- * Tests for equal hashCode using exact copies.
- */
- @Test
- public void testHashCodeExactCopy1()
- {
- ModifyDnRequestImpl req0 = getRequest();
- req0.setNewSuperior( null );
- ModifyDnRequestImpl req1 = getRequest();
- req1.setNewSuperior( null );
+ /**
+ * Tests for equal hashCode using exact copies.
+ */
+ @Test
+ public void testHashCodeExactCopy1()
+ {
+ ModifyDnRequestImpl req0 = getRequest();
+ req0.setNewSuperior( null );
+ ModifyDnRequestImpl req1 = getRequest();
+ req1.setNewSuperior( null );
- assertTrue( req0.hashCode() == req1.hashCode() );
- }
+ assertTrue( req0.hashCode() == req1.hashCode() );
+ }
/**
@@ -397,6 +398,12 @@ public class ModifyDnRequestImplTest
{
return false;
}
+
+
+ public Control getCurrentControl()
+ {
+ return null;
+ }
};
ModifyDnRequestImpl req1 = getRequest();