Control[] reqCtls = initialContext.getRequestControls();
assertEquals(1, reqCtls.length);
assertEquals("2.16.840.1.113730.3.4.2", reqCtls[0].getID());
assertEquals(Control.NONCRITICAL, reqCtls[0].isCritical());
initialContext.setRequestControls(new Control[] { new SortControl("",
Control.NONCRITICAL) });
reqCtls = initialContext.getRequestControls();
assertEquals(2, reqCtls.length);
Control control = reqCtls[0];
if (control instanceof SortControl) {
assertEquals(Control.NONCRITICAL, reqCtls[0].isCritical());
assertEquals("2.16.840.1.113730.3.4.2", reqCtls[1].getID());
assertEquals(Control.NONCRITICAL, reqCtls[1].isCritical());
} else {
assertEquals("2.16.840.1.113730.3.4.2", control.getID());
assertEquals(Control.NONCRITICAL, control.isCritical());
assertTrue(reqCtls[1] instanceof SortControl);
assertEquals(Control.NONCRITICAL, reqCtls[1].isCritical());
}
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_SEARCH_RESULT_DONE,
new EncodableLdapResult(), null) });
LdapContext context = (LdapContext) initialContext.lookup("");
// request controls are not inherited
reqCtls = context.getRequestControls();
assertEquals(1, reqCtls.length);
assertEquals("2.16.840.1.113730.3.4.2", reqCtls[0].getID());
assertEquals(Control.NONCRITICAL, reqCtls[0].isCritical());
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
context = context.newInstance(new Control[] { new SortControl("",
Control.NONCRITICAL) });
reqCtls = context.getRequestControls();
assertEquals(2, reqCtls.length);
control = reqCtls[0];