use of alfio.manager.user.UserManager 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.manager.user.UserManager in project alf.io by alfio-event.
the class EventManagerIntegrationTest method testDecreaseEventSeatsWithABoundedCategory.
@Test
public void testDecreaseEventSeatsWithABoundedCategory() {
List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 10, 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> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
Event event = pair.getKey();
EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null, null, null, null, null, event.getOrganizationId(), null, "0.0", "0.0", ZoneId.systemDefault().getId(), null, DateTimeModification.fromZonedDateTime(event.getBegin()), DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(), event.getCurrency(), 10, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), null, event.isFreeOfCharge(), null, 7, null, null);
eventManager.updateEventPrices(event, update, pair.getValue());
List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
assertNotNull(tickets);
assertFalse(tickets.isEmpty());
assertEquals(10, tickets.size());
assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() != null));
}
use of alfio.manager.user.UserManager in project alf.io by alfio-event.
the class EventManagerIntegrationTest method testUnboundedTicketsGeneration.
@Test
public void testUnboundedTicketsGeneration() {
List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null));
Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository).getKey();
List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
assertNotNull(tickets);
assertFalse(tickets.isEmpty());
assertEquals(AVAILABLE_SEATS, tickets.size());
assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() == null));
}
use of alfio.manager.user.UserManager in project alf.io by alfio-event.
the class TicketReservationManagerIntegrationTest method testTicketSelection.
@Test
public void testTicketSelection() {
List<TicketCategoryModification> categories = Arrays.asList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null), new TicketCategoryModification(null, "default", 10, 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> eventAndUsername = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
Event event = eventAndUsername.getKey();
TicketCategory bounded = ticketCategoryRepository.findByEventId(event.getId()).stream().filter(TicketCategory::isBounded).findFirst().orElseThrow(IllegalStateException::new);
TicketCategory unbounded = ticketCategoryRepository.findByEventId(event.getId()).stream().filter(t -> !t.isBounded()).findFirst().orElseThrow(IllegalStateException::new);
assertEquals(0, eventStatisticsManager.loadModifiedTickets(event.getId(), bounded.getId(), 0, null).size());
assertEquals(Integer.valueOf(0), eventStatisticsManager.countModifiedTicket(event.getId(), bounded.getId(), null));
assertEquals(0, eventStatisticsManager.loadModifiedTickets(event.getId(), unbounded.getId(), 0, null).size());
TicketReservationModification tr = new TicketReservationModification();
tr.setAmount(10);
tr.setTicketCategoryId(bounded.getId());
TicketReservationModification tr2 = new TicketReservationModification();
tr2.setAmount(9);
tr2.setTicketCategoryId(unbounded.getId());
TicketReservationWithOptionalCodeModification mod = new TicketReservationWithOptionalCodeModification(tr, Optional.empty());
TicketReservationWithOptionalCodeModification mod2 = new TicketReservationWithOptionalCodeModification(tr2, Optional.empty());
String reservationId = ticketReservationManager.createTicketReservation(event, Arrays.asList(mod, mod2), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.empty(), Locale.ENGLISH, false);
List<TicketReservation> reservations = ticketReservationManager.findAllReservationsInEvent(event.getId(), 0, null, null).getKey();
assertTrue(reservations.size() == 1);
assertEquals(reservationId, reservations.get(0).getId());
List<Ticket> pendingTickets = ticketRepository.findPendingTicketsInCategories(Arrays.asList(bounded.getId(), unbounded.getId()));
assertEquals(19, pendingTickets.size());
pendingTickets.forEach(t -> assertEquals(1000, t.getFinalPriceCts()));
List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
assertEquals(1, tickets.size());
assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() == null));
TotalPrice totalPrice = ticketReservationManager.totalReservationCostWithVAT(reservationId);
assertEquals(0, ticketReservationManager.getPendingPayments(event).size());
PaymentResult confirm = ticketReservationManager.confirm(null, null, event, reservationId, "email@example.com", new CustomerName("full name", "full", "name", event), Locale.ENGLISH, "billing address", totalPrice, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null);
assertTrue(confirm.isSuccessful());
assertEquals(TicketReservation.TicketReservationStatus.OFFLINE_PAYMENT, ticketReservationManager.findById(reservationId).get().getStatus());
assertEquals(1, ticketReservationManager.getPendingPayments(event).size());
Date now = new Date();
Date from = DateUtils.addDays(now, -1);
Date to = DateUtils.addDays(now, 1);
// -> no reservations
assertTrue(ticketReservationRepository.getSoldStatistic(event.getId(), from, to).isEmpty());
ticketReservationManager.validateAndConfirmOfflinePayment(reservationId, event, new BigDecimal("190.00"), eventAndUsername.getValue());
// -> 19 tickets reserved
assertEquals(19, ticketReservationRepository.getSoldStatistic(event.getId(), from, to).get(0).getTicketSoldCount());
assertEquals(10, eventStatisticsManager.loadModifiedTickets(event.getId(), bounded.getId(), 0, null).size());
assertEquals(Integer.valueOf(10), eventStatisticsManager.countModifiedTicket(event.getId(), bounded.getId(), null));
assertEquals(9, eventStatisticsManager.loadModifiedTickets(event.getId(), unbounded.getId(), 0, null).size());
assertEquals(Integer.valueOf(9), eventStatisticsManager.countModifiedTicket(event.getId(), unbounded.getId(), null));
assertEquals(TicketReservation.TicketReservationStatus.COMPLETE, ticketReservationManager.findById(reservationId).get().getStatus());
// -------------------
TicketReservationModification trForDelete = new TicketReservationModification();
trForDelete.setAmount(1);
trForDelete.setTicketCategoryId(unbounded.getId());
TicketReservationWithOptionalCodeModification modForDelete = new TicketReservationWithOptionalCodeModification(trForDelete, Optional.empty());
String reservationId2 = ticketReservationManager.createTicketReservation(event, Collections.singletonList(modForDelete), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.empty(), Locale.ENGLISH, false);
ticketReservationManager.confirm(null, null, event, reservationId2, "email@example.com", new CustomerName("full name", "full", "name", event), Locale.ENGLISH, "billing address", totalPrice, Optional.empty(), Optional.of(PaymentProxy.OFFLINE), false, null, null, null);
assertTrue(ticketReservationManager.findById(reservationId2).isPresent());
ticketReservationManager.deleteOfflinePayment(event, reservationId2, false);
Assert.assertFalse(ticketReservationManager.findById(reservationId2).isPresent());
}
use of alfio.manager.user.UserManager 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