use of com.unboundid.ldap.sdk.unboundidds.logs.v2.syntax.StringLogFieldSyntax 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.syntax.StringLogFieldSyntax in project ldapsdk by pingidentity.
the class JSONLogMessageTestCase method testGetStringList.
/**
* Tests the methods for getting a string list from a JSON object.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetStringList() 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.getStringList(REQUEST_CONTROL_OIDS), Arrays.asList("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.getStringList(REQUEST_CONTROL_OIDS), Collections.singletonList("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.getStringList(OPERATION_ID), Collections.emptyList());
// 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.getStringList(testField), Collections.emptyList());
// Test with a nonexistent field.
o = createMinimalMessageObject(CONNECT, null);
m = new JSONConnectAccessLogMessage(o);
assertEquals(m.getStringList(REQUEST_CONTROL_OIDS), Collections.emptyList());
}
Aggregations