killbill-uncached

Details

beatrix/pom.xml 5(+5 -0)

diff --git a/beatrix/pom.xml b/beatrix/pom.xml
index da3f0e6..0e5dc26 100644
--- a/beatrix/pom.xml
+++ b/beatrix/pom.xml
@@ -102,6 +102,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>com.ning.billing</groupId>
+            <artifactId>killbill-overdue</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.jdbi</groupId>
             <artifactId>jdbi</artifactId>
             <scope>test</scope>
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigration.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigration.java
index 7380ec9..0353bb7 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigration.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigration.java
@@ -155,8 +155,9 @@ public abstract class TestMigration extends TestApiBase {
 
             testListener.pushNextApiExpectedEvent(NextEvent.MIGRATE_BILLING);
             testListener.pushNextApiExpectedEvent(NextEvent.CANCEL);
-            Duration oneYear = getDurationYear(1);
-            clock.setDeltaFromReality(oneYear, 0);
+ //           Duration oneYear = getDurationYear(1);
+ //           clock.setDeltaFromReality(oneYear, 0);
+            clock.addYears(1);
             assertTrue(testListener.isApiCompleted(5000));
 
             assertDateWithin(subscription.getStartDate(), beforeMigration, afterMigration);
@@ -201,7 +202,8 @@ public abstract class TestMigration extends TestApiBase {
             testListener.pushNextApiExpectedEvent(NextEvent.MIGRATE_BILLING);
             testListener.pushNextApiExpectedEvent(NextEvent.PHASE);
             Duration thirtyDays = getDurationDay(30);
-            clock.setDeltaFromReality(thirtyDays, 0);
+           // clock.setDeltaFromReality(thirtyDays, 0);
+            clock.addDays(30);
             assertTrue(testListener.isApiCompleted(5000));
 
             assertEquals(subscription.getStartDate(), trialDate);
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/TestApiBase.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/TestApiBase.java
index ef82964..62d905a 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/TestApiBase.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/TestApiBase.java
@@ -321,7 +321,7 @@ public abstract class TestApiBase {
 
             @Override
             public DateTime addToDateTime(DateTime dateTime) {
-                return null;  //To change body of implemented methods use File | Settings | File Templates.
+                return dateTime.plusYears(years);  
             }
             @Override
             public Period toJodaPeriod() {
diff --git a/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueState.java b/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueState.java
index 7d84e7c..9a448c2 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueState.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueState.java
@@ -42,12 +42,12 @@ public class DefaultOverdueState<T extends Blockable> extends ValidatingConfig<O
 
 	@XmlElement(required=false, name="externalMessage")
 	private String externalMessage = "";
-
-    @XmlElement(required=false, name="disableEntitlementAndChangesBlocked")
-    private Boolean disableEntitlement = false;
     
     @XmlElement(required=false, name="blockChanges")
     private Boolean blockChanges = false;
+
+    @XmlElement(required=false, name="disableEntitlementAndChangesBlocked")
+    private Boolean disableEntitlement = false;
     
     @XmlElement(required=false, name="daysBetweenPaymentRetries")
     private Integer daysBetweenPaymentRetries = 8;

pom.xml 12(+12 -0)

diff --git a/pom.xml b/pom.xml
index 02b1aa6..7fe6a40 100644
--- a/pom.xml
+++ b/pom.xml
@@ -176,6 +176,18 @@
             </dependency>
             <dependency>
                 <groupId>com.ning.billing</groupId>
+                <artifactId>killbill-overdue</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.ning.billing</groupId>
+                <artifactId>killbill-overdue</artifactId>
+                <version>${project.version}</version>
+                <type>test-jar</type>
+                <scope>test</scope>
+            </dependency>
+            <dependency>
+                <groupId>com.ning.billing</groupId>
                 <artifactId>killbill-util</artifactId>
                 <version>${project.version}</version>
                 <type>test-jar</type>
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 9e51a80..9f4da5e 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
@@ -16,147 +16,116 @@
 
 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;
-
-// STEPH should really be in tests but not accessible from other sub modules
-public class ClockMock extends DefaultClock {
+import com.ning.billing.catalog.api.Duration;
+import com.ning.billing.catalog.api.TimeUnit;
 
+public class ClockMock implements Clock {
     private static final Logger log = LoggerFactory.getLogger(ClockMock.class);
-
-    private enum DeltaType {
-        DELTA_NONE,
-        DELTA_DURATION,
-        DELTA_ABS
-    }
-
-    private long deltaFromRealityMs;
-    private List<Duration> deltaFromRealityDuration;
-    private long deltaFromRealityDurationEpsilon;
-    private DeltaType deltaType;
-
-    public ClockMock() {
-        deltaType = DeltaType.DELTA_NONE;
-        deltaFromRealityMs = 0;
-        deltaFromRealityDurationEpsilon = 0;
-        deltaFromRealityDuration = null;
-    }
-
+    DateTime currentTime = new DateTime(DateTimeZone.UTC);
+     
     @Override
     public synchronized DateTime getNow(DateTimeZone tz) {
-        return adjust(super.getNow(tz));
+        return getUTCNow().toDateTime(tz);
     }
 
     @Override
     public synchronized DateTime getUTCNow() {
-        return getNow(DateTimeZone.UTC);
+        try {
+        return currentTime.plus(epsilon).minus(currentTime.getMillisOfSecond());
+        } catch(RuntimeException e) {
+            throw e;
+        }
     }
-
+    
+    public synchronized void setTime(DateTime time) {
+        adjustTo(time.toDateTime(DateTimeZone.UTC));
+   }
+    
+    public synchronized void addDays(int days) {
+        adjustTo(currentTime.plusDays(days));
+    }
+    
+    public synchronized void addWeeks(int weeks) {
+        adjustTo(currentTime.plusWeeks(weeks));
+    }
+    
+    public synchronized void addMonths(int months) {
+        adjustTo(currentTime.plusMonths(months));
+    }
+    
+    public synchronized void addYears(int years) {
+        adjustTo(currentTime.plusMonths(years));
+    }
+    
+    public synchronized void reset() {
+        adjustTo(new DateTime(DateTimeZone.UTC));
+    }
+    
+    @Override
+    public String toString() {
+        return getUTCNow().toString();
+    }
+    
+    private void adjustTo(DateTime newTime) {
+        if(newTime == null) {
+            log.error("Attempting to adjust clock to a null value");
+            newTime = new DateTime(DateTimeZone.UTC);
+        }
+        logClockAdjustment(currentTime, newTime);
+        currentTime = newTime;
+    }
+    
     private void logClockAdjustment(DateTime prev, DateTime next) {
         log.info(String.format("            ************      ADJUSTING CLOCK FROM %s to %s     ********************", prev, next));
     }
 
+    //
+    //Backward compatibility stuff
+    //
+    long epsilon = 0;
+    
     public synchronized void setDeltaFromReality(Duration delta, long epsilon) {
-        DateTime prev = getUTCNow();
-        deltaType = DeltaType.DELTA_DURATION;
-        deltaFromRealityDuration = new ArrayList<Duration>();
-        deltaFromRealityDuration.add(delta);
-        deltaFromRealityDurationEpsilon = epsilon;
-        deltaFromRealityMs = 0;
-        logClockAdjustment(prev, getUTCNow());
+        this.epsilon = epsilon;
+        addDeltaFromReality(delta);
     }
 
     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);
-        logClockAdjustment(prev, getUTCNow());
+        adjustTo(addDurationToDateTime(delta,currentTime));
     }
 
     public synchronized void setDeltaFromReality(long delta) {
-        DateTime prev = getUTCNow();
-        deltaType = DeltaType.DELTA_ABS;
-        deltaFromRealityDuration = null;
-        deltaFromRealityDurationEpsilon = 0;
-        deltaFromRealityMs = delta;
-        logClockAdjustment(prev, getUTCNow());
+        adjustTo(currentTime.plus(delta));
     }
 
     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;
-        deltaFromRealityDurationEpsilon = 0;
-        deltaFromRealityMs += delta;
-        logClockAdjustment(prev, getUTCNow());
+        adjustTo(currentTime.plus(delta));
     }
 
     public synchronized void resetDeltaFromReality() {
-        deltaType = DeltaType.DELTA_NONE;
-        deltaFromRealityDuration = null;
-        deltaFromRealityDurationEpsilon = 0;
-        deltaFromRealityMs = 0;
+        reset();
     }
+    
+    public DateTime addDurationToDateTime(Duration duration, DateTime dateTime) {
+        if (duration.getUnit() != TimeUnit.UNLIMITED) {return dateTime;}
 
-    private DateTime adjust(DateTime realNow) {
-        switch(deltaType) {
-            case DELTA_NONE:
-                return realNow;
-            case DELTA_ABS:
-                return adjustFromAbsolute(realNow);
-            case DELTA_DURATION:
-                return adjustFromDuration(realNow);
-            default:
-                return null;
-        }
-    }
-
-    private DateTime adjustFromDuration(DateTime input) {
-
-        DateTime result = input;
-        for (Duration cur : deltaFromRealityDuration) {
-            switch (cur.getUnit()) {
+        switch (duration.getUnit()) {
             case DAYS:
-                result = result.plusDays(cur.getNumber());
-                break;
-
+                return dateTime.plusDays(duration.getNumber());
             case MONTHS:
-                result = result.plusMonths(cur.getNumber());
-                break;
-
+                return dateTime.plusMonths(duration.getNumber());
             case YEARS:
-                result = result.plusYears(cur.getNumber());
-                break;
-
+                return dateTime.plusYears(duration.getNumber());
             case UNLIMITED:
+                return dateTime.plusYears(100);
             default:
-                throw new RuntimeException("ClockMock is adjusting an unlimited time period");
-            }
-        }
-        if (deltaFromRealityDurationEpsilon != 0) {
-            result = result.plus(deltaFromRealityDurationEpsilon);
+                return dateTime;
         }
-        return result;
     }
-
-    private DateTime adjustFromAbsolute(DateTime input) {
-        return truncateMs(input.plus(deltaFromRealityMs));
-    }
-
-    @Override
-    public String toString() {
-        return getUTCNow().toString();
-    }
-
     
+
 }
diff --git a/util/src/test/java/com/ning/billing/util/clock/MockClockModule.java b/util/src/test/java/com/ning/billing/util/clock/MockClockModule.java
index a8f0605..ece94b0 100644
--- a/util/src/test/java/com/ning/billing/util/clock/MockClockModule.java
+++ b/util/src/test/java/com/ning/billing/util/clock/MockClockModule.java
@@ -28,3 +28,4 @@ public class MockClockModule extends AbstractModule {
 	}
 
 }
+ 
\ No newline at end of file