use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class GracefulShutdownTest method testDecodeGracefulShutdownDelay32768.
/**
* Test the decoding of a GracefulShutdown with a delay above 32768
*/
@Test
public void testDecodeGracefulShutdownDelay32768() {
Asn1Decoder decoder = new Asn1Decoder();
ByteBuffer bb = ByteBuffer.allocate(0x07);
bb.put(new byte[] { // GracefulShutdown ::= SEQUENCE {
0x30, // GracefulShutdown ::= SEQUENCE {
0x05, (byte) 0x80, 0x03, 0x00, (byte) 0x80, // delay
(byte) 0x00 // INTEGER
// (0..86400)
// DEFAULT
// 0
});
String decodedPdu = Strings.dumpBytes(bb.array());
bb.flip();
GracefulShutdownContainer container = new GracefulShutdownContainer();
try {
decoder.decode(bb, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
assertEquals(0, gracefulShutdownRequest.getTimeOffline());
assertEquals(32768, gracefulShutdownRequest.getDelay());
// Check the length
assertEquals(0x07, gracefulShutdownRequest.computeLengthInternal());
// Check the encoding
try {
ByteBuffer bb1 = gracefulShutdownRequest.encodeInternal();
String encodedPdu = Strings.dumpBytes(bb1.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class GracefulShutdownTest method testDecodeGracefulShutdownDelay.
/**
* Test the decoding of a GracefulShutdown with a delay only
*/
@Test
public void testDecodeGracefulShutdownDelay() {
Asn1Decoder decoder = new Asn1Decoder();
ByteBuffer bb = ByteBuffer.allocate(0x05);
bb.put(new byte[] { // GracefulShutdown ::= SEQUENCE {
0x30, // GracefulShutdown ::= SEQUENCE {
0x03, (byte) 0x80, 0x01, // delay INTEGER (0..86400) DEFAULT
0x01 // 0
});
String decodedPdu = Strings.dumpBytes(bb.array());
bb.flip();
GracefulShutdownContainer container = new GracefulShutdownContainer();
try {
decoder.decode(bb, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
assertEquals(0, gracefulShutdownRequest.getTimeOffline());
assertEquals(1, gracefulShutdownRequest.getDelay());
// Check the length
assertEquals(0x05, gracefulShutdownRequest.computeLengthInternal());
// Check the encoding
try {
ByteBuffer bb1 = gracefulShutdownRequest.encodeInternal();
String encodedPdu = Strings.dumpBytes(bb1.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class GracefulShutdownTest method testDecodeGracefulShutdownEmpty.
/**
* Test the decoding of a empty GracefulShutdown
*/
@Test
public void testDecodeGracefulShutdownEmpty() {
Asn1Decoder decoder = new Asn1Decoder();
ByteBuffer bb = ByteBuffer.allocate(0x02);
bb.put(new byte[] { // GracefulShutdown ::= SEQUENCE {
0x30, // GracefulShutdown ::= SEQUENCE {
0x00 });
String decodedPdu = Strings.dumpBytes(bb.array());
bb.flip();
GracefulShutdownContainer container = new GracefulShutdownContainer();
try {
decoder.decode(bb, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
GracefulShutdownRequestDecorator gracefulShutdownRequest = container.getGracefulShutdownRequest();
assertEquals(0, gracefulShutdownRequest.getTimeOffline());
assertEquals(0, gracefulShutdownRequest.getDelay());
// Check the length
assertEquals(0x02, gracefulShutdownRequest.computeLengthInternal());
// Check the encoding
try {
ByteBuffer bb1 = gracefulShutdownRequest.encodeInternal();
String encodedPdu = Strings.dumpBytes(bb1.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class StoredProcedureTest method testDecodeStoredProcedureOneParam.
@Test
public void testDecodeStoredProcedureOneParam() throws IntegerDecoderException {
Asn1Decoder storedProcedureDecoder = new StoredProcedureDecoder();
ByteBuffer stream = ByteBuffer.allocate(0x1D);
stream.put(new byte[] { 0x30, 0x1B, 0x04, 0x04, 'J', 'a', 'v', 'a', 0x04, 0x07, 'e', 'x', 'e', 'c', 'u', 't', 'e', 0x30, 0x0A, 0x30, 0x08, 0x04, 0x03, 'i', 'n', 't', 0x04, 0x01, 0x01 });
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a StoredProcedure Container
StoredProcedureContainer storedProcedureContainer = new StoredProcedureContainer();
// Decode a StoredProcedure message
try {
storedProcedureDecoder.decode(stream, storedProcedureContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
StoredProcedureRequestDecorator storedProcedure = storedProcedureContainer.getStoredProcedure();
assertEquals("Java", storedProcedure.getLanguage());
assertEquals("execute", storedProcedure.getProcedureSpecification());
assertEquals(1, storedProcedure.size());
assertEquals("int", Strings.utf8ToString((byte[]) storedProcedure.getParameterType(0)));
assertEquals(1, IntegerDecoder.parse(new BerValue((byte[]) storedProcedure.getParameterValue(0))));
// Check the encoding
try {
ByteBuffer bb = storedProcedure.encodeInternal();
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.asn1.EncoderException in project directory-ldap-api by apache.
the class AdDirSyncControlTest method testAdDirSyncControl.
@Test
public void testAdDirSyncControl() throws Exception {
ByteBuffer bb = ByteBuffer.allocate(0x0F);
bb.put(new byte[] { 0x30, 0x0D, // flag (LDAP_DIRSYNC_OBJECT_SECURITY, LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER)
0x02, // flag (LDAP_DIRSYNC_OBJECT_SECURITY, LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER)
0x02, // flag (LDAP_DIRSYNC_OBJECT_SECURITY, LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER)
0x08, // flag (LDAP_DIRSYNC_OBJECT_SECURITY, LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER)
0x01, // maxReturnLength (no limit)
0x02, // maxReturnLength (no limit)
0x01, // maxReturnLength (no limit)
0x00, // the cookie
0x04, // the cookie
0x04, // the cookie
'x', // the cookie
'k', // the cookie
'c', // the cookie
'd' });
bb.flip();
AdDirSync decorator = new AdDirSyncDecorator(codec);
AdDirSync adDirSync = (AdDirSync) ((AdDirSyncDecorator) decorator).decode(bb.array());
assertEquals(EnumSet.of(AdDirSyncFlag.LDAP_DIRSYNC_OBJECT_SECURITY, AdDirSyncFlag.LDAP_DIRSYNC_ANCESTORS_FIRST_ORDER), adDirSync.getFlags());
assertEquals(0, adDirSync.getMaxReturnLength());
assertEquals("xkcd", Strings.utf8ToString(adDirSync.getCookie()));
// test encoding
try {
ByteBuffer buffer = ((AdDirSyncDecorator) adDirSync).encode(ByteBuffer.allocate(((AdDirSyncDecorator) adDirSync).computeLength()));
String expected = "0x30 0x0D 0x02 0x02 0x08 0x01 0x02 0x01 0x00 0x04 0x04 0x78 0x6B 0x63 0x64 ";
String decoded = Strings.dumpBytes(buffer.array());
assertEquals(expected, decoded);
} catch (EncoderException e) {
fail(e.getMessage());
}
}
Aggregations