Search in sources :

Example 71 with JSONArray

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.
    }
}
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 72 with JSONArray

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);
    }
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONObjectReader(com.unboundid.util.json.JSONObjectReader) JSONField(com.unboundid.util.json.JSONField) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 73 with JSONArray

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);
}
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) Test(org.testng.annotations.Test)

Example 74 with JSONArray

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);
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) JSONField(com.unboundid.util.json.JSONField) Test(org.testng.annotations.Test)

Example 75 with JSONArray

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);
}
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) Test(org.testng.annotations.Test)

Aggregations

JSONArray (com.unboundid.util.json.JSONArray)98 JSONObject (com.unboundid.util.json.JSONObject)89 JSONString (com.unboundid.util.json.JSONString)77 Test (org.testng.annotations.Test)72 JSONField (com.unboundid.util.json.JSONField)68 JSONValue (com.unboundid.util.json.JSONValue)27 JSONNumber (com.unboundid.util.json.JSONNumber)22 NotNull (com.unboundid.util.NotNull)20 ArrayList (java.util.ArrayList)19 LinkedHashMap (java.util.LinkedHashMap)18 PasswordPolicyStateJSONField (com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField)11 PasswordQualityRequirement (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement)7 Entry (com.unboundid.ldap.sdk.Entry)6 Map (java.util.Map)6 LDAPSDKUsageException (com.unboundid.util.LDAPSDKUsageException)5 JSONBoolean (com.unboundid.util.json.JSONBoolean)5 JSONException (com.unboundid.util.json.JSONException)5 Date (java.util.Date)4 List (java.util.List)4 LogField (com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField)3