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