Search in sources :

Example 96 with JSONField

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

the class SubstringJSONObjectFilterTestCase method testSingleContains.

/**
 * Tests the behavior of a filter that only uses a single contains component.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSingleContains() throws Exception {
    SubstringJSONObjectFilter f = new SubstringJSONObjectFilter("test-field", null, "defghi", null);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "test-field"), new JSONField("contains", "defghi")));
    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(), Collections.singletonList("defghi"));
    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", "defghi"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "DeFgHi"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "DEFGHI"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "defabcghijkl"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "defghijkl"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABCDEFGHI"))));
    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", "defghi"))));
    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("defghi"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("ahcDEFghiJKL"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("abcdef"), new JSONString("ghijkl"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("abcjkl"), new JSONString("defghi"))))));
    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", "defghi"), new JSONField("caseSensitive", true)));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "defghi"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "DeFgHi"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "DEFGHI"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "defghijkl"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "ABCDEFGHI"))));
    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", JSONArray.EMPTY_ARRAY))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("defghi"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("ahcDEFghiJKL"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("abcdef"), new JSONString("ghijkl"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("abcjkl"), new JSONString("defghi"))))));
}
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 97 with JSONField

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

the class JSONLogFieldSyntax method tokenizeEntireValue.

/**
 * {@inheritDoc}
 */
@Override()
public void tokenizeEntireValue(@NotNull final JSONObject value, @NotNull final byte[] pepper, @NotNull final ByteStringBuffer buffer) {
    final JSONObject tokenizedObject = new JSONObject(new JSONField("tokenized", tokenize(value.toNormalizedString(), pepper)));
    buffer.append(tokenizedObject.toSingleLineString());
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONField(com.unboundid.util.json.JSONField)

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