Search in sources :

Example 1 with EqualsJSONObjectFilter

use of com.unboundid.ldap.sdk.unboundidds.jsonfilter.EqualsJSONObjectFilter in project ldapsdk by pingidentity.

the class FilterTestCase method testMatchesEntryJSONObjectExtensibleMatch.

/**
 * Tests the behavior of the matchesEntry method when the provided filter uses
 * the jsonObjectFilterExtensibleMatch matching rule.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testMatchesEntryJSONObjectExtensibleMatch() throws Exception {
    final Entry entry = new Entry("dn: uid=test.user,ou=People,dc=example,dc=com", "objectClass: top", "objectClass: ubidPerson", "uid: test.user", "givenName: Test", "sn: User", "cn: Test User", "ubidEmailJSON: not-a-valid-json-object", "ubidEmailJSON: " + new JSONObject(new JSONField("type", "personal"), new JSONField("value", "test.user@example.com"), new JSONField("primary", true)).toSingleLineString());
    JSONObjectFilter jsonObjectFilter = new EqualsJSONObjectFilter("value", "test.user@example.com");
    Filter filter = jsonObjectFilter.toLDAPFilter("ubidEmailJSON");
    assertTrue(filter.matchesEntry(entry));
    jsonObjectFilter = new EqualsJSONObjectFilter("value", "different.user@example.com");
    filter = jsonObjectFilter.toLDAPFilter("ubidEmailJSON");
    assertFalse(filter.matchesEntry(entry));
    filter = jsonObjectFilter.toLDAPFilter("nonexistentAttribute");
    assertFalse(filter.matchesEntry(entry));
    try {
        filter = Filter.createExtensibleMatchFilter("ubidEmailJSON", "1.3.6.1.4.1.30221.2.4.13", false, "not-a-valid-json-object");
        filter.matchesEntry(entry);
        fail("Expected an exception when trying to use a JSON object filter " + "whose assertion value is not a valid JSON object");
    } catch (final LDAPException e) {
        assertEquals(e.getResultCode(), ResultCode.INAPPROPRIATE_MATCHING);
    }
    try {
        filter = Filter.createExtensibleMatchFilter("ubidEmailJSON", "1.3.6.1.4.1.30221.2.4.13", false, "{}");
        filter.matchesEntry(entry);
        fail("Expected an exception when trying to use a JSON object filter " + "whose assertion value is a valid JSON object but not a valid " + "JSON object filter");
    } catch (final LDAPException e) {
        assertEquals(e.getResultCode(), ResultCode.INAPPROPRIATE_MATCHING);
    }
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) EqualsJSONObjectFilter(com.unboundid.ldap.sdk.unboundidds.jsonfilter.EqualsJSONObjectFilter) JSONObjectFilter(com.unboundid.ldap.sdk.unboundidds.jsonfilter.JSONObjectFilter) EqualsJSONObjectFilter(com.unboundid.ldap.sdk.unboundidds.jsonfilter.EqualsJSONObjectFilter) JSONField(com.unboundid.util.json.JSONField) EqualsJSONObjectFilter(com.unboundid.ldap.sdk.unboundidds.jsonfilter.EqualsJSONObjectFilter) JSONObjectFilter(com.unboundid.ldap.sdk.unboundidds.jsonfilter.JSONObjectFilter) Test(org.testng.annotations.Test)

Aggregations

EqualsJSONObjectFilter (com.unboundid.ldap.sdk.unboundidds.jsonfilter.EqualsJSONObjectFilter)1 JSONObjectFilter (com.unboundid.ldap.sdk.unboundidds.jsonfilter.JSONObjectFilter)1 JSONField (com.unboundid.util.json.JSONField)1 JSONObject (com.unboundid.util.json.JSONObject)1 Test (org.testng.annotations.Test)1