{
BindRequest br1 = new BindRequestImpl();
br1.setDn( new Dn( "uid=admin,ou=system" ) );
br1.setCredentials( Strings.getBytesUtf8( "secret" ) );
BindResponse response1 = connection.bind( br1 );
assertTrue( connection.isAuthenticated() );
int messageId1 = response1.getMessageId();
// The messageId must have been incremented
BindRequest br2 = new BindRequestImpl();
br2.setDn( new Dn( "uid=admin,ou=system" ) );
br2.setCredentials( Strings.getBytesUtf8( "secret" ) );
BindResponse response2 = connection.bind( br2 );
int messageId2 = response2.getMessageId();
assertTrue( messageId2 > messageId1 );
assertTrue( connection.isAuthenticated() );
// Now, unbind
connection.unBind();
assertFalse( connection.isAuthenticated() );
assertFalse( connection.isConnected() );
// And Bind again. The messageId should be 1
BindRequest br3 = new BindRequestImpl();
br3.setDn( new Dn( "uid=admin,ou=system" ) );
br3.setCredentials( Strings.getBytesUtf8( "secret" ) );
BindResponse response3 = connection.bind( br3 );
int messageId = response3.getMessageId();
assertEquals( 1, messageId );
assertTrue( connection.isAuthenticated() );
}