Search in sources :

Example 26 with JSONArray

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

the class ORJSONObjectFilterTestCase method testZeroComponents.

/**
 * Tests the behavior of an OR filter with zero components.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testZeroComponents() throws Exception {
    ORJSONObjectFilter f = new ORJSONObjectFilter();
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "or"), new JSONField("orFilters", JSONArray.EMPTY_ARRAY)));
    f = (ORJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getORFilters());
    assertEquals(f.getORFilters(), Collections.emptyList());
    assertFalse(f.exclusive());
    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));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "foo"), new JSONField("b", 1234), new JSONField("c", true), new JSONField("d", false), new JSONField("e", JSONNull.NULL), new JSONField("f", JSONArray.EMPTY_ARRAY), new JSONField("g", new JSONArray(new JSONString("foo"), new JSONString("bar"))), new JSONField("h", JSONObject.EMPTY_OBJECT), new JSONField("i", new JSONObject(new JSONField("j", "k"))))));
    f.setExclusive(true);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "or"), new JSONField("orFilters", JSONArray.EMPTY_ARRAY), new JSONField("exclusive", true)));
    f = (ORJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.exclusive());
    assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "foo"), new JSONField("b", 1234), new JSONField("c", true), new JSONField("d", false), new JSONField("e", JSONNull.NULL), new JSONField("f", JSONArray.EMPTY_ARRAY), new JSONField("g", new JSONArray(new JSONString("foo"), new JSONString("bar"))), new JSONField("h", JSONObject.EMPTY_OBJECT), new JSONField("i", new JSONObject(new JSONField("j", "k"))))));
}
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 27 with JSONArray

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

the class RegularExpressionJSONObjectFilterTestCase method testPatternRegex.

/**
 * Tests the regular expression filter with a pattern regex.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testPatternRegex() throws Exception {
    RegularExpressionJSONObjectFilter f = new RegularExpressionJSONObjectFilter("a", Pattern.compile("[a-zA-Z][a-zA-Z0-9]*"));
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "regularExpression"), new JSONField("field", "a"), new JSONField("regularExpression", "[a-zA-Z][a-zA-Z0-9]*")));
    f = (RegularExpressionJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("a"));
    assertNotNull(f.getRegularExpression());
    assertEquals(f.getRegularExpression().pattern(), "[a-zA-Z][a-zA-Z0-9]*");
    assertFalse(f.matchAllElements());
    assertNotNull(f.getFilterType());
    assertEquals(f.getFilterType(), "regularExpression");
    assertNotNull(f.getRequiredFieldNames());
    assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Arrays.asList("field", "regularExpression")));
    assertNotNull(f.getOptionalFieldNames());
    assertEquals(f.getOptionalFieldNames(), Collections.singletonList("matchAllElements"));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "abc"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("b", "abc"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "abc123"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "a"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "ABC123"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "A"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "123abc"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", ""))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "abc!"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", JSONArray.EMPTY_ARRAY))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONString("abc"), new JSONString("def456"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONString("abc"), new JSONString("def456"), JSONNull.NULL)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONString("abc"), new JSONString("456def"))))));
    f.setMatchAllElements(true);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "regularExpression"), new JSONField("field", "a"), new JSONField("regularExpression", "[a-zA-Z][a-zA-Z0-9]*"), new JSONField("matchAllElements", true)));
    f = (RegularExpressionJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.matchAllElements());
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "abc"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("b", "abc"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "abc123"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "a"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "ABC123"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "A"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "123abc"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", ""))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "abc!"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", JSONArray.EMPTY_ARRAY))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONString("abc"), new JSONString("def456"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONString("abc"), new JSONString("def456"), JSONNull.NULL)))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONString("abc"), new JSONString("456def"))))));
}
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 28 with JSONArray

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

the class RegularExpressionJSONObjectFilterTestCase method testGetAndSetField.

/**
 * Provides test coverage for the methods that can be used to get and set the
 * target field for a filter.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetAndSetField() throws Exception {
    RegularExpressionJSONObjectFilter f = new RegularExpressionJSONObjectFilter("a", "[a-zA-Z][a-zA-Z0-9]*");
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("a"));
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "regularExpression"), new JSONField("field", "a"), new JSONField("regularExpression", "[a-zA-Z][a-zA-Z0-9]*")));
    f.setField("b");
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("b"));
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "regularExpression"), new JSONField("field", "b"), new JSONField("regularExpression", "[a-zA-Z][a-zA-Z0-9]*")));
    f.setField("first", "second", "third");
    assertNotNull(f.getField());
    assertEquals(f.getField(), Arrays.asList("first", "second", "third"));
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "regularExpression"), new JSONField("field", new JSONArray(new JSONString("first"), new JSONString("second"), new JSONString("third"))), new JSONField("regularExpression", "[a-zA-Z][a-zA-Z0-9]*")));
    try {
        f.setField();
        fail("Expected an exception with setField of empty");
    } 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 29 with JSONArray

use of com.unboundid.util.json.JSONArray 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 30 with JSONArray

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

the class SubstringJSONObjectFilterTestCase method testAllComponents.

/**
 * Tests the behavior of a filter that includes all substring components.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAllComponents() throws Exception {
    SubstringJSONObjectFilter f = new SubstringJSONObjectFilter(Arrays.asList("first", "second"), "abc", Arrays.asList("def", "ghi"), "jkl");
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", new JSONArray(new JSONString("first"), new JSONString("second"))), new JSONField("startsWith", "abc"), new JSONField("contains", new JSONArray(new JSONString("def"), new JSONString("ghi"))), new JSONField("endsWith", "jkl")));
    f = (SubstringJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Arrays.asList("first", "second"));
    assertNotNull(f.getStartsWith());
    assertEquals(f.getStartsWith(), "abc");
    assertNotNull(f.getContains());
    assertEquals(f.getContains(), Arrays.asList("def", "ghi"));
    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("first", new JSONObject(new JSONField("second", "abcdefghijkl"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("first", new JSONObject(new JSONField("second", "AbcDefGhiJkl"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("first", new JSONObject(new JSONField("second", "abcghidefjkl"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("first", new JSONObject(new JSONField("second", "abcXXXdefXXXghiXXXjkl"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("first", new JSONObject(new JSONField("second", "ABCxxxDEFxxxGHIxxxJKL"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("first", new JSONObject(new JSONField("second", "xxxABCxxxDEFxxxGHIxxxJKLxxx"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("first", new JSONObject(new JSONField("second", JSONArray.EMPTY_ARRAY))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("first", new JSONObject(new JSONField("second", new JSONArray(new JSONString("abcdefghijkl"))))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("first", new JSONObject(new JSONField("second", new JSONArray(new JSONString("abcdefghijkl"), new JSONString("mnopqrstuvwx"))))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("first", new JSONObject(new JSONField("second", new JSONArray(new JSONString("mnopqrstuvwx"), new JSONString("abcdefghijkl"))))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("first", new JSONObject(new JSONField("second", new JSONArray(new JSONString("abc"), new JSONString("def"), new JSONString("ghi"), new JSONString("jkl"))))))));
}
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)

Aggregations

JSONArray (com.unboundid.util.json.JSONArray)98 JSONObject (com.unboundid.util.json.JSONObject)89 JSONString (com.unboundid.util.json.JSONString)77 Test (org.testng.annotations.Test)72 JSONField (com.unboundid.util.json.JSONField)68 JSONValue (com.unboundid.util.json.JSONValue)27 JSONNumber (com.unboundid.util.json.JSONNumber)22 NotNull (com.unboundid.util.NotNull)20 ArrayList (java.util.ArrayList)19 LinkedHashMap (java.util.LinkedHashMap)18 PasswordPolicyStateJSONField (com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField)11 PasswordQualityRequirement (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement)7 Entry (com.unboundid.ldap.sdk.Entry)6 Map (java.util.Map)6 LDAPSDKUsageException (com.unboundid.util.LDAPSDKUsageException)5 JSONBoolean (com.unboundid.util.json.JSONBoolean)5 JSONException (com.unboundid.util.json.JSONException)5 Date (java.util.Date)4 List (java.util.List)4 LogField (com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField)3