killbill-aplcache

Changes

beatrix/pom.xml 1(+1 -0)

Details

beatrix/pom.xml 1(+1 -0)

diff --git a/beatrix/pom.xml b/beatrix/pom.xml
index ab4bd12..f1bf13e 100644
--- a/beatrix/pom.xml
+++ b/beatrix/pom.xml
@@ -201,6 +201,7 @@
                         <configuration>
                             <tasks>
                                 <copy file="${basedir}/../osgi-bundles/tests/beatrix/target/killbill-osgi-bundles-test-beatrix-${project.version}-jar-with-dependencies.jar" tofile="${basedir}/src/test/resources/killbill-osgi-bundles-test-beatrix-${project.version}-jar-with-dependencies.jar"/>
+                                <copy file="${basedir}/../osgi-bundles/tests/payment/target/killbill-osgi-bundles-test-payment-${project.version}-jar-with-dependencies.jar" tofile="${basedir}/src/test/resources/killbill-osgi-bundles-test-payment-${project.version}-jar-with-dependencies.jar"/>
                             </tasks>
                         </configuration>
                         <goals>
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixIntegrationModule.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixIntegrationModule.java
index 7399ddf..69fc92a 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixIntegrationModule.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixIntegrationModule.java
@@ -18,7 +18,6 @@ package com.ning.billing.beatrix.integration;
 
 import java.io.IOException;
 import java.net.URL;
-import java.util.Properties;
 import java.util.Set;
 
 import com.ning.billing.GuicyKillbillTestWithEmbeddedDBModule;
