*
* @throws Exception
*/
public void testGetInputStream() throws Exception
{
IFileUploadCleaner fileUploadCleaner = new FileUploadCleaner();
FileItem fileItem = new DiskFileItemFactory(fileUploadCleaner).createItem("dummyFieldName",
"text/java", false, "FileUploadTest.java");
// Initialize the upload
fileItem.getOutputStream();
// Get the internal list out
Field inputStreamsField = FileUpload.class.getDeclaredField("inputStreamsToClose");
inputStreamsField.setAccessible(true);
FileUpload fileUpload = new FileUpload(fileItem);
List<?> inputStreams = (List<?>)inputStreamsField.get(fileUpload);
assertNull(inputStreams);
InputStream is1 = fileUpload.getInputStream();
inputStreams = (List<?>)inputStreamsField.get(fileUpload);
assertEquals(1, inputStreams.size());
InputStream is2 = fileUpload.getInputStream();
inputStreams = (List<?>)inputStreamsField.get(fileUpload);
assertEquals(2, inputStreams.size());
assertNotSame(is1, is2);
// Ok lets close all the streams
try
{
fileUpload.closeStreams();
}
catch (Exception e)
{
fail();
}
inputStreams = (List<?>)inputStreamsField.get(fileUpload);
assertNull(inputStreams);
fileUploadCleaner.destroy();
}