killbill-memoizeit
Changes
payment/pom.xml 38(+38 -0)
payment/src/test/resources/log4j.xml 30(+30 -0)
pom.xml 13(+12 -1)
Details
diff --git a/invoice/src/main/java/com/ning/billing/invoice/model/Invoice.java b/invoice/src/main/java/com/ning/billing/invoice/model/Invoice.java
index 8d67d53..d15c387 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/model/Invoice.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/model/Invoice.java
@@ -16,14 +16,16 @@
package com.ning.billing.invoice.model;
-import com.ning.billing.catalog.api.Currency;
-import org.joda.time.DateTime;
-
import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;
-public class Invoice {
+import org.joda.time.DateTime;
+
+import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.util.eventbus.IEventBusType;
+
+public class Invoice implements IEventBusType {
private final InvoiceItemList items = new InvoiceItemList();
private final UUID invoiceId;
private UUID accountId;
payment/pom.xml 38(+38 -0)
diff --git a/payment/pom.xml b/payment/pom.xml
index 1a57af5..3a22601 100644
--- a/payment/pom.xml
+++ b/payment/pom.xml
@@ -20,6 +20,44 @@
<name>killbill-payment</name>
<packaging>jar</packaging>
<dependencies>
+ <dependency>
+ <groupId>com.ning.billing</groupId>
+ <artifactId>killbill-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.ning.billing</groupId>
+ <artifactId>killbill-invoice</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.inject</groupId>
+ <artifactId>guice</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.jayway.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.ning.billing</groupId>
+ <artifactId>killbill-util</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
</build>
diff --git a/payment/src/main/java/com/ning/billing/payment/InvoiceProcessor.java b/payment/src/main/java/com/ning/billing/payment/InvoiceProcessor.java
new file mode 100644
index 0000000..4577e0a
--- /dev/null
+++ b/payment/src/main/java/com/ning/billing/payment/InvoiceProcessor.java
@@ -0,0 +1,8 @@
+package com.ning.billing.payment;
+
+import com.ning.billing.invoice.model.Invoice;
+import com.ning.billing.util.eventbus.IEventBus.EventBusException;
+
+public interface InvoiceProcessor {
+ public void receiveInvoice(Invoice invoice) throws EventBusException;
+}
diff --git a/payment/src/main/java/com/ning/billing/payment/PaymentInfo.java b/payment/src/main/java/com/ning/billing/payment/PaymentInfo.java
new file mode 100644
index 0000000..ba7081c
--- /dev/null
+++ b/payment/src/main/java/com/ning/billing/payment/PaymentInfo.java
@@ -0,0 +1,47 @@
+package com.ning.billing.payment;
+
+import java.util.UUID;
+
+import com.ning.billing.util.eventbus.IEventBusType;
+
+public class PaymentInfo implements IEventBusType {
+ private final UUID id;
+
+ public PaymentInfo(PaymentInfo src) {
+ this.id = src.id;
+ }
+
+ public PaymentInfo(UUID id) {
+ this.id = id;
+ }
+
+ public UUID getId() {
+ return id;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ PaymentInfo other = (PaymentInfo) obj;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ }
+ else if (!id.equals(other.id))
+ return false;
+ return true;
+ }
+}
diff --git a/payment/src/test/java/com/ning/billing/payment/MockInvoiceProcessor.java b/payment/src/test/java/com/ning/billing/payment/MockInvoiceProcessor.java
new file mode 100644
index 0000000..d2f2957
--- /dev/null
+++ b/payment/src/test/java/com/ning/billing/payment/MockInvoiceProcessor.java
@@ -0,0 +1,24 @@
+package com.ning.billing.payment;
+
+import java.util.UUID;
+
+import com.google.common.eventbus.Subscribe;
+import com.google.inject.Inject;
+import com.ning.billing.invoice.model.Invoice;
+import com.ning.billing.util.eventbus.IEventBus;
+import com.ning.billing.util.eventbus.IEventBus.EventBusException;
+
+public class MockInvoiceProcessor implements InvoiceProcessor {
+ private final IEventBus eventBus;
+
+ @Inject
+ public MockInvoiceProcessor(IEventBus eventBus) {
+ this.eventBus = eventBus;
+ }
+
+ @Override
+ @Subscribe
+ public void receiveInvoice(Invoice invoice) throws EventBusException {
+ eventBus.post(new PaymentInfo(UUID.randomUUID()));
+ }
+}
diff --git a/payment/src/test/java/com/ning/billing/payment/TestInvoiceEvent.java b/payment/src/test/java/com/ning/billing/payment/TestInvoiceEvent.java
new file mode 100644
index 0000000..a5fa284
--- /dev/null
+++ b/payment/src/test/java/com/ning/billing/payment/TestInvoiceEvent.java
@@ -0,0 +1,86 @@
+package com.ning.billing.payment;
+
+import static com.jayway.awaitility.Awaitility.await;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.Callable;
+
+import org.joda.time.DateTime;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.eventbus.Subscribe;
+import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.invoice.model.Invoice;
+import com.ning.billing.invoice.model.InvoiceItem;
+import com.ning.billing.util.eventbus.IEventBus;
+import com.ning.billing.util.eventbus.IEventBus.EventBusException;
+import com.ning.billing.util.eventbus.MemoryEventBus;
+
+public class TestInvoiceEvent {
+ private static class MockPaymentProcessor {
+ private final List<PaymentInfo> processedPayments = Collections.synchronizedList(new ArrayList<PaymentInfo>());
+
+ @Subscribe
+ public void processedPayment(PaymentInfo paymentInfo) {
+ processedPayments.add(paymentInfo);
+ }
+
+ public List<PaymentInfo> getProcessedPayments() {
+ return new ArrayList<PaymentInfo>(processedPayments);
+ }
+ }
+
+ private IEventBus eventBus;
+ private InvoiceProcessor invoiceProcessor;
+ private MockPaymentProcessor mockPaymentProcessor;
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws EventBusException {
+ eventBus = new MemoryEventBus();
+ eventBus.start();
+
+ invoiceProcessor = new MockInvoiceProcessor(eventBus);
+ mockPaymentProcessor = new MockPaymentProcessor();
+ eventBus.register(invoiceProcessor);
+ eventBus.register(mockPaymentProcessor);
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown() {
+ eventBus.stop();
+ }
+
+ @Test
+ public void testSimpleInvoice() throws Exception {
+ final UUID subscriptionUuid = UUID.randomUUID();
+ final UUID invoiceUuid = UUID.randomUUID();
+ final DateTime now = new DateTime();
+ final InvoiceItem lineItem = new InvoiceItem(invoiceUuid,
+ subscriptionUuid,
+ now,
+ now.plusMonths(1),
+ "Test invoice",
+ new BigDecimal("10"),
+ new BigDecimal("1"),
+ Currency.USD);
+ final List<InvoiceItem> lineItems = Arrays.asList(lineItem);
+ final Invoice invoice = new Invoice(invoiceUuid, lineItems, Currency.USD);
+
+ eventBus.post(invoice);
+ await().atMost(1, SECONDS).until(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ List<PaymentInfo> processedPayments = mockPaymentProcessor.getProcessedPayments();
+ return processedPayments.size() == 1;
+ }
+ });
+ }
+}
payment/src/test/resources/log4j.xml 30(+30 -0)
diff --git a/payment/src/test/resources/log4j.xml b/payment/src/test/resources/log4j.xml
new file mode 100644
index 0000000..82b5a26
--- /dev/null
+++ b/payment/src/test/resources/log4j.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ ~ Copyright 2010 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.
+ -->
+<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
+<log4j:configuration debug="false"
+ xmlns:log4j='http://jakarta.apache.org/log4j/'>
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%p %d{ISO8601} %t %c %m%n"/>
+ </layout>
+ </appender>
+
+ <root>
+ <level value="info"/>
+ <appender-ref ref="CONSOLE"/>
+ </root>
+</log4j:configuration>
pom.xml 13(+12 -1)
diff --git a/pom.xml b/pom.xml
index beac545..578f141 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,6 +71,11 @@
</dependency>
<dependency>
<groupId>com.ning.billing</groupId>
+ <artifactId>killbill-invoice</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.ning.billing</groupId>
<artifactId>killbill-util</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
@@ -217,7 +222,13 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
- <version>6.0</version>
+ <version>6.3.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.jayway.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <version>1.3.3</version>
<scope>test</scope>
</dependency>
</dependencies>