@@ -78,7 +77,10 @@ import static org.testng.Assert.assertNotNull;
 
 public class BeatrixIntegrationModule extends AbstractModule {
 
-    public static final String PLUGIN_NAME = "yoyo";
+    public static final String NON_OSGI_PLUGIN_NAME = "yoyo";
+
+    // Same name the osgi-payment-test plugin uses to register its service
+    public static final String OSGI_PLUGIN_NAME = "osgiPaymentPlugin";
 
     @Override
     protected void configure() {
@@ -133,7 +135,7 @@ public class BeatrixIntegrationModule extends AbstractModule {
 
         @Override
         protected void installPaymentProviderPlugins(final PaymentConfig config) {
-            install(new MockPaymentProviderPluginModule(PLUGIN_NAME, TestIntegrationBase.getClock()));
+            install(new MockPaymentProviderPluginModule(NON_OSGI_PLUGIN_NAME, TestIntegrationBase.getClock()));
         }
     }
 
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestBasicOSGIWithTestBundle.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestBasicOSGIWithTestBundle.java
index 120414e..9515c1d 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestBasicOSGIWithTestBundle.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestBasicOSGIWithTestBundle.java
@@ -93,7 +93,7 @@ public class TestBasicOSGIWithTestBundle extends TestOSGIBase {
         assertTor.assertPluginInitialized();
 
         // Create an account and expect test bundle listen to KB events and write the external name in its table
-        final Account account = createAccountWithPaymentMethod(getAccountData(1));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(1));
         assertTor.assertPluginReceievdAccountCreationEvent(account.getExternalKey());
 
         // Retrieve the PaymentPluginApi that the test bundle registered
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestOSGIIntegration.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestOSGIIntegration.java
index 2be1879..36fd2e5 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestOSGIIntegration.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestOSGIIntegration.java
@@ -16,15 +16,12 @@
 
 package com.ning.billing.beatrix.integration.osgi;
 
-import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
-import com.ning.billing.beatrix.integration.BeatrixIntegrationModule;
-
 public class TestOSGIIntegration extends TestOSGIBase {
 
     @Test(groups = "slow")
     public void testJRubyIntegration() throws Exception {
-        createAccountWithPaymentMethod(getAccountData(1));
+        createAccountWithNonOsgiPaymentMethod(getAccountData(1));
     }
 }
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestPaymentOSGIWithTestPaymentBundle.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestPaymentOSGIWithTestPaymentBundle.java
new file mode 100644
index 0000000..f80e292
--- /dev/null
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestPaymentOSGIWithTestPaymentBundle.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright 2010-2013 Ning, Inc.
+ *
+ * Ning 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 com.ning.billing.beatrix.integration.osgi;
+
+import java.math.BigDecimal;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.UUID;
+
+import javax.inject.Inject;
+
+import org.joda.time.LocalDate;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.ning.billing.account.api.Account;
+import com.ning.billing.account.api.AccountData;
+import com.ning.billing.api.TestApiListener.NextEvent;
+import com.ning.billing.beatrix.integration.BeatrixIntegrationModule;
+import com.ning.billing.beatrix.osgi.SetupBundleWithAssertion;
+import com.ning.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck;
+import com.ning.billing.beatrix.util.PaymentChecker.ExpectedPaymentCheck;
+import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.catalog.api.ProductCategory;
+import com.ning.billing.entitlement.api.user.Subscription;
+import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.invoice.api.Invoice;
+import com.ning.billing.invoice.api.InvoiceItemType;
+import com.ning.billing.osgi.api.OSGIServiceRegistration;
+import com.ning.billing.payment.api.PaymentStatus;
+import com.ning.billing.payment.plugin.api.PaymentPluginApi;
+import com.ning.billing.payment.plugin.api.PaymentPluginApiException;
+import com.ning.billing.payment.plugin.api.PaymentPluginApiWithTestControl;
+
+public class TestPaymentOSGIWithTestPaymentBundle extends TestOSGIBase {
+
+    private final String BUNDLE_TEST_RESOURCE = "killbill-osgi-bundles-test-payment";
+
+    @Inject
+    private OSGIServiceRegistration<PaymentPluginApi> paymentPluginApiOSGIServiceRegistration;
+
+    @BeforeClass(groups = "slow")
+    public void beforeClass() throws Exception {
+
+        super.beforeClass();
+
+        // This is extracted from surefire system configuration-- needs to be added explicitly in IntelliJ for correct running
+        final String killbillVersion = System.getProperty("killbill.version");
+        SetupBundleWithAssertion setupTest = new SetupBundleWithAssertion(BUNDLE_TEST_RESOURCE, osgiConfig, killbillVersion);
+        setupTest.setupBundle();
+
+    }
+
+    @BeforeMethod(groups = "slow")
+    public void beforeMethod() throws Exception {
+        super.beforeMethod();
+        getTestPluginPaymentApi().resetToNormalbehavior();
+    }
+
+    @Test(groups = "slow")
+    public void testBasicProcessPaymentOK() throws Exception {
+        final PaymentPluginApiWithTestControl paymentPluginApi = getTestPluginPaymentApi();
+        paymentPluginApi.processPayment(UUID.randomUUID(), UUID.randomUUID(), BigDecimal.TEN, callContext);
+    }
+
+    @Test(groups = "slow")
+    public void testBasicProcessPaymentWithPaymentPluginApiException() throws Exception {
+
+        boolean gotException = false;
+        try {
+            final PaymentPluginApiWithTestControl paymentPluginApi = getTestPluginPaymentApi();
+            final PaymentPluginApiException e = new PaymentPluginApiException("test-error", "foo");
+
+            paymentPluginApi.setPaymentPluginApiExceptionOnNextCalls(e);
+            paymentPluginApi.processPayment(UUID.randomUUID(), UUID.randomUUID(), BigDecimal.TEN, callContext);
+            Assert.fail("Expected to fail with " + e.toString());
+        } catch (PaymentPluginApiException e) {
+            gotException = true;
+        }
+        Assert.assertTrue(gotException);
+    }
+
+    @Test(groups = "slow")
+    public void testBasicProcessPaymentWithRuntimeException() throws Exception {
+
+        boolean gotException = false;
+        try {
+            final PaymentPluginApiWithTestControl paymentPluginApi = getTestPluginPaymentApi();
+            final RuntimeException e = new RuntimeException("test-error");
+
+            paymentPluginApi.setPaymentRuntimeExceptionOnNextCalls(e);
+            paymentPluginApi.processPayment(UUID.randomUUID(), UUID.randomUUID(), BigDecimal.TEN, callContext);
+            Assert.fail("Expected to fail with " + e.toString());
+        } catch (RuntimeException e) {
+            gotException = true;
+        }
+        Assert.assertTrue(gotException);
+    }
+
+
+    @Test(groups = "slow")
+    public void testIntegrationOK() throws Exception {
+        setupIntegration(null, null);
+    }
+
+    @Test(groups = "slow")
+    public void testIntegrationWithPaymentPluginApiException() throws Exception {
+        final PaymentPluginApiException e = new PaymentPluginApiException("test-error", "foo");
+        setupIntegration(e, null);
+    }
+
+    @Test(groups = "slow")
+    public void testIntegrationWithRuntimeException() throws Exception {
+        final RuntimeException e = new RuntimeException("test-error");
+        setupIntegration(null, e);
+    }
+
+
+    private void setupIntegration(final PaymentPluginApiException expectedException, final RuntimeException expectedRuntimeException) throws Exception {
+
+        final PaymentPluginApiWithTestControl paymentPluginApi = getTestPluginPaymentApi();
+
+        final AccountData accountData = getAccountData(1);
+        final Account account = createAccountWithOsgiPaymentMethod(accountData);
+
+        // We take april as it has 30 days (easier to play with BCD)
+        // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
+        clock.setDay(new LocalDate(2012, 4, 1));
+
+        final SubscriptionBundle bundle = entitlementUserApi.createBundleForAccount(account.getId(), "whatever", callContext);
+        //
+        // CREATE SUBSCRIPTION AND EXPECT BOTH EVENTS: NextEvent.CREATE NextEvent.INVOICE
+        //
+        final Subscription bpSubscription = createSubscriptionAndCheckForCompletion(bundle.getId(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.INVOICE);
+        //
+        // ADD ADD_ON ON THE SAME DAY TO TRIGGER PAYMENT
+        //
+
+        final List<NextEvent> expectedEvents = new LinkedList<NextEvent>();
+        expectedEvents.add(NextEvent.CREATE);
+        expectedEvents.add(NextEvent.INVOICE);
+        if (expectedException == null && expectedRuntimeException == null) {
+            expectedEvents.add(NextEvent.PAYMENT);
+        } else if (expectedException != null) {
+            paymentPluginApi.setPaymentPluginApiExceptionOnNextCalls(expectedException);
+        } else if (expectedRuntimeException != null) {
+            paymentPluginApi.setPaymentRuntimeExceptionOnNextCalls(expectedRuntimeException);
+
+        }
+
+        createSubscriptionAndCheckForCompletion(bundle.getId(), "Telescopic-Scope", ProductCategory.ADD_ON, BillingPeriod.MONTHLY, expectedEvents.toArray(new NextEvent[expectedEvents.size()]));
+        Invoice invoice = invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 4, 1), new LocalDate(2012, 5, 1), InvoiceItemType.RECURRING, new BigDecimal("399.95")));
+
+        if (expectedException == null && expectedRuntimeException == null) {
+            paymentChecker.checkPayment(account.getId(), 1, callContext, new ExpectedPaymentCheck(new LocalDate(2012, 4, 1), new BigDecimal("399.95"), PaymentStatus.SUCCESS, invoice.getId(), Currency.USD));
+        } else if (expectedException != null) {
+            paymentChecker.checkPayment(account.getId(), 1, callContext, new ExpectedPaymentCheck(new LocalDate(2012, 4, 1), new BigDecimal("399.95"), PaymentStatus.PLUGIN_FAILURE, invoice.getId(), Currency.USD));
+        } else if (expectedRuntimeException != null) {
+            paymentChecker.checkPayment(account.getId(), 1, callContext, new ExpectedPaymentCheck(new LocalDate(2012, 4, 1), new BigDecimal("399.95"), PaymentStatus.UNKNOWN, invoice.getId(), Currency.USD));
+        }
+    }
+
+
+    private PaymentPluginApiWithTestControl getTestPluginPaymentApi() {
+        PaymentPluginApiWithTestControl result = (PaymentPluginApiWithTestControl) paymentPluginApiOSGIServiceRegistration.getServiceForPluginName(BeatrixIntegrationModule.OSGI_PLUGIN_NAME);
+        Assert.assertNotNull(result);
+        return result;
+    }
+}
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestBillingAlignment.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestBillingAlignment.java
index c4984c9..1fecc27 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestBillingAlignment.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestBillingAlignment.java
@@ -19,12 +19,10 @@ package com.ning.billing.beatrix.integration.overdue;
 import java.math.BigDecimal;
 
 import org.joda.time.LocalDate;
