Search in sources :

Example 36 with JSONField

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

the class ModifiablePasswordPolicyStateJSONBuilderTestCase method testPasswordChangedTime.

/**
 * Tests the behavior for properties related to the password changed time.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testPasswordChangedTime() throws Exception {
    final Date now = new Date();
    ModifiablePasswordPolicyStateJSONBuilder builder = new ModifiablePasswordPolicyStateJSONBuilder().setPasswordChangedTime(now.getTime());
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNotNull(builder.getPasswordChangedTime());
    assertEquals(builder.getPasswordChangedTime().longValue(), now.getTime());
    assertNull(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("password-changed-time", StaticUtils.encodeRFC3339Time(now))));
    builder.setPasswordChangedTime(-1234L);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNotNull(builder.getPasswordChangedTime());
    assertEquals(builder.getPasswordChangedTime().longValue(), -1L);
    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()), new JSONObject(new JSONField("password-changed-time", JSONNull.NULL)));
    builder.setPasswordChangedTime(now);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNotNull(builder.getPasswordChangedTime());
    assertEquals(builder.getPasswordChangedTime().longValue(), now.getTime());
    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()), new JSONObject(new JSONField("password-changed-time", StaticUtils.encodeRFC3339Time(now))));
    builder.setPasswordChangedTime(NULL_DATE);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNotNull(builder.getPasswordChangedTime());
    assertEquals(builder.getPasswordChangedTime().longValue(), -1L);
    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()), new JSONObject(new JSONField("password-changed-time", JSONNull.NULL)));
    builder.setPasswordChangedTime(NULL_LONG);
    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);
    builder.clearPasswordChangedTime();
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNotNull(builder.getPasswordChangedTime());
    assertEquals(builder.getPasswordChangedTime().longValue(), -1L);
    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()), new JSONObject(new JSONField("password-changed-time", JSONNull.NULL)));
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONField(com.unboundid.util.json.JSONField) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 37 with JSONField

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

the class ModifiablePasswordPolicyStateJSONBuilderTestCase method testAccountExpirationTime.

/**
 * Tests the behavior for properties related to the account expiration time.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAccountExpirationTime() throws Exception {
    final Date now = new Date();
    ModifiablePasswordPolicyStateJSONBuilder builder = new ModifiablePasswordPolicyStateJSONBuilder().setAccountExpirationTime(now.getTime());
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNotNull(builder.getAccountExpirationTime());
    assertEquals(builder.getAccountExpirationTime().longValue(), now.getTime());
    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-expiration-time", StaticUtils.encodeRFC3339Time(now))));
    builder.setAccountExpirationTime(-1234L);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNotNull(builder.getAccountExpirationTime());
    assertEquals(builder.getAccountExpirationTime().longValue(), -1L);
    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-expiration-time", JSONNull.NULL)));
    builder.setAccountExpirationTime(now);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNotNull(builder.getAccountExpirationTime());
    assertEquals(builder.getAccountExpirationTime().longValue(), now.getTime());
    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-expiration-time", StaticUtils.encodeRFC3339Time(now))));
    builder.setAccountExpirationTime(NULL_DATE);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNotNull(builder.getAccountExpirationTime());
    assertEquals(builder.getAccountExpirationTime().longValue(), -1L);
    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-expiration-time", JSONNull.NULL)));
    builder.setAccountExpirationTime(NULL_LONG);
    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);
    builder.clearAccountExpirationTime();
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNotNull(builder.getAccountExpirationTime());
    assertEquals(builder.getAccountExpirationTime().longValue(), -1L);
    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-expiration-time", JSONNull.NULL)));
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONField(com.unboundid.util.json.JSONField) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 38 with JSONField

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

the class ModifiablePasswordPolicyStateJSONBuilderTestCase method testAccountActivationTime.

/**
 * Tests the behavior for properties related to the account activation time.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAccountActivationTime() throws Exception {
    final Date now = new Date();
    ModifiablePasswordPolicyStateJSONBuilder builder = new ModifiablePasswordPolicyStateJSONBuilder().setAccountActivationTime(now.getTime());
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNotNull(builder.getAccountActivationTime());
    assertEquals(builder.getAccountActivationTime().longValue(), now.getTime());
    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-activation-time", StaticUtils.encodeRFC3339Time(now))));
    builder.setAccountActivationTime(-1234L);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNotNull(builder.getAccountActivationTime());
    assertEquals(builder.getAccountActivationTime().longValue(), -1L);
    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-activation-time", JSONNull.NULL)));
    builder.setAccountActivationTime(now);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNotNull(builder.getAccountActivationTime());
    assertEquals(builder.getAccountActivationTime().longValue(), now.getTime());
    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-activation-time", StaticUtils.encodeRFC3339Time(now))));
    builder.setAccountActivationTime(NULL_DATE);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNotNull(builder.getAccountActivationTime());
    assertEquals(builder.getAccountActivationTime().longValue(), -1L);
    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-activation-time", JSONNull.NULL)));
    builder.setAccountActivationTime(NULL_LONG);
    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);
    builder.clearAccountActivationTime();
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNotNull(builder.getAccountActivationTime());
    assertEquals(builder.getAccountActivationTime().longValue(), -1L);
    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-activation-time", JSONNull.NULL)));
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONField(com.unboundid.util.json.JSONField) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 39 with JSONField

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

the class ModifiablePasswordPolicyStateJSONBuilderTestCase method testPasswordExpirationWarnedTime.

/**
 * Tests the behavior for properties related to the password expiration warned
 * time.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testPasswordExpirationWarnedTime() throws Exception {
    final Date now = new Date();
    ModifiablePasswordPolicyStateJSONBuilder builder = new ModifiablePasswordPolicyStateJSONBuilder().setPasswordExpirationWarnedTime(now.getTime());
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNull(builder.getAccountExpirationTime());
    assertNull(builder.getAccountIsFailureLocked());
    assertNotNull(builder.getPasswordExpirationWarnedTime());
    assertEquals(builder.getPasswordExpirationWarnedTime().longValue(), now.getTime());
    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("password-expiration-warned-time", StaticUtils.encodeRFC3339Time(now))));
    builder.setPasswordExpirationWarnedTime(-1234L);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNull(builder.getAccountExpirationTime());
    assertNull(builder.getAccountIsFailureLocked());
    assertNotNull(builder.getPasswordExpirationWarnedTime());
    assertEquals(builder.getPasswordExpirationWarnedTime().longValue(), -1L);
    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("password-expiration-warned-time", JSONNull.NULL)));
    builder.setPasswordExpirationWarnedTime(now);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNull(builder.getAccountExpirationTime());
    assertNull(builder.getAccountIsFailureLocked());
    assertNotNull(builder.getPasswordExpirationWarnedTime());
    assertEquals(builder.getPasswordExpirationWarnedTime().longValue(), now.getTime());
    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("password-expiration-warned-time", StaticUtils.encodeRFC3339Time(now))));
    builder.setPasswordExpirationWarnedTime(NULL_DATE);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNull(builder.getAccountExpirationTime());
    assertNull(builder.getAccountIsFailureLocked());
    assertNotNull(builder.getPasswordExpirationWarnedTime());
    assertEquals(builder.getPasswordExpirationWarnedTime().longValue(), -1L);
    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("password-expiration-warned-time", JSONNull.NULL)));
    builder.setPasswordExpirationWarnedTime(NULL_LONG);
    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);
    builder.clearPasswordExpirationWarnedTime();
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNull(builder.getAccountExpirationTime());
    assertNull(builder.getAccountIsFailureLocked());
    assertNotNull(builder.getPasswordExpirationWarnedTime());
    assertEquals(builder.getPasswordExpirationWarnedTime().longValue(), -1L);
    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("password-expiration-warned-time", JSONNull.NULL)));
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) JSONField(com.unboundid.util.json.JSONField) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 40 with JSONField

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

the class ModifiablePasswordPolicyStateJSONBuilderTestCase method testMustChangePassword.

/**
 * Tests the behavior for properties related to the must change password flag.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testMustChangePassword() throws Exception {
    ModifiablePasswordPolicyStateJSONBuilder builder = new ModifiablePasswordPolicyStateJSONBuilder().setMustChangePassword(true);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNull(builder.getAccountExpirationTime());
    assertNull(builder.getAccountIsFailureLocked());
    assertNull(builder.getPasswordExpirationWarnedTime());
    assertNotNull(builder.getMustChangePassword());
    assertTrue(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("must-change-password", true)));
    builder.setMustChangePassword(false);
    builder = new ModifiablePasswordPolicyStateJSONBuilder(builder.build());
    assertNull(builder.getPasswordChangedTime());
    assertNull(builder.getAccountIsDisabled());
    assertNull(builder.getAccountActivationTime());
    assertNull(builder.getAccountExpirationTime());
    assertNull(builder.getAccountIsFailureLocked());
    assertNull(builder.getPasswordExpirationWarnedTime());
    assertNotNull(builder.getMustChangePassword());
    assertFalse(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("must-change-password", false)));
    builder.setMustChangePassword(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