Search in sources :

Example 1 with JSONNumber

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

the class JSONLogsTestCase method createPopulatedMessageObject.

/**
 * Creates a JSON object with an encoded representation of a log message that
 * has values populated for most of the optional common fields.
 *
 * @param  messageType    The message type for the log message.  This must not
 *                        be {@code null}.
 * @param  operationType  The operation type for the log message.  This may be
 *                        {@code null} if it is not an operation log message.
 * @param  fields         The set of additional fields to include in the log
 *                        message.  This must not be {@code null} but may be
 *                        empty.
 *
 * @return  The log message that was created.
 */
@NotNull()
protected static JSONObject createPopulatedMessageObject(@NotNull final AccessLogMessageType messageType, @Nullable final AccessLogOperationType operationType, @NotNull final JSONField... fields) {
    final Map<String, JSONValue> fieldMap = createMinimalFieldMap(messageType, operationType);
    fieldMap.put(PRODUCT_NAME.getFieldName(), new JSONString(DEFAULT_PRODUCT_NAME));
    fieldMap.put(INSTANCE_NAME.getFieldName(), new JSONString(DEFAULT_INSTANCE_NAME));
    fieldMap.put(STARTUP_ID.getFieldName(), new JSONString(DEFAULT_STARTUP_ID));
    fieldMap.put(THREAD_ID.getFieldName(), new JSONNumber(DEFAULT_THREAD_ID));
    fieldMap.put(CONNECTION_ID.getFieldName(), new JSONNumber(DEFAULT_CONNECTION_ID));
    if (operationType != null) {
        fieldMap.put(OPERATION_ID.getFieldName(), new JSONNumber(DEFAULT_OPERATION_ID));
        fieldMap.put(MESSAGE_ID.getFieldName(), new JSONNumber(DEFAULT_MESSAGE_ID));
        fieldMap.put(TRIGGERED_BY_CONNECTION_ID.getFieldName(), new JSONNumber(DEFAULT_TRIGGERED_BY_CONNECTION_ID));
        fieldMap.put(TRIGGERED_BY_OPERATION_ID.getFieldName(), new JSONNumber(DEFAULT_TRIGGERED_BY_OPERATION_ID));
        fieldMap.put(ORIGIN.getFieldName(), new JSONString(DEFAULT_ORIGIN));
        fieldMap.put(REQUESTER_IP_ADDRESS.getFieldName(), new JSONString(DEFAULT_REQUESTER_IP));
        fieldMap.put(REQUESTER_DN.getFieldName(), new JSONString(DEFAULT_REQUESTER_DN));
        fieldMap.put(REQUEST_CONTROL_OIDS.getFieldName(), createArray(DEFAULT_REQUEST_CONTROL_OIDS));
        fieldMap.put(USING_ADMIN_SESSION_WORKER_THREAD.getFieldName(), new JSONBoolean(DEFAULT_USING_ADMIN_SESSION_WORKER_THREAD));
        fieldMap.put(ADMINISTRATIVE_OPERATION.getFieldName(), new JSONString(DEFAULT_ADMIN_OP_MESSAGE));
        fieldMap.put(INTERMEDIATE_CLIENT_REQUEST_CONTROL.getFieldName(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getControlObject());
        fieldMap.put(OPERATION_PURPOSE.getFieldName(), DEFAULT_OPERATION_PURPOSE_REQUEST.getControlObject());
        if ((messageType == AccessLogMessageType.FORWARD) || (messageType == AccessLogMessageType.FORWARD_FAILED) || (messageType == AccessLogMessageType.RESULT) || (messageType == AccessLogMessageType.ASSURANCE_COMPLETE)) {
            fieldMap.put(TARGET_HOST.getFieldName(), new JSONString(DEFAULT_FORWARD_TARGET_HOST));
            fieldMap.put(TARGET_PORT.getFieldName(), new JSONNumber(DEFAULT_FORWARD_TARGET_PORT));
            fieldMap.put(TARGET_PROTOCOL.getFieldName(), new JSONString(DEFAULT_FORWARD_TARGET_PROTOCOL));
        }
        if ((messageType == AccessLogMessageType.FORWARD_FAILED) || (messageType == AccessLogMessageType.RESULT) || (messageType == AccessLogMessageType.ASSURANCE_COMPLETE)) {
            fieldMap.put(RESULT_CODE_VALUE.getFieldName(), new JSONNumber(DEFAULT_RESULT_CODE.intValue()));
            fieldMap.put(RESULT_CODE_NAME.getFieldName(), new JSONString(DEFAULT_RESULT_CODE.getName()));
            fieldMap.put(DIAGNOSTIC_MESSAGE.getFieldName(), new JSONString(DEFAULT_DIAGNOSTIC_MESSAGE));
        }
        if ((messageType == AccessLogMessageType.RESULT) || (messageType == AccessLogMessageType.ASSURANCE_COMPLETE) || (messageType == AccessLogMessageType.ENTRY) || (messageType == AccessLogMessageType.REFERENCE) || (messageType == AccessLogMessageType.INTERMEDIATE_RESPONSE)) {
            fieldMap.put(RESPONSE_CONTROL_OIDS.getFieldName(), createArray(DEFAULT_RESPONSE_CONTROL_OIDS));
        }
        if ((messageType == AccessLogMessageType.RESULT) || (messageType == AccessLogMessageType.ASSURANCE_COMPLETE)) {
            fieldMap.put(ADDITIONAL_INFO.getFieldName(), new JSONString(DEFAULT_ADDITIONAL_INFO_MESSAGE));
            fieldMap.put(MATCHED_DN.getFieldName(), new JSONString(DEFAULT_MATCHED_DN));
            fieldMap.put(REFERRAL_URLS.getFieldName(), createArray(DEFAULT_REFERRAL_URLS));
            fieldMap.put(SERVERS_ACCESSED.getFieldName(), createArray(DEFAULT_SERVERS_ACCESSED));
            fieldMap.put(UNCACHED_DATA_ACCESSED.getFieldName(), new JSONBoolean(DEFAULT_UNCACHED_DATA_ACCESSED));
            fieldMap.put(WORK_QUEUE_WAIT_TIME_MILLIS.getFieldName(), new JSONNumber(DEFAULT_WORK_QUEUE_WAIT_TIME_MILLIS));
            fieldMap.put(PROCESSING_TIME_MILLIS.getFieldName(), new JSONNumber(DEFAULT_PROCESSING_TIME_MILLIS));
            fieldMap.put(INTERMEDIATE_RESPONSES_RETURNED.getFieldName(), new JSONNumber(DEFAULT_INTERMEDIATE_RESPONSES_RETURNED));
            fieldMap.put(USED_PRIVILEGES.getFieldName(), createArray(DEFAULT_USED_PRIVILEGES));
            fieldMap.put(PRE_AUTHORIZATION_USED_PRIVILEGES.getFieldName(), createArray(DEFAULT_PRE_AUTHZ_USED_PRIVILEGES));
            fieldMap.put(MISSING_PRIVILEGES.getFieldName(), createArray(DEFAULT_MISSING_PRIVILEGES));
            if (operationType != AccessLogOperationType.ABANDON) {
                fieldMap.put(INTERMEDIATE_CLIENT_RESPONSE_CONTROL.getFieldName(), DEFAULT_INTERMEDIATE_CLIENT_RESPONSE.getControlObject());
            }
            if ((operationType == AccessLogOperationType.ADD) || (operationType == AccessLogOperationType.COMPARE) || (operationType == AccessLogOperationType.DELETE) || (operationType == AccessLogOperationType.MODIFY) || (operationType == AccessLogOperationType.MODDN) || (operationType == AccessLogOperationType.SEARCH)) {
                fieldMap.put(AUTHORIZATION_DN.getFieldName(), new JSONString(DEFAULT_AUTHZ_DN));
            }
            if ((operationType == AccessLogOperationType.ADD) || (operationType == AccessLogOperationType.DELETE) || (operationType == AccessLogOperationType.MODIFY) || (operationType == AccessLogOperationType.MODDN)) {
                fieldMap.put(REPLICATION_CHANGE_ID.getFieldName(), new JSONString(DEFAULT_REPLICATION_CHANGE_ID));
                fieldMap.put(ASSURED_REPLICATION_REQUIREMENTS.getFieldName(), createAssuredReplicationRequirements());
            }
            if ((operationType == AccessLogOperationType.ADD) || (operationType == AccessLogOperationType.DELETE) || (operationType == AccessLogOperationType.MODIFY) || (operationType == AccessLogOperationType.MODDN) || (operationType == AccessLogOperationType.SEARCH)) {
                fieldMap.put(INDEXES_WITH_KEYS_ACCESSED_NEAR_ENTRY_LIMIT.getFieldName(), createArray(DEFAULT_INDEXES_NEAR_ENTRY_LIMIT));
                fieldMap.put(INDEXES_WITH_KEYS_ACCESSED_EXCEEDING_ENTRY_LIMIT.getFieldName(), createArray(DEFAULT_INDEXES_EXCEEDING_ENTRY_LIMIT));
            }
        }
        if (messageType == AccessLogMessageType.ASSURANCE_COMPLETE) {
            fieldMap.put(LOCAL_ASSURANCE_SATISFIED.getFieldName(), new JSONBoolean(DEFAULT_LOCAL_ASSURANCE_SATISFIED));
            fieldMap.put(REMOTE_ASSURANCE_SATISFIED.getFieldName(), new JSONBoolean(DEFAULT_REMOTE_ASSURANCE_SATISFIED));
            fieldMap.put(SERVER_ASSURANCE_RESULTS.getFieldName(), new JSONArray(DEFAULT_ASSURED_REPLICATION_SERVER_RESULTS.get(0).getServerResultObject(), DEFAULT_ASSURED_REPLICATION_SERVER_RESULTS.get(1).getServerResultObject()));
        }
    }
    for (final JSONField field : fields) {
        fieldMap.put(field.getName(), field.getValue());
    }
    return new JSONObject(fieldMap);
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONBoolean(com.unboundid.util.json.JSONBoolean) JSONField(com.unboundid.util.json.JSONField) JSONNumber(com.unboundid.util.json.JSONNumber) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) NotNull(com.unboundid.util.NotNull)

Example 2 with JSONNumber

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

the class GreaterThanJSONObjectFilter method matches.

/**
 * Indicates whether the provided value matches the criteria of this filter.
 *
 * @param  v  The value for which to make the determination.
 *
 * @return  {@code true} if the provided value matches the criteria of this
 *          filter, or {@code false} if not.
 */
private boolean matches(@NotNull final JSONValue v) {
    if ((v instanceof JSONNumber) && (value instanceof JSONNumber)) {
        final BigDecimal targetValue = ((JSONNumber) value).getValue();
        final BigDecimal objectValue = ((JSONNumber) v).getValue();
        if (allowEquals) {
            return (objectValue.compareTo(targetValue) >= 0);
        } else {
            return (objectValue.compareTo(targetValue) > 0);
        }
    } else if ((v instanceof JSONString) && (value instanceof JSONString)) {
        final String targetValue = ((JSONString) value).stringValue();
        final String objectValue = ((JSONString) v).stringValue();
        if (allowEquals) {
            if (caseSensitive) {
                return (objectValue.compareTo(targetValue) >= 0);
            } else {
                return (objectValue.compareToIgnoreCase(targetValue) >= 0);
            }
        } else {
            if (caseSensitive) {
                return (objectValue.compareTo(targetValue) > 0);
            } else {
                return (objectValue.compareToIgnoreCase(targetValue) > 0);
            }
        }
    } else {
        return false;
    }
}
Also used : JSONNumber(com.unboundid.util.json.JSONNumber) JSONString(com.unboundid.util.json.JSONString) BigDecimal(java.math.BigDecimal) JSONString(com.unboundid.util.json.JSONString)

Example 3 with JSONNumber

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

the class ANDJSONObjectFilterTestCase method testOneComponent.

/**
 * Tests the behavior of an AND 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"));
    ANDJSONObjectFilter f = new ANDJSONObjectFilter(equalsFilter);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "and"), new JSONField("andFilters", new JSONArray(equalsFilter.toJSONObject()))));
    f = (ANDJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getANDFilters());
    assertEquals(f.getANDFilters(), Collections.singletonList(equalsFilter));
    assertNotNull(f.getFilterType());
    assertEquals(f.getFilterType(), "and");
    assertNotNull(f.getRequiredFieldNames());
    assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Collections.singletonList("andFilters")));
    assertNotNull(f.getOptionalFieldNames());
    assertEquals(f.getOptionalFieldNames(), Collections.emptySet());
    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 4 with JSONNumber

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

the class EqualsAnyJSONObjectFilterTestCase method testEqualsAnyList.

/**
 * Tests the behavior of the equals any filter with a number of cases and
 * values specified in a list.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testEqualsAnyList() throws Exception {
    EqualsAnyJSONObjectFilter f = new EqualsAnyJSONObjectFilter("test-field", Arrays.asList(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT));
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equalsAny"), new JSONField("field", "test-field"), new JSONField("values", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT))));
    f = (EqualsAnyJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("test-field"));
    assertNotNull(f.getValues());
    assertEquals(f.getValues(), Arrays.asList(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT));
    assertFalse(f.caseSensitive());
    assertNotNull(f.getFilterType());
    assertEquals(f.getFilterType(), "equalsAny");
    assertNotNull(f.getRequiredFieldNames());
    assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Arrays.asList("field", "values")));
    assertNotNull(f.getOptionalFieldNames());
    assertEquals(f.getOptionalFieldNames(), new HashSet<String>(Collections.singletonList("caseSensitive")));
    assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bar"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "baz"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 1234))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", true))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONNull.NULL))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONArray.EMPTY_ARRAY))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONObject.EMPTY_OBJECT))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "foo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("FOO"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("bar"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("baz"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(1234))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONBoolean.TRUE)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONNull.NULL)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONArray.EMPTY_ARRAY)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONObject.EMPTY_OBJECT)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT)))));
    f.setCaseSensitive(true);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equalsAny"), new JSONField("field", "test-field"), new JSONField("values", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT)), new JSONField("caseSensitive", true)));
    f = (EqualsAnyJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.caseSensitive());
    assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bar"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "baz"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 1234))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", true))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONNull.NULL))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONArray.EMPTY_ARRAY))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONObject.EMPTY_OBJECT))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "foo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("FOO"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("bar"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("baz"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(1234))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONBoolean.TRUE)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONNull.NULL)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONArray.EMPTY_ARRAY)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONObject.EMPTY_OBJECT)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT)))));
}
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 5 with JSONNumber

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

the class EqualsAnyJSONObjectFilterTestCase method testEqualsAnyArray.

/**
 * Tests the behavior of the equals any filter with a number of cases and
 * values specified in an array.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testEqualsAnyArray() throws Exception {
    EqualsAnyJSONObjectFilter f = new EqualsAnyJSONObjectFilter("test-field", new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equalsAny"), new JSONField("field", "test-field"), new JSONField("values", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT))));
    f = (EqualsAnyJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("test-field"));
    assertNotNull(f.getValues());
    assertEquals(f.getValues(), Arrays.asList(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT));
    assertFalse(f.caseSensitive());
    assertNotNull(f.getFilterType());
    assertEquals(f.getFilterType(), "equalsAny");
    assertNotNull(f.getRequiredFieldNames());
    assertEquals(f.getRequiredFieldNames(), new HashSet<String>(Arrays.asList("field", "values")));
    assertNotNull(f.getOptionalFieldNames());
    assertEquals(f.getOptionalFieldNames(), new HashSet<String>(Collections.singletonList("caseSensitive")));
    assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bar"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "baz"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 1234))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", true))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONNull.NULL))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONArray.EMPTY_ARRAY))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONObject.EMPTY_OBJECT))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "foo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("FOO"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("bar"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("baz"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(1234))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONBoolean.TRUE)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONNull.NULL)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONArray.EMPTY_ARRAY)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONObject.EMPTY_OBJECT)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT)))));
    f.setCaseSensitive(true);
    assertNotNull(f.toJSONObject());
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "equalsAny"), new JSONField("field", "test-field"), new JSONField("values", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT)), new JSONField("caseSensitive", true)));
    f = (EqualsAnyJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
    assertNotNull(f);
    assertTrue(f.caseSensitive());
    assertFalse(f.matchesJSONObject(JSONObject.EMPTY_OBJECT));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "foo"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "FOO"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "bar"))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", "baz"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", 1234))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", true))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONNull.NULL))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONArray.EMPTY_ARRAY))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", JSONObject.EMPTY_OBJECT))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("Test-Field", "foo"))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("FOO"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("bar"))))));
    assertFalse(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("baz"))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONNumber(1234))))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONBoolean.TRUE)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONNull.NULL)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONArray.EMPTY_ARRAY)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(JSONObject.EMPTY_OBJECT)))));
    assertTrue(f.matchesJSONObject(new JSONObject(new JSONField("test-field", new JSONArray(new JSONString("foo"), new JSONString("bar"), new JSONNumber(1234), JSONBoolean.TRUE, JSONNull.NULL, JSONArray.EMPTY_ARRAY, JSONObject.EMPTY_OBJECT)))));
}
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

JSONNumber (com.unboundid.util.json.JSONNumber)30 JSONString (com.unboundid.util.json.JSONString)28 JSONObject (com.unboundid.util.json.JSONObject)23 Test (org.testng.annotations.Test)23 JSONArray (com.unboundid.util.json.JSONArray)22 JSONField (com.unboundid.util.json.JSONField)20 JSONValue (com.unboundid.util.json.JSONValue)5 LDAPSDKUsageException (com.unboundid.util.LDAPSDKUsageException)4 NotNull (com.unboundid.util.NotNull)4 JSONBoolean (com.unboundid.util.json.JSONBoolean)4 LinkedHashMap (java.util.LinkedHashMap)4 Entry (com.unboundid.ldap.sdk.Entry)3 LogField (com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField)3 PasswordPolicyStateJSONField (com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField)2 StringLogFieldSyntax (com.unboundid.ldap.sdk.unboundidds.logs.v2.syntax.StringLogFieldSyntax)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 PasswordPolicyStateAccountUsabilityError (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityError)1 PasswordPolicyStateAccountUsabilityNotice (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityNotice)1 PasswordPolicyStateAccountUsabilityWarning (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordPolicyStateAccountUsabilityWarning)1