use of com.unboundid.util.json.JSONArray 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.
}
}
use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class LDIFSearchTestCase method testJSONOutputFormat.
/**
* Tests the behavior when using the JSON output format.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testJSONOutputFormat() throws Exception {
final File ldifFile = createTempFile("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example", "", "dn: ou=People,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: People", "", "dn: uid=test.user,ou=People,dc=example,dc=com", "objectClass: top", "objectClass: person", "objectClass: organizationalPerson", "objectClass: inetOrgPerson", "uid: test.user", "givenName: Test", "sn: User", "cn: Test User");
final File outputFile = createTempFile();
assertTrue(outputFile.exists());
final ByteArrayOutputStream out = new ByteArrayOutputStream();
assertEquals(LDIFSearch.main(out, out, "--ldifFile", ldifFile.getAbsolutePath(), "--outputFile", outputFile.getAbsolutePath(), "--baseDN", "ou=People,dc=example,dc=com", "--scope", "sub", "--outputFormat", "json", "(objectClass=person)", "objectClass", "uid", "cn"), ResultCode.SUCCESS);
try (FileInputStream inputStream = new FileInputStream(outputFile);
JSONObjectReader jsonReader = new JSONObjectReader(inputStream)) {
JSONObject jsonObject = jsonReader.readObject();
assertNotNull(jsonObject);
assertEquals(jsonObject, new JSONObject(new JSONField("result-type", "entry"), new JSONField("dn", "uid=test.user,ou=People,dc=example,dc=com"), new JSONField("attributes", new JSONArray(new JSONObject(new JSONField("name", "objectClass"), new JSONField("values", new JSONArray(new JSONString("top"), new JSONString("person"), new JSONString("organizationalPerson"), new JSONString("inetOrgPerson")))), new JSONObject(new JSONField("name", "uid"), new JSONField("values", new JSONArray(new JSONString("test.user")))), new JSONObject(new JSONField("name", "cn"), new JSONField("values", new JSONArray(new JSONString("Test User"))))))));
jsonObject = jsonReader.readObject();
assertNull(jsonObject);
}
}
use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class RecentLoginHistoryTestCase method testDecodeMalformedSuccessNotObject.
/**
* Tests the behavior when trying to decode a JSON object with a malformed
* set of successful attempts when the malformed attempt is not an object.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeMalformedSuccessNotObject() throws Exception {
final JSONObject o = new JSONObject(new JSONField("successful-attempts", new JSONArray(new JSONString("malformed"))));
new RecentLoginHistory(o);
}
use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class RecentLoginHistoryTestCase method testDecodeMalformedSuccessObject.
/**
* Tests the behavior when trying to decode a JSON object with a malformed
* set of successful attempts when the malformed attempt is an object.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeMalformedSuccessObject() throws Exception {
final JSONObject o = new JSONObject(new JSONField("successful-attempts", new JSONArray(new JSONObject(new JSONField("malformed", true)))));
new RecentLoginHistory(o);
}
use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.
the class RecentLoginHistoryTestCase method testDecodeMalformedFailureNotObject.
/**
* Tests the behavior when trying to decode a JSON object with a malformed
* set of failed attempts when the malformed attempt is not an object.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeMalformedFailureNotObject() throws Exception {
final JSONObject o = new JSONObject(new JSONField("failed-attempts", new JSONArray(new JSONString("malformed"))));
new RecentLoginHistory(o);
}
Aggregations