use of org.apache.directory.api.ldap.codec.decorators.UnbindRequestDecorator in project directory-ldap-api by apache.
the class UnBindRequestTest method testDecodeUnBindRequestNoControls.
/**
* Test the decoding of a UnBindRequest with no controls
*/
@Test
public void testDecodeUnBindRequestNoControls() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x07);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x05, 0x02, 0x01, // messageID MessageID
0x01, 0x42, // CHOICE { ..., unbindRequest UnbindRequest,...
0x00 // UnbindRequest ::= [APPLICATION 2] NULL
});
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a BindRequest Container
LdapMessageContainer<UnbindRequestDecorator> ldapMessageContainer = new LdapMessageContainer<UnbindRequestDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
UnbindRequest unbindRequest = ldapMessageContainer.getMessage();
assertEquals(1, unbindRequest.getMessageId());
// Check the encoding
UnbindRequest internalUnbindRequest = new UnbindRequestImpl();
internalUnbindRequest.setMessageId(unbindRequest.getMessageId());
try {
ByteBuffer bb = encoder.encodeMessage(internalUnbindRequest);
// Check the length
assertEquals(0x07, bb.limit());
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
Aggregations