Search in sources :

Example 6 with MockHttpServletRequest

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();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) MockServletContext(com.helger.servlet.mock.MockServletContext) Test(org.junit.Test)

Example 7 with MockHttpServletRequest

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));
}
Also used : ServletFileUpload(com.helger.web.fileupload.servlet.ServletFileUpload) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) ServletRequestContext(com.helger.web.fileupload.servlet.ServletRequestContext) AbstractServletInputStream(com.helger.servlet.io.AbstractServletInputStream) DiskFileItemFactory(com.helger.web.fileupload.parse.DiskFileItemFactory) AbstractFileUploadBase(com.helger.web.fileupload.parse.AbstractFileUploadBase) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Example 8 with MockHttpServletRequest

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));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) ServletFileUpload(com.helger.web.fileupload.servlet.ServletFileUpload) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) ServletRequestContext(com.helger.web.fileupload.servlet.ServletRequestContext) DiskFileItemFactory(com.helger.web.fileupload.parse.DiskFileItemFactory) AbstractFileUploadBase(com.helger.web.fileupload.parse.AbstractFileUploadBase)

Example 9 with MockHttpServletRequest

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) ServletFileUpload(com.helger.web.fileupload.servlet.ServletFileUpload) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) IFileItem(com.helger.web.fileupload.IFileItem)

Example 10 with MockHttpServletRequest

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);
}
Also used : MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) NonBlockingByteArrayOutputStream(com.helger.commons.io.stream.NonBlockingByteArrayOutputStream) Test(org.junit.Test)

Aggregations

MockHttpServletRequest (com.helger.servlet.mock.MockHttpServletRequest)20 Test (org.junit.Test)10 StopWatch (com.helger.commons.timing.StopWatch)6 WebScoped (com.helger.web.scope.mgr.WebScoped)6 PeppolParticipantIdentifier (com.helger.peppolid.peppol.participant.PeppolParticipantIdentifier)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Response (javax.ws.rs.core.Response)5 ServletFileUpload (com.helger.web.fileupload.servlet.ServletFileUpload)4 ObjectFactory (com.helger.xsds.peppol.smp1.ObjectFactory)4 PeppolDocumentTypeIdentifier (com.helger.peppolid.peppol.doctype.PeppolDocumentTypeIdentifier)3 PeppolProcessIdentifier (com.helger.peppolid.peppol.process.PeppolProcessIdentifier)3 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)3 IFileItem (com.helger.web.fileupload.IFileItem)3 DiskFileItemFactory (com.helger.web.fileupload.parse.DiskFileItemFactory)3 WebScopeTestRule (com.helger.web.scope.mock.WebScopeTestRule)3 ICommonsList (com.helger.commons.collection.impl.ICommonsList)2 PhotonSecurityManagerFactoryMongoDB (com.helger.phoss.smp.backend.mongodb.PhotonSecurityManagerFactoryMongoDB)2 SMPServerRESTTestRule (com.helger.phoss.smp.mock.SMPServerRESTTestRule)2 MockHttpServletResponse (com.helger.servlet.mock.MockHttpServletResponse)2 MockServletContext (com.helger.servlet.mock.MockServletContext)2