@Test public void test_delete_error() throws IOException, Exception { when(budgetService.delete(any(List.class), any(BindingResult.class), any(RequestInfo.class))) .thenReturn(getBudgets()); mockMvc.perform( post("/budgets/_delete").content(resources.readRequest("budget/budget_create_invalid_field_value.json")) .contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().is5xxServerError()); }
@PostMapping("/_delete") @ResponseStatus(HttpStatus.CREATED) public BudgetResponse delete(@RequestBody @Valid final BudgetRequest budgetRequest, final BindingResult errors) { final BudgetMapper mapper = new BudgetMapper(); final BudgetResponse budgetResponse = new BudgetResponse(); budgetResponse.setResponseInfo(getResponseInfo(budgetRequest.getRequestInfo())); List<Budget> budgets = new ArrayList<>(); Budget budget = null; BudgetContract contract = null; final List<BudgetContract> budgetContracts = new ArrayList<BudgetContract>(); budgetRequest.getRequestInfo().setAction(ACTION_DELETE); for (final BudgetContract budgetContract : budgetRequest.getBudgets()) { budget = mapper.toDomain(budgetContract); budgets.add(budget); } budgets = budgetService.delete(budgets, errors, budgetRequest.getRequestInfo()); for (final Budget b : budgets) { contract = mapper.toContract(b); budgetContracts.add(contract); } budgetResponse.setBudgets(budgetContracts); return budgetResponse; }
BudgetController { @PostMapping("/_delete") @ResponseStatus(HttpStatus.CREATED) public BudgetResponse delete(@RequestBody @Valid final BudgetRequest budgetRequest, final BindingResult errors) { final BudgetMapper mapper = new BudgetMapper(); final BudgetResponse budgetResponse = new BudgetResponse(); budgetResponse.setResponseInfo(getResponseInfo(budgetRequest.getRequestInfo())); List<Budget> budgets = new ArrayList<>(); Budget budget = null; BudgetContract contract = null; final List<BudgetContract> budgetContracts = new ArrayList<BudgetContract>(); budgetRequest.getRequestInfo().setAction(ACTION_DELETE); for (final BudgetContract budgetContract : budgetRequest.getBudgets()) { budget = mapper.toDomain(budgetContract); budgets.add(budget); } budgets = budgetService.delete(budgets, errors, budgetRequest.getRequestInfo()); for (final Budget b : budgets) { contract = mapper.toContract(b); budgetContracts.add(contract); } budgetResponse.setBudgets(budgetContracts); return budgetResponse; } }
BudgetController { @PostMapping("/_delete") @ResponseStatus(HttpStatus.CREATED) public BudgetResponse delete(@RequestBody @Valid final BudgetRequest budgetRequest, final BindingResult errors) { final BudgetMapper mapper = new BudgetMapper(); final BudgetResponse budgetResponse = new BudgetResponse(); budgetResponse.setResponseInfo(getResponseInfo(budgetRequest.getRequestInfo())); List<Budget> budgets = new ArrayList<>(); Budget budget = null; BudgetContract contract = null; final List<BudgetContract> budgetContracts = new ArrayList<BudgetContract>(); budgetRequest.getRequestInfo().setAction(ACTION_DELETE); for (final BudgetContract budgetContract : budgetRequest.getBudgets()) { budget = mapper.toDomain(budgetContract); budgets.add(budget); } budgets = budgetService.delete(budgets, errors, budgetRequest.getRequestInfo()); for (final Budget b : budgets) { contract = mapper.toContract(b); budgetContracts.add(contract); } budgetResponse.setBudgets(budgetContracts); return budgetResponse; }  }
BudgetController { @PostMapping("/_delete") @ResponseStatus(HttpStatus.CREATED) public BudgetResponse delete(@RequestBody @Valid final BudgetRequest budgetRequest, final BindingResult errors) { final BudgetMapper mapper = new BudgetMapper(); final BudgetResponse budgetResponse = new BudgetResponse(); budgetResponse.setResponseInfo(getResponseInfo(budgetRequest.getRequestInfo())); List<Budget> budgets = new ArrayList<>(); Budget budget = null; BudgetContract contract = null; final List<BudgetContract> budgetContracts = new ArrayList<BudgetContract>(); budgetRequest.getRequestInfo().setAction(ACTION_DELETE); for (final BudgetContract budgetContract : budgetRequest.getBudgets()) { budget = mapper.toDomain(budgetContract); budgets.add(budget); } budgets = budgetService.delete(budgets, errors, budgetRequest.getRequestInfo()); for (final Budget b : budgets) { contract = mapper.toContract(b); budgetContracts.add(contract); } budgetResponse.setBudgets(budgetContracts); return budgetResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) BudgetResponse create(@RequestBody final BudgetRequest budgetRequest, final BindingResult errors); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) BudgetResponse update(@RequestBody @Valid final BudgetRequest budgetRequest, final BindingResult errors); @PostMapping("/_delete") @ResponseStatus(HttpStatus.CREATED) BudgetResponse delete(@RequestBody @Valid final BudgetRequest budgetRequest, final BindingResult errors); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) BudgetResponse search(@ModelAttribute final BudgetSearchContract budgetSearchContract,
            @RequestBody final RequestInfo requestInfo, final BindingResult errors); }
BudgetController { @PostMapping("/_delete") @ResponseStatus(HttpStatus.CREATED) public BudgetResponse delete(@RequestBody @Valid final BudgetRequest budgetRequest, final BindingResult errors) { final BudgetMapper mapper = new BudgetMapper(); final BudgetResponse budgetResponse = new BudgetResponse(); budgetResponse.setResponseInfo(getResponseInfo(budgetRequest.getRequestInfo())); List<Budget> budgets = new ArrayList<>(); Budget budget = null; BudgetContract contract = null; final List<BudgetContract> budgetContracts = new ArrayList<BudgetContract>(); budgetRequest.getRequestInfo().setAction(ACTION_DELETE); for (final BudgetContract budgetContract : budgetRequest.getBudgets()) { budget = mapper.toDomain(budgetContract); budgets.add(budget); } budgets = budgetService.delete(budgets, errors, budgetRequest.getRequestInfo()); for (final Budget b : budgets) { contract = mapper.toContract(b); budgetContracts.add(contract); } budgetResponse.setBudgets(budgetContracts); return budgetResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) BudgetResponse create(@RequestBody final BudgetRequest budgetRequest, final BindingResult errors); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) BudgetResponse update(@RequestBody @Valid final BudgetRequest budgetRequest, final BindingResult errors); @PostMapping("/_delete") @ResponseStatus(HttpStatus.CREATED) BudgetResponse delete(@RequestBody @Valid final BudgetRequest budgetRequest, final BindingResult errors); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) BudgetResponse search(@ModelAttribute final BudgetSearchContract budgetSearchContract,
            @RequestBody final RequestInfo requestInfo, final BindingResult errors); static final String ACTION_CREATE; static final String ACTION_UPDATE; static final String ACTION_DELETE; static final String PLACEHOLDER; }