Search in sources :

Example 1 with ConfigurationRepository

use of alfio.repository.system.ConfigurationRepository in project alf.io by alfio-event.

the class CheckInManagerIntegrationTest method testReturnOnlyOnce.

@Test
void testReturnOnlyOnce() {
    IntegrationTestUtil.ensureMinimalConfiguration(configurationRepository);
    List<TicketCategoryModification> categories = List.of(new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(ClockProvider.clock()).minusDays(1), LocalTime.now(ClockProvider.clock())), new DateTimeModification(LocalDate.now(ClockProvider.clock()).plusDays(1), LocalTime.now(ClockProvider.clock())), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()));
    Pair<Event, String> eventAndUser = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
    var event = eventAndUser.getLeft();
    var additionalServiceRequest = new EventModification.AdditionalService(null, BigDecimal.ONE, true, 1, 100, 2, DateTimeModification.fromZonedDateTime(ZonedDateTime.now(ClockProvider.clock()).minusDays(1)), DateTimeModification.fromZonedDateTime(ZonedDateTime.now(ClockProvider.clock()).plusDays(1)), BigDecimal.ZERO, AdditionalService.VatType.INHERITED, List.of(), List.of(new EventModification.AdditionalServiceText(null, "en", "bla", AdditionalServiceText.TextType.TITLE)), List.of(new EventModification.AdditionalServiceText(null, "en", "blabla", AdditionalServiceText.TextType.DESCRIPTION)), AdditionalService.AdditionalServiceType.SUPPLEMENT, AdditionalService.SupplementPolicy.OPTIONAL_UNLIMITED_AMOUNT);
    var additionalService = eventManager.insertAdditionalService(event, additionalServiceRequest);
    var category = ticketCategoryRepository.findAllTicketCategories(event.getId()).get(0);
    TicketReservationModification tr = new TicketReservationModification();
    tr.setQuantity(AVAILABLE_SEATS);
    tr.setTicketCategoryId(category.getId());
    var tickets = new TicketReservationWithOptionalCodeModification(tr, Optional.empty());
    var additionalServices = new AdditionalServiceReservationModification();
    additionalServices.setAdditionalServiceId(additionalService.getId());
    additionalServices.setQuantity(1);
    var additionalServicesModification = new ASReservationWithOptionalCodeModification(additionalServices, Optional.empty());
    String reservationId = ticketReservationManager.createTicketReservation(event, List.of(tickets), List.of(additionalServicesModification), DateUtils.addDays(new Date(), 1), Optional.empty(), Locale.ENGLISH, false, null);
    Pair<TotalPrice, Optional<PromoCodeDiscount>> priceAndDiscount = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    TotalPrice reservationCost = priceAndDiscount.getLeft();
    assertTrue(priceAndDiscount.getRight().isEmpty());
    PaymentSpecification specification = new PaymentSpecification(reservationId, null, reservationCost.getPriceWithVAT(), event, "email@example.com", new CustomerName("full name", "full", "name", event.mustUseFirstAndLastName()), "billing address", null, Locale.ENGLISH, true, false, null, "IT", "123456", PriceContainer.VatStatus.INCLUDED, true, false);
    PaymentResult result = ticketReservationManager.performPayment(specification, reservationCost, PaymentProxy.OFFLINE, PaymentMethod.BANK_TRANSFER, null);
    assertTrue(result.isSuccessful());
    ticketReservationManager.confirmOfflinePayment(event, reservationId, eventAndUser.getRight());
    var returnedAdditionalServices = ticketReservationManager.findTicketsInReservation(reservationId).stream().filter(ticket -> !checkInManager.getAdditionalServicesForTicket(ticket).isEmpty()).collect(Collectors.toList());
    // 
    assertEquals(1, returnedAdditionalServices.size());
    assertEquals((int) ticketRepository.findFirstTicketIdInReservation(reservationId).orElseThrow(), returnedAdditionalServices.get(0).getId());
}
Also used : TicketCategoryRepository(alfio.repository.TicketCategoryRepository) PaymentProxy(alfio.model.transaction.PaymentProxy) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) PaymentResult(alfio.manager.support.PaymentResult) AlfioMetadata(alfio.model.metadata.AlfioMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) BigDecimal(java.math.BigDecimal) Pair(org.apache.commons.lang3.tuple.Pair) Locale(java.util.Locale) LocalTime(java.time.LocalTime) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketRepository(alfio.repository.TicketRepository) PaymentMethod(alfio.model.transaction.PaymentMethod) EventRepository(alfio.repository.EventRepository) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) Collectors(java.util.stream.Collectors) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) DateUtils(org.apache.commons.lang3.time.DateUtils) Test(org.junit.jupiter.api.Test) List(java.util.List) Initializer(alfio.config.Initializer) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) alfio.model(alfio.model) PaymentSpecification(alfio.manager.payment.PaymentSpecification) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) DataSourceConfiguration(alfio.config.DataSourceConfiguration) ClockProvider(alfio.util.ClockProvider) TestConfiguration(alfio.TestConfiguration) alfio.model.modification(alfio.model.modification) Transactional(org.springframework.transaction.annotation.Transactional) Optional(java.util.Optional) PaymentResult(alfio.manager.support.PaymentResult) Date(java.util.Date) LocalDate(java.time.LocalDate) PaymentSpecification(alfio.manager.payment.PaymentSpecification) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with ConfigurationRepository

