Search in sources :

Example 61 with JSONField

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

the class SubstringJSONObjectFilterTestCase method testMultipleContains.

/**
 * Tests the behavior of a filter that only uses multiple contains components.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testMultipleContains() throws Exception {
    SubstringJSONObjectFilter f = new SubstringJSONObjectFilter(Collections.singletonList("test-field"), null, Arrays.asList("aba", "bab"), null);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "test-field"), new JSONField("contains", new JSONArray(new JSONString("aba"), new JSONString("bab")))));
    f = (SubstringJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("test-field"));
    assertNull(f.getStartsWith());
    assertNotNull(f.getContains());
    assertEquals(f.getContains(), Arrays.asList("aba", "bab"));
    assertNull(f.getEndsWith());
    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", "ababab"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABABAB"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abaxbab"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABAxBAB"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "xabaxbabx"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "xABAxBABx"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abab"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bababa"))));
    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("aBABab"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("aba"), new JSONString("bab"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("ABAab"), new JSONString("BABab"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("AbAbAbAbA"), new JSONString("BaBaBaBaB"))))));
    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("contains", new JSONArray(new JSONString("aba"), new JSONString("bab"))), new JSONField("caseSensitive", true)));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ababab"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABABAB"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abaxbab"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABAxBAB"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "xabaxbabx"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "xABAxBABx"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abab"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bababa"))));
    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("ababab"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("aba"), new JSONString("bab"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("ABAab"), new JSONString("BABab"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("AbAbAbAbA"), new JSONString("BaBaBaBaB"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("ababababa"), new JSONString("BaBaBaBaB"))))));
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONField(com.unboundid.util.json.JSONField) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 62 with JSONField

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

the class SubstringJSONObjectFilterTestCase method testGetAndSetFields.

/**
 * Tests the behavior of the methods used to get and set the field name.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetAndSetFields() throws Exception {
    final SubstringJSONObjectFilter f = new SubstringJSONObjectFilter("a", "b", "c", "d");
    f.setCaseSensitive(true);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("a"));
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "a"), new JSONField("startsWith", "b"), new JSONField("contains", "c"), new JSONField("endsWith", "d"), new JSONField("caseSensitive", true)));
    f.setField("different");
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("different"));
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "different"), new JSONField("startsWith", "b"), new JSONField("contains", "c"), new JSONField("endsWith", "d"), new JSONField("caseSensitive", true)));
    f.setField("first", "second");
    assertNotNull(f.getField());
    assertEquals(f.getField(), Arrays.asList("first", "second"));
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", new JSONArray(new JSONString("first"), new JSONString("second"))), new JSONField("startsWith", "b"), new JSONField("contains", "c"), new JSONField("endsWith", "d"), new JSONField("caseSensitive", true)));
    try {
        f.setField();
        fail("Expected an exception from setField()");
    } catch (final LDAPSDKUsageException e) {
    // This was expected.
    }
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONField(com.unboundid.util.json.JSONField) LDAPSDKUsageException(com.unboundid.util.LDAPSDKUsageException) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 63 with JSONField

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

the class SubstringJSONObjectFilterTestCase method testDecodeNoSubstringComponents.

/**
 * Tests the behavior of the decode method with a JSON object that doesn't
 * include any of the substring components.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { JSONException.class })
public void testDecodeNoSubstringComponents() throws Exception {
    final JSONObject o = new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "test-field"), new JSONField("caseSensitive", true));
    JSONObjectFilter.decode(o);
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONField(com.unboundid.util.json.JSONField) Test(org.testng.annotations.Test)

Example 64 with JSONField

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

the class SubstringJSONObjectFilterTestCase method testStartsWith.

/**
 * Tests the behavior of a filter that only uses the startsWith component.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testStartsWith() throws Exception {
    SubstringJSONObjectFilter f = new SubstringJSONObjectFilter("test-field", "abc", null, null);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "test-field"), new JSONField("startsWith", "abc")));
    f = (SubstringJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("test-field"));
    assertNotNull(f.getStartsWith());
    assertEquals(f.getStartsWith(), "abc");
    assertNotNull(f.getContains());
    assertTrue(f.getContains().isEmpty());
    assertNull(f.getEndsWith());
    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", "abc"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "Abc"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABC"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ab"))));
    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", "defabcghi"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "abc"))));
    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("abcdef"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("abc"), new JSONString("DEF"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("def"), new JSONString("ABC"))))));
    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("startsWith", "abc"), new JSONField("caseSensitive", true)));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "abc"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "Abc"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABC"))));
    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("abcdef"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("abc"), new JSONString("DEF"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONBoolean.TRUE, new JSONString("abc"), JSONNull.NULL, new JSONString("DEF"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("def"), new JSONString("ABC"))))));
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONField(com.unboundid.util.json.JSONField) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 65 with JSONField

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

the class EqualsJSONObjectFilterTestCase method testTopLevelFieldNull.

/**
 * Provides test coverage for the case in which a filter references a
 * top-level field and a {@code JSONNull} value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testTopLevelFieldNull() throws Exception {
    EqualsJSONObjectFilter f = new EqualsJSONObjectFilter("top-level-field", JSONNull.NULL);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equals"), new JSONField("field", "top-level-field"), new JSONField("value", 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(), 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")));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", JSONNull.NULL))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONNull()))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(JSONNull.NULL, JSONBoolean.TRUE)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONArray(JSONBoolean.TRUE, JSONNull.NULL)))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("top-level-field", new JSONObject(new JSONField("top-level-field", JSONNull.NULL))))));
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONNull(com.unboundid.util.json.JSONNull) JSONArray(com.unboundid.util.json.JSONArray) JSONField(com.unboundid.util.json.JSONField) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Aggregations

JSONField (com.unboundid.util.json.JSONField)97 JSONObject (com.unboundid.util.json.JSONObject)97 Test (org.testng.annotations.Test)91 JSONArray (com.unboundid.util.json.JSONArray)68 JSONString (com.unboundid.util.json.JSONString)66 JSONNumber (com.unboundid.util.json.JSONNumber)20 PasswordPolicyStateJSONField (com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField)11 LDAPSDKUsageException (com.unboundid.util.LDAPSDKUsageException)8 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)7 Date (java.util.Date)7 Entry (com.unboundid.ldap.sdk.Entry)5 JSONException (com.unboundid.util.json.JSONException)5 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)4 JSONBoolean (com.unboundid.util.json.JSONBoolean)4 JSONValue (com.unboundid.util.json.JSONValue)4 CompareRequest (com.unboundid.ldap.sdk.CompareRequest)3 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)3 PasswordQualityRequirement (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement)3 LogField (com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField)3 ArrayList (java.util.ArrayList)3