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)));
}
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)));
}
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)));
}
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)));
}
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);
}
Aggregations