use of com.unboundid.util.json.JSONObject in project ldapsdk by pingidentity.
the class JSONAccessLogReaderTestCase method testModifyForwardFailedLogMessage.
/**
* Tests the ability to read a modify forward failed log message.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testModifyForwardFailedLogMessage() throws Exception {
final JSONObject minimalMessageObject = createMinimalMessageObject(FORWARD_FAILED, MODIFY);
final JSONObject populatedMessageObject = createPopulatedMessageObject(FORWARD_FAILED, MODIFY, createField(MODIFY_ENTRY_DN, "cn=modify,cn=dn"), createField(MODIFY_ATTRIBUTES, createArray("mod-attr-1", "mod-attr-2")));
final File logFile = createTempFile(minimalMessageObject.toSingleLineString(), populatedMessageObject.toSingleLineString());
try (JSONAccessLogReader reader = new JSONAccessLogReader(logFile)) {
assertNotNull(reader);
// Read the minimal log message.
final JSONModifyForwardFailedAccessLogMessage minimalLogMessage = (JSONModifyForwardFailedAccessLogMessage) reader.readMessage();
assertNotNull(minimalLogMessage);
// Common fields.
assertEquals(minimalLogMessage.getTimestamp(), DEFAULT_TIMESTAMP_DATE);
assertEquals(minimalLogMessage.getLogType(), ACCESS_LOG_TYPE);
assertEquals(minimalLogMessage.getMessageType(), FORWARD_FAILED);
assertEquals(minimalLogMessage.getOperationType(), MODIFY);
assertNull(minimalLogMessage.getProductName());
assertNull(minimalLogMessage.getInstanceName());
assertNull(minimalLogMessage.getStartupID());
assertNull(minimalLogMessage.getThreadID());
assertNull(minimalLogMessage.getConnectionID());
assertNull(minimalLogMessage.getOperationID());
assertNull(minimalLogMessage.getMessageID());
assertNull(minimalLogMessage.getTriggeredByConnectionID());
assertNull(minimalLogMessage.getTriggeredByOperationID());
assertNull(minimalLogMessage.getOrigin());
assertNull(minimalLogMessage.getRequesterIPAddress());
assertNull(minimalLogMessage.getRequesterDN());
assertEquals(minimalLogMessage.getRequestControlOIDs(), Collections.emptySet());
assertNull(minimalLogMessage.getUsingAdminSessionWorkerThread());
assertNull(minimalLogMessage.getAdministrativeOperationMessage());
assertNull(minimalLogMessage.getIntermediateClientRequestControl());
assertNull(minimalLogMessage.getOperationPurposeRequestControl());
assertNull(minimalLogMessage.getTargetHost());
assertNull(minimalLogMessage.getTargetPort());
assertNull(minimalLogMessage.getTargetProtocol());
assertNull(minimalLogMessage.getResultCode());
assertNull(minimalLogMessage.getDiagnosticMessage());
// Message-specific fields.
assertNull(minimalLogMessage.getDN());
assertEquals(minimalLogMessage.getAttributeNames(), Collections.emptySet());
// Read the fully-populated log message.
final JSONModifyForwardFailedAccessLogMessage populatedLogMessage = (JSONModifyForwardFailedAccessLogMessage) reader.readMessage();
assertNotNull(populatedLogMessage);
// Common fields.
assertEquals(populatedLogMessage.getTimestamp(), DEFAULT_TIMESTAMP_DATE);
assertEquals(populatedLogMessage.getLogType(), ACCESS_LOG_TYPE);
assertEquals(populatedLogMessage.getMessageType(), FORWARD_FAILED);
assertEquals(populatedLogMessage.getOperationType(), MODIFY);
assertEquals(populatedLogMessage.getProductName(), DEFAULT_PRODUCT_NAME);
assertEquals(populatedLogMessage.getInstanceName(), DEFAULT_INSTANCE_NAME);
assertEquals(populatedLogMessage.getStartupID(), DEFAULT_STARTUP_ID);
assertEquals(populatedLogMessage.getThreadID().longValue(), DEFAULT_THREAD_ID);
assertEquals(populatedLogMessage.getConnectionID().longValue(), DEFAULT_CONNECTION_ID);
assertEquals(populatedLogMessage.getOperationID().longValue(), DEFAULT_OPERATION_ID);
assertEquals(populatedLogMessage.getMessageID().intValue(), DEFAULT_MESSAGE_ID);
assertEquals(populatedLogMessage.getTriggeredByConnectionID().longValue(), DEFAULT_TRIGGERED_BY_CONNECTION_ID);
assertEquals(populatedLogMessage.getTriggeredByOperationID().longValue(), DEFAULT_TRIGGERED_BY_OPERATION_ID);
assertEquals(populatedLogMessage.getOrigin(), DEFAULT_ORIGIN);
assertEquals(populatedLogMessage.getRequesterIPAddress(), DEFAULT_REQUESTER_IP);
assertEquals(populatedLogMessage.getRequesterDN(), DEFAULT_REQUESTER_DN);
assertEquals(populatedLogMessage.getRequestControlOIDs(), DEFAULT_REQUEST_CONTROL_OIDS);
assertEquals(populatedLogMessage.getUsingAdminSessionWorkerThread(), DEFAULT_USING_ADMIN_SESSION_WORKER_THREAD);
assertEquals(populatedLogMessage.getAdministrativeOperationMessage(), DEFAULT_ADMIN_OP_MESSAGE);
assertEquals(populatedLogMessage.getTargetHost(), DEFAULT_FORWARD_TARGET_HOST);
assertEquals(populatedLogMessage.getTargetPort().intValue(), DEFAULT_FORWARD_TARGET_PORT);
assertEquals(populatedLogMessage.getTargetProtocol(), DEFAULT_FORWARD_TARGET_PROTOCOL);
assertEquals(populatedLogMessage.getResultCode(), DEFAULT_RESULT_CODE);
assertEquals(populatedLogMessage.getDiagnosticMessage(), DEFAULT_DIAGNOSTIC_MESSAGE);
final JSONIntermediateClientRequestControl intermediateClientRequest = populatedLogMessage.getIntermediateClientRequestControl();
assertNotNull(intermediateClientRequest);
assertNotNull(intermediateClientRequest.getControlObject());
assertEquals(intermediateClientRequest.getDownstreamClientAddress(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getDownstreamClientAddress());
assertEquals(intermediateClientRequest.getDownstreamClientSecure(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getDownstreamClientSecure());
assertEquals(intermediateClientRequest.getClientIdentity(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getClientIdentity());
assertEquals(intermediateClientRequest.getClientName(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getClientName());
assertEquals(intermediateClientRequest.getSessionID(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getSessionID());
assertEquals(intermediateClientRequest.getRequestID(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getRequestID());
assertNotNull(intermediateClientRequest.getDownstreamRequest());
assertNotNull(intermediateClientRequest.toString());
final JSONOperationPurposeRequestControl operationPurpose = populatedLogMessage.getOperationPurposeRequestControl();
assertNotNull(operationPurpose);
assertNotNull(operationPurpose.getControlObject());
assertEquals(operationPurpose.getApplicationName(), DEFAULT_OPERATION_PURPOSE_REQUEST.getApplicationName());
assertEquals(operationPurpose.getApplicationVersion(), DEFAULT_OPERATION_PURPOSE_REQUEST.getApplicationVersion());
assertEquals(operationPurpose.getCodeLocation(), DEFAULT_OPERATION_PURPOSE_REQUEST.getCodeLocation());
assertEquals(operationPurpose.getRequestPurpose(), DEFAULT_OPERATION_PURPOSE_REQUEST.getRequestPurpose());
assertNotNull(operationPurpose.toString());
// Message-specific fields.
assertEquals(populatedLogMessage.getDN(), "cn=modify,cn=dn");
assertEquals(populatedLogMessage.getAttributeNames(), StaticUtils.setOf("mod-attr-1", "mod-attr-2"));
// Make sure there are no more messages to read.
assertNull(reader.readMessage());
}
}
use of com.unboundid.util.json.JSONObject in project ldapsdk by pingidentity.
the class JSONAccessLogReaderTestCase method testModifyDNRequestLogMessage.
/**
* Tests the ability to read a modify DN request log message.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testModifyDNRequestLogMessage() throws Exception {
final JSONObject minimalMessageObject = createMinimalMessageObject(REQUEST, MODDN);
final JSONObject populatedMessageObject = createPopulatedMessageObject(REQUEST, MODDN, createField(MODDN_ENTRY_DN, "cn=moddn,cn=entry,cn=dn"), createField(MODDN_NEW_RDN, "cn=newrdn"), createField(MODDN_DELETE_OLD_RDN, true), createField(MODDN_NEW_SUPERIOR_DN, "cn=new,cn=superior,cn=dn"));
final File logFile = createTempFile(minimalMessageObject.toSingleLineString(), populatedMessageObject.toSingleLineString());
try (JSONAccessLogReader reader = new JSONAccessLogReader(logFile)) {
assertNotNull(reader);
// Read the minimal log message.
final JSONModifyDNRequestAccessLogMessage minimalLogMessage = (JSONModifyDNRequestAccessLogMessage) reader.readMessage();
assertNotNull(minimalLogMessage);
// Common fields.
assertEquals(minimalLogMessage.getTimestamp(), DEFAULT_TIMESTAMP_DATE);
assertEquals(minimalLogMessage.getLogType(), ACCESS_LOG_TYPE);
assertEquals(minimalLogMessage.getMessageType(), REQUEST);
assertEquals(minimalLogMessage.getOperationType(), MODDN);
assertNull(minimalLogMessage.getProductName());
assertNull(minimalLogMessage.getInstanceName());
assertNull(minimalLogMessage.getStartupID());
assertNull(minimalLogMessage.getThreadID());
assertNull(minimalLogMessage.getConnectionID());
assertNull(minimalLogMessage.getOperationID());
assertNull(minimalLogMessage.getMessageID());
assertNull(minimalLogMessage.getTriggeredByConnectionID());
assertNull(minimalLogMessage.getTriggeredByOperationID());
assertNull(minimalLogMessage.getOrigin());
assertNull(minimalLogMessage.getRequesterIPAddress());
assertNull(minimalLogMessage.getRequesterDN());
assertEquals(minimalLogMessage.getRequestControlOIDs(), Collections.emptySet());
assertNull(minimalLogMessage.getUsingAdminSessionWorkerThread());
assertNull(minimalLogMessage.getAdministrativeOperationMessage());
assertNull(minimalLogMessage.getIntermediateClientRequestControl());
assertNull(minimalLogMessage.getOperationPurposeRequestControl());
// Message-specific fields.
assertNull(minimalLogMessage.getDN());
assertNull(minimalLogMessage.getNewRDN());
assertNull(minimalLogMessage.getDeleteOldRDN());
assertNull(minimalLogMessage.getNewSuperiorDN());
// Read the fully-populated log message.
final JSONModifyDNRequestAccessLogMessage populatedLogMessage = (JSONModifyDNRequestAccessLogMessage) reader.readMessage();
assertNotNull(populatedLogMessage);
// Common fields.
assertEquals(populatedLogMessage.getTimestamp(), DEFAULT_TIMESTAMP_DATE);
assertEquals(populatedLogMessage.getLogType(), ACCESS_LOG_TYPE);
assertEquals(populatedLogMessage.getMessageType(), REQUEST);
assertEquals(populatedLogMessage.getOperationType(), MODDN);
assertEquals(populatedLogMessage.getProductName(), DEFAULT_PRODUCT_NAME);
assertEquals(populatedLogMessage.getInstanceName(), DEFAULT_INSTANCE_NAME);
assertEquals(populatedLogMessage.getStartupID(), DEFAULT_STARTUP_ID);
assertEquals(populatedLogMessage.getThreadID().longValue(), DEFAULT_THREAD_ID);
assertEquals(populatedLogMessage.getConnectionID().longValue(), DEFAULT_CONNECTION_ID);
assertEquals(populatedLogMessage.getOperationID().longValue(), DEFAULT_OPERATION_ID);
assertEquals(populatedLogMessage.getMessageID().intValue(), DEFAULT_MESSAGE_ID);
assertEquals(populatedLogMessage.getTriggeredByConnectionID().longValue(), DEFAULT_TRIGGERED_BY_CONNECTION_ID);
assertEquals(populatedLogMessage.getTriggeredByOperationID().longValue(), DEFAULT_TRIGGERED_BY_OPERATION_ID);
assertEquals(populatedLogMessage.getOrigin(), DEFAULT_ORIGIN);
assertEquals(populatedLogMessage.getRequesterIPAddress(), DEFAULT_REQUESTER_IP);
assertEquals(populatedLogMessage.getRequesterDN(), DEFAULT_REQUESTER_DN);
assertEquals(populatedLogMessage.getRequestControlOIDs(), DEFAULT_REQUEST_CONTROL_OIDS);
assertEquals(populatedLogMessage.getUsingAdminSessionWorkerThread(), DEFAULT_USING_ADMIN_SESSION_WORKER_THREAD);
assertEquals(populatedLogMessage.getAdministrativeOperationMessage(), DEFAULT_ADMIN_OP_MESSAGE);
final JSONIntermediateClientRequestControl intermediateClientRequest = populatedLogMessage.getIntermediateClientRequestControl();
assertNotNull(intermediateClientRequest);
assertNotNull(intermediateClientRequest.getControlObject());
assertEquals(intermediateClientRequest.getDownstreamClientAddress(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getDownstreamClientAddress());
assertEquals(intermediateClientRequest.getDownstreamClientSecure(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getDownstreamClientSecure());
assertEquals(intermediateClientRequest.getClientIdentity(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getClientIdentity());
assertEquals(intermediateClientRequest.getClientName(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getClientName());
assertEquals(intermediateClientRequest.getSessionID(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getSessionID());
assertEquals(intermediateClientRequest.getRequestID(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getRequestID());
assertNotNull(intermediateClientRequest.getDownstreamRequest());
assertNotNull(intermediateClientRequest.toString());
final JSONOperationPurposeRequestControl operationPurpose = populatedLogMessage.getOperationPurposeRequestControl();
assertNotNull(operationPurpose);
assertNotNull(operationPurpose.getControlObject());
assertEquals(operationPurpose.getApplicationName(), DEFAULT_OPERATION_PURPOSE_REQUEST.getApplicationName());
assertEquals(operationPurpose.getApplicationVersion(), DEFAULT_OPERATION_PURPOSE_REQUEST.getApplicationVersion());
assertEquals(operationPurpose.getCodeLocation(), DEFAULT_OPERATION_PURPOSE_REQUEST.getCodeLocation());
assertEquals(operationPurpose.getRequestPurpose(), DEFAULT_OPERATION_PURPOSE_REQUEST.getRequestPurpose());
assertNotNull(operationPurpose.toString());
// Message-specific fields.
assertEquals(populatedLogMessage.getDN(), "cn=moddn,cn=entry,cn=dn");
assertEquals(populatedLogMessage.getNewRDN(), "cn=newrdn");
assertEquals(populatedLogMessage.getDeleteOldRDN(), Boolean.TRUE);
assertEquals(populatedLogMessage.getNewSuperiorDN(), "cn=new,cn=superior,cn=dn");
// Make sure there are no more messages to read.
assertNull(reader.readMessage());
}
}
use of com.unboundid.util.json.JSONObject in project ldapsdk by pingidentity.
the class JSONAccessLogReaderTestCase method testModifyRequestLogMessage.
/**
* Tests the ability to read a modify request log message.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testModifyRequestLogMessage() throws Exception {
final JSONObject minimalMessageObject = createMinimalMessageObject(REQUEST, MODIFY);
final JSONObject populatedMessageObject = createPopulatedMessageObject(REQUEST, MODIFY, createField(MODIFY_ENTRY_DN, "cn=modify,cn=dn"), createField(MODIFY_ATTRIBUTES, createArray("mod-attr-1", "mod-attr-2")));
final File logFile = createTempFile(minimalMessageObject.toSingleLineString(), populatedMessageObject.toSingleLineString());
try (JSONAccessLogReader reader = new JSONAccessLogReader(logFile)) {
assertNotNull(reader);
// Read the minimal log message.
final JSONModifyRequestAccessLogMessage minimalLogMessage = (JSONModifyRequestAccessLogMessage) reader.readMessage();
assertNotNull(minimalLogMessage);
// Common fields.
assertEquals(minimalLogMessage.getTimestamp(), DEFAULT_TIMESTAMP_DATE);
assertEquals(minimalLogMessage.getLogType(), ACCESS_LOG_TYPE);
assertEquals(minimalLogMessage.getMessageType(), REQUEST);
assertEquals(minimalLogMessage.getOperationType(), MODIFY);
assertNull(minimalLogMessage.getProductName());
assertNull(minimalLogMessage.getInstanceName());
assertNull(minimalLogMessage.getStartupID());
assertNull(minimalLogMessage.getThreadID());
assertNull(minimalLogMessage.getConnectionID());
assertNull(minimalLogMessage.getOperationID());
assertNull(minimalLogMessage.getMessageID());
assertNull(minimalLogMessage.getTriggeredByConnectionID());
assertNull(minimalLogMessage.getTriggeredByOperationID());
assertNull(minimalLogMessage.getOrigin());
assertNull(minimalLogMessage.getRequesterIPAddress());
assertNull(minimalLogMessage.getRequesterDN());
assertEquals(minimalLogMessage.getRequestControlOIDs(), Collections.emptySet());
assertNull(minimalLogMessage.getUsingAdminSessionWorkerThread());
assertNull(minimalLogMessage.getAdministrativeOperationMessage());
assertNull(minimalLogMessage.getIntermediateClientRequestControl());
assertNull(minimalLogMessage.getOperationPurposeRequestControl());
// Message-specific fields.
assertNull(minimalLogMessage.getDN());
assertEquals(minimalLogMessage.getAttributeNames(), Collections.emptySet());
// Read the fully-populated log message.
final JSONModifyRequestAccessLogMessage populatedLogMessage = (JSONModifyRequestAccessLogMessage) reader.readMessage();
assertNotNull(populatedLogMessage);
// Common fields.
assertEquals(populatedLogMessage.getTimestamp(), DEFAULT_TIMESTAMP_DATE);
assertEquals(populatedLogMessage.getLogType(), ACCESS_LOG_TYPE);
assertEquals(populatedLogMessage.getMessageType(), REQUEST);
assertEquals(populatedLogMessage.getOperationType(), MODIFY);
assertEquals(populatedLogMessage.getProductName(), DEFAULT_PRODUCT_NAME);
assertEquals(populatedLogMessage.getInstanceName(), DEFAULT_INSTANCE_NAME);
assertEquals(populatedLogMessage.getStartupID(), DEFAULT_STARTUP_ID);
assertEquals(populatedLogMessage.getThreadID().longValue(), DEFAULT_THREAD_ID);
assertEquals(populatedLogMessage.getConnectionID().longValue(), DEFAULT_CONNECTION_ID);
assertEquals(populatedLogMessage.getOperationID().longValue(), DEFAULT_OPERATION_ID);
assertEquals(populatedLogMessage.getMessageID().intValue(), DEFAULT_MESSAGE_ID);
assertEquals(populatedLogMessage.getTriggeredByConnectionID().longValue(), DEFAULT_TRIGGERED_BY_CONNECTION_ID);
assertEquals(populatedLogMessage.getTriggeredByOperationID().longValue(), DEFAULT_TRIGGERED_BY_OPERATION_ID);
assertEquals(populatedLogMessage.getOrigin(), DEFAULT_ORIGIN);
assertEquals(populatedLogMessage.getRequesterIPAddress(), DEFAULT_REQUESTER_IP);
assertEquals(populatedLogMessage.getRequesterDN(), DEFAULT_REQUESTER_DN);
assertEquals(populatedLogMessage.getRequestControlOIDs(), DEFAULT_REQUEST_CONTROL_OIDS);
assertEquals(populatedLogMessage.getUsingAdminSessionWorkerThread(), DEFAULT_USING_ADMIN_SESSION_WORKER_THREAD);
assertEquals(populatedLogMessage.getAdministrativeOperationMessage(), DEFAULT_ADMIN_OP_MESSAGE);
final JSONIntermediateClientRequestControl intermediateClientRequest = populatedLogMessage.getIntermediateClientRequestControl();
assertNotNull(intermediateClientRequest);
assertNotNull(intermediateClientRequest.getControlObject());
assertEquals(intermediateClientRequest.getDownstreamClientAddress(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getDownstreamClientAddress());
assertEquals(intermediateClientRequest.getDownstreamClientSecure(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getDownstreamClientSecure());
assertEquals(intermediateClientRequest.getClientIdentity(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getClientIdentity());
assertEquals(intermediateClientRequest.getClientName(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getClientName());
assertEquals(intermediateClientRequest.getSessionID(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getSessionID());
assertEquals(intermediateClientRequest.getRequestID(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getRequestID());
assertNotNull(intermediateClientRequest.getDownstreamRequest());
assertNotNull(intermediateClientRequest.toString());
final JSONOperationPurposeRequestControl operationPurpose = populatedLogMessage.getOperationPurposeRequestControl();
assertNotNull(operationPurpose);
assertNotNull(operationPurpose.getControlObject());
assertEquals(operationPurpose.getApplicationName(), DEFAULT_OPERATION_PURPOSE_REQUEST.getApplicationName());
assertEquals(operationPurpose.getApplicationVersion(), DEFAULT_OPERATION_PURPOSE_REQUEST.getApplicationVersion());
assertEquals(operationPurpose.getCodeLocation(), DEFAULT_OPERATION_PURPOSE_REQUEST.getCodeLocation());
assertEquals(operationPurpose.getRequestPurpose(), DEFAULT_OPERATION_PURPOSE_REQUEST.getRequestPurpose());
assertNotNull(operationPurpose.toString());
// Message-specific fields.
assertEquals(populatedLogMessage.getDN(), "cn=modify,cn=dn");
assertEquals(populatedLogMessage.getAttributeNames(), StaticUtils.setOf("mod-attr-1", "mod-attr-2"));
// Make sure there are no more messages to read.
assertNull(reader.readMessage());
}
}
use of com.unboundid.util.json.JSONObject 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.util.json.JSONObject in project ldapsdk by pingidentity.
the class JSONAccessLogReaderTestCase method testSearchResultLogMessage.
/**
* Tests the ability to read a search result log message.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSearchResultLogMessage() throws Exception {
final JSONObject minimalMessageObject = createMinimalMessageObject(RESULT, SEARCH);
final JSONObject populatedMessageObject = createPopulatedMessageObject(RESULT, SEARCH, createField(SEARCH_BASE_DN, "cn=base,cn=dn"), createField(SEARCH_SCOPE_VALUE, SearchScope.SUB.intValue()), createField(SEARCH_SCOPE_NAME, SearchScope.SUB.getName()), createField(SEARCH_FILTER, "(filter=value)"), createField(SEARCH_SIZE_LIMIT, 2345), createField(SEARCH_TIME_LIMIT_SECONDS, 3456), createField(SEARCH_DEREF_POLICY, DereferencePolicy.NEVER.getName()), createField(SEARCH_TYPES_ONLY, false), createField(SEARCH_REQUESTED_ATTRIBUTES, createArray("requested-attr-1", "requested-attr-2")), createField(SEARCH_ENTRIES_RETURNED, 4567), createField(SEARCH_INDEXED, true));
final File logFile = createTempFile(minimalMessageObject.toSingleLineString(), populatedMessageObject.toSingleLineString());
try (JSONAccessLogReader reader = new JSONAccessLogReader(logFile)) {
assertNotNull(reader);
// Read the minimal log message.
final JSONSearchResultAccessLogMessage minimalLogMessage = (JSONSearchResultAccessLogMessage) reader.readMessage();
assertNotNull(minimalLogMessage);
// Common fields.
assertEquals(minimalLogMessage.getTimestamp(), DEFAULT_TIMESTAMP_DATE);
assertEquals(minimalLogMessage.getLogType(), ACCESS_LOG_TYPE);
assertEquals(minimalLogMessage.getMessageType(), RESULT);
assertEquals(minimalLogMessage.getOperationType(), SEARCH);
assertNull(minimalLogMessage.getProductName());
assertNull(minimalLogMessage.getInstanceName());
assertNull(minimalLogMessage.getStartupID());
assertNull(minimalLogMessage.getThreadID());
assertNull(minimalLogMessage.getConnectionID());
assertNull(minimalLogMessage.getOperationID());
assertNull(minimalLogMessage.getMessageID());
assertNull(minimalLogMessage.getTriggeredByConnectionID());
assertNull(minimalLogMessage.getTriggeredByOperationID());
assertNull(minimalLogMessage.getOrigin());
assertNull(minimalLogMessage.getRequesterIPAddress());
assertNull(minimalLogMessage.getRequesterDN());
assertEquals(minimalLogMessage.getRequestControlOIDs(), Collections.emptySet());
assertNull(minimalLogMessage.getUsingAdminSessionWorkerThread());
assertNull(minimalLogMessage.getAdministrativeOperationMessage());
assertNull(minimalLogMessage.getIntermediateClientRequestControl());
assertNull(minimalLogMessage.getOperationPurposeRequestControl());
assertNull(minimalLogMessage.getTargetHost());
assertNull(minimalLogMessage.getTargetPort());
assertNull(minimalLogMessage.getTargetProtocol());
assertNull(minimalLogMessage.getResultCode());
assertNull(minimalLogMessage.getDiagnosticMessage());
assertNull(minimalLogMessage.getAdditionalInformation());
assertNull(minimalLogMessage.getMatchedDN());
assertEquals(minimalLogMessage.getReferralURLs(), Collections.emptyList());
assertEquals(minimalLogMessage.getServersAccessed(), Collections.emptyList());
assertNull(minimalLogMessage.getUncachedDataAccessed());
assertNull(minimalLogMessage.getWorkQueueWaitTimeMillis());
assertNull(minimalLogMessage.getProcessingTimeMillis());
assertNull(minimalLogMessage.getIntermediateResponsesReturned());
assertEquals(minimalLogMessage.getResponseControlOIDs(), Collections.emptySet());
assertEquals(minimalLogMessage.getUsedPrivileges(), Collections.emptySet());
assertEquals(minimalLogMessage.getPreAuthorizationUsedPrivileges(), Collections.emptySet());
assertEquals(minimalLogMessage.getMissingPrivileges(), Collections.emptySet());
assertNull(minimalLogMessage.getAlternateAuthorizationDN());
assertEquals(minimalLogMessage.getIndexesWithKeysAccessedNearEntryLimit(), Collections.emptySet());
assertEquals(minimalLogMessage.getIndexesWithKeysAccessedExceedingEntryLimit(), Collections.emptySet());
// Message-specific fields.
assertNull(minimalLogMessage.getBaseDN());
assertNull(minimalLogMessage.getScope());
assertNull(minimalLogMessage.getFilter());
assertNull(minimalLogMessage.getSizeLimit());
assertNull(minimalLogMessage.getTimeLimitSeconds());
assertNull(minimalLogMessage.getDereferencePolicy());
assertNull(minimalLogMessage.getTypesOnly());
assertEquals(minimalLogMessage.getRequestedAttributes(), Collections.emptyList());
assertNull(minimalLogMessage.getEntriesReturned());
assertNull(minimalLogMessage.getUnindexed());
// Read the fully-populated log message.
final JSONSearchResultAccessLogMessage populatedLogMessage = (JSONSearchResultAccessLogMessage) reader.readMessage();
assertNotNull(populatedLogMessage);
// Common fields.
assertEquals(populatedLogMessage.getTimestamp(), DEFAULT_TIMESTAMP_DATE);
assertEquals(populatedLogMessage.getLogType(), ACCESS_LOG_TYPE);
assertEquals(populatedLogMessage.getMessageType(), RESULT);
assertEquals(populatedLogMessage.getOperationType(), SEARCH);
assertEquals(populatedLogMessage.getProductName(), DEFAULT_PRODUCT_NAME);
assertEquals(populatedLogMessage.getInstanceName(), DEFAULT_INSTANCE_NAME);
assertEquals(populatedLogMessage.getStartupID(), DEFAULT_STARTUP_ID);
assertEquals(populatedLogMessage.getThreadID().longValue(), DEFAULT_THREAD_ID);
assertEquals(populatedLogMessage.getConnectionID().longValue(), DEFAULT_CONNECTION_ID);
assertEquals(populatedLogMessage.getOperationID().longValue(), DEFAULT_OPERATION_ID);
assertEquals(populatedLogMessage.getMessageID().intValue(), DEFAULT_MESSAGE_ID);
assertEquals(populatedLogMessage.getTriggeredByConnectionID().longValue(), DEFAULT_TRIGGERED_BY_CONNECTION_ID);
assertEquals(populatedLogMessage.getTriggeredByOperationID().longValue(), DEFAULT_TRIGGERED_BY_OPERATION_ID);
assertEquals(populatedLogMessage.getOrigin(), DEFAULT_ORIGIN);
assertEquals(populatedLogMessage.getRequesterIPAddress(), DEFAULT_REQUESTER_IP);
assertEquals(populatedLogMessage.getRequesterDN(), DEFAULT_REQUESTER_DN);
assertEquals(populatedLogMessage.getRequestControlOIDs(), DEFAULT_REQUEST_CONTROL_OIDS);
assertEquals(populatedLogMessage.getUsingAdminSessionWorkerThread(), DEFAULT_USING_ADMIN_SESSION_WORKER_THREAD);
assertEquals(populatedLogMessage.getAdministrativeOperationMessage(), DEFAULT_ADMIN_OP_MESSAGE);
assertEquals(populatedLogMessage.getTargetHost(), DEFAULT_FORWARD_TARGET_HOST);
assertEquals(populatedLogMessage.getTargetPort().intValue(), DEFAULT_FORWARD_TARGET_PORT);
assertEquals(populatedLogMessage.getTargetProtocol(), DEFAULT_FORWARD_TARGET_PROTOCOL);
assertEquals(populatedLogMessage.getResultCode(), DEFAULT_RESULT_CODE);
assertEquals(populatedLogMessage.getDiagnosticMessage(), DEFAULT_DIAGNOSTIC_MESSAGE);
assertEquals(populatedLogMessage.getAdditionalInformation(), DEFAULT_ADDITIONAL_INFO_MESSAGE);
assertEquals(populatedLogMessage.getMatchedDN(), DEFAULT_MATCHED_DN);
assertEquals(populatedLogMessage.getReferralURLs(), DEFAULT_REFERRAL_URLS);
assertEquals(populatedLogMessage.getServersAccessed(), DEFAULT_SERVERS_ACCESSED);
assertEquals(populatedLogMessage.getUncachedDataAccessed(), DEFAULT_UNCACHED_DATA_ACCESSED);
assertEquals(populatedLogMessage.getWorkQueueWaitTimeMillis().doubleValue(), DEFAULT_WORK_QUEUE_WAIT_TIME_MILLIS);
assertEquals(populatedLogMessage.getProcessingTimeMillis().doubleValue(), DEFAULT_PROCESSING_TIME_MILLIS);
assertEquals(populatedLogMessage.getIntermediateResponsesReturned().longValue(), DEFAULT_INTERMEDIATE_RESPONSES_RETURNED);
assertEquals(populatedLogMessage.getResponseControlOIDs(), DEFAULT_RESPONSE_CONTROL_OIDS);
assertEquals(populatedLogMessage.getUsedPrivileges(), DEFAULT_USED_PRIVILEGES);
assertEquals(populatedLogMessage.getPreAuthorizationUsedPrivileges(), DEFAULT_PRE_AUTHZ_USED_PRIVILEGES);
assertEquals(populatedLogMessage.getMissingPrivileges(), DEFAULT_MISSING_PRIVILEGES);
assertEquals(populatedLogMessage.getAlternateAuthorizationDN(), DEFAULT_AUTHZ_DN);
assertEquals(populatedLogMessage.getIndexesWithKeysAccessedNearEntryLimit(), DEFAULT_INDEXES_NEAR_ENTRY_LIMIT);
assertEquals(populatedLogMessage.getIndexesWithKeysAccessedExceedingEntryLimit(), DEFAULT_INDEXES_EXCEEDING_ENTRY_LIMIT);
final JSONIntermediateClientRequestControl intermediateClientRequest = populatedLogMessage.getIntermediateClientRequestControl();
assertNotNull(intermediateClientRequest);
assertNotNull(intermediateClientRequest.getControlObject());
assertEquals(intermediateClientRequest.getDownstreamClientAddress(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getDownstreamClientAddress());
assertEquals(intermediateClientRequest.getDownstreamClientSecure(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getDownstreamClientSecure());
assertEquals(intermediateClientRequest.getClientIdentity(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getClientIdentity());
assertEquals(intermediateClientRequest.getClientName(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getClientName());
assertEquals(intermediateClientRequest.getSessionID(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getSessionID());
assertEquals(intermediateClientRequest.getRequestID(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getRequestID());
assertNotNull(intermediateClientRequest.getDownstreamRequest());
assertNotNull(intermediateClientRequest.toString());
final JSONOperationPurposeRequestControl operationPurpose = populatedLogMessage.getOperationPurposeRequestControl();
assertNotNull(operationPurpose);
assertNotNull(operationPurpose.getControlObject());
assertEquals(operationPurpose.getApplicationName(), DEFAULT_OPERATION_PURPOSE_REQUEST.getApplicationName());
assertEquals(operationPurpose.getApplicationVersion(), DEFAULT_OPERATION_PURPOSE_REQUEST.getApplicationVersion());
assertEquals(operationPurpose.getCodeLocation(), DEFAULT_OPERATION_PURPOSE_REQUEST.getCodeLocation());
assertEquals(operationPurpose.getRequestPurpose(), DEFAULT_OPERATION_PURPOSE_REQUEST.getRequestPurpose());
assertNotNull(operationPurpose.toString());
final JSONIntermediateClientResponseControl intermediateClientResponse = populatedLogMessage.getIntermediateClientResponseControl();
assertNotNull(intermediateClientResponse);
assertNotNull(intermediateClientResponse.getControlObject());
assertEquals(intermediateClientResponse.getUpstreamServerAddress(), DEFAULT_INTERMEDIATE_CLIENT_RESPONSE.getUpstreamServerAddress());
assertEquals(intermediateClientResponse.getUpstreamServerSecure(), DEFAULT_INTERMEDIATE_CLIENT_RESPONSE.getUpstreamServerSecure());
assertEquals(intermediateClientResponse.getServerName(), DEFAULT_INTERMEDIATE_CLIENT_RESPONSE.getServerName());
assertEquals(intermediateClientResponse.getSessionID(), DEFAULT_INTERMEDIATE_CLIENT_RESPONSE.getSessionID());
assertEquals(intermediateClientResponse.getResponseID(), DEFAULT_INTERMEDIATE_CLIENT_RESPONSE.getResponseID());
assertNotNull(intermediateClientResponse.getUpstreamResponse());
assertNotNull(intermediateClientResponse.toString());
// Message-specific fields.
assertEquals(populatedLogMessage.getBaseDN(), "cn=base,cn=dn");
assertEquals(populatedLogMessage.getScope(), SearchScope.SUB);
assertEquals(populatedLogMessage.getFilter(), "(filter=value)");
assertEquals(populatedLogMessage.getSizeLimit().intValue(), 2345);
assertEquals(populatedLogMessage.getTimeLimitSeconds().intValue(), 3456);
assertEquals(populatedLogMessage.getDereferencePolicy(), DereferencePolicy.NEVER);
assertEquals(populatedLogMessage.getTypesOnly(), Boolean.FALSE);
assertEquals(populatedLogMessage.getRequestedAttributes(), Arrays.asList("requested-attr-1", "requested-attr-2"));
assertEquals(populatedLogMessage.getUnindexed(), Boolean.FALSE);
// Make sure there are no more messages to read.
assertNull(reader.readMessage());
}
}
Aggregations