use of com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl in project ldapsdk by pingidentity.
the class StartTransactionExtendedRequestTestCase method testCommitTransaction.
/**
* Tests the process of creating a transaction, including multiple operations
* as part of that transaction, and then committing it.
* <BR><BR>
* Access to a Directory Server instance is required for complete processing.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testCommitTransaction() throws Exception {
if (!isDirectoryInstanceAvailable()) {
return;
}
LDAPConnection conn = getAdminConnection();
RootDSE rootDSE = conn.getRootDSE();
if ((rootDSE == null) || (!rootDSE.supportsExtendedOperation(StartTransactionExtendedRequest.START_TRANSACTION_REQUEST_OID))) {
conn.close();
return;
}
StartTransactionExtendedResult startTxnResult = (StartTransactionExtendedResult) conn.processExtendedOperation(new StartTransactionExtendedRequest());
assertEquals(startTxnResult.getResultCode(), ResultCode.SUCCESS);
ASN1OctetString txnID = startTxnResult.getTransactionID();
assertNotNull(txnID);
assertNotNull(startTxnResult.toString());
Control[] controls = { new TransactionSpecificationRequestControl(txnID), new PostReadRequestControl(true) };
AddRequest addRequest = new AddRequest(getTestBaseDN(), getBaseEntryAttributes(), controls);
conn.add(addRequest);
Modification[] mods = { new Modification(ModificationType.REPLACE, "description", "foo") };
ModifyRequest modifyRequest = new ModifyRequest(getTestBaseDN(), mods, controls);
conn.modify(modifyRequest);
EndTransactionExtendedResult endTxnResult = (EndTransactionExtendedResult) conn.processExtendedOperation(new EndTransactionExtendedRequest(txnID, true));
assertEquals(endTxnResult.getResultCode(), ResultCode.SUCCESS);
assertNotNull(endTxnResult.getOperationResponseControls());
assertFalse(endTxnResult.getOperationResponseControls().isEmpty());
assertNotNull(endTxnResult.toString());
conn.delete(getTestBaseDN());
conn.close();
}
use of com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl in project ldapsdk by pingidentity.
the class TransactionExtendedOperationHandlerTestCase method testTransactionControlWithoutTransaction.
/**
* Tests the behavior when trying to use the transaction specification request
* control when no transaction has been started.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testTransactionControlWithoutTransaction() 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);
final TransactionSpecificationRequestControl txnControl = new TransactionSpecificationRequestControl(new ASN1OctetString("nonexistent"));
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.UNAVAILABLE_CRITICAL_EXTENSION);
final DeleteRequest deleteRequest = new DeleteRequest("dc=example,dc=com");
deleteRequest.setControls(txnControl);
assertResultCodeEquals(conn, deleteRequest, ResultCode.UNAVAILABLE_CRITICAL_EXTENSION);
final ModifyRequest modifyRequest = new ModifyRequest("dn: dc=example,dc=com", "changeType: modify", "replace: description", "description: foo");
modifyRequest.setControls(txnControl);
assertResultCodeEquals(conn, modifyRequest, ResultCode.UNAVAILABLE_CRITICAL_EXTENSION);
final ModifyDNRequest modifyDNRequest = new ModifyDNRequest("ou=People,dc=example,dc=com", "ou=Users", true);
modifyDNRequest.setControls(txnControl);
assertResultCodeEquals(conn, modifyDNRequest, ResultCode.UNAVAILABLE_CRITICAL_EXTENSION);
conn.close();
assertEquals(unsolicitedNotificationHandler.getNotificationCount(), 0);
}
use of com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl 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.controls.TransactionSpecificationRequestControl 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.controls.TransactionSpecificationRequestControl in project ldapsdk by pingidentity.
the class StartTransactionExtendedRequestTestCase method testAbortTransaction.
/**
* Tests the process of creating a transaction, including multiple operations
* as part of that transaction, and then aborting it.
* <BR><BR>
* Access to a Directory Server instance is required for complete processing.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testAbortTransaction() throws Exception {
if (!isDirectoryInstanceAvailable()) {
return;
}
LDAPConnection conn = getAdminConnection();
RootDSE rootDSE = conn.getRootDSE();
if ((rootDSE == null) || (!rootDSE.supportsExtendedOperation(StartTransactionExtendedRequest.START_TRANSACTION_REQUEST_OID))) {
conn.close();
return;
}
StartTransactionExtendedResult startTxnResult = (StartTransactionExtendedResult) conn.processExtendedOperation(new StartTransactionExtendedRequest());
assertEquals(startTxnResult.getResultCode(), ResultCode.SUCCESS);
ASN1OctetString txnID = startTxnResult.getTransactionID();
assertNotNull(txnID);
assertNotNull(startTxnResult.toString());
Control[] controls = { new TransactionSpecificationRequestControl(txnID) };
AddRequest addRequest = new AddRequest(getTestBaseDN(), getBaseEntryAttributes(), controls);
conn.add(addRequest);
Modification[] mods = { new Modification(ModificationType.REPLACE, "description", "foo") };
ModifyRequest modifyRequest = new ModifyRequest(getTestBaseDN(), mods, controls);
conn.modify(modifyRequest);
ExtendedResult endTxnResult = conn.processExtendedOperation(new EndTransactionExtendedRequest(txnID, false));
assertEquals(endTxnResult.getResultCode(), ResultCode.SUCCESS);
assertNotNull(endTxnResult.toString());
try {
assertNull(conn.getEntry(getTestBaseDN()));
} finally {
conn.close();
}
}
Aggregations