killbill-memoizeit

Fixed tests for BillingEvents that must have been broken for

1/17/2012 1:49:24 AM

Changes

entitlement/src/test/resources/versionedCatalog/WeaponsHireSmall-1.xml 159(+0 -159)

entitlement/src/test/resources/versionedCatalog/WeaponsHireSmall-2.xml 159(+0 -159)

entitlement/src/test/resources/versionedCatalog/WeaponsHireSmall-3.xml 159(+0 -159)

Details

diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/billing/TestDefaultEntitlementBillingApi.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/billing/TestDefaultEntitlementBillingApi.java
index 08b05d6..77eb10b 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/billing/TestDefaultEntitlementBillingApi.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/billing/TestDefaultEntitlementBillingApi.java
@@ -89,7 +89,7 @@ public class TestDefaultEntitlementBillingApi {
         ((DefaultCatalogService)catalogService).loadCatalog();
 	}
 	
-	@BeforeMethod
+	@BeforeMethod(alwaysRun=true)
 	public void setupEveryTime() {
 		bundles = new ArrayList<SubscriptionBundle>();
 		final SubscriptionBundle bundle = new SubscriptionBundleData( zeroId,"TestKey", oneId,  new DateTime().minusDays(4));
@@ -97,13 +97,11 @@ public class TestDefaultEntitlementBillingApi {
 		
 		
 		transitions = new ArrayList<SubscriptionTransition>();
-		
-		
 		subscriptions = new ArrayList<Subscription>();
 		
 		SubscriptionBuilder builder = new SubscriptionBuilder();
 		subscriptionStartDate = new DateTime().minusDays(3);
-		builder.setStartDate(subscriptionStartDate);
+		builder.setStartDate(subscriptionStartDate).setId(oneId);
 		subscription = new SubscriptionData(builder) {
 		    public List<SubscriptionTransition> getAllTransitions() {
 		    	return transitions;
@@ -132,13 +130,11 @@ public class TestDefaultEntitlementBillingApi {
 			public SubscriptionBundle getSubscriptionBundleFromId(UUID bundleId) {
 				return bundle;
 			}
-
-
 		};
 
 	}
 	
-	@Test
+    @Test(enabled=true, groups="fast")
 	public void testBillingEventsEmpty() {
 		EntitlementDao dao = new BrainDeadMockEntitlementDao() {
 			public List<SubscriptionBundle> getSubscriptionBundleForAccount(
@@ -153,7 +149,7 @@ public class TestDefaultEntitlementBillingApi {
 		Assert.assertEquals(events.size(), 0);
 	}
 	
-	@Test
+    @Test(enabled=true, groups="fast")
 	public void testBillingEventsNoBillingPeriod() throws CatalogApiException {
 		DateTime now = clock.getUTCNow();
 		DateTime then = now.minusDays(1);
@@ -178,7 +174,7 @@ public class TestDefaultEntitlementBillingApi {
 		checkFirstEvent(events, nextPlan, 32, oneId, now, nextPhase, ApiEventType.CREATE.toString());
 	}
 
-	@Test
+    @Test(enabled=true, groups="fast")
 	public void testBillingEventsAnual() throws CatalogApiException {
 		DateTime now = clock.getUTCNow();
 		DateTime then = now.minusDays(1);
@@ -203,11 +199,11 @@ public class TestDefaultEntitlementBillingApi {
 		checkFirstEvent(events, nextPlan, subscription.getStartDate().getDayOfMonth(), oneId, now, nextPhase, ApiEventType.CREATE.toString());
 	}
 	
-	@Test
+    @Test(enabled=true, groups="fast")
 	public void testBillingEventsMonthly() throws CatalogApiException {
 		DateTime now = clock.getUTCNow();
 		DateTime then = now.minusDays(1);
-		Plan nextPlan = catalogService.getFullCatalog().findPlan("shotgun-annual", now);
+		Plan nextPlan = catalogService.getFullCatalog().findPlan("shotgun-monthly", now);
 		PlanPhase nextPhase = nextPlan.getAllPhases()[1];
 		String nextPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
 		SubscriptionTransition t = new SubscriptionTransitionData(
@@ -228,11 +224,11 @@ public class TestDefaultEntitlementBillingApi {
 		checkFirstEvent(events, nextPlan, 32, oneId, now, nextPhase, ApiEventType.CREATE.toString());
 	}
 	
-	@Test
+    @Test(enabled=true, groups="fast")
 	public void testBillingEventsAddOn() throws CatalogApiException {
 		DateTime now = clock.getUTCNow();
 		DateTime then = now.minusDays(1);
-		Plan nextPlan = catalogService.getFullCatalog().findPlan("shotgun-annual", now);
+		Plan nextPlan = catalogService.getFullCatalog().findPlan("laser-scope-monthly", now);
 		PlanPhase nextPhase = nextPlan.getAllPhases()[0];
 		String nextPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
 		SubscriptionTransition t = new SubscriptionTransitionData(
diff --git a/entitlement/src/test/resources/entitlement.properties b/entitlement/src/test/resources/entitlement.properties
index 227aa7e..d149d78 100644
--- a/entitlement/src/test/resources/entitlement.properties
+++ b/entitlement/src/test/resources/entitlement.properties
@@ -1,4 +1,4 @@
-killbill.catalog.uri=file:src/test/resources/versionedCatalog
+killbill.catalog.uri=file:src/test/resources/testInput.xml
 killbill.entitlement.dao.claim.time=60000
 killbill.entitlement.dao.ready.max=1
 killbill.entitlement.engine.notifications.sleep=500
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 a8a1b9e..5371824 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
@@ -18,112 +18,12 @@ package com.ning.billing.invoice.notification;
 
 import java.util.UUID;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.joda.time.DateTime;
+import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
 
-import com.google.inject.Inject;
-import com.ning.billing.config.InvoiceConfig;
-import com.ning.billing.entitlement.exceptions.EntitlementError;
-import com.ning.billing.lifecycle.KillbillService;
-import com.ning.billing.lifecycle.LifecycleHandlerType;
-import com.ning.billing.lifecycle.LifecycleHandlerType.LifecycleLevel;
-import com.ning.billing.util.eventbus.Bus;
-import com.ning.billing.util.eventbus.Bus.EventBusException;
-import com.ning.billing.util.notificationq.NotificationConfig;
-import com.ning.billing.util.notificationq.NotificationQueue;
-import com.ning.billing.util.notificationq.NotificationQueueService;
-import com.ning.billing.util.notificationq.NotificationQueueService.NotficationQueueAlreadyExists;
-import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueHandler;
+public interface NextBillingDateNotifier {
 
-public class NextBillingDateNotifier implements KillbillService {
-    private final static Logger log = LoggerFactory.getLogger(NextBillingDateNotifier.class);
-
-    private static final String NEXT_BILLING_DATE_NOTIFIER_SERVICE_NAME = "next-billing-date-notifier";
-    private static final String NEXT_BILLING_DATE_NOTIFIER_QUEUE = "next-billing-date-queue";
-    
-    private final Bus eventBus;
-	private boolean stoppedNotificationThread;
-	private boolean startedNotificationThread;
-    private final NotificationQueueService notificationQueueService;
-    private NotificationQueue nextBillingQueue;
-	private InvoiceConfig config;
-
-	@Inject
-	public NextBillingDateNotifier(NotificationQueueService notificationQueueService, Bus eventBus, InvoiceConfig config){
-		this.notificationQueueService = notificationQueueService;
-		this.config = config;
-		this.eventBus = eventBus;
-	}
-	
-	
-	@LifecycleHandlerType(LifecycleLevel.INIT_SERVICE)
-    public void initialize() {
-		try {
-            this.stoppedNotificationThread = false;
-            this.startedNotificationThread = false;
-            nextBillingQueue = notificationQueueService.createNotificationQueue(NEXT_BILLING_DATE_NOTIFIER_SERVICE_NAME,
-            		NEXT_BILLING_DATE_NOTIFIER_QUEUE,
-                    new NotificationQueueHandler() {
-                @Override
-                public void handleReadyNotification(String notificationKey) {
-                	UUID subscriptionId;
-                	try {
-                		subscriptionId = UUID.fromString(notificationKey);
-                	} catch (IllegalArgumentException e) {
-                		log.error("The key returned from the NextBillingNotificationQueue is not a valid UUID",e);
-                		return;
-                	}
-                    
-                    processEventReady(subscriptionId);
-                }
-            },
-            new NotificationConfig() {
-                @Override
-                public boolean isNotificationProcessingOff() {
-                    return config.isEventProcessingOff();
-                }
-                @Override
-                public long getNotificationSleepTimeMs() {
-                    return config.getNotificationSleepTimeMs();
-                }
-                @Override
-                public int getDaoMaxReadyEvents() {
-                    return config.getDaoMaxReadyEvents();
-                }
-                @Override
-                public long getDaoClaimTimeMs() {
-                    return config.getDaoMaxReadyEvents();
-                }
-            });
-        } catch (NotficationQueueAlreadyExists e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    @LifecycleHandlerType(LifecycleLevel.START_SERVICE)
-    public void start() {
-    	nextBillingQueue.startQueue();
-    }
-
-    @LifecycleHandlerType(LifecycleLevel.STOP_SERVICE)
-    public void stop() {
-        if (nextBillingQueue != null) {
-        	nextBillingQueue.stopQueue();
-        }
-        startedNotificationThread = false;
-    }
-     
-	@Override
-	public String getName() {
-		return NEXT_BILLING_DATE_NOTIFIER_SERVICE_NAME;
-	}
-	
-    public void processEventReady(UUID subscriptionId) {
-        try {
-            eventBus.post(new NextBillingDateEvent(subscriptionId));
-        } catch (EventBusException e) {
-            log.error("Failed to post entitlement event " + subscriptionId, e);
-        }
-    }
+	void insertNextBillingNotification(Transmogrifier transactionalDao,
+			UUID subscriptionId, DateTime futureNotificationTime);
 
 }