diff --git a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestBillingAlignment.java b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestBillingAlignment.java
index 086fab5..7ac14f6 100644
--- a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestBillingAlignment.java
+++ b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestBillingAlignment.java
@@ -21,8 +21,6 @@ package org.killbill.billing.beatrix.integration.overdue;
import java.math.BigDecimal;
import org.joda.time.LocalDate;
-import org.testng.annotations.Test;
-
import org.killbill.billing.account.api.Account;
import org.killbill.billing.api.TestApiListener.NextEvent;
import org.killbill.billing.beatrix.integration.TestIntegrationBase;
@@ -31,22 +29,18 @@ import org.killbill.billing.catalog.api.BillingPeriod;
import org.killbill.billing.catalog.api.ProductCategory;
import org.killbill.billing.entitlement.api.DefaultEntitlement;
import org.killbill.billing.invoice.api.InvoiceItemType;
+import org.killbill.billing.subscription.api.user.SubscriptionBaseTransition;
+import org.testng.Assert;
+import org.testng.annotations.Test;
import static org.testng.Assert.assertNotNull;
public class TestBillingAlignment extends TestIntegrationBase {
- // TODO test fails as it should not create a proration when the chnage to annual occurs. Instaed we should restart from the data of the chnage
- // since we have as a catalog rule:
- // <billingAlignmentCase>
- // <billingPeriod>ANNUAL</billingPeriod>
- // <alignment>SUBSCRIPTION</alignment>
- // </billingAlignmentCase>
- //
- @Test(groups = "slow", enabled = false)
- public void testTransitonAccountBAToSubscriptionBA() throws Exception {
-
- final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(1));
+ @Test(groups = "slow")
+ public void testTransitionAccountBAToSubscriptionBA() throws Exception {
+ // Set the BCD to the 25th
+ final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(25));
// We take april as it has 30 days (easier to play with BCD)
// Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
@@ -54,17 +48,44 @@ public class TestBillingAlignment extends TestIntegrationBase {
//
// CREATE SUBSCRIPTION AND EXPECT BOTH EVENTS: NextEvent.CREATE NextEvent.INVOICE
- // (Start with monthly that has a 'Account' billing alignment
+ // (Start with monthly that has an 'Account' billing alignment)
//
final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.INVOICE);
assertNotNull(bpEntitlement);
+
invoiceChecker.checkInvoice(account.getId(), 1, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 4, 1), null, InvoiceItemType.FIXED, new BigDecimal("0")));
+ invoiceChecker.checkChargedThroughDate(bpEntitlement.getId(), new LocalDate(2012, 4, 1), callContext);
- // GET OUT TRIAL
+ // GET OUT TRIAL (moving clock to 2012-05-04)
addDaysAndCheckForCompletion(33, NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
- //
- // Change plan to annual that has been configured to have a 'SubscriptionBase' billing alignment
- changeEntitlementAndCheckForCompletion(bpEntitlement, "Shotgun", BillingPeriod.ANNUAL, null, NextEvent.CHANGE, NextEvent.INVOICE);
+ invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 5, 25), InvoiceItemType.RECURRING, new BigDecimal("199.96")));
+ invoiceChecker.checkChargedThroughDate(bpEntitlement.getId(), new LocalDate(2012, 5, 25), callContext);
+
+ // Change plan to annual that has been configured to have a 'Subscription' billing alignment
+ final DefaultEntitlement changedBpEntitlement = changeEntitlementAndCheckForCompletion(bpEntitlement, "Shotgun", BillingPeriod.ANNUAL, null, NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.PAYMENT);
+
+ invoiceChecker.checkInvoice(account.getId(),
+ 3,
+ callContext,
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 4), new LocalDate(2013, 5, 1), InvoiceItemType.RECURRING, new BigDecimal("2380.22")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 4), new LocalDate(2012, 5, 25), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-174.97")));
+ invoiceChecker.checkChargedThroughDate(bpEntitlement.getId(), new LocalDate(2013, 5, 1), callContext);
+
+ Assert.assertEquals(changedBpEntitlement.getSubscriptionBase().getAllTransitions().size(), 3);
+
+ final SubscriptionBaseTransition trial = changedBpEntitlement.getSubscriptionBase().getAllTransitions().get(0);
+ Assert.assertEquals(trial.getEffectiveTransitionTime().toLocalDate().compareTo(new LocalDate(2012, 4, 1)), 0);
+ Assert.assertEquals(trial.getNextPhase().getName(), "shotgun-monthly-trial");
+
+ final SubscriptionBaseTransition smEvergreen = changedBpEntitlement.getSubscriptionBase().getAllTransitions().get(1);
+ Assert.assertEquals(smEvergreen.getEffectiveTransitionTime().toLocalDate().compareTo(new LocalDate(2012, 5, 1)), 0);
+ Assert.assertEquals(smEvergreen.getNextPhase().getName(), "shotgun-monthly-evergreen");
+
+ final SubscriptionBaseTransition saEvergreen = changedBpEntitlement.getSubscriptionBase().getAllTransitions().get(2);
+ // Verify the IMMEDIATE policy
+ Assert.assertEquals(saEvergreen.getEffectiveTransitionTime().toLocalDate().compareTo(new LocalDate(2012, 5, 4)), 0);
+ // Verify the START_OF_SUBSCRIPTION alignment (both plans have the same 30 days trial)
+ Assert.assertEquals(saEvergreen.getNextPhase().getName(), "shotgun-annual-evergreen");
}
}