Search in sources :

Example 6 with JSONNumber

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

the class EqualsJSONObjectFilterTestCase method testSetValue.

/**
 * Provides test coverage for the methods that can be used to get and set the
 * target value for a filter.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSetValue() throws Exception {
    final EqualsJSONObjectFilter f = new EqualsJSONObjectFilter("test-field-name", JSONNull.NULL);
    assertNotNull(f.getValue());
    f.setValue(new JSONString("foo"));
    assertNotNull(f.getValue());
    assertEquals(f.getValue(), new JSONString("foo"));
    f.setValue("bar");
    assertNotNull(f.getValue());
    assertEquals(f.getValue(), new JSONString("bar"));
    f.setValue(JSONBoolean.TRUE);
    assertNotNull(f.getValue());
    assertEquals(f.getValue(), JSONBoolean.TRUE);
    f.setValue(false);
    assertNotNull(f.getValue());
    assertEquals(f.getValue(), JSONBoolean.FALSE);
    f.setValue(1234);
    assertNotNull(f.getValue());
    assertEquals(f.getValue(), new JSONNumber(1234));
    f.setValue(true);
    assertNotNull(f.getValue());
    assertEquals(f.getValue(), JSONBoolean.TRUE);
    f.setValue(1234.5);
    assertNotNull(f.getValue());
    assertEquals(f.getValue(), new JSONNumber(1234.5));
}
Also used : JSONNumber(com.unboundid.util.json.JSONNumber) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 7 with JSONNumber

use of com.unboundid.util.json.JSONNumber 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))))));
}
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 8 with JSONNumber

use of com.unboundid.util.json.JSONNumber 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)))))));
}
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) Test(org.testng.annotations.Test)

Example 9 with JSONNumber

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

the class SubstringJSONObjectFilterTestCase method testEndsWith.

/**
 * Tests the behavior of a filter that only uses the endsWith component.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testEndsWith() throws Exception {
    SubstringJSONObjectFilter f = new SubstringJSONObjectFilter("test-field", null, null, "jkl");
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "test-field"), new JSONField("endsWith", "jkl")));
    f = (SubstringJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("test-field"));
    assertNull(f.getStartsWith());
    assertNotNull(f.getContains());
    assertTrue(f.getContains().isEmpty());
    assertNotNull(f.getEndsWith());
    assertEquals(f.getEndsWith(), "jkl");
    assertFalse(f.caseSensitive());
    assertNotNull(f.getFilterType());
    assertEquals(f.getFilterType(), "substring");
    assertNotNull(f.getRequiredFieldNames());
    assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Collections.singletonList("field")));
    assertNotNull(f.getOptionalFieldNames());
    assertEquals(f.getOptionalFieldNames(), new HashSet<String>(Arrays.asList("startsWith", "contains", "endsWith", "caseSensitive")));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "jkl"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "jkL"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "JKL"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "kl"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abcdefghijkl"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "AbCdEfGhIjKl"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABCDEFGHIJKL"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "defjklghi"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "jkl"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONArray.EMPTY_ARRAY))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("ghijkl"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONNull.NULL, new JSONString("ghi"), new JSONNumber(1234), new JSONString("JKL"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("jkl"), new JSONString("GHI"))))));
    f.setCaseSensitive(true);
    assertTrue(f.caseSensitive());
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "test-field"), new JSONField("endsWith", "jkl"), new JSONField("caseSensitive", true)));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "jkl"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "jkL"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "JKL"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abcdefghijkl"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "AbCdEfGhIjKl"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABCDEFGHIJKL"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONArray.EMPTY_ARRAY))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("ghijkl"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("ghi"), new JSONString("JKL"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("jkl"), new JSONString("GHI"))))));
}
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 10 with JSONNumber

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

the class LessThanJSONObjectFilterTestCase method testConstructors.

/**
 * Provides test coverage for the various constructors available for
 * less-than filters.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructors() throws Exception {
    LessThanJSONObjectFilter f = new LessThanJSONObjectFilter();
    assertNull(f.getField());
    assertNull(f.getValue());
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    f = new LessThanJSONObjectFilter("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 LessThanJSONObjectFilter("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 LessThanJSONObjectFilter("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 LessThanJSONObjectFilter("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 LessThanJSONObjectFilter("a", JSONNull.NULL);
        fail("Expected an exception from lessThan with null");
    } catch (final LDAPSDKUsageException e) {
    // This was expected.
    }
    f = new LessThanJSONObjectFilter(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 LessThanJSONObjectFilter(Arrays.asList("a", "b", "c"), JSONBoolean.TRUE);
        fail("Expected an exception from lessThan 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