use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class SubstringJSONObjectFilterTestCase method testMultipleContains.
/**
* Tests the behavior of a filter that only uses multiple contains components.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testMultipleContains() throws Exception {
SubstringJSONObjectFilter f = new SubstringJSONObjectFilter(Collections.singletonList("test-field"), null, Arrays.asList("aba", "bab"), null);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "test-field"), new JSONField("contains", new JSONArray(new JSONString("aba"), new JSONString("bab")))));
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(), Arrays.asList("aba", "bab"));
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", "ababab"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABABAB"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abaxbab"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABAxBAB"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "xabaxbabx"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "xABAxBABx"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abab"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bababa"))));
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("aBABab"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("aba"), new JSONString("bab"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("ABAab"), new JSONString("BABab"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("AbAbAbAbA"), new JSONString("BaBaBaBaB"))))));
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", new JSONArray(new JSONString("aba"), new JSONString("bab"))), new JSONField("caseSensitive", true)));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ababab"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABABAB"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abaxbab"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABAxBAB"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "xabaxbabx"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "xABAxBABx"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abab"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bababa"))));
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("ababab"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("aba"), new JSONString("bab"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("ABAab"), new JSONString("BABab"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("AbAbAbAbA"), new JSONString("BaBaBaBaB"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("ababababa"), new JSONString("BaBaBaBaB"))))));
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class SubstringJSONObjectFilterTestCase method testGetAndSetFields.
/**
* Tests the behavior of the methods used to get and set the field name.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetAndSetFields() throws Exception {
final SubstringJSONObjectFilter f = new SubstringJSONObjectFilter("a", "b", "c", "d");
f.setCaseSensitive(true);
assertNotNull(f.getField());
assertEquals(f.getField(), Collections.singletonList("a"));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "a"), new JSONField("startsWith", "b"), new JSONField("contains", "c"), new JSONField("endsWith", "d"), new JSONField("caseSensitive", true)));
f.setField("different");
assertNotNull(f.getField());
assertEquals(f.getField(), Collections.singletonList("different"));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "different"), new JSONField("startsWith", "b"), new JSONField("contains", "c"), new JSONField("endsWith", "d"), new JSONField("caseSensitive", true)));
f.setField("first", "second");
assertNotNull(f.getField());
assertEquals(f.getField(), Arrays.asList("first", "second"));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", new JSONArray(new JSONString("first"), new JSONString("second"))), new JSONField("startsWith", "b"), new JSONField("contains", "c"), new JSONField("endsWith", "d"), new JSONField("caseSensitive", true)));
try {
f.setField();
fail("Expected an exception from setField()");
} catch (final LDAPSDKUsageException e) {
// This was expected.
}
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class SubstringJSONObjectFilterTestCase method testDecodeNoSubstringComponents.
/**
* Tests the behavior of the decode method with a JSON object that doesn't
* include any of the substring components.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { JSONException.class })
public void testDecodeNoSubstringComponents() throws Exception {
final JSONObject o = new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "test-field"), new JSONField("caseSensitive", true));
JSONObjectFilter.decode(o);
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class SubstringJSONObjectFilterTestCase method testStartsWith.
/**
* Tests the behavior of a filter that only uses the startsWith component.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testStartsWith() throws Exception {
SubstringJSONObjectFilter f = new SubstringJSONObjectFilter("test-field", "abc", null, null);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "test-field"), new JSONField("startsWith", "abc")));
f = (SubstringJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
assertNotNull(f);
assertNotNull(f.getField());
assertEquals(f.getField(), Collections.singletonList("test-field"));
assertNotNull(f.getStartsWith());
assertEquals(f.getStartsWith(), "abc");
assertNotNull(f.getContains());
assertTrue(f.getContains().isEmpty());
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", "abc"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "Abc"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABC"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ab"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abcdefghijkl"))));
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", "defabcghi"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "abc"))));
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("abcdef"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("abc"), new JSONString("DEF"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("def"), new JSONString("ABC"))))));
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("startsWith", "abc"), new JSONField("caseSensitive", true)));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abc"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "Abc"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABC"))));
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", "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("abcdef"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("abc"), new JSONString("DEF"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONBoolean.TRUE, new JSONString("abc"), JSONNull.NULL, new JSONString("DEF"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("def"), new JSONString("ABC"))))));
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class EqualsJSONObjectFilterTestCase method testTopLevelFieldNull.
/**
* Provides test coverage for the case in which a filter references a
* top-level field and a {@code JSONNull} value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testTopLevelFieldNull() throws Exception {
EqualsJSONObjectFilter f = new EqualsJSONObjectFilter("top-level-field", JSONNull.NULL);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equals"), new JSONField("field", "top-level-field"), new JSONField("value", JSONNull.NULL)));
f = (EqualsJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
assertNotNull(f);
assertNotNull(f.getField());
assertEquals(f.getField(), Collections.singletonList("top-level-field"));
assertNotNull(f.getValue());
assertEquals(f.getValue(), JSONNull.NULL);
assertFalse(f.caseSensitive());
assertNotNull(f.getFilterType());
assertEquals(f.getFilterType(), "equals");
assertNotNull(f.getRequiredFieldNames());
assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Arrays.asList("field", "value")));
assertNotNull(f.getOptionalFieldNames());
assertEquals(f.getOptionalFieldNames(), new HashSet<String>(Collections.singletonList("caseSensitive")));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", JSONNull.NULL))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONNull()))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(JSONNull.NULL, JSONBoolean.TRUE)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(JSONBoolean.TRUE, JSONNull.NULL)))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("top-level-field", JSONNull.NULL))))));
}
Aggregations