use of com.unboundid.util.json.JSONNull 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