use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class EqualsJSONObjectFilterTestCase method testTopLevelFieldArray.
/**
* Provides test coverage for the case in which a filter references a
* top-level field and an array value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testTopLevelFieldArray() throws Exception {
EqualsJSONObjectFilter f = new EqualsJSONObjectFilter("top-level-field", new JSONArray(new JSONString("foo"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL));
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equals"), new JSONField("field", "top-level-field"), new JSONField("value", new JSONArray(new JSONString("foo"), new JSONNumber(1234), JSONBoolean.TRUE, 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(), new JSONArray(new JSONString("foo"), new JSONNumber(1234), JSONBoolean.TRUE, 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")));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", "foo"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", 1234))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", true))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", JSONNull.NULL))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONString("foo"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONString("FOO"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL)))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(JSONNull.NULL, JSONBoolean.TRUE, new JSONNumber(1234), new JSONString("foo"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONString("bar"), new JSONArray(new JSONString("foo"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONString("foo"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL)))))));
f.setCaseSensitive(true);
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONString("foo"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL)))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONString("FOO"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONString("bar"), new JSONArray(new JSONString("foo"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONString("bar"), new JSONArray(new JSONString("Foo"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL))))));
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class EqualsJSONObjectFilterTestCase method testTopLevelFieldBoolean.
/**
* Provides test coverage for the case in which a filter references a
* top-level field and a Boolean value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testTopLevelFieldBoolean() throws Exception {
EqualsJSONObjectFilter f = new EqualsJSONObjectFilter("top-level-field", JSONBoolean.TRUE);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equals"), new JSONField("field", "top-level-field"), new JSONField("value", true)));
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(), new JSONBoolean(true));
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", true))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", false))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(JSONBoolean.TRUE, JSONBoolean.FALSE)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(JSONBoolean.FALSE, JSONBoolean.TRUE)))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("top-level-field", true))))));
f = new EqualsJSONObjectFilter("top-level-field", JSONBoolean.FALSE);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equals"), new JSONField("field", "top-level-field"), new JSONField("value", false)));
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(), new JSONBoolean(false));
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")));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", true))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", false))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(JSONBoolean.TRUE, JSONBoolean.FALSE)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(JSONBoolean.FALSE, JSONBoolean.TRUE)))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("top-level-field", true))))));
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class EqualsJSONObjectFilterTestCase method testTopLevelFieldNumber.
/**
* Provides test coverage for the case in which a filter references a
* top-level field and a {@code JSONNumber} value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testTopLevelFieldNumber() throws Exception {
EqualsJSONObjectFilter f = new EqualsJSONObjectFilter("top-level-field", new JSONNumber(1234));
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equals"), new JSONField("field", "top-level-field"), new JSONField("value", 1234)));
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(), new JSONNumber(1234));
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", 1234))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", 1234.0))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", 5678))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONNumber("1234.0"), new JSONNumber("5678"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONNumber("5678"), new JSONNumber("1.234e3"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("top-level-field", new JSONNumber(1234)))))));
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class EqualsJSONObjectFilterTestCase method testMultiLevelFields.
/**
* Provides test coverage for the case in which a filter references a
* non-top-level-field.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testMultiLevelFields() throws Exception {
EqualsJSONObjectFilter f = new EqualsJSONObjectFilter(Arrays.asList("top-level-field", "second-level-field"), new JSONString("foo"));
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equals"), new JSONField("field", new JSONArray(new JSONString("top-level-field"), new JSONString("second-level-field"))), new JSONField("value", "foo")));
f = (EqualsJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
assertNotNull(f);
assertNotNull(f.getField());
assertEquals(f.getField(), Arrays.asList("top-level-field", "second-level-field"));
assertNotNull(f.getValue());
assertEquals(f.getValue(), new JSONString("foo"));
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")));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", "foo"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("second-level-field", "foo"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("second-level-field", "FOO"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("second-level-field", "bar"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONObject(new JSONField("second-level-field", "foo")), new JSONObject(new JSONField("second-level-field", "bar")))))));
f = new EqualsJSONObjectFilter(Arrays.asList("top-level-field", "second-level-field", "third-level-field"), new JSONString("foo"));
f.setCaseSensitive(true);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equals"), new JSONField("field", new JSONArray(new JSONString("top-level-field"), new JSONString("second-level-field"), new JSONString("third-level-field"))), new JSONField("value", "foo"), new JSONField("caseSensitive", true)));
f = (EqualsJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
assertNotNull(f);
assertNotNull(f.getField());
assertEquals(f.getField(), Arrays.asList("top-level-field", "second-level-field", "third-level-field"));
assertNotNull(f.getValue());
assertEquals(f.getValue(), new JSONString("foo"));
assertTrue(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")));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", "foo"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("second-level-field", "foo"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("second-level-field", new JSONObject(new JSONField("third-level-field", "foo"))))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("second-level-field", new JSONObject(new JSONField("third-level-field", "FOO"))))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONObject(new JSONField("second-level-field", new JSONObject(new JSONField("third-level-field", "foo")))), new JSONObject(new JSONField("second-level-field", new JSONObject(new JSONField("third-level-field", "bar")))))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONObject(new JSONField("second-level-field", new JSONArray(new JSONObject(new JSONField("third-level-field", "foo"))))), new JSONObject(new JSONField("second-level-field", new JSONArray(new JSONObject(new JSONField("third-level-field", "bar"))))))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONObject(new JSONField("second-level-field", new JSONArray(new JSONObject(new JSONField("third-level-field", new JSONArray(new JSONString("foo"))))))), new JSONObject(new JSONField("second-level-field", new JSONArray(new JSONObject(new JSONField("third-level-field", new JSONArray(new JSONString("bar"))))))))))));
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class NegateJSONObjectFilterTestCase method testNegateFilter.
/**
* Tests the behavior of a negate filter under normal conditions.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testNegateFilter() throws Exception {
final EqualsJSONObjectFilter equalsFilter = new EqualsJSONObjectFilter("a", new JSONString("b"));
NegateJSONObjectFilter f = new NegateJSONObjectFilter(equalsFilter);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "negate"), new JSONField("negateFilter", equalsFilter.toJSONObject())));
f = (NegateJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
assertNotNull(f);
assertNotNull(f.getNegateFilter());
assertEquals(f.getNegateFilter(), equalsFilter);
assertNotNull(f.getFilterType());
assertEquals(f.getFilterType(), "negate");
assertNotNull(f.getRequiredFieldNames());
assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Collections.singletonList("negateFilter")));
assertNotNull(f.getOptionalFieldNames());
assertEquals(f.getOptionalFieldNames(), Collections.emptySet());
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", 1234))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", true))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("b", "a"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("b", "b"))));
assertTrue(f.matchesJSONObject(new JSONObject()));
final ANDJSONObjectFilter andFilter = new ANDJSONObjectFilter();
f.setNegateFilter(andFilter);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "negate"), new JSONField("negateFilter", andFilter.toJSONObject())));
f = (NegateJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
assertNotNull(f);
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", 1234))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", true))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("b", "a"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("b", "b"))));
assertFalse(f.matchesJSONObject(new JSONObject()));
final ORJSONObjectFilter orFilter = new ORJSONObjectFilter();
f.setNegateFilter(orFilter);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "negate"), new JSONField("negateFilter", orFilter.toJSONObject())));
f = (NegateJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
assertNotNull(f);
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", 1234))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", true))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("b", "a"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("b", "b"))));
assertTrue(f.matchesJSONObject(new JSONObject()));
try {
f.setNegateFilter(null);
fail("Expected an exception from setNegateFilter(null)");
} catch (final LDAPSDKUsageException e) {
// This was expected
}
}
Aggregations