Details
diff --git a/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java b/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
index 9986bbf..3b27fa6 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
@@ -43,6 +43,7 @@ import com.ning.billing.invoice.api.user.DefaultInvoiceCreationNotification;
import com.ning.billing.invoice.model.FixedPriceInvoiceItem;
import com.ning.billing.invoice.model.RecurringInvoiceItem;
import com.ning.billing.invoice.notification.DefaultNextBillingDateNotifier;
+import com.ning.billing.invoice.notification.NextBillingDatePoster;
import com.ning.billing.util.bus.Bus;
import com.ning.billing.util.notificationq.NotificationKey;
import com.ning.billing.util.notificationq.NotificationQueue;
@@ -60,19 +61,19 @@ public class DefaultInvoiceDao implements InvoiceDao {
private final Bus eventBus;
- private NotificationQueueService notificationQueueService;
+ private NextBillingDatePoster nextBillingDatePoster;
@Inject
public DefaultInvoiceDao(final IDBI dbi, final Bus eventBus,
final EntitlementBillingApi entitlementBillingApi,
- NotificationQueueService notificationQueueService) {
+ NextBillingDatePoster nextBillingDatePoster) {
this.invoiceSqlDao = dbi.onDemand(InvoiceSqlDao.class);
this.recurringInvoiceItemSqlDao = dbi.onDemand(RecurringInvoiceItemSqlDao.class);
this.fixedPriceInvoiceItemSqlDao = dbi.onDemand(FixedPriceInvoiceItemSqlDao.class);
this.invoicePaymentSqlDao = dbi.onDemand(InvoicePaymentSqlDao.class);
this.eventBus = eventBus;
this.entitlementBillingApi = entitlementBillingApi;
- this.notificationQueueService = notificationQueueService;
+ this.nextBillingDatePoster = nextBillingDatePoster;
}
@Override
@@ -282,30 +283,12 @@ public class DefaultInvoiceDao implements InvoiceDao {
if ((recurringInvoiceItem.getEndDate() != null) &&
(recurringInvoiceItem.getAmount() == null ||
recurringInvoiceItem.getAmount().compareTo(BigDecimal.ZERO) >= 0)) {
- insertNextBillingNotification(dao, item.getSubscriptionId(), recurringInvoiceItem.getEndDate());
+ nextBillingDatePoster.insertNextBillingNotification(dao, item.getSubscriptionId(), recurringInvoiceItem.getEndDate());
}
}
}
}
- public void insertNextBillingNotification(final Transmogrifier transactionalDao, final UUID subscriptionId, final DateTime futureNotificationTime) {
- NotificationQueue nextBillingQueue;
- try {
- nextBillingQueue = notificationQueueService.getNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME,
- DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE);
- log.info("Queuing next billing date notification. id: {}, timestamp: {}", subscriptionId.toString(), futureNotificationTime.toString());
-
- nextBillingQueue.recordFutureNotificationFromTransaction(transactionalDao, futureNotificationTime, new NotificationKey(){
- @Override
- public String toString() {
- return subscriptionId.toString();
- }
- });
- } catch (NoSuchNotificationQueue e) {
- log.error("Attempting to put items on a non-existent queue (NextBillingDateNotifier).", e);
- }
- }
-
private void setChargedThroughDates(final InvoiceSqlDao dao, final Collection<InvoiceItem> fixedPriceItems,
final Collection<InvoiceItem> recurringItems) {
Map<UUID, DateTime> chargeThroughDates = new HashMap<UUID, DateTime>();
diff --git a/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDatePoster.java b/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDatePoster.java
new file mode 100644
index 0000000..8ddb29d
--- /dev/null
+++ b/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDatePoster.java
@@ -0,0 +1,63 @@
+/*
+ * 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.invoice.notification;
+
+import java.util.UUID;
+
+import org.joda.time.DateTime;
+import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.ning.billing.invoice.api.DefaultInvoiceService;
+import com.ning.billing.util.notificationq.NotificationKey;
+import com.ning.billing.util.notificationq.NotificationQueue;
+import com.ning.billing.util.notificationq.NotificationQueueService;
+import com.ning.billing.util.notificationq.NotificationQueueService.NoSuchNotificationQueue;
+
+public class DefaultNextBillingDatePoster implements NextBillingDatePoster {
+ private final static Logger log = LoggerFactory.getLogger(DefaultNextBillingDateNotifier.class);
+
+ private final NotificationQueueService notificationQueueService;
+
+ @Inject
+ public DefaultNextBillingDatePoster(
+ NotificationQueueService notificationQueueService) {
+ super();
+ this.notificationQueueService = notificationQueueService;
+ }
+
+ @Override
+ public void insertNextBillingNotification(final Transmogrifier transactionalDao, final UUID subscriptionId, final DateTime futureNotificationTime) {
+ NotificationQueue nextBillingQueue;
+ try {
+ nextBillingQueue = notificationQueueService.getNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME,
+ DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE);
+ log.info("Queuing next billing date notification. id: {}, timestamp: {}", subscriptionId.toString(), futureNotificationTime.toString());
+
+ nextBillingQueue.recordFutureNotificationFromTransaction(transactionalDao, futureNotificationTime, new NotificationKey(){
+ @Override
+ public String toString() {
+ return subscriptionId.toString();
+ }
+ });
+ } catch (NoSuchNotificationQueue e) {
+ log.error("Attempting to put items on a non-existent queue (NextBillingDateNotifier).", e);
+ }
+ }
+}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDateNotifier.java b/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDateNotifier.java
index febdc75..ea630aa 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDateNotifier.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDateNotifier.java
@@ -16,10 +16,6 @@
package com.ning.billing.invoice.notification;
-import java.util.UUID;
-
-import org.joda.time.DateTime;
-import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
public interface NextBillingDateNotifier {
diff --git a/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDatePoster.java b/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDatePoster.java
new file mode 100644
index 0000000..67598d1
--- /dev/null
+++ b/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDatePoster.java
@@ -0,0 +1,29 @@
+/*
+ * 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.invoice.notification;
+
+import java.util.UUID;
+
+import org.joda.time.DateTime;
+import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
+
+public interface NextBillingDatePoster {
+
+ void insertNextBillingNotification(Transmogrifier transactionalDao,
+ UUID subscriptionId, DateTime futureNotificationTime);
+
+}
\ No newline at end of file
diff --git a/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java b/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java
index 4fe003c..67c27fa 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java
@@ -74,6 +74,7 @@ public class TestNextBillingDateNotifier {
private Bus eventBus;
private MysqlTestingHelper helper;
private InvoiceListenerMock listener = new InvoiceListenerMock();
+ private NotificationQueueService notificationQueueService;
private static final class InvoiceListenerMock extends InvoiceListener {
int eventCount = 0;
@@ -251,7 +252,8 @@ public class TestNextBillingDateNotifier {
dao = dbi.onDemand(DummySqlTest.class);
eventBus = g.getInstance(Bus.class);
helper = g.getInstance(MysqlTestingHelper.class);
- notifier = new DefaultNextBillingDateNotifier(g.getInstance(NotificationQueueService.class),g.getInstance(InvoiceConfig.class), new MockEntitlementDao(), listener);
+ notificationQueueService = g.getInstance(NotificationQueueService.class);
+ notifier = new DefaultNextBillingDateNotifier(notificationQueueService,g.getInstance(InvoiceConfig.class), new MockEntitlementDao(), listener);
startMysql();
}
@@ -266,22 +268,24 @@ public class TestNextBillingDateNotifier {
}
- @Test(enabled=false, groups="slow")
+ @Test(enabled=true, groups="slow")
public void test() throws Exception {
final UUID subscriptionId = new UUID(0L,1L);
final DateTime now = new DateTime();
final DateTime readyTime = now.plusMillis(2000);
+ final NextBillingDatePoster poster = new DefaultNextBillingDatePoster(notificationQueueService);
eventBus.start();
notifier.initialize();
notifier.start();
+
dao.inTransaction(new Transaction<Void, DummySqlTest>() {
@Override
public Void inTransaction(DummySqlTest transactional,
TransactionStatus status) throws Exception {
- //DefaultInvoiceDao insertDao = new DefaultInvoiceDao();
- ((DefaultInvoiceDao)dao).insertNextBillingNotification(transactional, subscriptionId, readyTime);
+
+ poster.insertNextBillingNotification(transactional, subscriptionId, readyTime);
return null;
}
});