|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Uploading binary files via MockHttpServletRequest
by mperham
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message I'm trying to unit test a page that accepts a binary upload. I've got a unit test which works fine for a page that accepts an XML (i.e. text) file but the binary data seems to cause problems. Does anyone have an example of how to upload binary data? FYI, here's the XML upload method that works fine:
public void testUpload() throws URISyntaxException { // Upload a tiny changelist which contains a single ApplicationSuite object int before = getClient().getApplicationSuiteAdmin().getAllApplicationSuites().size(); FormTester form = tester.newFormTester("theForm"); File file = new File(new URI(getClass().getResource("simple-change.xml").toString())); tester.getServletRequest().addFile("fileUpload", file, "text/xml; charset=utf-8"); form.submit("submitButton"); tester.assertRenderedPage(SearchChanges.class); tester.assertNoErrorMessage(); // verify the change was NOT published to the repository int after = getClient().getApplicationSuiteAdmin().getAllApplicationSuites().size(); assertEquals(before, after); } |
|
|
Re: Uploading binary files via MockHttpServletRequest
by Frank Bille
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message Hi
On 7/31/07, mperham <mperham@...> wrote: > > > I'm trying to unit test a page that accepts a binary upload. I've got a > unit > test which works fine for a page that accepts an XML (i.e. text) file but > the binary data seems to cause problems. Does anyone have an example of > how > to upload binary data? FYI, here's the XML upload method that works fine: > > public void testUpload() throws URISyntaxException { > // Upload a tiny changelist which contains a single > ApplicationSuite > object > int before = > getClient().getApplicationSuiteAdmin().getAllApplicationSuites().size(); > > FormTester form = tester.newFormTester("theForm"); > File file = new File(new > URI(getClass().getResource("simple-change.xml").toString())); > tester.getServletRequest().addFile("fileUpload", file, "text/xml; > charset=utf-8"); > form.submit("submitButton"); > tester.assertRenderedPage(SearchChanges.class); > tester.assertNoErrorMessage(); > > // verify the change was NOT published to the repository > int after = > getClient().getApplicationSuiteAdmin().getAllApplicationSuites().size(); > assertEquals(before, after); > } > Sounds weird. I didn't actually test it with a binary file back when I did this. Can I get you to open an issue[1] and perhaps actually append a testcase patch for FormTesterTest[2], which shows that it fails? - Frank p.s. Please subscribe to our new user mailing list: users-subscribe@.... Or use the new list on nabble[3]. This list is being shut down. [1]: https://issues.apache.org/jira/browse/WICKET [2]: https://svn.apache.org/repos/asf/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/tester/FormTesterTest.java [3]: http://www.nabble.com/Wicket---User-f25133.html ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ IMPORTANT NOTICE: This mailing list is shutting down. Please subscribe to the Apache Wicket user list. Send a message to: "users-subscribe at wicket.apache.org" and follow the instructions. _______________________________________________ Wicket-user mailing list Wicket-user@... https://lists.sourceforge.net/lists/listinfo/wicket-user |
|
|
Re: Uploading binary files via MockHttpServletRequest
by mperham
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message Frank, thanks for replying. I believe the problem is in MockHttpServletRequest.buildRequest(). It takes the binary data out of the file and puts it into a String. This does an implicit decoding of the bytes based on the platform's default encoding (Cp1252 in Windows) and will cause corruption when you write the data out again (input != output).
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#String(byte[],%20int,%20int) https://issues.apache.org/jira/browse/WICKET-807 In general, I believe you should be building the request as a byte array, not a String. mike
|
|
|
Re: Uploading binary files via MockHttpServletRequest
by Frank Bille
::
Rate this Message:
Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message Thanx for the bug report.
On 7/31/07, mperham <mperham@...> wrote: > > In general, I believe you should be building the request as a byte array, > not a String. > Sounds reasonable. Perhaps you could provide a patch for it? Just attach it to the issue. Frank ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ IMPORTANT NOTICE: This mailing list is shutting down. Please subscribe to the Apache Wicket user list. Send a message to: "users-subscribe at wicket.apache.org" and follow the instructions. _______________________________________________ Wicket-user mailing list Wicket-user@... https://lists.sourceforge.net/lists/listinfo/wicket-user |
| Free embeddable forum powered by Nabble | Forum Help |