Search in sources :

Example 1 with MessageSourceManager

use of alfio.manager.i18n.MessageSourceManager in project alf.io by alfio-event.

the class TicketReservationManagerTest method init.

@BeforeEach
void init() {
    notificationManager = mock(NotificationManager.class);
    messageSource = mock(MessageSource.class);
    messageSourceManager = mock(MessageSourceManager.class);
    ticketReservationRepository = mock(TicketReservationRepository.class);
    ticketFieldRepository = mock(TicketFieldRepository.class);
    configurationManager = mock(ConfigurationManager.class);
    eventRepository = mock(EventRepository.class);
    organizationRepository = mock(OrganizationRepository.class);
    ticketRepository = mock(TicketRepository.class);
    ticketCategoryRepository = mock(TicketCategoryRepository.class);
    ticketCategoryDescriptionRepository = mock(TicketCategoryDescriptionRepository.class);
    paymentManager = mock(PaymentManager.class);
    promoCodeDiscountRepository = mock(PromoCodeDiscountRepository.class);
    specialPriceRepository = mock(SpecialPriceRepository.class);
    transactionRepository = mock(TransactionRepository.class);
    TemplateManager templateManager = mock(TemplateManager.class);
    PlatformTransactionManager transactionManager = mock(PlatformTransactionManager.class);
    waitingQueueManager = mock(WaitingQueueManager.class);
    AdditionalServiceRepository additionalServiceRepository = mock(AdditionalServiceRepository.class);
    AdditionalServiceTextRepository additionalServiceTextRepository = mock(AdditionalServiceTextRepository.class);
    AdditionalServiceItemRepository additionalServiceItemRepository = mock(AdditionalServiceItemRepository.class);
    auditingRepository = mock(AuditingRepository.class);
    event = mock(Event.class);
    specialPrice = mock(SpecialPrice.class);
    ticketCategory = mock(TicketCategory.class);
    ticket = mock(Ticket.class);
    when(ticket.getCurrencyCode()).thenReturn("CHF");
    when(ticket.getVatStatus()).thenReturn(PriceContainer.VatStatus.NOT_INCLUDED);
    when(ticket.getCategoryId()).thenReturn(TICKET_CATEGORY_ID);
    jdbcTemplate = mock(NamedParameterJdbcTemplate.class);
    json = mock(Json.class);
    reservationModification = mock(TicketReservationWithOptionalCodeModification.class);
    ticketReservation = mock(TicketReservation.class);
    when(ticketReservation.getStatus()).thenReturn(PENDING);
    when(ticketReservation.getUserLanguage()).thenReturn("en");
    when(ticketReservation.getId()).thenReturn(RESERVATION_ID);
    when(ticketReservation.getSrcPriceCts()).thenReturn(100);
    when(ticketReservation.getFinalPriceCts()).thenReturn(100);
    when(ticketReservation.getVatCts()).thenReturn(0);
    when(ticketReservation.getDiscountCts()).thenReturn(0);
    when(ticketReservation.getCurrencyCode()).thenReturn(EVENT_CURRENCY);
    when(ticketReservationRepository.findReservationByIdForUpdate(RESERVATION_ID)).thenReturn(ticketReservation);
    when(ticketReservationRepository.findReservationById(RESERVATION_ID)).thenReturn(ticketReservation);
    when(ticketReservationRepository.getAdditionalInfo(any())).thenReturn(mock(TicketReservationAdditionalInfo.class));
    organization = new Organization(ORGANIZATION_ID, "org", "desc", ORG_EMAIL, null, null);
    TicketSearchRepository ticketSearchRepository = mock(TicketSearchRepository.class);
    GroupManager groupManager = mock(GroupManager.class);
    userRepository = mock(UserRepository.class);
    ExtensionManager extensionManager = mock(ExtensionManager.class);
    billingDocumentRepository = mock(BillingDocumentRepository.class);
    when(ticketCategoryRepository.getByIdAndActive(anyInt(), eq(EVENT_ID))).thenReturn(ticketCategory);
    when(ticketCategoryRepository.getByIdsAndActive(anyCollection(), eq(EVENT_ID))).thenReturn(List.of(ticketCategory));
    when(ticketCategory.getName()).thenReturn("Category Name");
    when(ticketCategory.getCurrencyCode()).thenReturn(CATEGORY_CURRENCY);
    when(configurationManager.getFor(eq(VAT_NR), any())).thenReturn(new MaybeConfiguration(VAT_NR));
    when(messageSourceManager.getMessageSourceFor(any())).thenReturn(messageSource);
    when(messageSourceManager.getRootMessageSource()).thenReturn(messageSource);
    MaybeConfiguration configuration = mock(MaybeConfiguration.class);
    when(configurationManager.getFor(eq(SEND_TICKETS_AUTOMATICALLY), any())).thenReturn(configuration);
    when(configuration.getValueAsBooleanOrDefault()).thenReturn(true);
    purchaseContextManager = mock(PurchaseContextManager.class);
    when(purchaseContextManager.findByReservationId(anyString())).thenReturn(Optional.of(event));
    billingDocumentManager = mock(BillingDocumentManager.class);
    trm = new TicketReservationManager(eventRepository, organizationRepository, ticketRepository, ticketReservationRepository, ticketCategoryRepository, ticketCategoryDescriptionRepository, configurationManager, paymentManager, promoCodeDiscountRepository, specialPriceRepository, transactionRepository, notificationManager, messageSourceManager, templateManager, transactionManager, waitingQueueManager, ticketFieldRepository, additionalServiceRepository, additionalServiceItemRepository, additionalServiceTextRepository, auditingRepository, userRepository, extensionManager, ticketSearchRepository, groupManager, billingDocumentRepository, jdbcTemplate, json, billingDocumentManager, TestUtil.clockProvider(), purchaseContextManager, mock(SubscriptionRepository.class), mock(UserManager.class));
    when(event.getId()).thenReturn(EVENT_ID);
    when(event.getOrganizationId()).thenReturn(ORGANIZATION_ID);
    when(event.mustUseFirstAndLastName()).thenReturn(false);
    when(event.getCurrency()).thenReturn(EVENT_CURRENCY);
    when(event.now(any(ClockProvider.class))).thenReturn(ZonedDateTime.now(ClockProvider.clock()));
    when(event.now(any(Clock.class))).thenReturn(ZonedDateTime.now(ClockProvider.clock()));
    when(event.event()).thenReturn(Optional.of(event));
    when(event.getType()).thenReturn(PurchaseContext.PurchaseContextType.event);
    when(event.ofType(eq(PurchaseContext.PurchaseContextType.event))).thenReturn(true);
    when(ticketCategoryRepository.getByIdAndActive(eq(TICKET_CATEGORY_ID), eq(EVENT_ID))).thenReturn(ticketCategory);
    when(specialPrice.getCode()).thenReturn(SPECIAL_PRICE_CODE);
    when(specialPrice.getId()).thenReturn(SPECIAL_PRICE_ID);
    when(eventRepository.findByReservationId(eq(RESERVATION_ID))).thenReturn(event);
    when(eventRepository.findAll()).thenReturn(Collections.singletonList(event));
    var baseUrlConf = new MaybeConfiguration(ConfigurationKeys.BASE_URL, new ConfigurationKeyValuePathLevel(null, BASE_URL, null));
    when(configurationManager.baseUrl(any())).thenReturn(StringUtils.removeEnd(BASE_URL, "/"));
    when(configurationManager.getForSystem(ConfigurationKeys.BASE_URL)).thenReturn(baseUrlConf);
    when(configurationManager.getFor(eq(ConfigurationKeys.BASE_URL), any())).thenReturn(baseUrlConf);
    when(configurationManager.hasAllConfigurationsForInvoice(eq(event))).thenReturn(false);
    when(ticketReservationRepository.findReservationByIdForUpdate(RESERVATION_ID)).thenReturn(ticketReservation);
    when(ticket.getId()).thenReturn(TICKET_ID);
    when(ticket.getSrcPriceCts()).thenReturn(10);
    when(ticketCategory.getId()).thenReturn(TICKET_CATEGORY_ID);
    when(organizationRepository.getById(eq(ORGANIZATION_ID))).thenReturn(organization);
    when(event.getZoneId()).thenReturn(ClockProvider.clock().getZone());
    when(event.getBegin()).thenReturn(ZonedDateTime.now(ClockProvider.clock()).plusDays(1));
    when(event.getVatStatus()).thenReturn(PriceContainer.VatStatus.NOT_INCLUDED);
    when(userRepository.findIdByUserName(anyString())).thenReturn(Optional.empty());
    when(extensionManager.handleInvoiceGeneration(any(), any(), any(), anyMap())).thenReturn(Optional.empty());
    when(messageSource.getMessage(eq("ticket-has-changed-owner-subject"), any(), any())).thenReturn("subject");
    when(messageSource.getMessage(eq("reminder.ticket-not-assigned.subject"), any(), any())).thenReturn("subject");
    when(billingDocumentRepository.insert(anyInt(), anyString(), anyString(), any(), anyString(), any(), anyInt())).thenReturn(new AffectedRowCountAndKey<>(1, 1L));
    totalPrice = mock(TotalPrice.class);
}
Also used : Organization(alfio.model.user.Organization) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) OrganizationRepository(alfio.repository.user.OrganizationRepository) ConfigurationKeyValuePathLevel(alfio.model.system.ConfigurationKeyValuePathLevel) MaybeConfiguration(alfio.manager.system.ConfigurationManager.MaybeConfiguration) UserRepository(alfio.repository.user.UserRepository) ConfigurationManager(alfio.manager.system.ConfigurationManager) MessageSource(org.springframework.context.MessageSource) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) TicketReservationWithOptionalCodeModification(alfio.model.modification.TicketReservationWithOptionalCodeModification) MessageSourceManager(alfio.manager.i18n.MessageSourceManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MessageSourceManager (alfio.manager.i18n.MessageSourceManager)1 ConfigurationManager (alfio.manager.system.ConfigurationManager)1 MaybeConfiguration (alfio.manager.system.ConfigurationManager.MaybeConfiguration)1 TicketReservationWithOptionalCodeModification (alfio.model.modification.TicketReservationWithOptionalCodeModification)1 ConfigurationKeyValuePathLevel (alfio.model.system.ConfigurationKeyValuePathLevel)1 Organization (alfio.model.user.Organization)1 OrganizationRepository (alfio.repository.user.OrganizationRepository)1 UserRepository (alfio.repository.user.UserRepository)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 MessageSource (org.springframework.context.MessageSource)1 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)1 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)1