Search in sources :

Example 1 with TestIntermediateResponseListener

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

the class InMemoryOperationInterceptorTestCase method testExtendedWithTransformations.

/**
 * Tests to ensure that processing works correctly for extended operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExtendedWithTransformations() throws Exception {
    final LDAPConnection conn = ds.getConnection();
    WhoAmIExtendedRequest whoAmIRequest = new WhoAmIExtendedRequest();
    assertResultCodeEquals(conn, whoAmIRequest, ResultCode.SUCCESS);
    whoAmIRequest = new WhoAmIExtendedRequest(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.ALTER_DN));
    assertResultCodeEquals(conn, whoAmIRequest, ResultCode.SUCCESS);
    whoAmIRequest = new WhoAmIExtendedRequest(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.REJECT_REQUEST));
    assertResultCodeEquals(conn, whoAmIRequest, ResultCode.UNWILLING_TO_PERFORM);
    whoAmIRequest = new WhoAmIExtendedRequest(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.REQUEST_RUNTIME_EXCEPTION));
    assertResultCodeEquals(conn, whoAmIRequest, ResultCode.OTHER);
    whoAmIRequest = new WhoAmIExtendedRequest(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.ERROR_RESULT));
    assertResultCodeEquals(conn, whoAmIRequest, ResultCode.UNWILLING_TO_PERFORM);
    whoAmIRequest = new WhoAmIExtendedRequest(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.RESULT_RUNTIME_EXCEPTION));
    assertResultCodeEquals(conn, whoAmIRequest, ResultCode.OTHER);
    whoAmIRequest = new WhoAmIExtendedRequest(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.INJECT_INTERMEDIATE_RESPONSE));
    final TestIntermediateResponseListener testIRListener = new TestIntermediateResponseListener();
    whoAmIRequest.setIntermediateResponseListener(testIRListener);
    assertResultCodeEquals(conn, whoAmIRequest, ResultCode.SUCCESS);
    assertEquals(testIRListener.getCount(), 2);
    conn.close();
}
Also used : WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) TestIntermediateResponseListener(com.unboundid.ldap.sdk.TestIntermediateResponseListener) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) Test(org.testng.annotations.Test)

Example 2 with TestIntermediateResponseListener

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

the class InMemoryOperationInterceptorTestCase method testCompareWithTransformations.

/**
 * Tests to ensure that processing works correctly for compare operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testCompareWithTransformations() throws Exception {
    final LDAPConnection conn = ds.getConnection();
    CompareRequest compareRequest = new CompareRequest("dc=example,dc=com", "dc", "example");
    assertResultCodeEquals(conn, compareRequest, ResultCode.COMPARE_TRUE);
    compareRequest = new CompareRequest("dc=example,dc=com", "dc", "example");
    compareRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.ALTER_DN));
    assertResultCodeEquals(conn, compareRequest, ResultCode.NO_SUCH_OBJECT);
    compareRequest = new CompareRequest("dc=example,dc=com", "dc", "example");
    compareRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.REJECT_REQUEST));
    assertResultCodeEquals(conn, compareRequest, ResultCode.UNWILLING_TO_PERFORM);
    compareRequest = new CompareRequest("dc=example,dc=com", "dc", "example");
    compareRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.REQUEST_RUNTIME_EXCEPTION));
    assertResultCodeEquals(conn, compareRequest, ResultCode.OTHER);
    compareRequest = new CompareRequest("dc=example,dc=com", "dc", "example");
    compareRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.ERROR_RESULT));
    assertResultCodeEquals(conn, compareRequest, ResultCode.UNWILLING_TO_PERFORM);
    compareRequest = new CompareRequest("dc=example,dc=com", "dc", "example");
    compareRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.RESULT_RUNTIME_EXCEPTION));
    assertResultCodeEquals(conn, compareRequest, ResultCode.OTHER);
    compareRequest = new CompareRequest("dc=example,dc=com", "dc", "example");
    compareRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.INJECT_INTERMEDIATE_RESPONSE));
    final TestIntermediateResponseListener testIRListener = new TestIntermediateResponseListener();
    compareRequest.setIntermediateResponseListener(testIRListener);
    assertResultCodeEquals(conn, compareRequest, ResultCode.COMPARE_TRUE);
    assertEquals(testIRListener.getCount(), 2);
    conn.close();
}
Also used : CompareRequest(com.unboundid.ldap.sdk.CompareRequest) TestIntermediateResponseListener(com.unboundid.ldap.sdk.TestIntermediateResponseListener) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) Test(org.testng.annotations.Test)

Example 3 with TestIntermediateResponseListener

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

the class InMemoryOperationInterceptorTestCase method testModifyWithTransformations.

/**
 * Tests to ensure that processing works correctly for modify operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testModifyWithTransformations() throws Exception {
    final LDAPConnection conn = ds.getConnection();
    ModifyRequest modifyRequest = new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: test1");
    assertResultCodeEquals(conn, modifyRequest, ResultCode.SUCCESS);
    assertValueExists(conn, "dc=example,dc=com", "description", "test1");
    modifyRequest = new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: test2");
    modifyRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.ALTER_DN));
    assertResultCodeEquals(conn, modifyRequest, ResultCode.NO_SUCH_OBJECT);
    assertValueExists(conn, "dc=example,dc=com", "description", "test1");
    modifyRequest = new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: test2");
    modifyRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.REJECT_REQUEST));
    assertResultCodeEquals(conn, modifyRequest, ResultCode.UNWILLING_TO_PERFORM);
    assertValueExists(conn, "dc=example,dc=com", "description", "test1");
    modifyRequest = new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: test2");
    modifyRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.REQUEST_RUNTIME_EXCEPTION));
    assertResultCodeEquals(conn, modifyRequest, ResultCode.OTHER);
    assertValueExists(conn, "dc=example,dc=com", "description", "test1");
    modifyRequest = new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: test2");
    modifyRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.ERROR_RESULT));
    assertResultCodeEquals(conn, modifyRequest, ResultCode.UNWILLING_TO_PERFORM);
    assertValueExists(conn, "dc=example,dc=com", "description", "test2");
    modifyRequest = new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: test3");
    modifyRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.RESULT_RUNTIME_EXCEPTION));
    assertResultCodeEquals(conn, modifyRequest, ResultCode.OTHER);
    assertValueExists(conn, "dc=example,dc=com", "description", "test3");
    modifyRequest = new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: test4");
    modifyRequest.setControls(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.INJECT_INTERMEDIATE_RESPONSE));
    final TestIntermediateResponseListener testIRListener = new TestIntermediateResponseListener();
    modifyRequest.setIntermediateResponseListener(testIRListener);
    assertResultCodeEquals(conn, modifyRequest, ResultCode.SUCCESS);
    assertValueExists(conn, "dc=example,dc=com", "description", "test4");
    modifyRequest = new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description");
    assertResultCodeEquals(conn, modifyRequest, ResultCode.SUCCESS);
    assertAttributeMissing(conn, "dc=example,dc=com", "description");
    conn.close();
}
Also used : TestIntermediateResponseListener(com.unboundid.ldap.sdk.TestIntermediateResponseListener) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) Test(org.testng.annotations.Test)

Example 4 with TestIntermediateResponseListener

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

the class InMemoryOperationInterceptorTestCase method testIntermediateResponseWithTransformations.

/**
 * Tests to ensure that processing works correctly for intermediate responses.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testIntermediateResponseWithTransformations() throws Exception {
    final LDAPConnection conn = ds.getConnection();
    WhoAmIExtendedRequest whoAmIRequest = new WhoAmIExtendedRequest(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.INJECT_INTERMEDIATE_RESPONSE));
    TestIntermediateResponseListener testIRListener = new TestIntermediateResponseListener();
    whoAmIRequest.setIntermediateResponseListener(testIRListener);
    assertResultCodeEquals(conn, whoAmIRequest, ResultCode.SUCCESS);
    assertEquals(testIRListener.getCount(), 2);
    whoAmIRequest = new WhoAmIExtendedRequest(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.INJECT_INTERMEDIATE_RESPONSE, ControlBasedOperationInterceptor.TransformType.SUPPRESS_INTERMEDIATE_RESPONSE));
    testIRListener = new TestIntermediateResponseListener();
    whoAmIRequest.setIntermediateResponseListener(testIRListener);
    assertResultCodeEquals(conn, whoAmIRequest, ResultCode.SUCCESS);
    assertEquals(testIRListener.getCount(), 0);
    whoAmIRequest = new WhoAmIExtendedRequest(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.INJECT_INTERMEDIATE_RESPONSE, ControlBasedOperationInterceptor.TransformType.ALTER_INTERMEDIATE_RESPONSE));
    testIRListener = new TestIntermediateResponseListener();
    whoAmIRequest.setIntermediateResponseListener(testIRListener);
    assertResultCodeEquals(conn, whoAmIRequest, ResultCode.SUCCESS);
    assertEquals(testIRListener.getCount(), 2);
    whoAmIRequest = new WhoAmIExtendedRequest(ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.INJECT_INTERMEDIATE_RESPONSE, ControlBasedOperationInterceptor.TransformType.INTERMEDIATE_RESPONSE_RUNTIME_EXCEPTION));
    testIRListener = new TestIntermediateResponseListener();
    whoAmIRequest.setIntermediateResponseListener(testIRListener);
    assertResultCodeEquals(conn, whoAmIRequest, ResultCode.SUCCESS);
    assertEquals(testIRListener.getCount(), 0);
    conn.close();
}
Also used : WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) TestIntermediateResponseListener(com.unboundid.ldap.sdk.TestIntermediateResponseListener) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) Test(org.testng.annotations.Test)

Example 5 with TestIntermediateResponseListener

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

the class InMemoryOperationInterceptorTestCase method testSASLBindWithTransformations.

/**
 * Tests to ensure that processing works correctly for SASL bind operations.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSASLBindWithTransformations() throws Exception {
    final LDAPConnection conn = ds.getConnection();
    PLAINBindRequest bindRequest = new PLAINBindRequest("dn:cn=Directory Manager", "password");
    assertResultCodeEquals(conn, bindRequest, ResultCode.SUCCESS);
    bindRequest = new PLAINBindRequest("dn:cn=Directory Manager", "password", ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.ALTER_DN));
    assertResultCodeEquals(conn, bindRequest, ResultCode.SUCCESS);
    bindRequest = new PLAINBindRequest("dn:cn=Directory Manager", "password", ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.REJECT_REQUEST));
    assertResultCodeEquals(conn, bindRequest, ResultCode.UNWILLING_TO_PERFORM);
    bindRequest = new PLAINBindRequest("dn:cn=Directory Manager", "password", ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.REQUEST_RUNTIME_EXCEPTION));
    assertResultCodeEquals(conn, bindRequest, ResultCode.OTHER);
    bindRequest = new PLAINBindRequest("dn:cn=Directory Manager", "password", ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.ERROR_RESULT));
    assertResultCodeEquals(conn, bindRequest, ResultCode.UNWILLING_TO_PERFORM);
    bindRequest = new PLAINBindRequest("dn:cn=Directory Manager", "password", ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.RESULT_RUNTIME_EXCEPTION));
    assertResultCodeEquals(conn, bindRequest, ResultCode.OTHER);
    bindRequest = new PLAINBindRequest("dn:cn=Directory Manager", "password", ControlBasedOperationInterceptor.createControls(ControlBasedOperationInterceptor.TransformType.INJECT_INTERMEDIATE_RESPONSE));
    final TestIntermediateResponseListener testIRListener = new TestIntermediateResponseListener();
    bindRequest.setIntermediateResponseListener(testIRListener);
    assertResultCodeEquals(conn, bindRequest, ResultCode.SUCCESS);
    assertEquals(testIRListener.getCount(), 2);
    conn.close();
}
Also used : PLAINBindRequest(com.unboundid.ldap.sdk.PLAINBindRequest) TestIntermediateResponseListener(com.unboundid.ldap.sdk.TestIntermediateResponseListener) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) Test(org.testng.annotations.Test)

Aggregations

LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)11 TestIntermediateResponseListener (com.unboundid.ldap.sdk.TestIntermediateResponseListener)11 Test (org.testng.annotations.Test)11 WhoAmIExtendedRequest (com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest)2 AddRequest (com.unboundid.ldap.sdk.AddRequest)1 CompareRequest (com.unboundid.ldap.sdk.CompareRequest)1 DeleteRequest (com.unboundid.ldap.sdk.DeleteRequest)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 ModifyDNRequest (com.unboundid.ldap.sdk.ModifyDNRequest)1 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)1 PLAINBindRequest (com.unboundid.ldap.sdk.PLAINBindRequest)1 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)1 SearchResult (com.unboundid.ldap.sdk.SearchResult)1 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)1