killbill-memoizeit

Another overdue test

5/21/2012 4:58:13 PM

Details

diff --git a/account/src/test/java/com/ning/billing/account/glue/AccountModuleWithMocks.java b/account/src/test/java/com/ning/billing/account/glue/AccountModuleWithMocks.java
index 8700cfa..27e7f79 100644
--- a/account/src/test/java/com/ning/billing/account/glue/AccountModuleWithMocks.java
+++ b/account/src/test/java/com/ning/billing/account/glue/AccountModuleWithMocks.java
@@ -20,7 +20,7 @@ import com.ning.billing.account.dao.AccountDao;
 import com.ning.billing.account.dao.AccountEmailDao;
 import com.ning.billing.account.dao.MockAccountDao;
 import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.util.clock.MockClockModule;
+import com.ning.billing.mock.glue.MockClockModule;
 import com.ning.billing.util.customfield.CustomField;
 import com.ning.billing.util.customfield.dao.CustomFieldDao;
 import com.ning.billing.util.glue.CallContextModule;
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/payment/TestPaymentInvoiceIntegration.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/payment/TestPaymentInvoiceIntegration.java
index 9ac8a6b..ef7571e 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/payment/TestPaymentInvoiceIntegration.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/payment/TestPaymentInvoiceIntegration.java
@@ -45,6 +45,7 @@ import com.ning.billing.dbi.MysqlTestingHelper;
 import com.ning.billing.invoice.api.Invoice;
 import com.ning.billing.invoice.api.InvoicePaymentApi;
 import com.ning.billing.invoice.glue.InvoiceModuleWithMocks;
+import com.ning.billing.mock.glue.MockClockModule;
 import com.ning.billing.mock.glue.MockJunctionModule;
 import com.ning.billing.payment.RequestProcessor;
 import com.ning.billing.payment.api.PaymentApi;
@@ -54,7 +55,6 @@ import com.ning.billing.payment.api.PaymentInfoEvent;
 import com.ning.billing.payment.setup.PaymentTestModuleWithEmbeddedDb;
 import com.ning.billing.util.bus.Bus;
 import com.ning.billing.util.bus.Bus.EventBusException;
