use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class EqualsJSONObjectFilterTestCase method testTopLevelFieldObject.
/**
* Provides test coverage for the case in which a filter references a
* top-level field and an object value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testTopLevelFieldObject() throws Exception {
EqualsJSONObjectFilter f = new EqualsJSONObjectFilter("top-level-field", new JSONObject(new JSONField("a", true), new JSONField("b", false)));
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equals"), new JSONField("field", "top-level-field"), new JSONField("value", new JSONObject(new JSONField("a", true), new JSONField("b", 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 JSONObject(new JSONField("a", true), new JSONField("b", 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("a", true), new JSONField("b", false))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("a", true), new JSONField("b", false))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("b", false), new JSONField("a", true))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("a", false), new JSONField("b", true))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONObject(new JSONField("a", true), new JSONField("b", false)), new JSONObject(new JSONField("a", "foo"), new JSONField("b", "bar")))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONObject(new JSONField("a", "foo"), new JSONField("b", "bar")), new JSONObject(new JSONField("a", true), new JSONField("b", false)))))));
}
use of com.unboundid.util.json.JSONArray 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.JSONArray 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.JSONArray 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.JSONArray 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"))))))))))));
}
Aggregations