Created
October 5, 2009 21:19
-
-
Save lenards/202485 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Test method for {@link org.ipc.iptol.web.RequestHandlerServlet#uploadFile(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)}. | |
*/ | |
@Test | |
public void testUploadFile() { | |
ServletRunner sr = new ServletRunner(); | |
File testfile = new File("/Users/sriram/Documents/workspace/iPToLWeb/src/test/resources/test.nex"); | |
sr.registerServlet( "fileUploadServlet", RequestHandlerServlet.class.getName()); | |
ServletUnitClient sc = sr.newClient(); | |
WebRequest request = new PostMethodWebRequest("http://localhost:8080/fileUploadServlet"); | |
final UploadFileSpec ufs = new UploadFileSpec(testfile,"text/plain"); | |
UploadFileSpec [] spec = new UploadFileSpec[]{ufs}; | |
request.setParameter("document", spec); | |
request.selectFile("document", testfile); | |
try { | |
InvocationContext ic = sc.newInvocation(request) ; | |
RequestHandlerServlet servlet = (RequestHandlerServlet) ic.getServlet(); | |
byte[] file_bytes = servlet.uploadFile(ic.getRequest(), ic.getResponse()); | |
System.out.println(file_bytes); | |
} catch (MalformedURLException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} catch (ServletException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment