use of alfio.model.modification.AdminReservationModification.CustomerData in project alf.io by alfio-event.
the class AdminReservationManagerIntegrationTest method testReserveFromNewCategory.
@Test
public void testReserveFromNewCategory() throws Exception {
List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 1, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null));
Pair<Event, String> eventWithUsername = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
Event event = eventWithUsername.getKey();
String username = eventWithUsername.getValue();
DateTimeModification expiration = DateTimeModification.fromZonedDateTime(ZonedDateTime.now().plusDays(1));
CustomerData customerData = new CustomerData("Integration", "Test", "integration-test@test.ch", "Billing Address", "en");
Category category = new Category(null, "name", new BigDecimal("100.00"));
int attendees = AVAILABLE_SEATS;
List<TicketsInfo> ticketsInfoList = Collections.singletonList(new TicketsInfo(category, generateAttendees(attendees), true, false));
AdminReservationModification modification = new AdminReservationModification(expiration, customerData, ticketsInfoList, "en", false, null);
Result<Pair<TicketReservation, List<Ticket>>> result = adminReservationManager.createReservation(modification, event.getShortName(), username);
assertTrue(result.isSuccess());
Pair<TicketReservation, List<Ticket>> data = result.getData();
List<Ticket> tickets = data.getRight();
assertTrue(tickets.size() == attendees);
assertNotNull(data.getLeft());
int categoryId = tickets.get(0).getCategoryId();
Event modified = eventManager.getSingleEvent(event.getShortName(), username);
assertEquals(attendees + 1, eventRepository.countExistingTickets(event.getId()).intValue());
assertEquals(attendees, ticketRepository.findPendingTicketsInCategories(Collections.singletonList(categoryId)).size());
TicketCategory categoryModified = ticketCategoryRepository.getByIdAndActive(categoryId, event.getId());
assertEquals(categoryModified.getMaxTickets(), attendees);
ticketCategoryRepository.findByEventId(event.getId()).forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream().allMatch(sp -> sp.getStatus() == SpecialPrice.Status.PENDING)));
adminReservationManager.confirmReservation(event.getShortName(), data.getLeft().getId(), username);
ticketCategoryRepository.findByEventId(event.getId()).forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream().allMatch(sp -> sp.getStatus() == SpecialPrice.Status.TAKEN)));
assertFalse(ticketRepository.findAllReservationsConfirmedButNotAssigned(event.getId()).contains(data.getLeft().getId()));
}
use of alfio.model.modification.AdminReservationModification.CustomerData in project alf.io by alfio-event.
the class AdminReservationManagerIntegrationTest method testReserveMixed.
@Test
public void testReserveMixed() throws Exception {
List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 1, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null));
Pair<Event, String> eventWithUsername = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
Event event = eventWithUsername.getKey();
String username = eventWithUsername.getValue();
DateTimeModification expiration = DateTimeModification.fromZonedDateTime(ZonedDateTime.now().plusDays(1));
CustomerData customerData = new CustomerData("Integration", "Test", "integration-test@test.ch", "Billing Address", "en");
TicketCategory existingCategory = ticketCategoryRepository.findByEventId(event.getId()).get(0);
Category resExistingCategory = new Category(existingCategory.getId(), "", existingCategory.getPrice());
Category resNewCategory = new Category(null, "name", new BigDecimal("100.00"));
int attendees = 1;
List<TicketsInfo> ticketsInfoList = Arrays.asList(new TicketsInfo(resExistingCategory, generateAttendees(attendees), false, false), new TicketsInfo(resNewCategory, generateAttendees(attendees), false, false), new TicketsInfo(resExistingCategory, generateAttendees(attendees), false, false));
AdminReservationModification modification = new AdminReservationModification(expiration, customerData, ticketsInfoList, "en", false, null);
Result<Pair<TicketReservation, List<Ticket>>> result = adminReservationManager.createReservation(modification, event.getShortName(), username);
assertTrue(result.isSuccess());
Pair<TicketReservation, List<Ticket>> data = result.getData();
List<Ticket> tickets = data.getRight();
assertTrue(tickets.size() == 3);
assertNotNull(data.getLeft());
assertTrue(tickets.stream().allMatch(t -> t.getTicketsReservationId().equals(data.getKey().getId())));
int resExistingCategoryId = tickets.get(0).getCategoryId();
int resNewCategoryId = tickets.get(2).getCategoryId();
Event modified = eventManager.getSingleEvent(event.getShortName(), username);
assertEquals(AVAILABLE_SEATS, eventRepository.countExistingTickets(event.getId()).intValue());
assertEquals(3, ticketRepository.findPendingTicketsInCategories(Arrays.asList(resExistingCategoryId, resNewCategoryId)).size());
assertEquals(3, ticketRepository.findTicketsInReservation(data.getLeft().getId()).size());
String reservationId = data.getLeft().getId();
assertEquals(ticketRepository.findTicketsInReservation(reservationId).stream().findFirst().get().getId(), ticketRepository.findFirstTicketInReservation(reservationId).get().getId());
ticketCategoryRepository.findByEventId(event.getId()).forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream().allMatch(sp -> sp.getStatus() == SpecialPrice.Status.PENDING)));
adminReservationManager.confirmReservation(event.getShortName(), data.getLeft().getId(), username);
ticketCategoryRepository.findByEventId(event.getId()).forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream().allMatch(sp -> sp.getStatus() == SpecialPrice.Status.TAKEN)));
assertFalse(ticketRepository.findAllReservationsConfirmedButNotAssigned(event.getId()).contains(data.getLeft().getId()));
}
use of alfio.model.modification.AdminReservationModification.CustomerData in project alf.io by alfio-event.
the class AdminReservationRequestManager method spread.
private Stream<AdminReservationModification> spread(AdminReservationModification src, boolean single) {
if (single) {
return Stream.of(src);
}
return src.getTicketsInfo().stream().flatMap(ti -> ti.getAttendees().stream().map(a -> Pair.of(a, new AdminReservationModification.TicketsInfo(ti.getCategory(), singletonList(a), ti.isAddSeatsIfNotAvailable(), ti.isUpdateAttendees())))).map(p -> {
AdminReservationModification.Attendee attendee = p.getLeft();
String language = StringUtils.defaultIfBlank(attendee.getLanguage(), src.getLanguage());
CustomerData cd = new CustomerData(attendee.getFirstName(), attendee.getLastName(), attendee.getEmailAddress(), null, language);
return new AdminReservationModification(src.getExpiration(), cd, singletonList(p.getRight()), language, src.isUpdateContactData(), src.getNotification());
});
}
use of alfio.model.modification.AdminReservationModification.CustomerData in project alf.io by alfio-event.
the class AdminReservationManagerIntegrationTest method performExistingCategoryTest.
private Triple<Event, String, TicketReservation> performExistingCategoryTest(List<TicketCategoryModification> categories, boolean bounded, List<Integer> attendeesNr, boolean addSeatsIfNotAvailable, boolean expectSuccess, int reservedTickets, int expectedEventSeats) {
assertEquals("Test error: categories' size must be equal to attendees' size", categories.size(), attendeesNr.size());
Pair<Event, String> eventWithUsername = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
Event event = eventWithUsername.getKey();
String username = eventWithUsername.getValue();
DateTimeModification expiration = DateTimeModification.fromZonedDateTime(ZonedDateTime.now().plusDays(1));
CustomerData customerData = new CustomerData("Integration", "Test", "integration-test@test.ch", "Billing Address", "en");
Iterator<Integer> attendeesIterator = attendeesNr.iterator();
List<TicketCategory> existingCategories = ticketCategoryRepository.findByEventId(event.getId());
List<Attendee> allAttendees = new ArrayList<>();
List<TicketsInfo> ticketsInfoList = existingCategories.stream().map(existingCategory -> {
Category category = new Category(existingCategory.getId(), existingCategory.getName(), existingCategory.getPrice());
List<Attendee> attendees = generateAttendees(attendeesIterator.next());
allAttendees.addAll(attendees);
return new TicketsInfo(category, attendees, addSeatsIfNotAvailable, false);
}).collect(toList());
AdminReservationModification modification = new AdminReservationModification(expiration, customerData, ticketsInfoList, "en", false, null);
if (reservedTickets > 0) {
TicketReservationModification trm = new TicketReservationModification();
trm.setAmount(reservedTickets);
trm.setTicketCategoryId(existingCategories.get(0).getId());
TicketReservationWithOptionalCodeModification r = new TicketReservationWithOptionalCodeModification(trm, Optional.empty());
ticketReservationManager.createTicketReservation(event, Collections.singletonList(r), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.empty(), Locale.ENGLISH, false);
}
Result<Pair<TicketReservation, List<Ticket>>> result = adminReservationManager.createReservation(modification, event.getShortName(), username);
if (expectSuccess) {
validateSuccess(bounded, attendeesNr, event, username, existingCategories, result, allAttendees, expectedEventSeats, reservedTickets);
} else {
assertFalse(result.isSuccess());
return null;
}
return Triple.of(eventWithUsername.getLeft(), eventWithUsername.getRight(), result.getData().getKey());
}
Aggregations