public void testExtendedOperation() throws Exception {
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
LdapContext context = new InitialLdapContext(env, null);
ASN1Encodable encodableResponse = new ASN1Encodable() {
public void encodeValues(Object[] values) {
new EncodableLdapResult().encodeValues(values);
values[4] = Utils.getBytes("It's my id");
values[5] = new byte[] { 0, 1, 2, 3 };
}
};
server
.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_EXTENDED_RESPONSE,
encodableResponse, null) });
ExtendedResponse response = context
.extendedOperation(new MockExtendedRequest());
assertTrue(response instanceof MockExtendedResponse);
assertEquals("It's my id", response.getID());
assertEquals(4, response.getEncodedValue().length);
assertEquals(0, response.getEncodedValue()[0]);
assertEquals(1, response.getEncodedValue()[1]);
assertEquals(2, response.getEncodedValue()[2]);
assertEquals(3, response.getEncodedValue()[3]);
// test exception
encodableResponse = new ASN1Encodable() {
public void encodeValues(Object[] values) {
new EncodableLdapResult().encodeValues(values);
values[4] = Utils.getBytes("exception");
values[5] = new byte[] { 0, 1, 2, 3 };
}