killbill-memoizeit

Details

payment/pom.xml 4(+4 -0)

diff --git a/payment/pom.xml b/payment/pom.xml
index 3a22601..fae6a01 100644
--- a/payment/pom.xml
+++ b/payment/pom.xml
@@ -29,6 +29,10 @@
             <artifactId>killbill-invoice</artifactId>
         </dependency>
         <dependency>
+            <groupId>com.ning.billing</groupId>
+            <artifactId>killbill-account</artifactId>
+        </dependency>
+        <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
             <scope>provided</scope>
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 9183cc0..b387319 100644
--- a/payment/src/main/java/com/ning/billing/payment/InvoiceProcessor.java
+++ b/payment/src/main/java/com/ning/billing/payment/InvoiceProcessor.java
@@ -2,6 +2,7 @@ package com.ning.billing.payment;
 
 import com.google.common.eventbus.Subscribe;
 import com.google.inject.Inject;
+import com.ning.billing.account.api.Account;
 import com.ning.billing.invoice.model.Invoice;
 import com.ning.billing.payment.provider.PaymentProviderPlugin;
 import com.ning.billing.util.eventbus.IEventBus.EventBusException;
@@ -16,6 +17,9 @@ public class InvoiceProcessor {
 
     @Subscribe
     public void receiveInvoice(Invoice invoice) throws EventBusException {
-        provider.processInvoice(invoice);
+        // TODO: retrieve account
+        final Account account = null;
+
+        provider.processInvoice(account, invoice);
     }
 }
