use of com.unboundid.ldap.listener.TestIntermediateResponseExtendedOperationHandler in project ldapsdk by pingidentity.
the class LDAPConnectionLoggerTestCase method testLogExtendedOperationsSynchronous.
/**
* Tests to ensure that extended operations are logged as expected when using
* synchronous mode.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testLogExtendedOperationsSynchronous() throws Exception {
final InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=example,dc=com");
config.addAdditionalBindCredentials("cn=Directory Manager", "password");
config.addExtendedOperationHandler(new TestIntermediateResponseExtendedOperationHandler("1.2.3.4", "1.2.3.5", "1.2.3.6", 2, 3));
final InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);
ds.startListening();
try {
final int port = ds.getListenPort();
final TestLDAPConnectionLogger logger = new TestLDAPConnectionLogger();
final LDAPConnectionOptions options = new LDAPConnectionOptions();
options.setUseSynchronousMode(true);
options.setConnectionLogger(logger);
assertEquals(logger.getSuccessfulConnectCount(), 0);
assertEquals(logger.getFailedConnectCount(), 0);
assertEquals(logger.getDisconnectCount(), 0);
assertEquals(logger.getAbandonRequestCount(), 0);
assertEquals(logger.getAddRequestCount(), 0);
assertEquals(logger.getAddResultCount(), 0);
assertEquals(logger.getSimpleBindRequestCount(), 0);
assertEquals(logger.getSASLBindRequestCount(), 0);
assertEquals(logger.getBindResultCount(), 0);
assertEquals(logger.getCompareRequestCount(), 0);
assertEquals(logger.getCompareResultCount(), 0);
assertEquals(logger.getDeleteRequestCount(), 0);
assertEquals(logger.getDeleteResultCount(), 0);
assertEquals(logger.getExtendedRequestCount(), 0);
assertEquals(logger.getExtendedResultCount(), 0);
assertEquals(logger.getModifyRequestCount(), 0);
assertEquals(logger.getModifyResultCount(), 0);
assertEquals(logger.getModifyDNRequestCount(), 0);
assertEquals(logger.getModifyDNResultCount(), 0);
assertEquals(logger.getSearchRequestCount(), 0);
assertEquals(logger.getSearchResultEntryCount(), 0);
assertEquals(logger.getSearchResultReferenceCount(), 0);
assertEquals(logger.getSearchResultDoneCount(), 0);
assertEquals(logger.getUnbindRequestCount(), 0);
assertEquals(logger.getIntermediateResponseCount(), 0);
try (LDAPConnection connection = new LDAPConnection(options, "localhost", port)) {
// Verify that the connect was logged.
assertEquals(logger.getSuccessfulConnectCount(), 1);
assertEquals(logger.getFailedConnectCount(), 0);
assertEquals(logger.getDisconnectCount(), 0);
assertEquals(logger.getAbandonRequestCount(), 0);
assertEquals(logger.getAddRequestCount(), 0);
assertEquals(logger.getAddResultCount(), 0);
assertEquals(logger.getSimpleBindRequestCount(), 0);
assertEquals(logger.getSASLBindRequestCount(), 0);
assertEquals(logger.getBindResultCount(), 0);
assertEquals(logger.getCompareRequestCount(), 0);
assertEquals(logger.getCompareResultCount(), 0);
assertEquals(logger.getDeleteRequestCount(), 0);
assertEquals(logger.getDeleteResultCount(), 0);
assertEquals(logger.getExtendedRequestCount(), 0);
assertEquals(logger.getExtendedResultCount(), 0);
assertEquals(logger.getModifyRequestCount(), 0);
assertEquals(logger.getModifyResultCount(), 0);
assertEquals(logger.getModifyDNRequestCount(), 0);
assertEquals(logger.getModifyDNResultCount(), 0);
assertEquals(logger.getSearchRequestCount(), 0);
assertEquals(logger.getSearchResultEntryCount(), 0);
assertEquals(logger.getSearchResultReferenceCount(), 0);
assertEquals(logger.getSearchResultDoneCount(), 0);
assertEquals(logger.getUnbindRequestCount(), 0);
assertEquals(logger.getIntermediateResponseCount(), 0);
// Authenticate the connection.
assertResultCodeEquals(connection, new SimpleBindRequest("cn=Directory Manager", "password"), ResultCode.SUCCESS);
assertEquals(logger.getSuccessfulConnectCount(), 1);
assertEquals(logger.getFailedConnectCount(), 0);
assertEquals(logger.getDisconnectCount(), 0);
assertEquals(logger.getAbandonRequestCount(), 0);
assertEquals(logger.getAddRequestCount(), 0);
assertEquals(logger.getAddResultCount(), 0);
assertEquals(logger.getSimpleBindRequestCount(), 1);
assertEquals(logger.getSASLBindRequestCount(), 0);
assertEquals(logger.getBindResultCount(), 1);
assertEquals(logger.getCompareRequestCount(), 0);
assertEquals(logger.getCompareResultCount(), 0);
assertEquals(logger.getDeleteRequestCount(), 0);
assertEquals(logger.getDeleteResultCount(), 0);
assertEquals(logger.getExtendedRequestCount(), 0);
assertEquals(logger.getExtendedResultCount(), 0);
assertEquals(logger.getModifyRequestCount(), 0);
assertEquals(logger.getModifyResultCount(), 0);
assertEquals(logger.getModifyDNRequestCount(), 0);
assertEquals(logger.getModifyDNResultCount(), 0);
assertEquals(logger.getSearchRequestCount(), 0);
assertEquals(logger.getSearchResultEntryCount(), 0);
assertEquals(logger.getSearchResultReferenceCount(), 0);
assertEquals(logger.getSearchResultDoneCount(), 0);
assertEquals(logger.getUnbindRequestCount(), 0);
assertEquals(logger.getIntermediateResponseCount(), 0);
// Send a "Who Am I?" extended request on the connection.
assertResultCodeEquals(connection, new WhoAmIExtendedRequest(), ResultCode.SUCCESS);
assertEquals(logger.getSuccessfulConnectCount(), 1);
assertEquals(logger.getFailedConnectCount(), 0);
assertEquals(logger.getDisconnectCount(), 0);
assertEquals(logger.getAbandonRequestCount(), 0);
assertEquals(logger.getAddRequestCount(), 0);
assertEquals(logger.getAddResultCount(), 0);
assertEquals(logger.getSimpleBindRequestCount(), 1);
assertEquals(logger.getSASLBindRequestCount(), 0);
assertEquals(logger.getBindResultCount(), 1);
assertEquals(logger.getCompareRequestCount(), 0);
assertEquals(logger.getCompareResultCount(), 0);
assertEquals(logger.getDeleteRequestCount(), 0);
assertEquals(logger.getDeleteResultCount(), 0);
assertEquals(logger.getExtendedRequestCount(), 1);
assertEquals(logger.getExtendedResultCount(), 1);
assertEquals(logger.getModifyRequestCount(), 0);
assertEquals(logger.getModifyResultCount(), 0);
assertEquals(logger.getModifyDNRequestCount(), 0);
assertEquals(logger.getModifyDNResultCount(), 0);
assertEquals(logger.getSearchRequestCount(), 0);
assertEquals(logger.getSearchResultEntryCount(), 0);
assertEquals(logger.getSearchResultReferenceCount(), 0);
assertEquals(logger.getSearchResultDoneCount(), 0);
assertEquals(logger.getUnbindRequestCount(), 0);
assertEquals(logger.getIntermediateResponseCount(), 0);
// Send an extended request that will include intermediate responses.
assertResultCodeEquals(connection, new ExtendedRequest("1.2.3.4"), ResultCode.SUCCESS);
assertEquals(logger.getSuccessfulConnectCount(), 1);
assertEquals(logger.getFailedConnectCount(), 0);
assertEquals(logger.getDisconnectCount(), 0);
assertEquals(logger.getAbandonRequestCount(), 0);
assertEquals(logger.getAddRequestCount(), 0);
assertEquals(logger.getAddResultCount(), 0);
assertEquals(logger.getSimpleBindRequestCount(), 1);
assertEquals(logger.getSASLBindRequestCount(), 0);
assertEquals(logger.getBindResultCount(), 1);
assertEquals(logger.getCompareRequestCount(), 0);
assertEquals(logger.getCompareResultCount(), 0);
assertEquals(logger.getDeleteRequestCount(), 0);
assertEquals(logger.getDeleteResultCount(), 0);
assertEquals(logger.getExtendedRequestCount(), 2);
assertEquals(logger.getExtendedResultCount(), 2);
assertEquals(logger.getModifyRequestCount(), 0);
assertEquals(logger.getModifyResultCount(), 0);
assertEquals(logger.getModifyDNRequestCount(), 0);
assertEquals(logger.getModifyDNResultCount(), 0);
assertEquals(logger.getSearchRequestCount(), 0);
assertEquals(logger.getSearchResultEntryCount(), 0);
assertEquals(logger.getSearchResultReferenceCount(), 0);
assertEquals(logger.getSearchResultDoneCount(), 0);
assertEquals(logger.getUnbindRequestCount(), 0);
assertEquals(logger.getIntermediateResponseCount(), 5);
// Send an extended request with an unrecognized request OID.
assertResultCodeEquals(connection, new ExtendedRequest("4.3.2.1"), ResultCode.UNWILLING_TO_PERFORM);
assertEquals(logger.getSuccessfulConnectCount(), 1);
assertEquals(logger.getFailedConnectCount(), 0);
assertEquals(logger.getDisconnectCount(), 0);
assertEquals(logger.getAbandonRequestCount(), 0);
assertEquals(logger.getAddRequestCount(), 0);
assertEquals(logger.getAddResultCount(), 0);
assertEquals(logger.getSimpleBindRequestCount(), 1);
assertEquals(logger.getSASLBindRequestCount(), 0);
assertEquals(logger.getBindResultCount(), 1);
assertEquals(logger.getCompareRequestCount(), 0);
assertEquals(logger.getCompareResultCount(), 0);
assertEquals(logger.getDeleteRequestCount(), 0);
assertEquals(logger.getDeleteResultCount(), 0);
assertEquals(logger.getExtendedRequestCount(), 3);
assertEquals(logger.getExtendedResultCount(), 3);
assertEquals(logger.getModifyRequestCount(), 0);
assertEquals(logger.getModifyResultCount(), 0);
assertEquals(logger.getModifyDNRequestCount(), 0);
assertEquals(logger.getModifyDNResultCount(), 0);
assertEquals(logger.getSearchRequestCount(), 0);
assertEquals(logger.getSearchResultEntryCount(), 0);
assertEquals(logger.getSearchResultReferenceCount(), 0);
assertEquals(logger.getSearchResultDoneCount(), 0);
assertEquals(logger.getUnbindRequestCount(), 0);
assertEquals(logger.getIntermediateResponseCount(), 5);
}
// Verify that the unbind and disconnect were logged.
assertEquals(logger.getSuccessfulConnectCount(), 1);
assertEquals(logger.getFailedConnectCount(), 0);
assertEquals(logger.getDisconnectCount(), 1);
assertEquals(logger.getAbandonRequestCount(), 0);
assertEquals(logger.getAddRequestCount(), 0);
assertEquals(logger.getAddResultCount(), 0);
assertEquals(logger.getSimpleBindRequestCount(), 1);
assertEquals(logger.getSASLBindRequestCount(), 0);
assertEquals(logger.getBindResultCount(), 1);
assertEquals(logger.getCompareRequestCount(), 0);
assertEquals(logger.getCompareResultCount(), 0);
assertEquals(logger.getDeleteRequestCount(), 0);
assertEquals(logger.getDeleteResultCount(), 0);
assertEquals(logger.getExtendedRequestCount(), 3);
assertEquals(logger.getExtendedResultCount(), 3);
assertEquals(logger.getModifyRequestCount(), 0);
assertEquals(logger.getModifyResultCount(), 0);
assertEquals(logger.getModifyDNRequestCount(), 0);
assertEquals(logger.getModifyDNResultCount(), 0);
assertEquals(logger.getSearchRequestCount(), 0);
assertEquals(logger.getSearchResultEntryCount(), 0);
assertEquals(logger.getSearchResultReferenceCount(), 0);
assertEquals(logger.getSearchResultDoneCount(), 0);
assertEquals(logger.getUnbindRequestCount(), 1);
assertEquals(logger.getIntermediateResponseCount(), 5);
} finally {
ds.shutDown(true);
}
}
use of com.unboundid.ldap.listener.TestIntermediateResponseExtendedOperationHandler in project ldapsdk by pingidentity.
the class LDAPConnectionLoggerTestCase method testLogExtendedOperationsNonSynchronous.
/**
* Tests to ensure that extended operations are logged as expected when not
* using synchronous mode.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testLogExtendedOperationsNonSynchronous() throws Exception {
final InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=example,dc=com");
config.addAdditionalBindCredentials("cn=Directory Manager", "password");
config.addExtendedOperationHandler(new TestIntermediateResponseExtendedOperationHandler("1.2.3.4", "1.2.3.5", "1.2.3.6", 2, 3));
final InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);
ds.startListening();
try {
final int port = ds.getListenPort();
final TestLDAPConnectionLogger logger = new TestLDAPConnectionLogger();
final LDAPConnectionOptions options = new LDAPConnectionOptions();
options.setConnectionLogger(logger);
assertEquals(logger.getSuccessfulConnectCount(), 0);
assertEquals(logger.getFailedConnectCount(), 0);
assertEquals(logger.getDisconnectCount(), 0);
assertEquals(logger.getAbandonRequestCount(), 0);
assertEquals(logger.getAddRequestCount(), 0);
assertEquals(logger.getAddResultCount(), 0);
assertEquals(logger.getSimpleBindRequestCount(), 0);
assertEquals(logger.getSASLBindRequestCount(), 0);
assertEquals(logger.getBindResultCount(), 0);
assertEquals(logger.getCompareRequestCount(), 0);
assertEquals(logger.getCompareResultCount(), 0);
assertEquals(logger.getDeleteRequestCount(), 0);
assertEquals(logger.getDeleteResultCount(), 0);
assertEquals(logger.getExtendedRequestCount(), 0);
assertEquals(logger.getExtendedResultCount(), 0);
assertEquals(logger.getModifyRequestCount(), 0);
assertEquals(logger.getModifyResultCount(), 0);
assertEquals(logger.getModifyDNRequestCount(), 0);
assertEquals(logger.getModifyDNResultCount(), 0);
assertEquals(logger.getSearchRequestCount(), 0);
assertEquals(logger.getSearchResultEntryCount(), 0);
assertEquals(logger.getSearchResultReferenceCount(), 0);
assertEquals(logger.getSearchResultDoneCount(), 0);
assertEquals(logger.getUnbindRequestCount(), 0);
assertEquals(logger.getIntermediateResponseCount(), 0);
try (LDAPConnection connection = new LDAPConnection(options, "localhost", port)) {
// Verify that the connect was logged.
assertEquals(logger.getSuccessfulConnectCount(), 1);
assertEquals(logger.getFailedConnectCount(), 0);
assertEquals(logger.getDisconnectCount(), 0);
assertEquals(logger.getAbandonRequestCount(), 0);
assertEquals(logger.getAddRequestCount(), 0);
assertEquals(logger.getAddResultCount(), 0);
assertEquals(logger.getSimpleBindRequestCount(), 0);
assertEquals(logger.getSASLBindRequestCount(), 0);
assertEquals(logger.getBindResultCount(), 0);
assertEquals(logger.getCompareRequestCount(), 0);
assertEquals(logger.getCompareResultCount(), 0);
assertEquals(logger.getDeleteRequestCount(), 0);
assertEquals(logger.getDeleteResultCount(), 0);
assertEquals(logger.getExtendedRequestCount(), 0);
assertEquals(logger.getExtendedResultCount(), 0);
assertEquals(logger.getModifyRequestCount(), 0);
assertEquals(logger.getModifyResultCount(), 0);
assertEquals(logger.getModifyDNRequestCount(), 0);
assertEquals(logger.getModifyDNResultCount(), 0);
assertEquals(logger.getSearchRequestCount(), 0);
assertEquals(logger.getSearchResultEntryCount(), 0);
assertEquals(logger.getSearchResultReferenceCount(), 0);
assertEquals(logger.getSearchResultDoneCount(), 0);
assertEquals(logger.getUnbindRequestCount(), 0);
assertEquals(logger.getIntermediateResponseCount(), 0);
// Authenticate the connection.
assertResultCodeEquals(connection, new SimpleBindRequest("cn=Directory Manager", "password"), ResultCode.SUCCESS);
assertEquals(logger.getSuccessfulConnectCount(), 1);
assertEquals(logger.getFailedConnectCount(), 0);
assertEquals(logger.getDisconnectCount(), 0);
assertEquals(logger.getAbandonRequestCount(), 0);
assertEquals(logger.getAddRequestCount(), 0);
assertEquals(logger.getAddResultCount(), 0);
assertEquals(logger.getSimpleBindRequestCount(), 1);
assertEquals(logger.getSASLBindRequestCount(), 0);
assertEquals(logger.getBindResultCount(), 1);
assertEquals(logger.getCompareRequestCount(), 0);
assertEquals(logger.getCompareResultCount(), 0);
assertEquals(logger.getDeleteRequestCount(), 0);
assertEquals(logger.getDeleteResultCount(), 0);
assertEquals(logger.getExtendedRequestCount(), 0);
assertEquals(logger.getExtendedResultCount(), 0);
assertEquals(logger.getModifyRequestCount(), 0);
assertEquals(logger.getModifyResultCount(), 0);
assertEquals(logger.getModifyDNRequestCount(), 0);
assertEquals(logger.getModifyDNResultCount(), 0);
assertEquals(logger.getSearchRequestCount(), 0);
assertEquals(logger.getSearchResultEntryCount(), 0);
assertEquals(logger.getSearchResultReferenceCount(), 0);
assertEquals(logger.getSearchResultDoneCount(), 0);
assertEquals(logger.getUnbindRequestCount(), 0);
assertEquals(logger.getIntermediateResponseCount(), 0);
// Send a "Who Am I?" extended request on the connection.
assertResultCodeEquals(connection, new WhoAmIExtendedRequest(), ResultCode.SUCCESS);
assertEquals(logger.getSuccessfulConnectCount(), 1);
assertEquals(logger.getFailedConnectCount(), 0);
assertEquals(logger.getDisconnectCount(), 0);
assertEquals(logger.getAbandonRequestCount(), 0);
assertEquals(logger.getAddRequestCount(), 0);
assertEquals(logger.getAddResultCount(), 0);
assertEquals(logger.getSimpleBindRequestCount(), 1);
assertEquals(logger.getSASLBindRequestCount(), 0);
assertEquals(logger.getBindResultCount(), 1);
assertEquals(logger.getCompareRequestCount(), 0);
assertEquals(logger.getCompareResultCount(), 0);
assertEquals(logger.getDeleteRequestCount(), 0);
assertEquals(logger.getDeleteResultCount(), 0);
assertEquals(logger.getExtendedRequestCount(), 1);
assertEquals(logger.getExtendedResultCount(), 1);
assertEquals(logger.getModifyRequestCount(), 0);
assertEquals(logger.getModifyResultCount(), 0);
assertEquals(logger.getModifyDNRequestCount(), 0);
assertEquals(logger.getModifyDNResultCount(), 0);
assertEquals(logger.getSearchRequestCount(), 0);
assertEquals(logger.getSearchResultEntryCount(), 0);
assertEquals(logger.getSearchResultReferenceCount(), 0);
assertEquals(logger.getSearchResultDoneCount(), 0);
assertEquals(logger.getUnbindRequestCount(), 0);
assertEquals(logger.getIntermediateResponseCount(), 0);
// Send an extended request that will include intermediate responses.
assertResultCodeEquals(connection, new ExtendedRequest("1.2.3.4"), ResultCode.SUCCESS);
assertEquals(logger.getSuccessfulConnectCount(), 1);
assertEquals(logger.getFailedConnectCount(), 0);
assertEquals(logger.getDisconnectCount(), 0);
assertEquals(logger.getAbandonRequestCount(), 0);
assertEquals(logger.getAddRequestCount(), 0);
assertEquals(logger.getAddResultCount(), 0);
assertEquals(logger.getSimpleBindRequestCount(), 1);
assertEquals(logger.getSASLBindRequestCount(), 0);
assertEquals(logger.getBindResultCount(), 1);
assertEquals(logger.getCompareRequestCount(), 0);
assertEquals(logger.getCompareResultCount(), 0);
assertEquals(logger.getDeleteRequestCount(), 0);
assertEquals(logger.getDeleteResultCount(), 0);
assertEquals(logger.getExtendedRequestCount(), 2);
assertEquals(logger.getExtendedResultCount(), 2);
assertEquals(logger.getModifyRequestCount(), 0);
assertEquals(logger.getModifyResultCount(), 0);
assertEquals(logger.getModifyDNRequestCount(), 0);
assertEquals(logger.getModifyDNResultCount(), 0);
assertEquals(logger.getSearchRequestCount(), 0);
assertEquals(logger.getSearchResultEntryCount(), 0);
assertEquals(logger.getSearchResultReferenceCount(), 0);
assertEquals(logger.getSearchResultDoneCount(), 0);
assertEquals(logger.getUnbindRequestCount(), 0);
assertEquals(logger.getIntermediateResponseCount(), 5);
// Send an extended request with an unrecognized request OID.
assertResultCodeEquals(connection, new ExtendedRequest("4.3.2.1"), ResultCode.UNWILLING_TO_PERFORM);
assertEquals(logger.getSuccessfulConnectCount(), 1);
assertEquals(logger.getFailedConnectCount(), 0);
assertEquals(logger.getDisconnectCount(), 0);
assertEquals(logger.getAbandonRequestCount(), 0);
assertEquals(logger.getAddRequestCount(), 0);
assertEquals(logger.getAddResultCount(), 0);
assertEquals(logger.getSimpleBindRequestCount(), 1);
assertEquals(logger.getSASLBindRequestCount(), 0);
assertEquals(logger.getBindResultCount(), 1);
assertEquals(logger.getCompareRequestCount(), 0);
assertEquals(logger.getCompareResultCount(), 0);
assertEquals(logger.getDeleteRequestCount(), 0);
assertEquals(logger.getDeleteResultCount(), 0);
assertEquals(logger.getExtendedRequestCount(), 3);
assertEquals(logger.getExtendedResultCount(), 3);
assertEquals(logger.getModifyRequestCount(), 0);
assertEquals(logger.getModifyResultCount(), 0);
assertEquals(logger.getModifyDNRequestCount(), 0);
assertEquals(logger.getModifyDNResultCount(), 0);
assertEquals(logger.getSearchRequestCount(), 0);
assertEquals(logger.getSearchResultEntryCount(), 0);
assertEquals(logger.getSearchResultReferenceCount(), 0);
assertEquals(logger.getSearchResultDoneCount(), 0);
assertEquals(logger.getUnbindRequestCount(), 0);
assertEquals(logger.getIntermediateResponseCount(), 5);
}
// Verify that the unbind and disconnect were logged.
assertEquals(logger.getSuccessfulConnectCount(), 1);
assertEquals(logger.getFailedConnectCount(), 0);
assertEquals(logger.getDisconnectCount(), 1);
assertEquals(logger.getAbandonRequestCount(), 0);
assertEquals(logger.getAddRequestCount(), 0);
assertEquals(logger.getAddResultCount(), 0);
assertEquals(logger.getSimpleBindRequestCount(), 1);
assertEquals(logger.getSASLBindRequestCount(), 0);
assertEquals(logger.getBindResultCount(), 1);
assertEquals(logger.getCompareRequestCount(), 0);
assertEquals(logger.getCompareResultCount(), 0);
assertEquals(logger.getDeleteRequestCount(), 0);
assertEquals(logger.getDeleteResultCount(), 0);
assertEquals(logger.getExtendedRequestCount(), 3);
assertEquals(logger.getExtendedResultCount(), 3);
assertEquals(logger.getModifyRequestCount(), 0);
assertEquals(logger.getModifyResultCount(), 0);
assertEquals(logger.getModifyDNRequestCount(), 0);
assertEquals(logger.getModifyDNResultCount(), 0);
assertEquals(logger.getSearchRequestCount(), 0);
assertEquals(logger.getSearchResultEntryCount(), 0);
assertEquals(logger.getSearchResultReferenceCount(), 0);
assertEquals(logger.getSearchResultDoneCount(), 0);
assertEquals(logger.getUnbindRequestCount(), 1);
assertEquals(logger.getIntermediateResponseCount(), 5);
} finally {
ds.shutDown(true);
}
}
use of com.unboundid.ldap.listener.TestIntermediateResponseExtendedOperationHandler in project ldapsdk by pingidentity.
the class JSONLDAPConnectionLoggerTestCase method testExtendedOperationLogging.
/**
* Tests the behavior when logging extended operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testExtendedOperationLogging() throws Exception {
// Get the in-memory directory server instance.
final InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=example,dc=com");
config.addAdditionalBindCredentials("cn=Directory Manager", "password");
config.addExtendedOperationHandler(new TestIntermediateResponseExtendedOperationHandler("1.2.3.4", "1.2.3.5", "1.2.3.6", 1, 1));
final InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);
ds.startListening();
try {
// Create a logger to use for the test.
final TestLogHandler logHandler = new TestLogHandler();
final JSONLDAPConnectionLoggerProperties properties = new JSONLDAPConnectionLoggerProperties();
final JSONLDAPConnectionLogger logger = new JSONLDAPConnectionLogger(logHandler, properties);
final LDAPConnectionOptions options = new LDAPConnectionOptions();
options.setConnectionLogger(logger);
// Establish a connection and send an extended request on it.
try (LDAPConnection connection = new LDAPConnection(options, "localhost", ds.getListenPort())) {
assertResultCodeEquals(connection, new ExtendedRequest("1.2.3.4"), ResultCode.SUCCESS);
}
// Make sure that there were seven log messages:
// - Connect
// - Extended request
// - Intermediate response with value
// - Intermediate response without value
// - Extended result
// - Unbind
// - Disconnect
assertEquals(logHandler.getMessageCount(), 7, logHandler.getMessagesString());
final List<JSONObject> logMessages = parseLogMessages(logHandler);
assertMessageIs(logMessages.get(0), "connect", null);
assertMessageIs(logMessages.get(1), "request", OperationType.EXTENDED);
assertMessageIs(logMessages.get(2), "intermediate-response", null);
assertMessageIs(logMessages.get(3), "intermediate-response", null);
assertMessageIs(logMessages.get(4), "result", OperationType.EXTENDED);
assertMessageIs(logMessages.get(5), "request", OperationType.UNBIND);
assertMessageIs(logMessages.get(6), "disconnect", null);
} finally {
ds.shutDown(true);
}
}
Aggregations