Search in sources :

Example 11 with LDAPSDKUsageException

use of com.unboundid.util.LDAPSDKUsageException 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 12 with LDAPSDKUsageException

use of com.unboundid.util.LDAPSDKUsageException in project ldapsdk by pingidentity.

the class SubstringJSONObjectFilterTestCase method testGetAndSetFields.

/**
 * Tests the behavior of the methods used to get and set the field name.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetAndSetFields() throws Exception {
    final SubstringJSONObjectFilter f = new SubstringJSONObjectFilter("a", "b", "c", "d");
    f.setCaseSensitive(true);
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("a"));
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "a"), new JSONField("startsWith", "b"), new JSONField("contains", "c"), new JSONField("endsWith", "d"), new JSONField("caseSensitive", true)));
    f.setField("different");
    assertNotNull(f.getField());
    assertEquals(f.getField(), Collections.singletonList("different"));
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", "different"), new JSONField("startsWith", "b"), new JSONField("contains", "c"), new JSONField("endsWith", "d"), new JSONField("caseSensitive", true)));
    f.setField("first", "second");
    assertNotNull(f.getField());
    assertEquals(f.getField(), Arrays.asList("first", "second"));
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "substring"), new JSONField("field", new JSONArray(new JSONString("first"), new JSONString("second"))), new JSONField("startsWith", "b"), new JSONField("contains", "c"), new JSONField("endsWith", "d"), new JSONField("caseSensitive", true)));
    try {
        f.setField();
        fail("Expected an exception from setField()");
    } 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 13 with LDAPSDKUsageException

use of com.unboundid.util.LDAPSDKUsageException in project ldapsdk by pingidentity.

the class GreaterThanJSONObjectFilterTestCase method testConstructors.

/**
 * Provides test coverage for the various constructors available for
 * greater-than filters.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testConstructors() throws Exception {
    GreaterThanJSONObjectFilter f = new GreaterThanJSONObjectFilter();
    assertNull(f.getField());
    assertNull(f.getValue());
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    f = new GreaterThanJSONObjectFilter("a", 1234);
    assertEquals(f.getField(), Collections.singletonList("a"));
    assertEquals(f.getValue(), new JSONNumber(1234));
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    assertNotNull(f.toJSONObject());
    f = new GreaterThanJSONObjectFilter("a", 1234.5);
    assertEquals(f.getField(), Collections.singletonList("a"));
    assertEquals(f.getValue(), new JSONNumber(1234.5));
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    assertNotNull(f.toJSONObject());
    f = new GreaterThanJSONObjectFilter("a", "foo");
    assertEquals(f.getField(), Collections.singletonList("a"));
    assertEquals(f.getValue(), new JSONString("foo"));
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    assertNotNull(f.toJSONObject());
    f = new GreaterThanJSONObjectFilter("a", new JSONNumber("1.234e3"));
    assertEquals(f.getField(), Collections.singletonList("a"));
    assertEquals(f.getValue(), new JSONNumber(1234));
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    assertNotNull(f.toJSONObject());
    try {
        f = new GreaterThanJSONObjectFilter("a", JSONNull.NULL);
        fail("Expected an exception from greaterThan with null");
    } catch (final LDAPSDKUsageException e) {
    // This was expected.
    }
    f = new GreaterThanJSONObjectFilter(Arrays.asList("a", "b", "c"), new JSONString("bar"));
    assertEquals(f.getField(), Arrays.asList("a", "b", "c"));
    assertEquals(f.getValue(), new JSONString("bar"));
    assertFalse(f.allowEquals());
    assertFalse(f.matchAllElements());
    assertFalse(f.caseSensitive());
    assertNotNull(f.toJSONObject());
    try {
        f = new GreaterThanJSONObjectFilter(Arrays.asList("a", "b", "c"), JSONBoolean.TRUE);
        fail("Expected an exception from greaterThan with true");
    } catch (final LDAPSDKUsageException e) {
    // This was expected.
    }
}
Also used : LDAPSDKUsageException(com.unboundid.util.LDAPSDKUsageException) JSONNumber(com.unboundid.util.json.JSONNumber) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 14 with LDAPSDKUsageException

use of com.unboundid.util.LDAPSDKUsageException in project ldapsdk by pingidentity.

the class GreaterThanJSONObjectFilterTestCase method testGetAndSetValue.

/**
 * Provides test coverage for the methods that can be used to get and set the
 * value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetAndSetValue() throws Exception {
    final GreaterThanJSONObjectFilter f = new GreaterThanJSONObjectFilter("a", 1234);
    assertEquals(f.getValue(), new JSONNumber(1234));
    f.setValue(5678);
    assertEquals(f.getValue(), new JSONNumber(5678));
    f.setValue(1234.5);
    assertEquals(f.getValue(), new JSONNumber(1234.5));
    f.setValue("foo");
    assertEquals(f.getValue(), new JSONString("foo"));
    f.setValue(new JSONNumber("1.234e3"));
    assertEquals(f.getValue(), new JSONNumber(1234));
    f.setValue(new JSONString("1.234e3"));
    assertEquals(f.getValue(), new JSONString("1.234e3"));
    try {
        f.setValue((String) null);
        fail("Expected an exception from setValue String null");
    } catch (final LDAPSDKUsageException e) {
    // This was expected.
    }
    try {
        f.setValue((JSONValue) null);
        fail("Expected an exception from setValue JSONValue null");
    } catch (final LDAPSDKUsageException e) {
    // This was expected.
    }
    try {
        f.setValue(JSONBoolean.TRUE);
        fail("Expected an exception from setValue true");
    } catch (final LDAPSDKUsageException e) {
    // This was expected.
    }
}
Also used : LDAPSDKUsageException(com.unboundid.util.LDAPSDKUsageException) JSONNumber(com.unboundid.util.json.JSONNumber) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 15 with LDAPSDKUsageException

use of com.unboundid.util.LDAPSDKUsageException in project ldapsdk by pingidentity.

the class ContainsFieldJSONObjectFilterTestCase method testSetField.

/**
 * Provides test coverage for the methods used to get and set the target
 * field.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSetField() throws Exception {
    ContainsFieldJSONObjectFilter f = new ContainsFieldJSONObjectFilter("field-name");
    assertEquals(f.getField(), Collections.singletonList("field-name"));
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "containsField"), new JSONField("field", "field-name")));
    f.setField("different-name");
    assertEquals(f.getField(), Collections.singletonList("different-name"));
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "containsField"), new JSONField("field", "different-name")));
    f.setField("first", "second");
    assertEquals(f.getField(), Arrays.asList("first", "second"));
    assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "containsField"), new JSONField("field", new JSONArray(new JSONString("first"), new JSONString("second")))));
    try {
        f.setField();
        fail("Expected an exception from setField()");
    } 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)

Aggregations

LDAPSDKUsageException (com.unboundid.util.LDAPSDKUsageException)17 Test (org.testng.annotations.Test)17 JSONString (com.unboundid.util.json.JSONString)12 JSONField (com.unboundid.util.json.JSONField)8 JSONObject (com.unboundid.util.json.JSONObject)8 JSONArray (com.unboundid.util.json.JSONArray)5 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)4 InMemoryDirectoryServerConfig (com.unboundid.ldap.listener.InMemoryDirectoryServerConfig)4 JSONNumber (com.unboundid.util.json.JSONNumber)4 JSONException (com.unboundid.util.json.JSONException)1