killbill-memoizeit
Changes
beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueIntegration.java 73(+36 -37)
beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueWithSubscriptionCancellation.java 5(+3 -2)
beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueWithTags.java 16(+6 -10)
entitlement/src/main/java/org/killbill/billing/entitlement/api/svcs/DefaultInternalBlockingApi.java 7(+1 -6)
entitlement/src/test/java/org/killbill/billing/entitlement/dao/TestProxyBlockingStateDao.java 2(+1 -1)
Details
diff --git a/api/src/main/java/org/killbill/billing/junction/DefaultBlockingState.java b/api/src/main/java/org/killbill/billing/junction/DefaultBlockingState.java
index ccd2170..07537b0 100644
--- a/api/src/main/java/org/killbill/billing/junction/DefaultBlockingState.java
+++ b/api/src/main/java/org/killbill/billing/junction/DefaultBlockingState.java
@@ -29,9 +29,6 @@ import org.killbill.clock.Clock;
public class DefaultBlockingState extends EntityBase implements BlockingState {
- public static final String CLEAR_STATE_NAME = "__KILLBILL__CLEAR__OVERDUE_STATE__";
-
- private static BlockingState clearState = null;
private final UUID blockedId;
private final String stateName;
@@ -43,13 +40,6 @@ public class DefaultBlockingState extends EntityBase implements BlockingState {
private final BlockingStateType type;
private final Long totalOrdering;
- public static BlockingState getOverdueClearState(final BlockingStateType type, final String serviceName, final Clock clock) {
- if (clearState == null) {
- clearState = new DefaultBlockingState(null, type, CLEAR_STATE_NAME, serviceName, false, false, false, clock.getUTCNow());
- }
- return clearState;
- }
-
// Used by the DAO
public DefaultBlockingState(final UUID id,
final UUID blockedId,
diff --git a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueIntegration.java b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueIntegration.java
index 8c4f316..839cd8e 100644
--- a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueIntegration.java
+++ b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueIntegration.java
@@ -45,7 +45,7 @@ import org.killbill.billing.invoice.api.InvoiceItem;
import org.killbill.billing.invoice.api.InvoiceItemType;
import org.killbill.billing.invoice.api.InvoicePayment;
import org.killbill.billing.invoice.model.ExternalChargeInvoiceItem;
-import org.killbill.billing.junction.DefaultBlockingState;
+import org.killbill.billing.overdue.wrapper.OverdueWrapper;
import org.killbill.billing.payment.api.Payment;
import org.killbill.billing.payment.api.PluginProperty;
import org.testng.annotations.Test;
@@ -136,15 +136,15 @@ public class TestOverdueIntegration extends TestOverdueBase {
// 2012-06-08 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-16 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-24 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-30 => P1
addDaysAndCheckForCompletion(6, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT_ERROR);
@@ -223,15 +223,15 @@ public class TestOverdueIntegration extends TestOverdueBase {
// 2012-06-08 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-16 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-24 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-30 => P1
addDaysAndCheckForCompletion(6, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT_ERROR);
@@ -317,15 +317,15 @@ public class TestOverdueIntegration extends TestOverdueBase {
// 2012-06-08 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-16 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-24 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-30
addDaysAndCheckForCompletion(6, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT_ERROR);
@@ -417,15 +417,15 @@ public class TestOverdueIntegration extends TestOverdueBase {
// 2012-06-08 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-16 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-24 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-30
addDaysAndCheckForCompletion(6, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT_ERROR);
@@ -506,15 +506,15 @@ public class TestOverdueIntegration extends TestOverdueBase {
// 2012-06-08 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-16 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-24 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-30 => OD1
addDaysAndCheckForCompletion(6, NextEvent.BLOCK);
@@ -585,13 +585,13 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 6, 30), callContext);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-15 => DAY 45 - 15 days after invoice
addDaysAndCheckForCompletion(15);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-07-05 => DAY 65 - 35 days after invoice
// Single PAYMENT_ERROR here here triggered by the invoice
@@ -686,7 +686,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
// Should still be in clear state - the invoice for the bundle has been paid, but not the invoice with the external charge
// We refresh overdue just to be safe, see below
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-06 => Past 30 days since the external charge
addDaysAndCheckForCompletion(6, NextEvent.BLOCK);
@@ -697,7 +697,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
final Invoice externalChargeInvoice = invoiceUserApi.getUnpaidInvoicesByAccountId(account.getId(), clock.getUTCToday(), callContext).iterator().next();
createExternalPaymentAndCheckForCompletion(account, externalChargeInvoice, NextEvent.PAYMENT, NextEvent.BLOCK);
// We should be clear now
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
}
@Test(groups = "slow", description = "Test overdue after refund with no adjustment")
@@ -719,13 +719,13 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 6, 30), callContext);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-15 => DAY 45 - 15 days after invoice
addDaysAndCheckForCompletion(15);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-07-05 => DAY 65 - 35 days after invoice
addDaysAndCheckForCompletion(20, NextEvent.INVOICE, NextEvent.PAYMENT);
@@ -734,7 +734,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 7, 31), callContext);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// Now, refund the second (first non-zero dollar) invoice
final Payment payment = paymentApi.getPayment(invoiceUserApi.getInvoicesByAccount(account.getId(), callContext).get(1).getPayments().get(0).getPaymentId(), false, PLUGIN_PROPERTIES, callContext);
@@ -763,13 +763,13 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 6, 30), callContext);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-15 => DAY 45 - 15 days after invoice
addDaysAndCheckForCompletion(15);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-07-05 => DAY 65 - 35 days after invoice
addDaysAndCheckForCompletion(20, NextEvent.INVOICE, NextEvent.PAYMENT);
@@ -778,7 +778,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 7, 31), callContext);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// Now, create a chargeback for the second (first non-zero dollar) invoice
final InvoicePayment invoicePayment = invoicePaymentApi.getInvoicePayments(invoiceUserApi.getInvoicesByAccount(account.getId(), callContext).get(1).getPayments().get(0).getPaymentId(), callContext).get(0);
@@ -809,13 +809,13 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 6, 30), callContext);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-06-15 => DAY 45 - 15 days after invoice
addDaysAndCheckForCompletion(15, NextEvent.PAYMENT_ERROR);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// 2012-07-05 => DAY 65 - 35 days after invoice
addDaysAndCheckForCompletion(20, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT_ERROR, NextEvent.PAYMENT_ERROR);
@@ -834,7 +834,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
final Invoice firstNonZeroInvoice = invoiceUserApi.getUnpaidInvoicesByAccountId(account.getId(), clock.getUTCToday(), callContext).iterator().next();
createExternalPaymentAndCheckForCompletion(account, firstNonZeroInvoice, NextEvent.PAYMENT, NextEvent.BLOCK);
// We should be clear now
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
}
@Test(groups = "slow", description = "Test overdue clear after item adjustment")
@@ -857,13 +857,13 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 6, 30), callContext);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// DAY 45 - 15 days after invoice
addDaysAndCheckForCompletion(15, NextEvent.PAYMENT_ERROR);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// DAY 65 - 35 days after invoice
addDaysAndCheckForCompletion(20, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT_ERROR, NextEvent.PAYMENT_ERROR);
@@ -881,7 +881,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
final Invoice firstNonZeroInvoice = invoiceUserApi.getUnpaidInvoicesByAccountId(account.getId(), clock.getUTCToday(), callContext).iterator().next();
fullyAdjustInvoiceItemAndCheckForCompletion(account, firstNonZeroInvoice, 1, NextEvent.BLOCK, NextEvent.INVOICE_ADJUSTMENT);
// We should be clear now
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
invoiceChecker.checkInvoice(account.getId(), 2,
callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 31), new LocalDate(2012, 6, 30), InvoiceItemType.RECURRING, new BigDecimal("249.95")),
@@ -892,13 +892,13 @@ public class TestOverdueIntegration extends TestOverdueBase {
addDaysAndCheckForCompletion(5);
// We should still be clear
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// DAY 80 - 20 days after second invoice
addDaysAndCheckForCompletion(10, NextEvent.PAYMENT_ERROR);
// We should still be clear
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// DAY 95 - 35 days after second invoice
addDaysAndCheckForCompletion(15, NextEvent.BLOCK, NextEvent.PAYMENT_ERROR, NextEvent.INVOICE, NextEvent.PAYMENT_ERROR);
@@ -920,10 +920,9 @@ public class TestOverdueIntegration extends TestOverdueBase {
}
// We should be cleared again
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
}
-
private void allowPaymentsAndResetOverdueToClearByPayingAllUnpaidInvoices(final boolean extraPayment) {
// Reset plugin so payments should now succeed
paymentPlugin.makeAllInvoicesFailWithError(false);
@@ -951,7 +950,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
}
}
}
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
}
private List<Invoice> getUnpaidInvoicesOrderFromRecent() {
diff --git a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueWithSubscriptionCancellation.java b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueWithSubscriptionCancellation.java
index db0ce2b..ad3c961 100644
--- a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueWithSubscriptionCancellation.java
+++ b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueWithSubscriptionCancellation.java
@@ -31,6 +31,7 @@ import org.killbill.billing.entitlement.api.Entitlement.EntitlementState;
import org.killbill.billing.entitlement.api.SubscriptionBundle;
import org.killbill.billing.invoice.api.InvoiceItemType;
import org.killbill.billing.junction.DefaultBlockingState;
+import org.killbill.billing.overdue.wrapper.OverdueWrapper;
import org.killbill.billing.subscription.api.SubscriptionBase;
import org.testng.annotations.Test;
@@ -92,7 +93,7 @@ public class TestOverdueWithSubscriptionCancellation extends TestOverdueBase {
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// DAY 36 -- RIGHT AFTER OD1 (two block events, for the cancellation and the OD1 state)
@@ -148,7 +149,7 @@ public class TestOverdueWithSubscriptionCancellation extends TestOverdueBase {
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 6, 30), callContext);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// DAY 36 (2012-06-06)-- RIGHT AFTER OD1 (two block events, for the cancellation and the OD1 state)
// One BLOCK event is for the overdue state transition
diff --git a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueWithTags.java b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueWithTags.java
index 5e149e8..15e0790 100644
--- a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueWithTags.java
+++ b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/overdue/TestOverdueWithTags.java
@@ -21,18 +21,16 @@ import java.util.List;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
-import org.killbill.billing.invoice.api.Invoice;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
import org.killbill.billing.ObjectType;
import org.killbill.billing.api.TestApiListener.NextEvent;
import org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck;
import org.killbill.billing.catalog.api.ProductCategory;
import org.killbill.billing.entitlement.api.DefaultEntitlement;
+import org.killbill.billing.invoice.api.Invoice;
import org.killbill.billing.invoice.api.InvoiceItemType;
-import org.killbill.billing.junction.DefaultBlockingState;
+import org.killbill.billing.overdue.wrapper.OverdueWrapper;
import org.killbill.billing.util.tag.ControlTagType;
+import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
@@ -65,7 +63,6 @@ public class TestOverdueWithTags extends TestOverdueBase {
return configXml;
}
-
@Test(groups = "slow")
public void testOverdueStateAndWRITTEN_OFFTag() throws Exception {
clock.setTime(new DateTime(2012, 5, 1, 0, 3, 42, 0));
@@ -96,7 +93,7 @@ public class TestOverdueWithTags extends TestOverdueBase {
addDaysAndCheckForCompletion(6);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
busHandler.pushExpectedEvents(NextEvent.TAG, NextEvent.BLOCK);
tagUserApi.removeTag(nonNullInvoice.getId(), ObjectType.INVOICE, ControlTagType.WRITTEN_OFF.getId(), callContext);
@@ -104,7 +101,6 @@ public class TestOverdueWithTags extends TestOverdueBase {
checkODState("OD1");
}
-
@Test(groups = "slow")
public void testNonOverdueAccountWithOverdueEnforcementOffTag() throws Exception {
@@ -133,7 +129,7 @@ public class TestOverdueWithTags extends TestOverdueBase {
addDaysAndCheckForCompletion(6);
// Should still be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// Now remove OVERDUE_ENFORCEMENT_OFF tag
busHandler.pushExpectedEvents(NextEvent.TAG, NextEvent.BLOCK);
@@ -175,7 +171,7 @@ public class TestOverdueWithTags extends TestOverdueBase {
assertListenerStatus();
// Should now be in clear state
- checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
+ checkODState(OverdueWrapper.CLEAR_STATE_NAME);
// Now remove OVERDUE_ENFORCEMENT_OFF tag
busHandler.pushExpectedEvents(NextEvent.TAG, NextEvent.BLOCK);
diff --git a/entitlement/src/main/java/org/killbill/billing/entitlement/api/svcs/DefaultInternalBlockingApi.java b/entitlement/src/main/java/org/killbill/billing/entitlement/api/svcs/DefaultInternalBlockingApi.java
index 9259c5d..007c423 100644
--- a/entitlement/src/main/java/org/killbill/billing/entitlement/api/svcs/DefaultInternalBlockingApi.java
+++ b/entitlement/src/main/java/org/killbill/billing/entitlement/api/svcs/DefaultInternalBlockingApi.java
@@ -47,12 +47,7 @@ public class DefaultInternalBlockingApi implements BlockingInternalApi {
@Override
public BlockingState getBlockingStateForService(final UUID overdueableId, final BlockingStateType blockingStateType, final String serviceName, final InternalTenantContext context) {
- final BlockingState blockingStateForService = dao.getBlockingStateForService(overdueableId, blockingStateType, serviceName, context);
- if (blockingStateForService == null && serviceName.equals(OverdueService.OVERDUE_SERVICE_NAME)) {
- return DefaultBlockingState.getOverdueClearState(blockingStateType, serviceName, clock);
- } else {
- return blockingStateForService;
- }
+ return dao.getBlockingStateForService(overdueableId, blockingStateType, serviceName, context);
}
@Override
diff --git a/entitlement/src/test/java/org/killbill/billing/entitlement/dao/TestProxyBlockingStateDao.java b/entitlement/src/test/java/org/killbill/billing/entitlement/dao/TestProxyBlockingStateDao.java
index 549f02b..8c93f3a 100644
--- a/entitlement/src/test/java/org/killbill/billing/entitlement/dao/TestProxyBlockingStateDao.java
+++ b/entitlement/src/test/java/org/killbill/billing/entitlement/dao/TestProxyBlockingStateDao.java
@@ -78,7 +78,7 @@ public class TestProxyBlockingStateDao extends EntitlementTestSuiteNoDB {
final BlockingState bs4 = new DefaultBlockingState(UUID.randomUUID(),
blockedId,
blockingStateType,
- DefaultBlockingState.CLEAR_STATE_NAME,
+ "OD4",
service,
false,
false,
diff --git a/junction/src/test/java/org/killbill/billing/junction/TestDefaultBlockingState.java b/junction/src/test/java/org/killbill/billing/junction/TestDefaultBlockingState.java
index 2bc9e33..08616d2 100644
--- a/junction/src/test/java/org/killbill/billing/junction/TestDefaultBlockingState.java
+++ b/junction/src/test/java/org/killbill/billing/junction/TestDefaultBlockingState.java
@@ -45,7 +45,7 @@ public class TestDefaultBlockingState extends JunctionTestSuiteNoDB {
final BlockingState bs2 = new DefaultBlockingState(UUID.randomUUID(),
UUID.randomUUID(),
BlockingStateType.ACCOUNT,
- DefaultBlockingState.CLEAR_STATE_NAME,
+ "OD2",
"test",
false,
false,
diff --git a/overdue/src/main/java/org/killbill/billing/overdue/api/DefaultOverdueInternalApi.java b/overdue/src/main/java/org/killbill/billing/overdue/api/DefaultOverdueInternalApi.java
index 81c4002..4444547 100644
--- a/overdue/src/main/java/org/killbill/billing/overdue/api/DefaultOverdueInternalApi.java
+++ b/overdue/src/main/java/org/killbill/billing/overdue/api/DefaultOverdueInternalApi.java
@@ -50,6 +50,7 @@ import org.killbill.clock.Clock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.MoreObjects;
import com.google.inject.Inject;
public class DefaultOverdueInternalApi implements OverdueInternalApi {
@@ -83,7 +84,7 @@ public class DefaultOverdueInternalApi implements OverdueInternalApi {
public OverdueState getOverdueStateFor(final ImmutableAccountData overdueable, final TenantContext context) throws OverdueException {
try {
final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(context);
- final String stateName = accessApi.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, internalCallContextFactory.createInternalTenantContext(context)).getStateName();
+ final String stateName = MoreObjects.firstNonNull(accessApi.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, internalCallContextFactory.createInternalTenantContext(context)).getStateName(), OverdueWrapper.CLEAR_STATE_NAME);
final OverdueConfig overdueConfig = overdueConfigCache.getOverdueConfig(internalTenantContext);
final OverdueStateSet states = ((DefaultOverdueConfig) overdueConfig).getOverdueStatesAccount();
return states.findState(stateName);
diff --git a/overdue/src/main/java/org/killbill/billing/overdue/config/DefaultOverdueStateSet.java b/overdue/src/main/java/org/killbill/billing/overdue/config/DefaultOverdueStateSet.java
index 0628bae..eb71506 100644
--- a/overdue/src/main/java/org/killbill/billing/overdue/config/DefaultOverdueStateSet.java
+++ b/overdue/src/main/java/org/killbill/billing/overdue/config/DefaultOverdueStateSet.java
@@ -21,27 +21,26 @@ import javax.xml.bind.annotation.XmlAccessorType;
import org.joda.time.LocalDate;
import org.joda.time.Period;
-
import org.killbill.billing.ErrorCode;
import org.killbill.billing.overdue.api.OverdueApiException;
import org.killbill.billing.overdue.api.OverdueState;
import org.killbill.billing.overdue.config.api.BillingState;
import org.killbill.billing.overdue.config.api.OverdueStateSet;
+import org.killbill.billing.overdue.wrapper.OverdueWrapper;
import org.killbill.xmlloader.ValidatingConfig;
import org.killbill.xmlloader.ValidationErrors;
-import org.killbill.billing.junction.DefaultBlockingState;
@XmlAccessorType(XmlAccessType.NONE)
public abstract class DefaultOverdueStateSet extends ValidatingConfig<DefaultOverdueConfig> implements OverdueStateSet {
private static final Period ZERO_PERIOD = new Period();
- private final DefaultOverdueState clearState = new DefaultOverdueState().setName(DefaultBlockingState.CLEAR_STATE_NAME).setClearState(true);
+ private final DefaultOverdueState clearState = new DefaultOverdueState().setName(OverdueWrapper.CLEAR_STATE_NAME).setClearState(true);
public abstract DefaultOverdueState[] getStates();
@Override
public OverdueState findState(final String stateName) throws OverdueApiException {
- if (stateName.equals(DefaultBlockingState.CLEAR_STATE_NAME)) {
+ if (stateName.equals(OverdueWrapper.CLEAR_STATE_NAME)) {
return clearState;
}
for (final DefaultOverdueState state : getStates()) {
@@ -52,7 +51,6 @@ public abstract class DefaultOverdueStateSet extends ValidatingConfig<DefaultOve
throw new OverdueApiException(ErrorCode.CAT_NO_SUCH_OVEDUE_STATE, stateName);
}
-
/* (non-Javadoc)
* @see org.killbill.billing.catalog.overdue.OverdueBillingState#findClearState()
*/
diff --git a/overdue/src/main/java/org/killbill/billing/overdue/wrapper/OverdueWrapper.java b/overdue/src/main/java/org/killbill/billing/overdue/wrapper/OverdueWrapper.java
index a7c14f8..311db99 100644
--- a/overdue/src/main/java/org/killbill/billing/overdue/wrapper/OverdueWrapper.java
+++ b/overdue/src/main/java/org/killbill/billing/overdue/wrapper/OverdueWrapper.java
@@ -39,8 +39,13 @@ import org.killbill.commons.locker.LockFailedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.MoreObjects;
+
public class OverdueWrapper {
+
+ public static final String CLEAR_STATE_NAME = "__KILLBILL__CLEAR__OVERDUE_STATE__";
+
private static final Logger log = LoggerFactory.getLogger(OverdueWrapper.class);
// Should we introduce a config?
@@ -93,7 +98,7 @@ public class OverdueWrapper {
private OverdueState refreshWithLock(final InternalCallContext context) throws OverdueException, OverdueApiException {
final BillingState billingState = billingState(context);
- final String previousOverdueStateName = api.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, context).getStateName();
+ final String previousOverdueStateName = MoreObjects.firstNonNull(api.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, context).getStateName(), OverdueWrapper.CLEAR_STATE_NAME);
final OverdueState currentOverdueState = overdueStateSet.findState(previousOverdueStateName);
final OverdueState nextOverdueState = overdueStateSet.calculateOverdueState(billingState, clock.getToday(billingState.getAccountTimeZone()));
@@ -120,7 +125,7 @@ public class OverdueWrapper {
}
private void clearWithLock(final InternalCallContext context) throws OverdueException, OverdueApiException {
- final String previousOverdueStateName = api.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, context).getStateName();
+ final String previousOverdueStateName = MoreObjects.firstNonNull(api.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, context).getStateName(), OverdueWrapper.CLEAR_STATE_NAME);
final OverdueState previousOverdueState = overdueStateSet.findState(previousOverdueStateName);
overdueStateApplicator.clear(overdueable, previousOverdueState, overdueStateSet.getClearState(), context);
}
diff --git a/overdue/src/test/java/org/killbill/billing/overdue/applicator/TestOverdueStateApplicator.java b/overdue/src/test/java/org/killbill/billing/overdue/applicator/TestOverdueStateApplicator.java
index 5c77f5c..2222377 100644
--- a/overdue/src/test/java/org/killbill/billing/overdue/applicator/TestOverdueStateApplicator.java
+++ b/overdue/src/test/java/org/killbill/billing/overdue/applicator/TestOverdueStateApplicator.java
@@ -25,6 +25,7 @@ import java.util.concurrent.Callable;
import org.killbill.billing.account.api.ImmutableAccountData;
import org.killbill.billing.overdue.api.OverdueState;
import org.killbill.billing.overdue.config.DefaultOverdueConfig;
+import org.killbill.billing.overdue.wrapper.OverdueWrapper;
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -49,7 +50,7 @@ public class TestOverdueStateApplicator extends OverdueTestSuiteWithEmbeddedDB {
Mockito.when(account.getId()).thenReturn(UUID.randomUUID());
final OverdueStateSet overdueStateSet = config.getOverdueStatesAccount();
- final OverdueState clearState = config.getOverdueStatesAccount().findState(DefaultBlockingState.CLEAR_STATE_NAME);
+ final OverdueState clearState = config.getOverdueStatesAccount().findState(OverdueWrapper.CLEAR_STATE_NAME);
OverdueState state;
state = config.getOverdueStatesAccount().findState("OD1");
diff --git a/overdue/src/test/java/org/killbill/billing/overdue/glue/TestOverdueModule.java b/overdue/src/test/java/org/killbill/billing/overdue/glue/TestOverdueModule.java
index c0131ee..df5a469 100644
--- a/overdue/src/test/java/org/killbill/billing/overdue/glue/TestOverdueModule.java
+++ b/overdue/src/test/java/org/killbill/billing/overdue/glue/TestOverdueModule.java
@@ -21,6 +21,7 @@ package org.killbill.billing.overdue.glue;
import java.util.List;
import java.util.UUID;
+import org.joda.time.DateTime;
import org.killbill.billing.callcontext.InternalCallContext;
import org.killbill.billing.callcontext.InternalTenantContext;
import org.killbill.billing.entitlement.api.BlockingState;
@@ -37,6 +38,7 @@ import org.killbill.billing.overdue.applicator.OverdueBusListenerTester;
import org.killbill.billing.overdue.caching.MockOverdueConfigCache;
import org.killbill.billing.overdue.caching.OverdueCacheInvalidationCallback;
import org.killbill.billing.overdue.caching.OverdueConfigCache;
+import org.killbill.billing.overdue.wrapper.OverdueWrapper;
import org.killbill.billing.platform.api.KillbillConfigSource;
import org.killbill.billing.tenant.api.TenantInternalApi.CacheInvalidationCallback;
import org.killbill.billing.util.email.EmailModule;
@@ -46,6 +48,7 @@ import org.killbill.billing.util.glue.CacheModule;
import org.killbill.billing.util.glue.CallContextModule;
import org.killbill.billing.util.glue.CustomFieldModule;
import org.killbill.billing.util.glue.MemoryGlobalLockerModule;
+import org.killbill.clock.Clock;
import org.killbill.clock.ClockMock;
import com.google.inject.name.Names;
@@ -90,12 +93,13 @@ public class TestOverdueModule extends DefaultOverdueModule {
return blockingState;
}
+
@Override
public BlockingState getBlockingStateForService(final UUID blockableId, final BlockingStateType blockingStateType, final String serviceName, final InternalTenantContext context) {
if (blockingState != null && blockingState.getBlockedId().equals(blockableId)) {
return blockingState;
} else {
- return DefaultBlockingState.getOverdueClearState(blockingStateType, serviceName, new ClockMock());
+ return new DefaultBlockingState(null, blockingStateType, OverdueWrapper.CLEAR_STATE_NAME, serviceName, false, false, false, null);
}
}
diff --git a/overdue/src/test/java/org/killbill/billing/overdue/wrapper/TestOverdueWrapper.java b/overdue/src/test/java/org/killbill/billing/overdue/wrapper/TestOverdueWrapper.java
index c6e2231..2c22056 100644
--- a/overdue/src/test/java/org/killbill/billing/overdue/wrapper/TestOverdueWrapper.java
+++ b/overdue/src/test/java/org/killbill/billing/overdue/wrapper/TestOverdueWrapper.java
@@ -76,7 +76,7 @@ public class TestOverdueWrapper extends OverdueTestSuiteWithEmbeddedDB {
final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes());
final DefaultOverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, DefaultOverdueConfig.class);
- state = config.getOverdueStatesAccount().findState(DefaultBlockingState.CLEAR_STATE_NAME);
+ state = config.getOverdueStatesAccount().findState(OverdueWrapper.CLEAR_STATE_NAME);
account = testOverdueHelper.createImmutableAccountData(clock.getUTCToday().minusDays(31));
wrapper = overdueWrapperFactory.createOverdueWrapperFor(account, internalCallContext);
final OverdueState result = wrapper.refresh(internalCallContext);
diff --git a/payment/src/test/java/org/killbill/billing/payment/glue/MockEntitlementModuleForPayment.java b/payment/src/test/java/org/killbill/billing/payment/glue/MockEntitlementModuleForPayment.java
index ae2c6aa..46a82ab 100644
--- a/payment/src/test/java/org/killbill/billing/payment/glue/MockEntitlementModuleForPayment.java
+++ b/payment/src/test/java/org/killbill/billing/payment/glue/MockEntitlementModuleForPayment.java
@@ -43,7 +43,7 @@ public class MockEntitlementModuleForPayment extends MockEntitlementModule {
public void installBlockingApi() {
super.installBlockingApi();
- final BlockingState blockingState = new DefaultBlockingState(null, BlockingStateType.ACCOUNT, DefaultBlockingState.CLEAR_STATE_NAME, "test", false, false, false, new DateTime(DateTimeZone.UTC));
+ final BlockingState blockingState = new DefaultBlockingState(null, BlockingStateType.ACCOUNT, "CLEAR_STATE_NAME", "test", false, false, false, new DateTime(DateTimeZone.UTC));
Mockito.when(blockingApi.getBlockingAllForAccount(Mockito.<InternalTenantContext>any())).thenReturn(ImmutableList.<BlockingState>of(blockingState));
Mockito.when(blockingApi.getBlockingStateForService(Mockito.<UUID>any(), Mockito.<BlockingStateType>any(), Mockito.anyString(), Mockito.<InternalTenantContext>any())).thenReturn(blockingState);
}