use of org.springframework.validation.BindingResult in project motech by motech.
the class BootstrapControllerTest method shouldAddErrorsOnValidationFailure.
@Test
public void shouldAddErrorsOnValidationFailure() throws Exception {
when(messageBrokerTestService.pingBroker("tcp://localhost:61616")).thenReturn(true);
BindingResult bindingResult = mock(BindingResult.class);
when(bindingResult.hasErrors()).thenReturn(true);
when(bindingResult.getAllErrors()).thenReturn(Arrays.asList(new ObjectError("sqlUrl", new String[] { "server.dbUrl.error" }, null, null)));
BootstrapConfigForm bootstrapConfigForm = new BootstrapConfigForm();
bootstrapConfigForm.setSqlUrl("http://www.dburl.com");
ModelAndView actualView = bootstrapController.submitForm(bootstrapConfigForm, bindingResult, request);
assertThat(actualView.getViewName(), is("bootstrapconfig"));
assertThat((String) ((List) actualView.getModel().get("errors")).get(0), is("server.dbUrl.error"));
}
use of org.springframework.validation.BindingResult in project FuryViewer by TheDoctor-95.
the class ExceptionTranslator method handleMethodArgumentNotValid.
@Override
public ResponseEntity<Problem> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, @Nonnull NativeWebRequest request) {
BindingResult result = ex.getBindingResult();
List<FieldErrorVM> fieldErrors = result.getFieldErrors().stream().map(f -> new FieldErrorVM(f.getObjectName(), f.getField(), f.getCode())).collect(Collectors.toList());
Problem problem = Problem.builder().withType(ErrorConstants.CONSTRAINT_VIOLATION_TYPE).withTitle("Method argument not valid").withStatus(defaultConstraintViolationStatus()).with("message", ErrorConstants.ERR_VALIDATION).with("fieldErrors", fieldErrors).build();
return create(ex, problem, request);
}
use of org.springframework.validation.BindingResult in project dubion by valsamiq.
the class ExceptionTranslator method handleMethodArgumentNotValid.
@Override
public ResponseEntity<Problem> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, @Nonnull NativeWebRequest request) {
BindingResult result = ex.getBindingResult();
List<FieldErrorVM> fieldErrors = result.getFieldErrors().stream().map(f -> new FieldErrorVM(f.getObjectName(), f.getField(), f.getCode())).collect(Collectors.toList());
Problem problem = Problem.builder().withType(ErrorConstants.CONSTRAINT_VIOLATION_TYPE).withTitle("Method argument not valid").withStatus(defaultConstraintViolationStatus()).with("message", ErrorConstants.ERR_VALIDATION).with("fieldErrors", fieldErrors).build();
return create(ex, problem, request);
}
use of org.springframework.validation.BindingResult in project BroadleafCommerce by BroadleafCommerce.
the class RegisterCustomerControllerTest method createCustomerFromController.
@Test(groups = "createCustomerFromController", dataProvider = "setupCustomerControllerData", dataProviderClass = RegisterCustomerDataProvider.class, enabled = false)
@Transactional
@Rollback(false)
public void createCustomerFromController(RegisterCustomerForm registerCustomer) {
BindingResult errors = new BeanPropertyBindingResult(registerCustomer, "registerCustomer");
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
registerCustomerController.registerCustomer(registerCustomer, errors, request, response);
assert (errors.getErrorCount() == 0);
Customer customerFromDb = customerService.readCustomerByUsername(registerCustomer.getCustomer().getUsername());
assert (customerFromDb != null);
}
use of org.springframework.validation.BindingResult in project jprime by bgjug.
the class TicketsController method register.
/**
* User submitted the form.
*/
@Transactional
@RequestMapping(value = "/tickets/epay", method = RequestMethod.POST)
public String register(Model model, @Valid final Registrant registrant, BindingResult bindingResult, HttpServletRequest request) throws Exception {
boolean invalidCaptcha = false;
if (registrant.getCaptcha() == null || !registrant.getCaptcha().equals(request.getSession().getAttribute(CaptchaController.SESSION_PARAM_CAPTCHA_IMAGE))) {
bindingResult.rejectValue("captcha", "invalid");
invalidCaptcha = true;
}
if (bindingResult.hasErrors() || invalidCaptcha) {
return TICKETS_REGISTER_JSP;
}
// check empty users, server side validation
List<Visitor> toBeRemoved = registrant.getVisitors().stream().filter(v -> v.getEmail() == null || v.getEmail().isEmpty() || v.getName() == null || v.getName().isEmpty()).collect(Collectors.toList());
registrant.getVisitors().removeAll(toBeRemoved);
registrant.getVisitors().forEach(visitor -> visitor.setStatus(VisitorStatus.REQUESTING));
if (!registrant.isCompany()) {
handlePersonalRegistrant(registrant);
}
registrant.setPaymentType(Registrant.PaymentType.BANK_TRANSFER);
Registrant savedRegistrant = registrantFacade.save(registrant);
model.addAttribute("tags", userFacade.findAllTags());
InvoiceData invoiceData = buildInvoiceData(savedRegistrant);
byte[] pdf = invoiceExporter.exportInvoice(invoiceData, registrant.isCompany());
sendPDF(savedRegistrant, generatePdfFilename(registrant, invoiceData.getSinglePriceWithVAT()), pdf);
return result("ok", model);
}
Aggregations