List of usage examples for org.apache.commons.fileupload FileUpload setFileItemFactory
public void setFileItemFactory(FileItemFactory factory)
From source file:org.seasar.cubby.controller.impl.MultipartRequestParserImplMultipartRequestTest.java
@Before @SuppressWarnings("unchecked") public void setupRequest() throws Exception { request = createMock(HttpServletRequest.class); expect(request.getCharacterEncoding()).andStubReturn("UTF-8"); expect(request.getAttribute(String.class.cast(anyObject()))).andStubAnswer(new IAnswer<Object>() { public Object answer() throws Throwable { return attributes.get(getCurrentArguments()[0]); }/*from w w w .j a v a 2s . c o m*/ }); request.setAttribute(String.class.cast(anyObject()), anyObject()); expectLastCall().andStubAnswer(new IAnswer<Object>() { public Object answer() throws Throwable { attributes.put(String.class.cast(getCurrentArguments()[0]), getCurrentArguments()[1]); return null; } }); expect(request.getAttributeNames()).andStubAnswer(new IAnswer<Enumeration>() { public Enumeration answer() throws Throwable { return attributes.keys(); } }); expect(request.getParameterMap()).andStubReturn(attributes); expect(request.getContentType()).andStubAnswer(new IAnswer<String>() { public String answer() throws Throwable { return entity.getContentType(); } }); expect(request.getContentLength()).andStubAnswer(new IAnswer<Integer>() { public Integer answer() throws Throwable { return (int) entity.getContentLength(); } }); expect(request.getInputStream()).andStubReturn(new ServletInputStream() { @Override public int read() throws IOException { return input.read(); } }); replay(request); final FileUpload fileUpload = new ServletFileUpload(); fileUpload.setFileItemFactory(new DiskFileItemFactory()); final RequestContext requestContext = new ServletRequestContext(request); BinderPlugin binderPlugin = new BinderPlugin(); binderPlugin.bind(ContainerProvider.class).toInstance(new MockContainerProvider(new Container() { public <T> T lookup(final Class<T> type) { if (FileUpload.class.equals(type)) { return type.cast(fileUpload); } if (RequestContext.class.equals(type)) { return type.cast(requestContext); } return null; } })); pluginRegistry.register(binderPlugin); }