Search in sources :

Example 56 with JSONField

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

the class ObjectMatchesJSONObjectFilterTestCase method testObjectMatchesCompoundFilter.

/**
 * Tests the behavior of an object matches filter under a variety of
 * conditions with a compound filter.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testObjectMatchesCompoundFilter() throws Exception {
    final ANDJSONObjectFilter andFilter = new ANDJSONObjectFilter(new EqualsJSONObjectFilter("one", new JSONString("uno")), new EqualsJSONObjectFilter("two", new JSONString("dos")));
    ObjectMatchesJSONObjectFilter f = new ObjectMatchesJSONObjectFilter("a", andFilter);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "objectMatches"), new JSONField("field", "a"), new JSONField("filter", andFilter.toJSONObject())));
    f = (ObjectMatchesJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("a"));
    assertNotNull(f.getFilter());
    assertEquals(f.getFilter(), andFilter);
    assertNotNull(f.getFilterType());
    assertEquals(f.getFilterType(), "objectMatches");
    assertNotNull(f.getRequiredFieldNames());
    assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Arrays.asList("field", "filter")));
    assertNotNull(f.getOptionalFieldNames());
    assertEquals(f.getOptionalFieldNames(), Collections.emptySet());
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONObject(new JSONField("one", "uno"), new JSONField("two", "dos"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONObject(new JSONField("language", "Spanish"), new JSONField("one", "uno"), new JSONField("two", "dos")), new JSONObject(new JSONField("language", "French"), new JSONField("one", "une"), new JSONField("two", "deux")), new JSONObject(new JSONField("language", "Italian"), new JSONField("one", "una"), new JSONField("two", "due")))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONObject(new JSONField("one", "uno"), new JSONField("two", "due")), new JSONObject(new JSONField("one", "une"), new JSONField("two", "dos")), new JSONObject(new JSONField("one", "una"), new JSONField("two", "deux")))))));
}
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 57 with JSONField

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

the class ObjectMatchesJSONObjectFilterTestCase method testGetAndSetFilter.

/**
 * Tests the behavior of the methods that can be used to get and set the
 * object filter.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetAndSetFilter() throws Exception {
    JSONObjectFilter objectFilter = new EqualsJSONObjectFilter("b", new JSONString("c"));
    ObjectMatchesJSONObjectFilter f = new ObjectMatchesJSONObjectFilter("a", objectFilter);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "objectMatches"), new JSONField("field", "a"), new JSONField("filter", objectFilter.toJSONObject())));
    f = (ObjectMatchesJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getFilter());
    assertEquals(f.getFilter(), objectFilter);
    objectFilter = new ANDJSONObjectFilter(new EqualsJSONObjectFilter("one", new JSONString("uno")), new EqualsJSONObjectFilter("two", new JSONString("dos")));
    f.setFilter(objectFilter);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "objectMatches"), new JSONField("field", "a"), new JSONField("filter", objectFilter.toJSONObject())));
    f = (ObjectMatchesJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getFilter());
    assertEquals(f.getFilter(), objectFilter);
    try {
        f.setFilter(null);
        fail("Expected an exception with setFilter null");
    } catch (final LDAPSDKUsageException e) {
    // This was expected
    }
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONField(com.unboundid.util.json.JSONField) LDAPSDKUsageException(com.unboundid.util.LDAPSDKUsageException) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 58 with JSONField

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

the class ObjectMatchesJSONObjectFilterTestCase method testObjectMatchesSimpleFilter.

/**
 * Tests the behavior of an object matches filter under a variety of
 * conditions with a simple filter.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testObjectMatchesSimpleFilter() throws Exception {
    EqualsJSONObjectFilter equalsFilter = new EqualsJSONObjectFilter("b", new JSONString("c"));
    ObjectMatchesJSONObjectFilter f = new ObjectMatchesJSONObjectFilter("a", equalsFilter);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "objectMatches"), new JSONField("field", "a"), new JSONField("filter", equalsFilter.toJSONObject())));
    f = (ObjectMatchesJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("a"));
    assertNotNull(f.getFilter());
    assertEquals(f.getFilter(), equalsFilter);
    assertNotNull(f.getFilterType());
    assertEquals(f.getFilterType(), "objectMatches");
    assertNotNull(f.getRequiredFieldNames());
    assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Arrays.asList("field", "filter")));
    assertNotNull(f.getOptionalFieldNames());
    assertEquals(f.getOptionalFieldNames(), Collections.emptySet());
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONObject(new JSONField("b", "c"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("b", "c"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONObject(new JSONField("a", new JSONObject(new JSONField("b", "c"))))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONObject(new JSONField("b", "c")), new JSONObject(new JSONField("b", "d")))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONObject(new JSONField("b", new JSONArray(new JSONString("c"), new JSONString("d"))))))));
    equalsFilter = new EqualsJSONObjectFilter(Arrays.asList("a", "b"), new JSONString("c"));
    f = new ObjectMatchesJSONObjectFilter("a", equalsFilter);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "objectMatches"), new JSONField("field", "a"), new JSONField("filter", equalsFilter.toJSONObject())));
    f = (ObjectMatchesJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONObject(new JSONField("b", "c"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("b", "c"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONObject(new JSONField("a", new JSONObject(new JSONField("b", "c"))))))));
}
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 59 with JSONField

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

the class ObjectMatchesJSONObjectFilterTestCase method testGetAndSetField.

/**
 * Provides test coverage for the methods that can be used to get and set
 * the field.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetAndSetField() throws Exception {
    final EqualsJSONObjectFilter equalsFilter = new EqualsJSONObjectFilter("b", new JSONString("c"));
    ObjectMatchesJSONObjectFilter f = new ObjectMatchesJSONObjectFilter("a", equalsFilter);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "objectMatches"), new JSONField("field", "a"), new JSONField("filter", equalsFilter.toJSONObject())));
    f = (ObjectMatchesJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("a"));
    f.setField("x");
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "objectMatches"), new JSONField("field", "x"), new JSONField("filter", equalsFilter.toJSONObject())));
    f = (ObjectMatchesJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("x"));
    f.setField("one", "two", "three");
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "objectMatches"), new JSONField("field", new JSONArray(new JSONString("one"), new JSONString("two"), new JSONString("three"))), new JSONField("filter", equalsFilter.toJSONObject())));
    f = (ObjectMatchesJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Arrays.asList("one", "two", "three"));
    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 60 with JSONField

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

the class RegularExpressionJSONObjectFilterTestCase method testStringRegex.

/**
 * Tests the regular expression filter with a valid string regex.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testStringRegex() throws Exception {
    RegularExpressionJSONObjectFilter f = new RegularExpressionJSONObjectFilter("a", "[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)

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