killbill-memoizeit

Details

diff --git a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationWithCatalogUpdate.java b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationWithCatalogUpdate.java
index cd82660..3575872 100644
--- a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationWithCatalogUpdate.java
+++ b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationWithCatalogUpdate.java
@@ -359,9 +359,44 @@ public class TestIntegrationWithCatalogUpdate extends TestIntegrationBase {
 
         refreshedBaseEntitlement2 = subscriptionApi.getSubscriptionForEntitlementId(baseEntitlement2.getId(), testCallContext);
         assertEquals(refreshedBaseEntitlement2.getChargedThroughDate(), new LocalDate(2017, 1, 1));
+    }
+
+
+    @Test(groups = "slow")
+    public void testWithWeeklyTrials() throws Exception {
+
+        // Create a per-tenant catalog with one plan
+        final SimplePlanDescriptor simplePlanDescriptor = new DefaultSimplePlanDescriptor("hello-monthly", "Hello", ProductCategory.BASE, account.getCurrency(), BigDecimal.ONE, BillingPeriod.MONTHLY, 1, TimeUnit.WEEKS, ImmutableList.<String>of());
+        catalogUserApi.addSimplePlan(simplePlanDescriptor, init, testCallContext);
+        StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
+        assertEquals(catalog.getCurrentPlans().size(), 1);
+
+        final PlanPhaseSpecifier planPhaseSpec = new PlanPhaseSpecifier("hello-monthly", null);
+
+        busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
+        final Entitlement baseEntitlement = entitlementApi.createBaseEntitlement(account.getId(), planPhaseSpec, UUID.randomUUID().toString(), ImmutableList.<PlanPhasePriceOverride>of(), null, null, false, ImmutableList.<PluginProperty>of(), testCallContext);
+        assertListenerStatus();
+
+        Subscription refreshedBaseEntitlement = subscriptionApi.getSubscriptionForEntitlementId(baseEntitlement.getId(), testCallContext);
+        assertEquals(refreshedBaseEntitlement.getChargedThroughDate(), new LocalDate(2016, 6, 1));
+
+        busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
+        clock.addWeeks(1);
+        assertListenerStatus();
 
+        refreshedBaseEntitlement = subscriptionApi.getSubscriptionForEntitlementId(baseEntitlement.getId(), testCallContext);
+        assertEquals(refreshedBaseEntitlement.getChargedThroughDate(), new LocalDate(2016, 7, 8));
+
+        busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
+        clock.addMonths(1);
+        assertListenerStatus();
+
+
+        refreshedBaseEntitlement = subscriptionApi.getSubscriptionForEntitlementId(baseEntitlement.getId(), testCallContext);
+        assertEquals(refreshedBaseEntitlement.getChargedThroughDate(), new LocalDate(2016, 8, 8));
     }
 
+
     private Entitlement createEntitlement(final String planName, final boolean expectPayment) throws EntitlementApiException {
         final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(planName, null);
         return createEntitlement(spec, null, expectPayment);
@@ -392,7 +427,7 @@ public class TestIntegrationWithCatalogUpdate extends TestIntegrationBase {
 
     private void setupAccount() throws Exception {
 
-        final AccountData accountData = getAccountData(1);
+        final AccountData accountData = getAccountData(0);
         account = accountUserApi.createAccount(accountData, testCallContext);
         assertNotNull(account);
 
diff --git a/catalog/src/main/java/org/killbill/billing/catalog/DefaultDuration.java b/catalog/src/main/java/org/killbill/billing/catalog/DefaultDuration.java
index 5f76433..f993a03 100644
--- a/catalog/src/main/java/org/killbill/billing/catalog/DefaultDuration.java
+++ b/catalog/src/main/java/org/killbill/billing/catalog/DefaultDuration.java
@@ -71,6 +71,8 @@ public class DefaultDuration extends ValidatingConfig<StandaloneCatalog> impleme
         switch (unit) {
             case DAYS:
                 return dateTime.plusDays(number);
+            case WEEKS:
+                return dateTime.plusWeeks(number);
             case MONTHS:
                 return dateTime.plusMonths(number);
             case YEARS:
@@ -90,6 +92,8 @@ public class DefaultDuration extends ValidatingConfig<StandaloneCatalog> impleme
         switch (unit) {
             case DAYS:
                 return localDate.plusDays(number);
+            case WEEKS:
+                return localDate.plusWeeks(number);
             case MONTHS:
                 return localDate.plusMonths(number);
             case YEARS:
@@ -145,6 +149,8 @@ public class DefaultDuration extends ValidatingConfig<StandaloneCatalog> impleme
         switch (unit) {
             case DAYS:
                 return new Period().withDays(number);
+            case WEEKS:
+                return new Period().withWeeks(number);
             case MONTHS:
                 return new Period().withMonths(number);
             case YEARS:
diff --git a/overdue/src/main/java/org/killbill/billing/overdue/config/DefaultDuration.java b/overdue/src/main/java/org/killbill/billing/overdue/config/DefaultDuration.java
index 49396ea..3ae374c 100644
--- a/overdue/src/main/java/org/killbill/billing/overdue/config/DefaultDuration.java
+++ b/overdue/src/main/java/org/killbill/billing/overdue/config/DefaultDuration.java
@@ -58,6 +58,8 @@ public class DefaultDuration extends ValidatingConfig<DefaultOverdueConfig> impl
         switch (unit) {
             case DAYS:
                 return dateTime.plusDays(number);
+            case WEEKS:
+                return dateTime.plusWeeks(number);
             case MONTHS:
                 return dateTime.plusMonths(number);
             case YEARS:
@@ -77,6 +79,8 @@ public class DefaultDuration extends ValidatingConfig<DefaultOverdueConfig> impl
         switch (unit) {
             case DAYS:
                 return localDate.plusDays(number);
+            case WEEKS:
+                return localDate.plusWeeks(number);
             case MONTHS:
                 return localDate.plusMonths(number);
             case YEARS:
@@ -95,6 +99,8 @@ public class DefaultDuration extends ValidatingConfig<DefaultOverdueConfig> impl
         switch (unit) {
             case DAYS:
                 return new Period().withDays(number);
+            case WEEKS:
+                return new Period().withWeeks(number);
             case MONTHS:
                 return new Period().withMonths(number);
             case YEARS: