use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class ContainsFieldJSONObjectFilterTestCase method testSetExpectedType.
/**
* Provides test coverage for the methods used to get and set the target
* expected data type(s).
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSetExpectedType() throws Exception {
ContainsFieldJSONObjectFilter f = new ContainsFieldJSONObjectFilter("field-name");
assertEquals(f.getExpectedType(), EnumSet.allOf(ExpectedValueType.class));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "containsField"), new JSONField("field", "field-name")));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", "foo"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", true))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", false))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", 1234))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", JSONNull.NULL))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray()))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray(JSONBoolean.TRUE)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject()))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject(new JSONField("foo", "bar"))))));
f.setExpectedType(ExpectedValueType.STRING);
assertEquals(f.getExpectedType(), EnumSet.of(ExpectedValueType.STRING));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "containsField"), new JSONField("field", "field-name"), new JSONField("expectedType", "string")));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", "foo"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", true))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", false))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", 1234))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", JSONNull.NULL))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray()))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray(JSONBoolean.TRUE)))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject()))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject(new JSONField("foo", "bar"))))));
f.setExpectedType();
assertEquals(f.getExpectedType(), EnumSet.allOf(ExpectedValueType.class));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "containsField"), new JSONField("field", "field-name")));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", "foo"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", true))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", false))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", 1234))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", JSONNull.NULL))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray()))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray(JSONBoolean.TRUE)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject()))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject(new JSONField("foo", "bar"))))));
f.setExpectedType(ExpectedValueType.BOOLEAN);
assertEquals(f.getExpectedType(), EnumSet.of(ExpectedValueType.BOOLEAN));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "containsField"), new JSONField("field", "field-name"), new JSONField("expectedType", "boolean")));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", "foo"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", true))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", false))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", 1234))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", JSONNull.NULL))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray()))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray(JSONBoolean.TRUE)))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject()))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject(new JSONField("foo", "bar"))))));
f.setExpectedType(ExpectedValueType.NUMBER);
assertEquals(f.getExpectedType(), EnumSet.of(ExpectedValueType.NUMBER));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "containsField"), new JSONField("field", "field-name"), new JSONField("expectedType", "number")));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", "foo"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", true))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", false))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", 1234))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", JSONNull.NULL))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray()))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray(JSONBoolean.TRUE)))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject()))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject(new JSONField("foo", "bar"))))));
f.setExpectedType(ExpectedValueType.NULL);
assertEquals(f.getExpectedType(), EnumSet.of(ExpectedValueType.NULL));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "containsField"), new JSONField("field", "field-name"), new JSONField("expectedType", "null")));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", "foo"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", true))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", false))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", 1234))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", JSONNull.NULL))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray()))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray(JSONBoolean.TRUE)))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject()))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject(new JSONField("foo", "bar"))))));
f.setExpectedType(ExpectedValueType.EMPTY_ARRAY);
assertEquals(f.getExpectedType(), EnumSet.of(ExpectedValueType.EMPTY_ARRAY));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "containsField"), new JSONField("field", "field-name"), new JSONField("expectedType", "empty-array")));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", "foo"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", true))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", false))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", 1234))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", JSONNull.NULL))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray()))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray(JSONBoolean.TRUE)))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject()))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject(new JSONField("foo", "bar"))))));
f.setExpectedType(ExpectedValueType.NON_EMPTY_ARRAY);
assertEquals(f.getExpectedType(), EnumSet.of(ExpectedValueType.NON_EMPTY_ARRAY));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "containsField"), new JSONField("field", "field-name"), new JSONField("expectedType", "non-empty-array")));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", "foo"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", true))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", false))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", 1234))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", JSONNull.NULL))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray()))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray(JSONBoolean.TRUE)))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject()))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject(new JSONField("foo", "bar"))))));
f.setExpectedType(ExpectedValueType.OBJECT);
assertEquals(f.getExpectedType(), EnumSet.of(ExpectedValueType.OBJECT));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "containsField"), new JSONField("field", "field-name"), new JSONField("expectedType", "object")));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", "foo"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", true))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", false))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", 1234))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", JSONNull.NULL))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray()))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray(JSONBoolean.TRUE)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject()))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject(new JSONField("foo", "bar"))))));
f.setExpectedType((ExpectedValueType[]) null);
assertEquals(f.getExpectedType(), EnumSet.allOf(ExpectedValueType.class));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "containsField"), new JSONField("field", "field-name")));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", "foo"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", true))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", false))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", 1234))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", JSONNull.NULL))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray()))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray(JSONBoolean.TRUE)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject()))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject(new JSONField("foo", "bar"))))));
f.setExpectedType(ExpectedValueType.BOOLEAN, ExpectedValueType.NUMBER, ExpectedValueType.STRING);
assertEquals(f.getExpectedType(), EnumSet.of(ExpectedValueType.BOOLEAN, ExpectedValueType.NUMBER, ExpectedValueType.STRING));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "containsField"), new JSONField("field", "field-name"), new JSONField("expectedType", new JSONArray(new JSONString("boolean"), new JSONString("number"), new JSONString("string")))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", "foo"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", true))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", false))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("field-name", 1234))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", JSONNull.NULL))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray()))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONArray(JSONBoolean.TRUE)))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject()))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("field-name", new JSONObject(new JSONField("foo", "bar"))))));
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class EqualsAnyJSONObjectFilterTestCase method testEqualsAnyList.
/**
* Tests the behavior of the equals any filter with a number of cases and
* values specified in a list.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testEqualsAnyList() throws Exception {
EqualsAnyJSONObjectFilter f = new EqualsAnyJSONObjectFilter("test-field", Arrays.asList(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT));
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equalsAny"), new JSONField("field", "test-field"), new JSONField("values", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT))));
f = (EqualsAnyJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
assertNotNull(f);
assertNotNull(f.getField());
assertEquals(f.getField(), Collections.singletonList("test-field"));
assertNotNull(f.getValues());
assertEquals(f.getValues(), Arrays.asList(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT));
assertFalse(f.caseSensitive());
assertNotNull(f.getFilterType());
assertEquals(f.getFilterType(), "equalsAny");
assertNotNull(f.getRequiredFieldNames());
assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Arrays.asList("field", "values")));
assertNotNull(f.getOptionalFieldNames());
assertEquals(f.getOptionalFieldNames(), new HashSet<String>(Collections.singletonList("caseSensitive")));
assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOO"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bar"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "baz"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 1234))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", true))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONNull.NULL))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONArray.EMPTY_ARRAY))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONObject.EMPTY_OBJECT))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "foo"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("FOO"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("bar"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("baz"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(1234))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONBoolean.TRUE)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONNull.NULL)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONArray.EMPTY_ARRAY)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONObject.EMPTY_OBJECT)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT)))));
f.setCaseSensitive(true);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equalsAny"), new JSONField("field", "test-field"), new JSONField("values", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT)), new JSONField("caseSensitive", true)));
f = (EqualsAnyJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
assertNotNull(f);
assertTrue(f.caseSensitive());
assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOO"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bar"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "baz"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 1234))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", true))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONNull.NULL))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONArray.EMPTY_ARRAY))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONObject.EMPTY_OBJECT))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "foo"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("FOO"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("bar"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("baz"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(1234))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONBoolean.TRUE)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONNull.NULL)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONArray.EMPTY_ARRAY)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONObject.EMPTY_OBJECT)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT)))));
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class EqualsAnyJSONObjectFilterTestCase method testEqualsAnyArray.
/**
* Tests the behavior of the equals any filter with a number of cases and
* values specified in an array.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testEqualsAnyArray() throws Exception {
EqualsAnyJSONObjectFilter f = new EqualsAnyJSONObjectFilter("test-field", new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equalsAny"), new JSONField("field", "test-field"), new JSONField("values", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT))));
f = (EqualsAnyJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
assertNotNull(f);
assertNotNull(f.getField());
assertEquals(f.getField(), Collections.singletonList("test-field"));
assertNotNull(f.getValues());
assertEquals(f.getValues(), Arrays.asList(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT));
assertFalse(f.caseSensitive());
assertNotNull(f.getFilterType());
assertEquals(f.getFilterType(), "equalsAny");
assertNotNull(f.getRequiredFieldNames());
assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Arrays.asList("field", "values")));
assertNotNull(f.getOptionalFieldNames());
assertEquals(f.getOptionalFieldNames(), new HashSet<String>(Collections.singletonList("caseSensitive")));
assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOO"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bar"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "baz"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 1234))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", true))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONNull.NULL))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONArray.EMPTY_ARRAY))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONObject.EMPTY_OBJECT))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "foo"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("FOO"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("bar"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("baz"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(1234))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONBoolean.TRUE)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONNull.NULL)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONArray.EMPTY_ARRAY)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONObject.EMPTY_OBJECT)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT)))));
f.setCaseSensitive(true);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equalsAny"), new JSONField("field", "test-field"), new JSONField("values", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT)), new JSONField("caseSensitive", true)));
f = (EqualsAnyJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
assertNotNull(f);
assertTrue(f.caseSensitive());
assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOO"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bar"))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "baz"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 1234))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", true))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONNull.NULL))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONArray.EMPTY_ARRAY))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONObject.EMPTY_OBJECT))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "foo"))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("FOO"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("bar"))))));
assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("baz"))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(1234))))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONBoolean.TRUE)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONNull.NULL)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONArray.EMPTY_ARRAY)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONObject.EMPTY_OBJECT)))));
assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT)))));
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class EqualsAnyJSONObjectFilterTestCase method testGetAndSetField.
/**
* Provides test coverage for the methods that can be used to get and set the
* target field name for a filter.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetAndSetField() throws Exception {
final EqualsAnyJSONObjectFilter f = new EqualsAnyJSONObjectFilter("test-field-name", JSONNull.NULL);
assertNotNull(f.getField());
assertEquals(f.getField(), Collections.singletonList("test-field-name"));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equalsAny"), new JSONField("field", "test-field-name"), new JSONField("values", new JSONArray(JSONNull.NULL))));
f.setField("different-field-name");
assertNotNull(f.getField());
assertEquals(f.getField(), Collections.singletonList("different-field-name"));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equalsAny"), new JSONField("field", "different-field-name"), new JSONField("values", new JSONArray(JSONNull.NULL))));
f.setField("first", "second", "third");
assertNotNull(f.getField());
assertEquals(f.getField(), Arrays.asList("first", "second", "third"));
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equalsAny"), new JSONField("field", new JSONArray(new JSONString("first"), new JSONString("second"), new JSONString("third"))), new JSONField("values", new JSONArray(JSONNull.NULL))));
try {
f.setField();
fail("Expected an exception with setFieldName of empty");
} catch (final LDAPSDKUsageException e) {
// This was expected
}
}
use of com.unboundid.util.json.JSONField 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)))))));
}
Aggregations