use of com.unboundid.ldap.sdk.TestUnsolicitedNotificationHandler in project ldapsdk by pingidentity.
the class InMemoryOperationInterceptorTestCase method testUnsolicitedResponse.
/**
* Tests to ensure that unsolicited responses are handled properly.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testUnsolicitedResponse() throws Exception {
final LDAPConnection conn = ds.getConnection();
final TestUnsolicitedNotificationHandler testNotificationHandler = new TestUnsolicitedNotificationHandler();
final LDAPConnectionOptions options = conn.getConnectionOptions();
options.setUnsolicitedNotificationHandler(testNotificationHandler);
conn.setConnectionOptions(options);
WhoAmIExtendedRequest whoAmIRequest = new WhoAmIExtendedRequest(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.INJECT_UNSOLICITED_NOTIFICATION));
assertResultCodeEquals(conn, whoAmIRequest, ResultCode.SUCCESS);
assertEquals(testNotificationHandler.getNotificationCount(), 2);
conn.close();
}
use of com.unboundid.ldap.sdk.TestUnsolicitedNotificationHandler 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.TestUnsolicitedNotificationHandler 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);
}
use of com.unboundid.ldap.sdk.TestUnsolicitedNotificationHandler 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);
}
use of com.unboundid.ldap.sdk.TestUnsolicitedNotificationHandler 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);
}
Aggregations