diff --git a/payment/src/main/java/com/ning/billing/payment/PaymentError.java b/payment/src/main/java/com/ning/billing/payment/PaymentError.java
new file mode 100644
index 0000000..c14d8f2
--- /dev/null
+++ b/payment/src/main/java/com/ning/billing/payment/PaymentError.java
@@ -0,0 +1,47 @@
+package com.ning.billing.payment;
+
+import java.util.UUID;
+
+import com.ning.billing.util.eventbus.IEventBusType;
+
+public class PaymentError implements IEventBusType {
+    private final UUID id;
+
+    public PaymentError(PaymentError src) {
+        this.id = src.id;
+    }
+
+    public PaymentError(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;
+        PaymentError other = (PaymentError) 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/main/java/com/ning/billing/payment/PaymentInfo.java b/payment/src/main/java/com/ning/billing/payment/PaymentInfo.java
index ba7081c..bf45391 100644
--- a/payment/src/main/java/com/ning/billing/payment/PaymentInfo.java
+++ b/payment/src/main/java/com/ning/billing/payment/PaymentInfo.java
@@ -1,29 +1,269 @@
 package com.ning.billing.payment;
 
+import java.math.BigDecimal;
 import java.util.UUID;
 
+import org.joda.time.DateTime;
+
 import com.ning.billing.util.eventbus.IEventBusType;
 
 public class PaymentInfo implements IEventBusType {
+    public static class Builder {
+        private UUID id;
+        private BigDecimal amount;
+        private BigDecimal appliedCreditBalanceAmount;
+        private String bankIdentificationNumber;
+        private DateTime createdDate;
+        private DateTime effectiveDate;
+        private String paymentNumber;
+        private String referenceId;
+        private BigDecimal refundAmount;
+        private String secondPaymentReferenceId;
+        private String status;
+        private String type;
+        private DateTime updatedDate;
+
+        public Builder() {
+        }
+
+        public Builder(PaymentInfo src) {
+            this.id = src.id;
+            this.amount = src.amount;
+            this.appliedCreditBalanceAmount = src.appliedCreditBalanceAmount;
+            this.bankIdentificationNumber = src.bankIdentificationNumber;
+            this.createdDate = src.createdDate;
+            this.effectiveDate = src.effectiveDate;
+            this.paymentNumber = src.paymentNumber;
+            this.referenceId = src.referenceId;
+            this.refundAmount = src.refundAmount;
+            this.secondPaymentReferenceId = src.secondPaymentReferenceId;
+            this.status = src.status;
+            this.type = src.type;
+            this.updatedDate = src.updatedDate;
+        }
+
+        public Builder setId(UUID id) {
+            this.id = id;
+            return this;
+        }
+
+        public Builder setAmount(BigDecimal amount) {
+            this.amount = amount;
+            return this;
+        }
+
+        public Builder setAppliedCreditBalanceAmount(BigDecimal appliedCreditBalanceAmount) {
+            this.appliedCreditBalanceAmount = appliedCreditBalanceAmount;
+            return this;
+        }
+
+        public Builder setBankIdentificationNumber(String bankIdentificationNumber) {
+            this.bankIdentificationNumber = bankIdentificationNumber;
+            return this;
+        }
+
+        public Builder setCreatedDate(DateTime createdDate) {
+            this.createdDate = createdDate;
+            return this;
+        }
+
+        public Builder setEffectiveDate(DateTime effectiveDate) {
+            this.effectiveDate = effectiveDate;
+            return this;
+        }
+
+        public Builder setPaymentNumber(String paymentNumber) {
+            this.paymentNumber = paymentNumber;
+            return this;
+        }
+
+        public Builder setReferenceId(String referenceId) {
+            this.referenceId = referenceId;
+            return this;
+        }
+
+        public Builder setRefundAmount(BigDecimal refundAmount) {
+            this.refundAmount = refundAmount;
+            return this;
+        }
+
+        public Builder setSecondPaymentReferenceId(String secondPaymentReferenceId) {
+            this.secondPaymentReferenceId = secondPaymentReferenceId;
+            return this;
+        }
+
+        public Builder setStatus(String status) {
+            this.status = status;
+            return this;
+        }
+
+        public Builder setType(String type) {
+            this.type = type;
+            return this;
+        }
+
+        public Builder setUpdatedDate(DateTime updatedDate) {
+            this.updatedDate = updatedDate;
+            return this;
+        }
+
+        public PaymentInfo build() {
+            return new PaymentInfo(id,
+                                   amount,
+                                   appliedCreditBalanceAmount,
+                                   bankIdentificationNumber,
+                                   createdDate,
+                                   effectiveDate,
+                                   paymentNumber,
+                                   referenceId,
+                                   refundAmount,
+                                   secondPaymentReferenceId,
+                                   status,
+                                   type,
+                                   updatedDate);
+        }
+    }
+
     private final UUID id;
+    private final BigDecimal amount;
+    private final BigDecimal appliedCreditBalanceAmount;
+    private final String bankIdentificationNumber;
+    private final DateTime createdDate;
+    private final DateTime effectiveDate;
+    private final String paymentNumber;
+    private final String referenceId;
+    private final BigDecimal refundAmount;
+    private final String secondPaymentReferenceId;
+    private final String status;
+    private final String type;
+    private final DateTime updatedDate;
 
     public PaymentInfo(PaymentInfo src) {
         this.id = src.id;
+        this.amount = src.amount;
+        this.appliedCreditBalanceAmount = src.appliedCreditBalanceAmount;
+        this.bankIdentificationNumber = src.bankIdentificationNumber;
+        this.createdDate = src.createdDate;
+        this.effectiveDate = src.effectiveDate;
+        this.paymentNumber = src.paymentNumber;
+        this.referenceId = src.referenceId;
+        this.refundAmount = src.refundAmount;
+        this.secondPaymentReferenceId = src.secondPaymentReferenceId;
+        this.status = src.status;
+        this.type = src.type;
+        this.updatedDate = src.updatedDate;
     }
 
-    public PaymentInfo(UUID id) {
+    public PaymentInfo(UUID id,
+                       BigDecimal amount,
+                       BigDecimal appliedCreditBalanceAmount,
+                       String bankIdentificationNumber,
+                       DateTime createdDate,
+                       DateTime effectiveDate,
+                       String paymentNumber,
+                       String referenceId,
+                       BigDecimal refundAmount,
+                       String secondPaymentReferenceId,
+                       String status,
+                       String type,
+                       DateTime updatedDate) {
         this.id = id;
+        this.amount = amount;
+        this.appliedCreditBalanceAmount = appliedCreditBalanceAmount;
+        this.bankIdentificationNumber = bankIdentificationNumber;
+        this.createdDate = createdDate;
+        this.effectiveDate = effectiveDate;
+        this.paymentNumber = paymentNumber;
+        this.referenceId = referenceId;
+        this.refundAmount = refundAmount;
+        this.secondPaymentReferenceId = secondPaymentReferenceId;
+        this.status = status;
+        this.type = type;
+        this.updatedDate = updatedDate;
+    }
+
+    public Builder cloner() {
+        return new Builder(this);
     }
 
     public UUID getId() {
         return id;
     }
 
+    public BigDecimal getAmount() {
+        return amount;
+    }
+
+    public BigDecimal getAppliedCreditBalanceAmount() {
+        return appliedCreditBalanceAmount;
+    }
+
+    public String getBankIdentificationNumber() {
+        return bankIdentificationNumber;
+    }
+
+    public DateTime getCreatedDate() {
+        return createdDate;
+    }
+
+    public DateTime getEffectiveDate() {
+        return effectiveDate;
+    }
+
+    public String getPaymentNumber() {
+        return paymentNumber;
+    }
+
+    public String getReferenceId() {
+        return referenceId;
+    }
+
+    public BigDecimal getRefundAmount() {
+        return refundAmount;
+    }
+
+    public String getSecondPaymentReferenceId() {
+        return secondPaymentReferenceId;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public DateTime getUpdatedDate() {
+        return updatedDate;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = 1;
+        result = prime * result + ((amount == null) ? 0 : amount.hashCode());
+        result = prime * result + ((appliedCreditBalanceAmount == null) ? 0
+                                                                       : appliedCreditBalanceAmount.hashCode());
+        result = prime * result + ((bankIdentificationNumber == null) ? 0
+                                                                     : bankIdentificationNumber.hashCode());
+        result = prime * result + ((createdDate == null) ? 0
+                                                        : createdDate.hashCode());
+        result = prime * result + ((effectiveDate == null) ? 0
+                                                          : effectiveDate.hashCode());
         result = prime * result + ((id == null) ? 0 : id.hashCode());
+        result = prime * result + ((paymentNumber == null) ? 0
+                                                          : paymentNumber.hashCode());
+        result = prime * result + ((referenceId == null) ? 0
+                                                        : referenceId.hashCode());
+        result = prime * result + ((refundAmount == null) ? 0
+                                                         : refundAmount.hashCode());
+        result = prime * result + ((secondPaymentReferenceId == null) ? 0
+                                                                     : secondPaymentReferenceId.hashCode());
+        result = prime * result + ((status == null) ? 0 : status.hashCode());
+        result = prime * result + ((type == null) ? 0 : type.hashCode());
+        result = prime * result + ((updatedDate == null) ? 0
+                                                        : updatedDate.hashCode());
         return result;
     }
 
@@ -36,12 +276,84 @@ public class PaymentInfo implements IEventBusType {
         if (getClass() != obj.getClass())
             return false;
         PaymentInfo other = (PaymentInfo) obj;
+        if (amount == null) {
+            if (other.amount != null)
+                return false;
+        }
+        else if (!amount.equals(other.amount))
+            return false;
+        if (appliedCreditBalanceAmount == null) {
+            if (other.appliedCreditBalanceAmount != null)
+                return false;
+        }
+        else if (!appliedCreditBalanceAmount.equals(other.appliedCreditBalanceAmount))
+            return false;
+        if (bankIdentificationNumber == null) {
+            if (other.bankIdentificationNumber != null)
+                return false;
+        }
+        else if (!bankIdentificationNumber.equals(other.bankIdentificationNumber))
+            return false;
+        if (createdDate == null) {
+            if (other.createdDate != null)
+                return false;
+        }
+        else if (!createdDate.equals(other.createdDate))
+            return false;
+        if (effectiveDate == null) {
+            if (other.effectiveDate != null)
+                return false;
+        }
+        else if (!effectiveDate.equals(other.effectiveDate))
+            return false;
         if (id == null) {
             if (other.id != null)
                 return false;
         }
         else if (!id.equals(other.id))
             return false;
+        if (paymentNumber == null) {
+            if (other.paymentNumber != null)
+                return false;
+        }
+        else if (!paymentNumber.equals(other.paymentNumber))
+            return false;
+        if (referenceId == null) {
+            if (other.referenceId != null)
+                return false;
+        }
+        else if (!referenceId.equals(other.referenceId))
+            return false;
+        if (refundAmount == null) {
+            if (other.refundAmount != null)
+                return false;
+        }
+        else if (!refundAmount.equals(other.refundAmount))
+            return false;
+        if (secondPaymentReferenceId == null) {
+            if (other.secondPaymentReferenceId != null)
+                return false;
+        }
+        else if (!secondPaymentReferenceId.equals(other.secondPaymentReferenceId))
+            return false;
+        if (status == null) {
+            if (other.status != null)
+                return false;
+        }
+        else if (!status.equals(other.status))
+            return false;
+        if (type == null) {
+            if (other.type != null)
+                return false;
+        }
+        else if (!type.equals(other.type))
+            return false;
+        if (updatedDate == null) {
+            if (other.updatedDate != null)
+                return false;
+        }
+        else if (!updatedDate.equals(other.updatedDate))
+            return false;
         return true;
     }
 }
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
index 5636468..1c491da 100644
--- a/payment/src/main/java/com/ning/billing/payment/provider/PaymentProviderPlugin.java
+++ b/payment/src/main/java/com/ning/billing/payment/provider/PaymentProviderPlugin.java
@@ -1,7 +1,8 @@
 package com.ning.billing.payment.provider;
 
+import com.ning.billing.account.api.Account;
 import com.ning.billing.invoice.model.Invoice;
 
 public interface PaymentProviderPlugin {
-    public void processInvoice(Invoice invoice);
+    public void processInvoice(Account account, Invoice invoice);
 }
diff --git a/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java b/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java
index c12288e..cd3f0fd 100644
--- a/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java
+++ b/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java
@@ -3,6 +3,7 @@ package com.ning.billing.payment.provider;
 import java.util.UUID;
 
 import com.google.inject.Inject;
+import com.ning.billing.account.api.Account;
 import com.ning.billing.invoice.model.Invoice;
 import com.ning.billing.payment.PaymentInfo;
 import com.ning.billing.util.eventbus.IEventBus;
@@ -17,9 +18,9 @@ public class MockPaymentProviderPlugin implements PaymentProviderPlugin {
     }
 
     @Override
-    public void processInvoice(Invoice invoice) {
+    public void processInvoice(Account account, Invoice invoice) {
         try {
-            eventBus.post(new PaymentInfo(UUID.randomUUID()));
+            eventBus.post(new PaymentInfo.Builder().setId(UUID.randomUUID()).build());
         }
         catch (EventBusException ex) {
             throw new RuntimeException(ex);
diff --git a/payment/src/test/java/com/ning/billing/payment/TestPaymentProvider.java b/payment/src/test/java/com/ning/billing/payment/TestPaymentProvider.java
index 4054676..5c5f671 100644
--- a/payment/src/test/java/com/ning/billing/payment/TestPaymentProvider.java
+++ b/payment/src/test/java/com/ning/billing/payment/TestPaymentProvider.java
@@ -2,6 +2,8 @@ package com.ning.billing.payment;
 
 import static com.jayway.awaitility.Awaitility.await;
 import static java.util.concurrent.TimeUnit.MINUTES;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
@@ -30,15 +32,25 @@ import com.ning.billing.util.eventbus.IEventBus.EventBusException;
 public class TestPaymentProvider {
     private static class MockPaymentProcessor {
         private final List<PaymentInfo> processedPayments = Collections.synchronizedList(new ArrayList<PaymentInfo>());
+        private final List<PaymentError> errors = Collections.synchronizedList(new ArrayList<PaymentError>());
 
         @Subscribe
         public void processedPayment(PaymentInfo paymentInfo) {
             processedPayments.add(paymentInfo);
         }
 
+        @Subscribe
+        public void processedPaymentError(PaymentError paymentError) {
+            errors.add(paymentError);
+        }
+
         public List<PaymentInfo> getProcessedPayments() {
             return new ArrayList<PaymentInfo>(processedPayments);
         }
+
+        public List<PaymentError> getErrors() {
+            return new ArrayList<PaymentError>(errors);
+        }
     }
 
     @Inject
@@ -82,8 +94,13 @@ public class TestPaymentProvider {
             @Override
             public Boolean call() throws Exception {
                 List<PaymentInfo> processedPayments = mockPaymentProcessor.getProcessedPayments();
-                return processedPayments.size() == 1;
+                List<PaymentError> errors = mockPaymentProcessor.getErrors();
+
+                return processedPayments.size() == 1 || errors.size() == 1;
             }
         });
+
+        assertFalse(mockPaymentProcessor.getProcessedPayments().isEmpty());
+        assertTrue(mockPaymentProcessor.getErrors().isEmpty());
     }
 }