diff --git a/payment/src/test/java/org/killbill/billing/payment/api/TestExternalPaymentPlugin.java b/payment/src/test/java/org/killbill/billing/payment/api/TestExternalPaymentPlugin.java
new file mode 100644
index 0000000..d1d9278
--- /dev/null
+++ b/payment/src/test/java/org/killbill/billing/payment/api/TestExternalPaymentPlugin.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2014-2015 The Billing Project, LLC
+ *
+ * The Billing Project licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.killbill.billing.payment.api;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.UUID;
+
+import org.killbill.billing.account.api.Account;
+import org.killbill.billing.catalog.api.Currency;
+import org.killbill.billing.payment.PaymentTestSuiteWithEmbeddedDB;
+import org.killbill.billing.payment.invoice.InvoicePaymentControlPluginApi;
+import org.killbill.billing.payment.plugin.api.PaymentPluginApiException;
+import org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin;
+import org.killbill.billing.payment.provider.ExternalPaymentProviderPlugin;
+import org.killbill.billing.util.entity.Pagination;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class TestExternalPaymentPlugin extends PaymentTestSuiteWithEmbeddedDB {
+
+ private ExternalPaymentProviderPlugin plugin;
+
+ final PaymentOptions INVOICE_PAYMENT = new PaymentOptions() {
+ @Override
+ public boolean isExternalPayment() {
+ return false;
+ }
+
+ @Override
+ public List<String> getPaymentControlPluginNames() {
+ return ImmutableList.<String>of(InvoicePaymentControlPluginApi.PLUGIN_NAME);
+ }
+ };
+
+ private Account account;
+
+ @BeforeClass(groups = "slow")
+ protected void beforeClass() throws Exception {
+ super.beforeClass();
+ plugin = (ExternalPaymentProviderPlugin) registry.getServiceForName(ExternalPaymentProviderPlugin.PLUGIN_NAME);
+ }
+
+ @BeforeMethod(groups = "slow")
+ public void beforeMethod() throws Exception {
+ super.beforeMethod();
+ account = testHelper.createTestAccount("bob@gmail.com", false);
+ account = testHelper.addTestExternalPaymentMethod(account, new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), true, null));
+ }
+
+ @Test(groups = "slow")
+ public void testGetPaymentInfoWithAndWithoutPluginInfo() throws PaymentApiException, PaymentPluginApiException {
+
+ final BigDecimal requestedAmount = BigDecimal.TEN;
+
+ final String paymentExternalKey = "externalKey";
+ final String transactionExternalKey = "transactionKey";
+
+ final Payment payment = paymentApi.createPurchase(account, account.getPaymentMethodId(), null, requestedAmount, Currency.AED, paymentExternalKey, transactionExternalKey,
+ ImmutableList.<PluginProperty>of(), callContext);
+
+ final Payment paymentPluginInfoFalse = paymentApi.getPayment(payment.getId(), false, ImmutableList.<PluginProperty>of(), callContext);
+ final Payment paymentPluginInfoTrue = paymentApi.getPayment(payment.getId(), true, ImmutableList.<PluginProperty>of(), callContext);
+
+ Assert.assertEquals(paymentPluginInfoFalse.getAccountId(), paymentPluginInfoTrue.getAccountId());
+
+ Assert.assertEquals(paymentPluginInfoFalse.getTransactions().size(), paymentPluginInfoTrue.getTransactions().size());
+ Assert.assertEquals(paymentPluginInfoFalse.getExternalKey(), paymentPluginInfoTrue.getExternalKey());
+ Assert.assertEquals(paymentPluginInfoFalse.getPaymentMethodId(), paymentPluginInfoTrue.getPaymentMethodId());
+ Assert.assertEquals(paymentPluginInfoFalse.getAccountId(), paymentPluginInfoTrue.getAccountId());
+ Assert.assertEquals(paymentPluginInfoFalse.getAuthAmount().compareTo(paymentPluginInfoTrue.getAuthAmount()), 0);
+ Assert.assertEquals(paymentPluginInfoFalse.getCapturedAmount().compareTo(paymentPluginInfoTrue.getCapturedAmount()), 0);
+ Assert.assertEquals(paymentPluginInfoFalse.getPurchasedAmount().compareTo(paymentPluginInfoTrue.getPurchasedAmount()), 0);
+ Assert.assertEquals(paymentPluginInfoFalse.getRefundedAmount().compareTo(paymentPluginInfoTrue.getRefundedAmount()), 0);
+ Assert.assertEquals(paymentPluginInfoFalse.getCurrency(), paymentPluginInfoTrue.getCurrency());
+
+ for (int i = 0; i < paymentPluginInfoFalse.getTransactions().size(); i++) {
+ final PaymentTransaction noPluginInfoPaymentTransaction = paymentPluginInfoFalse.getTransactions().get(i);
+ final PaymentTransaction paymentTransaction = paymentPluginInfoTrue.getTransactions().get(i);
+ Assert.assertEquals(noPluginInfoPaymentTransaction.getAmount().compareTo(paymentTransaction.getAmount()), 0);
+ Assert.assertEquals(noPluginInfoPaymentTransaction.getProcessedAmount().compareTo(paymentTransaction.getProcessedAmount()), 0);
+ Assert.assertEquals(noPluginInfoPaymentTransaction.getCurrency(), paymentTransaction.getCurrency());
+ Assert.assertEquals(noPluginInfoPaymentTransaction.getExternalKey(), paymentTransaction.getExternalKey());
+ Assert.assertEquals(noPluginInfoPaymentTransaction.getTransactionStatus(), paymentTransaction.getTransactionStatus());
+
+ Assert.assertNull(noPluginInfoPaymentTransaction.getPaymentInfoPlugin());
+ Assert.assertNull(paymentTransaction.getPaymentInfoPlugin());
+ }
+
+ }
+
+ @Test(groups = "slow")
+ public void testGetPaymentmethodsWithAndWithoutPluginInfo() throws PaymentApiException, PaymentPluginApiException {
+
+ final BigDecimal requestedAmount = BigDecimal.TEN;
+
+ final String paymentExternalKey = "externalKey";
+ final String transactionExternalKey = "transactionKey";
+
+ final Payment payment = paymentApi.createPurchase(account, account.getPaymentMethodId(), null, requestedAmount, Currency.AED, paymentExternalKey, transactionExternalKey,
+ ImmutableList.<PluginProperty>of(), callContext);
+
+ final Pagination<PaymentMethod> paymentMethods = paymentApi.getPaymentMethods(0L, 10L, false, null, callContext);
+ final Pagination<PaymentMethod> paymentMethodsPlugin = paymentApi.getPaymentMethods(0L, 10L, true, null,callContext);
+
+ Assert.assertTrue(paymentMethods.getTotalNbRecords() == 1);
+ Assert.assertTrue(paymentMethodsPlugin.getTotalNbRecords() == 1);
+
+ PaymentMethod paymentMethod = paymentMethods.iterator().next();
+ PaymentMethod paymentMethodPlugin = paymentMethodsPlugin.iterator().next();
+
+ Assert.assertEquals(paymentMethod.getAccountId(), paymentMethodPlugin.getAccountId());
+ Assert.assertEquals(paymentMethod.getId(), paymentMethodPlugin.getId());
+ Assert.assertEquals(paymentMethod.getExternalKey(), paymentMethodPlugin.getExternalKey());
+ Assert.assertEquals(paymentMethod.getPluginName(), paymentMethodPlugin.getPluginName());
+
+ Assert.assertNull(paymentMethod.getPluginDetail());
+ Assert.assertNotNull(paymentMethodPlugin.getPluginDetail());
+
+ }
+
+}
diff --git a/payment/src/test/java/org/killbill/billing/payment/TestPaymentHelper.java b/payment/src/test/java/org/killbill/billing/payment/TestPaymentHelper.java
index 2aaa167..eadb1f1 100644
--- a/payment/src/test/java/org/killbill/billing/payment/TestPaymentHelper.java
+++ b/payment/src/test/java/org/killbill/billing/payment/TestPaymentHelper.java
@@ -37,6 +37,7 @@ import org.killbill.billing.payment.api.PaymentApi;
import org.killbill.billing.payment.api.PaymentMethodPlugin;
import org.killbill.billing.payment.api.PluginProperty;
import org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin;
+import org.killbill.billing.payment.provider.ExternalPaymentProviderPlugin;
import org.killbill.billing.payment.provider.MockPaymentProviderPlugin;
import org.killbill.billing.util.callcontext.CallContext;
import org.killbill.bus.api.PersistentBus;
@@ -161,6 +162,17 @@ public class TestPaymentHelper {
}
}
+ public Account addTestExternalPaymentMethod(final Account account, final PaymentMethodPlugin paymentMethodInfo) throws Exception {
+ final UUID paymentMethodId = paymentApi.addPaymentMethod(account, paymentMethodInfo.getExternalPaymentMethodId(), ExternalPaymentProviderPlugin.PLUGIN_NAME, true, paymentMethodInfo, ImmutableList.<PluginProperty>of(), context);
+ if (isFastTest()) {
+ Mockito.when(account.getPaymentMethodId()).thenReturn(paymentMethodId);
+ return account;
+ } else {
+ // To reflect the payment method id change
+ return accountApi.getAccountById(account.getId(), context);
+ }
+ }
+
// Unfortunately, this helper is shared across fast and slow tests
private boolean isFastTest() {
return Mockito.mockingDetails(accountInternalApi).isMock();