Details
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/inv_ent/TestBasic.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/inv_ent/TestBasic.java
index 9665d8d..7c89c41 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/inv_ent/TestBasic.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/inv_ent/TestBasic.java
@@ -169,11 +169,26 @@ public class TestBasic {
return ctd;
}
+
+ @Test(groups = "fast", enabled = true)
+ public void testBasePlanCompleteWithBillingDayInPast() throws Exception {
+ testBasePlanComplete(clock.getUTCNow().minusDays(1).getDayOfMonth());
+ }
+
+ @Test(groups = "fast", enabled = true)
+ public void testBasePlanCompleteWithBillingDayPresent() throws Exception {
+ testBasePlanComplete(clock.getUTCNow().getDayOfMonth());
+ }
+
@Test(groups = "fast", enabled = true)
- public void testBasePlanComplete() throws Exception {
+ public void testBasePlanCompleteWithBillingDayInFuture() throws Exception {
+ testBasePlanComplete(clock.getUTCNow().plusDays(1).getDayOfMonth());
+ }
+
+ private void testBasePlanComplete(int billingDay) throws Exception {
long DELAY = 5000;
- Account account = accountUserApi.createAccount(getAccountData(), null, null);
+ Account account = accountUserApi.createAccount(getAccountData(billingDay), null, null);
assertNotNull(account);
SubscriptionBundle bundle = entitlementUserApi.createBundleForAccount(account.getId(), "whatever");
@@ -237,8 +252,8 @@ public class TestBasic {
//
busHandler.pushExpectedEvent(NextEvent.CHANGE);
busHandler.pushExpectedEvent(NextEvent.INVOICE);
+
clock.addDeltaFromReality(ctd.getMillis() - clock.getUTCNow().getMillis());
- //clock.setDeltaFromReality(AT_LEAST_ONE_MONTH_MS + 1000);
assertTrue(busHandler.isCompleted(DELAY));
log.info("testSimple passed fourth busHandler checkpoint.");
@@ -275,7 +290,7 @@ public class TestBasic {
}
- protected AccountData getAccountData() {
+ protected AccountData getAccountData(final int billCycleDay) {
AccountData accountData = new AccountData() {
@Override
public String getName() {
@@ -299,7 +314,7 @@ public class TestBasic {
}
@Override
public int getBillCycleDay() {
- return 1;
+ return billCycleDay;
}
@Override
public Currency getCurrency() {
diff --git a/beatrix/src/test/resources/resource.properties b/beatrix/src/test/resources/resource.properties
index 1cf5ad0..cc82754 100644
--- a/beatrix/src/test/resources/resource.properties
+++ b/beatrix/src/test/resources/resource.properties
@@ -1,4 +1,4 @@
-killbill.catalog.uri=file:beatrix/src/test/resources/catalogSample.xml
+killbill.catalog.uri=file:src/test/resources/catalogSample.xml
killbill.entitlement.dao.claim.time=60000
killbill.entitlement.dao.ready.max=1
killbill.entitlement.engine.notifications.sleep=500
diff --git a/util/src/test/java/com/ning/billing/util/clock/ClockMock.java b/util/src/test/java/com/ning/billing/util/clock/ClockMock.java
index 7698697..72fd8f4 100644
--- a/util/src/test/java/com/ning/billing/util/clock/ClockMock.java
+++ b/util/src/test/java/com/ning/billing/util/clock/ClockMock.java
@@ -19,6 +19,8 @@ package com.ning.billing.util.clock;
import com.ning.billing.catalog.api.Duration;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
@@ -26,6 +28,8 @@ import java.util.List;
// STEPH should really be in tests but not accessible from other sub modules
public class ClockMock extends DefaultClock {
+ private static final Logger log = LoggerFactory.getLogger(ClockMock.class);
+
private enum DeltaType {
DELTA_NONE,
DELTA_DURATION,
@@ -54,35 +58,47 @@ public class ClockMock extends DefaultClock {
return getNow(DateTimeZone.UTC);
}
+ private void logClockAdjustement(DateTime prev, DateTime next) {
+ log.info(String.format(" ************ ADJUSTING CLOCK FROM %s to %s ********************", prev, next));
+ }
+
public synchronized void setDeltaFromReality(Duration delta, long epsilon) {
+ DateTime prev = getUTCNow();
deltaType = DeltaType.DELTA_DURATION;
deltaFromRealityDuration = new ArrayList<Duration>();
deltaFromRealityDuration.add(delta);
deltaFromRealitDurationEpsilon = epsilon;
deltaFromRealityMs = 0;
+ logClockAdjustement(prev, getUTCNow());
}
public synchronized void addDeltaFromReality(Duration delta) {
+ DateTime prev = getUTCNow();
if (deltaType != DeltaType.DELTA_DURATION) {
throw new RuntimeException("ClockMock should be set with type DELTA_DURATION");
}
deltaFromRealityDuration.add(delta);
+ logClockAdjustement(prev, getUTCNow());
}
public synchronized void setDeltaFromReality(long delta) {
+ DateTime prev = getUTCNow();
deltaType = DeltaType.DELTA_ABS;
deltaFromRealityDuration = null;
deltaFromRealitDurationEpsilon = 0;
deltaFromRealityMs = delta;
+ logClockAdjustement(prev, getUTCNow());
}
public synchronized void addDeltaFromReality(long delta) {
+ DateTime prev = getUTCNow();
if (deltaType != DeltaType.DELTA_ABS) {
throw new RuntimeException("ClockMock should be set with type DELTA_ABS");
}
deltaFromRealityDuration = null;
deltaFromRealitDurationEpsilon = 0;
deltaFromRealityMs += delta;
+ logClockAdjustement(prev, getUTCNow());
}
public synchronized void resetDeltaFromReality() {