Search in sources :

Example 26 with LogException

use of com.unboundid.ldap.sdk.unboundidds.logs.LogException in project ldapsdk by pingidentity.

the class TextFormattedAccessLogReaderTestCase method testReadMessageWithoutAnyUnnamedFields.

/**
 * Tests the behavior when trying to read a file that contains a log message
 * that doesn't have any unnamed fields.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testReadMessageWithoutAnyUnnamedFields() throws Exception {
    final StringBuilder messageBuffer = createLogMessage(true, null, null, false);
    appendField(messageBuffer, DIAGNOSTIC_MESSAGE, "value1");
    appendField(messageBuffer, ADDITIONAL_INFO, "value2");
    final File logFile = createTempFile(messageBuffer.toString());
    try (TextFormattedAccessLogReader reader = new TextFormattedAccessLogReader(logFile)) {
        reader.readMessage();
        fail("Expected an exception for a file that contains a message without " + "any unnamed fields");
    } catch (final LogException e) {
    // This was expected.
    }
}
Also used : File(java.io.File) LogException(com.unboundid.ldap.sdk.unboundidds.logs.LogException) Test(org.testng.annotations.Test)

Example 27 with LogException

use of com.unboundid.ldap.sdk.unboundidds.logs.LogException in project ldapsdk by pingidentity.

the class TextFormattedAccessLogReaderTestCase method testReadUnbindForwardMessage.

/**
 * Tests the behavior when trying to read a file that contains a log message
 * that attempts to create an unbind forward message, which is not valid.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testReadUnbindForwardMessage() throws Exception {
    final StringBuilder messageBuffer = createLogMessage(true, FORWARD, UNBIND, false);
    final File logFile = createTempFile(messageBuffer.toString());
    try (TextFormattedAccessLogReader reader = new TextFormattedAccessLogReader(logFile)) {
        reader.readMessage();
        fail("Expected an exception for a file that contains an unbind forward " + "message");
    } catch (final LogException e) {
    // This was expected.
    }
}
Also used : File(java.io.File) LogException(com.unboundid.ldap.sdk.unboundidds.logs.LogException) Test(org.testng.annotations.Test)

Example 28 with LogException

use of com.unboundid.ldap.sdk.unboundidds.logs.LogException in project ldapsdk by pingidentity.

the class TextFormattedAccessLogReaderTestCase method testReadMessageWithUnsupportedSecondUnnamedField.

/**
 * Tests the behavior when trying to read a file that contains a log message
 * that has two unnamed fields in which the second is not a valid message
 * type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testReadMessageWithUnsupportedSecondUnnamedField() throws Exception {
    final StringBuilder messageBuffer = createLogMessage(true, null, null, false);
    messageBuffer.append("ADD UNSUPPORTED");
    appendField(messageBuffer, DIAGNOSTIC_MESSAGE, "value1");
    appendField(messageBuffer, ADDITIONAL_INFO, "value2");
    final File logFile = createTempFile(messageBuffer.toString());
    try (TextFormattedAccessLogReader reader = new TextFormattedAccessLogReader(logFile)) {
        reader.readMessage();
        fail("Expected an exception for a file that contains a message with " + "an unsupported second unnamed field");
    } catch (final LogException e) {
    // This was expected.
    }
}
Also used : File(java.io.File) LogException(com.unboundid.ldap.sdk.unboundidds.logs.LogException) Test(org.testng.annotations.Test)

Example 29 with LogException

use of com.unboundid.ldap.sdk.unboundidds.logs.LogException in project ldapsdk by pingidentity.

the class TextFormattedAccessLogReaderTestCase method testFileMalformedLogMessage.

/**
 * Tests the behavior when trying to read a file that doesn't contain valid
 * log messages.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testFileMalformedLogMessage() throws Exception {
    final File logFile = createTempFile("# This is a comment", "# The next line will be blank", "", "# The next line will be parsed as a log message, but it's " + "malformed.", "This is a malformed log message");
    try (FileInputStream inputStream = new FileInputStream(logFile);
        TextFormattedAccessLogReader reader = new TextFormattedAccessLogReader(inputStream)) {
        reader.readMessage();
        fail("Expected an exception for a file that contains a malformed " + "message.");
    } catch (final LogException e) {
    // This was expected.
    }
}
Also used : File(java.io.File) FileInputStream(java.io.FileInputStream) LogException(com.unboundid.ldap.sdk.unboundidds.logs.LogException) Test(org.testng.annotations.Test)

Example 30 with LogException

use of com.unboundid.ldap.sdk.unboundidds.logs.LogException in project ldapsdk by pingidentity.

the class JSONAccessLogReaderTestCase method testReadUnbindForwardFailedMessage.

/**
 * Tests the behavior when trying to read a file containing a JSON object for
 * a forward failed log message for an unbind operation (which can't be
 * forwarded).
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testReadUnbindForwardFailedMessage() throws Exception {
    final JSONObject messageObject = createMinimalMessageObject(FORWARD_FAILED, UNBIND);
    final File logFile = createTempFile(messageObject.toSingleLineString());
    try (JSONAccessLogReader reader = new JSONAccessLogReader(logFile)) {
        reader.readMessage();
        fail("Expected an exception for a forward failed message with an " + "operation type of unbind.");
    } catch (final LogException e) {
    // This was expected.
    }
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) File(java.io.File) LogException(com.unboundid.ldap.sdk.unboundidds.logs.LogException) Test(org.testng.annotations.Test)

Aggregations

LogException (com.unboundid.ldap.sdk.unboundidds.logs.LogException)34 Test (org.testng.annotations.Test)30 File (java.io.File)22 JSONObject (com.unboundid.util.json.JSONObject)20 JSONString (com.unboundid.util.json.JSONString)8 JSONValue (com.unboundid.util.json.JSONValue)8 LinkedHashMap (java.util.LinkedHashMap)8 NotNull (com.unboundid.util.NotNull)4 AccessLogMessageType (com.unboundid.ldap.sdk.unboundidds.logs.AccessLogMessageType)2 AccessLogOperationType (com.unboundid.ldap.sdk.unboundidds.logs.AccessLogOperationType)2 LogField (com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField)2 FileInputStream (java.io.FileInputStream)2 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 SearchScope (com.unboundid.ldap.sdk.SearchScope)1 AbandonRequestAccessLogMessage (com.unboundid.ldap.sdk.unboundidds.logs.v2.AbandonRequestAccessLogMessage)1 AccessLogMessage (com.unboundid.ldap.sdk.unboundidds.logs.v2.AccessLogMessage)1 AccessLogReader (com.unboundid.ldap.sdk.unboundidds.logs.v2.AccessLogReader)1 AddResultAccessLogMessage (com.unboundid.ldap.sdk.unboundidds.logs.v2.AddResultAccessLogMessage)1 BindResultAccessLogMessage (com.unboundid.ldap.sdk.unboundidds.logs.v2.BindResultAccessLogMessage)1 CompareResultAccessLogMessage (com.unboundid.ldap.sdk.unboundidds.logs.v2.CompareResultAccessLogMessage)1