killbill-memoizeit

Details

diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java
index b8541b2..41979d0 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java
@@ -134,6 +134,7 @@ public class AccountTimelineJson {
             final String status = payment.getPaymentStatus().toString();
             this.payments.add(new PaymentJsonWithBundleKeys(payment.getAmount(), payment.getPaidAmount(), account.getId().toString(),
                                                             payment.getInvoiceId().toString(), payment.getId().toString(),
+                                                            payment.getPaymentMethodId().toString(),
                                                             payment.getEffectiveDate(), payment.getEffectiveDate(),
                                                             payment.getAttempts().size(), payment.getCurrency().toString(), status,
                                                             getBundleExternalKey(payment.getInvoiceId(), invoices, bundles),
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PaymentJsonSimple.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PaymentJsonSimple.java
index a075425..6d9cbaa 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PaymentJsonSimple.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PaymentJsonSimple.java
@@ -47,12 +47,15 @@ public class PaymentJsonSimple {
 
     private final String status;
 
+    private final String paymentMethodId;
+
     public PaymentJsonSimple() {
         this.amount = null;
         this.paidAmount = null;
         this.invoiceId = null;
         this.accountId = null;
         this.paymentId = null;
+        this.paymentMethodId = null;
         this.requestedDate = null;
         this.effectiveDate = null;
         this.currency = null;
@@ -66,6 +69,7 @@ public class PaymentJsonSimple {
                              @JsonProperty("accountId") final String accountId,
                              @JsonProperty("invoiceId") final String invoiceId,
                              @JsonProperty("paymentId") final String paymentId,
+                             @JsonProperty("paymentMethodId") final String paymentMethodId,
                              @JsonProperty("requestedDate") final DateTime requestedDate,
                              @JsonProperty("effectiveDate") final DateTime effectiveDate,
                              @JsonProperty("retryCount") final Integer retryCount,
@@ -77,6 +81,7 @@ public class PaymentJsonSimple {
         this.invoiceId = invoiceId;
         this.accountId = accountId;
         this.paymentId = paymentId;
+        this.paymentMethodId = paymentMethodId;
         this.requestedDate = DefaultClock.toUTCDateTime(requestedDate);
         this.effectiveDate = DefaultClock.toUTCDateTime(effectiveDate);
         this.currency = currency;
@@ -90,6 +95,7 @@ public class PaymentJsonSimple {
         this.invoiceId = src.getInvoiceId().toString();
         this.accountId = src.getAccountId().toString();
         this.paymentId = src.getId().toString();
+        this.paymentMethodId =src.getPaymentMethodId().toString();
         this.requestedDate = src.getEffectiveDate();
         this.effectiveDate = src.getEffectiveDate();
         this.currency = src.getCurrency().toString();
@@ -110,6 +116,10 @@ public class PaymentJsonSimple {
         return paymentId;
     }
 
+    public String getPaymentMethodId() {
+        return paymentMethodId;
+    }
+
     public DateTime getRequestedDate() {
         return DefaultClock.toUTCDateTime(requestedDate);
     }
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PaymentJsonWithBundleKeys.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PaymentJsonWithBundleKeys.java
index 255cef2..9451faa 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PaymentJsonWithBundleKeys.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PaymentJsonWithBundleKeys.java
@@ -44,6 +44,7 @@ public class PaymentJsonWithBundleKeys extends PaymentJsonSimple {
                                      @JsonProperty("accountId") final String accountId,
                                      @JsonProperty("invoiceId") final String invoiceId,
                                      @JsonProperty("paymentId") final String paymentId,
+                                     @JsonProperty("paymentMethodId") final String paymentMethodId,
                                      @JsonProperty("requestedDt") final DateTime requestedDate,
                                      @JsonProperty("effectiveDt") final DateTime effectiveDate,
                                      @JsonProperty("retryCount") final Integer retryCount,
@@ -52,7 +53,7 @@ public class PaymentJsonWithBundleKeys extends PaymentJsonSimple {
                                      @JsonProperty("externalBundleKeys") final String bundleKeys,
                                      @JsonProperty("refunds") final List<RefundJson> refunds,
                                      @JsonProperty("chargebacks") final List<ChargebackJson> chargebacks) {
-        super(amount, paidAmount, accountId, invoiceId, paymentId, requestedDate, effectiveDate, retryCount, currency, status);
+        super(amount, paidAmount, accountId, invoiceId, paymentId, paymentMethodId, requestedDate, effectiveDate, retryCount, currency, status);
         this.bundleKeys = bundleKeys;
         this.refunds = refunds;
         this.chargebacks = chargebacks;
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleTimelineJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleTimelineJson.java
index 96b6adf..9c835af 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleTimelineJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleTimelineJson.java
@@ -59,13 +59,13 @@ public class TestBundleTimelineJson extends JaxrsTestSuite {
         final BundleJsonWithSubscriptions bundleJsonWithSubscriptions = createBundleWithSubscriptions();
         final InvoiceJsonSimple invoiceJsonSimple = createInvoice();
         final PaymentJsonSimple paymentJsonSimple = createPayment(UUID.fromString(invoiceJsonSimple.getAccountId()),
-                                                                  UUID.fromString(invoiceJsonSimple.getInvoiceId()));
+                UUID.fromString(invoiceJsonSimple.getInvoiceId()));
 
         final BundleTimelineJson bundleTimelineJson = new BundleTimelineJson(viewId,
-                                                                             bundleJsonWithSubscriptions,
-                                                                             ImmutableList.<PaymentJsonSimple>of(paymentJsonSimple),
-                                                                             ImmutableList.<InvoiceJsonSimple>of(invoiceJsonSimple),
-                                                                             reason);
+                bundleJsonWithSubscriptions,
+                ImmutableList.<PaymentJsonSimple>of(paymentJsonSimple),
+                ImmutableList.<InvoiceJsonSimple>of(invoiceJsonSimple),
+                reason);
 
         final String asJson = mapper.writeValueAsString(bundleTimelineJson);
 
@@ -75,41 +75,42 @@ public class TestBundleTimelineJson extends JaxrsTestSuite {
         final InvoiceJsonSimple invoice = bundleTimelineJson.getInvoices().get(0);
 
         Assert.assertEquals(asJson, "{\"viewId\":\"" + bundleTimelineJson.getViewId() + "\"," +
-                                    "\"bundle\":{\"bundleId\":\"" + bundleTimelineJson.getBundle().getBundleId() + "\"," +
-                                    "\"externalKey\":\"" + bundleTimelineJson.getBundle().getExternalKey() + "\"," +
-                                    "\"subscriptions\":" +
-                                    "[{\"events\":[{\"eventId\":\"" + event.getEventId() + "\"," +
-                                    "\"billingPeriod\":\"" + event.getBillingPeriod() + "\"," +
-                                    "\"product\":\"" + event.getProduct() + "\"," +
-                                    "\"priceList\":\"" + event.getPriceList() + "\"," +
-                                    "\"eventType\":\"" + event.getEventType() + "\"," +
-                                    "\"phase\":\"" + event.getPhase() + "\"," +
-                                    "\"requestedDate\":null," +
-                                    "\"effectiveDate\":\"" + event.getEffectiveDate().toDateTimeISO().toString() + "\"}]," +
-                                    "\"subscriptionId\":\"" + subscription.getSubscriptionId() + "\"," +
-                                    "\"deletedEvents\":null," +
-                                    "\"newEvents\":null}]}," +
-                                    "\"payments\":[{\"amount\":" + payment.getAmount() + "," +
-                                    "\"paidAmount\":" + payment.getPaidAmount() + "," +
-                                    "\"accountId\":\"" + payment.getAccountId() + "\"," +
-                                    "\"invoiceId\":\"" + payment.getInvoiceId() + "\"," +
-                                    "\"paymentId\":\"" + payment.getPaymentId() + "\"," +
-                                    "\"requestedDate\":\"" + payment.getRequestedDate().toDateTimeISO().toString() + "\"," +
-                                    "\"effectiveDate\":\"" + payment.getEffectiveDate().toDateTimeISO().toString() + "\"," +
-                                    "\"retryCount\":" + payment.getRetryCount() + "," +
-                                    "\"currency\":\"" + payment.getCurrency() + "\"," +
-                                    "\"status\":\"" + payment.getStatus() + "\"}]," +
-                                    "\"invoices\":[{\"amount\":" + invoice.getAmount() + "," +
-                                    "\"cba\":" + invoice.getCBA() + "," +
-                                    "\"creditAdj\":" + invoice.getCreditAdj() + "," +
-                                    "\"refundAdj\":" + invoice.getRefundAdj() + "," +
-                                    "\"invoiceId\":\"" + invoice.getInvoiceId() + "\"," +
-                                    "\"invoiceDate\":\"" + invoice.getInvoiceDate().toString() + "\"," +
-                                    "\"targetDate\":\"" + invoice.getTargetDate() + "\"," +
-                                    "\"invoiceNumber\":\"" + invoice.getInvoiceNumber() + "\"," +
-                                    "\"balance\":" + invoice.getBalance() + "," +
-                                    "\"accountId\":\"" + invoice.getAccountId() + "\"}]," +
-                                    "\"reasonForChange\":\"" + reason + "\"}");
+            "\"bundle\":{\"bundleId\":\"" + bundleTimelineJson.getBundle().getBundleId() + "\"," +
+            "\"externalKey\":\"" + bundleTimelineJson.getBundle().getExternalKey() + "\"," +
+            "\"subscriptions\":" +
+            "[{\"events\":[{\"eventId\":\"" + event.getEventId() + "\"," +
+            "\"billingPeriod\":\"" + event.getBillingPeriod() + "\"," +
+            "\"product\":\"" + event.getProduct() + "\"," +
+            "\"priceList\":\"" + event.getPriceList() + "\"," +
+            "\"eventType\":\"" + event.getEventType() + "\"," +
+            "\"phase\":\"" + event.getPhase() + "\"," +
+            "\"requestedDate\":null," +
+            "\"effectiveDate\":\"" + event.getEffectiveDate().toDateTimeISO().toString() + "\"}]," +
+            "\"subscriptionId\":\"" + subscription.getSubscriptionId() + "\"," +
+            "\"deletedEvents\":null," +
+            "\"newEvents\":null}]}," +
+            "\"payments\":[{\"amount\":" + payment.getAmount() + "," +
+            "\"paidAmount\":" + payment.getPaidAmount() + "," +
+            "\"accountId\":\"" + payment.getAccountId() + "\"," +
+            "\"invoiceId\":\"" + payment.getInvoiceId() + "\"," +
+            "\"paymentId\":\"" + payment.getPaymentId() + "\"," +
+            "\"paymentMethodId\":\"" + payment.getPaymentMethodId() + "\"," +
+            "\"requestedDate\":\"" + payment.getRequestedDate().toDateTimeISO().toString() + "\"," +
+            "\"effectiveDate\":\"" + payment.getEffectiveDate().toDateTimeISO().toString() + "\"," +
+            "\"retryCount\":" + payment.getRetryCount() + "," +
+            "\"currency\":\"" + payment.getCurrency() + "\"," +
+            "\"status\":\"" + payment.getStatus() + "\"}]," +
+            "\"invoices\":[{\"amount\":" + invoice.getAmount() + "," +
+            "\"cba\":" + invoice.getCBA() + "," +
+            "\"creditAdj\":" + invoice.getCreditAdj() + "," +
+            "\"refundAdj\":" + invoice.getRefundAdj() + "," +
+            "\"invoiceId\":\"" + invoice.getInvoiceId() + "\"," +
+            "\"invoiceDate\":\"" + invoice.getInvoiceDate().toString() + "\"," +
+            "\"targetDate\":\"" + invoice.getTargetDate() + "\"," +
+            "\"invoiceNumber\":\"" + invoice.getInvoiceNumber() + "\"," +
+            "\"balance\":" + invoice.getBalance() + "," +
+            "\"accountId\":\"" + invoice.getAccountId() + "\"}]," +
+            "\"reasonForChange\":\"" + reason + "\"}");
 
         final BundleTimelineJson fromJson = mapper.readValue(asJson, BundleTimelineJson.class);
         Assert.assertEquals(fromJson, bundleTimelineJson);
@@ -120,8 +121,8 @@ public class TestBundleTimelineJson extends JaxrsTestSuite {
         final DateTime effectiveDate = clock.getUTCNow();
         final UUID eventId = UUID.randomUUID();
         final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier(UUID.randomUUID().toString(), ProductCategory.BASE,
-                                                                             BillingPeriod.NO_BILLING_PERIOD, UUID.randomUUID().toString(),
-                                                                             PhaseType.EVERGREEN);
+                BillingPeriod.NO_BILLING_PERIOD, UUID.randomUUID().toString(),
+                PhaseType.EVERGREEN);
         Mockito.when(event.getEffectiveDate()).thenReturn(effectiveDate);
         Mockito.when(event.getEventId()).thenReturn(eventId);
         Mockito.when(event.getSubscriptionTransitionType()).thenReturn(SubscriptionTransitionType.CREATE);
@@ -151,11 +152,12 @@ public class TestBundleTimelineJson extends JaxrsTestSuite {
         final BigDecimal balance = BigDecimal.ZERO;
 
         return new InvoiceJsonSimple(invoiceAmount, cba, creditAdj, refundAdj, invoiceId.toString(), invoiceDate,
-                                     targetDate, invoiceNumber, balance, accountId.toString());
+                targetDate, invoiceNumber, balance, accountId.toString());
     }
 
     private PaymentJsonSimple createPayment(final UUID accountId, final UUID invoiceId) {
         final UUID paymentId = UUID.randomUUID();
+        final UUID paymentMethodId = UUID.randomUUID();
         final BigDecimal paidAmount = BigDecimal.TEN;
         final BigDecimal amount = BigDecimal.ZERO;
         final DateTime paymentRequestedDate = clock.getUTCNow();
@@ -165,7 +167,6 @@ public class TestBundleTimelineJson extends JaxrsTestSuite {
         final String status = UUID.randomUUID().toString();
 
         return new PaymentJsonSimple(amount, paidAmount, accountId.toString(), invoiceId.toString(), paymentId.toString(),
-                                     paymentRequestedDate, paymentEffectiveDate, retryCount,
-                                     currency, status);
+                paymentMethodId.toString(), paymentRequestedDate, paymentEffectiveDate, retryCount, currency, status);
     }
 }
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestInvoice.java b/server/src/test/java/com/ning/billing/jaxrs/TestInvoice.java
index a4c59bc..e586273 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestInvoice.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestInvoice.java
@@ -205,7 +205,7 @@ public class TestInvoice extends TestJaxrsBase {
             }
 
             // CREATE INSTA PAYMENT
-            final PaymentJsonSimple payment = new PaymentJsonSimple(cur.getAmount(), BigDecimal.ZERO, accountJson.getAccountId(), cur.getInvoiceId(), null, null, null, 0, null, null);
+            final PaymentJsonSimple payment = new PaymentJsonSimple(cur.getAmount(), BigDecimal.ZERO, accountJson.getAccountId(), cur.getInvoiceId(), null, null, null, null, 0, null, null);
             final String postJson = mapper.writeValueAsString(payment);
 
             uri = JaxrsResource.INVOICES_PATH + "/" + cur.getInvoiceId() + "/" + JaxrsResource.PAYMENTS;
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestPayment.java b/server/src/test/java/com/ning/billing/jaxrs/TestPayment.java
index 3ca0383..c47efdf 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestPayment.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestPayment.java
@@ -29,6 +29,7 @@ import com.ning.billing.catalog.api.ProductCategory;
 import com.ning.billing.jaxrs.json.AccountJson;
 import com.ning.billing.jaxrs.json.BundleJsonNoSubscriptions;
 import com.ning.billing.jaxrs.json.PaymentJsonSimple;
+import com.ning.billing.jaxrs.json.PaymentMethodJson;
 import com.ning.billing.jaxrs.json.RefundJson;
 import com.ning.billing.jaxrs.json.SubscriptionJsonNoEvents;
 import com.ning.billing.jaxrs.resources.JaxrsResource;
@@ -66,6 +67,14 @@ public class TestPayment extends TestJaxrsBase {
         final String paymentId = objFromJson.get(0).getPaymentId();
         final BigDecimal paymentAmount = objFromJson.get(0).getAmount();
 
+        final String paymentMethodId = objFromJson.get(0).getPaymentMethodId();
+        uri = JaxrsResource.PAYMENT_METHODS_PATH + "/" + paymentMethodId;
+        response = doGet(uri, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
+        Assert.assertEquals(response.getStatusCode(), Status.OK.getStatusCode());
+        final PaymentMethodJson paymentMethodJson = mapper.readValue(response.getResponseBody(), PaymentMethodJson.class);
+        Assert.assertEquals(paymentMethodJson.getPaymentMethodId(), paymentMethodId);
+        Assert.assertEquals(paymentMethodJson.getAccountId(), accountJson.getAccountId());
+
         uri = JaxrsResource.PAYMENTS_PATH + "/" + paymentId + "/" + JaxrsResource.REFUNDS;
         response = doGet(uri, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
         Assert.assertEquals(response.getStatusCode(), Status.OK.getStatusCode());