@Test public void add_NewTodo_ShouldSaveTodo() { TodoDTO dto = TodoTestUtil.createDTO(null, TodoTestUtil.DESCRIPTION, TodoTestUtil.TITLE); Todo persisted = TodoTestUtil.createModel(TodoTestUtil.ID, TodoTestUtil.DESCRIPTION, TodoTestUtil.TITLE); when(repositoryMock.save(any(Todo.class))).thenReturn(persisted); service.add(dto); ArgumentCaptor<Todo> toDoArgument = ArgumentCaptor.forClass(Todo.class); verify(repositoryMock, times(1)).save(toDoArgument.capture()); verifyNoMoreInteractions(repositoryMock); verify(indexServiceMock, times(1)).addToIndex(persisted); verifyNoMoreInteractions(indexServiceMock); Todo model = toDoArgument.getValue(); assertNull(model.getId()); assertEquals(dto.getDescription(), model.getDescription()); assertEquals(dto.getTitle(), model.getTitle()); }
@PreAuthorize("hasPermission('Todo', 'add')") @Transactional @Override public Todo add(TodoDTO added) { LOGGER.debug("Adding a new to-do entry with information: {}", added); Todo model = Todo.getBuilder(added.getTitle()) .description(added.getDescription()) .build(); Todo persisted = repository.save(model); indexService.addToIndex(persisted); return persisted; }
RepositoryTodoService implements TodoService { @PreAuthorize("hasPermission('Todo', 'add')") @Transactional @Override public Todo add(TodoDTO added) { LOGGER.debug("Adding a new to-do entry with information: {}", added); Todo model = Todo.getBuilder(added.getTitle()) .description(added.getDescription()) .build(); Todo persisted = repository.save(model); indexService.addToIndex(persisted); return persisted; } }
RepositoryTodoService implements TodoService { @PreAuthorize("hasPermission('Todo', 'add')") @Transactional @Override public Todo add(TodoDTO added) { LOGGER.debug("Adding a new to-do entry with information: {}", added); Todo model = Todo.getBuilder(added.getTitle()) .description(added.getDescription()) .build(); Todo persisted = repository.save(model); indexService.addToIndex(persisted); return persisted; }  }
RepositoryTodoService implements TodoService { @PreAuthorize("hasPermission('Todo', 'add')") @Transactional @Override public Todo add(TodoDTO added) { LOGGER.debug("Adding a new to-do entry with information: {}", added); Todo model = Todo.getBuilder(added.getTitle()) .description(added.getDescription()) .build(); Todo persisted = repository.save(model); indexService.addToIndex(persisted); return persisted; }  @PreAuthorize("hasPermission('Todo', 'add')") @Transactional @Override Todo add(TodoDTO added); @PreAuthorize("hasPermission('Todo', 'delete')") @Transactional(rollbackFor = {TodoNotFoundException.class}) @Override Todo deleteById(Long id); @PreAuthorize("hasPermission('Todo', 'list')") @Transactional(readOnly = true) @Override List<Todo> findAll(); @PreAuthorize("hasPermission('Todo', 'find')") @Transactional(readOnly = true, rollbackFor = {TodoNotFoundException.class}) @Override Todo findById(Long id); @PreAuthorize("hasPermission('Todo', 'update')") @Transactional(rollbackFor = {TodoNotFoundException.class}) @Override Todo update(TodoDTO updated); @PreAuthorize("hasPermission('Todo', 'search')") @Override List<TodoDocument> search(String searchTerm); }
RepositoryTodoService implements TodoService { @PreAuthorize("hasPermission('Todo', 'add')") @Transactional @Override public Todo add(TodoDTO added) { LOGGER.debug("Adding a new to-do entry with information: {}", added); Todo model = Todo.getBuilder(added.getTitle()) .description(added.getDescription()) .build(); Todo persisted = repository.save(model); indexService.addToIndex(persisted); return persisted; }  @PreAuthorize("hasPermission('Todo', 'add')") @Transactional @Override Todo add(TodoDTO added); @PreAuthorize("hasPermission('Todo', 'delete')") @Transactional(rollbackFor = {TodoNotFoundException.class}) @Override Todo deleteById(Long id); @PreAuthorize("hasPermission('Todo', 'list')") @Transactional(readOnly = true) @Override List<Todo> findAll(); @PreAuthorize("hasPermission('Todo', 'find')") @Transactional(readOnly = true, rollbackFor = {TodoNotFoundException.class}) @Override Todo findById(Long id); @PreAuthorize("hasPermission('Todo', 'update')") @Transactional(rollbackFor = {TodoNotFoundException.class}) @Override Todo update(TodoDTO updated); @PreAuthorize("hasPermission('Todo', 'search')") @Override List<TodoDocument> search(String searchTerm);  }