Search in sources :

Example 11 with LogException

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

the class JSONAccessLogReaderTestCase method testReadIntermediateResponseWithInvalidOperationType.

/**
 * Tests the behavior when trying to read a file containing a JSON object for
 * an intermediate response log message that has an invalid operation type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testReadIntermediateResponseWithInvalidOperationType() throws Exception {
    final JSONObject messageObject = createMinimalMessageObject(INTERMEDIATE_RESPONSE, null, createField(OPERATION_TYPE, "invalid"));
    final File logFile = createTempFile(messageObject.toSingleLineString());
    try (JSONAccessLogReader reader = new JSONAccessLogReader(logFile)) {
        reader.readMessage();
        fail("Expected an exception for an intermediate response message with " + "an invalid operation type.");
    } 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)

Example 12 with LogException

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

the class JSONAccessLogReaderTestCase method testReadObjectWithInvalidOperationType.

/**
 * Tests the behavior when trying to read a file containing a JSON object
 * for an operation message that has an invalid operation type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testReadObjectWithInvalidOperationType() throws Exception {
    final JSONObject minimalMessageObject = createMinimalMessageObject(REQUEST, ABANDON);
    final Map<String, JSONValue> fieldsWithInvalidOperationType = new LinkedHashMap<>(minimalMessageObject.getFields());
    assertNotNull(fieldsWithInvalidOperationType.put(OPERATION_TYPE.getFieldName(), new JSONString("invalid")));
    final JSONObject objectWithoutMessageType = new JSONObject(fieldsWithInvalidOperationType);
    final File logFile = createTempFile(objectWithoutMessageType.toSingleLineString());
    try (JSONAccessLogReader reader = new JSONAccessLogReader(logFile)) {
        reader.readMessage();
        fail("Expected an exception for a file that contains a JSON object " + "with an invalid operation type");
    } catch (final LogException e) {
    // This was expected.
    }
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) JSONString(com.unboundid.util.json.JSONString) File(java.io.File) JSONString(com.unboundid.util.json.JSONString) LogException(com.unboundid.ldap.sdk.unboundidds.logs.LogException) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 13 with LogException

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

the class JSONAccessLogReaderTestCase method testReadObjectWithoutOperationType.

/**
 * Tests the behavior when trying to read a file containing a JSON object
 * for an operation message that doesn't include an operation type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testReadObjectWithoutOperationType() throws Exception {
    final JSONObject minimalMessageObject = createMinimalMessageObject(REQUEST, ABANDON);
    final Map<String, JSONValue> fieldsWithoutOperationType = new LinkedHashMap<>(minimalMessageObject.getFields());
    assertNotNull(fieldsWithoutOperationType.remove(OPERATION_TYPE.getFieldName()));
    final JSONObject objectWithoutMessageType = new JSONObject(fieldsWithoutOperationType);
    final File logFile = createTempFile(objectWithoutMessageType.toSingleLineString());
    try (JSONAccessLogReader reader = new JSONAccessLogReader(logFile)) {
        reader.readMessage();
        fail("Expected an exception for a file that contains a JSON object " + "without an operation type");
    } catch (final LogException e) {
    // This was expected.
    }
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) JSONString(com.unboundid.util.json.JSONString) File(java.io.File) LogException(com.unboundid.ldap.sdk.unboundidds.logs.LogException) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 14 with LogException

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

the class JSONLogMessageTestCase method testLogMessageWithoutTimestamp.

/**
 * Tests to ensure that it's not possible to create a log message without a
 * timestamp.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testLogMessageWithoutTimestamp() throws Exception {
    // Create a valid minimal message object and make sure we can create a log
    // message from it.
    final JSONObject validMessageObject = createMinimalMessageObject(CONNECT, null);
    new JSONConnectAccessLogMessage(validMessageObject);
    // Create a JSON object with all of the fields from the valid object except
    // the timestamp and verify that we can't create a log message from it.
    final Map<String, JSONValue> fieldsWithoutTimestamp = new LinkedHashMap<>(validMessageObject.getFields());
    assertNotNull(fieldsWithoutTimestamp.remove(TIMESTAMP.getFieldName()));
    final JSONObject messageObjectWithoutTimestamp = new JSONObject(fieldsWithoutTimestamp);
    try {
        new JSONConnectAccessLogMessage(messageObjectWithoutTimestamp);
        fail("Expected an exception when trying to create a log message " + "without a timestamp.");
    } catch (final LogException e) {
    // This was expected.
    }
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) JSONString(com.unboundid.util.json.JSONString) LogException(com.unboundid.ldap.sdk.unboundidds.logs.LogException) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 15 with LogException

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

the class JSONAccessLogReaderTestCase method testReadObjectWithInvalidMessageType.

/**
 * Tests the behavior when trying to read a file containing a JSON object
 * that includes an invalid message type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testReadObjectWithInvalidMessageType() throws Exception {
    final JSONObject minimalMessageObject = createMinimalMessageObject(CONNECT, null);
    final Map<String, JSONValue> fieldsWithInvalidMessageType = new LinkedHashMap<>(minimalMessageObject.getFields());
    assertNotNull(fieldsWithInvalidMessageType.put(MESSAGE_TYPE.getFieldName(), new JSONString("invalid")));
    final JSONObject objectWithoutMessageType = new JSONObject(fieldsWithInvalidMessageType);
    final File logFile = createTempFile(objectWithoutMessageType.toSingleLineString());
    try (JSONAccessLogReader reader = new JSONAccessLogReader(logFile)) {
        reader.readMessage();
        fail("Expected an exception for a file that contains a JSON object " + "with an invalid message type");
    } catch (final LogException e) {
    // This was expected.
    }
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) JSONString(com.unboundid.util.json.JSONString) File(java.io.File) JSONString(com.unboundid.util.json.JSONString) LogException(com.unboundid.ldap.sdk.unboundidds.logs.LogException) LinkedHashMap(java.util.LinkedHashMap) 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