* Test the decoding of a ModifyRequest, with different operations
*/
@Test
public void testDecodeModifyRequestManyOperations() throws LdapException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x18C );
stream.put( new byte[]
{ 0x30, ( byte ) 0x81, ( byte ) 0x89, 0x02, 0x01, 0x15, 0x66,
0x67,
0x04,
0x2B, // ModifyRequest object : cn=Tori Amos,ou=playground,dc=apache,dc=org
'c', 'n', '=', 'T', 'o', 'r', 'i', ' ', 'A', 'm', 'o', 's', ',', 'o', 'u', '=', 'p', 'l', 'a', 'y',
'g', 'r', 'o', 'u', 'n', 'd', ',', 'd', 'c', '=', 'a', 'p', 'a', 'c', 'h', 'e', ',', 'd', 'c', '=',
'o', 'r', 'g', 0x30,
0x38, // Modifications
0x30,
0x24, // Modification
0x0A, 0x01,
0x00, // Operation = ADD
0x30,
0x1F, // type : telephoneNumber
0x04, 0x0F, 't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r', 0x31,
0x0C, // vals : 1234567890
0x04, 0x0A, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0x30,
0x10, // Modification
0x0A, 0x01,
0x02, // Operation = REPLACE
0x30,
0x0B, // type : cn
0x04, 0x02, 'c', 'n', 0x31,
0x05, // vals : XXX
0x04, 0x03, 'X', 'X', 'X', ( byte ) 0xA0,
0x1B, // Control : 2.16.840.1.113730.3.4.2
0x30, 0x19, 0x04, 0x17, '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3',
'0', '.', '3', '.', '4', '.', '2' } );
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<ModifyRequestDecorator> ldapMessageContainer =
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
try
{
ldapDecoder.decode( stream, ldapMessageContainer );
}
catch ( DecoderException de )
{
de.printStackTrace();
fail( de.getMessage() );
}
// Check the decoded PDU
ModifyRequest modifyRequest = ldapMessageContainer.getMessage();
assertEquals( 21, modifyRequest.getMessageId() );
assertEquals( "cn=Tori Amos,ou=playground,dc=apache,dc=org", modifyRequest.getName().toString() );
Object[] modifications = modifyRequest.getModifications().toArray();
assertEquals( 2, modifications.length );
Modification modification = ( Modification ) modifications[0];
Attribute attributeValue = modification.getAttribute();
assertEquals( "telephonenumber", Strings.toLowerCase( attributeValue.getId() ) );
String attrValue = attributeValue.getString();
assertEquals( "1234567890", attrValue );
modification = ( Modification ) modifications[1];
attributeValue = modification.getAttribute();
assertEquals( "cn", Strings.toLowerCase( attributeValue.getUpId() ) );
attrValue = attributeValue.getString();
assertEquals( "XXX", attrValue );
// Check the encoding, by decoding and re-encoding the result
try
{
ByteBuffer bb = encoder.encodeMessage( modifyRequest );
// Check the length
assertEquals( 0x8C, bb.limit() );
String decodedPdu1 = Strings.dumpBytes(bb.array());
try
{
ldapDecoder.decode( bb, ldapMessageContainer );
}
catch ( DecoderException de )
{
de.printStackTrace();
fail( de.getMessage() );