Search in sources :

Example 46 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class FloatingPointLogFieldSyntaxTestCase method testJSONValueLogMethods.

/**
 * Tests the methods that may be used for logging JSON-formatted values
 * (without field names).
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testJSONValueLogMethods() throws Exception {
    final FloatingPointLogFieldSyntax syntax = FloatingPointLogFieldSyntax.getInstance();
    final JSONBuffer buffer = new JSONBuffer();
    syntax.logSanitizedValueToJSONFormattedLog(1.5d, buffer);
    assertEquals(buffer.toString(), "1.500");
    buffer.clear();
    syntax.logCompletelyRedactedValueToJSONFormattedLog(buffer);
    assertEquals(buffer.toString(), "-999999.999999");
    buffer.clear();
    syntax.logRedactedComponentsValueToJSONFormattedLog(1.5d, buffer);
    assertEquals(buffer.toString(), "-999999.999999");
    buffer.clear();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedValueToJSONFormattedLog(1.5d, pepper, buffer);
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("-999999."));
    assertFalse(completelyTokenizedString.equals("-999999.999999"));
    buffer.clear();
    syntax.logTokenizedComponentsValueToJSONFormattedLog(1.5d, pepper, buffer);
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("-999999."));
    assertEquals(tokenizedComponentsString, completelyTokenizedString);
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) Test(org.testng.annotations.Test)

Example 47 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class GeneralizedTimeLogFieldSyntaxTestCase method testJSONLogMethods.

/**
 * Tests the methods that may be used for logging JSON-formatted messages.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testJSONLogMethods() throws Exception {
    final GeneralizedTimeLogFieldSyntax syntax = GeneralizedTimeLogFieldSyntax.getInstance();
    final Date now = new Date();
    final JSONBuffer buffer = new JSONBuffer();
    buffer.beginObject();
    syntax.logSanitizedFieldToJSONFormattedLog("abc", now, buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"abc\":\"" + StaticUtils.encodeGeneralizedTime(now) + "\" }");
    buffer.clear();
    buffer.beginObject();
    syntax.logCompletelyRedactedFieldToJSONFormattedLog("def", buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"def\":\"99990101000000.000Z\" }");
    buffer.clear();
    buffer.beginObject();
    syntax.logRedactedComponentsFieldToJSONFormattedLog("ghi", now, buffer);
    buffer.endObject();
    assertEquals(buffer.toString(), "{ \"ghi\":\"99990101000000.000Z\" }");
    buffer.clear();
    buffer.beginObject();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedFieldToJSONFormattedLog("jkl", now, pepper, buffer);
    buffer.endObject();
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("{ \"jkl\":\"8888"));
    assertTrue(completelyTokenizedString.endsWith("Z\" }"));
    buffer.clear();
    buffer.beginObject();
    syntax.logTokenizedComponentsFieldToJSONFormattedLog("mno", now, pepper, buffer);
    buffer.endObject();
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("{ \"mno\":\"8888"));
    assertEquals(tokenizedComponentsString, "{ \"mno\":" + completelyTokenizedString.substring(8));
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 48 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class IntegerLogFieldSyntaxTestCase method testJSONValueLogMethods.

/**
 * Tests the methods that may be used for logging JSON-formatted values
 * (without field names).
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testJSONValueLogMethods() throws Exception {
    final IntegerLogFieldSyntax syntax = IntegerLogFieldSyntax.getInstance();
    final JSONBuffer buffer = new JSONBuffer();
    syntax.logSanitizedValueToJSONFormattedLog(1234L, buffer);
    assertEquals(buffer.toString(), "1234");
    buffer.clear();
    syntax.logCompletelyRedactedValueToJSONFormattedLog(buffer);
    assertEquals(buffer.toString(), "-999999999999999999");
    buffer.clear();
    syntax.logRedactedComponentsValueToJSONFormattedLog(1234L, buffer);
    assertEquals(buffer.toString(), "-999999999999999999");
    buffer.clear();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedValueToJSONFormattedLog(1234L, pepper, buffer);
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("-999999999"));
    assertFalse(completelyTokenizedString.equals("-999999999999999999"));
    buffer.clear();
    syntax.logTokenizedComponentsValueToJSONFormattedLog(1234L, pepper, buffer);
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("-999999999"));
    assertEquals(tokenizedComponentsString, completelyTokenizedString);
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) Test(org.testng.annotations.Test)

Example 49 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class JSONLogFieldSyntaxTestCase method testJSONValueLogMethods.

/**
 * Tests the methods that may be used for logging JSON-formatted values
 * (without field names).
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testJSONValueLogMethods() throws Exception {
    final Set<String> includeFields = StaticUtils.setOf("a");
    final JSONLogFieldSyntax syntax = new JSONLogFieldSyntax(10, includeFields, null);
    final JSONObject o = new JSONObject(new JSONField("a", "foo"), new JSONField("b", "ThisIsALongerValue"));
    final JSONBuffer buffer = new JSONBuffer();
    syntax.logSanitizedValueToJSONFormattedLog(o, buffer);
    assertEquals(buffer.toString(), "{ \"a\":\"foo\", " + "\"b\":\"ThisIsALon{8 more characters}\" }");
    buffer.clear();
    syntax.logCompletelyRedactedValueToJSONFormattedLog(buffer);
    assertEquals(buffer.toString(), "{ \"redacted\":\"{REDACTED}\" }");
    buffer.clear();
    syntax.logRedactedComponentsValueToJSONFormattedLog(o, buffer);
    assertEquals(buffer.toString(), "{ \"a\":\"{REDACTED}\", " + "\"b\":\"ThisIsALon{8 more characters}\" }");
    buffer.clear();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedValueToJSONFormattedLog(o, pepper, buffer);
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("{ \"tokenized\":\"{TOKENIZED:"));
    assertTrue(completelyTokenizedString.endsWith("}\" }"));
    buffer.clear();
    syntax.logTokenizedComponentsValueToJSONFormattedLog(o, pepper, buffer);
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("{ \"a\":\"{TOKENIZED:"));
    assertTrue(tokenizedComponentsString.endsWith("}\", \"b\":\"ThisIsALon{8 more characters}\" }"));
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONBuffer(com.unboundid.util.json.JSONBuffer) JSONField(com.unboundid.util.json.JSONField) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 50 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class StringLogFieldSyntaxTestCase method testJSONValueLogMethods.

/**
 * Tests the methods that may be used for logging JSON-formatted values
 * (without field names).
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testJSONValueLogMethods() throws Exception {
    final StringLogFieldSyntax syntax = new StringLogFieldSyntax(10);
    final JSONBuffer buffer = new JSONBuffer();
    syntax.logSanitizedValueToJSONFormattedLog("ThisIsALongerValue", buffer);
    assertEquals(buffer.toString(), "\"ThisIsALon{8 more characters}\"");
    buffer.clear();
    syntax.logCompletelyRedactedValueToJSONFormattedLog(buffer);
    assertEquals(buffer.toString(), "\"{REDACTED}\"");
    buffer.clear();
    syntax.logRedactedComponentsValueToJSONFormattedLog("ThisIsALongerValue", buffer);
    assertEquals(buffer.toString(), "\"{REDACTED}\"");
    buffer.clear();
    final byte[] pepper = StaticUtils.randomBytes(8, false);
    syntax.logCompletelyTokenizedValueToJSONFormattedLog("ThisIsALongerValue", pepper, buffer);
    final String completelyTokenizedString = buffer.toString();
    assertTrue(completelyTokenizedString.startsWith("\"{TOKENIZED:"));
    assertTrue(completelyTokenizedString.endsWith("}\""));
    buffer.clear();
    syntax.logTokenizedComponentsValueToJSONFormattedLog("ThisIsALongerValue", pepper, buffer);
    final String tokenizedComponentsString = buffer.toString();
    assertTrue(tokenizedComponentsString.startsWith("\"{TOKENIZED:"));
    assertEquals(tokenizedComponentsString, completelyTokenizedString);
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) Test(org.testng.annotations.Test)

Aggregations

JSONBuffer (com.unboundid.util.json.JSONBuffer)73 Test (org.testng.annotations.Test)20 NotNull (com.unboundid.util.NotNull)16 LogRecord (java.util.logging.LogRecord)12 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)8 Date (java.util.Date)5 LDAPException (com.unboundid.ldap.sdk.LDAPException)3 LDAPRuntimeException (com.unboundid.ldap.sdk.LDAPRuntimeException)3 JSONException (com.unboundid.util.json.JSONException)3 DN (com.unboundid.ldap.sdk.DN)2 RDN (com.unboundid.ldap.sdk.RDN)2 JSONField (com.unboundid.util.json.JSONField)2 JSONObject (com.unboundid.util.json.JSONObject)2 JSONString (com.unboundid.util.json.JSONString)2 AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)1 BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)1 CompareResponseProtocolOp (com.unboundid.ldap.protocol.CompareResponseProtocolOp)1 DeleteResponseProtocolOp (com.unboundid.ldap.protocol.DeleteResponseProtocolOp)1 ExtendedResponseProtocolOp (com.unboundid.ldap.protocol.ExtendedResponseProtocolOp)1 ModifyDNResponseProtocolOp (com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp)1