Search in sources :

Example 1 with ExternalPaymentProviderPlugin

use of org.killbill.billing.payment.provider.ExternalPaymentProviderPlugin in project killbill by killbill.

the class TestPaymentMethodProcessorNoDB method testGetExternalPaymentProviderPlugin.

@Test(groups = "fast")
public void testGetExternalPaymentProviderPlugin() throws Exception {
    final Iterable<PluginProperty> properties = ImmutableList.<PluginProperty>of();
    final UUID accountId = UUID.randomUUID();
    final Account account = Mockito.mock(Account.class);
    Mockito.when(account.getId()).thenReturn(accountId);
    Mockito.when(account.getExternalKey()).thenReturn(accountId.toString());
    Assert.assertEquals(paymentMethodProcessor.getPaymentMethods(false, properties, internalCallContext).size(), 0);
    // The first call should create the payment method
    final ExternalPaymentProviderPlugin providerPlugin = paymentMethodProcessor.createPaymentMethodAndGetExternalPaymentProviderPlugin(UUID.randomUUID().toString(), account, properties, callContext, internalCallContext);
    final List<PaymentMethod> paymentMethods = paymentMethodProcessor.getPaymentMethods(false, properties, internalCallContext);
    Assert.assertEquals(paymentMethods.size(), 1);
    Assert.assertEquals(paymentMethods.get(0).getPluginName(), ExternalPaymentProviderPlugin.PLUGIN_NAME);
    Assert.assertEquals(paymentMethods.get(0).getAccountId(), account.getId());
    // The succeeding calls should not create any other payment method
    final UUID externalPaymentMethodId = paymentMethods.get(0).getId();
    for (int i = 0; i < 50; i++) {
        final ExternalPaymentProviderPlugin foundProviderPlugin = paymentMethodProcessor.createPaymentMethodAndGetExternalPaymentProviderPlugin(UUID.randomUUID().toString(), account, properties, callContext, internalCallContext);
        Assert.assertNotNull(foundProviderPlugin);
        final List<PaymentMethod> foundPaymentMethods = paymentMethodProcessor.getPaymentMethods(false, properties, internalCallContext);
        Assert.assertEquals(foundPaymentMethods.size(), 1);
        Assert.assertEquals(foundPaymentMethods.get(0).getPluginName(), ExternalPaymentProviderPlugin.PLUGIN_NAME);
        Assert.assertEquals(foundPaymentMethods.get(0).getAccountId(), account.getId());
        Assert.assertEquals(foundPaymentMethods.get(0).getId(), externalPaymentMethodId);
    }
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Account(org.killbill.billing.account.api.Account) PaymentMethod(org.killbill.billing.payment.api.PaymentMethod) UUID(java.util.UUID) ExternalPaymentProviderPlugin(org.killbill.billing.payment.provider.ExternalPaymentProviderPlugin) Test(org.testng.annotations.Test)

Aggregations

UUID (java.util.UUID)1 Account (org.killbill.billing.account.api.Account)1 PaymentMethod (org.killbill.billing.payment.api.PaymentMethod)1 PluginProperty (org.killbill.billing.payment.api.PluginProperty)1 ExternalPaymentProviderPlugin (org.killbill.billing.payment.provider.ExternalPaymentProviderPlugin)1 Test (org.testng.annotations.Test)1