use of com.unboundid.ldap.sdk.unboundidds.extensions.CollectSupportDataArchiveFragmentIntermediateResponse in project ldapsdk by pingidentity.
the class CollectSupportDataIRListenerTestCase method testThrowOnWrite.
/**
* Tests the behavior for the case in which an attempt to write an archive
* fragment throws an exception.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testThrowOnWrite() throws Exception {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ByteArrayOutputStream err = new ByteArrayOutputStream();
final CollectSupportData tool = new CollectSupportData(out, err);
final File outputFile = createTempFile();
assertTrue(outputFile.delete());
final CollectSupportDataIRListener listener = new CollectSupportDataIRListener(tool, outputFile);
listener.handleArchiveFragmentIntermediateResponse(new CollectSupportDataArchiveFragmentIntermediateResponse("csd.zip", 10L, true, StaticUtils.getBytes("Hello")));
assertTrue(out.size() > 0);
assertEquals(err.size(), 0);
assertTrue(outputFile.exists());
assertEquals(outputFile.length(), 5L);
assertNotNull(listener.getOutputStreamReference().get());
assertNull(listener.getFirstIOExceptionReference().get());
out.reset();
final OutputStream streamToWrap = listener.getOutputStreamReference().get();
listener.getOutputStreamReference().set(new TestOutputStream(streamToWrap, new IOException("write error"), 0, false));
listener.handleArchiveFragmentIntermediateResponse(new CollectSupportDataArchiveFragmentIntermediateResponse("csd.zip", 10L, false, StaticUtils.getBytes("There")));
assertEquals(out.size(), 0);
assertTrue(err.size() > 0);
assertTrue(outputFile.exists());
assertEquals(outputFile.length(), 5L);
assertNotNull(listener.getOutputStreamReference().get());
assertNotNull(listener.getFirstIOExceptionReference().get());
out.reset();
err.reset();
listener.handleArchiveFragmentIntermediateResponse(new CollectSupportDataArchiveFragmentIntermediateResponse("csd.zip", 10L, false, StaticUtils.getBytes("There")));
assertEquals(out.size(), 0);
assertEquals(err.size(), 0);
assertTrue(outputFile.exists());
assertEquals(outputFile.length(), 5L);
assertNotNull(listener.getOutputStreamReference().get());
assertNotNull(listener.getFirstIOExceptionReference().get());
out.reset();
err.reset();
try {
listener.close();
fail("Expected an exception when trying to close the output stream");
} catch (final IOException e) {
// This was expected.
}
assertEquals(out.size(), 0);
assertEquals(err.size(), 0);
assertTrue(outputFile.exists());
assertEquals(outputFile.length(), 5L);
assertEquals(readFileBytes(outputFile), StaticUtils.getBytes("Hello"));
assertNull(listener.getOutputStreamReference().get());
assertNotNull(listener.getFirstIOExceptionReference().get());
}
use of com.unboundid.ldap.sdk.unboundidds.extensions.CollectSupportDataArchiveFragmentIntermediateResponse in project ldapsdk by pingidentity.
the class CollectSupportDataIRListenerTestCase method testArchiveFragments.
/**
* Tests the behavior for archive fragments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testArchiveFragments() throws Exception {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ByteArrayOutputStream err = new ByteArrayOutputStream();
final CollectSupportData tool = new CollectSupportData(out, err);
final File outputFile = createTempFile();
assertTrue(outputFile.delete());
final CollectSupportDataIRListener listener = new CollectSupportDataIRListener(tool, outputFile);
listener.handleArchiveFragmentIntermediateResponse(new CollectSupportDataArchiveFragmentIntermediateResponse("csd.zip", 10L, true, StaticUtils.getBytes("Hello")));
assertTrue(out.size() > 0);
assertEquals(err.size(), 0);
assertTrue(outputFile.exists());
assertEquals(outputFile.length(), 5L);
assertNotNull(listener.getOutputStreamReference().get());
assertNull(listener.getFirstIOExceptionReference().get());
out.reset();
listener.handleArchiveFragmentIntermediateResponse(new CollectSupportDataArchiveFragmentIntermediateResponse("csd.zip", 10L, false, StaticUtils.getBytes("There")));
assertTrue(out.size() > 0);
assertEquals(err.size(), 0);
assertTrue(outputFile.exists());
assertEquals(outputFile.length(), 10L);
assertNotNull(listener.getOutputStreamReference().get());
assertNull(listener.getFirstIOExceptionReference().get());
out.reset();
listener.close();
assertEquals(out.size(), 0);
assertEquals(err.size(), 0);
assertTrue(outputFile.exists());
assertEquals(outputFile.length(), 10L);
assertEquals(readFileBytes(outputFile), StaticUtils.getBytes("HelloThere"));
assertNull(listener.getOutputStreamReference().get());
assertNull(listener.getFirstIOExceptionReference().get());
}
use of com.unboundid.ldap.sdk.unboundidds.extensions.CollectSupportDataArchiveFragmentIntermediateResponse in project ldapsdk by pingidentity.
the class CollectSupportDataIRListenerTestCase method testThrowOnClose.
/**
* Tests the behavior for the case in which an attempt to close the output
* stream should throw an exception.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testThrowOnClose() throws Exception {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ByteArrayOutputStream err = new ByteArrayOutputStream();
final CollectSupportData tool = new CollectSupportData(out, err);
final File outputFile = createTempFile();
assertTrue(outputFile.delete());
final CollectSupportDataIRListener listener = new CollectSupportDataIRListener(tool, outputFile);
listener.handleArchiveFragmentIntermediateResponse(new CollectSupportDataArchiveFragmentIntermediateResponse("csd.zip", 10L, true, StaticUtils.getBytes("Hello")));
assertTrue(out.size() > 0);
assertEquals(err.size(), 0);
assertTrue(outputFile.exists());
assertEquals(outputFile.length(), 5L);
assertNotNull(listener.getOutputStreamReference().get());
assertNull(listener.getFirstIOExceptionReference().get());
out.reset();
final OutputStream streamToWrap = listener.getOutputStreamReference().get();
listener.getOutputStreamReference().set(new TestOutputStream(streamToWrap, new IOException("close error"), Integer.MAX_VALUE, true));
listener.handleArchiveFragmentIntermediateResponse(new CollectSupportDataArchiveFragmentIntermediateResponse("csd.zip", 10L, false, StaticUtils.getBytes("There")));
assertTrue(out.size() > 0L);
assertEquals(err.size(), 0);
assertTrue(outputFile.exists());
assertEquals(outputFile.length(), 10L);
assertNotNull(listener.getOutputStreamReference().get());
assertNull(listener.getFirstIOExceptionReference().get());
out.reset();
try {
listener.close();
fail("Expected an exception when trying to close the output stream");
} catch (final IOException e) {
// This was expected.
}
assertEquals(out.size(), 0);
assertTrue(err.size() > 0);
assertTrue(outputFile.exists());
assertEquals(outputFile.length(), 10L);
assertEquals(readFileBytes(outputFile), StaticUtils.getBytes("HelloThere"));
assertNull(listener.getOutputStreamReference().get());
assertNotNull(listener.getFirstIOExceptionReference().get());
}
Aggregations