@Test public void shouldImportTask() throws Exception { ObjectMapper mapper = new ObjectMapper(); StringWriter writer = new StringWriter(); IOUtils.copy(this.getClass().getResourceAsStream("/new-task-version.json"), writer); ObjectNode node = (ObjectNode) mapper.readTree(writer.toString()); node.remove(asList("validationErrors", "type", "_rev")); String json = node.toString(); when(taskService.importTask(json.toString())).thenReturn(new Task(null, trigger, null)); when(file.getInputStream()).thenReturn(new ByteArrayInputStream(json.getBytes())); controller.importTask(file); verify(taskService).importTask(json); }
@RequestMapping(value = "/task/import", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void importTask(@RequestParam(value = "file") MultipartFile file) throws IOException { StringWriter writer = new StringWriter(); IOUtils.copy(file.getInputStream(), writer); taskService.importTask(writer.toString()); }
TaskController { @RequestMapping(value = "/task/import", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void importTask(@RequestParam(value = "file") MultipartFile file) throws IOException { StringWriter writer = new StringWriter(); IOUtils.copy(file.getInputStream(), writer); taskService.importTask(writer.toString()); } }
TaskController { @RequestMapping(value = "/task/import", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void importTask(@RequestParam(value = "file") MultipartFile file) throws IOException { StringWriter writer = new StringWriter(); IOUtils.copy(file.getInputStream(), writer); taskService.importTask(writer.toString()); }  }
TaskController { @RequestMapping(value = "/task/import", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void importTask(@RequestParam(value = "file") MultipartFile file) throws IOException { StringWriter writer = new StringWriter(); IOUtils.copy(file.getInputStream(), writer); taskService.importTask(writer.toString()); }  @RequestMapping(value = "/task", method = RequestMethod.GET) @ResponseBody List<TaskDto> getAllTasks(); @RequestMapping(value = "/task/import", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) void importTask(@RequestParam(value = "file") MultipartFile file); @RequestMapping(value = "/task/{taskId}", method = RequestMethod.GET) @ResponseBody TaskDto getTask(@PathVariable Long taskId); @RequestMapping(value = "/task/{taskId}", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) @ResponseBody Set<TaskErrorDto> saveTask(@RequestBody Task task); @RequestMapping(value = "/task/enable-or-disable/{taskId}", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) @ResponseBody void setTaskEnabledOrDisabled(@RequestBody Task task); @RequestMapping(value = "/task/{taskId}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) void deleteTask(@PathVariable Long taskId); @RequestMapping(value = "/task/{taskId}/export", method = RequestMethod.GET) void exportTask(@PathVariable Long taskId, HttpServletResponse response); @RequestMapping(value = "/task/save", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) @ResponseBody Set<TaskErrorDto> save(@RequestBody Task task); @ExceptionHandler(ValidationException.class) @ResponseStatus(HttpStatus.NOT_FOUND) @ResponseBody Set<TaskErrorDto> handleException(ValidationException e); @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.NOT_FOUND) @ResponseBody String handleException(Exception e); }
TaskController { @RequestMapping(value = "/task/import", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void importTask(@RequestParam(value = "file") MultipartFile file) throws IOException { StringWriter writer = new StringWriter(); IOUtils.copy(file.getInputStream(), writer); taskService.importTask(writer.toString()); }  @RequestMapping(value = "/task", method = RequestMethod.GET) @ResponseBody List<TaskDto> getAllTasks(); @RequestMapping(value = "/task/import", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) void importTask(@RequestParam(value = "file") MultipartFile file); @RequestMapping(value = "/task/{taskId}", method = RequestMethod.GET) @ResponseBody TaskDto getTask(@PathVariable Long taskId); @RequestMapping(value = "/task/{taskId}", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) @ResponseBody Set<TaskErrorDto> saveTask(@RequestBody Task task); @RequestMapping(value = "/task/enable-or-disable/{taskId}", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) @ResponseBody void setTaskEnabledOrDisabled(@RequestBody Task task); @RequestMapping(value = "/task/{taskId}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) void deleteTask(@PathVariable Long taskId); @RequestMapping(value = "/task/{taskId}/export", method = RequestMethod.GET) void exportTask(@PathVariable Long taskId, HttpServletResponse response); @RequestMapping(value = "/task/save", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) @ResponseBody Set<TaskErrorDto> save(@RequestBody Task task); @ExceptionHandler(ValidationException.class) @ResponseStatus(HttpStatus.NOT_FOUND) @ResponseBody Set<TaskErrorDto> handleException(ValidationException e); @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.NOT_FOUND) @ResponseBody String handleException(Exception e);  }