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