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);
}
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));
}
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);
}
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}\" }"));
}
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);
}
Aggregations