MassConvertController { @RequestMapping(value = "/batch", method = RequestMethod.GET) public void convert(@RequestParam(PARAM_URL) String sourceUrlParams, @RequestParam(value = PARAM_URL_TEMPLATE, required = false, defaultValue = DEFAULT_URL_TEMPLATE) String sourceUrlTemplate, @RequestParam(value = PARAM_OUT_FORMAT, required = false, defaultValue = DEFAULT_OUT_FORMAT) String outputFormat, HttpServletResponse response) throws Exception { if (sourceUrlParams == null || sourceUrlParams.length() == 0) { throw new Exception("Required parameter missing: " + PARAM_URL); } String[] sourceUrls = getSourceUrls(sourceUrlTemplate, sourceUrlParams); Arrays.sort(sourceUrls); String batchSignature = calculateBatchSignature(sourceUrls); String batchFilePath = batchDao.findBatchPath(batchSignature, outputFormat); if (batchFilePath != null) { sendRedirect(response, batchFilePath); return; } List<Callable<Object>> tasks = new ArrayList<Callable<Object>>(sourceUrls.length); for (final String sourceUrl : sourceUrls) { tasks.add(createSingleConversionTask(sourceUrl, outputFormat)); } converterExecutor.invokeAll(tasks); File batchFile = zipFiles(sourceUrls, outputFormat, batchSignature); batchDao.addBatch(batchSignature, outputFormat, batchFile); batchFilePath = batchDao.findBatchPath(batchSignature, outputFormat); sendRedirect(response, batchFilePath); }  @RequestMapping(value = "/batch", method = RequestMethod.GET) void convert(@RequestParam(PARAM_URL) String sourceUrlParams,
                        @RequestParam(value = PARAM_URL_TEMPLATE, required = false, defaultValue = DEFAULT_URL_TEMPLATE) String sourceUrlTemplate,
                        @RequestParam(value = PARAM_OUT_FORMAT, required = false, defaultValue = DEFAULT_OUT_FORMAT) String outputFormat,
                        HttpServletResponse response); void shutdown(); void setStaticRedirectUrlPrefix(String staticRedirectUrlPrefix); void setConvertersPoolSize(int convertersPoolSize); void setUseXAccelRerirect(Boolean useXAccelRerirect); static final String PARAM_URL; static final String PARAM_URL_TEMPLATE; static final String PARAM_OUT_FORMAT; static final String PARAM_SOURCE_FORMAT; static final String DEFAULT_OUT_FORMAT; static final String DEFAULT_URL_TEMPLATE; }
@Test public void testZipFile() throws Exception { MassConvertController controller = new MassConvertController(); BatchDao batchDao = mock(BatchDao.class); when(batchDao.findBatchPath(anyString(), anyString())).thenReturn(null); controller.batchDao = batchDao; UrlDao urlDao = mock(UrlDao.class); when(urlDao.findUrlInfo("http: @Override public UrlInfo answer(InvocationOnMock invocation) throws Throwable { UrlInfo info = new UrlInfo(); info.setBookId("123"); info.setSourceFormat("epub"); return info; } }); when(urlDao.findUrlInfo("http: @Override public UrlInfo answer(InvocationOnMock invocation) throws Throwable { UrlInfo info = new UrlInfo(); info.setBookId("345"); info.setSourceFormat("epub"); return info; } }); controller.urlDao = urlDao; BookDao bookDao = mock(BookDao.class); when(bookDao.findBook("123", "epub")).thenReturn(null); File testFile = createTestFile("345", "epub"); when(bookDao.findBook("345", "epub")).thenReturn(testFile); controller.bookDao = bookDao; controller.singleConverterController = new SingleUrlConverter() { @Override public void convert(String sourceUrl, String sourceMd5, String outputFormat, String sourceFormat, HttpServletResponse response) throws Exception { } }; controller.convert("123;abc;dd_345;def", "http: new HttpServletResponse() { @Override public void addCookie(Cookie cookie) { } @Override public boolean containsHeader(String name) { return false; } @Override public String encodeURL(String url) { return null; } @Override public String encodeRedirectURL(String url) { return null; } @Override public String encodeUrl(String url) { return null; } @Override public String encodeRedirectUrl(String url) { return null; } @Override public void sendError(int sc, String msg) throws IOException { } @Override public void sendError(int sc) throws IOException { } @Override public void sendRedirect(String location) throws IOException { System.out.println("location = " + location); } @Override public void setDateHeader(String name, long date) { } @Override public void addDateHeader(String name, long date) { } @Override public void setHeader(String name, String value) { } @Override public void addHeader(String name, String value) { } @Override public void setIntHeader(String name, int value) { } @Override public void addIntHeader(String name, int value) { } @Override public void setStatus(int sc) { } @Override public void setStatus(int sc, String sm) { } @Override public String getCharacterEncoding() { return null; } @Override public String getContentType() { return null; } @Override public ServletOutputStream getOutputStream() throws IOException { return null; } @Override public PrintWriter getWriter() throws IOException { return null; } @Override public void setCharacterEncoding(String charset) { } @Override public void setContentLength(int len) { } @Override public void setContentType(String type) { } @Override public void setBufferSize(int size) { } @Override public int getBufferSize() { return 0; } @Override public void flushBuffer() throws IOException { } @Override public void resetBuffer() { } @Override public boolean isCommitted() { return false; } @Override public void reset() { } @Override public void setLocale(Locale loc) { } @Override public Locale getLocale() { return null; } }); }