-import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
 import com.ning.billing.account.api.Account;
 import com.ning.billing.api.TestApiListener.NextEvent;
-import com.ning.billing.beatrix.integration.BeatrixIntegrationModule;
 import com.ning.billing.beatrix.integration.TestIntegrationBase;
 import com.ning.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck;
 import com.ning.billing.catalog.api.BillingPeriod;
@@ -45,7 +43,7 @@ public class TestBillingAlignment extends TestIntegrationBase {
     @Test(groups = "slow", enabled = false)
     public void testTransitonAccountBAToSubscriptionBA() throws Exception {
 
-        final Account account = createAccountWithPaymentMethod(getAccountData(1));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(1));
 
         // We take april as it has 30 days (easier to play with BCD)
         // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueBase.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueBase.java
index a15bcd0..3594ec2 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueBase.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueBase.java
@@ -79,10 +79,10 @@ public abstract class TestOverdueBase extends TestIntegrationBase {
         final OverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class);
         overdueWrapperFactory.setOverdueConfig(config);
 
-        account = createAccountWithPaymentMethod(getAccountData(0));
+        account = createAccountWithNonOsgiPaymentMethod(getAccountData(0));
         assertNotNull(account);
 
-        paymentApi.addPaymentMethod(BeatrixIntegrationModule.PLUGIN_NAME, account, true, paymentMethodPlugin, callContext);
+        paymentApi.addPaymentMethod(BeatrixIntegrationModule.NON_OSGI_PLUGIN_NAME, account, true, paymentMethodPlugin, callContext);
 
         bundle = entitlementUserApi.createBundleForAccount(account.getId(), "whatever", callContext);
 
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java
index b66e107..5ad8c97 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java
@@ -21,7 +21,6 @@ import java.util.Collection;
 
 import org.joda.time.DateTime;
 import org.joda.time.LocalDate;
-import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
 import com.ning.billing.api.TestApiListener.NextEvent;
@@ -255,7 +254,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
         checkChangePlanWithOverdueState(baseSubscription, true);
 
         // Add a payment method and set it as default
-        paymentApi.addPaymentMethod(BeatrixIntegrationModule.PLUGIN_NAME, account, true, paymentMethodPlugin, callContext);
+        paymentApi.addPaymentMethod(BeatrixIntegrationModule.NON_OSGI_PLUGIN_NAME, account, true, paymentMethodPlugin, callContext);
 
         // Pay all invoices
         final Collection<Invoice> invoices = invoiceUserApi.getUnpaidInvoicesByAccountId(account.getId(), clock.getUTCToday(), callContext);
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestAnalytics.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestAnalytics.java
index f6863b4..a139e9e 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestAnalytics.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestAnalytics.java
@@ -27,7 +27,6 @@ import org.joda.time.LocalDate;
 import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
 import com.ning.billing.ObjectType;
@@ -251,7 +250,7 @@ public class TestAnalytics extends TestIntegrationBase {
         Assert.assertNull(invoicePaymentsForAccount.get(0).getExtFirstPaymentRefId());
         Assert.assertNull(invoicePaymentsForAccount.get(0).getExtSecondPaymentRefId());
         Assert.assertEquals(invoicePaymentsForAccount.get(0).getProcessingStatus(), PaymentStatus.PAYMENT_FAILURE.toString());
-        Assert.assertEquals(invoicePaymentsForAccount.get(0).getPluginName(), BeatrixIntegrationModule.PLUGIN_NAME);
+        Assert.assertEquals(invoicePaymentsForAccount.get(0).getPluginName(), BeatrixIntegrationModule.NON_OSGI_PLUGIN_NAME);
 
         // Verify the account object has been updated
         Assert.assertEquals(analyticsUserApi.getAccountByKey(account.getExternalKey(), callContext).getBalance(),
@@ -340,7 +339,7 @@ public class TestAnalytics extends TestIntegrationBase {
         Assert.assertNull(analyticsUserApi.getAccountByKey(accountData.getExternalKey(), callContext));
 
         // Create an account
-        final Account account = createAccountWithPaymentMethod(accountData);
+        final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
         Assert.assertNotNull(account);
 
         waitALittle();
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBundleTransfer.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBundleTransfer.java
index c27ac26..2c6b654 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBundleTransfer.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBundleTransfer.java
@@ -47,7 +47,7 @@ public class TestBundleTransfer extends TestIntegrationBase {
     @Test(groups = "slow")
     public void testBundleTransferWithBPAnnualOnly() throws Exception {
 
-        final Account account = createAccountWithPaymentMethod(getAccountData(3));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(3));
 
         // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
 
@@ -84,7 +84,7 @@ public class TestBundleTransfer extends TestIntegrationBase {
         assertListenerStatus();
 
         // BUNDLE TRANSFER
-        final Account newAccount = createAccountWithPaymentMethod(getAccountData(17));
+        final Account newAccount = createAccountWithNonOsgiPaymentMethod(getAccountData(17));
 
         busHandler.pushExpectedEvent(NextEvent.TRANSFER);
         busHandler.pushExpectedEvent(NextEvent.INVOICE);
@@ -107,7 +107,7 @@ public class TestBundleTransfer extends TestIntegrationBase {
     @Test(groups = "slow")
     public void testBundleTransferWithBPMonthlyOnly() throws Exception {
 
-        final Account account = createAccountWithPaymentMethod(getAccountData(0));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(0));
 
         // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
 
@@ -144,7 +144,7 @@ public class TestBundleTransfer extends TestIntegrationBase {
         assertListenerStatus();
 
         // BUNDLE TRANSFER
-        final Account newAccount = createAccountWithPaymentMethod(getAccountData(0));
+        final Account newAccount = createAccountWithNonOsgiPaymentMethod(getAccountData(0));
 
         busHandler.pushExpectedEvent(NextEvent.TRANSFER);
         busHandler.pushExpectedEvent(NextEvent.INVOICE);
@@ -174,7 +174,7 @@ public class TestBundleTransfer extends TestIntegrationBase {
     @Test(groups = "slow")
     public void testBundleTransferWithBPMonthlyOnlyWIthCancellationImm() throws Exception {
 
-        final Account account = createAccountWithPaymentMethod(getAccountData(9));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(9));
 
         // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
 
@@ -211,7 +211,7 @@ public class TestBundleTransfer extends TestIntegrationBase {
         assertListenerStatus();
 
         // BUNDLE TRANSFER
-        final Account newAccount = createAccountWithPaymentMethod(getAccountData(15));
+        final Account newAccount = createAccountWithNonOsgiPaymentMethod(getAccountData(15));
 
         busHandler.pushExpectedEvent(NextEvent.CANCEL);
         busHandler.pushExpectedEvent(NextEvent.TRANSFER);
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestEntitlement.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestEntitlement.java
index af1f885..adea394 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestEntitlement.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestEntitlement.java
@@ -49,7 +49,7 @@ public class TestEntitlement extends TestIntegrationBase {
     public void testForcePolicy() throws Exception {
         // We take april as it has 30 days (easier to play with BCD)
         final LocalDate today = new LocalDate(2012, 4, 1);
-        final Account account = createAccountWithPaymentMethod(getAccountData(1));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(1));
 
         // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
         clock.setDeltaFromReality(today.toDateTimeAtCurrentTime(DateTimeZone.UTC).getMillis() - clock.getUTCNow().getMillis());
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
index 7b50732..8453fd7 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
@@ -23,7 +23,6 @@ import java.util.UUID;
 import org.joda.time.DateTime;
 import org.joda.time.Interval;
 import org.joda.time.LocalDate;
-import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
 import com.ning.billing.account.api.Account;
@@ -54,7 +53,7 @@ public class TestIntegration extends TestIntegrationBase {
     public void testCancelBPWithAOTheSameDay() throws Exception {
 
         final AccountData accountData = getAccountData(1);
-        final Account account = createAccountWithPaymentMethod(accountData);
+        final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
         accountChecker.checkAccount(account.getId(), accountData, callContext);
 
         // We take april as it has 30 days (easier to play with BCD)
@@ -101,7 +100,7 @@ public class TestIntegration extends TestIntegrationBase {
         final DateTime initialCreationDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone);
 
         log.info("Beginning test with BCD of " + billingDay);
-        final Account account = createAccountWithPaymentMethod(getAccountData(billingDay));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
 
         // set clock to the initial start date
         clock.setTime(initialCreationDate);
@@ -183,7 +182,7 @@ public class TestIntegration extends TestIntegrationBase {
         final DateTime initialCreationDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone);
 
         log.info("Beginning test with BCD of " + billingDay);
-        final Account account = createAccountWithPaymentMethod(getAccountData(billingDay));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
 
         // set clock to the initial start date
         clock.setTime(initialCreationDate);
@@ -265,7 +264,7 @@ public class TestIntegration extends TestIntegrationBase {
         final DateTime initialCreationDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone);
 
         log.info("Beginning test with BCD of " + billingDay);
-        final Account account = createAccountWithPaymentMethod(getAccountData(billingDay));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
 
         // set clock to the initial start date
         clock.setTime(initialCreationDate);
@@ -398,7 +397,7 @@ public class TestIntegration extends TestIntegrationBase {
         final DateTime initialDate = new DateTime(2012, 4, 25, 0, 13, 42, 0, testTimeZone);
         clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
 
-        final Account account = createAccountWithPaymentMethod(getAccountData(25));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(25));
         assertNotNull(account);
 
         final SubscriptionBundle bundle = entitlementUserApi.createBundleForAccount(account.getId(), "whatever", callContext);
@@ -477,7 +476,7 @@ public class TestIntegration extends TestIntegrationBase {
 
         log.info("Starting testRepairForInvoicing");
 
-        final Account account = createAccountWithPaymentMethod(getAccountData(1));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(1));
         final UUID accountId = account.getId();
         assertNotNull(account);
 
@@ -510,7 +509,7 @@ public class TestIntegration extends TestIntegrationBase {
         final int billingDay = 2;
 
         log.info("Beginning test with BCD of " + billingDay);
-        final Account account = createAccountWithPaymentMethod(getAccountData(billingDay));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
         final UUID accountId = account.getId();
         assertNotNull(account);
 
@@ -582,7 +581,7 @@ public class TestIntegration extends TestIntegrationBase {
         final DateTime initialCreationDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone);
         clock.setDeltaFromReality(initialCreationDate.getMillis() - clock.getUTCNow().getMillis());
 
-        final Account account = createAccountWithPaymentMethod(getAccountData(2));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(2));
         final UUID accountId = account.getId();
 
         final String productName = "Blowdart";
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
index 0e19854..cbd4256 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
@@ -154,7 +154,7 @@ public class TestIntegrationBase extends BeatrixTestSuiteWithEmbeddedDB implemen
     @Inject
     protected PaymentApi paymentApi;
 
-    @Named(BeatrixIntegrationModule.PLUGIN_NAME)
+    @Named(BeatrixIntegrationModule.NON_OSGI_PLUGIN_NAME)
     @Inject
     protected MockPaymentProviderPlugin paymentPlugin;
 
@@ -306,7 +306,15 @@ public class TestIntegrationBase extends BeatrixTestSuiteWithEmbeddedDB implemen
         return (SubscriptionData) ((BlockingSubscription) sub).getDelegateSubscription();
     }
 
-    protected Account createAccountWithPaymentMethod(final AccountData accountData) throws Exception {
+    protected Account createAccountWithOsgiPaymentMethod(final AccountData accountData) throws Exception {
+        return createAccountWithPaymentMethod(accountData, BeatrixIntegrationModule.OSGI_PLUGIN_NAME);
+    }
+
+    protected Account createAccountWithNonOsgiPaymentMethod(final AccountData accountData) throws Exception {
+        return createAccountWithPaymentMethod(accountData, BeatrixIntegrationModule.NON_OSGI_PLUGIN_NAME);
+    }
+
+    private Account createAccountWithPaymentMethod(final AccountData accountData, final String paymentPluginName) throws Exception {
         final Account account = accountUserApi.createAccount(accountData, callContext);
         assertNotNull(account);
 
@@ -332,7 +340,7 @@ public class TestIntegrationBase extends BeatrixTestSuiteWithEmbeddedDB implemen
             }
         };
 
-        paymentApi.addPaymentMethod(BeatrixIntegrationModule.PLUGIN_NAME, account, true, info, callContext);
+        paymentApi.addPaymentMethod(paymentPluginName, account, true, info, callContext);
         return accountUserApi.getAccountById(account.getId(), callContext);
     }
 
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationWithAutoInvoiceOffTag.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationWithAutoInvoiceOffTag.java
index fa14d21..3fe7604 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationWithAutoInvoiceOffTag.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationWithAutoInvoiceOffTag.java
@@ -22,7 +22,6 @@ import java.util.UUID;
 
 import org.joda.time.DateTime;
 import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
 import com.ning.billing.ObjectType;
@@ -66,7 +65,7 @@ public class TestIntegrationWithAutoInvoiceOffTag extends TestIntegrationBase {
     @BeforeMethod(groups = {"slow"})
     public void beforeMethod() throws Exception {
         super.beforeMethod();
-        account = createAccountWithPaymentMethod(getAccountData(25));
+        account = createAccountWithNonOsgiPaymentMethod(getAccountData(25));
         assertNotNull(account);
 
         bundle = entitlementUserApi.createBundleForAccount(account.getId(), "whatever", callContext);
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationWithAutoPayOff.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationWithAutoPayOff.java
index bd07214..ae23993 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationWithAutoPayOff.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationWithAutoPayOff.java
@@ -22,7 +22,6 @@ import java.util.UUID;
 
 import org.joda.time.DateTime;
 import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
 import com.ning.billing.ObjectType;
@@ -73,7 +72,7 @@ public class TestIntegrationWithAutoPayOff extends TestIntegrationBase {
     @BeforeMethod(groups = {"slow"})
     public void beforeMethod() throws Exception {
         super.beforeMethod();
-        account = createAccountWithPaymentMethod(getAccountData(25));
+        account = createAccountWithNonOsgiPaymentMethod(getAccountData(25));
         assertNotNull(account);
 
         bundle = entitlementUserApi.createBundleForAccount(account.getId(), "whatever", callContext);
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPaymentRefund.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPaymentRefund.java
index 4afd2b8..f3e829b 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPaymentRefund.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPaymentRefund.java
@@ -26,7 +26,6 @@ import javax.annotation.Nullable;
 import org.joda.time.DateTime;
 import org.joda.time.LocalDate;
 import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
 import com.ning.billing.account.api.Account;
@@ -100,7 +99,7 @@ public class TestPaymentRefund extends TestIntegrationBase {
         final int billingDay = 31;
         initialCreationDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone);
 
-        account = createAccountWithPaymentMethod(getAccountData(billingDay));
+        account = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
 
         // set clock to the initial start date
         clock.setTime(initialCreationDate);
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPublicBus.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPublicBus.java
index db26e0c..a7349b9 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPublicBus.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPublicBus.java
@@ -22,7 +22,6 @@ import java.util.UUID;
 
 import org.joda.time.DateTime;
 import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
 import com.ning.billing.account.api.Account;
@@ -78,7 +77,7 @@ public class TestPublicBus extends TestIntegrationBase {
         final int billingDay = 2;
 
         log.info("Beginning test with BCD of " + billingDay);
-        final Account account = createAccountWithPaymentMethod(getAccountData(billingDay));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
         final UUID accountId = account.getId();
         assertNotNull(account);
 
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestRepairIntegration.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestRepairIntegration.java
index 170f015..59d4cae 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestRepairIntegration.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestRepairIntegration.java
@@ -24,7 +24,6 @@ import java.util.UUID;
 import org.joda.time.DateTime;
 import org.joda.time.Interval;
 import org.testng.Assert;
-import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
 import com.ning.billing.account.api.Account;
@@ -69,7 +68,7 @@ public class TestRepairIntegration extends TestIntegrationBase {
         final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
         clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
 
-        final Account account = createAccountWithPaymentMethod(getAccountData(25));
+        final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(25));
 
         final SubscriptionBundle bundle = entitlementUserApi.createBundleForAccount(account.getId(), "whatever", callContext);
 
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/util/PaymentChecker.java b/beatrix/src/test/java/com/ning/billing/beatrix/util/PaymentChecker.java
index 233679e..2763aed 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/util/PaymentChecker.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/util/PaymentChecker.java
@@ -53,7 +53,11 @@ public class PaymentChecker {
         final List<Payment> payments = paymentApi.getAccountPayments(accountId, context);
         Assert.assertEquals(payments.size(), paymentOrderingNumber);
         final Payment payment = payments.get(paymentOrderingNumber - 1);
-        checkPayment(accountId, payment, context, expected);
+        if (payment.getPaymentStatus() == PaymentStatus.UNKNOWN) {
+            checkPaymentNoAuditForRuntimeException(accountId, payment, context, expected);
+        } else {
+            checkPayment(accountId, payment, context, expected);
+        }
         return payment;
     }
 
@@ -66,6 +70,14 @@ public class PaymentChecker {
         auditChecker.checkPaymentCreated(payment, context);
     }
 
+    private void checkPaymentNoAuditForRuntimeException(final UUID accountId, final Payment payment, final CallContext context, final ExpectedPaymentCheck expected) {
+        Assert.assertEquals(payment.getAccountId(), accountId);
+        Assert.assertTrue(payment.getAmount().compareTo(expected.getAmount()) == 0);
+        Assert.assertEquals(payment.getPaymentStatus(),expected.getStatus());
+        Assert.assertEquals(payment.getInvoiceId(), expected.getInvoiceId());
+        Assert.assertEquals(payment.getCurrency(), expected.getCurrency());
+    }
+
     public static class ExpectedPaymentCheck {
 
         private final LocalDate paymentDate;
diff --git a/osgi-bundles/tests/payment/pom.xml b/osgi-bundles/tests/payment/pom.xml
new file mode 100644
index 0000000..c63ad49
--- /dev/null
+++ b/osgi-bundles/tests/payment/pom.xml
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2010-2013 Ning, Inc.
+  ~
+  ~ Ning 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.ning.billing</groupId>
+        <artifactId>killbill-osgi-test-bundles</artifactId>
+        <version>0.1.56-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <artifactId>killbill-osgi-bundles-test-payment</artifactId>
+    <name>Killbill billing platform: OSGI Beatrix Test payment</name>
+    <packaging>bundle</packaging>
+    <dependencies>
+        <dependency>
+            <groupId>com.ning.billing</groupId>
+            <artifactId>killbill-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.ning.billing</groupId>
+            <artifactId>killbill-osgi-bundles-lib-killbill</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>osgi-over-slf4j</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jdbi</groupId>
+            <artifactId>jdbi</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.ning.billing</groupId>
+            <artifactId>killbill-util</artifactId>
+            <type>test-jar</type>
+            <!-- Override the scope since we build this test as 'source' -->
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.testng</groupId>
+            <artifactId>testng</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <version>1.5</version>
+                <executions>
+                    <execution>
+                        <id>add-source</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>src/test/java</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-Activator>com.ning.billing.osgi.bundles.test.PaymentActivator</Bundle-Activator>
+                        <Import-Package>
+                            <!-- maven-bundle-plugin does not seem to detect that the library is using OSGIKillbill, this is annoying... -->
+                            *;resolution:=optional,com.ning.billing.osgi.api
+                        </Import-Package>
+                    </instructions>
+                </configuration>
+                <executions>
+                    <execution>
+                        <phase>process-classes</phase>
+                        <goals>
+                            <goal>manifest</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>assemble-killbill-osgi-bundles-test</id>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                        <phase>package</phase>
+                        <configuration>
+                            <shadedArtifactAttached>true</shadedArtifactAttached>
+                            <shadedClassifierName>jar-with-dependencies</shadedClassifierName>
+                            <filters>
+                                <filter>
+                                    <artifact>${project.groupId}:${project.artifactId}</artifact>
+                                </filter>
+                            </filters>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-clean-plugin</artifactId>
+                <version>2.5</version>
+                <executions>
+                    <execution>
+                        <id>auto-clean</id>
+                        <phase>install</phase>
+                        <goals>
+                            <goal>clean</goal>
+                        </goals>
+                        <configuration>
+                            <excludeDefaultDirectories>true</excludeDefaultDirectories>
+                            <filesets>
+                                <fileset>
+                                    <directory>${project.build.directory}</directory>
+                                    <includes>
+                                        <include>${project.artifactId}-${project.version}.jar</include>
+                                        <include>${project.artifactId}-${project.version}-sources.jar</include>
+                                    </includes>
+                                </fileset>
+                            </filesets>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/PaymentActivator.java b/osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/PaymentActivator.java
new file mode 100644
index 0000000..00d2113
--- /dev/null
+++ b/osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/PaymentActivator.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2010-2013 Ning, Inc.
+ *
+ * Ning 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 com.ning.billing.osgi.bundles.test;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.framework.BundleContext;
+
+import com.ning.billing.osgi.api.OSGIPluginProperties;
+import com.ning.billing.payment.plugin.api.PaymentPluginApi;
+import com.ning.billing.payment.plugin.api.PaymentPluginApiWithTestControl;
+import com.ning.killbill.osgi.libs.killbill.KillbillActivatorBase;
+import com.ning.killbill.osgi.libs.killbill.OSGIKillbillEventDispatcher.OSGIKillbillEventHandler;
+
+/**
+ * Test class used by Payment tests-- to test fake OSGI payment bundle
+ */
+public class PaymentActivator extends KillbillActivatorBase {
+
+    @Override
+    public void start(final BundleContext context) throws Exception {
+
+        final String bundleName = context.getBundle().getSymbolicName();
+        System.out.println("PaymentActivator starting bundle = " + bundleName);
+
+        super.start(context);
+        registerPaymentApi(context);
+    }
+
+    @Override
+    public void stop(final BundleContext context) throws Exception {
+        super.stop(context);
+        System.out.println("Good bye world from PaymentActivator!");
+    }
+
+    @Override
+    public OSGIKillbillEventHandler getOSGIKillbillEventHandler() {
+        return null;
+    }
+
+    private void registerPaymentApi(final BundleContext context) {
+
+        final Dictionary props = new Hashtable();
+        // Same name the beatrix tests expect when using that payment plugin
+        props.put(OSGIPluginProperties.PLUGIN_NAME_PROP, "osgiPaymentPlugin");
+        registrar.registerService(context, PaymentPluginApiWithTestControl.class, new TestPaymentPluginApi("test"), props);
+    }
+}
diff --git a/osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java b/osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java
new file mode 100644
index 0000000..b3d4fb6
--- /dev/null
+++ b/osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2010-2013 Ning, Inc.
+ *
+ * Ning 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 com.ning.billing.osgi.bundles.test;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.UUID;
+
+import org.joda.time.DateTime;
+
+import com.ning.billing.payment.api.PaymentMethodPlugin;
+import com.ning.billing.payment.plugin.api.PaymentInfoPlugin;
+import com.ning.billing.payment.plugin.api.PaymentMethodInfoPlugin;
+import com.ning.billing.payment.plugin.api.PaymentPluginApiException;
+import com.ning.billing.payment.plugin.api.PaymentPluginApiWithTestControl;
+import com.ning.billing.payment.plugin.api.RefundInfoPlugin;
+import com.ning.billing.util.callcontext.CallContext;
+import com.ning.billing.util.callcontext.TenantContext;
+
+public class TestPaymentPluginApi implements PaymentPluginApiWithTestControl {
+
+    private final String name;
+
+    private PaymentPluginApiException paymentPluginApiExceptionOnNextCalls;
+    private RuntimeException runtimeExceptionOnNextCalls;
+
+    public TestPaymentPluginApi(final String name) {
+        this.name = name;
+        resetToNormalbehavior();
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public PaymentInfoPlugin processPayment(final UUID kbPaymentId, final UUID kbPaymentMethodId, final BigDecimal amount, final CallContext context) throws PaymentPluginApiException {
+        return withRuntimeCheckForExceptions(new PaymentInfoPlugin() {
+            @Override
+            public BigDecimal getAmount() {
+                return amount;
+            }
+            @Override
+            public DateTime getCreatedDate() {
+                return new DateTime();
+            }
+            @Override
+            public DateTime getEffectiveDate() {
+                return new DateTime();
+            }
+            @Override
+            public PaymentPluginStatus getStatus() {
+                return PaymentPluginStatus.PROCESSED;
+            }
+            @Override
+            public String getGatewayError() {
+                return null;
+            }
+            @Override
+            public String getGatewayErrorCode() {
+                return null;
+            }
+        });
+    }
+
+    @Override
+    public PaymentInfoPlugin getPaymentInfo(final UUID kbPaymentId, final TenantContext context) throws PaymentPluginApiException {
+
+        final BigDecimal someAmount = new BigDecimal("12.45");
+        return withRuntimeCheckForExceptions(new PaymentInfoPlugin() {
+            @Override
+            public BigDecimal getAmount() {
+                return someAmount;
+            }
+            @Override
+            public DateTime getCreatedDate() {
+                return new DateTime();
+            }
+            @Override
+            public DateTime getEffectiveDate() {
+                return new DateTime();
+            }
+            @Override
+            public PaymentPluginStatus getStatus() {
+                return PaymentPluginStatus.PROCESSED;
+            }
+            @Override
+            public String getGatewayError() {
+                return null;
+            }
+            @Override
+            public String getGatewayErrorCode() {
+                return null;
+            }
+        });
+    }
+
+    @Override
+    public RefundInfoPlugin processRefund(final UUID kbPaymentId, final BigDecimal refundAmount, final CallContext context) throws PaymentPluginApiException {
+
+        final BigDecimal someAmount = new BigDecimal("12.45");
+        return withRuntimeCheckForExceptions(new RefundInfoPlugin() {
+            @Override
+            public BigDecimal getAmount() {
+                return null;
+            }
+            @Override
+            public DateTime getCreatedDate() {
+                return null;
+            }
+            @Override
+            public DateTime getEffectiveDate() {
+                return null;
+            }
+            @Override
+            public RefundPluginStatus getStatus() {
+                return null;
+            }
+            @Override
+            public String getGatewayError() {
+                return null;
+            }
+            @Override
+            public String getGatewayErrorCode() {
+                return null;
+            }
+        });
+    }
+
+    @Override
+    public void addPaymentMethod(final UUID kbPaymentMethodId, final PaymentMethodPlugin paymentMethodProps, final boolean setDefault, final CallContext context) throws PaymentPluginApiException {
+    }
+
+    @Override
+    public void deletePaymentMethod(final UUID kbPaymentMethodId, final CallContext context) throws PaymentPluginApiException {
+    }
+
+    @Override
+    public void setDefaultPaymentMethod(final UUID kbPaymentMethodId, final CallContext context) throws PaymentPluginApiException {
+    }
+
+    @Override
+    public List<PaymentMethodInfoPlugin> getPaymentMethods(final UUID kbAccountId, final boolean refreshFromGateway, final CallContext context) throws PaymentPluginApiException {
+        return null;
+    }
+
+    @Override
+    public void resetPaymentMethods(final List<PaymentMethodInfoPlugin> paymentMethods) throws PaymentPluginApiException {
+    }
+
+
+    private <T> T withRuntimeCheckForExceptions(final T result) throws PaymentPluginApiException {
+        if (paymentPluginApiExceptionOnNextCalls != null) {
+            throw paymentPluginApiExceptionOnNextCalls;
+
+        } else if (runtimeExceptionOnNextCalls != null) {
+            throw runtimeExceptionOnNextCalls;
+        } else {
+            return result;
+        }
+    }
+
+    @Override
+    public void setPaymentPluginApiExceptionOnNextCalls(final PaymentPluginApiException e) {
+        resetToNormalbehavior();
+        paymentPluginApiExceptionOnNextCalls = e;
+    }
+
+    @Override
+    public void setPaymentRuntimeExceptionOnNextCalls(final RuntimeException e) {
+        resetToNormalbehavior();
+        runtimeExceptionOnNextCalls = e;
+    }
+
+    @Override
+    public void resetToNormalbehavior() {
+        paymentPluginApiExceptionOnNextCalls = null;
+        runtimeExceptionOnNextCalls = null;
+    }
+}
diff --git a/osgi-bundles/tests/payment/src/test/resources/ddl_test.sql b/osgi-bundles/tests/payment/src/test/resources/ddl_test.sql
new file mode 100644
index 0000000..e4bfa5d
--- /dev/null
+++ b/osgi-bundles/tests/payment/src/test/resources/ddl_test.sql
@@ -0,0 +1,10 @@
+/*! SET storage_engine=INNODB */;
+
+DROP TABLE IF EXISTS test_bundle;
+CREATE TABLE test_bundle (
+    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    is_started bool DEFAULT false,
+    is_logged bool DEFAULT false,
+    external_key varchar(128) NULL
+    PRIMARY KEY(record_id)
+);
diff --git a/osgi-bundles/tests/pom.xml b/osgi-bundles/tests/pom.xml
index a9fb702..79083cf 100644
--- a/osgi-bundles/tests/pom.xml
+++ b/osgi-bundles/tests/pom.xml
@@ -28,5 +28,6 @@
     <packaging>pom</packaging>
     <modules>
         <module>beatrix</module>
+        <module>payment</module>
     </modules>
 </project>
diff --git a/payment/src/main/java/com/ning/billing/payment/provider/ExternalPaymentProviderPlugin.java b/payment/src/main/java/com/ning/billing/payment/provider/ExternalPaymentProviderPlugin.java
index 0262bce..ac621ba 100644
--- a/payment/src/main/java/com/ning/billing/payment/provider/ExternalPaymentProviderPlugin.java
+++ b/payment/src/main/java/com/ning/billing/payment/provider/ExternalPaymentProviderPlugin.java
@@ -16,11 +16,6 @@
 
 package com.ning.billing.payment.provider;
 
-import java.util.List;
-import java.util.UUID;
-
-import com.ning.billing.payment.plugin.api.PaymentMethodInfoPlugin;
-import com.ning.billing.util.callcontext.CallContext;
 import com.ning.billing.util.clock.Clock;
 
 import com.google.inject.Inject;
diff --git a/util/src/test/java/com/ning/billing/payment/plugin/api/PaymentPluginApiWithTestControl.java b/util/src/test/java/com/ning/billing/payment/plugin/api/PaymentPluginApiWithTestControl.java
new file mode 100644
index 0000000..9336aab
--- /dev/null
+++ b/util/src/test/java/com/ning/billing/payment/plugin/api/PaymentPluginApiWithTestControl.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2010-2013 Ning, Inc.
+ *
+ * Ning 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 com.ning.billing.payment.plugin.api;
+
+public interface PaymentPluginApiWithTestControl extends PaymentPluginApi {
+
+    public void setPaymentPluginApiExceptionOnNextCalls(PaymentPluginApiException e);
+
+    public void setPaymentRuntimeExceptionOnNextCalls(RuntimeException e);
+
+    public void resetToNormalbehavior();
+}