killbill-aplcache

Code review for e8bca41ce466d4b5832c7943d6ba0175e6f64d0e: Add

6/6/2015 7:08:40 PM

Details

diff --git a/payment/src/test/java/org/killbill/billing/payment/dao/TestPaymentDao.java b/payment/src/test/java/org/killbill/billing/payment/dao/TestPaymentDao.java
index d0ee734..0b1d03f 100644
--- a/payment/src/test/java/org/killbill/billing/payment/dao/TestPaymentDao.java
+++ b/payment/src/test/java/org/killbill/billing/payment/dao/TestPaymentDao.java
@@ -319,7 +319,7 @@ public class TestPaymentDao extends PaymentTestSuiteWithEmbeddedDB {
     }
 
     @Test(groups = "slow")
-    public void testPaymentByStates() {
+    public void testPaymentByStatesAcrossTenants() {
 
         final UUID paymentMethodId = UUID.randomUUID();
         final UUID accountId = UUID.randomUUID();
@@ -350,8 +350,8 @@ public class TestPaymentDao extends PaymentTestSuiteWithEmbeddedDB {
                                                                                        TransactionStatus.UNKNOWN, BigDecimal.TEN, Currency.AED,
                                                                                        "unknown", "");
 
-        final InternalCallContext context1 = new InternalCallContext(internalCallContext.getTenantRecordId(),
-                                                                     internalCallContext.getAccountRecordId(),
+        final InternalCallContext context1 = new InternalCallContext(1L,
+                                                                     1L,
                                                                      internalCallContext.getUserToken(),
                                                                      internalCallContext.getCreatedBy(),
                                                                      internalCallContext.getCallOrigin(),
@@ -372,8 +372,8 @@ public class TestPaymentDao extends PaymentTestSuiteWithEmbeddedDB {
                                                                                        TransactionStatus.UNKNOWN, BigDecimal.TEN, Currency.AED,
                                                                                        "unknown", "");
 
-        final InternalCallContext context2 = new InternalCallContext(internalCallContext.getTenantRecordId(),
-                                                                     internalCallContext.getAccountRecordId(),
+        final InternalCallContext context2 = new InternalCallContext(2L,
+                                                                     2L,
                                                                      internalCallContext.getUserToken(),
                                                                      internalCallContext.getCreatedBy(),
                                                                      internalCallContext.getCallOrigin(),
@@ -393,8 +393,8 @@ public class TestPaymentDao extends PaymentTestSuiteWithEmbeddedDB {
                                                                                        TransactionStatus.UNKNOWN, BigDecimal.TEN, Currency.AED,
                                                                                        "unknown", "");
 
-        final InternalCallContext context3 = new InternalCallContext(internalCallContext.getTenantRecordId(),
-                                                                     internalCallContext.getAccountRecordId(),
+        final InternalCallContext context3 = new InternalCallContext(3L,
+                                                                     3L,
                                                                      internalCallContext.getUserToken(),
                                                                      internalCallContext.getCreatedBy(),
                                                                      internalCallContext.getCallOrigin(),
@@ -416,8 +416,8 @@ public class TestPaymentDao extends PaymentTestSuiteWithEmbeddedDB {
                                                                                        TransactionStatus.UNKNOWN, BigDecimal.TEN, Currency.AED,
                                                                                        "unknown", "");
 
-        final InternalCallContext context4 = new InternalCallContext(internalCallContext.getTenantRecordId(),
-                                                                     internalCallContext.getAccountRecordId(),
+        final InternalCallContext context4 = new InternalCallContext(4L,
+                                                                     4L,
                                                                      internalCallContext.getUserToken(),
                                                                      internalCallContext.getCreatedBy(),
                                                                      internalCallContext.getCallOrigin(),
@@ -438,8 +438,8 @@ public class TestPaymentDao extends PaymentTestSuiteWithEmbeddedDB {
                                                                                        TransactionStatus.UNKNOWN, BigDecimal.TEN, Currency.AED,
                                                                                        "unknown", "");
 
-        final InternalCallContext context5 = new InternalCallContext(internalCallContext.getTenantRecordId(),
-                                                                     internalCallContext.getAccountRecordId(),
+        final InternalCallContext context5 = new InternalCallContext(5L,
+                                                                     5L,
                                                                      internalCallContext.getUserToken(),
                                                                      internalCallContext.getCreatedBy(),
                                                                      internalCallContext.getCallOrigin(),
@@ -456,6 +456,63 @@ public class TestPaymentDao extends PaymentTestSuiteWithEmbeddedDB {
         assertEquals(result.size(), 2);
     }
 
+    @Test(groups = "slow")
+    public void testPaymentAttemptsByStateAcrossTenants() {
+
+        final UUID paymentMethodId = UUID.randomUUID();
+        final UUID accountId = UUID.randomUUID();
+        final String externalKey1 = "gfhfg";
+        final String transactionExternalKey1 = "sadas";
+
+        final String externalKey2 = "asdwqeqw";
+        final String transactionExternalKey2 = "fghfg";
+
+        final DateTime createdAfterDate = clock.getUTCNow().minusDays(10);
+        final DateTime createdBeforeDate = clock.getUTCNow().minusDays(1);
+
+        final String stateName = "FOO";
+        final String pluginName = "miraculous";
+
+        final PaymentAttemptModelDao attempt1 = new PaymentAttemptModelDao(accountId, paymentMethodId, createdAfterDate, createdAfterDate, externalKey1,
+                                                                     UUID.randomUUID(), transactionExternalKey1, TransactionType.AUTHORIZE, stateName, BigDecimal.ONE, Currency.USD,
+                                                                     ImmutableList.<String>of(pluginName), null);
+
+
+        final PaymentAttemptModelDao attempt2 = new PaymentAttemptModelDao(accountId, paymentMethodId, createdAfterDate, createdAfterDate, externalKey2,
+                                                                     UUID.randomUUID(), transactionExternalKey2, TransactionType.AUTHORIZE, stateName, BigDecimal.ONE, Currency.USD,
+                                                                     ImmutableList.<String>of(pluginName), null);
+
+        final InternalCallContext context1 = new InternalCallContext(1L,
+                                                                     1L,
+                                                                     internalCallContext.getUserToken(),
+                                                                     internalCallContext.getCreatedBy(),
+                                                                     internalCallContext.getCallOrigin(),
+                                                                     internalCallContext.getContextUserType(),
+                                                                     internalCallContext.getReasonCode(),
+                                                                     internalCallContext.getComments(),
+                                                                     createdAfterDate,
+                                                                     createdAfterDate);
+        paymentDao.insertPaymentAttemptWithProperties(attempt1, context1);
+
+
+        final InternalCallContext context2 = new InternalCallContext(2L,
+                                                                     2L,
+                                                                     internalCallContext.getUserToken(),
+                                                                     internalCallContext.getCreatedBy(),
+                                                                     internalCallContext.getCallOrigin(),
+                                                                     internalCallContext.getContextUserType(),
+                                                                     internalCallContext.getReasonCode(),
+                                                                     internalCallContext.getComments(),
+                                                                     createdAfterDate,
+                                                                     createdAfterDate);
+        paymentDao.insertPaymentAttemptWithProperties(attempt2, context2);
+
+
+        final List<PaymentAttemptModelDao> result = paymentDao.getPaymentAttemptsByStateAcrossTenants(stateName, createdBeforeDate);
+        Assert.assertEquals(result.size(), 2);
+    }
+
+
     private List<PaymentTransactionModelDao> getPendingTransactions(final UUID paymentId) {
         final List<PaymentTransactionModelDao> total = paymentDao.getTransactionsForPayment(paymentId, internalCallContext);
         return ImmutableList.copyOf(Iterables.filter(total, new Predicate<PaymentTransactionModelDao>() {