Search in sources :

Example 21 with JSONNumber

use of com.unboundid.util.json.JSONNumber in project ldapsdk by pingidentity.

the class ORJSONObjectFilterTestCase method testOneComponent.

/**
 * Tests the behavior of an OR filter with one component.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testOneComponent() throws Exception {
    final EqualsJSONObjectFilter equalsFilter = new EqualsJSONObjectFilter("a", new JSONString("b"));
    ORJSONObjectFilter f = new ORJSONObjectFilter(equalsFilter);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "or"), new JSONField("orFilters", new JSONArray(equalsFilter.toJSONObject()))));
    f = (ORJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getORFilters());
    assertEquals(f.getORFilters(), Collections.singletonList(equalsFilter));
    assertNotNull(f.getFilterType());
    assertEquals(f.getFilterType(), "or");
    assertNotNull(f.getRequiredFieldNames());
    assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Collections.singletonList("orFilters")));
    assertNotNull(f.getOptionalFieldNames());
    assertEquals(f.getOptionalFieldNames(), new HashSet<String>(Collections.singletonList("exclusive")));
    assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "x"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("x", "b"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONNumber(1234), new JSONString("b"), JSONNull.NULL)))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", 1234))));
    f.setExclusive(true);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "or"), new JSONField("orFilters", new JSONArray(equalsFilter.toJSONObject())), new JSONField("exclusive", true)));
    f = (ORJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.exclusive());
    assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "x"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("x", "b"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONNumber(1234), new JSONString("b"), JSONNull.NULL)))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", 1234))));
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONField(com.unboundid.util.json.JSONField) JSONNumber(com.unboundid.util.json.JSONNumber) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 22 with JSONNumber

use of com.unboundid.util.json.JSONNumber in project ldapsdk by pingidentity.

the class ORJSONObjectFilterTestCase method testMultipleComponents.

/**
 * Tests the behavior of an OR filter with multiple components.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testMultipleComponents() throws Exception {
    final EqualsJSONObjectFilter f1 = new EqualsJSONObjectFilter("a", new JSONString("b"));
    final EqualsJSONObjectFilter f2 = new EqualsJSONObjectFilter("c", new JSONString("d"));
    final EqualsJSONObjectFilter f3 = new EqualsJSONObjectFilter("e", new JSONString("f"));
    ORJSONObjectFilter f = new ORJSONObjectFilter(f1, f2, f3);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "or"), new JSONField("orFilters", new JSONArray(f1.toJSONObject(), f2.toJSONObject(), f3.toJSONObject()))));
    f = (ORJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getORFilters());
    assertEquals(f.getORFilters(), Arrays.asList(f1, f2, f3));
    assertNotNull(f.getFilterType());
    assertEquals(f.getFilterType(), "or");
    assertNotNull(f.getRequiredFieldNames());
    assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Collections.singletonList("orFilters")));
    assertNotNull(f.getOptionalFieldNames());
    assertEquals(f.getOptionalFieldNames(), new HashSet<String>(Collections.singletonList("exclusive")));
    assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "x"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("x", "b"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONNumber(1234), new JSONString("a"), JSONNull.NULL)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONNumber(1234), new JSONString("b"), JSONNull.NULL)))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", 1234))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"), new JSONField("c", "d"), new JSONField("e", "f"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"), new JSONField("c", "d"), new JSONField("e", "f"), new JSONField("g", "h"), new JSONField("i", "j"))));
    f.setExclusive(true);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "or"), new JSONField("orFilters", JSONArray.EMPTY_ARRAY), new JSONField("orFilters", new JSONArray(f1.toJSONObject(), f2.toJSONObject(), f3.toJSONObject())), new JSONField("exclusive", true)));
    f = (ORJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.exclusive());
    assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "x"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("x", "b"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONNumber(1234), new JSONString("a"), JSONNull.NULL)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONNumber(1234), new JSONString("b"), JSONNull.NULL)))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", 1234))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"), new JSONField("c", "d"), new JSONField("e", "f"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"), new JSONField("c", "d"), new JSONField("e", "f"), new JSONField("g", "h"), new JSONField("i", "j"))));
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONField(com.unboundid.util.json.JSONField) JSONNumber(com.unboundid.util.json.JSONNumber) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 23 with JSONNumber

use of com.unboundid.util.json.JSONNumber in project ldapsdk by pingidentity.

the class EqualsJSONObjectFilterTestCase method testTopLevelFieldString.

/**
 * Provides test coverage for the case in which a filter references a
 * top-level field and a string value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testTopLevelFieldString() throws Exception {
    EqualsJSONObjectFilter f = new EqualsJSONObjectFilter("top-level-field", new JSONString("foo"));
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equals"), new JSONField("field", "top-level-field"), new JSONField("value", "foo")));
    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 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")));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", "foo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", "Foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Top-Level-Field", "foo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONString("foo"), new JSONString("bar"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONString("Bar"), new JSONString("Foo"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", 1234))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONNumber(1234), new JSONNumber(5678))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONNumber(1234), new JSONNumber(5678), new JSONString("foo"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", true))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", false))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", JSONNull.NULL))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", JSONArray.EMPTY_ARRAY))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", JSONObject.EMPTY_OBJECT))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("top-level-field", "foo"))))));
    f.setCaseSensitive(true);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equals"), new JSONField("field", "top-level-field"), new JSONField("value", "foo"), new JSONField("caseSensitive", 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 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")));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", "Foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Top-Level-Field", "foo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONString("foo"), new JSONString("bar"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONString("Bar"), new JSONString("Foo"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", 1234))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONNumber(1234), new JSONNumber(5678))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(new JSONNumber(1234), new JSONNumber(5678), new JSONString("foo"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", true))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", false))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", JSONNull.NULL))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", JSONArray.EMPTY_ARRAY))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", JSONObject.EMPTY_OBJECT))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("top-level-field", "foo"))))));
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONField(com.unboundid.util.json.JSONField) JSONNumber(com.unboundid.util.json.JSONNumber) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 24 with JSONNumber

use of com.unboundid.util.json.JSONNumber in project ldapsdk by pingidentity.

the class GreaterThanJSONObjectFilterTestCase method testGreaterThanNumber.

/**
 * Tests the behavior of the greater-than filter with a numeric value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGreaterThanNumber() throws Exception {
    GreaterThanJSONObjectFilter f = new GreaterThanJSONObjectFilter("test-field", 5678);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "greaterThan"), new JSONField("field", "test-field"), new JSONField("value", 5678)));
    f = (GreaterThanJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("test-field"));
    assertNotNull(f.getValue());
    assertEquals(f.getValue(), new JSONNumber(5678));
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    assertNotNull(f.getFilterType());
    assertEquals(f.getFilterType(), "greaterThan");
    assertNotNull(f.getRequiredFieldNames());
    assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Arrays.asList("field", "value")));
    assertNotNull(f.getOptionalFieldNames());
    assertEquals(f.getOptionalFieldNames(), new HashSet<String>(Arrays.asList("allowEquals", "matchAllElements", "caseSensitive")));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5679))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", Boolean.TRUE))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", 5679))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 9999))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 10000))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 999))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678.5))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678.0))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "5679"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5679))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5678), new JSONNumber(5679), new JSONNumber(10000))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(1234), new JSONNumber(5679), new JSONNumber(10000))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5679), new JSONNumber(10000))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5679), new JSONNumber(10000), new JSONString("foo"), JSONNull.NULL)))));
    f.setMatchAllElements(true);
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "greaterThan"), new JSONField("field", "test-field"), new JSONField("value", 5678), new JSONField("matchAllElements", true)));
    f = (GreaterThanJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.matchAllElements());
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5679))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", Boolean.TRUE))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", 5679))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 9999))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 10000))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 999))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5679))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678.5))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678.0))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "5679"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5679))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5678), new JSONNumber(5679), new JSONNumber(10000))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(1234), new JSONNumber(5679), new JSONNumber(10000))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5679), new JSONNumber(10000))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5679), new JSONNumber(10000), new JSONString("foo"), JSONNull.NULL)))));
    f.setAllowEquals(true);
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "greaterThan"), new JSONField("field", "test-field"), new JSONField("value", 5678), new JSONField("matchAllElements", true), new JSONField("allowEquals", true)));
    f = (GreaterThanJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.allowEquals());
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5679))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", Boolean.TRUE))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", 5679))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 9999))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 10000))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 999))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5679))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678.5))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678.0))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "5679"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5679))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5678), new JSONNumber(5679), new JSONNumber(10000))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(1234), new JSONNumber(5679), new JSONNumber(10000))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5679), new JSONNumber(10000))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5679), new JSONNumber(10000), new JSONString("foo"), JSONNull.NULL)))));
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONField(com.unboundid.util.json.JSONField) JSONNumber(com.unboundid.util.json.JSONNumber) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 25 with JSONNumber

use of com.unboundid.util.json.JSONNumber in project ldapsdk by pingidentity.

the class GreaterThanJSONObjectFilterTestCase method testConstructors.

/**
 * Provides test coverage for the various constructors available for
 * greater-than filters.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructors() throws Exception {
    GreaterThanJSONObjectFilter f = new GreaterThanJSONObjectFilter();
    assertNull(f.getField());
    assertNull(f.getValue());
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    f = new GreaterThanJSONObjectFilter("a", 1234);
    assertEquals(f.getField(), Collections.singletonList("a"));
    assertEquals(f.getValue(), new JSONNumber(1234));
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    assertNotNull(f.toJSONObject());
    f = new GreaterThanJSONObjectFilter("a", 1234.5);
    assertEquals(f.getField(), Collections.singletonList("a"));
    assertEquals(f.getValue(), new JSONNumber(1234.5));
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    assertNotNull(f.toJSONObject());
    f = new GreaterThanJSONObjectFilter("a", "foo");
    assertEquals(f.getField(), Collections.singletonList("a"));
    assertEquals(f.getValue(), new JSONString("foo"));
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    assertNotNull(f.toJSONObject());
    f = new GreaterThanJSONObjectFilter("a", new JSONNumber("1.234e3"));
    assertEquals(f.getField(), Collections.singletonList("a"));
    assertEquals(f.getValue(), new JSONNumber(1234));
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    assertNotNull(f.toJSONObject());
    try {
        f = new GreaterThanJSONObjectFilter("a", JSONNull.NULL);
        fail("Expected an exception from greaterThan with null");
    } catch (final LDAPSDKUsageException e) {
    // This was expected.
    }
    f = new GreaterThanJSONObjectFilter(Arrays.asList("a", "b", "c"), new JSONString("bar"));
    assertEquals(f.getField(), Arrays.asList("a", "b", "c"));
    assertEquals(f.getValue(), new JSONString("bar"));
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    assertNotNull(f.toJSONObject());
    try {
        f = new GreaterThanJSONObjectFilter(Arrays.asList("a", "b", "c"), JSONBoolean.TRUE);
        fail("Expected an exception from greaterThan with true");
    } catch (final LDAPSDKUsageException e) {
    // This was expected.
    }
}
Also used : LDAPSDKUsageException(com.unboundid.util.LDAPSDKUsageException) JSONNumber(com.unboundid.util.json.JSONNumber) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Aggregations

JSONNumber (com.unboundid.util.json.JSONNumber)30 JSONString (com.unboundid.util.json.JSONString)28 JSONObject (com.unboundid.util.json.JSONObject)23 Test (org.testng.annotations.Test)23 JSONArray (com.unboundid.util.json.JSONArray)22 JSONField (com.unboundid.util.json.JSONField)20 JSONValue (com.unboundid.util.json.JSONValue)5 LDAPSDKUsageException (com.unboundid.util.LDAPSDKUsageException)4 NotNull (com.unboundid.util.NotNull)4 JSONBoolean (com.unboundid.util.json.JSONBoolean)4 LinkedHashMap (java.util.LinkedHashMap)4 Entry (com.unboundid.ldap.sdk.Entry)3 LogField (com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField)3 PasswordPolicyStateJSONField (com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField)2 StringLogFieldSyntax (com.unboundid.ldap.sdk.unboundidds.logs.v2.syntax.StringLogFieldSyntax)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 PasswordPolicyStateAccountUsabilityError (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityError)1 PasswordPolicyStateAccountUsabilityNotice (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice)1 PasswordPolicyStateAccountUsabilityWarning (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityWarning)1