use of com.unboundid.ldap.sdk.ReadOnlyDeleteRequest in project ldapsdk by pingidentity.
the class InMemoryDirectoryServerLDAPInterfaceTestCase method testDelete.
/**
* Provides test coverage for the methods that can be used to process delete
* operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDelete() throws Exception {
ds.restoreSnapshot(snapshot);
// Test the method that takes a DN.
LDAPResult deleteResult = ds.delete("uid=test.user,ou=People,dc=example,dc=com");
assertNotNull(deleteResult);
assertEquals(deleteResult.getResultCode(), ResultCode.SUCCESS);
// Test the method that takes a delete request object, including controls.
final DeleteRequest deleteRequest = new DeleteRequest("ou=People,dc=example,dc=com");
deleteRequest.addControl(new AssertionRequestControl("(objectClass=top)"));
deleteRequest.addControl(new PreReadRequestControl("*", "+"));
deleteResult = ds.delete(deleteRequest);
assertNotNull(deleteResult);
assertEquals(deleteResult.getResultCode(), ResultCode.SUCCESS);
assertTrue(deleteResult.hasResponseControl(PreReadResponseControl.PRE_READ_RESPONSE_OID));
final PreReadResponseControl preReadResponse = PreReadResponseControl.get(deleteResult);
assertNotNull(preReadResponse);
assertTrue(preReadResponse.getEntry().hasAttribute("ou"));
assertTrue(preReadResponse.getEntry().hasAttribute("objectClass"));
assertTrue(preReadResponse.getEntry().hasAttribute("entryDN"));
assertTrue(preReadResponse.getEntry().hasAttribute("entryUUID"));
// Test the method that takes a read-only delete request object with a
// failed request.
ReadOnlyDeleteRequest readOnlyDeleteRequest = new DeleteRequest("ou=missing,dc=example,dc=com");
try {
ds.delete(readOnlyDeleteRequest);
fail("Expected an exception when trying to process a delete request " + "targeting a nonexistent entry.");
} catch (final LDAPException le) {
// This was expected.
assertEquals(le.getResultCode(), ResultCode.NO_SUCH_OBJECT);
}
// Test the method that takes a read-only delete request object with a
// successful request.
readOnlyDeleteRequest = new DeleteRequest("dc=example,dc=com");
deleteResult = ds.delete(readOnlyDeleteRequest);
assertNotNull(deleteResult);
assertEquals(deleteResult.getResultCode(), ResultCode.SUCCESS);
}
Aggregations