use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.
the class InMemoryOperationInterceptorTestCase method testModifyDNWithTransformations.
/**
* Tests to ensure that processing works correctly for modify DN operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testModifyDNWithTransformations() throws Exception {
final LDAPConnection conn = ds.getConnection();
conn.add("dn: ou=test1,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: test1");
conn.add("dn: ou=test2,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: test2");
conn.add("dn: ou=test3,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: test3");
conn.add("dn: ou=test4,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: test4");
conn.add("dn: ou=altered,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: altered");
ModifyDNRequest modifyDNRequest = new ModifyDNRequest("ou=test1,dc=example,dc=com", "ou=renamed1", true);
assertResultCodeEquals(conn, modifyDNRequest, ResultCode.SUCCESS);
assertEntryMissing(conn, "ou=test1,dc=example,dc=com");
assertEntryExists(conn, "ou=renamed1,dc=example,dc=com");
modifyDNRequest = new ModifyDNRequest("ou=test2,dc=example,dc=com", "ou=renamed2", true);
modifyDNRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.ALTER_DN));
assertResultCodeEquals(conn, modifyDNRequest, ResultCode.SUCCESS);
assertEntryExists(conn, "ou=test2,dc=example,dc=com");
assertEntryMissing(conn, "ou=altered,dc=example,dc=com");
assertEntryExists(conn, "ou=renamed2,dc=example,dc=com");
modifyDNRequest = new ModifyDNRequest("ou=test2,dc=example,dc=com", "ou=renamed3", true);
modifyDNRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.REJECT_REQUEST));
assertResultCodeEquals(conn, modifyDNRequest, ResultCode.UNWILLING_TO_PERFORM);
assertEntryExists(conn, "ou=test2,dc=example,dc=com");
assertEntryMissing(conn, "ou=renamed3,dc=example,dc=com");
modifyDNRequest = new ModifyDNRequest("ou=test2,dc=example,dc=com", "ou=renamed3", true);
modifyDNRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.REQUEST_RUNTIME_EXCEPTION));
assertResultCodeEquals(conn, modifyDNRequest, ResultCode.OTHER);
assertEntryExists(conn, "ou=test2,dc=example,dc=com");
assertEntryMissing(conn, "ou=renamed3,dc=example,dc=com");
modifyDNRequest = new ModifyDNRequest("ou=test2,dc=example,dc=com", "ou=renamed3", true);
modifyDNRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.ERROR_RESULT));
assertResultCodeEquals(conn, modifyDNRequest, ResultCode.UNWILLING_TO_PERFORM);
assertEntryMissing(conn, "ou=test2,dc=example,dc=com");
assertEntryExists(conn, "ou=renamed3,dc=example,dc=com");
modifyDNRequest = new ModifyDNRequest("ou=test3,dc=example,dc=com", "ou=renamed4", true);
modifyDNRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.RESULT_RUNTIME_EXCEPTION));
assertResultCodeEquals(conn, modifyDNRequest, ResultCode.OTHER);
assertEntryMissing(conn, "ou=test3,dc=example,dc=com");
assertEntryExists(conn, "ou=renamed4,dc=example,dc=com");
modifyDNRequest = new ModifyDNRequest("ou=test4,dc=example,dc=com", "ou=renamed5", true);
modifyDNRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.INJECT_INTERMEDIATE_RESPONSE));
final TestIntermediateResponseListener testIRListener = new TestIntermediateResponseListener();
modifyDNRequest.setIntermediateResponseListener(testIRListener);
assertResultCodeEquals(conn, modifyDNRequest, ResultCode.SUCCESS);
assertEntryMissing(conn, "ou=test4,dc=example,dc=com");
assertEntryExists(conn, "ou=renamed5,dc=example,dc=com");
assertEquals(testIRListener.getCount(), 2);
conn.delete("ou=renamed1,dc=example,dc=com");
conn.delete("ou=renamed2,dc=example,dc=com");
conn.delete("ou=renamed3,dc=example,dc=com");
conn.delete("ou=renamed4,dc=example,dc=com");
conn.delete("ou=renamed5,dc=example,dc=com");
conn.close();
}
use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.
the class InterceptedModifyDNOperationTestCase method testBasics.
/**
* Provides basic test coverage for an intercepted modify DN operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testBasics() throws Exception {
// Create an intercepted modify DN operation. We'll use a null connection,
// which shouldn't happen naturally but will be sufficient for this test.
final ModifyDNRequestProtocolOp requestOp = new ModifyDNRequestProtocolOp(new ModifyDNRequest("ou=a,dc=example,dc=com", "ou=b", true));
final InterceptedModifyDNOperation o = new InterceptedModifyDNOperation(null, 1, requestOp);
assertNotNull(o.toString());
// Test methods for a generic intercepted operation.
assertNull(o.getClientConnection());
assertEquals(o.getConnectionID(), -1L);
assertNull(o.getConnectedAddress());
assertEquals(o.getConnectedPort(), -1);
assertEquals(o.getMessageID(), 1);
assertNull(o.getProperty("propX"));
o.setProperty("propX", "valX");
assertNotNull(o.getProperty("propX"));
assertEquals(o.getProperty("propX"), "valX");
assertNotNull(o.toString());
o.setProperty("propX", null);
assertNull(o.getProperty("propX"));
// Test methods specific to an intercepted modify DN operation.
assertNotNull(o.getRequest());
assertDNsEqual(o.getRequest().getNewRDN(), "ou=b");
assertNotNull(o.toString());
final ModifyDNRequest r = o.getRequest().duplicate();
r.setNewRDN("ou=c");
o.setRequest(r);
assertNotNull(o.getRequest());
assertDNsEqual(o.getRequest().getNewRDN(), "ou=c");
assertNotNull(o.toString());
assertNull(o.getResult());
o.setResult(new LDAPResult(o.getMessageID(), ResultCode.SUCCESS));
assertNotNull(o.getResult());
assertNotNull(o.toString());
}
use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.
the class TransactionExtendedOperationHandlerTestCase method testFailedTransaction.
/**
* Provides a test case for a transaction in which one of the operations
* fails after other operations that should have succeeded.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testFailedTransaction() throws Exception {
final TestUnsolicitedNotificationHandler unsolicitedNotificationHandler = new TestUnsolicitedNotificationHandler();
final LDAPConnectionOptions connectionOptions = new LDAPConnectionOptions();
connectionOptions.setUnsolicitedNotificationHandler(unsolicitedNotificationHandler);
final InMemoryDirectoryServer ds = getTestDS(true, true);
final LDAPConnection conn = ds.getConnection(connectionOptions);
assertEquals(unsolicitedNotificationHandler.getNotificationCount(), 0);
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
final StartTransactionExtendedResult startTxnResult = (StartTransactionExtendedResult) conn.processExtendedOperation(new StartTransactionExtendedRequest());
assertResultCodeEquals(startTxnResult, ResultCode.SUCCESS);
final ASN1OctetString txnID = startTxnResult.getTransactionID();
assertNotNull(txnID);
final TransactionSpecificationRequestControl txnControl = new TransactionSpecificationRequestControl(txnID);
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
final AddRequest addRequest = new AddRequest("dn: ou=test,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: test");
addRequest.setControls(txnControl);
assertResultCodeEquals(conn, addRequest, ResultCode.SUCCESS);
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
final ModifyRequest modifyRequest = new ModifyRequest("dn: uid=test.user,ou=People,dc=example,dc=com", "changeType: modify", "replace: description", "description: foo");
modifyRequest.setControls(txnControl);
assertResultCodeEquals(conn, modifyRequest, ResultCode.SUCCESS);
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
final ModifyDNRequest modifyDNRequest = new ModifyDNRequest("uid=test.user,ou=People,dc=example,dc=com", "uid=test.user", false, "ou=test,dc=example,dc=com");
modifyDNRequest.setControls(txnControl);
assertResultCodeEquals(conn, modifyDNRequest, ResultCode.SUCCESS);
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
final DeleteRequest deleteRequest = new DeleteRequest("ou=missing,dc=example,dc=com");
deleteRequest.setControls(txnControl);
assertResultCodeEquals(conn, deleteRequest, ResultCode.SUCCESS);
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
final EndTransactionExtendedResult endTxnResult = (EndTransactionExtendedResult) conn.processExtendedOperation(new EndTransactionExtendedRequest(txnID, true));
assertResultCodeEquals(endTxnResult, ResultCode.NO_SUCH_OBJECT);
assertTrue(endTxnResult.getFailedOpMessageID() > 0);
assertEquals(endTxnResult.getFailedOpMessageID(), deleteRequest.getLastMessageID());
assertNotNull(endTxnResult.getOperationResponseControls());
assertTrue(endTxnResult.getOperationResponseControls().isEmpty());
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
conn.close();
assertEquals(unsolicitedNotificationHandler.getNotificationCount(), 0);
}
use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.
the class TransactionExtendedOperationHandlerTestCase method testFailedModifyDNInTransaction.
/**
* Provides a test case for a transaction in which a modify DN operation fails
* after other operations that should have succeeded.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testFailedModifyDNInTransaction() throws Exception {
final TestUnsolicitedNotificationHandler unsolicitedNotificationHandler = new TestUnsolicitedNotificationHandler();
final LDAPConnectionOptions connectionOptions = new LDAPConnectionOptions();
connectionOptions.setUnsolicitedNotificationHandler(unsolicitedNotificationHandler);
final InMemoryDirectoryServer ds = getTestDS(true, true);
final LDAPConnection conn = ds.getConnection(connectionOptions);
assertEquals(unsolicitedNotificationHandler.getNotificationCount(), 0);
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
final StartTransactionExtendedResult startTxnResult = (StartTransactionExtendedResult) conn.processExtendedOperation(new StartTransactionExtendedRequest());
assertResultCodeEquals(startTxnResult, ResultCode.SUCCESS);
final ASN1OctetString txnID = startTxnResult.getTransactionID();
assertNotNull(txnID);
final TransactionSpecificationRequestControl txnControl = new TransactionSpecificationRequestControl(txnID);
final AddRequest addRequest = new AddRequest("dn: ou=test,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: test");
addRequest.setControls(txnControl);
assertResultCodeEquals(conn, addRequest, ResultCode.SUCCESS);
final ModifyDNRequest modifyDNRequest = new ModifyDNRequest("ou=Missing,dc=example,dc=com", "ou=Still Missing", true);
modifyDNRequest.setControls(txnControl);
assertResultCodeEquals(conn, modifyDNRequest, ResultCode.SUCCESS);
final EndTransactionExtendedResult endTxnResult = (EndTransactionExtendedResult) conn.processExtendedOperation(new EndTransactionExtendedRequest(txnID, true));
assertResultCodeEquals(endTxnResult, ResultCode.NO_SUCH_OBJECT);
assertTrue(endTxnResult.getFailedOpMessageID() > 0);
assertEquals(endTxnResult.getFailedOpMessageID(), modifyDNRequest.getLastMessageID());
assertNotNull(endTxnResult.getOperationResponseControls());
assertTrue(endTxnResult.getOperationResponseControls().isEmpty());
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
conn.close();
assertEquals(unsolicitedNotificationHandler.getNotificationCount(), 0);
}
use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.
the class MultiUpdateExtendedRequestTestCase method testBasicWithControls.
/**
* Provides basic test coverage for the multi-update extended request with
* controls.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testBasicWithControls() throws Exception {
final Control[] modDNControls = { new ManageDsaITRequestControl() };
final LDAPRequest[] requests = { new AddRequest("dn: uid=test.user,ou=People,dc=example,dc=com", "objectClass: top", "objectClass: person", "objectClass: organizationalPerson", "objectClass: inetOrgPerson", "uid: test.user", "givenName: Test", "sn: User", "cn: Test User", "userPassword: password"), new ModifyRequest("dn: uid=test.user,ou=People,dc=example,dc=com", "changetype: modify", "replace: description", "description: foo"), new ModifyDNRequest("uid=test.user,ou=People,dc=example,dc=com", "cn=Test User", false, modDNControls), new PasswordModifyExtendedRequest("dn:cn=Test User,ou=People,dc=example,dc=com", "password", "newPassword"), new DeleteRequest("cn=Test User,ou=People,dc=example,dc=com") };
final Control[] controls = { new Control("1.2.3.4"), new Control("1.2.3.5", true) };
MultiUpdateExtendedRequest r = new MultiUpdateExtendedRequest(MultiUpdateErrorBehavior.ATOMIC, requests, controls);
r = new MultiUpdateExtendedRequest(r);
r = r.duplicate();
assertNotNull(r.getErrorBehavior());
assertEquals(r.getErrorBehavior(), MultiUpdateErrorBehavior.ATOMIC);
assertNotNull(r.getRequests());
assertEquals(r.getRequests().size(), 5);
assertEquals(r.getRequests().get(0).getOperationType(), OperationType.ADD);
assertNotNull(r.getRequests().get(0).getControls());
assertEquals(r.getRequests().get(0).getControls().length, 0);
assertEquals(r.getRequests().get(1).getOperationType(), OperationType.MODIFY);
assertNotNull(r.getRequests().get(1).getControls());
assertEquals(r.getRequests().get(1).getControls().length, 0);
assertEquals(r.getRequests().get(2).getOperationType(), OperationType.MODIFY_DN);
assertNotNull(r.getRequests().get(2).getControls());
assertEquals(r.getRequests().get(2).getControls().length, 1);
assertEquals(r.getRequests().get(3).getOperationType(), OperationType.EXTENDED);
assertNotNull(r.getRequests().get(3).getControls());
assertEquals(r.getRequests().get(3).getControls().length, 0);
assertEquals(r.getRequests().get(4).getOperationType(), OperationType.DELETE);
assertNotNull(r.getRequests().get(4).getControls());
assertEquals(r.getRequests().get(4).getControls().length, 0);
assertNotNull(r.getControls());
assertEquals(r.getControls().length, 2);
assertNotNull(r.getExtendedRequestName());
assertNotNull(r.toString());
}
Aggregations