Search in sources :

Example 6 with EndTransactionExtendedResult

use of com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult in project ldapsdk by pingidentity.

the class TransactionExtendedOperationHandlerTestCase method testSuccessfulTransaction.

/**
 * Provides a test case for a completely successful transaction.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSuccessfulTransaction() 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=People,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.SUCCESS);
    assertTrue(endTxnResult.getFailedOpMessageID() < 0);
    assertNotNull(endTxnResult.getOperationResponseControls());
    assertTrue(endTxnResult.getOperationResponseControls().isEmpty());
    ds.assertEntryExists("dc=example,dc=com");
    ds.assertEntryExists("ou=test,dc=example,dc=com");
    ds.assertEntryExists("uid=test.user,ou=test,dc=example,dc=com");
    ds.assertEntryMissing("ou=People,dc=example,dc=com");
    ds.assertEntryMissing("uid=test.user,ou=People,dc=example,dc=com");
    conn.close();
    assertEquals(unsolicitedNotificationHandler.getNotificationCount(), 0);
}
Also used : LDAPConnectionOptions(com.unboundid.ldap.sdk.LDAPConnectionOptions) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) EndTransactionExtendedRequest(com.unboundid.ldap.sdk.extensions.EndTransactionExtendedRequest) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) AddRequest(com.unboundid.ldap.sdk.AddRequest) ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) StartTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedResult) StartTransactionExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedRequest) DeleteRequest(com.unboundid.ldap.sdk.DeleteRequest) EndTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult) TestUnsolicitedNotificationHandler(com.unboundid.ldap.sdk.TestUnsolicitedNotificationHandler) TransactionSpecificationRequestControl(com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl) Test(org.testng.annotations.Test)

Example 7 with EndTransactionExtendedResult

use of com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult in project ldapsdk by pingidentity.

the class TransactionExtendedOperationHandlerTestCase method testFailedDeleteInTransaction.

/**
 * Provides a test case for a transaction in which a delete operation fails
 * after other operations that should have succeeded.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testFailedDeleteInTransaction() 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 DeleteRequest deleteRequest = new DeleteRequest("ou=People,dc=example,dc=com");
    deleteRequest.setControls(txnControl);
    assertResultCodeEquals(conn, deleteRequest, ResultCode.SUCCESS);
    final EndTransactionExtendedResult endTxnResult = (EndTransactionExtendedResult) conn.processExtendedOperation(new EndTransactionExtendedRequest(txnID, true));
    assertResultCodeEquals(endTxnResult, ResultCode.NOT_ALLOWED_ON_NONLEAF);
    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);
}
Also used : LDAPConnectionOptions(com.unboundid.ldap.sdk.LDAPConnectionOptions) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) AddRequest(com.unboundid.ldap.sdk.AddRequest) StartTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedResult) StartTransactionExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedRequest) EndTransactionExtendedRequest(com.unboundid.ldap.sdk.extensions.EndTransactionExtendedRequest) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) DeleteRequest(com.unboundid.ldap.sdk.DeleteRequest) EndTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult) TestUnsolicitedNotificationHandler(com.unboundid.ldap.sdk.TestUnsolicitedNotificationHandler) TransactionSpecificationRequestControl(com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl) Test(org.testng.annotations.Test)

Example 8 with EndTransactionExtendedResult

use of com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult in project ldapsdk by pingidentity.

the class TransactionExtendedOperationHandlerTestCase method testEndTransactionWithMismatchedTransactionID.

/**
 * Tests the behavior when trying to use the end transaction extended request
 * with a transaction ID that differs from the ID of the associated
 * transaction.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testEndTransactionWithMismatchedTransactionID() 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 StartTransactionExtendedResult startTxnResult = (StartTransactionExtendedResult) conn.processExtendedOperation(new StartTransactionExtendedRequest());
    assertResultCodeEquals(startTxnResult, ResultCode.SUCCESS);
    final ASN1OctetString txnID = startTxnResult.getTransactionID();
    assertNotNull(txnID);
    final ASN1OctetString wrongTxnID = new ASN1OctetString(txnID.stringValue() + "-wrong");
    final EndTransactionExtendedResult endTxnResult = (EndTransactionExtendedResult) conn.processExtendedOperation(new EndTransactionExtendedRequest(wrongTxnID, true));
    assertResultCodeEquals(endTxnResult, ResultCode.CONSTRAINT_VIOLATION);
    conn.close();
    assertEquals(unsolicitedNotificationHandler.getNotificationCount(), 1);
}
Also used : LDAPConnectionOptions(com.unboundid.ldap.sdk.LDAPConnectionOptions) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) StartTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedResult) StartTransactionExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedRequest) EndTransactionExtendedRequest(com.unboundid.ldap.sdk.extensions.EndTransactionExtendedRequest) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) EndTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult) TestUnsolicitedNotificationHandler(com.unboundid.ldap.sdk.TestUnsolicitedNotificationHandler) Test(org.testng.annotations.Test)

Example 9 with EndTransactionExtendedResult

use of com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult in project ldapsdk by pingidentity.

the class TransactionExtendedOperationHandlerTestCase method testMalformedEndTransactionRequest.

/**
 * Tests the behavior when provided with a malformed end transaction request.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testMalformedEndTransactionRequest() 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 StartTransactionExtendedResult startTxnResult = (StartTransactionExtendedResult) conn.processExtendedOperation(new StartTransactionExtendedRequest());
    assertResultCodeEquals(startTxnResult, ResultCode.SUCCESS);
    final ASN1OctetString txnID = startTxnResult.getTransactionID();
    assertNotNull(txnID);
    try {
        final EndTransactionExtendedResult endTxnResult = (EndTransactionExtendedResult) conn.processExtendedOperation(EndTransactionExtendedRequest.END_TRANSACTION_REQUEST_OID);
        assertResultCodeEquals(endTxnResult, ResultCode.PROTOCOL_ERROR);
    } catch (final LDAPException le) {
        assertResultCodeEquals(le, ResultCode.PROTOCOL_ERROR);
    }
    conn.close();
    assertEquals(unsolicitedNotificationHandler.getNotificationCount(), 1);
}
Also used : LDAPConnectionOptions(com.unboundid.ldap.sdk.LDAPConnectionOptions) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) LDAPException(com.unboundid.ldap.sdk.LDAPException) StartTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedResult) StartTransactionExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedRequest) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) EndTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult) TestUnsolicitedNotificationHandler(com.unboundid.ldap.sdk.TestUnsolicitedNotificationHandler) Test(org.testng.annotations.Test)

Example 10 with EndTransactionExtendedResult

use of com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult in project ldapsdk by pingidentity.

the class TransactionExtendedOperationHandlerTestCase method testStartTransactionWithAnotherActive.

/**
 * Tests the behavior when trying to start a transaction when another
 * transaction is already in progress on the connection.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testStartTransactionWithAnotherActive() 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 StartTransactionExtendedResult startTxn1Result = (StartTransactionExtendedResult) conn.processExtendedOperation(new StartTransactionExtendedRequest());
    assertResultCodeEquals(startTxn1Result, ResultCode.SUCCESS);
    final ASN1OctetString txnID1 = startTxn1Result.getTransactionID();
    assertNotNull(txnID1);
    final StartTransactionExtendedResult startTxn2Result = (StartTransactionExtendedResult) conn.processExtendedOperation(new StartTransactionExtendedRequest());
    assertResultCodeEquals(startTxn2Result, ResultCode.SUCCESS);
    final ASN1OctetString txnID2 = startTxn2Result.getTransactionID();
    assertNotNull(txnID2);
    assertEquals(unsolicitedNotificationHandler.getNotificationCount(), 1);
    final EndTransactionExtendedResult endTxn2Result = (EndTransactionExtendedResult) conn.processExtendedOperation(new EndTransactionExtendedRequest(txnID2, true));
    assertResultCodeEquals(endTxn2Result, ResultCode.SUCCESS);
    final EndTransactionExtendedResult endTxn1Result = (EndTransactionExtendedResult) conn.processExtendedOperation(new EndTransactionExtendedRequest(txnID1, true));
    assertResultCodeEquals(endTxn1Result, ResultCode.CONSTRAINT_VIOLATION);
    conn.close();
    assertEquals(unsolicitedNotificationHandler.getNotificationCount(), 1);
}
Also used : LDAPConnectionOptions(com.unboundid.ldap.sdk.LDAPConnectionOptions) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) StartTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedResult) StartTransactionExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedRequest) EndTransactionExtendedRequest(com.unboundid.ldap.sdk.extensions.EndTransactionExtendedRequest) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) EndTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult) TestUnsolicitedNotificationHandler(com.unboundid.ldap.sdk.TestUnsolicitedNotificationHandler) Test(org.testng.annotations.Test)

Aggregations

ASN1OctetString (com.unboundid.asn1.ASN1OctetString)15 EndTransactionExtendedResult (com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult)15 StartTransactionExtendedResult (com.unboundid.ldap.sdk.extensions.StartTransactionExtendedResult)14 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)12 LDAPConnectionOptions (com.unboundid.ldap.sdk.LDAPConnectionOptions)12 TestUnsolicitedNotificationHandler (com.unboundid.ldap.sdk.TestUnsolicitedNotificationHandler)12 EndTransactionExtendedRequest (com.unboundid.ldap.sdk.extensions.EndTransactionExtendedRequest)12 StartTransactionExtendedRequest (com.unboundid.ldap.sdk.extensions.StartTransactionExtendedRequest)12 Test (org.testng.annotations.Test)12 TransactionSpecificationRequestControl (com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl)9 AddRequest (com.unboundid.ldap.sdk.AddRequest)8 ModifyDNRequest (com.unboundid.ldap.sdk.ModifyDNRequest)5 Control (com.unboundid.ldap.sdk.Control)4 DeleteRequest (com.unboundid.ldap.sdk.DeleteRequest)4 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)4 PostReadResponseControl (com.unboundid.ldap.sdk.controls.PostReadResponseControl)4 PreReadResponseControl (com.unboundid.ldap.sdk.controls.PreReadResponseControl)4 AbortedTransactionExtendedResult (com.unboundid.ldap.sdk.extensions.AbortedTransactionExtendedResult)3 ObjectPair (com.unboundid.util.ObjectPair)3 ArrayList (java.util.ArrayList)3