Search in sources :

Example 21 with MaybeConfiguration

use of alfio.manager.system.ConfigurationManager.MaybeConfiguration in project alf.io by alfio-event.

the class TicketReservationManagerTest method sendAssignmentReminderBeforeEventEnd.

@Test
void sendAssignmentReminderBeforeEventEnd() {
    TicketReservation reservation = mock(TicketReservation.class);
    when(configurationManager.getFor(eq(ASSIGNMENT_REMINDER_START), any())).thenReturn(new MaybeConfiguration(ASSIGNMENT_REMINDER_START));
    when(configurationManager.getFor(eq(ASSIGNMENT_REMINDER_INTERVAL), any())).thenReturn(new MaybeConfiguration(ASSIGNMENT_REMINDER_INTERVAL));
    // when(configurationManager.getForSystem(any())).thenReturn(Optional.empty());
    when(configurationManager.getFor(eq(BANKING_KEY), any())).thenReturn(BANKING_INFO);
    when(reservation.latestNotificationTimestamp(any())).thenReturn(Optional.empty());
    when(reservation.getId()).thenReturn("abcd");
    when(reservation.getUserLanguage()).thenReturn("en");
    when(reservation.getEmail()).thenReturn("ciccio");
    when(reservation.getValidity()).thenReturn(new Date(Instant.now(ClockProvider.clock()).getEpochSecond()));
    when(ticketReservationRepository.findReservationById(eq("abcd"))).thenReturn(reservation);
    when(ticketReservationRepository.findOptionalReservationById(eq("abcd"))).thenReturn(Optional.of(reservation));
    when(eventRepository.findByReservationId("abcd")).thenReturn(event);
    when(eventRepository.findAll()).thenReturn(singletonList(event));
    when(ticketRepository.findAllReservationsConfirmedButNotAssignedForUpdate(anyInt())).thenReturn(singleton("abcd"));
    trm.sendReminderForTicketAssignment();
    verify(notificationManager, times(1)).sendSimpleEmail(eq(event), eq("abcd"), eq("ciccio"), anyString(), any(TemplateGenerator.class));
}
Also used : TemplateGenerator(alfio.manager.support.TemplateGenerator) MaybeConfiguration(alfio.manager.system.ConfigurationManager.MaybeConfiguration) Test(org.junit.jupiter.api.Test)

Example 22 with MaybeConfiguration

use of alfio.manager.system.ConfigurationManager.MaybeConfiguration in project alf.io by alfio-event.

the class StripeWebhookPaymentManagerTest method stripeConfigurationIncompletePlatformModeOff.

@Test
void stripeConfigurationIncompletePlatformModeOff() {
    var configuration = new HashMap<>(completeStripeConfiguration(true));
    // missing config
    configuration.put(STRIPE_CONNECTED_ID, new MaybeConfiguration(STRIPE_CONNECTED_ID));
    configuration.put(PLATFORM_MODE_ENABLED, new MaybeConfiguration(PLATFORM_MODE_ENABLED));
    configuration.put(STRIPE_WEBHOOK_PAYMENT_KEY, new MaybeConfiguration(STRIPE_WEBHOOK_PAYMENT_KEY));
    var configurationLevel = ConfigurationLevel.organization(1);
    when(configurationManager.getFor(EnumSet.of(STRIPE_ENABLE_SCA, BASE_URL, STRIPE_WEBHOOK_PAYMENT_KEY, STRIPE_CC_ENABLED, PLATFORM_MODE_ENABLED, STRIPE_CONNECTED_ID), configurationLevel)).thenReturn(configuration);
    assertFalse(stripeWebhookPaymentManager.accept(PaymentMethod.CREDIT_CARD, new PaymentContext(null, configurationLevel), TransactionRequest.empty()));
}
Also used : MaybeConfiguration(alfio.manager.system.ConfigurationManager.MaybeConfiguration) Test(org.junit.jupiter.api.Test)

Example 23 with MaybeConfiguration

use of alfio.manager.system.ConfigurationManager.MaybeConfiguration in project alf.io by alfio-event.

the class StripeWebhookPaymentManagerTest method doNotConsiderConnectedIdIfConfigurationLevelIsSystem.

@Test
void doNotConsiderConnectedIdIfConfigurationLevelIsSystem() {
    var configuration = new HashMap<>(completeStripeConfiguration(true));
    // missing config
    configuration.put(STRIPE_CONNECTED_ID, new MaybeConfiguration(STRIPE_CONNECTED_ID));
    var configurationLevel = ConfigurationLevel.system();
    when(configurationManager.getFor(EnumSet.of(STRIPE_ENABLE_SCA, BASE_URL, STRIPE_WEBHOOK_PAYMENT_KEY, STRIPE_CC_ENABLED, PLATFORM_MODE_ENABLED, STRIPE_CONNECTED_ID), configurationLevel)).thenReturn(configuration);
    assertTrue(stripeWebhookPaymentManager.accept(PaymentMethod.CREDIT_CARD, new PaymentContext(null, configurationLevel), TransactionRequest.empty()));
}
Also used : MaybeConfiguration(alfio.manager.system.ConfigurationManager.MaybeConfiguration) Test(org.junit.jupiter.api.Test)

