StreamReceiverHandler implements Serializable { protected void doHandleMultipartFileUpload(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamReceiver streamReceiver, StateNode owner) throws IOException { boolean success = false; try { if (hasParts(request)) { success = handleMultipartFileUploadFromParts(session, request, streamReceiver, owner); } else { success = handleMultipartFileUploadFromInputStream(session, request, streamReceiver, owner); } } catch (Exception exception) { session.lock(); try { session.getErrorHandler().error(new ErrorEvent(exception)); } finally { session.unlock(); } } sendUploadResponse(response, success); }  void handleRequest(VaadinSession session, VaadinRequest request,
            VaadinResponse response, StreamReceiver streamReceiver, String uiId,
            String securityKey); static final int DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS; }
@Test public void doHandleMultipartFileUpload_noPart_uploadFailed_responseStatusIs500() throws IOException { handler.doHandleMultipartFileUpload(session, request, response, streamReceiver, stateNode); Mockito.verify(response) .setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); }
@Test public void doHandleMultipartFileUpload_hasParts_uploadFailed_responseStatusIs500() throws IOException { contentType = "multipart/form-data; boundary=----WebKitFormBoundary7NsWHeCJVZNwi6ll"; inputStream = createInputStream( "------WebKitFormBoundary7NsWHeCJVZNwi6ll\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"EBookJP.txt\"\n" + "Content-Type: text/plain\n" + "\n" + "\n" + "------WebKitFormBoundary7NsWHeCJVZNwi6ll--"); Mockito.doThrow(RuntimeException.class).when(outputStream) .write(Mockito.any(), Mockito.anyInt(), Mockito.anyInt()); contentLength = "99"; parts = new ArrayList<>(); parts.add(createPart(createInputStream("foobar"), "text/plain", "EBookJP.txt", 6)); handler.doHandleMultipartFileUpload(session, request, response, streamReceiver, stateNode); Mockito.verify(response) .setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); }
@Test public void exceptionIsThrownOnUnexpectedEnd() throws IOException { contentType = "multipart/form-data; boundary=----WebKitFormBoundary7NsWHeCJVZNwi6ll"; inputStream = createInputStream( "------WebKitFormBoundary7NsWHeCJVZNwi6ll\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"EBookJP.txt\"\n" + "Content-Type: text/plain\n" + "\n" + "\n" + "------WebKitFormBoundary7NsWHeCJVZNwi6ll--"); contentLength = "99"; handler.doHandleMultipartFileUpload(session, request, response, null, null); Mockito.verify(response) .setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); }