use of com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField in project ldapsdk by pingidentity.
the class TextFormattedAccessLogFieldsTestCase method testValidateFields.
/**
* Tests to ensure that all fields defined in the class are available via the
* {@code getDefinedFields} method with the appropriate constant name.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testValidateFields() throws Exception {
assertNotNull(TextFormattedAccessLogFields.getDefinedFields());
assertFalse(TextFormattedAccessLogFields.getDefinedFields().isEmpty());
int numFieldConstants = 0;
for (final Field f : TextFormattedAccessLogFields.class.getDeclaredFields()) {
if (f.getType().isAssignableFrom(LogField.class)) {
numFieldConstants++;
final String fieldName = f.getName();
assertTrue(TextFormattedAccessLogFields.getDefinedFields().containsKey(fieldName), "Did not find expected field '" + fieldName + "' in the defined " + "set of constants.");
assertNotNull(TextFormattedAccessLogFields.getFieldForConstantName(fieldName));
assertNotNull(TextFormattedAccessLogFields.getFieldForConstantName(fieldName.toLowerCase().replace('_', '-')));
final LogField logField = TextFormattedAccessLogFields.getFieldForConstantName(fieldName);
assertNotNull(logField);
assertNotNull(logField.getConstantName());
assertEquals(logField.getConstantName(), fieldName);
}
}
assertEquals(numFieldConstants, TextFormattedAccessLogFields.getDefinedFields().size());
assertNull(TextFormattedAccessLogFields.getFieldForConstantName("THIS_NAME_DOES_NOT_CORRESPOND_TO_ANY_DEFINED_FIELD"));
}
use of com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField in project ldapsdk by pingidentity.
the class JSONFormattedAccessLogFieldsTestCase method testValidateFields.
/**
* Tests to ensure that all fields defined in the class are available via the
* {@code getDefinedFields} method with the appropriate constant name.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testValidateFields() throws Exception {
assertNotNull(JSONFormattedAccessLogFields.getDefinedFields());
assertFalse(JSONFormattedAccessLogFields.getDefinedFields().isEmpty());
int numFieldConstants = 0;
for (final Field f : JSONFormattedAccessLogFields.class.getDeclaredFields()) {
if (f.getType().isAssignableFrom(LogField.class)) {
numFieldConstants++;
final String fieldName = f.getName();
assertTrue(JSONFormattedAccessLogFields.getDefinedFields().containsKey(fieldName), "Did not find expected field '" + fieldName + "' in the defined " + "set of constants.");
assertNotNull(JSONFormattedAccessLogFields.getFieldForConstantName(fieldName));
assertNotNull(JSONFormattedAccessLogFields.getFieldForConstantName(fieldName.toLowerCase().replace('_', '-')));
final LogField logField = JSONFormattedAccessLogFields.getFieldForConstantName(fieldName);
assertNotNull(logField);
assertNotNull(logField.getConstantName());
assertEquals(logField.getConstantName(), fieldName);
}
}
assertEquals(numFieldConstants, JSONFormattedAccessLogFields.getDefinedFields().size());
assertNull(JSONFormattedAccessLogFields.getFieldForConstantName("THIS_NAME_DOES_NOT_CORRESPOND_TO_ANY_DEFINED_FIELD"));
}
use of com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField in project ldapsdk by pingidentity.
the class JSONLogMessageTestCase method testGetFirstValue.
/**
* Tests the methods for retrieving the first value for a given field.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetFirstValue() throws Exception {
// Test with a field whose value is a single string.
JSONObject o = createMinimalMessageObject(CONNECT, null, createField(CONNECT_FROM_ADDRESS, "1.2.3.4"));
JSONAccessLogMessage m = new JSONConnectAccessLogMessage(o);
assertEquals(m.getFirstValue(CONNECT_FROM_ADDRESS), new JSONString("1.2.3.4"));
// Test with a field whose value is a single Boolean.
o = createMinimalMessageObject(CONNECT, null, createField(UNCACHED_DATA_ACCESSED, true));
m = new JSONConnectAccessLogMessage(o);
assertEquals(m.getFirstValue(UNCACHED_DATA_ACCESSED), JSONBoolean.TRUE);
// Test with a field whose value is a non-empty array of strings.
o = createMinimalMessageObject(CONNECT, null, createField(REQUEST_CONTROL_OIDS, "1.2.3.4", "5.6.7.8"));
m = new JSONConnectAccessLogMessage(o);
assertEquals(m.getFirstValue(REQUEST_CONTROL_OIDS), new JSONString("1.2.3.4"));
// Test with a field whose value is a non-empty array of non-strings.
final LogField testField = new LogField("testField", IntegerLogFieldSyntax.getInstance());
o = createMinimalMessageObject(CONNECT, null, new JSONField("testField", new JSONArray(new JSONNumber(1L), new JSONNumber(2L), new JSONNumber(3L), new JSONNumber(4L))));
m = new JSONConnectAccessLogMessage(o);
assertEquals(m.getFirstValue(testField), new JSONNumber(1L));
// Test with a field whose value is an empty array.
o = createMinimalMessageObject(CONNECT, null, createField(REQUEST_CONTROL_OIDS));
m = new JSONConnectAccessLogMessage(o);
assertNull(m.getFirstValue(REQUEST_CONTROL_OIDS));
}
use of com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField in project ldapsdk by pingidentity.
the class JSONLogMessageTestCase method testGetStringSet.
/**
* Tests the methods for getting a string list from a JSON object.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetStringSet() throws Exception {
// Test with a field whose value is an array of strings.
JSONObject o = createMinimalMessageObject(CONNECT, null, createField(REQUEST_CONTROL_OIDS, "1.2.3.4", "5.6.7.8"));
JSONAccessLogMessage m = new JSONConnectAccessLogMessage(o);
assertEquals(m.getStringSet(REQUEST_CONTROL_OIDS), StaticUtils.setOf("1.2.3.4", "5.6.7.8"));
// Test with a field whose value is a single string.
o = createMinimalMessageObject(CONNECT, null, createField(REQUEST_CONTROL_OIDS, "1.2.3.4"));
m = new JSONConnectAccessLogMessage(o);
assertEquals(m.getStringSet(REQUEST_CONTROL_OIDS), Collections.singleton("1.2.3.4"));
// Test with a field whose value is a single number.
o = createMinimalMessageObject(CONNECT, null, createField(OPERATION_ID, 1L));
m = new JSONConnectAccessLogMessage(o);
assertEquals(m.getStringSet(OPERATION_ID), Collections.emptySet());
// Test with a field whose value is an array of non-strings.
final LogField testField = new LogField("testField", new StringLogFieldSyntax(100));
o = createMinimalMessageObject(CONNECT, null, new JSONField(testField.getFieldName(), new JSONArray(JSONBoolean.TRUE, new JSONNumber("1234"))));
m = new JSONConnectAccessLogMessage(o);
assertEquals(m.getStringSet(testField), Collections.emptySet());
// Test with a nonexistent field.
o = createMinimalMessageObject(CONNECT, null);
m = new JSONConnectAccessLogMessage(o);
assertEquals(m.getStringSet(REQUEST_CONTROL_OIDS), Collections.emptySet());
}
use of com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField in project ldapsdk by pingidentity.
the class JSONLogMessageTestCase method testGetRFC3339Timestamp.
/**
* Tests the methods for getting an RFC 3339 timestamp value from a JSON
* object.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetRFC3339Timestamp() throws Exception {
// Test with a field whose value is a valid generalized time string.
final LogField testField = new LogField("test-gt", RFC3339TimestampLogFieldSyntax.getInstance());
JSONObject o = createMinimalMessageObject(CONNECT, null, createField(testField, StaticUtils.encodeRFC3339Time(DEFAULT_TIMESTAMP_DATE)));
JSONAccessLogMessage m = new JSONConnectAccessLogMessage(o);
assertEquals(m.getRFC3339Timestamp(testField), DEFAULT_TIMESTAMP_DATE);
assertEquals(m.getRFC3339TimestampNoThrow(testField), DEFAULT_TIMESTAMP_DATE);
// Test with a field that is missing.
o = createMinimalMessageObject(CONNECT, null);
m = new JSONConnectAccessLogMessage(o);
assertNull(m.getRFC3339Timestamp(testField));
assertNull(m.getRFC3339TimestampNoThrow(testField));
// Test with a field that has an invalid string value.
o = createMinimalMessageObject(CONNECT, null, createField(testField, "invalid"));
m = new JSONConnectAccessLogMessage(o);
try {
m.getRFC3339Timestamp(testField);
fail("Expected an exception for an invalid string value.");
} catch (final LogException e) {
// This was expected.
}
assertNull(m.getRFC3339TimestampNoThrow(testField));
// Test with a field that has a non-string value.
o = createMinimalMessageObject(CONNECT, null, createField(testField, 1234L));
m = new JSONConnectAccessLogMessage(o);
try {
m.getRFC3339Timestamp(testField);
fail("Expected an exception for an invalid value type.");
} catch (final LogException e) {
// This was expected.
}
assertNull(m.getRFC3339TimestampNoThrow(UNCACHED_DATA_ACCESSED));
}
Aggregations