Search in sources :

Example 1 with PaymentMethodDTO

use of alfio.manager.PaymentManager.PaymentMethodDTO in project alf.io by alfio-event.

the class TicketReservationManagerTest method testValidatePaymentMethodsAllBlacklisted.

@Test
void testValidatePaymentMethodsAllBlacklisted() {
    when(totalPrice.requiresPayment()).thenReturn(true);
    when(ticketRepository.getCategoriesIdToPayInReservation(RESERVATION_ID)).thenReturn(List.of(1));
    when(configurationManager.getBlacklistedMethodsForReservation(eq(event), any())).thenReturn(new ArrayList<>(EnumSet.complementOf(EnumSet.of(PaymentMethod.NONE))));
    when(paymentManager.getPaymentMethods(eq(event), any())).thenReturn(Arrays.stream(PaymentProxy.values()).map(pp -> new PaymentMethodDTO(pp, pp.getPaymentMethod(), PaymentMethodStatus.ACTIVE)).collect(Collectors.toList()));
    Assertions.assertFalse(trm.canProceedWithPayment(event, totalPrice, RESERVATION_ID));
}
Also used : PaymentMethodDTO(alfio.manager.PaymentManager.PaymentMethodDTO) Test(org.junit.jupiter.api.Test)

Example 2 with PaymentMethodDTO

use of alfio.manager.PaymentManager.PaymentMethodDTO in project alf.io by alfio-event.

the class TicketReservationManagerTest method testValidatePaymentMethodsPartiallyAllowed.

@Test
void testValidatePaymentMethodsPartiallyAllowed() {
    when(totalPrice.requiresPayment()).thenReturn(true);
    when(ticketRepository.getCategoriesIdToPayInReservation(RESERVATION_ID)).thenReturn(List.of(1, 2));
    when(configurationManager.getBlacklistedMethodsForReservation(eq(event), any())).thenReturn(List.of(PaymentMethod.CREDIT_CARD));
    when(paymentManager.getPaymentMethods(eq(event), any())).thenReturn(Arrays.stream(PaymentProxy.values()).map(pp -> new PaymentMethodDTO(pp, pp.getPaymentMethod(), PaymentMethodStatus.ACTIVE)).collect(Collectors.toList()));
    Assertions.assertTrue(trm.canProceedWithPayment(event, totalPrice, RESERVATION_ID));
}
Also used : PaymentMethodDTO(alfio.manager.PaymentManager.PaymentMethodDTO) Test(org.junit.jupiter.api.Test)

Example 3 with PaymentMethodDTO

use of alfio.manager.PaymentManager.PaymentMethodDTO in project alf.io by alfio-event.

the class TicketReservationManagerTest method testValidatePaymentMethodsReservationFreeOfCharge.

@Test
void testValidatePaymentMethodsReservationFreeOfCharge() {
    when(totalPrice.requiresPayment()).thenReturn(false);
    when(configurationManager.getFor(eq(RESERVATION_TIMEOUT), any())).thenReturn(new MaybeConfiguration(RESERVATION_TIMEOUT));
    when(ticketRepository.getCategoriesIdToPayInReservation(RESERVATION_ID)).thenReturn(List.of(1));
    when(configurationManager.getBlacklistedMethodsForReservation(eq(event), any())).thenReturn(Arrays.asList(PaymentMethod.values()));
    when(paymentManager.getPaymentMethods(eq(event), any())).thenReturn(Arrays.stream(PaymentProxy.values()).map(pp -> new PaymentMethodDTO(pp, pp.getPaymentMethod(), PaymentMethodStatus.ACTIVE)).collect(Collectors.toList()));
    Assertions.assertTrue(trm.canProceedWithPayment(event, totalPrice, RESERVATION_ID));
}
Also used : PaymentMethodDTO(alfio.manager.PaymentManager.PaymentMethodDTO) MaybeConfiguration(alfio.manager.system.ConfigurationManager.MaybeConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with PaymentMethodDTO

use of alfio.manager.PaymentManager.PaymentMethodDTO in project alf.io by alfio-event.

the class TicketReservationManagerTest method testValidatePaymentMethodsPayPalError.

@Test
void testValidatePaymentMethodsPayPalError() {
    when(totalPrice.requiresPayment()).thenReturn(true);
    when(ticketRepository.getCategoriesIdToPayInReservation(RESERVATION_ID)).thenReturn(List.of(1));
    when(configurationManager.getBlacklistedMethodsForReservation(eq(event), any())).thenReturn(new ArrayList<>(EnumSet.complementOf(EnumSet.of(PaymentMethod.PAYPAL, PaymentMethod.NONE))));
    when(paymentManager.getPaymentMethods(eq(event), any())).thenReturn(Arrays.stream(PaymentProxy.values()).map(pp -> new PaymentMethodDTO(pp, pp.getPaymentMethod(), pp.getPaymentMethod() == PaymentMethod.PAYPAL ? PaymentMethodStatus.ERROR : PaymentMethodStatus.ACTIVE)).collect(Collectors.toList()));
    Assertions.assertFalse(trm.canProceedWithPayment(event, totalPrice, RESERVATION_ID));
}
Also used : PaymentMethodDTO(alfio.manager.PaymentManager.PaymentMethodDTO) Test(org.junit.jupiter.api.Test)

Example 5 with PaymentMethodDTO

use of alfio.manager.PaymentManager.PaymentMethodDTO in project alf.io by alfio-event.

the class TicketReservationManagerTest method testValidatePaymentMethodsAllowed.

@Test
void testValidatePaymentMethodsAllowed() {
    when(totalPrice.requiresPayment()).thenReturn(true);
    when(ticketRepository.getCategoriesIdToPayInReservation(RESERVATION_ID)).thenReturn(List.of(1));
    when(configurationManager.getBlacklistedMethodsForReservation(eq(event), any())).thenReturn(List.of());
    when(paymentManager.getPaymentMethods(eq(event), any())).thenReturn(Arrays.stream(PaymentProxy.values()).map(pp -> new PaymentMethodDTO(pp, pp.getPaymentMethod(), PaymentMethodStatus.ACTIVE)).collect(Collectors.toList()));
    Assertions.assertTrue(trm.canProceedWithPayment(event, totalPrice, RESERVATION_ID));
}
Also used : PaymentMethodDTO(alfio.manager.PaymentManager.PaymentMethodDTO) Test(org.junit.jupiter.api.Test)

Aggregations

PaymentMethodDTO (alfio.manager.PaymentManager.PaymentMethodDTO)5 Test (org.junit.jupiter.api.Test)5 MaybeConfiguration (alfio.manager.system.ConfigurationManager.MaybeConfiguration)1