Example 24 with MaybeConfiguration

use of alfio.manager.system.ConfigurationManager.MaybeConfiguration in project alf.io by alfio-event.

the class TicketReservationManagerTest method considerZoneIdWhileCheckingExpired.

@Test
void considerZoneIdWhileCheckingExpired() {
    TicketReservation reservation = mock(TicketReservation.class);
    when(configurationManager.getFor(eq(ASSIGNMENT_REMINDER_START), any())).thenReturn(new MaybeConfiguration(ASSIGNMENT_REMINDER_START));
    // when(configurationManager.getStringConfigValue(any())).thenReturn(Optional.empty());
    when(reservation.latestNotificationTimestamp(any())).thenReturn(Optional.empty());
    when(reservation.getId()).thenReturn("abcd");
    when(ticketReservationRepository.findReservationById(eq("abcd"))).thenReturn(reservation);
    when(eventRepository.findByReservationId("abcd")).thenReturn(event);
    when(event.getZoneId()).thenReturn(ZoneId.of("UTC-8"));
    // same day
    when(event.getBegin()).thenReturn(ZonedDateTime.now(ZoneId.of("UTC-8")));
    when(eventRepository.findAll()).thenReturn(singletonList(event));
    when(ticketRepository.findAllReservationsConfirmedButNotAssignedForUpdate(anyInt())).thenReturn(singleton("abcd"));
    trm.sendReminderForTicketAssignment();
    verify(notificationManager, never()).sendSimpleEmail(eq(event), anyString(), anyString(), anyString(), any(TemplateGenerator.class));
}
Also used : TemplateGenerator(alfio.manager.support.TemplateGenerator) MaybeConfiguration(alfio.manager.system.ConfigurationManager.MaybeConfiguration) Test(org.junit.jupiter.api.Test)

Example 25 with MaybeConfiguration

use of alfio.manager.system.ConfigurationManager.MaybeConfiguration in project alf.io by alfio-event.

the class DeferredBankTransferManagerTest method acceptPaymentRequest.

@Test
void acceptPaymentRequest() {
    var paymentContext = new PaymentContext(event);
    when(bankTransferManager.options(paymentContext)).thenReturn(Map.of(DEFERRED_BANK_TRANSFER_ENABLED, new MaybeConfiguration(DEFERRED_BANK_TRANSFER_ENABLED, new ConfigurationKeyValuePathLevel(DEFERRED_BANK_TRANSFER_ENABLED.name(), "true", null))));
    when(bankTransferManager.bankTransferEnabledForMethod(any(), eq(paymentContext), anyMap())).thenReturn(true);
    when(bankTransferManager.isPaymentDeferredEnabled(anyMap())).thenCallRealMethod();
    assertTrue(deferredBankTransferManager.accept(PaymentMethod.BANK_TRANSFER, paymentContext, TransactionRequest.empty()));
    assertFalse(deferredBankTransferManager.accept(PaymentMethod.BANK_TRANSFER, new PaymentContext(), TransactionRequest.empty()));
}
Also used : ConfigurationKeyValuePathLevel(alfio.model.system.ConfigurationKeyValuePathLevel) MaybeConfiguration(alfio.manager.system.ConfigurationManager.MaybeConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

MaybeConfiguration (alfio.manager.system.ConfigurationManager.MaybeConfiguration)25 Test (org.junit.jupiter.api.Test)21 TemplateGenerator (alfio.manager.support.TemplateGenerator)8 ConfigurationKeyValuePathLevel (alfio.model.system.ConfigurationKeyValuePathLevel)7 PaymentResult (alfio.manager.support.PaymentResult)2 ConfigurationManager (alfio.manager.system.ConfigurationManager)2 StripeCreditCardToken (alfio.model.transaction.token.StripeCreditCardToken)2 Organization (alfio.model.user.Organization)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 PaymentMethodDTO (alfio.manager.PaymentManager.PaymentMethodDTO)1 MessageSourceManager (alfio.manager.i18n.MessageSourceManager)1 EventAndOrganizationId (alfio.model.EventAndOrganizationId)1 TicketReservationWithOptionalCodeModification (alfio.model.modification.TicketReservationWithOptionalCodeModification)1 OrganizationRepository (alfio.repository.user.OrganizationRepository)1 UserRepository (alfio.repository.user.UserRepository)1 MessageSource (org.springframework.context.MessageSource)1 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)1 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)1