killbill-memoizeit

Details

diff --git a/payment/src/main/java/com/ning/billing/payment/InvoiceProcessor.java b/payment/src/main/java/com/ning/billing/payment/InvoiceProcessor.java
index 4577e0a..9183cc0 100644
--- a/payment/src/main/java/com/ning/billing/payment/InvoiceProcessor.java
+++ b/payment/src/main/java/com/ning/billing/payment/InvoiceProcessor.java
@@ -1,8 +1,21 @@
 package com.ning.billing.payment;
 
+import com.google.common.eventbus.Subscribe;
+import com.google.inject.Inject;
 import com.ning.billing.invoice.model.Invoice;
+import com.ning.billing.payment.provider.PaymentProviderPlugin;
 import com.ning.billing.util.eventbus.IEventBus.EventBusException;
 
-public interface InvoiceProcessor {
-    public void receiveInvoice(Invoice invoice) throws EventBusException;
+public class InvoiceProcessor {
+    private final PaymentProviderPlugin provider;
+
+    @Inject
+    public InvoiceProcessor(PaymentProviderPlugin provider) {
+        this.provider = provider;
+    }
+
+    @Subscribe
+    public void receiveInvoice(Invoice invoice) throws EventBusException {
+        provider.processInvoice(invoice);
+    }
 }
diff --git a/payment/src/main/java/com/ning/billing/payment/provider/PaymentProviderPlugin.java b/payment/src/main/java/com/ning/billing/payment/provider/PaymentProviderPlugin.java
new file mode 100644
index 0000000..5636468
--- /dev/null
+++ b/payment/src/main/java/com/ning/billing/payment/provider/PaymentProviderPlugin.java
@@ -0,0 +1,7 @@
+package com.ning.billing.payment.provider;
+
+import com.ning.billing.invoice.model.Invoice;
+
+public interface PaymentProviderPlugin {
+    public void processInvoice(Invoice invoice);
+}
diff --git a/payment/src/main/java/com/ning/billing/payment/setup/PaymentConfig.java b/payment/src/main/java/com/ning/billing/payment/setup/PaymentConfig.java
new file mode 100644
index 0000000..55155b9
--- /dev/null
+++ b/payment/src/main/java/com/ning/billing/payment/setup/PaymentConfig.java
@@ -0,0 +1,11 @@
+package com.ning.billing.payment.setup;
+
+import org.skife.config.Config;
+import org.skife.config.DefaultNull;
+
+public interface PaymentConfig
+{
+    @Config("killbill.payment.providerPluginClass")
+    @DefaultNull
+    public String getProviderPluginClass();
+}
diff --git a/payment/src/main/java/com/ning/billing/payment/setup/PaymentModule.java b/payment/src/main/java/com/ning/billing/payment/setup/PaymentModule.java
new file mode 100644
index 0000000..f6fac51
--- /dev/null
+++ b/payment/src/main/java/com/ning/billing/payment/setup/PaymentModule.java
@@ -0,0 +1,46 @@
+package com.ning.billing.payment.setup;
+
+import java.util.Properties;
+
+import org.skife.config.ConfigurationObjectFactory;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Key;
+import com.ning.billing.payment.provider.PaymentProviderPlugin;
+
+public class PaymentModule extends AbstractModule {
+    private final Properties props;
+
+    public PaymentModule() {
+        this.props = System.getProperties();
+    }
+
+    public PaymentModule(Properties props) {
+        this.props = props;
+    }
+
+    @SuppressWarnings("unchecked")
+    protected void installPaymentProviderPlugin(PaymentConfig config) {
+        String pluginClassName = config.getProviderPluginClass();
+
+        if (pluginClassName == null) {
+            throw new IllegalArgumentException("No payment provider plugin class configured");
+        }
+        Class<? extends PaymentProviderPlugin> pluginClass = null;
+
+        try {
+            pluginClass = (Class<? extends PaymentProviderPlugin>)Class.forName(pluginClassName);
+        }
+        catch (Exception ex) {
+            throw new IllegalArgumentException("Illegal payment provider plugin class configured", ex);
+        }
+        bind(PaymentProviderPlugin.class).to(Key.get(pluginClass));
+    }
+
+    @Override
+    protected void configure() {
+        final PaymentConfig config = new ConfigurationObjectFactory(props).build(PaymentConfig.class);
+
+        installPaymentProviderPlugin(config);
+    }
+}
diff --git a/payment/src/test/java/com/ning/billing/payment/setup/PaymentTestModule.java b/payment/src/test/java/com/ning/billing/payment/setup/PaymentTestModule.java
new file mode 100644
index 0000000..865babd
--- /dev/null
+++ b/payment/src/test/java/com/ning/billing/payment/setup/PaymentTestModule.java
@@ -0,0 +1,20 @@
+package com.ning.billing.payment.setup;
+
+import com.ning.billing.payment.provider.MockPaymentProviderPlugin;
+import com.ning.billing.payment.provider.PaymentProviderPlugin;
+import com.ning.billing.util.eventbus.IEventBus;
+import com.ning.billing.util.eventbus.MemoryEventBus;
+
+public class PaymentTestModule extends PaymentModule {
+    @Override
+    protected void installPaymentProviderPlugin(PaymentConfig config) {
+        bind(PaymentProviderPlugin.class).to(MockPaymentProviderPlugin.class);
+        bind(MockPaymentProviderPlugin.class).asEagerSingleton();
+    }
+
+    @Override
+    protected void configure() {
+        super.configure();
+        bind(IEventBus.class).to(MemoryEventBus.class).asEagerSingleton();
+    }
+}

pom.xml 6(+3 -3)

diff --git a/pom.xml b/pom.xml
index 578f141..9a81de4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -89,17 +89,17 @@
             <dependency>
                 <groupId>org.codehaus.jackson</groupId>
                 <artifactId>jackson-core-asl</artifactId>
-                <version>1.9.0</version>
+                <version>1.9.2</version>
             </dependency>
             <dependency>
                 <groupId>org.codehaus.jackson</groupId>
                 <artifactId>jackson-jaxrs</artifactId>
-                <version>1.9.0</version>
+                <version>1.9.2</version>
             </dependency>
             <dependency>
                 <groupId>org.codehaus.jackson</groupId>
                 <artifactId>jackson-mapper-asl</artifactId>
-                <version>1.9.0</version>
+                <version>1.9.2</version>
             </dependency>
             <dependency>
                 <groupId>com.jolbox</groupId>