use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class SubstringJSONObjectFilterTestCase method testSingleContains.
/**
* Tests the behavior of a filter that only uses a single contains component.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSingleContains() throws Exception {
SubstringJSONObjectFilter f = new SubstringJSONObjectFilter("test-field", null, "defghi", null);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "test-field"), new JSONField("contains", "defghi")));
f = (SubstringJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
assertNotNull(f);
assertNotNull(f.getField());
assertEquals(f.getField(), Collections.singletonList("test-field"));
assertNull(f.getStartsWith());
assertNotNull(f.getContains());
assertEquals(f.getContains(), Collections.singletonList("defghi"));
assertNull(f.getEndsWith());
assertFalse(f.caseSensitive());
assertNotNull(f.getFilterType());
assertEquals(f.getFilterType(), "substring");
assertNotNull(f.getRequiredFieldNames());
assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Collections.singletonList("field")));
assertNotNull(f.getOptionalFieldNames());
assertEquals(f.getOptionalFieldNames(), new HashSet<String>(Arrays.asList("startsWith", "contains", "endsWith", "caseSensitive")));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "defghi"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "DeFgHi"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "DEFGHI"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "defabcghijkl"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "defghijkl"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABCDEFGHI"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abcdefghijkl"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABCDEFGHIJKL"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "defghi"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONArray.EMPTY_ARRAY))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("defghi"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("ahcDEFghiJKL"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("abcdef"), new JSONString("ghijkl"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("abcjkl"), new JSONString("defghi"))))));
f.setCaseSensitive(true);
assertTrue(f.caseSensitive());
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "test-field"), new JSONField("contains", "defghi"), new JSONField("caseSensitive", true)));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "defghi"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "DeFgHi"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "DEFGHI"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "defghijkl"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABCDEFGHI"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abcdefghijkl"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABCDEFGHIJKL"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONArray.EMPTY_ARRAY))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("defghi"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("ahcDEFghiJKL"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("abcdef"), new JSONString("ghijkl"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("abcjkl"), new JSONString("defghi"))))));
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class JSONLogFieldSyntax method tokenizeEntireValue.
/**
* {@inheritDoc}
*/
@Override()
public void tokenizeEntireValue(@NotNull final JSONObject value, @NotNull final byte[] pepper, @NotNull final ByteStringBuffer buffer) {
final JSONObject tokenizedObject = new JSONObject(new JSONField("tokenized", tokenize(value.toNormalizedString(), pepper)));
buffer.append(tokenizedObject.toSingleLineString());
}
Aggregations