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.
}
}
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.
}
}
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.
}
}
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.
}
}
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.
}
}
Aggregations