Search in sources :

Example 1 with ReadOnlyModifyDNRequest

use of com.unboundid.ldap.sdk.ReadOnlyModifyDNRequest in project ldapsdk by pingidentity.

the class InMemoryDirectoryServerLDAPInterfaceTestCase method testModifyDN.

/**
 * Provides test coverage for the methods that can be used to process modify
 * DN operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyDN() throws Exception {
    ds.restoreSnapshot(snapshot);
    ds.add("dn: ou=Users,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: Users");
    // Test the method that takes a DN, new RDN, and deleteOldRDN flag.
    LDAPResult modifyDNResult = ds.modifyDN("uid=test.user,ou=People,dc=example,dc=com", "uid=test.2", true);
    assertNotNull(modifyDNResult);
    assertEquals(modifyDNResult.getResultCode(), ResultCode.SUCCESS);
    // Test the method that takes a DN, new RDN, deleteOldRDN flag and a new
    // superior DN.
    modifyDNResult = ds.modifyDN("uid=test.2,ou=People,dc=example,dc=com", "uid=test.2", false, "ou=Users,dc=example,dc=com");
    assertNotNull(modifyDNResult);
    assertEquals(modifyDNResult.getResultCode(), ResultCode.SUCCESS);
    // Test the method that takes a modify DN request, with controls.
    final ModifyDNRequest modifyDNRequest = new ModifyDNRequest("uid=test.2,ou=Users,dc=example,dc=com", "uid=test.3", true);
    modifyDNRequest.addControl(new PreReadRequestControl("*", "+"));
    modifyDNRequest.addControl(new PostReadRequestControl("*", "+"));
    modifyDNResult = ds.modifyDN(modifyDNRequest);
    assertNotNull(modifyDNResult);
    assertEquals(modifyDNResult.getResultCode(), ResultCode.SUCCESS);
    assertTrue(modifyDNResult.hasResponseControl(PreReadResponseControl.PRE_READ_RESPONSE_OID));
    final PreReadResponseControl preReadResponse = PreReadResponseControl.get(modifyDNResult);
    assertNotNull(preReadResponse);
    assertTrue(preReadResponse.getEntry().hasAttributeValue("uid", "test.2"));
    assertTrue(modifyDNResult.hasResponseControl(PostReadResponseControl.POST_READ_RESPONSE_OID));
    final PostReadResponseControl postReadResponse = PostReadResponseControl.get(modifyDNResult);
    assertNotNull(postReadResponse);
    assertTrue(postReadResponse.getEntry().hasAttributeValue("uid", "test.3"));
    // Test the method that takes a read-only modify DN request.
    final ReadOnlyModifyDNRequest readOnlyModifyDNRequest = new ModifyDNRequest("uid=test.3,ou=Users,dc=example,dc=com", "uid=test.4", true);
    modifyDNResult = ds.modifyDN(readOnlyModifyDNRequest);
    assertNotNull(modifyDNResult);
    assertEquals(modifyDNResult.getResultCode(), ResultCode.SUCCESS);
}
Also used : ReadOnlyModifyDNRequest(com.unboundid.ldap.sdk.ReadOnlyModifyDNRequest) ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) ReadOnlyModifyDNRequest(com.unboundid.ldap.sdk.ReadOnlyModifyDNRequest) PreReadResponseControl(com.unboundid.ldap.sdk.controls.PreReadResponseControl) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) PreReadRequestControl(com.unboundid.ldap.sdk.controls.PreReadRequestControl) PostReadResponseControl(com.unboundid.ldap.sdk.controls.PostReadResponseControl) PostReadRequestControl(com.unboundid.ldap.sdk.controls.PostReadRequestControl) Test(org.testng.annotations.Test)

Aggregations

LDAPResult (com.unboundid.ldap.sdk.LDAPResult)1 ModifyDNRequest (com.unboundid.ldap.sdk.ModifyDNRequest)1 ReadOnlyModifyDNRequest (com.unboundid.ldap.sdk.ReadOnlyModifyDNRequest)1 PostReadRequestControl (com.unboundid.ldap.sdk.controls.PostReadRequestControl)1 PostReadResponseControl (com.unboundid.ldap.sdk.controls.PostReadResponseControl)1 PreReadRequestControl (com.unboundid.ldap.sdk.controls.PreReadRequestControl)1 PreReadResponseControl (com.unboundid.ldap.sdk.controls.PreReadResponseControl)1 Test (org.testng.annotations.Test)1