use of alfio.repository.system.ConfigurationRepository in project alf.io by alfio-event.

the class WaitingQueueProcessorMultiThreadedIntegrationTest method testPreRegistration.

@Test
public void testPreRegistration() throws InterruptedException {
    IntegrationTestUtil.ensureMinimalConfiguration(configurationRepository);
    configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_PRE_REGISTRATION, "true");
    configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true");
    initAdminUser(userRepository, authorityRepository);
    Event event = null;
    try {
        List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, 10, new DateTimeModification(LocalDate.now(ClockProvider.clock()).plusDays(1), LocalTime.now(ClockProvider.clock())), new DateTimeModification(LocalDate.now(ClockProvider.clock()).plusDays(2), LocalTime.now(ClockProvider.clock())), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()));
        Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
        event = pair.getKey();
        waitingQueueManager.subscribe(event, new CustomerName("Giuseppe Garibaldi", "Giuseppe", "Garibaldi", event.mustUseFirstAndLastName()), "peppino@garibaldi.com", null, Locale.ENGLISH);
        waitingQueueManager.subscribe(event, new CustomerName("Nino Bixio", "Nino", "Bixio", event.mustUseFirstAndLastName()), "bixio@mille.org", null, Locale.ITALIAN);
        assertEquals(2, (int) waitingQueueRepository.countWaitingPeople(event.getId()));
        final int parallelism = 10;
        List<Callable<Void>> calls = new ArrayList<>(parallelism);
        ExecutorService executor = Executors.newFixedThreadPool(parallelism);
        final Event eventF = event;
        for (int i = 0; i < parallelism; i++) {
            calls.add(() -> {
                waitingQueueSubscriptionProcessor.distributeAvailableSeats(eventF);
                return null;
            });
        }
        executor.invokeAll(calls);
        executor.shutdown();
        while (!executor.awaitTermination(10, TimeUnit.MILLISECONDS)) {
        }
        assertEquals(18, ticketRepository.findFreeByEventId(event.getId()).size());
        TicketCategoryModification tcm = new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, 10, new DateTimeModification(LocalDate.now(ClockProvider.clock()).minusDays(1), LocalTime.now(ClockProvider.clock())), new DateTimeModification(LocalDate.now(ClockProvider.clock()).plusDays(5), LocalTime.now(ClockProvider.clock())), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null, 0, null, null, AlfioMetadata.empty());
        eventManager.insertCategory(event.getId(), tcm, pair.getValue());
        // System.err.println("------------------------------------------------");
        executor = Executors.newFixedThreadPool(parallelism);
        calls.clear();
        for (int i = 0; i < parallelism; i++) {
            calls.add(() -> {
                waitingQueueSubscriptionProcessor.distributeAvailableSeats(eventF);
                return null;
            });
        }
        executor.invokeAll(calls);
        executor.shutdown();
        while (!executor.awaitTermination(10, TimeUnit.MILLISECONDS)) {
        }
        List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId());
        assertEquals(2, subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count());
        assertTrue(subscriptions.stream().allMatch(w -> w.getStatus().equals(WaitingQueueSubscription.Status.PENDING)));
        assertTrue(subscriptions.stream().allMatch(w -> w.getSubscriptionType().equals(WaitingQueueSubscription.Type.PRE_SALES)));
    } finally {
        if (event != null) {
            eventManager.deleteEvent(event.getId(), UserManager.ADMIN_USERNAME);
        }
        configurationManager.deleteKey(ConfigurationKeys.ENABLE_PRE_REGISTRATION.name());
        configurationManager.deleteKey(ConfigurationKeys.ENABLE_WAITING_QUEUE.name());
        removeAdminUser(userRepository, authorityRepository);
    }
}
Also used : java.util(java.util) WaitingQueueRepository(alfio.repository.WaitingQueueRepository) AlfioMetadata(alfio.model.metadata.AlfioMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) Callable(java.util.concurrent.Callable) ConfigurationManager(alfio.manager.system.ConfigurationManager) StringUtils(org.apache.commons.lang3.StringUtils) DateTimeModification(alfio.model.modification.DateTimeModification) BigDecimal(java.math.BigDecimal) Pair(org.apache.commons.lang3.tuple.Pair) LocalTime(java.time.LocalTime) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ExecutorService(java.util.concurrent.ExecutorService) AuthorityRepository(alfio.repository.user.AuthorityRepository) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) TicketRepository(alfio.repository.TicketRepository) CustomerName(alfio.model.CustomerName) EventRepository(alfio.repository.EventRepository) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) Executors(java.util.concurrent.Executors) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) TicketCategory(alfio.model.TicketCategory) WaitingQueueSubscription(alfio.model.WaitingQueueSubscription) Initializer(alfio.config.Initializer) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) UserRepository(alfio.repository.user.UserRepository) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) DataSourceConfiguration(alfio.config.DataSourceConfiguration) Event(alfio.model.Event) ClockProvider(alfio.util.ClockProvider) TestConfiguration(alfio.TestConfiguration) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Callable(java.util.concurrent.Callable) WaitingQueueSubscription(alfio.model.WaitingQueueSubscription) DateTimeModification(alfio.model.modification.DateTimeModification) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) ExecutorService(java.util.concurrent.ExecutorService) Event(alfio.model.Event) CustomerName(alfio.model.CustomerName) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

TestConfiguration (alfio.TestConfiguration)2 DataSourceConfiguration (alfio.config.DataSourceConfiguration)2 Initializer (alfio.config.Initializer)2 UserManager (alfio.manager.user.UserManager)2 AlfioMetadata (alfio.model.metadata.AlfioMetadata)2 EventRepository (alfio.repository.EventRepository)2 TicketRepository (alfio.repository.TicketRepository)2 ConfigurationRepository (alfio.repository.system.ConfigurationRepository)2 OrganizationRepository (alfio.repository.user.OrganizationRepository)2 IntegrationTestUtil (alfio.test.util.IntegrationTestUtil)2 ClockProvider (alfio.util.ClockProvider)2 BigDecimal (java.math.BigDecimal)2 LocalDate (java.time.LocalDate)2 LocalTime (java.time.LocalTime)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 Test (org.junit.jupiter.api.Test)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2