use of com.unboundid.ldap.sdk.ReadOnlyModifyRequest in project ldapsdk by pingidentity.
the class InMemoryDirectoryServerLDAPInterfaceTestCase method testModify.
/**
* Provides test coverage for the methods that can be used to process modify
* operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testModify() throws Exception {
ds.restoreSnapshot(snapshot);
// Test the method that takes a DN and a single modification.
LDAPResult modifyResult = ds.modify("dc=example,dc=com", new Modification(ModificationType.REPLACE, "description", "mod 1"));
assertNotNull(modifyResult);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
// Test the method that takes a DN and an array of modifications.
modifyResult = ds.modify("dc=example,dc=com", new Modification(ModificationType.DELETE, "description", "mod 1"), new Modification(ModificationType.ADD, "description", "mod 2"));
assertNotNull(modifyResult);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
// Test the method that takes a DN and a list of modifications.
modifyResult = ds.modify("dc=example,dc=com", Arrays.asList(new Modification(ModificationType.DELETE, "description", "mod 2"), new Modification(ModificationType.ADD, "description", "mod 3")));
assertNotNull(modifyResult);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
// Test the method that takes an LDIF representation of the modification.
modifyResult = ds.modify("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: mod 4");
assertNotNull(modifyResult);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
// Test the method that takes a modify request, with controls.
final ModifyRequest modifyRequest = new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: mod 5");
modifyRequest.addControl(new PreReadRequestControl("*", "+"));
modifyRequest.addControl(new PostReadRequestControl("*", "+"));
modifyResult = ds.modify(modifyRequest);
assertNotNull(modifyResult);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
assertTrue(modifyResult.hasResponseControl(PreReadResponseControl.PRE_READ_RESPONSE_OID));
final PreReadResponseControl preReadResponse = PreReadResponseControl.get(modifyResult);
assertNotNull(preReadResponse);
assertTrue(preReadResponse.getEntry().hasAttributeValue("description", "mod 4"));
assertTrue(modifyResult.hasResponseControl(PostReadResponseControl.POST_READ_RESPONSE_OID));
final PostReadResponseControl postReadResponse = PostReadResponseControl.get(modifyResult);
assertNotNull(postReadResponse);
assertTrue(postReadResponse.getEntry().hasAttributeValue("description", "mod 5"));
// Test the method that takes a read-only modify request, with controls.
final ReadOnlyModifyRequest readOnlyModifyRequest = new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: mod 6");
modifyResult = ds.modify(readOnlyModifyRequest);
assertNotNull(modifyResult);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
}
Aggregations