Search in sources :

Example 6 with OrganizationRepository

use of alfio.repository.user.OrganizationRepository in project alf.io by alfio-event.

the class EventManagerIntegrationTest method testEventGenerationWithOverflow.

@Test(expected = IllegalArgumentException.class)
public void testEventGenerationWithOverflow() {
    List<TicketCategoryModification> categories = Arrays.asList(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), 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), new TicketCategoryModification(null, "default", 0, 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().noneMatch(t -> t.getCategoryId() == null));
}
Also used : alfio.repository(alfio.repository) java.util(java.util) BeforeClass(org.junit.BeforeClass) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) RepositoryConfiguration(alfio.config.RepositoryConfiguration) BigDecimal(java.math.BigDecimal) ErrorCode(alfio.model.result.ErrorCode) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Pair(org.apache.commons.lang3.tuple.Pair) LocalTime(java.time.LocalTime) OrganizationRepository(alfio.repository.user.OrganizationRepository) Test(org.junit.Test) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) ZoneId(java.time.ZoneId) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) DateUtils(org.apache.commons.lang3.time.DateUtils) Result(alfio.model.result.Result) TicketCategory(alfio.model.TicketCategory) Initializer(alfio.config.Initializer) Ticket(alfio.model.Ticket) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) DataSourceConfiguration(alfio.config.DataSourceConfiguration) Event(alfio.model.Event) TestConfiguration(alfio.TestConfiguration) Assert(org.junit.Assert) alfio.model.modification(alfio.model.modification) Transactional(org.springframework.transaction.annotation.Transactional) Ticket(alfio.model.Ticket) Event(alfio.model.Event) Test(org.junit.Test)

Example 7 with OrganizationRepository

use of alfio.repository.user.OrganizationRepository in project alf.io by alfio-event.

the class WaitingQueueProcessorIntegrationTest method testPreRegistration.

@Test
public void testPreRegistration() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now().plusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
    Event event = pair.getKey();
    waitingQueueManager.subscribe(event, new CustomerName("Giuseppe Garibaldi", "Giuseppe", "Garibaldi", event), "peppino@garibaldi.com", null, Locale.ENGLISH);
    waitingQueueManager.subscribe(event, new CustomerName("Nino Bixio", "Nino", "Bixio", event), "bixio@mille.org", null, Locale.ITALIAN);
    assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2);
    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
    assertEquals(18, ticketRepository.findFreeByEventId(event.getId()).size());
    TicketCategoryModification tcm = new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null);
    eventManager.insertCategory(event.getId(), tcm, pair.getValue());
    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
    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)));
}
Also used : java.util(java.util) BeforeClass(org.junit.BeforeClass) WaitingQueueRepository(alfio.repository.WaitingQueueRepository) TicketReservationRepository(alfio.repository.TicketReservationRepository) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ConfigurationManager(alfio.manager.system.ConfigurationManager) EventModification(alfio.model.modification.EventModification) StringUtils(org.apache.commons.lang3.StringUtils) DateTimeModification(alfio.model.modification.DateTimeModification) RepositoryConfiguration(alfio.config.RepositoryConfiguration) BigDecimal(java.math.BigDecimal) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Pair(org.apache.commons.lang3.tuple.Pair) LocalTime(java.time.LocalTime) AuthorityRepository(alfio.repository.user.AuthorityRepository) Before(org.junit.Before) DateTimeModification.fromZonedDateTime(alfio.model.modification.DateTimeModification.fromZonedDateTime) Collections.emptyMap(java.util.Collections.emptyMap) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) TicketRepository(alfio.repository.TicketRepository) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) EventRepository(alfio.repository.EventRepository) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) DateUtils(org.apache.commons.lang3.time.DateUtils) Initializer(alfio.config.Initializer) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) DataSourceConfiguration(alfio.config.DataSourceConfiguration) TestConfiguration(alfio.TestConfiguration) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) DateTimeModification(alfio.model.modification.DateTimeModification) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) Test(org.junit.Test)

Example 8 with OrganizationRepository

use of alfio.repository.user.OrganizationRepository 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());
}
Also used : alfio.repository(alfio.repository) IntStream(java.util.stream.IntStream) java.util(java.util) BeforeClass(org.junit.BeforeClass) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) Attendee(alfio.model.modification.AdminReservationModification.Attendee) RepositoryConfiguration(alfio.config.RepositoryConfiguration) BigDecimal(java.math.BigDecimal) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Pair(org.apache.commons.lang3.tuple.Pair) LocalTime(java.time.LocalTime) Triple(org.apache.commons.lang3.tuple.Triple) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketsInfo(alfio.model.modification.AdminReservationModification.TicketsInfo) Test(org.junit.Test) CustomerData(alfio.model.modification.AdminReservationModification.CustomerData) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) DateUtils(org.apache.commons.lang3.time.DateUtils) Result(alfio.model.result.Result) Collectors.toList(java.util.stream.Collectors.toList) Initializer(alfio.config.Initializer) alfio.model(alfio.model) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) DataSourceConfiguration(alfio.config.DataSourceConfiguration) Category(alfio.model.modification.AdminReservationModification.Category) TestConfiguration(alfio.TestConfiguration) Assert(org.junit.Assert) alfio.model.modification(alfio.model.modification) Transactional(org.springframework.transaction.annotation.Transactional) Category(alfio.model.modification.AdminReservationModification.Category) CustomerData(alfio.model.modification.AdminReservationModification.CustomerData) TicketsInfo(alfio.model.modification.AdminReservationModification.TicketsInfo) Attendee(alfio.model.modification.AdminReservationModification.Attendee) LocalDate(java.time.LocalDate) Collectors.toList(java.util.stream.Collectors.toList) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

TestConfiguration (alfio.TestConfiguration)8 DataSourceConfiguration (alfio.config.DataSourceConfiguration)8 Initializer (alfio.config.Initializer)8 RepositoryConfiguration (alfio.config.RepositoryConfiguration)8 UserManager (alfio.manager.user.UserManager)8 OrganizationRepository (alfio.repository.user.OrganizationRepository)8 IntegrationTestUtil (alfio.test.util.IntegrationTestUtil)8 BigDecimal (java.math.BigDecimal)8 LocalDate (java.time.LocalDate)8 LocalTime (java.time.LocalTime)8 java.util (java.util)8 DateUtils (org.apache.commons.lang3.time.DateUtils)8 Pair (org.apache.commons.lang3.tuple.Pair)8 BeforeClass (org.junit.BeforeClass)8 Test (org.junit.Test)8 RunWith (org.junit.runner.RunWith)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 ActiveProfiles (org.springframework.test.context.ActiveProfiles)8 ContextConfiguration (org.springframework.test.context.ContextConfiguration)8 SpringJUnit4ClassRunner (org.springframework.test.context.junit4.SpringJUnit4ClassRunner)8