Search in sources :

Example 51 with JSONField

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

the class OAUTHBEARERBindResultTestCase method testFailureResultWithCredentialsOnlyAuthzErrorCode.

/**
 * Tests the behavior for a failure result that includes server SASL
 * credentials with just an authorization error code.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testFailureResultWithCredentialsOnlyAuthzErrorCode() throws Exception {
    final String[] initialReferralURLs = { "ldap://ds1.example.com:389/o=initial" };
    final Control[] initialControls = { new Control("1.2.3.4") };
    final JSONObject initialFailureDetails = new JSONObject(new JSONField("status", "invalid_token"));
    final ASN1OctetString initialServerSASLCredentials = new ASN1OctetString(initialFailureDetails.toSingleLineString());
    final String[] finalReferralURLs = { "ldap://ds1.example.com:389/o=final" };
    final Control[] finalControls = { new Control("1.2.3.5") };
    final BindResult initialBindResult = new BindResult(3, ResultCode.SASL_BIND_IN_PROGRESS, "initial diagnostic message", "o=initial matched DN", initialReferralURLs, initialControls, initialServerSASLCredentials);
    final BindResult finalBindResult = new BindResult(4, ResultCode.INVALID_CREDENTIALS, "final diagnostic message", "o=final matched DN", finalReferralURLs, finalControls, null);
    final OAUTHBEARERBindResult bindResult = new OAUTHBEARERBindResult(initialBindResult, finalBindResult);
    assertEquals(bindResult.getMessageID(), 4);
    assertNotNull(bindResult.getResultCode());
    assertEquals(bindResult.getResultCode(), ResultCode.INVALID_CREDENTIALS);
    assertNotNull(bindResult.getDiagnosticMessage());
    assertEquals(bindResult.getDiagnosticMessage(), "final diagnostic message");
    assertNotNull(bindResult.getMatchedDN());
    assertDNsEqual(bindResult.getMatchedDN(), "o=final matched DN");
    assertNotNull(bindResult.getReferralURLs());
    assertEquals(bindResult.getReferralURLs().length, 1);
    assertEquals(bindResult.getReferralURLs()[0], finalReferralURLs[0]);
    assertNotNull(bindResult.getResponseControls());
    assertEquals(bindResult.getResponseControls().length, 1);
    assertEquals(bindResult.getResponseControls()[0], finalControls[0]);
    assertNotNull(bindResult.getServerSASLCredentials());
    assertTrue(bindResult.getServerSASLCredentials().equalsIgnoreType(initialServerSASLCredentials));
    assertNotNull(bindResult.getInitialBindResult());
    assertEquals(bindResult.getInitialBindResult(), initialBindResult);
    assertNotNull(bindResult.getFinalBindResult());
    assertEquals(bindResult.getFinalBindResult(), finalBindResult);
    assertNotNull(bindResult.getFailureDetailsObject());
    assertEquals(bindResult.getFailureDetailsObject(), initialFailureDetails);
    assertNotNull(bindResult.getAuthorizationErrorCode());
    assertEquals(bindResult.getAuthorizationErrorCode(), "invalid_token");
    assertNotNull(bindResult.getScopes());
    assertTrue(bindResult.getScopes().isEmpty());
    assertNull(bindResult.getOpenIDConfigurationURL());
    assertNotNull(bindResult.toString());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) JSONObject(com.unboundid.util.json.JSONObject) JSONField(com.unboundid.util.json.JSONField) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 52 with JSONField

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

the class LessThanJSONObjectFilterTestCase method testGreaterThanString.

/**
 * Tests the behavior of the greater-than filter with a string value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGreaterThanString() throws Exception {
    LessThanJSONObjectFilter f = new LessThanJSONObjectFilter("test-field", "foo");
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "lessThan"), new JSONField("field", "test-field"), new JSONField("value", "foo")));
    f = (LessThanJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("test-field"));
    assertNotNull(f.getValue());
    assertEquals(f.getValue(), new JSONString("foo"));
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    assertNotNull(f.getFilterType());
    assertEquals(f.getFilterType(), "lessThan");
    assertNotNull(f.getRequiredFieldNames());
    assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Arrays.asList("field", "value")));
    assertNotNull(f.getOptionalFieldNames());
    assertEquals(f.getOptionalFieldNames(), new HashSet<String>(Arrays.asList("allowEquals", "matchAllElements", "caseSensitive")));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "boo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 1234))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", Boolean.TRUE))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "boo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "flo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fool"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fold"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fr"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "f"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "b"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "boo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FLO"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOOL"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOLD"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FO"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FR"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "F"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "BO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "B"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("boo"), new JSONString("foo"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("boo"), new JSONString("fob"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("boo"), new JSONString("fool"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"), new JSONString("fool"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("too"), new JSONString("boo"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("BOO"), new JSONString("FOOL"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("FOO"), new JSONString("FOOL"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("TOO"), new JSONString("BOO"))))));
    f.setMatchAllElements(true);
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "lessThan"), new JSONField("field", "test-field"), new JSONField("value", "foo"), new JSONField("matchAllElements", true)));
    f = (LessThanJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.matchAllElements());
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "boo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 1234))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", Boolean.TRUE))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "boo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "flo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fool"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fold"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fr"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "f"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "b"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "boo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FLO"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOOL"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOLD"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FO"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FR"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "F"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "BO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "B"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("boo"), new JSONString("foo"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("boo"), new JSONString("fob"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("boo"), new JSONString("fool"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"), new JSONString("fool"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("too"), new JSONString("boo"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("BOO"), new JSONString("FOOL"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("FOO"), new JSONString("FOOL"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("TOO"), new JSONString("BOO"))))));
    f.setAllowEquals(true);
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "lessThan"), new JSONField("field", "test-field"), new JSONField("value", "foo"), new JSONField("matchAllElements", true), new JSONField("allowEquals", true)));
    f = (LessThanJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.allowEquals());
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "boo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 1234))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", Boolean.TRUE))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "boo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "flo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fool"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fold"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fr"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "f"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "b"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "boo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FLO"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOOL"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOLD"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FO"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FR"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "F"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "BO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "B"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("boo"), new JSONString("foo"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("boo"), new JSONString("fob"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("boo"), new JSONString("fool"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"), new JSONString("fool"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("too"), new JSONString("boo"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("BOO"), new JSONString("FOOL"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("FOO"), new JSONString("FOOL"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("TOO"), new JSONString("BOO"))))));
    f.setCaseSensitive(true);
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "lessThan"), new JSONField("field", "test-field"), new JSONField("value", "foo"), new JSONField("matchAllElements", true), new JSONField("allowEquals", true), new JSONField("caseSensitive", true)));
    f = (LessThanJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.caseSensitive());
    // NOTE:  All uppercase characters are considered "less than" all lowercase.
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "boo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 1234))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", Boolean.TRUE))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "goo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "flo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fool"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fold"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "f"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "b"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "BOO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FRO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOOL"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOLD"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "F"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "BO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "B"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("boo"), new JSONString("fold"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"), new JSONString("fold"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("too"), new JSONString("goo"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("BOO"), new JSONString("FOLD"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("FOO"), new JSONString("FOLD"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("too"), new JSONString("BOO"))))));
    f.setAllowEquals(false);
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "lessThan"), new JSONField("field", "test-field"), new JSONField("value", "foo"), new JSONField("matchAllElements", true), new JSONField("caseSensitive", true)));
    f = (LessThanJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertFalse(f.allowEquals());
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "boo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 1234))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", Boolean.TRUE))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "boo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "flo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fool"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fold"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "fr"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "f"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "b"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "boo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FLO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOOL"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOLD"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FR"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "F"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "BO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "B"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("boo"), new JSONString("foo"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("boo"), new JSONString("fob"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("boo"), new JSONString("fool"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"), new JSONString("fool"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("too"), new JSONString("boo"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("BOO"), new JSONString("FOOL"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("FOO"), new JSONString("FOOL"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("TOO"), new JSONString("BOO"))))));
}
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 53 with JSONField

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

the class LessThanJSONObjectFilterTestCase method testLessThanNumber.

/**
 * Tests the behavior of the less-than filter with a numeric value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testLessThanNumber() throws Exception {
    LessThanJSONObjectFilter f = new LessThanJSONObjectFilter("test-field", 5678);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "lessThan"), new JSONField("field", "test-field"), new JSONField("value", 5678)));
    f = (LessThanJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("test-field"));
    assertNotNull(f.getValue());
    assertEquals(f.getValue(), new JSONNumber(5678));
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    assertNotNull(f.getFilterType());
    assertEquals(f.getFilterType(), "lessThan");
    assertNotNull(f.getRequiredFieldNames());
    assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Arrays.asList("field", "value")));
    assertNotNull(f.getOptionalFieldNames());
    assertEquals(f.getOptionalFieldNames(), new HashSet<String>(Arrays.asList("allowEquals", "matchAllElements", "caseSensitive")));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5677))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", Boolean.TRUE))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", 5677))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 9999))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 10000))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 999))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 100))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5677.5))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678.0))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "5677"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5677))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5678), new JSONNumber(5677), new JSONNumber(1000))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(1234), new JSONNumber(5677), new JSONNumber(1000))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5677), new JSONNumber(1000))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5677), new JSONNumber(1000), new JSONString("foo"), JSONNull.NULL)))));
    f.setMatchAllElements(true);
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "lessThan"), new JSONField("field", "test-field"), new JSONField("value", 5678), new JSONField("matchAllElements", true)));
    f = (LessThanJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.matchAllElements());
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5677))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", Boolean.TRUE))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", 5677))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 9999))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 10000))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 999))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 100))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5677))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5677.5))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678.0))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "5677"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5677))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5678), new JSONNumber(5677), new JSONNumber(1000))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(1234), new JSONNumber(5677), new JSONNumber(1000))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5677), new JSONNumber(1000))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5677), new JSONNumber(1000), new JSONString("foo"), JSONNull.NULL)))));
    f.setAllowEquals(true);
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "lessThan"), new JSONField("field", "test-field"), new JSONField("value", 5678), new JSONField("matchAllElements", true), new JSONField("allowEquals", true)));
    f = (LessThanJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.allowEquals());
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5677))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", Boolean.TRUE))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", 5677))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 9999))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 10000))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 999))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 100))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5677))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5677.5))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 5678.0))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "5677"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5677))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5678), new JSONNumber(5677), new JSONNumber(1000))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(1234), new JSONNumber(5677), new JSONNumber(1000))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5677), new JSONNumber(1000))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(5677), new JSONNumber(1000), new JSONString("foo"), 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 54 with JSONField

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

the class ORJSONObjectFilterTestCase method testOneComponent.

/**
 * Tests the behavior of an OR filter with one component.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testOneComponent() throws Exception {
    final EqualsJSONObjectFilter equalsFilter = new EqualsJSONObjectFilter("a", new JSONString("b"));
    ORJSONObjectFilter f = new ORJSONObjectFilter(equalsFilter);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "or"), new JSONField("orFilters", new JSONArray(equalsFilter.toJSONObject()))));
    f = (ORJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getORFilters());
    assertEquals(f.getORFilters(), Collections.singletonList(equalsFilter));
    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));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "x"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("x", "b"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONNumber(1234), new JSONString("b"), JSONNull.NULL)))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", 1234))));
    f.setExclusive(true);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "or"), new JSONField("orFilters", new JSONArray(equalsFilter.toJSONObject())), new JSONField("exclusive", true)));
    f = (ORJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.exclusive());
    assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "x"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("x", "b"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONNumber(1234), new JSONString("b"), JSONNull.NULL)))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", 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) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 55 with JSONField

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

the class ORJSONObjectFilterTestCase method testMultipleComponents.

/**
 * Tests the behavior of an OR filter with multiple components.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testMultipleComponents() throws Exception {
    final EqualsJSONObjectFilter f1 = new EqualsJSONObjectFilter("a", new JSONString("b"));
    final EqualsJSONObjectFilter f2 = new EqualsJSONObjectFilter("c", new JSONString("d"));
    final EqualsJSONObjectFilter f3 = new EqualsJSONObjectFilter("e", new JSONString("f"));
    ORJSONObjectFilter f = new ORJSONObjectFilter(f1, f2, f3);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "or"), new JSONField("orFilters", new JSONArray(f1.toJSONObject(), f2.toJSONObject(), f3.toJSONObject()))));
    f = (ORJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getORFilters());
    assertEquals(f.getORFilters(), Arrays.asList(f1, f2, f3));
    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));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "x"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("x", "b"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONNumber(1234), new JSONString("a"), JSONNull.NULL)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONNumber(1234), new JSONString("b"), JSONNull.NULL)))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", 1234))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"), new JSONField("c", "d"), new JSONField("e", "f"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"), new JSONField("c", "d"), new JSONField("e", "f"), new JSONField("g", "h"), new JSONField("i", "j"))));
    f.setExclusive(true);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "or"), new JSONField("orFilters", JSONArray.EMPTY_ARRAY), new JSONField("orFilters", new JSONArray(f1.toJSONObject(), f2.toJSONObject(), f3.toJSONObject())), new JSONField("exclusive", true)));
    f = (ORJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.exclusive());
    assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "x"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("x", "b"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONNumber(1234), new JSONString("a"), JSONNull.NULL)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("a", new JSONArray(new JSONNumber(1234), new JSONString("b"), JSONNull.NULL)))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", 1234))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"), new JSONField("c", "d"), new JSONField("e", "f"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("a", "b"), new JSONField("c", "d"), new JSONField("e", "f"), new JSONField("g", "h"), new JSONField("i", "j"))));
}
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)

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