WicketTester could not handle Multipart form without upload
-----------------------------------------------------------
Key: WICKET-728
URL: https://issues.apache.org/jira/browse/WICKET-728
Project: Wicket
Issue Type: Bug
Affects Versions: 1.3.0-beta2
Environment: linux 2.6 jdk6
Reporter: Ingram Chen
Attachments: upload-patch.txt
When testing the form that contains FileUploadField without upload,
wicketTester throw exception
with message: "ServletRequest does not contain multipart content"
// ex:
public class FormTesterTest extends WicketTestCase
{
/**
* Test that formTester deal with Multipart form correctly when no
actual
* upload
*/
public void testSubmitWithoutUploadFile()
{
tester.startPage(MockFormFileUploadPage.class);
MockFormFileUploadPage page =
(MockFormFileUploadPage)tester.getLastRenderedPage();
Session.get().setLocale(Locale.US);
FormTester formTester = tester.newFormTester("form");
// without file upload
formTester.submit();
assertNull(page.getFileUpload());
tester.assertErrorMessages(new String[] { "Field 'file' is
required." });
}
}
The cause is that Form contains FileUploadField is considered as multipart. But
MockHttpServletRequest only generate Multipart contentType and contentLength
when there is any upload file added via formTester.setFile(...). Thus without
any file upload while testing, MultipartServletWebRequest throw exception.
To solve this, I try to introduce a flag useMultiPartContentType in
MockHttpServletRequest, so FormTester can change MockHttpServletRequest to
generate correct contentType.
attachment is patch
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.