Search in sources :

Example 1 with ReadOnlyModifyRequest

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);
}
Also used : Modification(com.unboundid.ldap.sdk.Modification) ReadOnlyModifyRequest(com.unboundid.ldap.sdk.ReadOnlyModifyRequest) PreReadResponseControl(com.unboundid.ldap.sdk.controls.PreReadResponseControl) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) ReadOnlyModifyRequest(com.unboundid.ldap.sdk.ReadOnlyModifyRequest) 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 Modification (com.unboundid.ldap.sdk.Modification)1 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)1 ReadOnlyModifyRequest (com.unboundid.ldap.sdk.ReadOnlyModifyRequest)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