use of org.apache.commons.lang3.time.DateUtils.addHours in project alf.io by alfio-event.
the class WaitingQueueProcessorIntegrationTest method initSoldOutEvent.
private Pair<String, Event> initSoldOutEvent(boolean withUnboundedCategory) throws InterruptedException {
int boundedCategorySize = AVAILABLE_SEATS - (withUnboundedCategory ? 1 : 0);
List<TicketCategoryModification> categories = new ArrayList<>();
categories.add(new TicketCategoryModification(null, "default", boundedCategorySize, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()), DESCRIPTION, BigDecimal.ZERO, false, "", true, null, null, null, null, null));
if (withUnboundedCategory) {
categories.add(new TicketCategoryModification(null, "unbounded", 0, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()), DESCRIPTION, BigDecimal.ZERO, false, "", false, null, null, null, null, null));
}
Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
Event event = pair.getKey();
List<TicketCategory> ticketCategories = eventManager.loadTicketCategories(event);
TicketCategory bounded = ticketCategories.stream().filter(t -> t.getName().equals("default")).findFirst().orElseThrow(IllegalStateException::new);
List<Integer> boundedReserved = ticketRepository.selectFreeTicketsForPreReservation(event.getId(), 20, bounded.getId());
assertEquals(boundedCategorySize, boundedReserved.size());
List<Integer> reserved = new ArrayList<>(boundedReserved);
String reservationId = UUID.randomUUID().toString();
ticketReservationRepository.createNewReservation(reservationId, DateUtils.addHours(new Date(), 1), null, Locale.ITALIAN.getLanguage(), event.getId(), event.getVat(), event.isVatIncluded());
List<Integer> reservedForUpdate = withUnboundedCategory ? reserved.subList(0, 19) : reserved;
ticketRepository.reserveTickets(reservationId, reservedForUpdate, bounded.getId(), Locale.ITALIAN.getLanguage(), 0);
if (withUnboundedCategory) {
TicketCategory unbounded = ticketCategories.stream().filter(t -> t.getName().equals("unbounded")).findFirst().orElseThrow(IllegalStateException::new);
List<Integer> unboundedReserved = ticketRepository.selectNotAllocatedFreeTicketsForPreReservation(event.getId(), 20);
assertEquals(1, unboundedReserved.size());
reserved.addAll(unboundedReserved);
ticketRepository.reserveTickets(reservationId, reserved.subList(19, 20), unbounded.getId(), Locale.ITALIAN.getLanguage(), 0);
}
ticketRepository.updateTicketsStatusWithReservationId(reservationId, Ticket.TicketStatus.ACQUIRED.name());
// sold-out
waitingQueueManager.subscribe(event, new CustomerName("Giuseppe Garibaldi", "Giuseppe", "Garibaldi", event), "peppino@garibaldi.com", null, Locale.ENGLISH);
// we are testing ordering, not concurrency...
Thread.sleep(100L);
waitingQueueManager.subscribe(event, new CustomerName("Nino Bixio", "Nino", "Bixio", event), "bixio@mille.org", null, Locale.ITALIAN);
List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId());
assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2);
assertTrue(subscriptions.stream().allMatch(w -> w.getSubscriptionType().equals(WaitingQueueSubscription.Type.SOLD_OUT)));
// the following call shouldn't have any effect
waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2);
return Pair.of(reservationId, event);
}
Aggregations