Skip to content

Instantly share code, notes, and snippets.

@lenards
Created October 5, 2009 21:19
Show Gist options
  • Save lenards/202485 to your computer and use it in GitHub Desktop.
Save lenards/202485 to your computer and use it in GitHub Desktop.
/**
* 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