use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.
the class JSONLDAPConnectionLoggerTestCase method testModifyWithAllDetailsIncluded.
/**
* Provides coverage for the case in which a modify request log message
* contains modifications and both names and values are to be logged.
*
* Tests the behavior when logging search operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testModifyWithAllDetailsIncluded() throws Exception {
// Get the in-memory directory server instance.
final InMemoryDirectoryServer ds = getTestDS(false, false);
// Create a logger to use for the test.
final TestLogHandler logHandler = new TestLogHandler();
final JSONLDAPConnectionLoggerProperties properties = new JSONLDAPConnectionLoggerProperties();
properties.setIncludeModifyAttributeNames(true);
properties.setIncludeModifyAttributeValues(true);
final JSONLDAPConnectionLogger logger = new JSONLDAPConnectionLogger(logHandler, properties);
final LDAPConnectionOptions options = new LDAPConnectionOptions();
options.setConnectionLogger(logger);
// Generate a log message.
try (LDAPConnection connection = ds.getConnection()) {
connection.setConnectionName("The connection name");
connection.setConnectionPoolName("The connection pool name");
final ModifyRequest modifyRequest = new ModifyRequest("dn: uid=test.user,ou=People,dc=example,dc=com", "changetype: modify", "replace: userPassword", "userPassword: newPassword", "-", "replace: authpassword", "authpassword: anotherNewPassword", "-", "replace: description", "-", "delete: givenName", "-", "add: givenName", "givenName: Foo", "-", "delete: givenName", "givenName: Foo", "-", "add: givenName", "givenName: Test", "-", "increment: intValueAttr", "intValueAttr: 1", "-");
logger.logModifyRequest(connection, 1, modifyRequest);
}
// Make sure that we can decode the message.
assertEquals(logHandler.getMessageCount(), 1, logHandler.getMessagesString());
final List<JSONObject> logMessages = parseLogMessages(logHandler);
assertMessageIs(logMessages.get(0), "request", OperationType.MODIFY);
}
use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.
the class JSONLDAPConnectionLoggerTestCase method testModifyLogging.
/**
* Tests the behavior when logging modify operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testModifyLogging() throws Exception {
// Get the in-memory directory server instance.
final InMemoryDirectoryServer ds = getTestDS(true, false);
// 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 a modify request on it.
try (LDAPConnection connection = new LDAPConnection(options, "localhost", ds.getListenPort())) {
connection.modify("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: foo");
}
// Make sure that there were five log messages:
// - Connect
// - Modify request
// - Modify result
// - Unbind
// - Disconnect
assertEquals(logHandler.getMessageCount(), 5, logHandler.getMessagesString());
final List<JSONObject> logMessages = parseLogMessages(logHandler);
assertMessageIs(logMessages.get(0), "connect", null);
assertMessageIs(logMessages.get(1), "request", OperationType.MODIFY);
assertMessageIs(logMessages.get(2), "result", OperationType.MODIFY);
assertMessageIs(logMessages.get(3), "request", OperationType.UNBIND);
assertMessageIs(logMessages.get(4), "disconnect", null);
}
use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.
the class JSONLDAPConnectionLoggerTestCase method testDisconnectLoggingAllElements.
/**
* Provides coverage for the case in which a disconnect log message contains
* all elements.
*
* Tests the behavior when logging search operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDisconnectLoggingAllElements() throws Exception {
// Get the in-memory directory server instance.
final InMemoryDirectoryServer ds = getTestDS(false, false);
// 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);
// Generate a log message.
try (LDAPConnection connection = ds.getConnection()) {
logger.logDisconnect(connection, "localhost", ds.getListenPort(), DisconnectType.OTHER, "Testing disconnect logging", new Exception());
}
// Make sure that we can decode the message.
assertEquals(logHandler.getMessageCount(), 1, logHandler.getMessagesString());
final List<JSONObject> logMessages = parseLogMessages(logHandler);
assertMessageIs(logMessages.get(0), "disconnect", null);
}
use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.
the class JSONLDAPConnectionLoggerTestCase method testCompareLogging.
/**
* Tests the behavior when logging compare operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testCompareLogging() throws Exception {
// Get the in-memory directory server instance.
final InMemoryDirectoryServer ds = getTestDS(true, false);
// 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 a compare request on it.
try (LDAPConnection connection = new LDAPConnection(options, "localhost", ds.getListenPort())) {
assertTrue(connection.compare("dc=example,dc=com", "dc", "example").compareMatched());
}
// Make sure that there were five log messages:
// - Connect
// - Compare request
// - Compare result
// - Unbind
// - Disconnect
assertEquals(logHandler.getMessageCount(), 5, logHandler.getMessagesString());
final List<JSONObject> logMessages = parseLogMessages(logHandler);
assertMessageIs(logMessages.get(0), "connect", null);
assertMessageIs(logMessages.get(1), "request", OperationType.COMPARE);
assertMessageIs(logMessages.get(2), "result", OperationType.COMPARE);
assertMessageIs(logMessages.get(3), "request", OperationType.UNBIND);
assertMessageIs(logMessages.get(4), "disconnect", null);
}
use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.
the class JSONLDAPConnectionLoggerTestCase method testAbandonWithControls.
/**
* Provides coverage for the case in which an abandon request includes
* controls, which will be processed as a list.
*
* Tests the behavior when logging search operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testAbandonWithControls() throws Exception {
// Get the in-memory directory server instance.
final InMemoryDirectoryServer ds = getTestDS(false, false);
// 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);
// Generate a log message.
try (LDAPConnection connection = ds.getConnection()) {
logger.logAbandonRequest(connection, 2, 1, Arrays.asList(new Control("1.2.3.4", false, null), new Control("1.2.3.5", true, new ASN1OctetString("foo"))));
}
// Make sure that we can decode the message.
assertEquals(logHandler.getMessageCount(), 1, logHandler.getMessagesString());
final List<JSONObject> logMessages = parseLogMessages(logHandler);
assertMessageIs(logMessages.get(0), "request", OperationType.ABANDON);
}
Aggregations