use of com.unboundid.util.LDAPSDKUsageException in project ldapsdk by pingidentity.
the class RegularExpressionJSONObjectFilterTestCase method testGetAndSetRegularExpression.
/**
* Provides test coverage for the methods that can be used to get and set the
* regular expression for a filter.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetAndSetRegularExpression() throws Exception {
RegularExpressionJSONObjectFilter f = new RegularExpressionJSONObjectFilter("a", "[a-zA-Z][a-zA-Z0-9]*");
assertNotNull(f.getRegularExpression());
assertEquals(f.getRegularExpression().pattern(), "[a-zA-Z][a-zA-Z0-9]*");
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "regularExpression"), new JSONField("field", "a"), new JSONField("regularExpression", "[a-zA-Z][a-zA-Z0-9]*")));
f.setRegularExpression("[a-zA-Z0-9]+");
assertNotNull(f.getRegularExpression());
assertEquals(f.getRegularExpression().pattern(), "[a-zA-Z0-9]+");
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "regularExpression"), new JSONField("field", "a"), new JSONField("regularExpression", "[a-zA-Z0-9]+")));
f.setRegularExpression(Pattern.compile("[a-zA-Z0-9]*"));
assertNotNull(f.getRegularExpression());
assertEquals(f.getRegularExpression().pattern(), "[a-zA-Z0-9]*");
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "regularExpression"), new JSONField("field", "a"), new JSONField("regularExpression", "[a-zA-Z0-9]*")));
try {
f.setRegularExpression((String) null);
fail("Expected an exception with setRegularExpression of string null");
} catch (final LDAPSDKUsageException e) {
// This was expected
}
try {
f.setRegularExpression("[invalid");
fail("Expected an exception with setRegularExpression of string invalid");
} catch (final JSONException e) {
// This was expected
}
try {
f.setRegularExpression((Pattern) null);
fail("Expected an exception with setRegularExpression of pattern null");
} catch (final LDAPSDKUsageException e) {
// This was expected
}
}
use of com.unboundid.util.LDAPSDKUsageException in project ldapsdk by pingidentity.
the class RegularExpressionJSONObjectFilterTestCase method testGetAndSetField.
/**
* Provides test coverage for the methods that can be used to get and set the
* target field for a filter.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetAndSetField() throws Exception {
RegularExpressionJSONObjectFilter f = new RegularExpressionJSONObjectFilter("a", "[a-zA-Z][a-zA-Z0-9]*");
assertNotNull(f.getField());
assertEquals(f.getField(), Collections.singletonList("a"));
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "regularExpression"), new JSONField("field", "a"), new JSONField("regularExpression", "[a-zA-Z][a-zA-Z0-9]*")));
f.setField("b");
assertNotNull(f.getField());
assertEquals(f.getField(), Collections.singletonList("b"));
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "regularExpression"), new JSONField("field", "b"), new JSONField("regularExpression", "[a-zA-Z][a-zA-Z0-9]*")));
f.setField("first", "second", "third");
assertNotNull(f.getField());
assertEquals(f.getField(), Arrays.asList("first", "second", "third"));
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "regularExpression"), new JSONField("field", new JSONArray(new JSONString("first"), new JSONString("second"), new JSONString("third"))), new JSONField("regularExpression", "[a-zA-Z][a-zA-Z0-9]*")));
try {
f.setField();
fail("Expected an exception with setField of empty");
} catch (final LDAPSDKUsageException e) {
// This was expected
}
}
use of com.unboundid.util.LDAPSDKUsageException in project ldapsdk by pingidentity.
the class LessThanJSONObjectFilterTestCase method testConstructors.
/**
* Provides test coverage for the various constructors available for
* less-than filters.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testConstructors() throws Exception {
LessThanJSONObjectFilter f = new LessThanJSONObjectFilter();
assertNull(f.getField());
assertNull(f.getValue());
assertFalse(f.allowEquals());
assertFalse(f.matchAllElements());
assertFalse(f.caseSensitive());
f = new LessThanJSONObjectFilter("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 LessThanJSONObjectFilter("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 LessThanJSONObjectFilter("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 LessThanJSONObjectFilter("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 LessThanJSONObjectFilter("a", JSONNull.NULL);
fail("Expected an exception from lessThan with null");
} catch (final LDAPSDKUsageException e) {
// This was expected.
}
f = new LessThanJSONObjectFilter(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 LessThanJSONObjectFilter(Arrays.asList("a", "b", "c"), JSONBoolean.TRUE);
fail("Expected an exception from lessThan with true");
} catch (final LDAPSDKUsageException e) {
// This was expected.
}
}
use of com.unboundid.util.LDAPSDKUsageException in project ldapsdk by pingidentity.
the class LessThanJSONObjectFilterTestCase 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 LessThanJSONObjectFilter f = new LessThanJSONObjectFilter("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.
}
}
use of com.unboundid.util.LDAPSDKUsageException in project ldapsdk by pingidentity.
the class ObjectMatchesJSONObjectFilterTestCase method testGetAndSetFilter.
/**
* Tests the behavior of the methods that can be used to get and set the
* object filter.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetAndSetFilter() throws Exception {
JSONObjectFilter objectFilter = new EqualsJSONObjectFilter("b", new JSONString("c"));
ObjectMatchesJSONObjectFilter f = new ObjectMatchesJSONObjectFilter("a", objectFilter);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "objectMatches"), new JSONField("field", "a"), new JSONField("filter", objectFilter.toJSONObject())));
f = (ObjectMatchesJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
assertNotNull(f);
assertNotNull(f.getFilter());
assertEquals(f.getFilter(), objectFilter);
objectFilter = new ANDJSONObjectFilter(new EqualsJSONObjectFilter("one", new JSONString("uno")), new EqualsJSONObjectFilter("two", new JSONString("dos")));
f.setFilter(objectFilter);
assertNotNull(f.toJSONObject());
assertEquals(f.toJSONObject(), new JSONObject(new JSONField("filterType", "objectMatches"), new JSONField("field", "a"), new JSONField("filter", objectFilter.toJSONObject())));
f = (ObjectMatchesJSONObjectFilter) JSONObjectFilter.decode(f.toJSONObject());
assertNotNull(f);
assertNotNull(f.getFilter());
assertEquals(f.getFilter(), objectFilter);
try {
f.setFilter(null);
fail("Expected an exception with setFilter null");
} catch (final LDAPSDKUsageException e) {
// This was expected
}
}
Aggregations