Search in sources :

Example 1 with ReadOnlyDeleteRequest

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);
}
Also used : AssertionRequestControl(com.unboundid.ldap.sdk.controls.AssertionRequestControl) LDAPException(com.unboundid.ldap.sdk.LDAPException) PreReadResponseControl(com.unboundid.ldap.sdk.controls.PreReadResponseControl) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) ReadOnlyDeleteRequest(com.unboundid.ldap.sdk.ReadOnlyDeleteRequest) PreReadRequestControl(com.unboundid.ldap.sdk.controls.PreReadRequestControl) ReadOnlyDeleteRequest(com.unboundid.ldap.sdk.ReadOnlyDeleteRequest) DeleteRequest(com.unboundid.ldap.sdk.DeleteRequest) Test(org.testng.annotations.Test)

Aggregations

DeleteRequest (com.unboundid.ldap.sdk.DeleteRequest)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)1 ReadOnlyDeleteRequest (com.unboundid.ldap.sdk.ReadOnlyDeleteRequest)1 AssertionRequestControl (com.unboundid.ldap.sdk.controls.AssertionRequestControl)1 PreReadRequestControl (com.unboundid.ldap.sdk.controls.PreReadRequestControl)1 PreReadResponseControl (com.unboundid.ldap.sdk.controls.PreReadResponseControl)1 Test (org.testng.annotations.Test)1