-import com.ning.billing.util.clock.MockClockModule;
 import com.ning.billing.util.glue.CallContextModule;
 
 public class TestPaymentInvoiceIntegration {
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModule.java b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModule.java
index 31e0da3..d541d63 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModule.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModule.java
@@ -19,7 +19,7 @@ package com.ning.billing.entitlement.glue;
 import com.ning.billing.account.api.AccountUserApi;
 import com.ning.billing.catalog.glue.CatalogModule;
 import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.util.clock.MockClockModule;
+import com.ning.billing.mock.glue.MockClockModule;
 import com.ning.billing.util.glue.BusModule;
 import com.ning.billing.util.glue.CallContextModule;
 
diff --git a/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java b/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java
index a0eb6d5..3d0e010 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java
@@ -53,13 +53,13 @@ import com.ning.billing.invoice.glue.InvoiceModuleWithMocks;
 import com.ning.billing.lifecycle.KillbillService;
 import com.ning.billing.mock.BrainDeadProxyFactory;
 import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
+import com.ning.billing.mock.glue.MockClockModule;
 import com.ning.billing.mock.glue.MockJunctionModule;
 import com.ning.billing.util.bus.Bus;
 import com.ning.billing.util.callcontext.CallContextFactory;
 import com.ning.billing.util.callcontext.DefaultCallContextFactory;
 import com.ning.billing.util.clock.Clock;
 import com.ning.billing.util.clock.ClockMock;
-import com.ning.billing.util.clock.MockClockModule;
 import com.ning.billing.util.glue.BusModule;
 import com.ning.billing.util.glue.BusModule.BusType;
 import com.ning.billing.util.glue.NotificationQueueModule;
diff --git a/junction/src/test/java/com/ning/billing/junction/MockModule.java b/junction/src/test/java/com/ning/billing/junction/MockModule.java
index 23e18d7..e542d2e 100644
--- a/junction/src/test/java/com/ning/billing/junction/MockModule.java
+++ b/junction/src/test/java/com/ning/billing/junction/MockModule.java
@@ -18,8 +18,8 @@ package com.ning.billing.junction;
 
 import com.ning.billing.catalog.glue.CatalogModule;
 import com.ning.billing.junction.glue.DefaultJunctionModule;
+import com.ning.billing.mock.glue.MockClockModule;
 import com.ning.billing.mock.glue.MockDbHelperModule;
-import com.ning.billing.util.clock.MockClockModule;
 import com.ning.billing.util.glue.CallContextModule;
 
 

overdue/pom.xml 229(+115 -114)

diff --git a/overdue/pom.xml b/overdue/pom.xml
index 3662f2b..b366de7 100644
--- a/overdue/pom.xml
+++ b/overdue/pom.xml
@@ -1,118 +1,119 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!-- ~ Copyright 2010-2011 Ning, Inc. ~ ~ Ning licenses this file to you 
-    under the Apache License, version 2.0 ~ (the "License"); you may not use 
-    this file except in compliance with the ~ License. You may obtain a copy 
-    of the License at: ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless 
-    required by applicable law or agreed to in writing, software ~ distributed 
-    under the License is distributed on an "AS IS" BASIS, WITHOUT ~ WARRANTIES 
-    OR CONDITIONS OF ANY KIND, either express or implied. See the ~ License for 
-    the specific language governing permissions and limitations ~ under the License. -->
+	under the Apache License, version 2.0 ~ (the "License"); you may not use 
+	this file except in compliance with the ~ License. You may obtain a copy 
+	of the License at: ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless 
+	required by applicable law or agreed to in writing, software ~ distributed 
+	under the License is distributed on an "AS IS" BASIS, WITHOUT ~ WARRANTIES 
+	OR CONDITIONS OF ANY KIND, either express or implied. See the ~ License for 
+	the specific language governing permissions and limitations ~ under the License. -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-    <parent>
-        <groupId>com.ning.billing</groupId>
-        <artifactId>killbill</artifactId>
-        <version>0.1.11-SNAPSHOT</version>
-        <relativePath>../pom.xml</relativePath>
-    </parent>
-    <artifactId>killbill-overdue</artifactId>
-    <name>killbill-overdue</name>
-    <packaging>jar</packaging>
-    <dependencies>
-        <dependency>
-            <groupId>com.ning.billing</groupId>
-            <artifactId>killbill-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.ning.billing</groupId>
-            <artifactId>killbill-util</artifactId>
-        </dependency>
-          <dependency>
-            <groupId>com.google.inject</groupId>
-            <artifactId>guice</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.skife.config</groupId>
-            <artifactId>config-magic</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>joda-time</groupId>
-            <artifactId>joda-time</artifactId>
-        </dependency>
-         <dependency>
-            <groupId>org.jdbi</groupId>
-            <artifactId>jdbi</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
-         </dependency>
-        
-        <!-- TEST SCOPE -->
-        <dependency>
-            <groupId>org.testng</groupId>
-            <artifactId>testng</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-            <scope>test</scope>
-        </dependency>
-                
-        <dependency>
-            <groupId>com.ning.billing</groupId>
-            <artifactId>killbill-util</artifactId>
-            <type>test-jar</type>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>com.ning.billing</groupId>
-            <artifactId>killbill-catalog</artifactId>
-            <type>test-jar</type>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>com.ning.billing</groupId>
-            <artifactId>killbill-catalog</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>mysql</groupId>
-            <artifactId>mysql-connector-java</artifactId>
-            <scope>runtime</scope>
-        </dependency>
-        <dependency>
-            <groupId>mysql</groupId>
-            <artifactId>mysql-connector-mxj</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>mysql</groupId>
-            <artifactId>mysql-connector-mxj-db-files</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>com.jayway.awaitility</groupId>
-            <artifactId>awaitility</artifactId>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-jar-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>test-jar</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>com.ning.billing</groupId>
+		<artifactId>killbill</artifactId>
+		<version>0.1.11-SNAPSHOT</version>
+		<relativePath>../pom.xml</relativePath>
+	</parent>
+	<artifactId>killbill-overdue</artifactId>
+	<name>killbill-overdue</name>
+	<packaging>jar</packaging>
+	<dependencies>
+		<dependency>
+			<groupId>com.ning.billing</groupId>
+			<artifactId>killbill-api</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>com.ning.billing</groupId>
+			<artifactId>killbill-util</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>com.google.inject</groupId>
+			<artifactId>guice</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.skife.config</groupId>
+			<artifactId>config-magic</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>joda-time</groupId>
+			<artifactId>joda-time</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.jdbi</groupId>
+			<artifactId>jdbi</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>com.google.guava</groupId>
+			<artifactId>guava</artifactId>
+		</dependency>
+
+		<!-- TEST SCOPE -->
+		<dependency>
+			<groupId>org.testng</groupId>
+			<artifactId>testng</artifactId>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>commons-io</groupId>
+			<artifactId>commons-io</artifactId>
+			<scope>test</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>com.ning.billing</groupId>
+			<artifactId>killbill-util</artifactId>
+			<type>test-jar</type>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.ning.billing</groupId>
+			<artifactId>killbill-catalog</artifactId>
+			<type>test-jar</type>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.ning.billing</groupId>
+			<artifactId>killbill-catalog</artifactId>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-java</artifactId>
+			<scope>runtime</scope>
+		</dependency>
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-mxj</artifactId>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-mxj-db-files</artifactId>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.jayway.awaitility</groupId>
+			<artifactId>awaitility</artifactId>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-jar-plugin</artifactId>
+				<executions>
+					<execution>
+						<goals>
+							<goal>test-jar</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
 </project>
diff --git a/overdue/src/main/java/com/ning/billing/overdue/applicator/OverdueStateApplicator.java b/overdue/src/main/java/com/ning/billing/overdue/applicator/OverdueStateApplicator.java
index 139357b..958d8b9 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/applicator/OverdueStateApplicator.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/applicator/OverdueStateApplicator.java
@@ -16,7 +16,6 @@
 
 package com.ning.billing.overdue.applicator;
 
-import org.apache.commons.lang.NotImplementedException;
 import org.joda.time.DateTime;
 import org.joda.time.Period;
 
@@ -66,9 +65,6 @@ public class OverdueStateApplicator<T extends Blockable>{
         if(nextOverdueState.isClearState()) {
             clear(overdueable);
         }
-
-
-
     }
 
 
diff --git a/overdue/src/test/java/com/ning/billing/overdue/applicator/ApplicatorMockJunctionModule.java b/overdue/src/test/java/com/ning/billing/overdue/applicator/ApplicatorMockJunctionModule.java
new file mode 100644
index 0000000..4933492
--- /dev/null
+++ b/overdue/src/test/java/com/ning/billing/overdue/applicator/ApplicatorMockJunctionModule.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.overdue.applicator;
+
+import java.util.SortedSet;
+import java.util.UUID;
+
+import org.apache.commons.lang.NotImplementedException;
+
+import com.ning.billing.junction.api.Blockable;
+import com.ning.billing.junction.api.BlockingApi;
+import com.ning.billing.junction.api.BlockingState;
+import com.ning.billing.mock.glue.MockJunctionModule;
+
+public class ApplicatorMockJunctionModule extends MockJunctionModule {
+    
+    public static class ApplicatorBlockingApi implements BlockingApi {
+            private BlockingState blockingState;
+
+            public BlockingState getBlockingState() {
+                return blockingState;
+            }
+
+            @Override
+            public BlockingState getBlockingStateFor(Blockable overdueable) {
+                throw new NotImplementedException();
+            }
+
+            @Override
+            public BlockingState getBlockingStateFor(UUID overdueableId) {
+                throw new NotImplementedException();
+            }
+
+            @Override
+            public SortedSet<BlockingState> getBlockingHistory(Blockable overdueable) {
+                throw new NotImplementedException();
+            }
+
+            @Override
+            public SortedSet<BlockingState> getBlockingHistory(UUID overdueableId) {
+                throw new NotImplementedException();
+           }
+
+            @Override
+            public <T extends Blockable> void setBlockingState(BlockingState state) {
+                blockingState = state;
+            }
+            
+        }
+    
+    @Override
+    public void installBlockingApi() {
+        bind(BlockingApi.class).toInstance(new ApplicatorBlockingApi() );
+        
+    }
+    
+}
\ No newline at end of file
diff --git a/overdue/src/test/java/com/ning/billing/overdue/applicator/TestOverdueStateApplicator.java b/overdue/src/test/java/com/ning/billing/overdue/applicator/TestOverdueStateApplicator.java
new file mode 100644
index 0000000..fc242a9
--- /dev/null
+++ b/overdue/src/test/java/com/ning/billing/overdue/applicator/TestOverdueStateApplicator.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.overdue.applicator;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.UUID;
+
+import org.testng.Assert;
+import org.testng.annotations.Guice;
+import org.testng.annotations.Test;
+
+import com.google.inject.Inject;
+import com.ning.billing.catalog.glue.CatalogModule;
+import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.junction.api.BlockingApi;
+import com.ning.billing.junction.api.BlockingState;
+import com.ning.billing.mock.BrainDeadProxyFactory;
+import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
+import com.ning.billing.mock.glue.MockClockModule;
+import com.ning.billing.mock.glue.MockInvoiceModule;
+import com.ning.billing.mock.glue.MockPaymentModule;
+import com.ning.billing.mock.glue.TestDbiModule;
+import com.ning.billing.overdue.OverdueState;
+import com.ning.billing.overdue.OverdueTestBase;
+import com.ning.billing.overdue.applicator.ApplicatorMockJunctionModule.ApplicatorBlockingApi;
+import com.ning.billing.overdue.config.OverdueConfig;
+import com.ning.billing.overdue.glue.DefaultOverdueModule;
+import com.ning.billing.util.config.XMLLoader;
+import com.ning.billing.util.glue.BusModule;
+import com.ning.billing.util.glue.NotificationQueueModule;
+
+@Guice( modules = {DefaultOverdueModule.class, MockClockModule.class, ApplicatorMockJunctionModule.class, CatalogModule.class, MockInvoiceModule.class, MockPaymentModule.class, BusModule.class, NotificationQueueModule.class, TestDbiModule.class})
+public class TestOverdueStateApplicator extends OverdueTestBase {
+    @Inject
+    OverdueStateApplicator<SubscriptionBundle> applicator;
+    
+    @Inject
+    BlockingApi blockingApi;
+  
+    
+    @Test( groups={"fast"} , enabled = true)
+     public void testApplicator() throws Exception {
+         InputStream is = new ByteArrayInputStream(configXml.getBytes());
+         config = XMLLoader.getObjectFromStreamNoValidation(is,  OverdueConfig.class);
+         service.registerForBus();
+         service.initialize();
+         overdueWrapperFactory.setOverdueConfig(config);
+         
+         SubscriptionBundle bundle = BrainDeadProxyFactory.createBrainDeadProxyFor(SubscriptionBundle.class);
+         ((ZombieControl)bundle).addResult("getId", UUID.randomUUID());
+         
+         OverdueState<SubscriptionBundle> state;
+         BlockingState result;
+         
+         state = config.getBundleStateSet().findState("OD1");
+         applicator.apply(bundle, BlockingApi.CLEAR_STATE_NAME, state);
+         result = ((ApplicatorBlockingApi)blockingApi).getBlockingState();
+         Assert.assertEquals(result.getStateName(),state.getName());
+         Assert.assertEquals(result.isBlockChange(), state.blockChanges());
+         Assert.assertEquals(result.isBlockEntitlement(), state.disableEntitlementAndChangesBlocked());
+         Assert.assertEquals(result.isBlockBilling(), state.disableEntitlementAndChangesBlocked());
+        
+         state = config.getBundleStateSet().findState("OD2");
+         applicator.apply(bundle, BlockingApi.CLEAR_STATE_NAME, state);
+         result = ((ApplicatorBlockingApi)blockingApi).getBlockingState();
+         Assert.assertEquals(result.getStateName(),state.getName());
+         Assert.assertEquals(result.isBlockChange(), state.blockChanges());
+         Assert.assertEquals(result.isBlockEntitlement(), state.disableEntitlementAndChangesBlocked());
+         Assert.assertEquals(result.isBlockBilling(), state.disableEntitlementAndChangesBlocked());
+        
+         state = config.getBundleStateSet().findState("OD3");
+         applicator.apply(bundle, BlockingApi.CLEAR_STATE_NAME, state);
+         result = ((ApplicatorBlockingApi)blockingApi).getBlockingState();
+         Assert.assertEquals(result.getStateName(),state.getName());
+         Assert.assertEquals(result.isBlockChange(), state.blockChanges());
+         Assert.assertEquals(result.isBlockEntitlement(), state.disableEntitlementAndChangesBlocked());
+         Assert.assertEquals(result.isBlockBilling(), state.disableEntitlementAndChangesBlocked());
+        
+         
+        //TODO
+        // Check blocking API called with correct arguments for the state
+        // Check notification is posted with correct time delay
+    }
+    
+    
+}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/calculator/TestBillingStateCalculatorBundle.java b/overdue/src/test/java/com/ning/billing/overdue/calculator/TestBillingStateCalculatorBundle.java
index 5d2061b..c2f4baf 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/calculator/TestBillingStateCalculatorBundle.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/calculator/TestBillingStateCalculatorBundle.java
@@ -178,7 +178,9 @@ public class TestBillingStateCalculatorBundle extends TestBillingStateCalculator
        
     }
     
