use of org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectDecoder in project directory-ldap-api by apache.
the class GracefulDisconnectResponseTest method testDecodeGracefulDisconnectReplicatedContextsOnly.
/**
* Test the decoding of a GracefulDisconnect with replicatedContexts only
*/
@Test
public void testDecodeGracefulDisconnectReplicatedContextsOnly() {
Asn1Decoder decoder = new GracefulDisconnectDecoder();
ByteBuffer stream = ByteBuffer.allocate(0x6A);
stream.put(new byte[] { // GracefulDisconnec ::= SEQUENCE {
0x30, // GracefulDisconnec ::= SEQUENCE {
0x68, 0x30, // replicatedContexts Referral OPTIONAL
0x66, 0x04, 0x1F, 'l', 'd', 'a', 'p', ':', '/', '/', 'd', 'i', 'r', 'e', 'c', 't', 'o', 'r', 'y', '.', 'a', 'p', 'a', 'c', 'h', 'e', '.', 'o', 'r', 'g', ':', '8', '0', '/', 0x04, 0x43, 'l', 'd', 'a', 'p', ':', '/', '/', 'l', 'd', 'a', 'p', '.', 'n', 'e', 't', 's', 'c', 'a', 'p', 'e', '.', 'c', 'o', 'm', '/', 'o', '=', 'B', 'a', 'b', 's', 'c', 'o', ',', 'c', '=', 'U', 'S', '?', '?', '?', '(', 'i', 'n', 't', '=', '%', '5', 'c', '0', '0', '%', '5', 'c', '0', '0', '%', '5', 'c', '0', '0', '%', '5', 'c', '0', '4', ')' });
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
GracefulDisconnectContainer container = new GracefulDisconnectContainer();
try {
decoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
GracefulDisconnectResponseDecorator gracefulDisconnect = container.getGracefulDisconnectResponse();
assertEquals(0, gracefulDisconnect.getTimeOffline());
assertEquals(0, gracefulDisconnect.getDelay());
assertEquals(2, gracefulDisconnect.getReplicatedContexts().getLdapUrls().size());
Iterator<String> ldapUrls = gracefulDisconnect.getReplicatedContexts().getLdapUrls().iterator();
assertEquals("ldap://directory.apache.org:80/", ldapUrls.next());
assertEquals("ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)", ldapUrls.next());
// Check the length
assertEquals(0x6A, gracefulDisconnect.computeLengthInternal());
// Check the encoding
try {
ByteBuffer bb = gracefulDisconnect.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.gracefulDisconnect.GracefulDisconnectDecoder in project directory-ldap-api by apache.
the class GracefulDisconnectResponseTest method testDecodeGracefulDisconnectDelayOffLimit.
/**
* Test the decoding of a GracefulDisconnect with a delay off limit
*/
@Test
public void testDecodeGracefulDisconnectDelayOffLimit() {
Asn1Decoder decoder = new GracefulDisconnectDecoder();
ByteBuffer bb = ByteBuffer.allocate(0x0b);
bb.put(new byte[] { // GracefulDisconnect ::= SEQUENCE {
0x30, // GracefulDisconnect ::= SEQUENCE {
0x05, (byte) 0x80, 0x03, 0x01, (byte) 0x86, // delay
(byte) 0xA0 // INTEGER
// (0..86400)
// DEFAULT
// 0
});
bb.flip();
GracefulDisconnectContainer container = new GracefulDisconnectContainer();
try {
decoder.decode(bb, container);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectDecoder in project directory-ldap-api by apache.
the class GracefulDisconnectResponseTest method testDecodeGracefulDisconnectReplicatedContextsInvalid.
/**
* Test the decoding of a GracefulDisconnect with an invalid replicated
* context
*/
@Test
public void testDecodeGracefulDisconnectReplicatedContextsInvalid() {
Asn1Decoder decoder = new GracefulDisconnectDecoder();
ByteBuffer bb = ByteBuffer.allocate(0x06);
bb.put(new byte[] { // GracefulDisconnect ::= SEQUENCE {
0x30, // GracefulDisconnect ::= SEQUENCE {
0x04, 0x30, // replicatedContexts Referral OPTIONAL
0x02, 0x04, 0x00 });
bb.flip();
GracefulDisconnectContainer container = new GracefulDisconnectContainer();
try {
decoder.decode(bb, container);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectDecoder in project directory-ldap-api by apache.
the class GracefulDisconnectResponseTest method testDecodeGracefulDisconnectEmpty.
/**
* Test the decoding of a empty GracefulDisconnect
*/
@Test
public void testDecodeGracefulDisconnectEmpty() {
Asn1Decoder decoder = new GracefulDisconnectDecoder();
ByteBuffer bb = ByteBuffer.allocate(0x02);
bb.put(new byte[] { // GracefulDisconnect ::= SEQUENCE {
0x30, // GracefulDisconnect ::= SEQUENCE {
0x00 });
String decodedPdu = Strings.dumpBytes(bb.array());
bb.flip();
GracefulDisconnectContainer container = new GracefulDisconnectContainer();
try {
decoder.decode(bb, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
GracefulDisconnectResponseDecorator gracefulDisconnect = container.getGracefulDisconnectResponse();
assertEquals(0, gracefulDisconnect.getTimeOffline());
assertEquals(0, gracefulDisconnect.getDelay());
assertEquals(0, gracefulDisconnect.getReplicatedContexts().getLdapUrls().size());
// Check the length
assertEquals(0x02, gracefulDisconnect.computeLengthInternal());
// Check the encoding
try {
ByteBuffer bb1 = gracefulDisconnect.encodeInternal();
String encodedPdu = Strings.dumpBytes(bb1.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectDecoder in project directory-ldap-api by apache.
the class GracefulDisconnectResponseTest method testDecodeGracefulDisconnectDelay.
/**
* Test the decoding of a GracefulDisconnect with a delay only
*/
@Test
public void testDecodeGracefulDisconnectDelay() {
Asn1Decoder decoder = new GracefulDisconnectDecoder();
ByteBuffer bb = ByteBuffer.allocate(0x05);
bb.put(new byte[] { // GracefulDisconnect ::= SEQUENCE {
0x30, // GracefulDisconnect ::= SEQUENCE {
0x03, (byte) 0x80, 0x01, // delay INTEGER (0..86400) DEFAULT
0x01 // 0
});
String decodedPdu = Strings.dumpBytes(bb.array());
bb.flip();
GracefulDisconnectContainer container = new GracefulDisconnectContainer();
try {
decoder.decode(bb, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
GracefulDisconnectResponseDecorator gracefulDisconnect = container.getGracefulDisconnectResponse();
assertEquals(0, gracefulDisconnect.getTimeOffline());
assertEquals(1, gracefulDisconnect.getDelay());
assertEquals(0, gracefulDisconnect.getReplicatedContexts().getLdapUrls().size());
// Check the length
assertEquals(0x05, gracefulDisconnect.computeLengthInternal());
// Check the encoding
try {
ByteBuffer bb1 = gracefulDisconnect.encodeInternal();
String encodedPdu = Strings.dumpBytes(bb1.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
Aggregations