Control[] expected = new Control[] { new PagedResultsControl(10,
Control.NONCRITICAL) };
env.put("java.naming.ldap.control.connect", expected);
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
LdapContext context = new InitialLdapContext(env, null);
Control[] controls = context.getConnectControls();
assertNotNull(controls);
assertNotSame(expected, controls);
Control c = controls[0];
assertTrue(c instanceof PagedResultsControl);
assertEquals(Control.NONCRITICAL, ((PagedResultsControl) c)
.isCritical());
assertEquals(expected[0], c);
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
expected = new Control[] { new SortControl("", Control.NONCRITICAL) };
context.reconnect(expected);
controls = context.getConnectControls();
assertNotNull(controls);
assertEquals(1, controls.length);
c = controls[0];
assertTrue(c instanceof SortControl);
assertEquals(Control.NONCRITICAL, ((SortControl) c).isCritical());
assertNotSame(expected, controls);
assertEquals(expected[0], c);
expected[0] = new PagedResultsControl(10, Control.NONCRITICAL);
controls = context.getConnectControls();
assertNotNull(controls);
assertEquals(1, controls.length);
c = controls[0];
assertTrue(c instanceof SortControl);
assertEquals(Control.NONCRITICAL, ((SortControl) c).isCritical());
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
context.reconnect(null);
assertNull(context.getConnectControls());
}