use of org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelDecoder in project directory-ldap-api by apache.
the class CancelRequestTest method testDecodeCancelBadCancelId.
/**
* Test a Cancel message with a bad cancelId
*/
@Test
public void testDecodeCancelBadCancelId() {
Asn1Decoder cancelDecoder = new CancelDecoder();
ByteBuffer stream = ByteBuffer.allocate(0x08);
stream.put(new byte[] { 0x30, 0x06, 0x02, 0x04, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }).flip();
// Allocate a Cancel Container
Asn1Container cancelContainer = new CancelContainer();
// Decode a Cancel message
try {
cancelDecoder.decode(stream, cancelContainer);
fail("CancelID expected");
} catch (DecoderException de) {
assertTrue(true);
}
}
use of org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelDecoder 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());
}
}
use of org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelDecoder in project directory-ldap-api by apache.
the class CancelRequestTest method testDecodeCancelEmptyCancelId.
/**
* Test a Cancel message with an empty cancelId
*/
@Test
public void testDecodeCancelEmptyCancelId() {
Asn1Decoder cancelDecoder = new CancelDecoder();
ByteBuffer stream = ByteBuffer.allocate(0x04);
stream.put(new byte[] { 0x30, 0x02, 0x02, 0x00 }).flip();
// Allocate a Cancel Container
Asn1Container cancelContainer = new CancelContainer();
// Decode a Cancel message
try {
cancelDecoder.decode(stream, cancelContainer);
fail("CancelID expected");
} catch (DecoderException de) {
assertTrue(true);
}
}
use of org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelDecoder in project directory-ldap-api by apache.
the class CancelRequestTest method testDecodeCancelMoreThanOneCancelId.
/**
* Test a Cancel message with more than one cancelId
*/
@Test
public void testDecodeCancelMoreThanOneCancelId() {
Asn1Decoder cancelDecoder = new CancelDecoder();
ByteBuffer stream = ByteBuffer.allocate(0x08);
stream.put(new byte[] { 0x30, 0x06, 0x02, 0x01, 0x01, 0x02, 0x01, 0x02 }).flip();
// Allocate a Cancel Container
Asn1Container cancelContainer = new CancelContainer();
// Decode a Cancel message
try {
cancelDecoder.decode(stream, cancelContainer);
fail("CancelID expected");
} catch (DecoderException de) {
assertTrue(true);
}
}
use of org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelDecoder in project directory-ldap-api by apache.
the class CancelRequestTest method testDecodeCancelNoCancelId.
/**
* Test a Cancel message with no cancelId
*/
@Test
public void testDecodeCancelNoCancelId() {
Asn1Decoder cancelDecoder = new CancelDecoder();
ByteBuffer stream = ByteBuffer.allocate(0x02);
stream.put(new byte[] { 0x30, 0x00 }).flip();
// Allocate a Cancel Container
Asn1Container cancelContainer = new CancelContainer();
// Decode a Cancel message
try {
cancelDecoder.decode(stream, cancelContainer);
fail("CancelID expected");
} catch (DecoderException de) {
assertTrue(true);
}
}
Aggregations