use of org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelRequestDecorator in project directory-ldap-api by apache.
the class CancelRequestTest method testDecodeCancel.
/**
* Test the normal Cancel message
*/
@Test
public void testDecodeCancel() {
Asn1Decoder cancelDecoder = new CancelDecoder();
ByteBuffer stream = ByteBuffer.allocate(0x05);
stream.put(new byte[] { 0x30, 0x03, 0x02, 0x01, 0x01 }).flip();
String decodedPdu = Strings.dumpBytes(stream.array());
// Allocate a Cancel Container
Asn1Container cancelContainer = new CancelContainer();
// Decode a Cancel message
try {
cancelDecoder.decode(stream, cancelContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
CancelRequestDecorator cancel = ((CancelContainer) cancelContainer).getCancel();
assertEquals(1, cancel.getCancelId());
// Check the encoding
try {
ByteBuffer bb = cancel.encodeInternal();
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
Aggregations