Search in sources :

Example 1 with TestInputStream

use of com.unboundid.util.TestInputStream in project ldapsdk by pingidentity.

the class LDAPListenerClientConnectionTestCase method testThrowOnGetInputStream.

/**
 * Tests the behavior when a client connection has been created without a
 * listener and with a socket that throws an exception when trying to get the
 * input stream.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testThrowOnGetInputStream() throws Exception {
    final TestSocket s = new TestSocket(new TestInputStream(new ByteArrayInputStream(new byte[1024]), new IOException("foo"), 100, true), new TestOutputStream(new ByteArrayOutputStream(), new IOException("bar"), 1024, true));
    s.setThrowOnGetInputStream(true);
    s.setThrowOnClose(true);
    new LDAPListenerClientConnection(null, s, new CannedResponseRequestHandler(), null);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) TestOutputStream(com.unboundid.util.TestOutputStream) TestSocket(com.unboundid.util.TestSocket) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TestInputStream(com.unboundid.util.TestInputStream) Test(org.testng.annotations.Test)

Example 2 with TestInputStream

use of com.unboundid.util.TestInputStream in project ldapsdk by pingidentity.

the class LDAPListenerClientConnectionTestCase method testThrowOnClose.

/**
 * Tests the behavior when a client connection has been created without a
 * listener and with elements that throw exceptions on closure.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testThrowOnClose() throws Exception {
    final TestSocket s = new TestSocket(new TestInputStream(new ByteArrayInputStream(new byte[1024]), new IOException("foo"), 100, true), new TestOutputStream(new ByteArrayOutputStream(), new IOException("bar"), 1024, true));
    s.setThrowOnClose(true);
    final LDAPListenerClientConnection conn = new LDAPListenerClientConnection(null, s, new CannedResponseRequestHandler(), new TestLDAPListenerExceptionHandler());
    conn.removeSearchEntryTransformer(null);
    conn.removeSearchReferenceTransformer(null);
    conn.removeIntermediateResponseTransformer(null);
    conn.close(new LDAPException(ResultCode.LOCAL_ERROR, "foo"));
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) ByteArrayInputStream(java.io.ByteArrayInputStream) TestOutputStream(com.unboundid.util.TestOutputStream) TestSocket(com.unboundid.util.TestSocket) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TestInputStream(com.unboundid.util.TestInputStream) Test(org.testng.annotations.Test)

Example 3 with TestInputStream

use of com.unboundid.util.TestInputStream in project ldapsdk by pingidentity.

the class LDAPMessageTestCase method testReadFromIOExceptionAfterFirst.

/**
 * Tests the {@code LDAPMessage.readFrom} method with an input stream that
 * throws an exception after the first byte has been read.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testReadFromIOExceptionAfterFirst() throws Exception {
    ByteArrayInputStream baos = new ByteArrayInputStream(new byte[10]);
    TestInputStream is = new TestInputStream(baos, new IOException(), 1, false);
    LDAPMessage.readFrom(new ASN1StreamReader(is), false);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) TestInputStream(com.unboundid.util.TestInputStream) Test(org.testng.annotations.Test)

Example 4 with TestInputStream

use of com.unboundid.util.TestInputStream in project ldapsdk by pingidentity.

the class LDIFEntrySourceTestCase method testReaderThrowsIOException.

/**
 * Tests with an LDIF reader that will always throw an I/O exception.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { EntrySourceException.class })
public void testReaderThrowsIOException() throws Exception {
    InputStream is = new TestInputStream(new FileInputStream(ldifFile), new IOException(), 0, true);
    LDIFEntrySource s = new LDIFEntrySource(new LDIFReader(is));
    try {
        s.nextEntry();
    } finally {
        s.close();
    }
}
Also used : TestInputStream(com.unboundid.util.TestInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) TestInputStream(com.unboundid.util.TestInputStream) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 5 with TestInputStream

use of com.unboundid.util.TestInputStream in project ldapsdk by pingidentity.

the class LDAPListenerClientConnectionTestCase method testThrowOnNewRequestHandlerInstance.

/**
 * Tests the behavior when a client connection has been created without a
 * listener and with a request handler that throws an exception when trying to
 * create a new instance.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testThrowOnNewRequestHandlerInstance() throws Exception {
    final TestSocket s = new TestSocket(new TestInputStream(new ByteArrayInputStream(new byte[1024]), new IOException("foo"), 100, true), new TestOutputStream(new ByteArrayOutputStream(), new IOException("bar"), 1024, true));
    s.setThrowOnClose(true);
    TestRequestHandler.setThrowOnNewInstance(true);
    try {
        new LDAPListenerClientConnection(null, s, new TestRequestHandler(), null);
    } finally {
        TestRequestHandler.setThrowOnNewInstance(false);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) TestOutputStream(com.unboundid.util.TestOutputStream) TestSocket(com.unboundid.util.TestSocket) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TestInputStream(com.unboundid.util.TestInputStream) Test(org.testng.annotations.Test)

Aggregations

TestInputStream (com.unboundid.util.TestInputStream)6 IOException (java.io.IOException)6 Test (org.testng.annotations.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 TestOutputStream (com.unboundid.util.TestOutputStream)4 TestSocket (com.unboundid.util.TestSocket)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 ASN1StreamReader (com.unboundid.asn1.ASN1StreamReader)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1