use of org.springframework.validation.BeanPropertyBindingResult in project alf.io by alfio-event.
the class BillingDocumentCreationIntegrationTest method createReservation.
private String createReservation(Consumer<ContactAndTicketsForm> formCustomizer) {
var categories = ticketCategoryRepository.findAllTicketCategories(event.getId());
assertFalse(categories.isEmpty());
int categoryId = categories.get(0).getId();
var form = new ReservationForm();
var ticketReservation = new TicketReservationModification();
ticketReservation.setQuantity(1);
ticketReservation.setTicketCategoryId(categoryId);
form.setReservation(List.of(ticketReservation));
var res = eventApiV2Controller.reserveTickets(event.getShortName(), "en", form, new BeanPropertyBindingResult(form, "reservation"), new ServletWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse()), null);
assertEquals(HttpStatus.OK, res.getStatusCode());
var resBody = res.getBody();
assertNotNull(resBody);
assertTrue(resBody.isSuccess());
assertEquals(0, resBody.getErrorCount());
var reservationId = resBody.getValue();
// reservation is now in PENDING status
var resInfoRes = reservationApiV2Controller.getReservationInfo(reservationId, null);
assertEquals(HttpStatus.OK, resInfoRes.getStatusCode());
assertNotNull(resInfoRes.getBody());
var ticketsByCat = resInfoRes.getBody().getTicketsByCategory();
assertEquals(1, ticketsByCat.size());
assertEquals(1, ticketsByCat.get(0).getTickets().size());
var ticket = ticketsByCat.get(0).getTickets().get(0);
var contactForm = new ContactAndTicketsForm();
contactForm.setAddCompanyBillingDetails(true);
contactForm.setSkipVatNr(false);
contactForm.setInvoiceRequested(true);
contactForm.setEmail("test@test.com");
contactForm.setFirstName("full");
contactForm.setLastName("name");
var ticketForm1 = new UpdateTicketOwnerForm();
ticketForm1.setFirstName("ticketfull");
ticketForm1.setLastName("ticketname");
ticketForm1.setEmail("tickettest@test.com");
formCustomizer.accept(contactForm);
contactForm.setTickets(Map.of(ticket.getUuid(), ticketForm1));
var success = reservationApiV2Controller.validateToOverview(reservationId, "en", false, contactForm, new BeanPropertyBindingResult(contactForm, "paymentForm"), null);
assertEquals(HttpStatus.OK, success.getStatusCode());
var paymentForm = new PaymentForm();
paymentForm.setPrivacyPolicyAccepted(true);
paymentForm.setTermAndConditionsAccepted(true);
paymentForm.setPaymentProxy(PaymentProxy.OFFLINE);
paymentForm.setSelectedPaymentMethod(PaymentMethod.BANK_TRANSFER);
var handleRes = reservationApiV2Controller.confirmOverview(reservationId, "en", paymentForm, new BeanPropertyBindingResult(paymentForm, "paymentForm"), new MockHttpServletRequest(), null);
assertEquals(HttpStatus.OK, handleRes.getStatusCode());
return reservationId;
}
use of org.springframework.validation.BeanPropertyBindingResult in project alf.io by alfio-event.
the class BaseReservationFlowTest method ensureConfiguration.
private void ensureConfiguration(ReservationFlowContext context) {
IntegrationTestUtil.ensureMinimalConfiguration(configurationRepository);
// promo code at event level
eventManager.addPromoCode(PROMO_CODE, context.event.getId(), null, ZonedDateTime.now(clockProvider.getClock()).minusDays(2), context.event.getEnd().plusDays(2), 10, PromoCodeDiscount.DiscountType.PERCENTAGE, null, 3, "description", "test@test.ch", PromoCodeDiscount.CodeType.DISCOUNT, null);
hiddenCategoryId = ticketCategoryRepository.findAllTicketCategories(context.event.getId()).stream().filter(TicketCategory::isAccessRestricted).collect(Collectors.toList()).get(0).getId();
eventManager.addPromoCode(HIDDEN_CODE, context.event.getId(), null, ZonedDateTime.now(clockProvider.getClock()).minusDays(2), context.event.getEnd().plusDays(2), 0, PromoCodeDiscount.DiscountType.NONE, null, null, "hidden", "test@test.ch", PromoCodeDiscount.CodeType.ACCESS, hiddenCategoryId);
// add additional fields before and after, with one mandatory
var af = new EventModification.AdditionalField(-1, true, "field1", "text", true, false, null, null, null, Map.of("en", new EventModification.Description("field en", "", null)), null, null);
eventManager.addAdditionalField(context.event, af);
var afId = ticketFieldRepository.findAdditionalFieldsForEvent(context.event.getId()).get(0).getId();
ticketFieldRepository.updateFieldOrder(afId, -1);
var af2 = new EventModification.AdditionalField(1, true, "field2", "text", false, false, null, null, null, Map.of("en", new EventModification.Description("field2 en", "", null)), null, null);
eventManager.addAdditionalField(context.event, af2);
//
// add additional service
var addServ = new EventModification.AdditionalService(null, new BigDecimal("40.00"), true, 0, 1, 1, new DateTimeModification(ZonedDateTime.now(clockProvider.getClock()).minusDays(2).toLocalDate(), ZonedDateTime.now(clockProvider.getClock()).minusDays(2).toLocalTime()), new DateTimeModification(context.event.getEnd().plusDays(2).toLocalDate(), context.event.getEnd().plusDays(2).toLocalTime()), context.event.getVat(), AdditionalService.VatType.INHERITED, null, Collections.singletonList(new EventModification.AdditionalServiceText(null, "en", "additional title", AdditionalServiceText.TextType.TITLE)), Collections.singletonList(new EventModification.AdditionalServiceText(null, "en", "additional desc", AdditionalServiceText.TextType.DESCRIPTION)), AdditionalService.AdditionalServiceType.SUPPLEMENT, AdditionalService.SupplementPolicy.OPTIONAL_MAX_AMOUNT_PER_TICKET);
var addServRes = additionalServiceApiController.insert(context.event.getId(), addServ, new BeanPropertyBindingResult(addServ, "additionalService"));
assertNotNull(addServRes.getBody());
additionalServiceId = addServRes.getBody().getId();
//
var af3 = new EventModification.AdditionalField(2, true, "field3", "text", true, false, null, null, null, Map.of("en", new EventModification.Description("field3 en", "", null)), addServRes.getBody(), null);
eventManager.addAdditionalField(context.event, af3);
// enable reservation list and pre sales
configurationRepository.insertEventLevel(context.event.getOrganizationId(), context.event.getId(), ConfigurationKeys.ENABLE_WAITING_QUEUE.getValue(), "true", "");
configurationRepository.insertEventLevel(context.event.getOrganizationId(), context.event.getId(), ConfigurationKeys.ENABLE_PRE_REGISTRATION.getValue(), "true", "");
//
specialPriceTokenGenerator.generatePendingCodes();
}
use of org.springframework.validation.BeanPropertyBindingResult in project alf.io by alfio-event.
the class BaseReservationFlowTest method testAddSubscription.
protected void testAddSubscription(ReservationFlowContext context, int numberOfTickets) {
var form = new ReservationForm();
var ticketReservation = new TicketReservationModification();
ticketReservation.setQuantity(numberOfTickets);
var categoriesResponse = eventApiV2Controller.getTicketCategories(context.event.getShortName(), null);
assertTrue(categoriesResponse.getStatusCode().is2xxSuccessful());
assertNotNull(categoriesResponse.getBody());
ticketReservation.setTicketCategoryId(categoriesResponse.getBody().getTicketCategories().get(0).getId());
form.setReservation(Collections.singletonList(ticketReservation));
var res = eventApiV2Controller.reserveTickets(context.event.getShortName(), "en", form, new BeanPropertyBindingResult(form, "reservation"), new ServletWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse()), null);
assertEquals(HttpStatus.OK, res.getStatusCode());
var resBody = res.getBody();
assertNotNull(resBody);
assertTrue(resBody.isSuccess());
assertEquals(0, resBody.getErrorCount());
var reservationId = resBody.getValue();
checkStatus(reservationId, HttpStatus.OK, false, TicketReservation.TicketReservationStatus.PENDING, context);
var resInfoRes = reservationApiV2Controller.getReservationInfo(reservationId, context.getPublicUser());
assertEquals(HttpStatus.OK, resInfoRes.getStatusCode());
var reservation = resInfoRes.getBody();
assertNotNull(reservation);
assertEquals(reservationId, reservation.getId());
assertEquals(1, reservation.getTicketsByCategory().size());
assertEquals(numberOfTickets, reservation.getTicketsByCategory().get(0).getTickets().size());
var contactForm = new ContactAndTicketsForm();
// move to overview status
contactForm = new ContactAndTicketsForm();
contactForm.setEmail("test@test.com");
contactForm.setBillingAddress("my billing address");
contactForm.setFirstName("full");
contactForm.setLastName("name");
var tickets = reservation.getTicketsByCategory().get(0).getTickets().stream().map(t -> {
var ticketForm = new UpdateTicketOwnerForm();
ticketForm.setFirstName("ticketfull");
ticketForm.setLastName("ticketname");
ticketForm.setEmail("tickettest@test.com");
ticketForm.setAdditional(Collections.singletonMap("field1", Collections.singletonList("value")));
return Map.entry(t.getUuid(), ticketForm);
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
contactForm.setTickets(tickets);
var overviewRes = reservationApiV2Controller.validateToOverview(reservationId, "en", false, contactForm, new BeanPropertyBindingResult(contactForm, "paymentForm"), context.getPublicAuthentication());
assertEquals(HttpStatus.OK, overviewRes.getStatusCode());
checkStatus(reservationId, HttpStatus.OK, true, TicketReservation.TicketReservationStatus.PENDING, context);
var reservationCodeForm = new ReservationCodeForm();
reservationCodeForm.setCode(Objects.requireNonNullElseGet(context.subscriptionPin, context.subscriptionId::toString));
reservationCodeForm.setType(ReservationCodeForm.ReservationCodeType.SUBSCRIPTION);
var bindingResult = new BeanPropertyBindingResult(reservationCodeForm, "reservationCodeForm");
var codeApplicationResult = reservationApiV2Controller.applyCode(reservationId, reservationCodeForm, bindingResult);
assertTrue(codeApplicationResult.getStatusCode().is2xxSuccessful());
var codeApplicationResponse = codeApplicationResult.getBody();
assertNotNull(codeApplicationResponse);
assertTrue(codeApplicationResponse.isSuccess());
assertFalse(bindingResult.hasErrors(), bindingResult::toString);
assertEquals(true, codeApplicationResponse.getValue());
// reload reservation, and assert it is now free of charge
resInfoRes = reservationApiV2Controller.getReservationInfo(reservationId, context.getPublicUser());
assertEquals(HttpStatus.OK, resInfoRes.getStatusCode());
reservation = resInfoRes.getBody();
assertNotNull(reservation);
assertTrue(reservation.getOrderSummary().isFree());
// assert that there is a row in the summary for the subscription
var summaryRowSubscription = reservation.getOrderSummary().getSummary().stream().filter(r -> r.getType() == SummaryRow.SummaryType.APPLIED_SUBSCRIPTION).findFirst();
assertTrue(summaryRowSubscription.isPresent());
assertEquals(numberOfTickets, summaryRowSubscription.get().getAmount());
// proceed with the confirmation
var paymentForm = new PaymentForm();
paymentForm.setPrivacyPolicyAccepted(true);
paymentForm.setTermAndConditionsAccepted(true);
paymentForm.setSelectedPaymentMethod(PaymentMethod.NONE);
var propertyBindingResult = new BeanPropertyBindingResult(paymentForm, "paymentForm");
var handleRes = reservationApiV2Controller.confirmOverview(reservationId, "en", paymentForm, propertyBindingResult, new MockHttpServletRequest(), null);
log.warn("received {}", propertyBindingResult);
assertEquals(HttpStatus.OK, handleRes.getStatusCode());
checkStatus(reservationId, HttpStatus.OK, true, TicketReservation.TicketReservationStatus.COMPLETE, context);
// trigger email processing
triggerEmailProcessingAndCheck(context, reservationId);
}
use of org.springframework.validation.BeanPropertyBindingResult in project Asqatasun by Asqatasun.
the class UserManagementControllerTest method testSubmitEditUserForm.
/**
* Test of submitEditUserForm method, of class UserManagementController.
*/
@Test
public void testSubmitEditUserForm() throws Exception {
setUpMockRoleDataService();
setUpMockUserDataService(false, true, false);
setUpMockAuthenticationContext();
// Finally the form is conform and the admin page is returned
CreateUserCommand createUserCommand = createUserCommandFactory.getNewCreateUserCommand();
createUserCommand.setEmail("user@test.com");
createUserCommand.setLastName("newName");
createUserCommand.setFirstName("newFirstName");
createUserCommand.setPhoneNumber("0102030405");
createUserCommand.setActivated(false);
createUserCommand.setAdmin(true);
MockHttpServletRequest request = new MockHttpServletRequest();
request.getSession().setAttribute(TgolKeyStore.USER_ID_KEY, 5L);
BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
Model model = new ExtendedModelMap();
String result = instance.submitEditUserForm(createUserCommand, bindingResult, request, model);
assertEquals(TgolKeyStore.ADMIN_VIEW_NAME, result);
assertFalse(bindingResult.hasErrors());
assertTrue(bindingResult.getFieldErrors().isEmpty());
assertEquals(2, model.asMap().size());
assertEquals("user@test.com", model.asMap().get(TgolKeyStore.UPDATED_USER_NAME_KEY));
assertTrue(((List<User>) model.asMap().get(TgolKeyStore.USER_LIST_KEY)).isEmpty());
}
use of org.springframework.validation.BeanPropertyBindingResult in project chassis by Kixeye.
the class RawWebSocketMessage method deserialize.
/**
* Deserializes the given message.
*
* @param action
* @return
* @throws Exception
*/
public T deserialize(WebSocketAction action) throws Exception {
// first deserialize
T message = null;
if (messageClass != null) {
message = serDe.deserialize(new ByteBufferBackedInputStream(rawData), messageClass);
}
// then validate
if (message != null && action.shouldValidatePayload()) {
SpringValidatorAdapter validatorAdapter = new SpringValidatorAdapter(messageValidator);
BeanPropertyBindingResult result = new BeanPropertyBindingResult(message, messageClass.getName());
validatorAdapter.validate(message, result);
if (result.hasErrors()) {
throw new MethodArgumentNotValidException(new MethodParameter(action.getMethod(), action.getPayloadParameterIndex()), result);
}
}
return message;
}
Aggregations