Search in sources :

Example 6 with MemoryBasedLogHandler

use of com.unboundid.util.MemoryBasedLogHandler in project ldapsdk by pingidentity.

the class AccessLogRequestHandlerTestCase method createListener.

/**
 * Creates a new listener that will write log messages to an in-memory buffer.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@BeforeClass()
public void createListener() throws Exception {
    logHandler = new MemoryBasedLogHandler();
    logHandler.setFormatter(new MinimalLogFormatter());
    logHandler.setLevel(Level.INFO);
    final CannedResponseRequestHandler successHandler = new CannedResponseRequestHandler();
    final LDAPListenerConfig successConfig = new LDAPListenerConfig(0, new AccessLogRequestHandler(logHandler, successHandler));
    successListener = new LDAPListener(successConfig);
    successListener.startListening();
    successPort = successListener.getListenPort();
    assertTrue(successPort > 0);
    final CannedResponseRequestHandler failureHandler = new CannedResponseRequestHandler(ResultCode.NO_SUCH_OBJECT, "dc=example,dc=com", "The target entry was not found", Arrays.asList("ldap://server1.example.com/dc=example,dc=com", "ldap://server2.example.com/dc=example,dc=com"));
    final LDAPListenerConfig failureConfig = new LDAPListenerConfig(0, new AccessLogRequestHandler(logHandler, failureHandler));
    failureListener = new LDAPListener(failureConfig);
    failureListener.startListening();
    failurePort = failureListener.getListenPort();
    assertTrue(failurePort > 0);
}
Also used : MemoryBasedLogHandler(com.unboundid.util.MemoryBasedLogHandler) MinimalLogFormatter(com.unboundid.util.MinimalLogFormatter) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

MemoryBasedLogHandler (com.unboundid.util.MemoryBasedLogHandler)6 Test (org.testng.annotations.Test)4 DN (com.unboundid.ldap.sdk.DN)2 LDAPException (com.unboundid.ldap.sdk.LDAPException)2 MinimalLogFormatter (com.unboundid.util.MinimalLogFormatter)2 File (java.io.File)2 BeforeClass (org.testng.annotations.BeforeClass)2 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1