diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
index 943f470..1656428 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
@@ -94,7 +94,7 @@ public class TestIntegration extends TestIntegrationBase {
// STEPH set to disabled until test written properly and fixed
- @Test(groups = "slow", enabled = false)
+ @Test(groups = "slow", enabled = true)
public void testRepairChangeBPWithAddonIncluded() throws Exception {
log.info("Starting testRepairChangeBPWithAddonIncluded");
@@ -117,6 +117,7 @@ public class TestIntegration extends TestIntegrationBase {
new PlanPhaseSpecifier(productName, ProductCategory.BASE, term, planSetName, null), null, context));
assertNotNull(baseSubscription);
assertTrue(busHandler.isCompleted(DELAY));
+ assertListenerStatus();
// MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3));
@@ -128,6 +129,8 @@ public class TestIntegration extends TestIntegrationBase {
subscriptionDataFromSubscription(entitlementUserApi.createSubscription(bundle.getId(),
new PlanPhaseSpecifier("Telescopic-Scope", ProductCategory.ADD_ON, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null), null, context));
assertTrue(busHandler.isCompleted(DELAY));
+ assertListenerStatus();
+
busHandler.pushExpectedEvent(NextEvent.CREATE);
busHandler.pushExpectedEvent(NextEvent.INVOICE);
@@ -135,20 +138,49 @@ public class TestIntegration extends TestIntegrationBase {
SubscriptionData aoSubscription2 = subscriptionDataFromSubscription(entitlementUserApi.createSubscription(bundle.getId(),
new PlanPhaseSpecifier("Laser-Scope", ProductCategory.ADD_ON, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null), null, context));
assertTrue(busHandler.isCompleted(DELAY));
-
+ assertListenerStatus();
// MOVE CLOCK A LITTLE BIT MORE -- EITHER STAY IN TRIAL OR GET OUT
- int duration = 35;
+ // 26 / 5
+ int duration = 28;
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(duration));
busHandler.pushExpectedEvent(NextEvent.PHASE);
- busHandler.pushExpectedEvent(NextEvent.PHASE);
- busHandler.pushExpectedEvent(NextEvent.PHASE);
+ busHandler.pushExpectedEvent(NextEvent.PHASE);
+ busHandler.pushExpectedEvent(NextEvent.INVOICE);
+ busHandler.pushExpectedEvent(NextEvent.PAYMENT);
+ clock.addDeltaFromReality(it.toDurationMillis());
+ assertTrue(busHandler.isCompleted(DELAY));
+ assertListenerStatus();
+
+ // 29 / 5
+ it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3));
+ busHandler.pushExpectedEvent(NextEvent.PHASE);
busHandler.pushExpectedEvent(NextEvent.INVOICE);
busHandler.pushExpectedEvent(NextEvent.PAYMENT);
clock.addDeltaFromReality(it.toDurationMillis());
assertTrue(busHandler.isCompleted(DELAY));
+ assertListenerStatus();
+
+ // 8 / 6
+ it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(10));
+ clock.addDeltaFromReality(it.toDurationMillis());
+ assertTrue(busHandler.isCompleted(DELAY));
+ assertListenerStatus();
+
+ // 26 / 6
+ it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(18));
+ busHandler.pushExpectedEvent(NextEvent.INVOICE);
+ busHandler.pushExpectedEvent(NextEvent.PAYMENT);
+ clock.addDeltaFromReality(it.toDurationMillis());
+ assertTrue(busHandler.isCompleted(DELAY));
+ assertListenerStatus();
+ it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3));
+ clock.addDeltaFromReality(it.toDurationMillis());
+ assertTrue(busHandler.isCompleted(DELAY));
assertListenerStatus();
+
+
}
@Test(groups = {"slow"})
diff --git a/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoiceGenerator.java b/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoiceGenerator.java
index 08e19c0..12a7b04 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoiceGenerator.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoiceGenerator.java
@@ -70,8 +70,6 @@ public class DefaultInvoiceGenerator implements InvoiceGenerator {
}
validateTargetDate(targetDate);
- //TODO MDW can use subscription Id - not bundle
- //TODO MDW worry about null sub id
List<InvoiceItem> existingItems = new ArrayList<InvoiceItem>();
if (existingInvoices != null) {
diff --git a/junction/src/main/java/com/ning/billing/junction/plumbing/billing/DefaultBillingEvent.java b/junction/src/main/java/com/ning/billing/junction/plumbing/billing/DefaultBillingEvent.java
index 35bc837..f493a32 100644
--- a/junction/src/main/java/com/ning/billing/junction/plumbing/billing/DefaultBillingEvent.java
+++ b/junction/src/main/java/com/ning/billing/junction/plumbing/billing/DefaultBillingEvent.java
@@ -55,7 +55,7 @@ public class DefaultBillingEvent implements BillingEvent {
this.account = account;
this.billCycleDay = billCycleDay;
this.subscription = subscription;
- effectiveDate = transition.getEffectiveTransitionTime();
+ effectiveDate = truncateEffectiveDateInTimeZone(transition, account);
String planPhaseName = (transition.getTransitionType() != SubscriptionTransitionType.CANCEL) ?
transition.getNextPhase() : transition.getPreviousPhase();
planPhase = (planPhaseName != null) ? catalog.findPhase(planPhaseName, transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null;
@@ -84,6 +84,11 @@ public class DefaultBillingEvent implements BillingEvent {
totalOrdering = transition.getTotalOrdering();
}
+ private DateTime truncateEffectiveDateInTimeZone(SubscriptionEvent transition, Account account) {
+ DateTime originalTime = transition.getEffectiveTransitionTime().toDateTime(account.getTimeZone());
+ return new DateTime(originalTime.getYear(), originalTime.getMonthOfYear(), originalTime.getDayOfMonth(),0,0);
+ }
+
public DefaultBillingEvent(Account account, Subscription subscription, DateTime effectiveDate, Plan plan, PlanPhase planPhase,
BigDecimal fixedPrice, BigDecimal recurringPrice, Currency currency,
BillingPeriod billingPeriod, int billCycleDay, BillingModeType billingModeType,
diff --git a/util/src/test/java/com/ning/billing/api/TestApiListener.java b/util/src/test/java/com/ning/billing/api/TestApiListener.java
index 9eddf7b..5a9d762 100644
--- a/util/src/test/java/com/ning/billing/api/TestApiListener.java
+++ b/util/src/test/java/com/ning/billing/api/TestApiListener.java
@@ -225,7 +225,7 @@ public class TestApiListener {
}
if (!foundIt && !nonExpectedMode) {
Joiner joiner = Joiner.on(" ");
- log.error("TestApiListener Received event " + received + "; expecting " + joiner.join(nextExpectedEvent));
+ log.error("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TestApiListener Received event " + received + "; expecting " + joiner.join(nextExpectedEvent) + "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
if (testStatus != null) {
testStatus.failed("TestApiListener [ApiListenerStatus]: Received event " + received + "; expecting " + joiner.join(nextExpectedEvent));
}