Search in sources :

Example 91 with JSONField

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

the class OIDRegistryItemTestCase method testDecodeObjectWithoutType.

/**
 * Tests the behavior when trying to decode a JSON object that does not
 * include a type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeObjectWithoutType() throws Exception {
    final JSONObject o = new JSONObject(new JSONField("oid", "1.2.3.4"), new JSONField("name", "test-name"), new JSONField("origin", "test-origin"), new JSONField("url", "https://test.example.com/"));
    new OIDRegistryItem(o);
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONField(com.unboundid.util.json.JSONField) Test(org.testng.annotations.Test)

Example 92 with JSONField

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

the class LDAPCompareJSONOutputHandlerTestCase method testErrorResult.

/**
 * Tests the behavior of the output handler for a compare operation in which
 * the assertion yielded an error result.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testErrorResult() throws Exception {
    final CompareRequest compareRequest = new CompareRequest("ou=missing,dc=example,dc=com", "testAttr", "irrelevant");
    final String[] referralURLs = { "ldap://ds1.example.com/", "ldap://ds2.example.com/" };
    final LDAPResult compareResult = new LDAPResult(-1, ResultCode.NO_SUCH_OBJECT, "Entry 'ou=missing,dc=example,dc=com' does not exist", "dc=example,dc=com", referralURLs, null);
    final LDAPCompareJSONOutputHandler outputHandler = new LDAPCompareJSONOutputHandler();
    assertNotNull(outputHandler.getHeaderLines());
    assertTrue(outputHandler.getHeaderLines().length == 0);
    final String formattedOutput = outputHandler.formatResult(compareRequest, compareResult);
    assertNotNull(formattedOutput);
    assertEquals(formattedOutput, new JSONObject(new JSONField("entry-dn", "ou=missing,dc=example,dc=com"), new JSONField("attribute-name", "testAttr"), new JSONField("assertion-value", "irrelevant"), new JSONField("result-code-value", 32), new JSONField("result-code-name", "no such object"), new JSONField("diagnostic-message", "Entry 'ou=missing,dc=example,dc=com' does not exist"), new JSONField("matched-dn", "dc=example,dc=com"), new JSONField("referral-urls", new JSONArray(new JSONString("ldap://ds1.example.com/"), new JSONString("ldap://ds2.example.com/")))).toSingleLineString());
}
Also used : CompareRequest(com.unboundid.ldap.sdk.CompareRequest) JSONObject(com.unboundid.util.json.JSONObject) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) JSONArray(com.unboundid.util.json.JSONArray) JSONField(com.unboundid.util.json.JSONField) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 93 with JSONField

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

the class LDAPCompareJSONOutputHandlerTestCase method testCompareTrueResult.

/**
 * Tests the behavior of the output handler for a compare operation in which
 * the assertion matched.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testCompareTrueResult() throws Exception {
    final CompareRequest compareRequest = new CompareRequest("dc=example,dc=com", "objectClass", "top");
    final LDAPResult compareResult = new LDAPResult(-1, ResultCode.COMPARE_TRUE);
    final LDAPCompareJSONOutputHandler outputHandler = new LDAPCompareJSONOutputHandler();
    assertNotNull(outputHandler.getHeaderLines());
    assertTrue(outputHandler.getHeaderLines().length == 0);
    final String formattedOutput = outputHandler.formatResult(compareRequest, compareResult);
    assertNotNull(formattedOutput);
    assertEquals(formattedOutput, new JSONObject(new JSONField("entry-dn", "dc=example,dc=com"), new JSONField("attribute-name", "objectClass"), new JSONField("assertion-value", "top"), new JSONField("result-code-value", 6), new JSONField("result-code-name", "compare true")).toSingleLineString());
}
Also used : CompareRequest(com.unboundid.ldap.sdk.CompareRequest) JSONObject(com.unboundid.util.json.JSONObject) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) JSONField(com.unboundid.util.json.JSONField) JSONString(com.unboundid.util.json.JSONString) Test(org.testng.annotations.Test)

Example 94 with JSONField

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

the class ModifiablePasswordPolicyStateJSONBuilderTestCase method testAccountIsFailureLocked.

/**
 * Tests the behavior for properties related to the account is failure-locked
 * flag.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAccountIsFailureLocked() throws Exception {
    ModifiablePasswordPolicyStateJSONBuilder builder = new ModifiablePasswordPolicyStateJSONBuilder().setAccountIsFailureLocked(true);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNull(builder.getAccountExpirationTime());
    assertNotNull(builder.getAccountIsFailureLocked());
    assertTrue(builder.getAccountIsFailureLocked());
    assertNull(builder.getPasswordExpirationWarnedTime());
    assertNull(builder.getMustChangePassword());
    assertNotNull(builder.toString());
    ModifyRequest modifyRequest = builder.toModifyRequest("uid=test.user,ou=People,dc=example,dc=com");
    assertNotNull(modifyRequest);
    assertDNsEqual(modifyRequest.getDN(), "uid=test.user,ou=People,dc=example,dc=com");
    assertEquals(modifyRequest.getModifications().size(), 1);
    assertEquals(modifyRequest.getModifications().get(0).getModificationType(), ModificationType.REPLACE);
    assertEquals(modifyRequest.getModifications().get(0).getAttributeName(), "ds-pwp-modifiable-state-json");
    assertEquals(new JSONObject(modifyRequest.getModifications().get(0).getAttribute().getValue()), new JSONObject(new JSONField("account-is-failure-locked", true)));
    builder.setAccountIsFailureLocked(false);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNull(builder.getAccountExpirationTime());
    assertNotNull(builder.getAccountIsFailureLocked());
    assertFalse(builder.getAccountIsFailureLocked());
    assertNull(builder.getPasswordExpirationWarnedTime());
    assertNull(builder.getMustChangePassword());
    assertNotNull(builder.toString());
    modifyRequest = builder.toModifyRequest("uid=test.user,ou=People,dc=example,dc=com");
    assertNotNull(modifyRequest);
    assertDNsEqual(modifyRequest.getDN(), "uid=test.user,ou=People,dc=example,dc=com");
    assertEquals(modifyRequest.getModifications().size(), 1);
    assertEquals(modifyRequest.getModifications().get(0).getModificationType(), ModificationType.REPLACE);
    assertEquals(modifyRequest.getModifications().get(0).getAttributeName(), "ds-pwp-modifiable-state-json");
    assertEquals(new JSONObject(modifyRequest.getModifications().get(0).getAttribute().getValue()), new JSONObject(new JSONField("account-is-failure-locked", false)));
    builder.setAccountIsFailureLocked(null);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNull(builder.getAccountExpirationTime());
    assertNull(builder.getAccountIsFailureLocked());
    assertNull(builder.getPasswordExpirationWarnedTime());
    assertNull(builder.getMustChangePassword());
    assertNotNull(builder.toString());
    modifyRequest = builder.toModifyRequest("uid=test.user,ou=People,dc=example,dc=com");
    assertNotNull(modifyRequest);
    assertDNsEqual(modifyRequest.getDN(), "uid=test.user,ou=People,dc=example,dc=com");
    assertEquals(modifyRequest.getModifications().size(), 1);
    assertEquals(modifyRequest.getModifications().get(0).getModificationType(), ModificationType.REPLACE);
    assertEquals(modifyRequest.getModifications().get(0).getAttributeName(), "ds-pwp-modifiable-state-json");
    assertEquals(new JSONObject(modifyRequest.getModifications().get(0).getAttribute().getValue()), JSONObject.EMPTY_OBJECT);
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONField(com.unboundid.util.json.JSONField) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) Test(org.testng.annotations.Test)

Example 95 with JSONField

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

the class ModifiablePasswordPolicyStateJSONBuilderTestCase method testAccountIsDisabled.

/**
 * Tests the behavior for properties related to the account is disabled flag.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAccountIsDisabled() throws Exception {
    ModifiablePasswordPolicyStateJSONBuilder builder = new ModifiablePasswordPolicyStateJSONBuilder().setAccountIsDisabled(true);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNotNull(builder.getAccountIsDisabled());
    assertTrue(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNull(builder.getAccountExpirationTime());
    assertNull(builder.getAccountIsFailureLocked());
    assertNull(builder.getPasswordExpirationWarnedTime());
    assertNull(builder.getMustChangePassword());
    assertNotNull(builder.toString());
    ModifyRequest modifyRequest = builder.toModifyRequest("uid=test.user,ou=People,dc=example,dc=com");
    assertNotNull(modifyRequest);
    assertDNsEqual(modifyRequest.getDN(), "uid=test.user,ou=People,dc=example,dc=com");
    assertEquals(modifyRequest.getModifications().size(), 1);
    assertEquals(modifyRequest.getModifications().get(0).getModificationType(), ModificationType.REPLACE);
    assertEquals(modifyRequest.getModifications().get(0).getAttributeName(), "ds-pwp-modifiable-state-json");
    assertEquals(new JSONObject(modifyRequest.getModifications().get(0).getAttribute().getValue()), new JSONObject(new JSONField("account-is-disabled", true)));
    builder.setAccountIsDisabled(false);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNotNull(builder.getAccountIsDisabled());
    assertFalse(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNull(builder.getAccountExpirationTime());
    assertNull(builder.getAccountIsFailureLocked());
    assertNull(builder.getPasswordExpirationWarnedTime());
    assertNull(builder.getMustChangePassword());
    assertNotNull(builder.toString());
    modifyRequest = builder.toModifyRequest("uid=test.user,ou=People,dc=example,dc=com");
    assertNotNull(modifyRequest);
    assertDNsEqual(modifyRequest.getDN(), "uid=test.user,ou=People,dc=example,dc=com");
    assertEquals(modifyRequest.getModifications().size(), 1);
    assertEquals(modifyRequest.getModifications().get(0).getModificationType(), ModificationType.REPLACE);
    assertEquals(modifyRequest.getModifications().get(0).getAttributeName(), "ds-pwp-modifiable-state-json");
    assertEquals(new JSONObject(modifyRequest.getModifications().get(0).getAttribute().getValue()), new JSONObject(new JSONField("account-is-disabled", false)));
    builder.setAccountIsDisabled(null);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNull(builder.getAccountExpirationTime());
    assertNull(builder.getAccountIsFailureLocked());
    assertNull(builder.getPasswordExpirationWarnedTime());
    assertNull(builder.getMustChangePassword());
    assertNotNull(builder.toString());
    modifyRequest = builder.toModifyRequest("uid=test.user,ou=People,dc=example,dc=com");
    assertNotNull(modifyRequest);
    assertDNsEqual(modifyRequest.getDN(), "uid=test.user,ou=People,dc=example,dc=com");
    assertEquals(modifyRequest.getModifications().size(), 1);
    assertEquals(modifyRequest.getModifications().get(0).getModificationType(), ModificationType.REPLACE);
    assertEquals(modifyRequest.getModifications().get(0).getAttributeName(), "ds-pwp-modifiable-state-json");
    assertEquals(new JSONObject(modifyRequest.getModifications().get(0).getAttribute().getValue()), JSONObject.EMPTY_OBJECT);
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONField(com.unboundid.util.json.JSONField) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) Test(org.testng.annotations.Test)

Aggregations

JSONField (com.unboundid.util.json.JSONField)97 JSONObject (com.unboundid.util.json.JSONObject)97 Test (org.testng.annotations.Test)91 JSONArray (com.unboundid.util.json.JSONArray)68 JSONString (com.unboundid.util.json.JSONString)66 JSONNumber (com.unboundid.util.json.JSONNumber)20 PasswordPolicyStateJSONField (com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField)11 LDAPSDKUsageException (com.unboundid.util.LDAPSDKUsageException)8 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)7 Date (java.util.Date)7 Entry (com.unboundid.ldap.sdk.Entry)5 JSONException (com.unboundid.util.json.JSONException)5 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)4 JSONBoolean (com.unboundid.util.json.JSONBoolean)4 JSONValue (com.unboundid.util.json.JSONValue)4 CompareRequest (com.unboundid.ldap.sdk.CompareRequest)3 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)3 PasswordQualityRequirement (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement)3 LogField (com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField)3 ArrayList (java.util.ArrayList)3