killbill-memoizeit
Changes
beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java 250(+126 -124)
junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultEntitlementBillingApi.java 6(+3 -3)
overdue/pom.xml 13(+6 -7)
overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java 3(+2 -1)
Details
diff --git a/api/src/main/java/com/ning/billing/BillingExceptionBase.java b/api/src/main/java/com/ning/billing/BillingExceptionBase.java
index 3a458fc..a4ff3cd 100644
--- a/api/src/main/java/com/ning/billing/BillingExceptionBase.java
+++ b/api/src/main/java/com/ning/billing/BillingExceptionBase.java
@@ -35,6 +35,13 @@ public class BillingExceptionBase extends Exception {
this.code = code;
this.cause = cause;
}
+
+ public BillingExceptionBase(BillingExceptionBase cause) {
+ this.formattedMsg = cause.getMessage();
+ this.code = cause.getCode();
+ this.cause = cause;
+ }
+
public BillingExceptionBase(Throwable cause, ErrorCode code, final Object... args) {
String tmp = null;
diff --git a/api/src/main/java/com/ning/billing/ErrorCode.java b/api/src/main/java/com/ning/billing/ErrorCode.java
index 3aa190b..860ae6c 100644
--- a/api/src/main/java/com/ning/billing/ErrorCode.java
+++ b/api/src/main/java/com/ning/billing/ErrorCode.java
@@ -193,6 +193,7 @@ public enum ErrorCode {
*/
OVERDUE_CAT_ERROR_ENCOUNTERED(5001,"Catalog error encountered on Overdueable: id='%s', type='%s'"),
OVERDUE_TYPE_NOT_SUPPORTED(5002,"Overdue of this type is not supported: id='%s', type='%s'"),
+ OVERDUE_NO_REEVALUATION_INTERVAL(5003,"No valid reevaluation interval for state (name: %s)"),
/*
*
* Range 6000: Blocking system
diff --git a/api/src/main/java/com/ning/billing/junction/api/BlockingApi.java b/api/src/main/java/com/ning/billing/junction/api/BlockingApi.java
index 18c6799..d7fc678 100644
--- a/api/src/main/java/com/ning/billing/junction/api/BlockingApi.java
+++ b/api/src/main/java/com/ning/billing/junction/api/BlockingApi.java
@@ -25,11 +25,11 @@ public interface BlockingApi {
public BlockingState getBlockingStateFor(Blockable overdueable);
- public BlockingState getBlockingStateFor(UUID overdueableId, Blockable.Type type);
+ public BlockingState getBlockingStateFor(UUID overdueableId);
public SortedSet<BlockingState> getBlockingHistory(Blockable overdueable);
- public SortedSet<BlockingState> getBlockingHistory(UUID overdueableId, Blockable.Type type);
+ public SortedSet<BlockingState> getBlockingHistory(UUID overdueableId);
public <T extends Blockable> void setBlockingState(BlockingState state);
diff --git a/api/src/main/java/com/ning/billing/junction/api/BlockingState.java b/api/src/main/java/com/ning/billing/junction/api/BlockingState.java
index fcb38fc..08202a2 100644
--- a/api/src/main/java/com/ning/billing/junction/api/BlockingState.java
+++ b/api/src/main/java/com/ning/billing/junction/api/BlockingState.java
@@ -21,6 +21,8 @@ import org.joda.time.DateTime;
public interface BlockingState extends Comparable<BlockingState> {
public abstract String getStateName();
+
+ public abstract Blockable.Type getType();
public abstract DateTime getTimestamp();
diff --git a/api/src/main/java/com/ning/billing/junction/api/DefaultBlockingState.java b/api/src/main/java/com/ning/billing/junction/api/DefaultBlockingState.java
index f2e632d..332cb85 100644
--- a/api/src/main/java/com/ning/billing/junction/api/DefaultBlockingState.java
+++ b/api/src/main/java/com/ning/billing/junction/api/DefaultBlockingState.java
@@ -23,8 +23,6 @@ import org.joda.time.DateTime;
public class DefaultBlockingState implements BlockingState{
- private static final String CLEAR_STATE = "clear";
-
private static BlockingState clearState= null;
private final UUID blockingId;
@@ -38,7 +36,7 @@ public class DefaultBlockingState implements BlockingState{
public static BlockingState getClearState() {
if(clearState == null) {
- clearState = new DefaultBlockingState(null, CLEAR_STATE, null, null, false, false, false);
+ clearState = new DefaultBlockingState(null, BlockingApi.CLEAR_STATE_NAME, null, null, false, false, false);
}
return clearState;
}
@@ -92,6 +90,7 @@ public class DefaultBlockingState implements BlockingState{
return stateName;
}
+ @Override
public Blockable.Type getType() {
return type;
}
diff --git a/api/src/main/java/com/ning/billing/overdue/config/api/OverdueError.java b/api/src/main/java/com/ning/billing/overdue/config/api/OverdueError.java
index b71b299..78f62c6 100644
--- a/api/src/main/java/com/ning/billing/overdue/config/api/OverdueError.java
+++ b/api/src/main/java/com/ning/billing/overdue/config/api/OverdueError.java
@@ -20,6 +20,15 @@ import com.ning.billing.BillingExceptionBase;
import com.ning.billing.ErrorCode;
public class OverdueError extends BillingExceptionBase {
+
+ public OverdueError(BillingExceptionBase cause) {
+ super(cause);
+ }
+
+ public OverdueError(Throwable cause, int code, String msg) {
+ super(cause, code, msg);
+ }
+
private static final long serialVersionUID = 1L;
public OverdueError(Throwable cause, ErrorCode code, Object... args) {
diff --git a/api/src/main/java/com/ning/billing/overdue/config/api/OverdueStateSet.java b/api/src/main/java/com/ning/billing/overdue/config/api/OverdueStateSet.java
index 796e482..693fa8f 100644
--- a/api/src/main/java/com/ning/billing/overdue/config/api/OverdueStateSet.java
+++ b/api/src/main/java/com/ning/billing/overdue/config/api/OverdueStateSet.java
@@ -18,18 +18,15 @@ package com.ning.billing.overdue.config.api;
import org.joda.time.DateTime;
-import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.junction.api.Blockable;
+import com.ning.billing.overdue.OverdueApiException;
import com.ning.billing.overdue.OverdueState;
public interface OverdueStateSet<T extends Blockable> {
- public abstract OverdueState<T> findClearState() throws CatalogApiException;
+ public abstract OverdueState<T> findClearState() throws OverdueApiException;
- public abstract OverdueState<T> findState(String stateName) throws CatalogApiException;
-
- public abstract OverdueState<T> calculateOverdueState(BillingState<T> billingState, DateTime now) throws CatalogApiException;
-
- public abstract DateTime dateOfNextCheck(BillingState<T> billingState, DateTime now);
+ public abstract OverdueState<T> findState(String stateName) throws OverdueApiException;
+ public abstract OverdueState<T> calculateOverdueState(BillingState<T> billingState, DateTime now) throws OverdueApiException;
}
\ No newline at end of file
diff --git a/api/src/main/java/com/ning/billing/overdue/OverdueState.java b/api/src/main/java/com/ning/billing/overdue/OverdueState.java
index 0679416..3de2c94 100644
--- a/api/src/main/java/com/ning/billing/overdue/OverdueState.java
+++ b/api/src/main/java/com/ning/billing/overdue/OverdueState.java
@@ -16,6 +16,8 @@
package com.ning.billing.overdue;
+import org.joda.time.Period;
+
import com.ning.billing.junction.api.Blockable;
@@ -33,4 +35,6 @@ public interface OverdueState<T extends Blockable> {
public boolean blockChanges();
public boolean isClearState();
+
+ public Period getReevaluationInterval() throws OverdueApiException;
}
\ No newline at end of file
diff --git a/api/src/main/java/com/ning/billing/overdue/OverdueUserApi.java b/api/src/main/java/com/ning/billing/overdue/OverdueUserApi.java
index 74764b3..3101c10 100644
--- a/api/src/main/java/com/ning/billing/overdue/OverdueUserApi.java
+++ b/api/src/main/java/com/ning/billing/overdue/OverdueUserApi.java
@@ -16,15 +16,13 @@
package com.ning.billing.overdue;
-import com.ning.billing.catalog.api.CatalogApiException;
-import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.overdue.config.api.BillingState;
import com.ning.billing.overdue.config.api.OverdueError;
public interface OverdueUserApi {
- public <T extends Blockable> OverdueState<T> refreshOverdueStateFor(T overdueable) throws OverdueError, CatalogApiException, EntitlementUserApiException;
+ public <T extends Blockable> OverdueState<T> refreshOverdueStateFor(T overdueable) throws OverdueError, OverdueApiException;
public <T extends Blockable> void setOverrideBillingStateForAccount(T overdueable, BillingState<T> state) throws OverdueError;
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java
index 2dfe2ee..edc9ec1 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java
@@ -14,127 +14,129 @@
* under the License.
*/
-//package com.ning.billing.beatrix.integration.overdue;
-//
-//import static org.testng.Assert.assertNotNull;
-//
-//import java.io.ByteArrayInputStream;
-//import java.io.InputStream;
-//
-//import org.joda.time.DateTime;
-//import org.joda.time.Interval;
-//
-//import com.google.inject.Inject;
-//import com.ning.billing.account.api.Account;
-//import com.ning.billing.beatrix.integration.TestIntegrationBase;
-//import com.ning.billing.catalog.api.BillingPeriod;
-//import com.ning.billing.catalog.api.Duration;
-//import com.ning.billing.catalog.api.PlanPhaseSpecifier;
-//import com.ning.billing.catalog.api.PriceListSet;
-//import com.ning.billing.catalog.api.ProductCategory;
-//import com.ning.billing.entitlement.api.user.SubscriptionBundle;
-//import com.ning.billing.entitlement.api.user.SubscriptionData;
-//import com.ning.billing.junction.api.BlockingApi;
-//import com.ning.billing.overdue.config.OverdueConfig;
-//import com.ning.billing.payment.provider.MockPaymentProviderPlugin;
-//import com.ning.billing.util.clock.ClockMock;
-//import com.ning.billing.util.config.XMLLoader;
-//
-//public class TestOverdueIntegration extends TestIntegrationBase {
-// private final String configXml =
-// "<overdueConfig>" +
-// " <bundleOverdueStates>" +
-// " <state name=\"OD1\">" +
-// " <condition>" +
-// " <timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
-// " <unit>MONTHS</unit><number>1</number>" +
-// " </timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
-// " </condition>" +
-// " <externalMessage>Reached OD1</externalMessage>" +
-// " <blockChanges>true</blockChanges>" +
-// " <disableEntitlementAndChangesBlocked>false</disableEntitlementAndChangesBlocked>" +
-// " </state>" +
-// " <state name=\"OD2\">" +
-// " <condition>" +
-// " <timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
-// " <unit>MONTHS</unit><number>2</number>" +
-// " </timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
-// " </condition>" +
-// " <externalMessage>Reached OD1</externalMessage>" +
-// " <blockChanges>true</blockChanges>" +
-// " <disableEntitlementAndChangesBlocked>true</disableEntitlementAndChangesBlocked>" +
-// " </state>" +
-// " </bundleOverdueStates>" +
-// "</overdueConfig>";
-// private OverdueConfig config;
-//
-// @Inject
-// private ClockMock clock;
-//
-// @Inject
-// private MockPaymentProviderPlugin paymentPlugin;
-//
-// @Inject
-// private BlockingApi blockingApi;
-//
-// private Account account;
-// private SubscriptionBundle bundle;
-// private String productName;
-// private BillingPeriod term;
-// private String planSetName;
-//
-// long twoWeeks = new Interval(clock.getUTCNow(), clock.getUTCNow().plusWeeks(2)).toDurationMillis();
-// long fourWeeks = new Interval(clock.getUTCNow(), clock.getUTCNow().plusWeeks(4)).toDurationMillis();
-//
-// //@BeforeMethod
-// public void setup() throws Exception {
-// InputStream is = new ByteArrayInputStream(configXml.getBytes());
-// config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class);
-// Account account = accountUserApi.createAccount(getAccountData(25), null, null, context);
-// assertNotNull(account);
-//
-// bundle = entitlementUserApi.createBundleForAccount(account.getId(), "whatever", context);
-//
-// productName = "Shotgun";
-// term = BillingPeriod.MONTHLY;
-// planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
-//
-// // create account
-// // set mock payments to fail
-// // reset clock
-// // configure basic OD state rules for 2 states OD1 1-2month, OD2 2-3 month
-// }
-//
-// //@AfterMethod
-// public void cleanup(){
-// // Clear databases
-// }
-//
-// public void testBasicOverdueState() throws Exception {
-// DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
-// clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
-//
-//
-// // set next invoice to fail and create network
-// paymentPlugin.makeNextInvoiceFail();
-// SubscriptionData baseSubscription = subscriptionDataFromSubscription(entitlementUserApi.createSubscription(bundle.getId(),
-// new PlanPhaseSpecifier(productName, ProductCategory.BASE, term, planSetName, null), null, context));
-// assertNotNull(baseSubscription);
-//
-//
-// // advance time 2weeks
-// clock.addDeltaFromReality(twoWeeks);
-//
-// // should still be in clear state
-// blockingApi.getBlockingStateFor(bundle);
-//
-// // set next invoice to fail and advance time 1 month
-// clock.addDeltaFromReality(fourWeeks);
-//
-// // should now be in OD1 state
-// // set next invoice to fail and advance time 1 month
-// // should now be in OD2 state
-//
-//
-// }
-//}
+package com.ning.billing.beatrix.integration.overdue;
+
+import static org.testng.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.joda.time.DateTime;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Guice;
+import org.testng.annotations.Test;
+
+import com.google.inject.Inject;
+import com.ning.billing.account.api.Account;
+import com.ning.billing.beatrix.integration.MockModule;
+import com.ning.billing.beatrix.integration.TestIntegrationBase;
+import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.PlanPhaseSpecifier;
+import com.ning.billing.catalog.api.PriceListSet;
+import com.ning.billing.catalog.api.ProductCategory;
+import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.entitlement.api.user.SubscriptionData;
+import com.ning.billing.junction.api.BlockingApi;
+import com.ning.billing.junction.api.BlockingState;
+import com.ning.billing.overdue.config.OverdueConfig;
+import com.ning.billing.payment.provider.MockPaymentProviderPlugin;
+import com.ning.billing.util.clock.ClockMock;
+import com.ning.billing.util.config.XMLLoader;
+
+@Test(groups = "slow")
+@Guice(modules = {MockModule.class})
+public class TestOverdueIntegration extends TestIntegrationBase {
+ private final String configXml =
+ "<overdueConfig>" +
+ " <bundleOverdueStates>" +
+ " <state name=\"OD1\">" +
+ " <condition>" +
+ " <timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
+ " <unit>MONTHS</unit><number>1</number>" +
+ " </timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
+ " </condition>" +
+ " <externalMessage>Reached OD1</externalMessage>" +
+ " <blockChanges>true</blockChanges>" +
+ " <disableEntitlementAndChangesBlocked>false</disableEntitlementAndChangesBlocked>" +
+ " </state>" +
+ " <state name=\"OD2\">" +
+ " <condition>" +
+ " <timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
+ " <unit>MONTHS</unit><number>2</number>" +
+ " </timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
+ " </condition>" +
+ " <externalMessage>Reached OD1</externalMessage>" +
+ " <blockChanges>true</blockChanges>" +
+ " <disableEntitlementAndChangesBlocked>true</disableEntitlementAndChangesBlocked>" +
+ " </state>" +
+ " </bundleOverdueStates>" +
+ "</overdueConfig>";
+ private OverdueConfig config;
+
+ @Inject
+ private ClockMock clock;
+
+ @Inject
+ private MockPaymentProviderPlugin paymentPlugin;
+
+ @Inject
+ private BlockingApi blockingApi;
+
+ private Account account;
+ private SubscriptionBundle bundle;
+ private String productName;
+ private BillingPeriod term;
+ private String planSetName;
+
+ @BeforeMethod(groups = {"slow"})
+ public void setupOverdue() throws Exception {
+ InputStream is = new ByteArrayInputStream(configXml.getBytes());
+ config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class);
+ Account account = accountUserApi.createAccount(getAccountData(25), null, null, context);
+ assertNotNull(account);
+
+ bundle = entitlementUserApi.createBundleForAccount(account.getId(), "whatever", context);
+
+ productName = "Shotgun";
+ term = BillingPeriod.MONTHLY;
+ planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
+
+ // create account
+ // set mock payments to fail
+ // reset clock
+ // configure basic OD state rules for 2 states OD1 1-2month, OD2 2-3 month
+ }
+
+ @AfterMethod
+ public void cleanup(){
+ // Clear databases
+ }
+
+ @Test(groups={"slow"}, enabled = true)
+ public void testBasicOverdueState() throws Exception {
+ clock.setTime(new DateTime(2012, 5, 1, 0, 3, 42, 0));
+
+ // set next invoice to fail and create network
+ paymentPlugin.makeNextInvoiceFail();
+ SubscriptionData baseSubscription = subscriptionDataFromSubscription(entitlementUserApi.createSubscription(bundle.getId(),
+ new PlanPhaseSpecifier(productName, ProductCategory.BASE, term, planSetName, null), null, context));
+ assertNotNull(baseSubscription);
+
+ // advance time 2weeks
+ clock.addWeeks(2);
+
+ // should still be in clear state
+ BlockingState state = blockingApi.getBlockingStateFor(bundle);
+ Assert.assertEquals(state.getStateName(), BlockingApi.CLEAR_STATE_NAME);
+ // set next invoice to fail and advance time 1 month
+ clock.addWeeks(4);
+
+ // should now be in OD1 state
+ // set next invoice to fail and advance time 1 month
+ // should now be in OD2 state
+ clock.addWeeks(4);
+
+ }
+}
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
index 44e7297..a408755 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
@@ -85,6 +85,7 @@ public class TestIntegrationBase implements TestListenerStatus {
protected static final Logger log = LoggerFactory.getLogger(TestIntegration.class);
protected static long AT_LEAST_ONE_MONTH_MS = 31L * 24L * 3600L * 1000L;
+
protected static final long DELAY = 5000;
@Inject
diff --git a/junction/src/main/java/com/ning/billing/junction/api/blocking/DefaultBlockingApi.java b/junction/src/main/java/com/ning/billing/junction/api/blocking/DefaultBlockingApi.java
index 62878ad..904d303 100644
--- a/junction/src/main/java/com/ning/billing/junction/api/blocking/DefaultBlockingApi.java
+++ b/junction/src/main/java/com/ning/billing/junction/api/blocking/DefaultBlockingApi.java
@@ -21,7 +21,6 @@ import java.util.UUID;
import com.google.inject.Inject;
import com.ning.billing.junction.api.Blockable;
-import com.ning.billing.junction.api.Blockable.Type;
import com.ning.billing.junction.api.BlockingApi;
import com.ning.billing.junction.api.BlockingState;
import com.ning.billing.junction.api.DefaultBlockingState;
@@ -49,8 +48,8 @@ public class DefaultBlockingApi implements BlockingApi {
}
@Override
- public BlockingState getBlockingStateFor(UUID overdueableId, Type type) {
- return dao.getBlockingStateFor(overdueableId, type);
+ public BlockingState getBlockingStateFor(UUID overdueableId) {
+ return dao.getBlockingStateFor(overdueableId);
}
@Override
@@ -59,9 +58,8 @@ public class DefaultBlockingApi implements BlockingApi {
}
@Override
- public SortedSet<BlockingState> getBlockingHistory(UUID overdueableId,
- Type type) {
- return dao.getBlockingHistoryForIdAndType(overdueableId, type);
+ public SortedSet<BlockingState> getBlockingHistory(UUID overdueableId) {
+ return dao.getBlockingHistoryFor(overdueableId);
}
@Override
diff --git a/junction/src/main/java/com/ning/billing/junction/block/DefaultBlockingChecker.java b/junction/src/main/java/com/ning/billing/junction/block/DefaultBlockingChecker.java
index 26e97cd..38f8bb7 100644
--- a/junction/src/main/java/com/ning/billing/junction/block/DefaultBlockingChecker.java
+++ b/junction/src/main/java/com/ning/billing/junction/block/DefaultBlockingChecker.java
@@ -116,7 +116,7 @@ public class DefaultBlockingChecker implements BlockingChecker {
public BlockingAggregator getBlockedStateAccountId(UUID accountId) {
BlockingAggregator result = new BlockingAggregator();
if(accountId != null) {
- BlockingState accountState = dao.getBlockingStateFor(accountId, Blockable.Type.ACCOUNT);
+ BlockingState accountState = dao.getBlockingStateFor(accountId);
result.or(accountState);
}
return result;
diff --git a/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateDao.java b/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateDao.java
index b5b03ae..6f5396d 100644
--- a/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateDao.java
+++ b/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateDao.java
@@ -29,11 +29,11 @@ public interface BlockingStateDao {
//Read
public BlockingState getBlockingStateFor(Blockable blockable);
- public BlockingState getBlockingStateFor(UUID blockableId, Type type);
+ public BlockingState getBlockingStateFor(UUID blockableId);
public SortedSet<BlockingState> getBlockingHistoryFor(Blockable blockable);
- public SortedSet<BlockingState> getBlockingHistoryForIdAndType(UUID blockableId, Type type);
+ public SortedSet<BlockingState> getBlockingHistoryFor(UUID blockableId);
//Write
<T extends Blockable> void setBlockingState(BlockingState state, Clock clock);
diff --git a/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateSqlDao.java b/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateSqlDao.java
index 4345f6d..ba241a4 100644
--- a/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateSqlDao.java
+++ b/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateSqlDao.java
@@ -63,7 +63,7 @@ public interface BlockingStateSqlDao extends BlockingStateDao, CloseMe, Transmog
@Override
@SqlQuery
@Mapper(BlockingHistorySqlMapper.class)
- public abstract BlockingState getBlockingStateFor(@Bind(binder = UUIDBinder.class) UUID overdueableId, @Bind(binder = BlockableTypeBinder.class) Type type);
+ public abstract BlockingState getBlockingStateFor(@Bind(binder = UUIDBinder.class) UUID overdueableId);
@Override
@SqlQuery
@@ -73,7 +73,7 @@ public interface BlockingStateSqlDao extends BlockingStateDao, CloseMe, Transmog
@Override
@SqlQuery
@Mapper(BlockingHistorySqlMapper.class)
- public abstract SortedSet<BlockingState> getBlockingHistoryForIdAndType(@Bind(binder = UUIDBinder.class) UUID blockableId, @Bind(binder = BlockableTypeBinder.class) Type type);
+ public abstract SortedSet<BlockingState> getBlockingHistoryFor(@Bind(binder = UUIDBinder.class) UUID blockableId);
public class BlockingHistorySqlMapper extends MapperBase implements ResultSetMapper<BlockingState> {
diff --git a/junction/src/main/java/com/ning/billing/junction/plumbing/billing/BlockingCalculator.java b/junction/src/main/java/com/ning/billing/junction/plumbing/billing/BlockingCalculator.java
index 9c1aab1..999c5d6 100644
--- a/junction/src/main/java/com/ning/billing/junction/plumbing/billing/BlockingCalculator.java
+++ b/junction/src/main/java/com/ning/billing/junction/plumbing/billing/BlockingCalculator.java
@@ -85,8 +85,8 @@ public class BlockingCalculator {
SortedSet<BillingEvent> billingEventsToRemove = new TreeSet<BillingEvent>();
for(UUID bundleId : bundleMap.keySet()) {
- SortedSet<BlockingState> blockingEvents = blockingApi.getBlockingHistory(bundleId, Blockable.Type.SUBSCRIPTION_BUNDLE);
- blockingEvents.addAll(blockingApi.getBlockingHistory(account.getId(), Blockable.Type.ACCOUNT));
+ SortedSet<BlockingState> blockingEvents = blockingApi.getBlockingHistory(bundleId);
+ blockingEvents.addAll(blockingApi.getBlockingHistory(account.getId()));
List<DisabledDuration> blockingDurations = createBlockingDurations(blockingEvents);
for (Subscription subscription: bundleMap.get(bundleId)) {
diff --git a/junction/src/main/resources/com/ning/billing/junction/dao/BlockingStateSqlDao.sql.stg b/junction/src/main/resources/com/ning/billing/junction/dao/BlockingStateSqlDao.sql.stg
index 98125a2..0bd6686 100644
--- a/junction/src/main/resources/com/ning/billing/junction/dao/BlockingStateSqlDao.sql.stg
+++ b/junction/src/main/resources/com/ning/billing/junction/dao/BlockingStateSqlDao.sql.stg
@@ -17,25 +17,6 @@ getBlockingStateFor() ::= <<
;
>>
-getBlockingStateForIdAndType() ::= <<
- select
- id
- , state
- , type
- , service
- , block_change
- , block_entitlement
- , block_billing
- , created_date
- from blocking_states
- where id = :id
- and type = :type
- order by created_date desc
- limit 1
- ;
->>
-
-
getBlockingHistoryFor() ::= <<
select
id
@@ -52,23 +33,6 @@ getBlockingHistoryFor() ::= <<
;
>>
-getBlockingHistoryForIdAndType() ::= <<
- select
- id
- , state
- , type
- , service
- , block_change
- , block_entitlement
- , block_billing
- , created_date
- from blocking_states
- where id = :id
- and type = :type
- order by created_date asc
- ;
->>
-
setBlockingState() ::= <<
insert into blocking_states (
id
diff --git a/junction/src/test/java/com/ning/billing/junction/api/blocking/TestBlockingApi.java b/junction/src/test/java/com/ning/billing/junction/api/blocking/TestBlockingApi.java
index 1d814b8..78ca164 100644
--- a/junction/src/test/java/com/ning/billing/junction/api/blocking/TestBlockingApi.java
+++ b/junction/src/test/java/com/ning/billing/junction/api/blocking/TestBlockingApi.java
@@ -105,7 +105,7 @@ public class TestBlockingApi {
((ZombieControl)bundle).addResult("getId", uuid);
Assert.assertEquals(api.getBlockingStateFor(bundle).getStateName(), overdueStateName2);
- Assert.assertEquals(api.getBlockingStateFor(bundle.getId(), Blockable.Type.SUBSCRIPTION_BUNDLE).getStateName(), overdueStateName2);
+ Assert.assertEquals(api.getBlockingStateFor(bundle.getId()).getStateName(), overdueStateName2);
}
@@ -133,7 +133,7 @@ public class TestBlockingApi {
SortedSet<BlockingState> history1 = api.getBlockingHistory(bundle);
- SortedSet<BlockingState> history2 = api.getBlockingHistory(bundle.getId(), Blockable.Type.get(bundle));
+ SortedSet<BlockingState> history2 = api.getBlockingHistory(bundle.getId());
Assert.assertEquals(history1.size(), 2);
Assert.assertEquals(history1.first().getStateName(), overdueStateName);
diff --git a/junction/src/test/java/com/ning/billing/junction/blocking/TestBlockingChecker.java b/junction/src/test/java/com/ning/billing/junction/blocking/TestBlockingChecker.java
index 22869b7..0753924 100644
--- a/junction/src/test/java/com/ning/billing/junction/blocking/TestBlockingChecker.java
+++ b/junction/src/test/java/com/ning/billing/junction/blocking/TestBlockingChecker.java
@@ -32,7 +32,6 @@ import com.ning.billing.entitlement.api.user.EntitlementUserApi;
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.junction.api.Blockable;
-import com.ning.billing.junction.api.Blockable.Type;
import com.ning.billing.junction.api.BlockingApiException;
import com.ning.billing.junction.api.BlockingState;
import com.ning.billing.junction.api.DefaultBlockingState;
@@ -54,9 +53,9 @@ public class TestBlockingChecker {
@Override
public BlockingState getBlockingStateFor(Blockable blockable) {
- if(blockable instanceof Account) {
+ if(blockable.getId() == account.getId()) {
return accountState;
- } else if(blockable instanceof Subscription) {
+ } else if(blockable.getId() == subscription.getId()) {
return subscriptionState;
} else {
return bundleState;
@@ -64,10 +63,10 @@ public class TestBlockingChecker {
}
@Override
- public BlockingState getBlockingStateFor(UUID blockableId, Type type) {
- if(type == Blockable.Type.ACCOUNT) {
+ public BlockingState getBlockingStateFor(UUID blockableId) {
+ if(blockableId == account.getId()) {
return accountState;
- } else if(type == Blockable.Type.SUBSCRIPTION) {
+ } else if(blockableId == subscription.getId()) {
return subscriptionState;
} else {
return bundleState;
@@ -80,7 +79,7 @@ public class TestBlockingChecker {
}
@Override
- public SortedSet<BlockingState> getBlockingHistoryForIdAndType(UUID overdueableId, Type type) {
+ public SortedSet<BlockingState> getBlockingHistoryFor(UUID overdueableId) {
throw new NotImplementedException();
}
@@ -97,18 +96,19 @@ public class TestBlockingChecker {
@BeforeClass(groups={"fast"})
public void setup() {
- subscription = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
- ((ZombieControl) subscription).addResult("getId", new UUID(0L,0L));
+ account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
+ ((ZombieControl) account).addResult("getId", UUID.randomUUID());
bundle = BrainDeadProxyFactory.createBrainDeadProxyFor(SubscriptionBundle.class);
- ((ZombieControl) bundle).addResult("getAccountId", new UUID(0L,0L));
- ((ZombieControl) bundle).addResult("getId", new UUID(0L,0L));
+ ((ZombieControl) bundle).addResult("getAccountId", account.getId());
+ ((ZombieControl) bundle).addResult("getId", UUID.randomUUID());
((ZombieControl) bundle).addResult("getKey", "key");
- ((ZombieControl) subscription).addResult("getBundleId", new UUID(0L,0L));
- account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- ((ZombieControl) account).addResult("getId", new UUID(0L,0L));
-
+ subscription = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
+ ((ZombieControl) subscription).addResult("getId", UUID.randomUUID());
+ ((ZombieControl) subscription).addResult("getBundleId", bundle.getId());
+
+
Injector i = Guice.createInjector(new AbstractModule() {
@Override
diff --git a/junction/src/test/java/com/ning/billing/junction/dao/TestBlockingDao.java b/junction/src/test/java/com/ning/billing/junction/dao/TestBlockingDao.java
index 0c3b8c8..8e02e55 100644
--- a/junction/src/test/java/com/ning/billing/junction/dao/TestBlockingDao.java
+++ b/junction/src/test/java/com/ning/billing/junction/dao/TestBlockingDao.java
@@ -93,7 +93,7 @@ public class TestBlockingDao {
((ZombieControl)bundle).addResult("getId", uuid);
Assert.assertEquals(dao.getBlockingStateFor(bundle).getStateName(), state2.getStateName());
- Assert.assertEquals(dao.getBlockingStateFor(bundle.getId(), Blockable.Type.SUBSCRIPTION_BUNDLE).getStateName(), overdueStateName2);
+ Assert.assertEquals(dao.getBlockingStateFor(bundle.getId()).getStateName(), overdueStateName2);
}
@@ -121,7 +121,7 @@ public class TestBlockingDao {
SortedSet<BlockingState> history1 = dao.getBlockingHistoryFor(bundle);
- SortedSet<BlockingState> history2 = dao.getBlockingHistoryForIdAndType(bundle.getId(), Blockable.Type.get(bundle));
+ SortedSet<BlockingState> history2 = dao.getBlockingHistoryFor(bundle.getId());
Assert.assertEquals(history1.size(), 2);
Assert.assertEquals(history1.first().getStateName(), overdueStateName);
diff --git a/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultEntitlementBillingApi.java b/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultEntitlementBillingApi.java
index 9dce3b0..65ebcb3 100644
--- a/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultEntitlementBillingApi.java
+++ b/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultEntitlementBillingApi.java
@@ -389,7 +389,7 @@ public class TestDefaultEntitlementBillingApi {
public <T extends Blockable> void setBlockingState(BlockingState state) {}
@Override
- public BlockingState getBlockingStateFor(UUID overdueableId, Type type) {
+ public BlockingState getBlockingStateFor(UUID overdueableId) {
return null;
}
@@ -399,8 +399,8 @@ public class TestDefaultEntitlementBillingApi {
}
@Override
- public SortedSet<BlockingState> getBlockingHistory(UUID overdueableId, Type type) {
- if(type == Type.SUBSCRIPTION_BUNDLE) {
+ public SortedSet<BlockingState> getBlockingHistory(UUID overdueableId) {
+ if(overdueableId == bunId) {
return blockingStates;
}
return new TreeSet<BlockingState>();
overdue/pom.xml 13(+6 -7)
diff --git a/overdue/pom.xml b/overdue/pom.xml
index 2182ffc..3662f2b 100644
--- a/overdue/pom.xml
+++ b/overdue/pom.xml
@@ -46,6 +46,12 @@
<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>
@@ -93,13 +99,6 @@
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
- <!-- Strangely this is needed in order to run the tests in local db mode -->
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <scope>test</scope>
- </dependency>
-
</dependencies>
<build>
<plugins>
diff --git a/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java b/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java
index 5e3e8e3..9f45075 100644
--- a/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java
+++ b/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.ning.billing.config.NotificationConfig;
import com.ning.billing.overdue.OverdueProperties;
+import com.ning.billing.overdue.listener.OverdueListener;
import com.ning.billing.overdue.service.DefaultOverdueService;
import com.ning.billing.util.notificationq.NotificationQueue;
import com.ning.billing.util.notificationq.NotificationQueueService;
@@ -97,7 +98,7 @@ public class DefaultOverdueCheckNotifier implements OverdueCheckNotifier {
}
private void processEvent(UUID overdueableId, DateTime eventDateTime) {
- listener.handleNextOverdueCheck(overdueableId, eventDateTime);
+ listener.handleNextOverdueCheck(overdueableId);
}
diff --git a/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckPoster.java b/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckPoster.java
index 106a5c4..81ba766 100644
--- a/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckPoster.java
+++ b/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckPoster.java
@@ -42,14 +42,14 @@ public class DefaultOverdueCheckPoster implements OverdueCheckPoster {
}
@Override
- public void insertOverdueCheckNotification(final Transmogrifier transactionalDao, final Blockable overdueable, final DateTime futureNotificationTime) {
+ public void insertOverdueCheckNotification(final Blockable overdueable, final DateTime futureNotificationTime) {
NotificationQueue checkOverdueQueue;
try {
checkOverdueQueue = notificationQueueService.getNotificationQueue(DefaultOverdueService.OVERDUE_SERVICE_NAME,
DefaultOverdueCheckNotifier.OVERDUE_CHECK_NOTIFIER_QUEUE);
log.info("Queuing overdue check notification. id: {}, timestamp: {}", overdueable.getId().toString(), futureNotificationTime.toString());
- checkOverdueQueue.recordFutureNotificationFromTransaction(transactionalDao, futureNotificationTime, new NotificationKey(){
+ checkOverdueQueue.recordFutureNotification(futureNotificationTime, new NotificationKey(){
@Override
public String toString() {
return overdueable.getId().toString();
@@ -58,9 +58,12 @@ public class DefaultOverdueCheckPoster implements OverdueCheckPoster {
} catch (NoSuchNotificationQueue e) {
log.error("Attempting to put items on a non-existent queue (DefaultOverdueCheck).", e);
}
+
}
- public void clearNotificationEventsFor(final Blockable overdueable) {
+
+ @Override
+ public void clearNotificationsFor(final Blockable overdueable) {
NotificationQueue checkOverdueQueue;
try {
checkOverdueQueue = notificationQueueService.getNotificationQueue(DefaultOverdueService.OVERDUE_SERVICE_NAME,
@@ -70,4 +73,5 @@ public class DefaultOverdueCheckPoster implements OverdueCheckPoster {
log.error("Attempting to clear items from a non-existent queue (DefaultOverdueCheck).", e);
}
}
+
}
diff --git a/overdue/src/main/java/com/ning/billing/ovedue/notification/OverdueCheckPoster.java b/overdue/src/main/java/com/ning/billing/ovedue/notification/OverdueCheckPoster.java
index 8105bc7..3a2aa48 100644
--- a/overdue/src/main/java/com/ning/billing/ovedue/notification/OverdueCheckPoster.java
+++ b/overdue/src/main/java/com/ning/billing/ovedue/notification/OverdueCheckPoster.java
@@ -24,7 +24,8 @@ import com.ning.billing.junction.api.Blockable;
public interface OverdueCheckPoster {
- void insertOverdueCheckNotification(Transmogrifier transactionalDao,
- Blockable overdueable, DateTime futureNotificationTime);
+ void insertOverdueCheckNotification(Blockable blockable, DateTime futureNotificationTime);
+
+ void clearNotificationsFor(Blockable blockable);
}
\ No newline at end of file
diff --git a/overdue/src/main/java/com/ning/billing/overdue/api/DefaultOverdueUserApi.java b/overdue/src/main/java/com/ning/billing/overdue/api/DefaultOverdueUserApi.java
index 8a9ea68..83487ea 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/api/DefaultOverdueUserApi.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/api/DefaultOverdueUserApi.java
@@ -20,12 +20,12 @@ import org.apache.commons.lang.NotImplementedException;
import com.google.inject.Inject;
import com.ning.billing.ErrorCode;
-import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.CatalogService;
import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.junction.api.BlockingApi;
+import com.ning.billing.overdue.OverdueApiException;
import com.ning.billing.overdue.OverdueState;
import com.ning.billing.overdue.OverdueUserApi;
import com.ning.billing.overdue.config.OverdueConfig;
@@ -57,13 +57,13 @@ public class DefaultOverdueUserApi implements OverdueUserApi {
String stateName = accessApi.getBlockingStateFor(overdueable).getStateName();
OverdueStateSet<SubscriptionBundle> states = overdueConfig.getBundleStateSet();
return (OverdueState<T>) states.findState(stateName);
- } catch (CatalogApiException e) {
+ } catch (OverdueApiException e) {
throw new OverdueError(e, ErrorCode.OVERDUE_CAT_ERROR_ENCOUNTERED,overdueable.getId(), overdueable.getClass().getSimpleName());
}
}
@Override
- public <T extends Blockable> OverdueState<T> refreshOverdueStateFor(T overdueable) throws OverdueError, CatalogApiException, EntitlementUserApiException {
+ public <T extends Blockable> OverdueState<T> refreshOverdueStateFor(T overdueable) throws OverdueError, OverdueApiException {
OverdueWrapper<T> wrapper = factory.createOverdueWrapperFor(overdueable);
return wrapper.refresh();
}
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 82ad93c..abd4e0a 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
@@ -18,44 +18,57 @@ package com.ning.billing.overdue.applicator;
import org.apache.commons.lang.NotImplementedException;
import org.joda.time.DateTime;
+import org.joda.time.Period;
import com.google.inject.Inject;
import com.ning.billing.ErrorCode;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.junction.api.BlockingApi;
import com.ning.billing.junction.api.DefaultBlockingState;
-
+import com.ning.billing.ovedue.notification.OverdueCheckPoster;
+import com.ning.billing.overdue.OverdueApiException;
import com.ning.billing.overdue.OverdueService;
import com.ning.billing.overdue.OverdueState;
import com.ning.billing.overdue.config.api.OverdueError;
+import com.ning.billing.util.clock.Clock;
public class OverdueStateApplicator<T extends Blockable>{
private final BlockingApi blockingApi;
+ private final Clock clock;
+ private final OverdueCheckPoster poster;
@Inject
- public OverdueStateApplicator(BlockingApi accessApi) {
+ public OverdueStateApplicator(BlockingApi accessApi, Clock clock, OverdueCheckPoster poster) {
this.blockingApi = accessApi;
+ this.clock = clock;
+ this.poster = poster;
}
- public void apply(T overdueable, OverdueState<T> previousOverdueState, OverdueState<T> nextOverdueState, DateTime timeOfNextCheck) throws OverdueError {
+ public void apply(T overdueable, OverdueState<T> previousOverdueState, OverdueState<T> nextOverdueState) throws OverdueError {
if(previousOverdueState.getName().equals(nextOverdueState.getName())) {
return; // nothing to do
}
-
+
storeNewState(overdueable, nextOverdueState);
-
- if(timeOfNextCheck != null && !nextOverdueState.isClearState()) {
- createFutureNotification(overdueable, timeOfNextCheck);
+ try {
+ Period reevaluationInterval = nextOverdueState.getReevaluationInterval();
+ if(!nextOverdueState.isClearState()) {
+ createFutureNotification(overdueable, clock.getUTCNow().plus(reevaluationInterval));
+ }
+ } catch(OverdueApiException e) {
+ if(e.getCode() != ErrorCode.OVERDUE_NO_REEVALUATION_INTERVAL.getCode()) {
+ new OverdueError(e);
+ }
}
if(nextOverdueState.isClearState()) {
clear(overdueable);
}
-
- //If new state is clear state reset next events and override table
- throw new NotImplementedException();
+
+
+
}
@@ -82,17 +95,13 @@ public class OverdueStateApplicator<T extends Blockable>{
protected void createFutureNotification(T overdueable,
DateTime timeOfNextCheck) {
- // TODO MDW
-
- }
+ poster.insertOverdueCheckNotification(overdueable, timeOfNextCheck);
+ }
-
- protected void clear(T overdueable) {
- //TODO MDW
- // Clear future notification checks
- // Clear any overrides
-
+ protected void clear(T blockable) {
+ //Need to clear the overrride table here too (when we add it)
+ poster.clearNotificationsFor(blockable);
}
}
diff --git a/overdue/src/main/java/com/ning/billing/overdue/config/DefaultCondition.java b/overdue/src/main/java/com/ning/billing/overdue/config/DefaultCondition.java
index 08c13a9..44f6c99 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/config/DefaultCondition.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/config/DefaultCondition.java
@@ -26,6 +26,8 @@ import javax.xml.bind.annotation.XmlElementWrapper;
import org.joda.time.DateTime;
+import com.ning.billing.catalog.api.Duration;
+import com.ning.billing.catalog.api.TimeUnit;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.overdue.config.api.BillingState;
import com.ning.billing.overdue.config.api.PaymentResponse;
@@ -90,4 +92,13 @@ public class DefaultCondition<T extends Blockable> extends ValidatingConfig<Over
@Override
public void initialize(OverdueConfig root, URI uri) {
}
+
+ public Duration getTimeOffset() {
+ if (timeSinceEarliestUnpaidInvoiceEqualsOrExceeds != null) {
+ return timeSinceEarliestUnpaidInvoiceEqualsOrExceeds;
+ } else {
+ return new DefaultDuration().setUnit(TimeUnit.DAYS).setNumber(0); // zero time
+ }
+
+ }
}
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 9a448c2..690d717 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
@@ -22,7 +22,14 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlID;
+import org.joda.time.DateTime;
+import org.joda.time.Period;
+
+import com.ning.billing.ErrorCode;
+import com.ning.billing.catalog.api.TimeUnit;
+import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.junction.api.Blockable;
+import com.ning.billing.overdue.OverdueApiException;
import com.ning.billing.overdue.OverdueState;
import com.ning.billing.util.config.ValidatingConfig;
import com.ning.billing.util.config.ValidationError;
@@ -55,6 +62,11 @@ public class DefaultOverdueState<T extends Blockable> extends ValidatingConfig<O
@XmlElement(required=false, name="isClearState")
private Boolean isClearState = false;
+ @XmlElement(required=false, name="autoReevaluationInterval")
+ private DefaultDuration autoReevaluationInterval;
+
+
+
//Other actions could include
// - send email
// - trigger payment retry?
@@ -91,7 +103,14 @@ public class DefaultOverdueState<T extends Blockable> extends ValidatingConfig<O
public boolean disableEntitlementAndChangesBlocked() {
return disableEntitlement;
}
-
+
+ @Override
+ public Period getReevaluationInterval() throws OverdueApiException {
+ if(autoReevaluationInterval == null || autoReevaluationInterval.getUnit() == TimeUnit.UNLIMITED || autoReevaluationInterval.getNumber() == 0) {
+ throw new OverdueApiException(ErrorCode.OVERDUE_NO_REEVALUATION_INTERVAL, name);
+ }
+ return autoReevaluationInterval.toJodaPeriod();
+ }
protected DefaultCondition<T> getCondition() {
return condition;
diff --git a/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueStateSet.java b/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueStateSet.java
index bbda620..277fb1b 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueStateSet.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueStateSet.java
@@ -19,12 +19,14 @@ package com.ning.billing.overdue.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
-import org.apache.commons.lang.NotImplementedException;
import org.joda.time.DateTime;
+import org.joda.time.MutablePeriod;
+import org.joda.time.Period;
import com.ning.billing.ErrorCode;
-import com.ning.billing.catalog.api.CatalogApiException;
+import com.ning.billing.catalog.api.Duration;
import com.ning.billing.junction.api.Blockable;
+import com.ning.billing.overdue.OverdueApiException;
import com.ning.billing.overdue.OverdueState;
import com.ning.billing.overdue.config.api.BillingState;
import com.ning.billing.overdue.config.api.OverdueStateSet;
@@ -33,57 +35,52 @@ import com.ning.billing.util.config.ValidationErrors;
@XmlAccessorType(XmlAccessType.NONE)
public abstract class DefaultOverdueStateSet<T extends Blockable> extends ValidatingConfig<OverdueConfig> implements OverdueStateSet<T> {
+ private static final Period ZERO_PERIOD = new Period();
private DefaultOverdueState<T> clearState;
-
+
protected abstract DefaultOverdueState<T>[] getStates();
-
- private DefaultOverdueState<T> getClearState() throws CatalogApiException {
+
+ private DefaultOverdueState<T> getClearState() throws OverdueApiException {
for(DefaultOverdueState<T> overdueState : getStates()) {
if(overdueState.isClearState()) {
return overdueState;
}
}
- throw new CatalogApiException(ErrorCode.CAT_MISSING_CLEAR_STATE);
+ throw new OverdueApiException(ErrorCode.CAT_MISSING_CLEAR_STATE);
}
-
+
@Override
- public OverdueState<T> findState(String stateName) throws CatalogApiException {
+ public OverdueState<T> findState(String stateName) throws OverdueApiException {
for(DefaultOverdueState<T> state: getStates()) {
if(state.getName().equals(stateName) ) { return state; }
}
- throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_OVEDUE_STATE, stateName);
+ throw new OverdueApiException(ErrorCode.CAT_NO_SUCH_OVEDUE_STATE, stateName);
}
-
-
+
+
/* (non-Javadoc)
* @see com.ning.billing.catalog.overdue.OverdueBillingState#findClearState()
*/
@Override
- public DefaultOverdueState<T> findClearState() throws CatalogApiException {
+ public DefaultOverdueState<T> findClearState() throws OverdueApiException {
if (clearState != null) {
clearState = getClearState();
}
return clearState;
}
-
+
/* (non-Javadoc)
* @see com.ning.billing.catalog.overdue.OverdueBillingState#calculateOverdueState(com.ning.billing.catalog.api.overdue.BillingState, org.joda.time.DateTime)
*/
@Override
- public DefaultOverdueState<T> calculateOverdueState(BillingState<T> billingState, DateTime now) throws CatalogApiException {
- for(DefaultOverdueState<T> overdueState : getStates()) {
- if(overdueState.getCondition().evaluate(billingState, now)) {
- return overdueState;
- }
+ public DefaultOverdueState<T> calculateOverdueState(BillingState<T> billingState, DateTime now) throws OverdueApiException {
+ for(DefaultOverdueState<T> overdueState : getStates()) {
+ if(overdueState.getCondition().evaluate(billingState, now)) {
+ return overdueState;
}
- return findClearState();
- }
-
- @Override
- public DateTime dateOfNextCheck(BillingState<T> billingState, DateTime now) {
- throw new NotImplementedException();
+ }
+ return findClearState();
}
-
@Override
public ValidationErrors validate(OverdueConfig root,
@@ -93,13 +90,13 @@ public abstract class DefaultOverdueStateSet<T extends Blockable> extends Valida
}
try {
getClearState();
- } catch (CatalogApiException e) {
+ } catch (OverdueApiException e) {
if(e.getCode() == ErrorCode.CAT_MISSING_CLEAR_STATE.getCode()) {
errors.add("Overdue state set is missing a clear state.",
root.getURI(), this.getClass(), "");
- }
+ }
}
-
+
return errors;
}
}
diff --git a/overdue/src/main/java/com/ning/billing/overdue/config/OverdueConfig.java b/overdue/src/main/java/com/ning/billing/overdue/config/OverdueConfig.java
index 1217122..16d5a51 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/config/OverdueConfig.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/config/OverdueConfig.java
@@ -38,7 +38,6 @@ public class OverdueConfig extends ValidatingConfig<OverdueConfig> {
return bundleOverdueStates;
}
-
@Override
public ValidationErrors validate(OverdueConfig root,
ValidationErrors errors) {
diff --git a/overdue/src/main/java/com/ning/billing/overdue/config/OverdueStatesBundle.java b/overdue/src/main/java/com/ning/billing/overdue/config/OverdueStatesBundle.java
index 50d000b..3f07db5 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/config/OverdueStatesBundle.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/config/OverdueStatesBundle.java
@@ -18,7 +18,14 @@ package com.ning.billing.overdue.config;
import javax.xml.bind.annotation.XmlElement;
+import org.joda.time.DateTime;
+
+import com.ning.billing.ErrorCode;
+import com.ning.billing.catalog.api.Duration;
+import com.ning.billing.catalog.api.TimeUnit;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.overdue.OverdueApiException;
+import com.ning.billing.overdue.OverdueState;
public class OverdueStatesBundle extends DefaultOverdueStateSet<SubscriptionBundle>{
diff --git a/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueDispatcher.java b/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueDispatcher.java
new file mode 100644
index 0000000..8f2d03f
--- /dev/null
+++ b/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueDispatcher.java
@@ -0,0 +1,87 @@
+/*
+ * 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.listener;
+
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.ning.billing.account.api.Account;
+import com.ning.billing.account.api.AccountApiException;
+import com.ning.billing.account.api.AccountUserApi;
+import com.ning.billing.entitlement.api.user.EntitlementUserApi;
+import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
+import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.junction.api.Blockable;
+import com.ning.billing.overdue.OverdueApiException;
+import com.ning.billing.overdue.config.api.OverdueError;
+import com.ning.billing.overdue.wrapper.OverdueWrapper;
+import com.ning.billing.overdue.wrapper.OverdueWrapperFactory;
+
+public class OverdueDispatcher {
+ Logger log = LoggerFactory.getLogger(OverdueDispatcher.class);
+
+ private final EntitlementUserApi entitlementUserApi;
+ private final AccountUserApi accountUserApi;
+ private final OverdueWrapperFactory factory;
+
+ @Inject
+ public OverdueDispatcher(AccountUserApi accountUserApi,
+ EntitlementUserApi entitlementUserApi,
+ OverdueWrapperFactory factory) {
+ this.accountUserApi = accountUserApi;
+ this.entitlementUserApi = entitlementUserApi;
+ this.factory = factory;
+ }
+
+ public void processOverdueForAccount(UUID accountId) {
+ try {
+ Account account = accountUserApi.getAccountById(accountId);
+ processOverdue(account);
+ } catch (AccountApiException e) {
+ log.error("Error processing Overdue for Account with id: " + accountId.toString(), e);
+ }
+ }
+
+ public void processOverdueForBundle(UUID bundleId) {
+ try {
+ SubscriptionBundle bundle = entitlementUserApi.getBundleFromId(bundleId);
+ processOverdue(bundle);
+ } catch (EntitlementUserApiException e) {
+ log.error("Error processing Overdue for Bundle with id: " + bundleId.toString(), e);
+ }
+ }
+
+ public void processOverdue(Blockable bloackable) {
+ try {
+ OverdueWrapper<?> wrapper = factory.createOverdueWrapperFor(bloackable);
+ wrapper.refresh();
+ } catch (OverdueError e) {
+ log.error("Error processing Overdue for Blockable with id: " + bloackable.getId().toString(), e);
+ } catch (OverdueApiException e) {
+ log.error("Error processing Overdue for Blockable with id: " + bloackable.getId().toString(), e);
+ }
+ }
+
+ public void processOverdue(UUID blockableId) {
+
+
+ }
+
+}
diff --git a/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueListener.java b/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueListener.java
new file mode 100644
index 0000000..2c193b4
--- /dev/null
+++ b/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueListener.java
@@ -0,0 +1,66 @@
+/*
+ * 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.listener;
+
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.eventbus.Subscribe;
+import com.google.inject.Inject;
+import com.ning.billing.payment.api.PaymentApi;
+import com.ning.billing.payment.api.PaymentAttempt;
+import com.ning.billing.payment.api.PaymentErrorEvent;
+import com.ning.billing.payment.api.PaymentInfoEvent;
+
+public class OverdueListener {
+ OverdueDispatcher dispatcher;
+
+ //
+ //TODO disabled overdue for prod deployment - comments should be removed
+ //
+
+ private final static Logger log = LoggerFactory.getLogger(OverdueListener.class);
+ private final PaymentApi paymentApi;
+
+ @Inject
+ public OverdueListener(OverdueDispatcher dispatcher, PaymentApi paymentApi) {
+ this.dispatcher = dispatcher;
+ this.paymentApi = paymentApi;
+ }
+
+ @Subscribe
+ public void handlePaymentInfoEvent(final PaymentInfoEvent event) {
+// String paymentId = event.getPaymentId();
+// PaymentAttempt attempt = paymentApi.getPaymentAttemptForPaymentId(paymentId);
+// UUID accountId = attempt.getAccountId();
+// dispatcher.processOverdueForAccount(accountId);
+ }
+
+ @Subscribe
+ public void handlePaymentErrorEvent(final PaymentErrorEvent event) {
+// UUID accountId = event.getAccountId();
+// dispatcher.processOverdueForAccount(accountId);
+ }
+
+ public void handleNextOverdueCheck(UUID overdueableId) {
+// dispatcher.processOverdue(overdueableId);
+ }
+
+
+}
diff --git a/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapper.java b/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapper.java
index 0223803..97220d5 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapper.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapper.java
@@ -16,10 +16,10 @@
package com.ning.billing.overdue.wrapper;
-import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.junction.api.BlockingApi;
+import com.ning.billing.overdue.OverdueApiException;
import com.ning.billing.overdue.OverdueState;
import com.ning.billing.overdue.applicator.OverdueStateApplicator;
import com.ning.billing.overdue.calculator.BillingStateCalculator;
@@ -49,15 +49,20 @@ public class OverdueWrapper<T extends Blockable> {
this.overdueStateApplicator = overdueStateApplicator;
}
- public OverdueState<T> refresh() throws OverdueError, CatalogApiException, EntitlementUserApiException {
- OverdueState<T> nextOverdueState;
- BillingState<T> billingState = billingStateCalcuator.calculateBillingState(overdueable);
- String previousOverdueStateName = api.getBlockingStateFor(overdueable).getStateName();
- nextOverdueState = overdueStateSet.calculateOverdueState(billingState, clock.getUTCNow());
- if (!previousOverdueStateName.equals(nextOverdueState.getName())) {
- overdueStateApplicator.apply(overdueable, nextOverdueState, nextOverdueState, overdueStateSet.dateOfNextCheck(billingState, clock.getUTCNow()));
- }
+ public OverdueState<T> refresh() throws OverdueError, OverdueApiException {
+ try {
+ OverdueState<T> nextOverdueState;
+ BillingState<T> billingState = billingStateCalcuator.calculateBillingState(overdueable);
+ String previousOverdueStateName = api.getBlockingStateFor(overdueable).getStateName();
+ nextOverdueState = overdueStateSet.calculateOverdueState(billingState, clock.getUTCNow());
+
+ if(!previousOverdueStateName.equals(nextOverdueState.getName())) {
+ overdueStateApplicator.apply(overdueable, nextOverdueState, nextOverdueState);
+ }
- return nextOverdueState;
+ return nextOverdueState;
+ } catch (EntitlementUserApiException e) {
+ throw new OverdueError(e);
+ }
}
}
\ No newline at end of file
diff --git a/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapperFactory.java b/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapperFactory.java
index d542e24..0fd6854 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapperFactory.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapperFactory.java
@@ -16,11 +16,19 @@
package com.ning.billing.overdue.wrapper;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.google.inject.Inject;
import com.ning.billing.ErrorCode;
+import com.ning.billing.entitlement.api.user.EntitlementUserApi;
+import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
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.overdue.applicator.OverdueStateApplicator;
import com.ning.billing.overdue.calculator.BillingStateCalculatorBundle;
import com.ning.billing.overdue.config.OverdueConfig;
@@ -29,8 +37,10 @@ import com.ning.billing.overdue.service.ExtendedOverdueService;
import com.ning.billing.util.clock.Clock;
public class OverdueWrapperFactory {
+ private static final Logger log = LoggerFactory.getLogger(OverdueWrapperFactory.class);
private final OverdueConfig overdueConfig;
+ private final EntitlementUserApi entitlementApi;
private final BillingStateCalculatorBundle billingStateCalcuatorBundle;
private final OverdueStateApplicator<SubscriptionBundle> overdueStateApplicatorBundle;
private final BlockingApi api;
@@ -38,9 +48,12 @@ public class OverdueWrapperFactory {
@Inject
public OverdueWrapperFactory(BlockingApi api, ExtendedOverdueService service, Clock clock,
- BillingStateCalculatorBundle billingStateCalcuatorBundle, OverdueStateApplicator<SubscriptionBundle> overdueStateApplicatorBundle) {
+ BillingStateCalculatorBundle billingStateCalcuatorBundle,
+ OverdueStateApplicator<SubscriptionBundle> overdueStateApplicatorBundle,
+ EntitlementUserApi entitlementApi) {
this.billingStateCalcuatorBundle = billingStateCalcuatorBundle;
this.overdueStateApplicatorBundle = overdueStateApplicatorBundle;
+ this.entitlementApi = entitlementApi;
this.overdueConfig = service.getOverdueConfig();
this.api = api;
this.clock = clock;
@@ -56,5 +69,26 @@ public class OverdueWrapperFactory {
}
}
+ @SuppressWarnings("unchecked")
+ public <T extends Blockable> OverdueWrapper<T> createOverdueWrapperFor(UUID id) throws OverdueError {
+ BlockingState state = api.getBlockingStateFor(id);
+
+ try {
+ switch (state.getType()) {
+ case SUBSCRIPTION_BUNDLE : {
+ SubscriptionBundle bundle = entitlementApi.getBundleFromId(id);
+ return (OverdueWrapper<T>)new OverdueWrapper<SubscriptionBundle>(bundle, api, overdueConfig.getBundleStateSet(),
+ clock, billingStateCalcuatorBundle, overdueStateApplicatorBundle );
+ }
+ default : {
+ throw new OverdueError(ErrorCode.OVERDUE_TYPE_NOT_SUPPORTED, id, state.getType());
+ }
+
+ }
+ } catch (EntitlementUserApiException e) {
+ throw new OverdueError(e);
+ }
+ }
+
}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/notification/MockOverdueCheckPoster.java b/overdue/src/test/java/com/ning/billing/overdue/notification/MockOverdueCheckPoster.java
index 29d30ca..c1cfb65 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/notification/MockOverdueCheckPoster.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/notification/MockOverdueCheckPoster.java
@@ -17,7 +17,6 @@
package com.ning.billing.overdue.notification;
import org.joda.time.DateTime;
-import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.ovedue.notification.OverdueCheckPoster;
@@ -25,9 +24,15 @@ import com.ning.billing.ovedue.notification.OverdueCheckPoster;
public class MockOverdueCheckPoster implements OverdueCheckPoster {
@Override
- public void insertOverdueCheckNotification(Transmogrifier transactionalDao, Blockable overdueable,
+ public void insertOverdueCheckNotification(Blockable overdueable,
DateTime futureNotificationTime) {
// TODO Auto-generated method stub
}
+
+ @Override
+ public void clearNotificationsFor(Blockable blockable) {
+ // TODO Auto-generated method stub
+
+ }
}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java b/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java
index dca8cb7..7f48dda 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java
@@ -28,8 +28,6 @@ import org.apache.commons.io.IOUtils;
import org.joda.time.DateTime;
import org.skife.config.ConfigurationObjectFactory;
import org.skife.jdbi.v2.IDBI;
-import org.skife.jdbi.v2.Transaction;
-import org.skife.jdbi.v2.TransactionStatus;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -54,9 +52,9 @@ import com.ning.billing.mock.glue.MockJunctionModule;
import com.ning.billing.ovedue.notification.DefaultOverdueCheckNotifier;
import com.ning.billing.ovedue.notification.DefaultOverdueCheckPoster;
import com.ning.billing.ovedue.notification.OverdueCheckPoster;
-import com.ning.billing.ovedue.notification.OverdueListener;
import com.ning.billing.overdue.OverdueProperties;
import com.ning.billing.overdue.glue.OverdueModule;
+import com.ning.billing.overdue.listener.OverdueListener;
import com.ning.billing.util.bus.Bus;
import com.ning.billing.util.bus.InMemoryBus;
import com.ning.billing.util.callcontext.CallContextFactory;
@@ -68,7 +66,6 @@ import com.ning.billing.util.customfield.dao.CustomFieldDao;
import com.ning.billing.util.globallocker.GlobalLocker;
import com.ning.billing.util.globallocker.MySqlGlobalLocker;
import com.ning.billing.util.notificationq.DefaultNotificationQueueService;
-import com.ning.billing.util.notificationq.DummySqlTest;
import com.ning.billing.util.notificationq.NotificationQueueService;
import com.ning.billing.util.notificationq.dao.NotificationSqlDao;
import com.ning.billing.util.tag.dao.AuditedTagDao;
@@ -77,7 +74,7 @@ import com.ning.billing.util.tag.dao.TagDao;
public class TestOverdueCheckNotifier {
private Clock clock;
private DefaultOverdueCheckNotifier notifier;
- private DummySqlTest dao;
+
private Bus eventBus;
private MysqlTestingHelper helper;
private OverdueListenerMock listener;
@@ -88,11 +85,11 @@ public class TestOverdueCheckNotifier {
UUID latestSubscriptionId = null;
public OverdueListenerMock() {
- super();
+ super(null,null);
}
@Override
- public void handleNextOverdueCheck(UUID subscriptionId, DateTime eventDateTime) {
+ public void handleNextOverdueCheck(UUID subscriptionId) {
eventCount++;
latestSubscriptionId=subscriptionId;
}
@@ -158,7 +155,6 @@ public class TestOverdueCheckNotifier {
eventBus.start();
notifier.initialize();
notifier.start();
- dao = dbi.onDemand(DummySqlTest.class);
}
private void startMysql() throws IOException, ClassNotFoundException, SQLException {
@@ -180,16 +176,7 @@ public class TestOverdueCheckNotifier {
final OverdueCheckPoster poster = new DefaultOverdueCheckPoster(notificationQueueService);
-
- dao.inTransaction(new Transaction<Void, DummySqlTest>() {
- @Override
- public Void inTransaction(DummySqlTest transactional,
- TransactionStatus status) throws Exception {
-
- poster.insertOverdueCheckNotification(transactional, blockable, readyTime);
- return null;
- }
- });
+ poster.insertOverdueCheckNotification(blockable, readyTime);
// Move time in the future after the notification effectiveDate
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java b/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
index 92b6266..414f2a0 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
@@ -113,8 +113,7 @@ public class TestAccount extends TestJaxrsBase {
@Test(groups="slow", enabled=true)
public void testAccountTimeline() throws Exception {
- DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
- clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
+ clock.setTime(new DateTime(2012, 4, 25, 0, 3, 42, 0));
AccountJson accountJson = createAccount("poney", "shdddqgfhwe", "poney@yahoo.com");
@@ -127,8 +126,7 @@ public class TestAccount extends TestJaxrsBase {
assertNotNull(subscriptionJson);
// MOVE AFTER TRIAL
- Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(3).plusDays(1));
- clock.addDeltaFromReality(it.toDurationMillis());
+ clock.addMonths(3);
crappyWaitForLackOfProperSynchonization();
@@ -142,7 +140,7 @@ public class TestAccount extends TestJaxrsBase {
assertNotNull(objFromJson);
log.info(baseJson);
- Assert.assertEquals(objFromJson.getPayments().size(), 3);
+ Assert.assertEquals(objFromJson.getPayments().size(), 3);
Assert.assertEquals(objFromJson.getInvoices().size(), 4);
Assert.assertEquals(objFromJson.getBundles().size(), 1);
Assert.assertEquals(objFromJson.getBundles().get(0).getSubscriptions().size(), 1);
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java
index d5c2425..f28ff63 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java
@@ -26,45 +26,48 @@ import com.ning.billing.util.queue.QueueLifecycle;
public interface NotificationQueue extends QueueLifecycle {
- /**
- *
- * Record the need to be called back when the notification is ready
- *
- * @param futureNotificationTime the time at which the notification is ready
- * @param notificationKey the key for that notification
- */
- public void recordFutureNotification(final DateTime futureNotificationTime, final NotificationKey notificationKey);
+ /**
+ *
+ * Record the need to be called back when the notification is ready
+ *
+ * @param futureNotificationTime the time at which the notification is ready
+ * @param notificationKey the key for that notification
+ */
+ public void recordFutureNotification(final DateTime futureNotificationTime, final NotificationKey notificationKey);
- /**
- *
- * Record from within a transaction the need to be called back when the notification is ready
- *
- * @param transactionalDao the transactionalDao
- * @param futureNotificationTime the time at which the notification is ready
- * @param notificationKey the key for that notification
- */
- public void recordFutureNotificationFromTransaction(final Transmogrifier transactionalDao,
- final DateTime futureNotificationTime, final NotificationKey notificationKey);
+ /**
+ *
+ * Record from within a transaction the need to be called back when the notification is ready
+ *
+ * @param transactionalDao the transactionalDao
+ * @param futureNotificationTime the time at which the notification is ready
+ * @param notificationKey the key for that notification
+ */
+ public void recordFutureNotificationFromTransaction(final Transmogrifier transactionalDao,
+ final DateTime futureNotificationTime, final NotificationKey notificationKey);
- /**
- * Remove all notifications associated with this key
- *
- * @param key
- */
- public void removeNotificationsByKey(UUID key);
+
+ /**
+ * Remove all notifications associated with this key
+ *
+ * @param key
+ */
+ public void removeNotificationsByKey(UUID key);
+
+ /**
+ * This is only valid when the queue has been configured with isNotificationProcessingOff is true
+ * In which case, it will callback users for all the ready notifications.
+ *
+ * @return the number of entries we processed
+ */
+ public int processReadyNotification();
+
+ /**
+ *
+ * @return the name of that queue
+ */
+ public String getFullQName();
- /**
- * This is only valid when the queue has been configured with isNotificationProcessingOff is true
- * In which case, it will callback users for all the ready notifications.
- *
- * @return the number of entries we processed
- */
- public int processReadyNotification();
- /**
- *
- * @return the name of that queue
- */
- public String getFullQName();
}