-    
+    public void testCorrectBehaviorForNoOverdueConfig() {
+        //TODO with no overdue config the system should be fine - take no action but see no NPEs
+    }
     
     
     
diff --git a/overdue/src/test/java/com/ning/billing/overdue/OverdueTestBase.java b/overdue/src/test/java/com/ning/billing/overdue/OverdueTestBase.java
new file mode 100644
index 0000000..e44efed
--- /dev/null
+++ b/overdue/src/test/java/com/ning/billing/overdue/OverdueTestBase.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.overdue;
+
+import java.io.IOException;
+
+import org.apache.commons.io.IOUtils;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Guice;
+
+import com.google.inject.Inject;
+import com.ning.billing.account.api.Account;
+import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.dbi.MysqlTestingHelper;
+import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.invoice.api.InvoiceUserApi;
+import com.ning.billing.junction.api.BlockingApi;
+import com.ning.billing.mock.glue.MockInvoiceModule;
+import com.ning.billing.mock.glue.MockJunctionModule;
+import com.ning.billing.overdue.applicator.TestOverdueStateApplicator;
+import com.ning.billing.overdue.config.OverdueConfig;
+import com.ning.billing.overdue.glue.DefaultOverdueModule;
+import com.ning.billing.overdue.service.DefaultOverdueService;
+import com.ning.billing.overdue.wrapper.OverdueWrapperFactory;
+import com.ning.billing.util.bus.BusService;
+import com.ning.billing.util.clock.ClockMock;
+
+@Guice(modules = {MockJunctionModule.class, MockInvoiceModule.class, DefaultOverdueModule.class})
+public class OverdueTestBase {
+    protected final String configXml =  
+            "<overdueConfig>" +
+                    "   <bundleOverdueStates>" +
+                    "       <state name=\"OD3\">" +
+                    "           <condition>" +
+                    "               <timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
+                    "                   <unit>DAYS</unit><number>50</number>" +
+                    "               </timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
+                    "           </condition>" +
+                    "           <externalMessage>Reached OD3</externalMessage>" +
+                    "           <blockChanges>true</blockChanges>" +
+                    "           <disableEntitlementAndChangesBlocked>true</disableEntitlementAndChangesBlocked>" +
+                    "           <autoReevaluationInterval>" +
+                    "               <unit>DAYS</unit><number>5</number>" +
+                    "           </autoReevaluationInterval>" +
+                    "       </state>" +
+                    "       <state name=\"OD2\">" +
+                    "           <condition>" +
+                    "               <timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
+                    "                   <unit>DAYS</unit><number>40</number>" +
+                    "               </timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
+                    "           </condition>" +
+                    "           <externalMessage>Reached OD2</externalMessage>" +
+                    "           <blockChanges>true</blockChanges>" +
+                    "           <disableEntitlementAndChangesBlocked>true</disableEntitlementAndChangesBlocked>" +
+                    "           <autoReevaluationInterval>" +
+                    "               <unit>DAYS</unit><number>5</number>" +
+                    "           </autoReevaluationInterval>" +
+                    "       </state>" +
+                    "       <state name=\"OD1\">" +
+                    "           <condition>" +
+                    "               <timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
+                    "                   <unit>DAYS</unit><number>30</number>" +
+                    "               </timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
+                    "           </condition>" +
+                    "           <externalMessage>Reached OD1</externalMessage>" +
+                    "           <blockChanges>true</blockChanges>" +
+                    "           <disableEntitlementAndChangesBlocked>false</disableEntitlementAndChangesBlocked>" +
+                    "           <autoReevaluationInterval>" +
+                    "               <unit>DAYS</unit><number>100</number>" + // this number is intentionally too high
+                    "           </autoReevaluationInterval>" +
+                    "       </state>" +
+                    "   </bundleOverdueStates>" +
+                    "</overdueConfig>";
+    protected OverdueConfig config; 
+
+    @Inject
+    protected ClockMock clock;
+
+    @Inject
+    protected BlockingApi blockingApi;
+    
+    @Inject
+    protected OverdueWrapperFactory overdueWrapperFactory;
+    
+    @Inject
+    protected OverdueUserApi overdueApi;
+   
+    
+    @Inject
+    protected InvoiceUserApi invoiceApi;
+
+    protected Account account;
+    protected SubscriptionBundle bundle;
+    protected String productName;
+    protected BillingPeriod term;
+    protected String planSetName;
+    
+    @Inject
+    protected DefaultOverdueService service;
+    @Inject
+    protected BusService busService;
+    @Inject
+    protected MysqlTestingHelper helper;
+
+    protected void setupMySQL() throws IOException
+    {
+        final String utilDdl = IOUtils.toString(TestOverdueStateApplicator.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
+
+        helper.startMysql();
+
+        helper.initDb(utilDdl);
+    }
+
+  
+    @BeforeClass(groups = "slow")
+    public void setup() throws Exception{
+
+        setupMySQL();
+    }
+
+    @AfterClass(groups = "slow")
+    public void tearDown() throws Exception {
+        helper.stopMysql();
+    }
+
+
+    @BeforeMethod(groups = "slow")
+    public void setupTest() throws Exception {
+
+        // Pre test cleanup
+        helper.cleanupAllTables();
+
+        clock.resetDeltaFromReality();
+
+    }
+}
diff --git a/payment/src/test/java/com/ning/billing/payment/api/TestMockPaymentApi.java b/payment/src/test/java/com/ning/billing/payment/api/TestMockPaymentApi.java
index 0ff39d2..bda4a6f 100644
--- a/payment/src/test/java/com/ning/billing/payment/api/TestMockPaymentApi.java
+++ b/payment/src/test/java/com/ning/billing/payment/api/TestMockPaymentApi.java
@@ -20,10 +20,10 @@ import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
 import com.google.inject.Inject;
+import com.ning.billing.mock.glue.MockClockModule;
 import com.ning.billing.mock.glue.MockJunctionModule;
 import com.ning.billing.payment.setup.PaymentTestModuleWithMocks;
 import com.ning.billing.util.clock.Clock;
-import com.ning.billing.util.clock.MockClockModule;
 import com.ning.billing.util.glue.CallContextModule;
 
 @Guice(modules = { PaymentTestModuleWithMocks.class, MockClockModule.class, MockJunctionModule.class, CallContextModule.class })
diff --git a/payment/src/test/java/com/ning/billing/payment/TestRetryService.java b/payment/src/test/java/com/ning/billing/payment/TestRetryService.java
index 2c519d0..5f455f0 100644
--- a/payment/src/test/java/com/ning/billing/payment/TestRetryService.java
+++ b/payment/src/test/java/com/ning/billing/payment/TestRetryService.java
@@ -46,6 +46,7 @@ import com.ning.billing.invoice.api.Invoice;
 import com.ning.billing.invoice.api.InvoicePaymentApi;
 import com.ning.billing.mock.BrainDeadProxyFactory;
 import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
+import com.ning.billing.mock.glue.MockClockModule;
 import com.ning.billing.mock.glue.MockJunctionModule;
 import com.ning.billing.payment.api.PaymentApi;
 import com.ning.billing.payment.api.PaymentApiException;
@@ -59,7 +60,6 @@ import com.ning.billing.payment.setup.PaymentTestModuleWithMocks;
 import com.ning.billing.util.bus.Bus;
 import com.ning.billing.util.clock.Clock;
 import com.ning.billing.util.clock.ClockMock;
-import com.ning.billing.util.clock.MockClockModule;
 import com.ning.billing.util.glue.CallContextModule;
 import com.ning.billing.util.notificationq.MockNotificationQueue;
 import com.ning.billing.util.notificationq.Notification;
diff --git a/util/src/test/java/com/ning/billing/mock/glue/MockClockModule.java b/util/src/test/java/com/ning/billing/mock/glue/MockClockModule.java
index 82605ae..cf7051f 100644
--- a/util/src/test/java/com/ning/billing/mock/glue/MockClockModule.java
+++ b/util/src/test/java/com/ning/billing/mock/glue/MockClockModule.java
@@ -20,10 +20,14 @@ import com.google.inject.AbstractModule;
 import com.ning.billing.util.clock.Clock;
 import com.ning.billing.util.clock.ClockMock;
 
+
 public class MockClockModule extends AbstractModule {
 
 	@Override
 	protected void configure() {
-		bind(Clock.class).to(ClockMock.class).asEagerSingleton();
+	    bind(Clock.class).to(ClockMock.class).asEagerSingleton();
+        bind(ClockMock.class).asEagerSingleton();
 	}
+
 }
+ 
\ No newline at end of file
diff --git a/util/src/test/java/com/ning/billing/util/tag/MockTagStoreModuleSql.java b/util/src/test/java/com/ning/billing/util/tag/MockTagStoreModuleSql.java
index 3364c97..6dbc537 100644
--- a/util/src/test/java/com/ning/billing/util/tag/MockTagStoreModuleSql.java
+++ b/util/src/test/java/com/ning/billing/util/tag/MockTagStoreModuleSql.java
@@ -21,7 +21,7 @@ import org.skife.jdbi.v2.Handle;
 import org.skife.jdbi.v2.IDBI;
 
 import com.ning.billing.dbi.MysqlTestingHelper;
-import com.ning.billing.util.clock.MockClockModule;
+import com.ning.billing.mock.glue.MockClockModule;
 import com.ning.billing.util.glue.TagStoreModule;
 import org.skife.jdbi.v2.tweak.HandleCallback;