{
de.printStackTrace();
fail( de.getMessage() );
}
AddRequest addRequest = container.getMessage();
// Check the decoded message
assertEquals( 1, addRequest.getMessageId() );
assertEquals( "cn=testModify,ou=users,ou=system", addRequest.getEntryDn().toString() );
Entry entry = addRequest.getEntry();
assertEquals( 2, entry.size() );
Set<String> expectedTypes = new HashSet<String>();
expectedTypes.add( "l" );
expectedTypes.add( "attrs" );
Map<String, Set<String>> typesVals = new HashMap<String, Set<String>>();
Set<String> lVal1 = new HashSet<String>();
lVal1.add( "Paris" );
typesVals.put( "l", lVal1 );
Set<String> lVal2 = new HashSet<String>();
lVal2.add( "test1" );
lVal2.add( "test2" );
lVal2.add( "test3" );
typesVals.put( "attrs", lVal2 );
Attribute attribute = entry.get( "l" );
assertTrue( expectedTypes.contains( Strings.toLowerCase( attribute.getId() ) ) );
Set<String> vals = ( Set<String> ) typesVals.get( Strings.toLowerCase( attribute.getId() ) );
for ( Value<?> value : attribute )
{
assertTrue( vals.contains( value.getValue() ) );
vals.remove( value.getValue() );
}
attribute = entry.get( "attrs" );
assertTrue( expectedTypes.contains( Strings.toLowerCase( attribute.getId() ) ) );
vals = ( Set<String> ) typesVals.get( Strings.toLowerCase( attribute.getId() ) );
for ( Value<?> value : attribute )
{
assertTrue( vals.contains( value.getValue() ) );
vals.remove( value.getValue() );
}
// Check the encoding
try
{
ByteBuffer bb = encoder.encodeMessage( addRequest );
// Check the length
assertEquals( 0x59, bb.limit() );
// We cannot compare the PDU, as the attributes order is not
// kept. Let's decode again and compare the resulting AddRequest
try
{
ldapDecoder.decode( bb, container );
}
catch ( DecoderException de )
{
de.printStackTrace();
fail( de.getMessage() );
}
AddRequest addRequest2 = container.getMessage();
assertEquals( addRequest, addRequest2 );
}
catch ( EncoderException ee )
{
ee.printStackTrace();