use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.
the class StringLogFieldSyntaxTestCase 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 StringLogFieldSyntax syntax = new StringLogFieldSyntax(10);
final JSONBuffer buffer = new JSONBuffer();
buffer.beginObject();
syntax.logSanitizedFieldToJSONFormattedLog("abc", "ThisIsALongerValue", buffer);
buffer.endObject();
assertEquals(buffer.toString(), "{ \"abc\":\"ThisIsALon{8 more characters}\" }");
buffer.clear();
buffer.beginObject();
syntax.logCompletelyRedactedFieldToJSONFormattedLog("def", buffer);
buffer.endObject();
assertEquals(buffer.toString(), "{ \"def\":\"{REDACTED}\" }");
buffer.clear();
buffer.beginObject();
syntax.logRedactedComponentsFieldToJSONFormattedLog("ghi", "ThisIsALongerValue", buffer);
buffer.endObject();
assertEquals(buffer.toString(), "{ \"ghi\":\"{REDACTED}\" }");
buffer.clear();
buffer.beginObject();
final byte[] pepper = StaticUtils.randomBytes(8, false);
syntax.logCompletelyTokenizedFieldToJSONFormattedLog("jkl", "ThisIsALongerValue", pepper, buffer);
buffer.endObject();
final String completelyTokenizedString = buffer.toString();
assertTrue(completelyTokenizedString.startsWith("{ \"jkl\":\"{TOKENIZED:"));
assertTrue(completelyTokenizedString.endsWith("}\" }"));
buffer.clear();
buffer.beginObject();
syntax.logTokenizedComponentsFieldToJSONFormattedLog("mno", "ThisIsALongerValue", pepper, buffer);
buffer.endObject();
final String tokenizedComponentsString = buffer.toString();
assertTrue(tokenizedComponentsString.startsWith("{ \"mno\":\"{TOKENIZED:"));
assertEquals(tokenizedComponentsString, "{ \"mno\":" + completelyTokenizedString.substring(8));
}
use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.
the class FilterLogFieldSyntaxTestCase 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> includedAttributes = StaticUtils.setOf("uid");
final Set<String> excludedAttributes = Collections.emptySet();
final FilterLogFieldSyntax syntax = new FilterLogFieldSyntax(100, null, includedAttributes, excludedAttributes);
final JSONBuffer buffer = new JSONBuffer();
syntax.logSanitizedValueToJSONFormattedLog(Filter.createEqualityFilter("uid", "test.user"), buffer);
assertEquals(buffer.toString(), "\"(uid=test.user)\"");
buffer.clear();
syntax.logCompletelyRedactedValueToJSONFormattedLog(buffer);
assertEquals(buffer.toString(), "\"(redacted={REDACTED})\"");
buffer.clear();
syntax.logRedactedComponentsValueToJSONFormattedLog(Filter.createEqualityFilter("uid", "test.user"), buffer);
assertEquals(buffer.toString(), "\"(uid={REDACTED})\"");
buffer.clear();
final byte[] pepper = StaticUtils.randomBytes(8, false);
syntax.logCompletelyTokenizedValueToJSONFormattedLog(Filter.createEqualityFilter("uid", "test.user"), pepper, buffer);
final String completelyTokenizedString = buffer.toString();
assertTrue(completelyTokenizedString.startsWith("\"(tokenized={TOKENIZED:"));
assertTrue(completelyTokenizedString.endsWith("})\""));
buffer.clear();
syntax.logTokenizedComponentsValueToJSONFormattedLog(Filter.createEqualityFilter("uid", "test.user"), pepper, buffer);
final String tokenizedComponentsString = buffer.toString();
assertTrue(tokenizedComponentsString.startsWith("\"(uid={TOKENIZED:"));
assertTrue(tokenizedComponentsString.endsWith("})\""));
}
use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.
the class FloatingPointLogFieldSyntaxTestCase 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 FloatingPointLogFieldSyntax syntax = FloatingPointLogFieldSyntax.getInstance();
final JSONBuffer buffer = new JSONBuffer();
buffer.beginObject();
syntax.logSanitizedFieldToJSONFormattedLog("abc", 1.5d, buffer);
buffer.endObject();
assertEquals(buffer.toString(), "{ \"abc\":1.500 }");
buffer.clear();
buffer.beginObject();
syntax.logCompletelyRedactedFieldToJSONFormattedLog("def", buffer);
buffer.endObject();
assertEquals(buffer.toString(), "{ \"def\":-999999.999999 }");
buffer.clear();
buffer.beginObject();
syntax.logRedactedComponentsFieldToJSONFormattedLog("ghi", 1.5d, buffer);
buffer.endObject();
assertEquals(buffer.toString(), "{ \"ghi\":-999999.999999 }");
buffer.clear();
buffer.beginObject();
final byte[] pepper = StaticUtils.randomBytes(8, false);
syntax.logCompletelyTokenizedFieldToJSONFormattedLog("jkl", 1.5d, pepper, buffer);
buffer.endObject();
final String completelyTokenizedString = buffer.toString();
assertTrue(completelyTokenizedString.startsWith("{ \"jkl\":-999999."));
assertTrue(completelyTokenizedString.endsWith(" }"));
assertFalse(completelyTokenizedString.equals("{ \"jkl\":-999999.999999 }"));
buffer.clear();
buffer.beginObject();
syntax.logTokenizedComponentsFieldToJSONFormattedLog("mno", 1.5d, pepper, buffer);
buffer.endObject();
final String tokenizedComponentsString = buffer.toString();
assertTrue(tokenizedComponentsString.startsWith("{ \"mno\":-999999."));
assertTrue(tokenizedComponentsString.endsWith(" }"));
assertEquals(tokenizedComponentsString, "{ \"mno\"" + completelyTokenizedString.substring(7));
}
use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.
the class GeneralizedTimeLogFieldSyntaxTestCase 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 GeneralizedTimeLogFieldSyntax syntax = GeneralizedTimeLogFieldSyntax.getInstance();
final Date now = new Date();
final JSONBuffer buffer = new JSONBuffer();
syntax.logSanitizedValueToJSONFormattedLog(now, buffer);
assertEquals(buffer.toString(), '"' + StaticUtils.encodeGeneralizedTime(now) + '"');
buffer.clear();
syntax.logCompletelyRedactedValueToJSONFormattedLog(buffer);
assertEquals(buffer.toString(), "\"99990101000000.000Z\"");
buffer.clear();
syntax.logRedactedComponentsValueToJSONFormattedLog(now, buffer);
assertEquals(buffer.toString(), "\"99990101000000.000Z\"");
buffer.clear();
final byte[] pepper = StaticUtils.randomBytes(8, false);
syntax.logCompletelyTokenizedValueToJSONFormattedLog(now, pepper, buffer);
final String completelyTokenizedString = buffer.toString();
assertTrue(completelyTokenizedString.startsWith("\"8888"));
assertTrue(completelyTokenizedString.endsWith("Z\""));
buffer.clear();
syntax.logTokenizedComponentsValueToJSONFormattedLog(now, pepper, buffer);
final String tokenizedComponentsString = buffer.toString();
assertTrue(tokenizedComponentsString.startsWith("\"8888"));
assertEquals(tokenizedComponentsString, completelyTokenizedString);
}
use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.
the class IntegerLogFieldSyntaxTestCase 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 IntegerLogFieldSyntax syntax = IntegerLogFieldSyntax.getInstance();
final JSONBuffer buffer = new JSONBuffer();
buffer.beginObject();
syntax.logSanitizedFieldToJSONFormattedLog("abc", 1234L, buffer);
buffer.endObject();
assertEquals(buffer.toString(), "{ \"abc\":1234 }");
buffer.clear();
buffer.beginObject();
syntax.logCompletelyRedactedFieldToJSONFormattedLog("def", buffer);
buffer.endObject();
assertEquals(buffer.toString(), "{ \"def\":-999999999999999999 }");
buffer.clear();
buffer.beginObject();
syntax.logRedactedComponentsFieldToJSONFormattedLog("ghi", 1234L, buffer);
buffer.endObject();
assertEquals(buffer.toString(), "{ \"ghi\":-999999999999999999 }");
buffer.clear();
buffer.beginObject();
final byte[] pepper = StaticUtils.randomBytes(8, false);
syntax.logCompletelyTokenizedFieldToJSONFormattedLog("jkl", 1234L, pepper, buffer);
buffer.endObject();
final String completelyTokenizedString = buffer.toString();
assertTrue(completelyTokenizedString.startsWith("{ \"jkl\":-999999999"));
assertTrue(completelyTokenizedString.endsWith(" }"));
assertFalse(completelyTokenizedString.equals("{ \"jkl\":-999999999999999999 }"));
buffer.clear();
buffer.beginObject();
syntax.logTokenizedComponentsFieldToJSONFormattedLog("mno", 1234L, pepper, buffer);
buffer.endObject();
final String tokenizedComponentsString = buffer.toString();
assertTrue(tokenizedComponentsString.startsWith("{ \"mno\":-999999999"));
assertTrue(tokenizedComponentsString.endsWith(" }"));
assertEquals(tokenizedComponentsString, "{ \"mno\"" + completelyTokenizedString.substring(7));
}
Aggregations