Search in sources :

Example 1 with StringLogFieldSyntax

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());
}
Also used : StringLogFieldSyntax(com.unboundid.ldap.sdk.unboundidds.logs.v2.syntax.StringLogFieldSyntax) JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONField(com.unboundid.util.json.JSONField) JSONNumber(com.unboundid.util.json.JSONNumber) LogField(com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField) Test(org.testng.annotations.Test)

Example 2 with StringLogFieldSyntax

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());
}
Also used : StringLogFieldSyntax(com.unboundid.ldap.sdk.unboundidds.logs.v2.syntax.StringLogFieldSyntax) JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONField(com.unboundid.util.json.JSONField) JSONNumber(com.unboundid.util.json.JSONNumber) LogField(com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField) Test(org.testng.annotations.Test)

Aggregations

LogField (com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField)2 StringLogFieldSyntax (com.unboundid.ldap.sdk.unboundidds.logs.v2.syntax.StringLogFieldSyntax)2 JSONArray (com.unboundid.util.json.JSONArray)2 JSONField (com.unboundid.util.json.JSONField)2 JSONNumber (com.unboundid.util.json.JSONNumber)2 JSONObject (com.unboundid.util.json.JSONObject)2 Test (org.testng.annotations.Test)2