@Test public void test_should_fail_while_updateall_for_invalid_input() { BankBranchContractRequest request = new BankBranchContractRequest(); request.setRequestInfo(getRequestInfo()); request.setBankBranches(null); BindingResult errors = new BeanPropertyBindingResult(request, "BankBranchContractRequest"); bankBranchService.validate(request, "updateAll", errors); assertEquals(errors.getAllErrors().get(0).getDefaultMessage(), "BankBranches to update must not be null"); }
public BindingResult validate(BankBranchContractRequest bankBranchContractRequest, String method, BindingResult errors) { try { switch (method) { case "update": Assert.notNull(bankBranchContractRequest.getBankBranch(), "BankBranch to edit must not be null"); validator.validate(bankBranchContractRequest.getBankBranch(), errors); break; case "view": break; case "create": Assert.notNull(bankBranchContractRequest.getBankBranches(), "BankBranches to create must not be null"); for (BankBranchContract b : bankBranchContractRequest.getBankBranches()) { validator.validate(b, errors); } break; case "updateAll": Assert.notNull(bankBranchContractRequest.getBankBranches(), "BankBranches to update must not be null"); for (BankBranchContract b : bankBranchContractRequest.getBankBranches()) { validator.validate(b, errors); } break; default: validator.validate(bankBranchContractRequest.getRequestInfo(), errors); } } catch (IllegalArgumentException e) { errors.addError(new ObjectError("Missing data ", e.getMessage())); } return errors; }
BankBranchService { public BindingResult validate(BankBranchContractRequest bankBranchContractRequest, String method, BindingResult errors) { try { switch (method) { case "update": Assert.notNull(bankBranchContractRequest.getBankBranch(), "BankBranch to edit must not be null"); validator.validate(bankBranchContractRequest.getBankBranch(), errors); break; case "view": break; case "create": Assert.notNull(bankBranchContractRequest.getBankBranches(), "BankBranches to create must not be null"); for (BankBranchContract b : bankBranchContractRequest.getBankBranches()) { validator.validate(b, errors); } break; case "updateAll": Assert.notNull(bankBranchContractRequest.getBankBranches(), "BankBranches to update must not be null"); for (BankBranchContract b : bankBranchContractRequest.getBankBranches()) { validator.validate(b, errors); } break; default: validator.validate(bankBranchContractRequest.getRequestInfo(), errors); } } catch (IllegalArgumentException e) { errors.addError(new ObjectError("Missing data ", e.getMessage())); } return errors; } }
BankBranchService { public BindingResult validate(BankBranchContractRequest bankBranchContractRequest, String method, BindingResult errors) { try { switch (method) { case "update": Assert.notNull(bankBranchContractRequest.getBankBranch(), "BankBranch to edit must not be null"); validator.validate(bankBranchContractRequest.getBankBranch(), errors); break; case "view": break; case "create": Assert.notNull(bankBranchContractRequest.getBankBranches(), "BankBranches to create must not be null"); for (BankBranchContract b : bankBranchContractRequest.getBankBranches()) { validator.validate(b, errors); } break; case "updateAll": Assert.notNull(bankBranchContractRequest.getBankBranches(), "BankBranches to update must not be null"); for (BankBranchContract b : bankBranchContractRequest.getBankBranches()) { validator.validate(b, errors); } break; default: validator.validate(bankBranchContractRequest.getRequestInfo(), errors); } } catch (IllegalArgumentException e) { errors.addError(new ObjectError("Missing data ", e.getMessage())); } return errors; } @Autowired  BankBranchService(final BankBranchRepository bankBranchRepository,
			BankBranchQueueRepository bankBranchQueueRepository,BankService bankService,SmartValidator validator); }
BankBranchService { public BindingResult validate(BankBranchContractRequest bankBranchContractRequest, String method, BindingResult errors) { try { switch (method) { case "update": Assert.notNull(bankBranchContractRequest.getBankBranch(), "BankBranch to edit must not be null"); validator.validate(bankBranchContractRequest.getBankBranch(), errors); break; case "view": break; case "create": Assert.notNull(bankBranchContractRequest.getBankBranches(), "BankBranches to create must not be null"); for (BankBranchContract b : bankBranchContractRequest.getBankBranches()) { validator.validate(b, errors); } break; case "updateAll": Assert.notNull(bankBranchContractRequest.getBankBranches(), "BankBranches to update must not be null"); for (BankBranchContract b : bankBranchContractRequest.getBankBranches()) { validator.validate(b, errors); } break; default: validator.validate(bankBranchContractRequest.getRequestInfo(), errors); } } catch (IllegalArgumentException e) { errors.addError(new ObjectError("Missing data ", e.getMessage())); } return errors; } @Autowired  BankBranchService(final BankBranchRepository bankBranchRepository,
			BankBranchQueueRepository bankBranchQueueRepository,BankService bankService,SmartValidator validator); void push(final BankBranchContractRequest bankBranchContractRequest); @Transactional BankBranchContractResponse create(HashMap<String, Object> financialContractRequestMap); @Transactional BankBranchContractResponse update(HashMap<String, Object> financialContractRequestMap); List<BankBranchContract> getBankBranches(BankBranchGetRequest bankBranchGetRequest); BindingResult validate(BankBranchContractRequest bankBranchContractRequest, String method,
			BindingResult errors); BankBranchContractRequest fetchRelatedContracts(BankBranchContractRequest bankBranchContractRequest); }
BankBranchService { public BindingResult validate(BankBranchContractRequest bankBranchContractRequest, String method, BindingResult errors) { try { switch (method) { case "update": Assert.notNull(bankBranchContractRequest.getBankBranch(), "BankBranch to edit must not be null"); validator.validate(bankBranchContractRequest.getBankBranch(), errors); break; case "view": break; case "create": Assert.notNull(bankBranchContractRequest.getBankBranches(), "BankBranches to create must not be null"); for (BankBranchContract b : bankBranchContractRequest.getBankBranches()) { validator.validate(b, errors); } break; case "updateAll": Assert.notNull(bankBranchContractRequest.getBankBranches(), "BankBranches to update must not be null"); for (BankBranchContract b : bankBranchContractRequest.getBankBranches()) { validator.validate(b, errors); } break; default: validator.validate(bankBranchContractRequest.getRequestInfo(), errors); } } catch (IllegalArgumentException e) { errors.addError(new ObjectError("Missing data ", e.getMessage())); } return errors; } @Autowired  BankBranchService(final BankBranchRepository bankBranchRepository,
			BankBranchQueueRepository bankBranchQueueRepository,BankService bankService,SmartValidator validator); void push(final BankBranchContractRequest bankBranchContractRequest); @Transactional BankBranchContractResponse create(HashMap<String, Object> financialContractRequestMap); @Transactional BankBranchContractResponse update(HashMap<String, Object> financialContractRequestMap); List<BankBranchContract> getBankBranches(BankBranchGetRequest bankBranchGetRequest); BindingResult validate(BankBranchContractRequest bankBranchContractRequest, String method,
			BindingResult errors); BankBranchContractRequest fetchRelatedContracts(BankBranchContractRequest bankBranchContractRequest);  }