referralServer.stop();
}
public void testAddToEnvironment() throws Exception {
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
assertNull(env.get(Context.REFERRAL));
InitialDirContext initialDirContext = new InitialDirContext(env);
// Context.REFERRAL changed doesn't cause re-bind operation
initialDirContext.addToEnvironment(Context.REFERRAL, "ignore");
assertEquals("ignore", initialDirContext.getEnvironment().get(
Context.REFERRAL));
server.setResponseSeq(new LdapMessage[] { new LdapMessage(
LdapASN1Constant.OP_DEL_RESPONSE, new EncodableLdapResult(),
null) });
initialDirContext.destroySubcontext("cn=test");
/*
* Context.SECURITY_AUTHENTICATION will case re-bind when invoke context
* methods at first time
*/
Object preValue = initialDirContext.addToEnvironment(
Context.SECURITY_AUTHENTICATION, "none");
assertFalse("none".equals(preValue));
server.setResponseSeq(new LdapMessage[] {
new LdapMessage(LdapASN1Constant.OP_BIND_RESPONSE,
new BindResponse(), null),
new LdapMessage(LdapASN1Constant.OP_SEARCH_RESULT_DONE,
new EncodableLdapResult(), null) });
initialDirContext.lookup("");
preValue = initialDirContext.addToEnvironment(
Context.SECURITY_AUTHENTICATION, "simple");
assertFalse("simple".equals(preValue));
// initialDirContext is shared connection, will create new connection
server = new MockLdapServer(server);
server.start();
server.setResponseSeq(new LdapMessage[] {
new LdapMessage(LdapASN1Constant.OP_BIND_RESPONSE,
new BindResponse(), null),
new LdapMessage(LdapASN1Constant.OP_SEARCH_RESULT_DONE,
new EncodableLdapResult(), null) });
initialDirContext.lookup("");