use of com.helger.servlet.mock.MockHttpServletRequest in project ph-web by phax.
the class RequestLoggerTest method testBasic.
@Test
public void testBasic() {
final MockServletContext aSC = MockServletContext.create();
try {
final HttpServletRequest aHttpRequest = new MockHttpServletRequest(aSC);
assertNotNull(RequestLogger.getRequestFieldMap(aHttpRequest));
} finally {
aSC.invalidate();
}
}
use of com.helger.servlet.mock.MockHttpServletRequest in project ph-web by phax.
the class StreamingFuncTest method _parseUploadToList.
@Nonnull
@ReturnsMutableCopy
private ICommonsList<IFileItem> _parseUploadToList(final InputStream pStream, final int pLength) throws FileUploadException {
final String contentType = "multipart/form-data; boundary=---1234";
final AbstractFileUploadBase upload = new ServletFileUpload(new DiskFileItemFactory(10240));
final MockHttpServletRequest request = new MockHttpServletRequest() {
@Override
public int getContentLength() {
return pLength;
}
@Override
public ServletInputStream getInputStream() {
return new AbstractServletInputStream() {
@Override
public int read() throws IOException {
return pStream.read();
}
};
}
};
request.setContentType(contentType);
return upload.parseRequest(new ServletRequestContext(request));
}
use of com.helger.servlet.mock.MockHttpServletRequest in project ph-web by phax.
the class StreamingFuncTest method _parseUploadToIterator.
private IFileItemIterator _parseUploadToIterator(final byte[] aContent) throws FileUploadException, IOException {
final String contentType = "multipart/form-data; boundary=---1234";
final AbstractFileUploadBase upload = new ServletFileUpload(new DiskFileItemFactory(10240));
final HttpServletRequest request = new MockHttpServletRequest().setContent(aContent).setContentType(contentType);
return upload.getItemIterator(new ServletRequestContext(request));
}
use of com.helger.servlet.mock.MockHttpServletRequest in project ph-web by phax.
the class AbstractFileUploadTestCase method parseUpload.
protected final ICommonsList<IFileItem> parseUpload(final byte[] bytes, final String contentType) throws FileUploadException {
final ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory(10240));
final HttpServletRequest request = new MockHttpServletRequest().setContent(bytes).setContentType(contentType);
final ICommonsList<IFileItem> fileItems = upload.parseRequest(request);
return fileItems;
}
use of com.helger.servlet.mock.MockHttpServletRequest in project ph-web by phax.
the class IProgressListenerTest method testProgressListener.
/**
* Parse a very long file upload by using a progress listener.
*
* @throws Exception
* In case of error
*/
@Test
public void testProgressListener() throws Exception {
final int NUM_ITEMS = 512;
byte[] contents;
try (final NonBlockingByteArrayOutputStream baos = new NonBlockingByteArrayOutputStream()) {
for (int i = 0; i < NUM_ITEMS; i++) {
final String header = "-----1234\r\n" + "Content-Disposition: form-data; name=\"field" + (i + 1) + "\"\r\n" + "\r\n";
baos.write(header.getBytes(US_ASCII));
for (int j = 0; j < 16384 + i; j++) {
baos.write((byte) j);
}
baos.write("\r\n".getBytes(US_ASCII));
}
baos.write("-----1234--\r\n".getBytes(US_ASCII));
contents = baos.toByteArray();
}
MockHttpServletRequest request = new MockHttpServletRequest().setContent(contents).setContentType("multipart/form-data; boundary=---1234");
_runTest(NUM_ITEMS, contents.length, request);
request = new MockHttpServletRequest() {
@Override
public int getContentLength() {
return -1;
}
};
request.setContent(contents);
request.setContentType("multipart/form-data; boundary=---1234");
_runTest(NUM_ITEMS, contents.length, request);
}
Aggregations