TemplateRestService { @RequestMapping(method = RequestMethod.GET, produces = "application/vnd.openxmlformats-officedocument.wordprocessingml.document") public byte[] getTemplate(@RequestParam String name, @RequestParam String language, HttpServletResponse response) throws Exception { byte[] documentContent = null; Template<?> template = templateRepository.getTemplate(name, language); if (template != null) { ByteArrayOutputStream out = new ByteArrayOutputStream(); template.write(out); documentContent = out.toByteArray(); response.setHeader("Content-Disposition", "attachment; filename=\"" + template.getDocumentName() + ".docx\""); } return documentContent; }  @RequestMapping(method = RequestMethod.GET, produces = "application/vnd.openxmlformats-officedocument.wordprocessingml.document") byte[] getTemplate(@RequestParam String name, @RequestParam String language, HttpServletResponse response); @RequestMapping(method = RequestMethod.POST, produces = "text/html; charset=UTF-8") String updateTemplate(@RequestParam("name") String name, @RequestParam("language") String language,
			@RequestParam("file") MultipartFile file); @RequestMapping(value = "temp", method = RequestMethod.POST, produces = "text/html; charset=UTF-8") String uploadFile(@RequestParam("name") String name, @RequestParam("file") MultipartFile file); @ExceptionHandler(WteFileUploadException.class) String handleException(WteFileUploadException e); @ExceptionHandler(IllegalStateException.class) String handleException(IllegalStateException e); @ExceptionHandler(WteException.class) String handleException(WteException e); @ExceptionHandler(LockingException.class) String handleException(LockingException e); @ExceptionHandler(InvalidTemplateException.class) String handleException(InvalidTemplateException e); @Order(Ordered.LOWEST_PRECEDENCE) @ExceptionHandler(RuntimeException.class) String handleException(RuntimeException e);  }
@Test public void submitTemplateTest() throws Exception { @SuppressWarnings("unchecked") Template<Object> template = Mockito.mock(Template.class); when(repository.getTemplate("template", "de")).thenReturn(template); mockMvc.perform( MockMvcRequestBuilders.fileUpload("/templates") .file("file", "test".getBytes()) .param("name", "template") .param("language", "de")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentType("text/html;charset=UTF-8")); }