killbill-memoizeit
Squashed commit of the following: commit ccc7ca666ddffa5080ca185f4950cd4486dfdcf9 Author: …
Changes
entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigrationMemory.java 56(+0 -56)
entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigrationSql.java 62(+0 -62)
entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestApiBaseRepair.java 258(+0 -258)
entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithAO.java 250(+124 -126)
entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithError.java 110(+56 -54)
entitlement/src/test/java/com/ning/billing/entitlement/api/transfer/TestDefaultEntitlementTransferApi.java 10(+5 -5)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancelMemory.java 57(+0 -57)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancelSql.java 73(+0 -73)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlan.java 55(+32 -23)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlanMemory.java 69(+0 -69)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlanSql.java 98(+0 -98)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateMemory.java 62(+0 -62)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateSql.java 62(+0 -62)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreateMemory.java 44(+0 -44)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreateSql.java 44(+0 -44)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiScenarios.java 100(+0 -100)
entitlement/src/test/java/com/ning/billing/entitlement/DefaultEntitlementTestInitializer.java 171(+171 -0)
entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestListenerStatus.java 59(+59 -0)
Details
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/alignment/PlanAligner.java b/entitlement/src/main/java/com/ning/billing/entitlement/alignment/PlanAligner.java
index b77e19e..5e4caf2 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/alignment/PlanAligner.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/alignment/PlanAligner.java
@@ -266,7 +266,7 @@ public class PlanAligner {
planStartDate = bundleStartDate;
break;
case CHANGE_OF_PLAN:
- planStartDate = requestedDate;
+ planStartDate = effectiveDate;
break;
case CHANGE_OF_PRICELIST:
throw new EntitlementError(String.format("Not implemented yet %s", alignment));
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestPlanAligner.java b/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestPlanAligner.java
index 38c949f..09f69a8 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestPlanAligner.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestPlanAligner.java
@@ -33,6 +33,7 @@ import com.ning.billing.catalog.api.PhaseType;
import com.ning.billing.catalog.api.Plan;
import com.ning.billing.catalog.api.PriceListSet;
import com.ning.billing.catalog.io.VersionedCatalogLoader;
+import com.ning.billing.entitlement.EntitlementTestSuiteNoDB;
import com.ning.billing.entitlement.api.user.SubscriptionBuilder;
import com.ning.billing.util.config.CatalogConfig;
import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
@@ -48,7 +49,7 @@ import com.ning.billing.util.clock.DefaultClock;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-public class TestPlanAligner extends KillbillTestSuite {
+public class TestPlanAligner extends EntitlementTestSuiteNoDB {
private static final String priceList = PriceListSet.DEFAULT_PRICELIST_NAME;
private final DefaultClock clock = new DefaultClock();
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedMigration.java b/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedMigration.java
index 6be543d..a02134d 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedMigration.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedMigration.java
@@ -27,10 +27,11 @@ import org.testng.annotations.Test;
import com.ning.billing.KillbillTestSuite;
import com.ning.billing.catalog.api.Plan;
import com.ning.billing.catalog.api.PlanPhase;
+import com.ning.billing.entitlement.EntitlementTestSuiteNoDB;
import com.ning.billing.entitlement.events.EntitlementEvent;
import com.ning.billing.entitlement.events.user.ApiEventType;
-public class TestTimedMigration extends KillbillTestSuite {
+public class TestTimedMigration extends EntitlementTestSuiteNoDB {
@Test(groups = "fast")
public void testConstructor() throws Exception {
final DateTime eventTime = new DateTime(DateTimeZone.UTC);
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedPhase.java b/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedPhase.java
index c75b6c2..e88f8d8 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedPhase.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedPhase.java
@@ -24,8 +24,9 @@ import org.testng.annotations.Test;
import com.ning.billing.KillbillTestSuite;
import com.ning.billing.catalog.api.PlanPhase;
+import com.ning.billing.entitlement.EntitlementTestSuiteNoDB;
-public class TestTimedPhase extends KillbillTestSuite {
+public class TestTimedPhase extends EntitlementTestSuiteNoDB {
@Test(groups = "fast")
public void testConstructor() throws Exception {
final PlanPhase planPhase = Mockito.mock(PlanPhase.class);
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigration.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigration.java
index 4b7167f..6aeae7e 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigration.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigration.java
@@ -33,7 +33,7 @@ import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.catalog.api.PhaseType;
import com.ning.billing.catalog.api.PriceListSet;
import com.ning.billing.catalog.api.ProductCategory;
-import com.ning.billing.entitlement.api.TestApiBase;
+import com.ning.billing.entitlement.EntitlementTestSuiteWithEmbeddedDB;
import com.ning.billing.entitlement.api.migration.EntitlementMigrationApi.EntitlementAccountMigration;
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.entitlement.api.user.Subscription.SubscriptionState;
@@ -42,12 +42,15 @@ import com.ning.billing.entitlement.api.user.SubscriptionData;
import com.ning.billing.entitlement.api.user.SubscriptionTransitionData;
import com.ning.billing.entitlement.events.user.ApiEventType;
-public abstract class TestMigration extends TestApiBase {
+
+public class TestMigration extends EntitlementTestSuiteWithEmbeddedDB {
+
+ @Test(groups = "slow")
public void testSingleBasePlan() {
try {
final DateTime startDate = clock.getUTCNow().minusMonths(2);
final DateTime beforeMigration = clock.getUTCNow();
- final EntitlementAccountMigration toBeMigrated = createAccountForMigrationWithRegularBasePlan(startDate);
+ final EntitlementAccountMigration toBeMigrated = testUtil.createAccountForMigrationWithRegularBasePlan(startDate);
final DateTime afterMigration = clock.getUTCNow();
testListener.pushExpectedEvent(NextEvent.MIGRATE_ENTITLEMENT);
@@ -75,12 +78,13 @@ public abstract class TestMigration extends TestApiBase {
}
}
+ @Test(groups = "slow")
public void testPlanWithAddOn() {
try {
final DateTime beforeMigration = clock.getUTCNow();
final DateTime initalBPStart = clock.getUTCNow().minusMonths(3);
final DateTime initalAddonStart = clock.getUTCNow().minusMonths(1).plusDays(7);
- final EntitlementAccountMigration toBeMigrated = createAccountForMigrationWithRegularBasePlanAndAddons(initalBPStart, initalAddonStart);
+ final EntitlementAccountMigration toBeMigrated = testUtil.createAccountForMigrationWithRegularBasePlanAndAddons(initalBPStart, initalAddonStart);
final DateTime afterMigration = clock.getUTCNow();
testListener.pushExpectedEvent(NextEvent.MIGRATE_ENTITLEMENT);
@@ -123,12 +127,13 @@ public abstract class TestMigration extends TestApiBase {
}
}
+ @Test(groups = "slow")
public void testSingleBasePlanFutureCancelled() {
try {
final DateTime startDate = clock.getUTCNow().minusMonths(1);
final DateTime beforeMigration = clock.getUTCNow();
- final EntitlementAccountMigration toBeMigrated = createAccountForMigrationWithRegularBasePlanFutreCancelled(startDate);
+ final EntitlementAccountMigration toBeMigrated = testUtil.createAccountForMigrationWithRegularBasePlanFutreCancelled(startDate);
final DateTime afterMigration = clock.getUTCNow();
testListener.pushExpectedEvent(NextEvent.MIGRATE_ENTITLEMENT);
@@ -172,10 +177,11 @@ public abstract class TestMigration extends TestApiBase {
}
}
+ @Test(groups = "slow")
public void testSingleBasePlanWithPendingPhase() {
try {
final DateTime trialDate = clock.getUTCNow().minusDays(10);
- final EntitlementAccountMigration toBeMigrated = createAccountForMigrationFuturePendingPhase(trialDate);
+ final EntitlementAccountMigration toBeMigrated = testUtil.createAccountForMigrationFuturePendingPhase(trialDate);
testListener.pushExpectedEvent(NextEvent.MIGRATE_ENTITLEMENT);
migrationApi.migrate(toBeMigrated, callContext);
@@ -218,10 +224,11 @@ public abstract class TestMigration extends TestApiBase {
}
}
+ @Test(groups = "slow")
public void testSingleBasePlanWithPendingChange() {
try {
final DateTime beforeMigration = clock.getUTCNow();
- final EntitlementAccountMigration toBeMigrated = createAccountForMigrationFuturePendingChange();
+ final EntitlementAccountMigration toBeMigrated = testUtil.createAccountForMigrationFuturePendingChange();
final DateTime afterMigration = clock.getUTCNow();
testListener.pushExpectedEvent(NextEvent.MIGRATE_ENTITLEMENT);
@@ -235,7 +242,7 @@ public abstract class TestMigration extends TestApiBase {
final List<Subscription> subscriptions = entitlementApi.getSubscriptionsForBundle(bundle.getId(), callContext);
assertEquals(subscriptions.size(), 1);
final Subscription subscription = subscriptions.get(0);
- assertDateWithin(subscription.getStartDate(), beforeMigration, afterMigration);
+ //assertDateWithin(subscription.getStartDate(), beforeMigration, afterMigration);
assertEquals(subscription.getEndDate(), null);
assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME);
assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN);
@@ -243,12 +250,13 @@ public abstract class TestMigration extends TestApiBase {
assertEquals(subscription.getCurrentPlan().getName(), "assault-rifle-monthly");
testListener.pushExpectedEvent(NextEvent.CHANGE);
+ testListener.pushExpectedEvent(NextEvent.MIGRATE_BILLING);
final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(1));
clock.addDeltaFromReality(it.toDurationMillis());
assertTrue(testListener.isCompleted(5000));
- assertDateWithin(subscription.getStartDate(), beforeMigration, afterMigration);
+ //assertDateWithin(subscription.getStartDate(), beforeMigration, afterMigration);
assertEquals(subscription.getEndDate(), null);
assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME);
@@ -263,11 +271,12 @@ public abstract class TestMigration extends TestApiBase {
}
}
+ @Test(groups = "slow")
public void testChangePriorMigrateBilling() throws Exception {
try {
final DateTime startDate = clock.getUTCNow().minusMonths(2);
final DateTime beforeMigration = clock.getUTCNow();
- final EntitlementAccountMigration toBeMigrated = createAccountForMigrationWithRegularBasePlan(startDate);
+ final EntitlementAccountMigration toBeMigrated = testUtil.createAccountForMigrationWithRegularBasePlan(startDate);
final DateTime afterMigration = clock.getUTCNow();
testListener.pushExpectedEvent(NextEvent.MIGRATE_ENTITLEMENT);
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/TestEventJson.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/TestEventJson.java
index 9c70840..4de79dc 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/TestEventJson.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/TestEventJson.java
@@ -22,7 +22,8 @@ import org.joda.time.DateTime;
import org.testng.Assert;
import org.testng.annotations.Test;
-import com.ning.billing.entitlement.EntitlementTestSuite;
+import com.ning.billing.GuicyKillbillTestSuiteNoDB;
+import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.entitlement.api.timeline.DefaultRepairEntitlementEvent;
import com.ning.billing.entitlement.api.user.DefaultEffectiveSubscriptionEvent;
import com.ning.billing.entitlement.api.user.Subscription.SubscriptionState;
@@ -30,7 +31,8 @@ import com.ning.billing.util.events.EffectiveSubscriptionInternalEvent;
import com.ning.billing.util.events.RepairEntitlementInternalEvent;
import com.ning.billing.util.jackson.ObjectMapper;
-public class TestEventJson extends EntitlementTestSuite {
+public class TestEventJson extends GuicyKillbillTestSuiteNoDB {
+
private final ObjectMapper mapper = new ObjectMapper();
@Test(groups = "fast")
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairBP.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairBP.java
index 8052a4f..d03ef83 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairBP.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairBP.java
@@ -39,6 +39,7 @@ import com.ning.billing.catalog.api.PlanPhase;
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.EntitlementTestSuiteWithEmbeddedDB;
import com.ning.billing.entitlement.api.SubscriptionTransitionType;
import com.ning.billing.entitlement.api.timeline.SubscriptionTimeline.DeletedEvent;
import com.ning.billing.entitlement.api.timeline.SubscriptionTimeline.ExistingEvent;
@@ -48,18 +49,15 @@ import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.entitlement.api.user.Subscription.SubscriptionState;
import com.ning.billing.entitlement.api.user.SubscriptionData;
import com.ning.billing.entitlement.api.user.SubscriptionEvents;
+import com.ning.billing.entitlement.api.user.TestUtil.TestWithException;
+import com.ning.billing.entitlement.api.user.TestUtil.TestWithExceptionCallback;
import com.ning.billing.entitlement.glue.MockEngineModuleSql;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
-public class TestRepairBP extends TestApiBaseRepair {
-
- @Override
- public Injector getInjector() {
- return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleSql());
- }
+public class TestRepairBP extends EntitlementTestSuiteWithEmbeddedDB {
@Test(groups = "slow")
public void testFetchBundleRepair() throws Exception {
@@ -68,13 +66,13 @@ public class TestRepairBP extends TestApiBaseRepair {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- final Subscription baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ final Subscription baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
final String aoProduct = "Telescopic-Scope";
final BillingPeriod aoTerm = BillingPeriod.MONTHLY;
final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
- final SubscriptionData aoSubscription = createSubscription(aoProduct, aoTerm, aoPriceList);
+ final SubscriptionData aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
final List<SubscriptionTimeline> subscriptionRepair = bundleRepair.getSubscriptions();
@@ -86,7 +84,7 @@ public class TestRepairBP extends TestApiBaseRepair {
final List<ExistingEvent> events = cur.getExistingEvents();
assertEquals(events.size(), 2);
- sortExistingEvent(events);
+ testUtil.sortExistingEvent(events);
assertEquals(events.get(0).getSubscriptionTransitionType(), SubscriptionTransitionType.CREATE);
assertEquals(events.get(1).getSubscriptionTransitionType(), SubscriptionTransitionType.PHASE);
@@ -130,27 +128,27 @@ public class TestRepairBP extends TestApiBaseRepair {
final DateTime startDate = clock.getUTCNow();
// CREATE BP
- final Subscription baseSubscription = createSubscription(baseProduct, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
+ final Subscription baseSubscription = testUtil.createSubscription(bundle, baseProduct, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
// Stays in trial-- for instance
final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(10));
clock.addDeltaFromReality(it.toDurationMillis());
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
- des.add(createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CANCEL, baseSubscription.getStartDate(), null);
+ des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CANCEL, baseSubscription.getStartDate(), null);
- final SubscriptionTimeline sRepair = createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
+ final SubscriptionTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
// FIRST ISSUE DRY RUN
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
boolean dryRun = true;
final BundleTimeline dryRunBundleRepair = repairApi.repairBundle(bRepair, dryRun, callContext);
- sortEventsOnBundle(dryRunBundleRepair);
+ testUtil.sortEventsOnBundle(dryRunBundleRepair);
List<SubscriptionTimeline> subscriptionRepair = dryRunBundleRepair.getSubscriptions();
assertEquals(subscriptionRepair.size(), 1);
SubscriptionTimeline cur = subscriptionRepair.get(0);
@@ -158,13 +156,13 @@ public class TestRepairBP extends TestApiBaseRepair {
final List<ExistingEvent> events = subscriptionRepair.get(0).getExistingEvents();
assertEquals(events.size(), 2);
final List<ExistingEvent> expected = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, baseProduct, PhaseType.TRIAL,
- ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, baseSubscription.getStartDate()));
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CANCEL, baseProduct, PhaseType.TRIAL,
- ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, baseSubscription.getStartDate()));
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, baseProduct, PhaseType.TRIAL,
+ ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, baseSubscription.getStartDate()));
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CANCEL, baseProduct, PhaseType.TRIAL,
+ ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, baseSubscription.getStartDate()));
for (final ExistingEvent e : expected) {
- validateExistingEventForAssertion(e, events.get(index++));
+ testUtil.validateExistingEventForAssertion(e, events.get(index++));
}
final SubscriptionData dryRunBaseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId(), callContext);
@@ -195,7 +193,7 @@ public class TestRepairBP extends TestApiBaseRepair {
assertEquals(cur.getId(), baseSubscription.getId());
index = 0;
for (final ExistingEvent e : expected) {
- validateExistingEventForAssertion(e, events.get(index++));
+ testUtil.validateExistingEventForAssertion(e, events.get(index++));
}
final SubscriptionData realRunBaseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId(), callContext);
assertEquals(realRunBaseSubscription.getAllTransitions().size(), 2);
@@ -219,10 +217,10 @@ public class TestRepairBP extends TestApiBaseRepair {
final DateTime restartDate = startDate.plusDays(clockShift).minusDays(1);
final LinkedList<ExistingEvent> expected = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, newBaseProduct, PhaseType.TRIAL,
- ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, restartDate));
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.PHASE, newBaseProduct, PhaseType.EVERGREEN,
- ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, restartDate.plusDays(30)));
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, newBaseProduct, PhaseType.TRIAL,
+ ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, restartDate));
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.PHASE, newBaseProduct, PhaseType.EVERGREEN,
+ ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, restartDate.plusDays(30)));
testBPRepairCreate(true, startDate, clockShift, baseProduct, newBaseProduct, expected);
assertListenerStatus();
@@ -238,10 +236,10 @@ public class TestRepairBP extends TestApiBaseRepair {
final DateTime restartDate = startDate.plusDays(clockShift).minusDays(1);
final LinkedList<ExistingEvent> expected = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, newBaseProduct, PhaseType.TRIAL,
- ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, restartDate));
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.PHASE, newBaseProduct, PhaseType.EVERGREEN,
- ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, restartDate.plusDays(30)));
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, newBaseProduct, PhaseType.TRIAL,
+ ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, restartDate));
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.PHASE, newBaseProduct, PhaseType.EVERGREEN,
+ ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, restartDate.plusDays(30)));
final UUID baseSubscriptionId = testBPRepairCreate(true, startDate, clockShift, baseProduct, newBaseProduct, expected);
@@ -281,10 +279,10 @@ public class TestRepairBP extends TestApiBaseRepair {
final DateTime restartDate = startDate.plusDays(clockShift).minusDays(1);
final LinkedList<ExistingEvent> expected = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, newBaseProduct, PhaseType.TRIAL,
- ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, restartDate));
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.PHASE, newBaseProduct, PhaseType.EVERGREEN,
- ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, restartDate.plusDays(30)));
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, newBaseProduct, PhaseType.TRIAL,
+ ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, restartDate));
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.PHASE, newBaseProduct, PhaseType.EVERGREEN,
+ ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, restartDate.plusDays(30)));
testBPRepairCreate(false, startDate, clockShift, baseProduct, newBaseProduct, expected);
assertListenerStatus();
@@ -293,7 +291,7 @@ public class TestRepairBP extends TestApiBaseRepair {
private UUID testBPRepairCreate(final boolean inTrial, final DateTime startDate, final int clockShift,
final String baseProduct, final String newBaseProduct, final List<ExistingEvent> expectedEvents) throws Exception {
// CREATE BP
- final Subscription baseSubscription = createSubscription(baseProduct, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
+ final Subscription baseSubscription = testUtil.createSubscription(bundle, baseProduct, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
// MOVE CLOCK
if (clockShift > 0) {
@@ -309,21 +307,21 @@ public class TestRepairBP extends TestApiBaseRepair {
}
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
final DateTime newCreateTime = baseSubscription.getStartDate().plusDays(clockShift - 1);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(newBaseProduct, ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.TRIAL);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CREATE, newCreateTime, spec);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CREATE, newCreateTime, spec);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
- des.add(createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(0).getEventId()));
- des.add(createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
+ des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(0).getEventId()));
+ des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
- final SubscriptionTimeline sRepair = createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
+ final SubscriptionTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
// FIRST ISSUE DRY RUN
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
boolean dryRun = true;
final BundleTimeline dryRunBundleRepair = repairApi.repairBundle(bRepair, dryRun, callContext);
@@ -336,7 +334,7 @@ public class TestRepairBP extends TestApiBaseRepair {
assertEquals(expectedEvents.size(), events.size());
int index = 0;
for (final ExistingEvent e : expectedEvents) {
- validateExistingEventForAssertion(e, events.get(index++));
+ testUtil.validateExistingEventForAssertion(e, events.get(index++));
}
final SubscriptionData dryRunBaseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId(), callContext);
@@ -375,7 +373,7 @@ public class TestRepairBP extends TestApiBaseRepair {
assertEquals(events.size(), expectedEvents.size());
index = 0;
for (final ExistingEvent e : expectedEvents) {
- validateExistingEventForAssertion(e, events.get(index++));
+ testUtil.validateExistingEventForAssertion(e, events.get(index++));
}
final SubscriptionData realRunBaseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId(), callContext);
assertEquals(realRunBaseSubscription.getAllTransitions().size(), 2);
@@ -407,12 +405,12 @@ public class TestRepairBP extends TestApiBaseRepair {
final DateTime changeDate = startDate.plusDays(clockShift).minusDays(1);
final LinkedList<ExistingEvent> expected = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, baseProduct, PhaseType.TRIAL,
- ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, startDate));
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CHANGE, newBaseProduct, PhaseType.TRIAL,
- ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, changeDate));
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.PHASE, newBaseProduct, PhaseType.EVERGREEN,
- ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, startDate.plusDays(30)));
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, baseProduct, PhaseType.TRIAL,
+ ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, startDate));
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CHANGE, newBaseProduct, PhaseType.TRIAL,
+ ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, changeDate));
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.PHASE, newBaseProduct, PhaseType.EVERGREEN,
+ ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, startDate.plusDays(30)));
final UUID baseSubscriptionId = testBPRepairAddChange(true, startDate, clockShift, baseProduct, newBaseProduct, expected, 3);
@@ -451,12 +449,12 @@ public class TestRepairBP extends TestApiBaseRepair {
final DateTime changeDate = startDate.plusDays(clockShift).minusDays(1);
final LinkedList<ExistingEvent> expected = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, baseProduct, PhaseType.TRIAL,
- ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, startDate));
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.PHASE, baseProduct, PhaseType.EVERGREEN,
- ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, startDate.plusDays(30)));
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CHANGE, newBaseProduct, PhaseType.EVERGREEN,
- ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, changeDate));
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, baseProduct, PhaseType.TRIAL,
+ ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, startDate));
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.PHASE, baseProduct, PhaseType.EVERGREEN,
+ ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, startDate.plusDays(30)));
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CHANGE, newBaseProduct, PhaseType.EVERGREEN,
+ ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, changeDate));
testBPRepairAddChange(false, startDate, clockShift, baseProduct, newBaseProduct, expected, 3);
assertListenerStatus();
@@ -465,7 +463,7 @@ public class TestRepairBP extends TestApiBaseRepair {
private UUID testBPRepairAddChange(final boolean inTrial, final DateTime startDate, final int clockShift,
final String baseProduct, final String newBaseProduct, final List<ExistingEvent> expectedEvents, final int expectedTransitions) throws Exception {
// CREATE BP
- final Subscription baseSubscription = createSubscription(baseProduct, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
+ final Subscription baseSubscription = testUtil.createSubscription(bundle, baseProduct, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
// MOVE CLOCK
if (!inTrial) {
@@ -479,21 +477,21 @@ public class TestRepairBP extends TestApiBaseRepair {
}
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
final DateTime changeTime = baseSubscription.getStartDate().plusDays(clockShift - 1);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(newBaseProduct, ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.TRIAL);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CHANGE, changeTime, spec);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CHANGE, changeTime, spec);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
if (inTrial) {
- des.add(createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
+ des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
}
- final SubscriptionTimeline sRepair = createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
+ final SubscriptionTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
// FIRST ISSUE DRY RUN
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
boolean dryRun = true;
final BundleTimeline dryRunBundleRepair = repairApi.repairBundle(bRepair, dryRun, callContext);
@@ -507,7 +505,7 @@ public class TestRepairBP extends TestApiBaseRepair {
assertEquals(expectedEvents.size(), events.size());
int index = 0;
for (final ExistingEvent e : expectedEvents) {
- validateExistingEventForAssertion(e, events.get(index++));
+ testUtil.validateExistingEventForAssertion(e, events.get(index++));
}
final SubscriptionData dryRunBaseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId(), callContext);
@@ -544,7 +542,7 @@ public class TestRepairBP extends TestApiBaseRepair {
assertEquals(expectedEvents.size(), events.size());
index = 0;
for (final ExistingEvent e : expectedEvents) {
- validateExistingEventForAssertion(e, events.get(index++));
+ testUtil.validateExistingEventForAssertion(e, events.get(index++));
}
final SubscriptionData realRunBaseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId(), callContext);
assertEquals(realRunBaseSubscription.getAllTransitions().size(), expectedTransitions);
@@ -574,7 +572,7 @@ public class TestRepairBP extends TestApiBaseRepair {
final DateTime startDate = clock.getUTCNow();
// CREATE BP
- Subscription baseSubscription = createSubscription("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
+ Subscription baseSubscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
// MOVE CLOCK -- OUT OF TRIAL
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -600,18 +598,18 @@ public class TestRepairBP extends TestApiBaseRepair {
final DateTime repairTime = clock.getUTCNow().minusDays(1);
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CHANGE, repairTime, spec);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CHANGE, repairTime, spec);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
- des.add(createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(2).getEventId()));
+ des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(2).getEventId()));
- final SubscriptionTimeline sRepair = createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
+ final SubscriptionTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
// SKIP DRY RUN AND DO REPAIR...
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
final boolean dryRun = false;
testListener.pushExpectedEvent(NextEvent.REPAIR_BUNDLE);
@@ -643,22 +641,22 @@ public class TestRepairBP extends TestApiBaseRepair {
final TestWithException test = new TestWithException();
final DateTime startDate = clock.getUTCNow();
- final Subscription baseSubscription = createSubscription("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
+ final Subscription baseSubscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
test.withException(new TestWithExceptionCallback() {
@Override
public void doTest() throws EntitlementRepairException, EntitlementUserApiException {
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
- des.add(createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(0).getEventId()));
- des.add(createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
- final SubscriptionTimeline sRepair = createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
+ des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(0).getEventId()));
+ des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
+ final SubscriptionTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
testListener.pushExpectedEvent(NextEvent.CHANGE);
final DateTime changeTime = clock.getUTCNow();
@@ -676,22 +674,22 @@ public class TestRepairBP extends TestApiBaseRepair {
final TestWithException test = new TestWithException();
final DateTime startDate = clock.getUTCNow();
- final Subscription baseSubscription = createSubscription("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
+ final Subscription baseSubscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
test.withException(new TestWithExceptionCallback() {
@Override
public void doTest() throws EntitlementRepairException, EntitlementUserApiException {
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
- des.add(createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(0).getEventId()));
- des.add(createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
- final SubscriptionTimeline sRepair = createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
+ des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(0).getEventId()));
+ des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
+ final SubscriptionTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
final DateTime newChargedThroughDate = baseSubscription.getStartDate().plusDays(30).plusMonths(1);
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithAO.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithAO.java
index 8aedd2f..220cdd0 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithAO.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithAO.java
@@ -36,6 +36,7 @@ import com.ning.billing.catalog.api.PlanPhase;
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.EntitlementTestSuiteWithEmbeddedDB;
import com.ning.billing.entitlement.api.SubscriptionTransitionType;
import com.ning.billing.entitlement.api.timeline.SubscriptionTimeline.DeletedEvent;
import com.ning.billing.entitlement.api.timeline.SubscriptionTimeline.ExistingEvent;
@@ -49,12 +50,9 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
-public class TestRepairWithAO extends TestApiBaseRepair {
+public class TestRepairWithAO extends EntitlementTestSuiteWithEmbeddedDB {
+
- @Override
- public Injector getInjector() {
- return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleSql());
- }
@Test(groups = "slow")
public void testRepairChangeBPWithAddonIncluded() throws Exception {
@@ -63,89 +61,89 @@ public class TestRepairWithAO extends TestApiBaseRepair {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- final SubscriptionData baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ final SubscriptionData baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
// MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4));
clock.addDeltaFromReality(it.toDurationMillis());
- final SubscriptionData aoSubscription = createSubscription("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
+ final SubscriptionData aoSubscription = testUtil.createSubscription(bundle, "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
- final SubscriptionData aoSubscription2 = createSubscription("Laser-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
+ final SubscriptionData aoSubscription2 = testUtil.createSubscription(bundle, "Laser-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
// MOVE CLOCK A LITTLE BIT MORE -- STILL IN TRIAL
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3));
clock.addDeltaFromReality(it.toDurationMillis());
BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
// Quick check
- SubscriptionTimeline bpRepair = getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
+ SubscriptionTimeline bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 2);
- SubscriptionTimeline aoRepair = getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
+ SubscriptionTimeline aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
- SubscriptionTimeline aoRepair2 = getSubscriptionRepair(aoSubscription2.getId(), bundleRepair);
+ SubscriptionTimeline aoRepair2 = testUtil.getSubscriptionRepair(aoSubscription2.getId(), bundleRepair);
assertEquals(aoRepair2.getExistingEvents().size(), 2);
final DateTime bpChangeDate = clock.getUTCNow().minusDays(1);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
- des.add(createDeletedEvent(bpRepair.getExistingEvents().get(1).getEventId()));
+ des.add(testUtil.createDeletedEvent(bpRepair.getExistingEvents().get(1).getEventId()));
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.TRIAL);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CHANGE, bpChangeDate, spec);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CHANGE, bpChangeDate, spec);
- bpRepair = createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
+ bpRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
- bundleRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(bpRepair));
+ bundleRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(bpRepair));
boolean dryRun = true;
final BundleTimeline dryRunBundleRepair = repairApi.repairBundle(bundleRepair, dryRun, callContext);
- aoRepair = getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
+ aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
- aoRepair2 = getSubscriptionRepair(aoSubscription2.getId(), dryRunBundleRepair);
+ aoRepair2 = testUtil.getSubscriptionRepair(aoSubscription2.getId(), dryRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
- bpRepair = getSubscriptionRepair(baseSubscription.getId(), dryRunBundleRepair);
+ bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), dryRunBundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 3);
// Check expected for AO
final List<ExistingEvent> expectedAO = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expectedAO.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.DISCOUNT,
+ expectedAO.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.DISCOUNT,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, aoSubscription.getStartDate()));
- expectedAO.add(createExistingEventForAssertion(SubscriptionTransitionType.CANCEL, "Telescopic-Scope", PhaseType.DISCOUNT,
+ expectedAO.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CANCEL, "Telescopic-Scope", PhaseType.DISCOUNT,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, bpChangeDate));
int index = 0;
for (final ExistingEvent e : expectedAO) {
- validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
}
final List<ExistingEvent> expectedAO2 = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expectedAO2.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Laser-Scope", PhaseType.DISCOUNT,
+ expectedAO2.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Laser-Scope", PhaseType.DISCOUNT,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, aoSubscription2.getStartDate()));
- expectedAO2.add(createExistingEventForAssertion(SubscriptionTransitionType.PHASE, "Laser-Scope", PhaseType.EVERGREEN,
+ expectedAO2.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.PHASE, "Laser-Scope", PhaseType.EVERGREEN,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, aoSubscription2.getStartDate().plusMonths(1)));
index = 0;
for (final ExistingEvent e : expectedAO2) {
- validateExistingEventForAssertion(e, aoRepair2.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, aoRepair2.getExistingEvents().get(index++));
}
// Check expected for BP
final List<ExistingEvent> expectedBP = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expectedBP.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Shotgun", PhaseType.TRIAL,
+ expectedBP.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Shotgun", PhaseType.TRIAL,
ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, baseSubscription.getStartDate()));
- expectedBP.add(createExistingEventForAssertion(SubscriptionTransitionType.CHANGE, "Assault-Rifle", PhaseType.TRIAL,
+ expectedBP.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CHANGE, "Assault-Rifle", PhaseType.TRIAL,
ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, bpChangeDate));
- expectedBP.add(createExistingEventForAssertion(SubscriptionTransitionType.PHASE, "Assault-Rifle", PhaseType.EVERGREEN,
+ expectedBP.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.PHASE, "Assault-Rifle", PhaseType.EVERGREEN,
ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, baseSubscription.getStartDate().plusDays(30)));
index = 0;
for (final ExistingEvent e : expectedBP) {
- validateExistingEventForAssertion(e, bpRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, bpRepair.getExistingEvents().get(index++));
}
SubscriptionData newAoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId(), callContext);
@@ -168,25 +166,25 @@ public class TestRepairWithAO extends TestApiBaseRepair {
final BundleTimeline realRunBundleRepair = repairApi.repairBundle(bundleRepair, dryRun, callContext);
assertTrue(testListener.isCompleted(5000));
- aoRepair = getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
+ aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
- bpRepair = getSubscriptionRepair(baseSubscription.getId(), realRunBundleRepair);
+ bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), realRunBundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 3);
index = 0;
for (final ExistingEvent e : expectedAO) {
- validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
}
index = 0;
for (final ExistingEvent e : expectedAO2) {
- validateExistingEventForAssertion(e, aoRepair2.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, aoRepair2.getExistingEvents().get(index++));
}
index = 0;
for (final ExistingEvent e : expectedBP) {
- validateExistingEventForAssertion(e, bpRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, bpRepair.getExistingEvents().get(index++));
}
newAoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId(), callContext);
@@ -212,13 +210,13 @@ public class TestRepairWithAO extends TestApiBaseRepair {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- final SubscriptionData baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ final SubscriptionData baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
// MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3));
clock.addDeltaFromReality(it.toDurationMillis());
- final SubscriptionData aoSubscription = createSubscription("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
+ final SubscriptionData aoSubscription = testUtil.createSubscription(bundle, "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
// MOVE CLOCK A LITTLE BIT MORE -- AFTER TRIAL
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -229,57 +227,57 @@ public class TestRepairWithAO extends TestApiBaseRepair {
assertTrue(testListener.isCompleted(7000));
BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
// Quick check
- SubscriptionTimeline bpRepair = getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
+ SubscriptionTimeline bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 2);
- SubscriptionTimeline aoRepair = getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
+ SubscriptionTimeline aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
final DateTime bpChangeDate = clock.getUTCNow().minusDays(1);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Pistol", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CHANGE, bpChangeDate, spec);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CHANGE, bpChangeDate, spec);
- bpRepair = createSubscriptionRepair(baseSubscription.getId(), Collections.<SubscriptionTimeline.DeletedEvent>emptyList(), Collections.singletonList(ne));
+ bpRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), Collections.<SubscriptionTimeline.DeletedEvent>emptyList(), Collections.singletonList(ne));
- bundleRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(bpRepair));
+ bundleRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(bpRepair));
boolean dryRun = true;
final BundleTimeline dryRunBundleRepair = repairApi.repairBundle(bundleRepair, dryRun, callContext);
- aoRepair = getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
+ aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 3);
- bpRepair = getSubscriptionRepair(baseSubscription.getId(), dryRunBundleRepair);
+ bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), dryRunBundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 3);
// Check expected for AO
final List<ExistingEvent> expectedAO = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expectedAO.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.DISCOUNT,
+ expectedAO.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.DISCOUNT,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, aoSubscription.getStartDate()));
- expectedAO.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.EVERGREEN,
+ expectedAO.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.EVERGREEN,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, baseSubscription.getStartDate().plusMonths(1)));
- expectedAO.add(createExistingEventForAssertion(SubscriptionTransitionType.CANCEL, "Telescopic-Scope", PhaseType.EVERGREEN,
+ expectedAO.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CANCEL, "Telescopic-Scope", PhaseType.EVERGREEN,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, bpChangeDate));
int index = 0;
for (final ExistingEvent e : expectedAO) {
- validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
}
// Check expected for BP
final List<ExistingEvent> expectedBP = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expectedBP.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Shotgun", PhaseType.TRIAL,
+ expectedBP.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Shotgun", PhaseType.TRIAL,
ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, baseSubscription.getStartDate()));
- expectedBP.add(createExistingEventForAssertion(SubscriptionTransitionType.PHASE, "Shotgun", PhaseType.EVERGREEN,
+ expectedBP.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.PHASE, "Shotgun", PhaseType.EVERGREEN,
ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, baseSubscription.getStartDate().plusDays(30)));
- expectedBP.add(createExistingEventForAssertion(SubscriptionTransitionType.CHANGE, "Pistol", PhaseType.EVERGREEN,
+ expectedBP.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CHANGE, "Pistol", PhaseType.EVERGREEN,
ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, bpChangeDate));
index = 0;
for (final ExistingEvent e : expectedBP) {
- validateExistingEventForAssertion(e, bpRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, bpRepair.getExistingEvents().get(index++));
}
SubscriptionData newAoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId(), callContext);
@@ -297,20 +295,20 @@ public class TestRepairWithAO extends TestApiBaseRepair {
final BundleTimeline realRunBundleRepair = repairApi.repairBundle(bundleRepair, dryRun, callContext);
assertTrue(testListener.isCompleted(5000));
- aoRepair = getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
+ aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 3);
- bpRepair = getSubscriptionRepair(baseSubscription.getId(), realRunBundleRepair);
+ bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), realRunBundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 3);
index = 0;
for (final ExistingEvent e : expectedAO) {
- validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
}
index = 0;
for (final ExistingEvent e : expectedBP) {
- validateExistingEventForAssertion(e, bpRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, bpRepair.getExistingEvents().get(index++));
}
newAoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId(), callContext);
@@ -331,13 +329,13 @@ public class TestRepairWithAO extends TestApiBaseRepair {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- SubscriptionData baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ SubscriptionData baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
// MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4));
clock.addDeltaFromReality(it.toDurationMillis());
- final SubscriptionData aoSubscription = createSubscription("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
+ final SubscriptionData aoSubscription = testUtil.createSubscription(bundle, "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
// MOVE CLOCK A LITTLE BIT MORE -- AFTER TRIAL
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -353,54 +351,54 @@ public class TestRepairWithAO extends TestApiBaseRepair {
baseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId(), callContext);
BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
// Quick check
- SubscriptionTimeline bpRepair = getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
+ SubscriptionTimeline bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 2);
- SubscriptionTimeline aoRepair = getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
+ SubscriptionTimeline aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
final DateTime bpCancelDate = clock.getUTCNow().minusDays(1);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CANCEL, bpCancelDate, null);
- bpRepair = createSubscriptionRepair(baseSubscription.getId(), Collections.<SubscriptionTimeline.DeletedEvent>emptyList(), Collections.singletonList(ne));
- bundleRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(bpRepair));
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CANCEL, bpCancelDate, null);
+ bpRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), Collections.<SubscriptionTimeline.DeletedEvent>emptyList(), Collections.singletonList(ne));
+ bundleRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(bpRepair));
boolean dryRun = true;
final BundleTimeline dryRunBundleRepair = repairApi.repairBundle(bundleRepair, dryRun, callContext);
- aoRepair = getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
+ aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 3);
- bpRepair = getSubscriptionRepair(baseSubscription.getId(), dryRunBundleRepair);
+ bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), dryRunBundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 3);
// Check expected for AO
final List<ExistingEvent> expectedAO = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expectedAO.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.DISCOUNT,
+ expectedAO.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.DISCOUNT,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, aoSubscription.getStartDate()));
- expectedAO.add(createExistingEventForAssertion(SubscriptionTransitionType.PHASE, "Telescopic-Scope", PhaseType.EVERGREEN,
+ expectedAO.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.PHASE, "Telescopic-Scope", PhaseType.EVERGREEN,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, baseSubscription.getStartDate().plusMonths(1)));
- expectedAO.add(createExistingEventForAssertion(SubscriptionTransitionType.CANCEL, "Telescopic-Scope", PhaseType.EVERGREEN,
+ expectedAO.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CANCEL, "Telescopic-Scope", PhaseType.EVERGREEN,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, newChargedThroughDate));
int index = 0;
for (final ExistingEvent e : expectedAO) {
- validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
}
// Check expected for BP
final List<ExistingEvent> expectedBP = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expectedBP.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Shotgun", PhaseType.TRIAL,
+ expectedBP.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Shotgun", PhaseType.TRIAL,
ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.NO_BILLING_PERIOD, baseSubscription.getStartDate()));
- expectedBP.add(createExistingEventForAssertion(SubscriptionTransitionType.PHASE, "Shotgun", PhaseType.EVERGREEN,
+ expectedBP.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.PHASE, "Shotgun", PhaseType.EVERGREEN,
ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, baseSubscription.getStartDate().plusDays(30)));
- expectedBP.add(createExistingEventForAssertion(SubscriptionTransitionType.CANCEL, "Shotgun", PhaseType.EVERGREEN,
+ expectedBP.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CANCEL, "Shotgun", PhaseType.EVERGREEN,
ProductCategory.BASE, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, newChargedThroughDate));
index = 0;
for (final ExistingEvent e : expectedBP) {
- validateExistingEventForAssertion(e, bpRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, bpRepair.getExistingEvents().get(index++));
}
SubscriptionData newAoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId(), callContext);
@@ -418,20 +416,20 @@ public class TestRepairWithAO extends TestApiBaseRepair {
final BundleTimeline realRunBundleRepair = repairApi.repairBundle(bundleRepair, dryRun, callContext);
assertTrue(testListener.isCompleted(5000));
- aoRepair = getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
+ aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 3);
- bpRepair = getSubscriptionRepair(baseSubscription.getId(), realRunBundleRepair);
+ bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), realRunBundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 3);
index = 0;
for (final ExistingEvent e : expectedAO) {
- validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
}
index = 0;
for (final ExistingEvent e : expectedBP) {
- validateExistingEventForAssertion(e, bpRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, bpRepair.getExistingEvents().get(index++));
}
newAoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId(), callContext);
@@ -470,55 +468,55 @@ public class TestRepairWithAO extends TestApiBaseRepair {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- final SubscriptionData baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ final SubscriptionData baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
// MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4));
clock.addDeltaFromReality(it.toDurationMillis());
- final SubscriptionData aoSubscription = createSubscription("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
+ final SubscriptionData aoSubscription = testUtil.createSubscription(bundle, "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
// MOVE CLOCK A LITTLE BIT MORE -- STILL IN TRIAL
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3));
clock.addDeltaFromReality(it.toDurationMillis());
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
// Quick check
- SubscriptionTimeline bpRepair = getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
+ SubscriptionTimeline bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 2);
- SubscriptionTimeline aoRepair = getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
+ SubscriptionTimeline aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
- des.add(createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
+ des.add(testUtil.createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
final DateTime aoCancelDate = aoSubscription.getStartDate().plusDays(1);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CANCEL, aoCancelDate, null);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CANCEL, aoCancelDate, null);
- final SubscriptionTimeline saoRepair = createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne));
+ final SubscriptionTimeline saoRepair = testUtil.createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne));
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair));
boolean dryRun = true;
final BundleTimeline dryRunBundleRepair = repairApi.repairBundle(bRepair, dryRun, callContext);
- aoRepair = getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
+ aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
- bpRepair = getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
+ bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 2);
final List<ExistingEvent> expected = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.DISCOUNT,
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.DISCOUNT,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, aoSubscription.getStartDate()));
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CANCEL, "Telescopic-Scope", PhaseType.DISCOUNT,
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CANCEL, "Telescopic-Scope", PhaseType.DISCOUNT,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, aoCancelDate));
int index = 0;
for (final ExistingEvent e : expected) {
- validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
}
SubscriptionData newAoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId(), callContext);
assertEquals(newAoSubscription.getState(), SubscriptionState.ACTIVE);
@@ -535,11 +533,11 @@ public class TestRepairWithAO extends TestApiBaseRepair {
final BundleTimeline realRunBundleRepair = repairApi.repairBundle(bRepair, dryRun, callContext);
assertTrue(testListener.isCompleted(5000));
- aoRepair = getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
+ aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
index = 0;
for (final ExistingEvent e : expected) {
- validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
}
newAoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId(), callContext);
@@ -560,54 +558,54 @@ public class TestRepairWithAO extends TestApiBaseRepair {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- final SubscriptionData baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ final SubscriptionData baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
// MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4));
clock.addDeltaFromReality(it.toDurationMillis());
- final SubscriptionData aoSubscription = createSubscription("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
+ final SubscriptionData aoSubscription = testUtil.createSubscription(bundle, "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
// MOVE CLOCK A LITTLE BIT MORE -- STILL IN TRIAL
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3));
clock.addDeltaFromReality(it.toDurationMillis());
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
// Quick check
- final SubscriptionTimeline bpRepair = getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
+ final SubscriptionTimeline bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 2);
- SubscriptionTimeline aoRepair = getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
+ SubscriptionTimeline aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
- des.add(createDeletedEvent(aoRepair.getExistingEvents().get(0).getEventId()));
- des.add(createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
+ des.add(testUtil.createDeletedEvent(aoRepair.getExistingEvents().get(0).getEventId()));
+ des.add(testUtil.createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
final DateTime aoRecreateDate = aoSubscription.getStartDate().plusDays(1);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Telescopic-Scope", ProductCategory.ADD_ON, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.DISCOUNT);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CREATE, aoRecreateDate, spec);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CREATE, aoRecreateDate, spec);
- final SubscriptionTimeline saoRepair = createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne));
+ final SubscriptionTimeline saoRepair = testUtil.createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne));
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair));
boolean dryRun = true;
final BundleTimeline dryRunBundleRepair = repairApi.repairBundle(bRepair, dryRun, callContext);
- aoRepair = getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
+ aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
final List<ExistingEvent> expected = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.DISCOUNT,
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.DISCOUNT,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, aoRecreateDate));
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.PHASE, "Telescopic-Scope", PhaseType.EVERGREEN,
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.PHASE, "Telescopic-Scope", PhaseType.EVERGREEN,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, baseSubscription.getStartDate().plusMonths(1) /* Bundle align */));
int index = 0;
for (final ExistingEvent e : expected) {
- validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
}
SubscriptionData newAoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId(), callContext);
assertEquals(newAoSubscription.getState(), SubscriptionState.ACTIVE);
@@ -621,11 +619,11 @@ public class TestRepairWithAO extends TestApiBaseRepair {
final BundleTimeline realRunBundleRepair = repairApi.repairBundle(bRepair, dryRun, callContext);
assertTrue(testListener.isCompleted(5000));
- aoRepair = getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
+ aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
index = 0;
for (final ExistingEvent e : expected) {
- validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
}
newAoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId(), callContext);
@@ -651,56 +649,56 @@ public class TestRepairWithAO extends TestApiBaseRepair {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- final SubscriptionData baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ final SubscriptionData baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
// MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4));
clock.addDeltaFromReality(it.toDurationMillis());
- final SubscriptionData aoSubscription = createSubscription("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
+ final SubscriptionData aoSubscription = testUtil.createSubscription(bundle, "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
// MOVE CLOCK A LITTLE BIT MORE -- STILL IN TRIAL
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3));
clock.addDeltaFromReality(it.toDurationMillis());
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
// Quick check
- final SubscriptionTimeline bpRepair = getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
+ final SubscriptionTimeline bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 2);
- SubscriptionTimeline aoRepair = getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
+ SubscriptionTimeline aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
- des.add(createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
+ des.add(testUtil.createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
final DateTime aoChangeDate = aoSubscription.getStartDate().plusDays(1);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Laser-Scope", ProductCategory.ADD_ON, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.TRIAL);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CHANGE, aoChangeDate, spec);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CHANGE, aoChangeDate, spec);
- final SubscriptionTimeline saoRepair = createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne));
+ final SubscriptionTimeline saoRepair = testUtil.createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne));
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair));
boolean dryRun = true;
final BundleTimeline dryRunBundleRepair = repairApi.repairBundle(bRepair, dryRun, callContext);
- aoRepair = getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
+ aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 3);
final List<ExistingEvent> expected = new LinkedList<SubscriptionTimeline.ExistingEvent>();
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.DISCOUNT,
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.DISCOUNT,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, aoSubscription.getStartDate()));
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CHANGE, "Laser-Scope", PhaseType.DISCOUNT,
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.CHANGE, "Laser-Scope", PhaseType.DISCOUNT,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, aoChangeDate));
- expected.add(createExistingEventForAssertion(SubscriptionTransitionType.PHASE, "Laser-Scope", PhaseType.EVERGREEN,
+ expected.add(testUtil.createExistingEventForAssertion(SubscriptionTransitionType.PHASE, "Laser-Scope", PhaseType.EVERGREEN,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY,
aoSubscription.getStartDate().plusMonths(1) /* Subscription alignment */));
int index = 0;
for (final ExistingEvent e : expected) {
- validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
}
SubscriptionData newAoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId(), callContext);
assertEquals(newAoSubscription.getState(), SubscriptionState.ACTIVE);
@@ -712,11 +710,11 @@ public class TestRepairWithAO extends TestApiBaseRepair {
final BundleTimeline realRunBundleRepair = repairApi.repairBundle(bRepair, dryRun, callContext);
assertTrue(testListener.isCompleted(5000));
- aoRepair = getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
+ aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 3);
index = 0;
for (final ExistingEvent e : expected) {
- validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
+ testUtil.validateExistingEventForAssertion(e, aoRepair.getExistingEvents().get(index++));
}
newAoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId(), callContext);
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithError.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithError.java
index 3ddf408..890e555 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithError.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithError.java
@@ -23,6 +23,7 @@ import java.util.UUID;
import org.joda.time.DateTime;
import org.joda.time.Interval;
+import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -33,12 +34,15 @@ import com.ning.billing.catalog.api.PhaseType;
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.EntitlementTestSuiteNoDB;
import com.ning.billing.entitlement.api.SubscriptionTransitionType;
import com.ning.billing.entitlement.api.timeline.SubscriptionTimeline.DeletedEvent;
import com.ning.billing.entitlement.api.timeline.SubscriptionTimeline.NewEvent;
import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.entitlement.api.user.SubscriptionData;
+import com.ning.billing.entitlement.api.user.TestUtil.TestWithException;
+import com.ning.billing.entitlement.api.user.TestUtil.TestWithExceptionCallback;
import com.ning.billing.entitlement.glue.MockEngineModuleMemory;
import com.google.inject.Guice;
@@ -48,22 +52,19 @@ import com.google.inject.Stage;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
-public class TestRepairWithError extends TestApiBaseRepair {
+public class TestRepairWithError extends EntitlementTestSuiteNoDB {
+
private static final String baseProduct = "Shotgun";
private TestWithException test;
private Subscription baseSubscription;
- @Override
- public Injector getInjector() {
- return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleMemory());
- }
@BeforeMethod(alwaysRun = true)
public void setupTest() throws Exception {
super.setupTest();
test = new TestWithException();
final DateTime startDate = clock.getUTCNow();
- baseSubscription = createSubscription(baseProduct, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
+ baseSubscription = testUtil.createSubscription(bundle, baseProduct, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
}
@Test(groups = "fast")
@@ -80,13 +81,13 @@ public class TestRepairWithError extends TestApiBaseRepair {
assertTrue(testListener.isCompleted(5000));
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec);
- final SubscriptionTimeline sRepair = createSubscriptionRepair(baseSubscription.getId(), Collections.<DeletedEvent>emptyList(), Collections.singletonList(ne));
+ final SubscriptionTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), Collections.<DeletedEvent>emptyList(), Collections.singletonList(ne));
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
repairApi.repairBundle(bRepair, true, callContext);
}
@@ -114,13 +115,13 @@ public class TestRepairWithError extends TestApiBaseRepair {
assertTrue(testListener.isCompleted(5000));
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec);
- final DeletedEvent de = createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId());
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec);
+ final DeletedEvent de = testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId());
- final SubscriptionTimeline sRepair = createSubscriptionRepair(baseSubscription.getId(), Collections.singletonList(de), Collections.singletonList(ne));
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
+ final SubscriptionTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), Collections.singletonList(de), Collections.singletonList(ne));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
repairApi.repairBundle(bRepair, true, callContext);
}
@@ -134,13 +135,13 @@ public class TestRepairWithError extends TestApiBaseRepair {
public void doTest() throws EntitlementRepairException {
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec);
- final DeletedEvent de = createDeletedEvent(UUID.randomUUID());
- final SubscriptionTimeline sRepair = createSubscriptionRepair(baseSubscription.getId(), Collections.singletonList(de), Collections.singletonList(ne));
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec);
+ final DeletedEvent de = testUtil.createDeletedEvent(UUID.randomUUID());
+ final SubscriptionTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), Collections.singletonList(de), Collections.singletonList(ne));
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
repairApi.repairBundle(bRepair, true, callContext);
}
@@ -160,14 +161,14 @@ public class TestRepairWithError extends TestApiBaseRepair {
assertTrue(testListener.isCompleted(5000));
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CREATE, baseSubscription.getStartDate().plusDays(10), spec);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CREATE, baseSubscription.getStartDate().plusDays(10), spec);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
- des.add(createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
- final SubscriptionTimeline sRepair = createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
+ des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
+ final SubscriptionTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
repairApi.repairBundle(bRepair, true, callContext);
@@ -189,15 +190,15 @@ public class TestRepairWithError extends TestApiBaseRepair {
assertTrue(testListener.isCompleted(5000));
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
- des.add(createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(0).getEventId()));
- des.add(createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
- final SubscriptionTimeline sRepair = createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
+ des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(0).getEventId()));
+ des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
+ final SubscriptionTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
repairApi.repairBundle(bRepair, true, callContext);
}
@@ -212,33 +213,33 @@ public class TestRepairWithError extends TestApiBaseRepair {
// MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4));
clock.addDeltaFromReality(it.toDurationMillis());
- final SubscriptionData aoSubscription = createSubscription("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
+ final SubscriptionData aoSubscription = testUtil.createSubscription(bundle, "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
// MOVE CLOCK A LITTLE BIT MORE -- STILL IN TRIAL
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4));
clock.addDeltaFromReality(it.toDurationMillis());
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
// Quick check
- final SubscriptionTimeline bpRepair = getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
+ final SubscriptionTimeline bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 2);
- final SubscriptionTimeline aoRepair = getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
+ final SubscriptionTimeline aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
- des.add(createDeletedEvent(aoRepair.getExistingEvents().get(0).getEventId()));
- des.add(createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
+ des.add(testUtil.createDeletedEvent(aoRepair.getExistingEvents().get(0).getEventId()));
+ des.add(testUtil.createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
final DateTime aoRecreateDate = aoSubscription.getStartDate().minusDays(5);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Telescopic-Scope", ProductCategory.ADD_ON, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.DISCOUNT);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CREATE, aoRecreateDate, spec);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CREATE, aoRecreateDate, spec);
- final SubscriptionTimeline saoRepair = createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne));
+ final SubscriptionTimeline saoRepair = testUtil.createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne));
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair));
final boolean dryRun = true;
repairApi.repairBundle(bRepair, dryRun, callContext);
@@ -255,31 +256,31 @@ public class TestRepairWithError extends TestApiBaseRepair {
// MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4));
clock.addDeltaFromReality(it.toDurationMillis());
- final SubscriptionData aoSubscription = createSubscription("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
+ final SubscriptionData aoSubscription = testUtil.createSubscription(bundle, "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
// MOVE CLOCK A LITTLE BIT MORE -- STILL IN TRIAL
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4));
clock.addDeltaFromReality(it.toDurationMillis());
BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
// Quick check
- final SubscriptionTimeline bpRepair = getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
+ final SubscriptionTimeline bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
assertEquals(bpRepair.getExistingEvents().size(), 2);
- final SubscriptionTimeline aoRepair = getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
+ final SubscriptionTimeline aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
//des.add(createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
final DateTime aoCancelDate = aoSubscription.getStartDate().plusDays(10);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CANCEL, aoCancelDate, null);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CANCEL, aoCancelDate, null);
- final SubscriptionTimeline saoRepair = createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne));
+ final SubscriptionTimeline saoRepair = testUtil.createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne));
- bundleRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair));
+ bundleRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair));
final boolean dryRun = true;
repairApi.repairBundle(bundleRepair, dryRun, callContext);
@@ -299,24 +300,24 @@ public class TestRepairWithError extends TestApiBaseRepair {
clock.addDeltaFromReality(it.toDurationMillis());
//assertTrue(testListener.isCompleted(5000));
- final SubscriptionData aoSubscription = createSubscription("Laser-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
+ final SubscriptionData aoSubscription = testUtil.createSubscription(bundle, "Laser-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
final BundleTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext);
- sortEventsOnBundle(bundleRepair);
+ testUtil.sortEventsOnBundle(bundleRepair);
final DateTime newCreateTime = baseSubscription.getStartDate().plusDays(3);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Pistol", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.TRIAL);
- final NewEvent ne = createNewEvent(SubscriptionTransitionType.CREATE, newCreateTime, spec);
+ final NewEvent ne = testUtil.createNewEvent(SubscriptionTransitionType.CREATE, newCreateTime, spec);
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
- des.add(createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(0).getEventId()));
- des.add(createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
+ des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(0).getEventId()));
+ des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()));
- final SubscriptionTimeline sRepair = createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
+ final SubscriptionTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
// FIRST ISSUE DRY RUN
- final BundleTimeline bRepair = createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
+ final BundleTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair));
final boolean dryRun = true;
repairApi.repairBundle(bRepair, dryRun, callContext);
@@ -423,4 +424,5 @@ public class TestRepairWithError extends TestApiBaseRepair {
}
}, ErrorCode.ENT_REPAIR_MISSING_AO_DELETE_EVENT);
}
+
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/transfer/TestDefaultEntitlementTransferApi.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/transfer/TestDefaultEntitlementTransferApi.java
index 88efe2b..29b3d81 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/transfer/TestDefaultEntitlementTransferApi.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/transfer/TestDefaultEntitlementTransferApi.java
@@ -21,11 +21,12 @@ import java.util.UUID;
import org.joda.time.DateTime;
import org.mockito.Mockito;
-import org.skife.jdbi.v2.IDBI;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import com.ning.billing.GuicyKillbillTestSuiteNoDB;
+import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.catalog.MockCatalog;
import com.ning.billing.catalog.MockCatalogService;
import com.ning.billing.catalog.api.BillingPeriod;
@@ -34,7 +35,8 @@ import com.ning.billing.catalog.api.PhaseType;
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.EntitlementTestSuite;
+import com.ning.billing.entitlement.EntitlementTestSuiteNoDB;
+import com.ning.billing.entitlement.EntitlementTestSuiteWithEmbeddedDB;
import com.ning.billing.entitlement.api.SubscriptionApiService;
import com.ning.billing.entitlement.api.SubscriptionTransitionType;
import com.ning.billing.entitlement.api.timeline.EntitlementTimelineApi;
@@ -55,9 +57,7 @@ import com.ning.billing.util.dao.NonEntityDao;
import com.google.common.collect.ImmutableList;
// Simple unit tests for DefaultEntitlementTransferApi, see TestTransfer for more advanced tests with dao
-public class TestDefaultEntitlementTransferApi extends EntitlementTestSuite {
-
- private final Clock clock = new ClockMock();
+public class TestDefaultEntitlementTransferApi extends EntitlementTestSuiteNoDB {
private DefaultEntitlementTransferApi transferApi;
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/transfer/TestTransfer.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/transfer/TestTransfer.java
index ee43c8b..11a8dc4 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/transfer/TestTransfer.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/transfer/TestTransfer.java
@@ -13,12 +13,8 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package com.ning.billing.entitlement.api.transfer;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
+package com.ning.billing.entitlement.api.transfer;
import java.util.List;
import java.util.UUID;
@@ -35,8 +31,8 @@ import com.ning.billing.catalog.api.PhaseType;
import com.ning.billing.catalog.api.Plan;
import com.ning.billing.catalog.api.PriceListSet;
import com.ning.billing.catalog.api.Product;
+import com.ning.billing.entitlement.EntitlementTestSuiteWithEmbeddedDB;
import com.ning.billing.entitlement.api.SubscriptionTransitionType;
-import com.ning.billing.entitlement.api.TestApiBase;
import com.ning.billing.entitlement.api.migration.EntitlementMigrationApi.EntitlementAccountMigration;
import com.ning.billing.entitlement.api.migration.EntitlementMigrationApiException;
import com.ning.billing.entitlement.api.user.Subscription;
@@ -49,16 +45,14 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
-public class TestTransfer extends TestApiBase {
-
- protected static final Logger log = LoggerFactory.getLogger(TestTransfer.class);
-
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
- @Override
- protected Injector getInjector() {
- return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleSql());
- }
+public class TestTransfer extends EntitlementTestSuiteWithEmbeddedDB {
+ protected static final Logger log = LoggerFactory.getLogger(TestTransfer.class);
@Test(groups = "slow")
@@ -69,7 +63,7 @@ public class TestTransfer extends TestApiBase {
try {
final DateTime startDate = clock.getUTCNow().minusMonths(2);
final DateTime beforeMigration = clock.getUTCNow();
- final EntitlementAccountMigration toBeMigrated = createAccountForMigrationWithRegularBasePlan(startDate);
+ final EntitlementAccountMigration toBeMigrated = testUtil.createAccountForMigrationWithRegularBasePlan(startDate);
final DateTime afterMigration = clock.getUTCNow();
testListener.pushExpectedEvent(NextEvent.MIGRATE_ENTITLEMENT);
@@ -83,7 +77,7 @@ public class TestTransfer extends TestApiBase {
final List<Subscription> subscriptions = entitlementApi.getSubscriptionsForBundle(bundle.getId(), callContext);
assertEquals(subscriptions.size(), 1);
final Subscription subscription = subscriptions.get(0);
- assertDateWithin(subscription.getStartDate(), beforeMigration.minusMonths(2), afterMigration.minusMonths(2));
+ testUtil.assertDateWithin(subscription.getStartDate(), beforeMigration.minusMonths(2), afterMigration.minusMonths(2));
assertEquals(subscription.getEndDate(), null);
assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME);
assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN);
@@ -130,7 +124,7 @@ public class TestTransfer extends TestApiBase {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- final Subscription baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ final Subscription baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
final DateTime evergreenPhaseDate = ((SubscriptionData) baseSubscription).getPendingTransition().getEffectiveTransitionTime();
@@ -149,7 +143,7 @@ public class TestTransfer extends TestApiBase {
// CHECK OLD BASE IS CANCEL AT THE TRANSFER DATE
final Subscription oldBaseSubscription = entitlementApi.getSubscriptionFromId(baseSubscription.getId(), callContext);
assertNotNull(oldBaseSubscription.getEndDate());
- assertDateWithin(oldBaseSubscription.getEndDate(), beforeTransferDate, afterTransferDate);
+ testUtil.assertDateWithin(oldBaseSubscription.getEndDate(), beforeTransferDate, afterTransferDate);
assertTrue(oldBaseSubscription.getEndDate().compareTo(transferRequestedDate) == 0);
// CHECK NEW BUNDLE EXIST, WITH ONE SUBSCRIPTION STARTING ON TRANSFER_DATE
@@ -181,7 +175,7 @@ public class TestTransfer extends TestApiBase {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- final Subscription baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ final Subscription baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
final DateTime ctd = baseSubscription.getStartDate().plusDays(30);
entitlementInternalApi.setChargedThroughDate(baseSubscription.getId(), ctd.toLocalDate(), internalCallContext);
@@ -230,7 +224,7 @@ public class TestTransfer extends TestApiBase {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- final Subscription baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ final Subscription baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
// MOVE AFTER TRIAL
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -248,7 +242,7 @@ public class TestTransfer extends TestApiBase {
// CHECK OLD BASE IS CANCEL AT THE TRANSFER DATE
final Subscription oldBaseSubscription = entitlementApi.getSubscriptionFromId(baseSubscription.getId(), callContext);
assertNotNull(oldBaseSubscription.getEndDate());
- assertDateWithin(oldBaseSubscription.getEndDate(), beforeTransferDate, afterTransferDate);
+ testUtil.assertDateWithin(oldBaseSubscription.getEndDate(), beforeTransferDate, afterTransferDate);
assertTrue(oldBaseSubscription.getEndDate().compareTo(transferRequestedDate) == 0);
// CHECK NEW BUNDLE EXIST, WITH ONE SUBSCRIPTION STARTING ON TRANSFER_DATE
@@ -278,7 +272,7 @@ public class TestTransfer extends TestApiBase {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- final Subscription baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ final Subscription baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
// MOVE AFTER TRIAL
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -358,13 +352,13 @@ public class TestTransfer extends TestApiBase {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- final Subscription baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ final Subscription baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
// MOVE 3 DAYS AND CREATE AO1
clock.addDays(3);
final String aoProduct1 = "Telescopic-Scope";
final BillingPeriod aoTerm1 = BillingPeriod.MONTHLY;
- final SubscriptionData aoSubscription1 = createSubscription(aoProduct1, aoTerm1, basePriceList);
+ final SubscriptionData aoSubscription1 = testUtil.createSubscription(bundle, aoProduct1, aoTerm1, basePriceList);
assertEquals(aoSubscription1.getState(), SubscriptionState.ACTIVE);
// MOVE ANOTHER 25 DAYS AND CREATE AO2 [ BP STILL IN TRIAL]
@@ -372,7 +366,7 @@ public class TestTransfer extends TestApiBase {
clock.addDays(25);
final String aoProduct2 = "Laser-Scope";
final BillingPeriod aoTerm2 = BillingPeriod.MONTHLY;
- final SubscriptionData aoSubscription2 = createSubscription(aoProduct2, aoTerm2, basePriceList);
+ final SubscriptionData aoSubscription2 = testUtil.createSubscription(bundle, aoProduct2, aoTerm2, basePriceList);
assertEquals(aoSubscription2.getState(), SubscriptionState.ACTIVE);
// MOVE AFTER TRIAL AND AO DISCOUNT PHASE [LASER SCOPE STILL IN DISCOUNT]
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiAddOn.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiAddOn.java
index 2421ad5..fad3659 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiAddOn.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiAddOn.java
@@ -39,21 +39,12 @@ import com.ning.billing.catalog.api.PlanPhase;
import com.ning.billing.catalog.api.PlanSpecifier;
import com.ning.billing.catalog.api.PriceListSet;
import com.ning.billing.catalog.api.ProductCategory;
-import com.ning.billing.entitlement.api.TestApiBase;
+import com.ning.billing.entitlement.EntitlementTestSuiteWithEmbeddedDB;
import com.ning.billing.entitlement.api.user.Subscription.SubscriptionState;
import com.ning.billing.entitlement.api.user.SubscriptionStatusDryRun.DryRunChangeReason;
-import com.ning.billing.entitlement.glue.MockEngineModuleSql;
import com.ning.billing.util.clock.DefaultClock;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.Stage;
-
-public class TestUserApiAddOn extends TestApiBase {
- @Override
- public Injector getInjector() {
- return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleSql());
- }
+public class TestUserApiAddOn extends EntitlementTestSuiteWithEmbeddedDB {
@Test(groups = "slow")
public void testCreateCancelAddon() {
@@ -62,13 +53,13 @@ public class TestUserApiAddOn extends TestApiBase {
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
- createSubscription(baseProduct, baseTerm, basePriceList);
+ testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
final String aoProduct = "Telescopic-Scope";
final BillingPeriod aoTerm = BillingPeriod.MONTHLY;
final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
- final SubscriptionData aoSubscription = createSubscription(aoProduct, aoTerm, aoPriceList);
+ final SubscriptionData aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
assertEquals(aoSubscription.getState(), SubscriptionState.ACTIVE);
final DateTime now = clock.getUTCNow();
@@ -94,13 +85,13 @@ public class TestUserApiAddOn extends TestApiBase {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- SubscriptionData baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ SubscriptionData baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
final String aoProduct = "Telescopic-Scope";
final BillingPeriod aoTerm = BillingPeriod.MONTHLY;
final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
- SubscriptionData aoSubscription = createSubscription(aoProduct, aoTerm, aoPriceList);
+ SubscriptionData aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
testListener.reset();
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -113,7 +104,7 @@ public class TestUserApiAddOn extends TestApiBase {
// SET CTD TO CANCEL IN FUTURE
final DateTime now = clock.getUTCNow();
- final Duration ctd = getDurationMonth(1);
+ final Duration ctd = testUtil.getDurationMonth(1);
// Why not just use clock.getUTCNow().plusMonths(1) ?
final DateTime newChargedThroughDate = DefaultClock.addDuration(now, ctd);
entitlementInternalApi.setChargedThroughDate(baseSubscription.getId(), newChargedThroughDate.toLocalDate(), internalCallContext);
@@ -155,13 +146,13 @@ public class TestUserApiAddOn extends TestApiBase {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- SubscriptionData baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ SubscriptionData baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
final String aoProduct = "Telescopic-Scope";
final BillingPeriod aoTerm = BillingPeriod.MONTHLY;
final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
- SubscriptionData aoSubscription = createSubscription(aoProduct, aoTerm, aoPriceList);
+ SubscriptionData aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
testListener.reset();
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -174,7 +165,7 @@ public class TestUserApiAddOn extends TestApiBase {
// SET CTD TO CHANGE IN FUTURE
final DateTime now = clock.getUTCNow();
- final Duration ctd = getDurationMonth(1);
+ final Duration ctd = testUtil.getDurationMonth(1);
final DateTime newChargedThroughDate = DefaultClock.addDuration(now, ctd);
entitlementInternalApi.setChargedThroughDate(baseSubscription.getId(), newChargedThroughDate.toLocalDate(), internalCallContext);
baseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId(), callContext);
@@ -218,13 +209,13 @@ public class TestUserApiAddOn extends TestApiBase {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- SubscriptionData baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ SubscriptionData baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
final String aoProduct = "Telescopic-Scope";
final BillingPeriod aoTerm = BillingPeriod.MONTHLY;
final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
- SubscriptionData aoSubscription = createSubscription(aoProduct, aoTerm, aoPriceList);
+ SubscriptionData aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
testListener.reset();
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -237,7 +228,7 @@ public class TestUserApiAddOn extends TestApiBase {
// SET CTD TO CANCEL IN FUTURE
final DateTime now = clock.getUTCNow();
- final Duration ctd = getDurationMonth(1);
+ final Duration ctd = testUtil.getDurationMonth(1);
final DateTime newChargedThroughDate = DefaultClock.addDuration(now, ctd);
entitlementInternalApi.setChargedThroughDate(baseSubscription.getId(), newChargedThroughDate.toLocalDate(), internalCallContext);
baseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId(), callContext);
@@ -335,7 +326,7 @@ public class TestUserApiAddOn extends TestApiBase {
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
- final SubscriptionData baseSubscription = createSubscription(baseProduct, baseTerm, basePriceList);
+ final SubscriptionData baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
// MOVE CLOCK 14 DAYS LATER
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(14));
@@ -343,7 +334,7 @@ public class TestUserApiAddOn extends TestApiBase {
// CREATE ADDON
final DateTime beforeAOCreation = clock.getUTCNow();
- SubscriptionData aoSubscription = createSubscription(aoProduct, aoTerm, aoPriceList);
+ SubscriptionData aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
final DateTime afterAOCreation = clock.getUTCNow();
// CHECK EVERYTHING
@@ -357,7 +348,7 @@ public class TestUserApiAddOn extends TestApiBase {
assertNotNull(aoCurrentPhase);
assertEquals(aoCurrentPhase.getPhaseType(), PhaseType.DISCOUNT);
- assertDateWithin(aoSubscription.getStartDate(), beforeAOCreation, afterAOCreation);
+ testUtil.assertDateWithin(aoSubscription.getStartDate(), beforeAOCreation, afterAOCreation);
assertEquals(aoSubscription.getBundleStartDate(), baseSubscription.getBundleStartDate());
// CHECK next AO PHASE EVENT IS INDEED A MONTH AFTER BP STARTED => BUNDLE ALIGNMENT
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancel.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancel.java
index d6e2060..272414d 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancel.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancel.java
@@ -24,6 +24,7 @@ import static org.testng.Assert.assertTrue;
import org.joda.time.DateTime;
import org.joda.time.Interval;
import org.testng.Assert;
+import org.testng.annotations.Test;
import com.ning.billing.api.TestApiListener.NextEvent;
import com.ning.billing.catalog.api.BillingPeriod;
@@ -32,12 +33,14 @@ import com.ning.billing.catalog.api.PhaseType;
import com.ning.billing.catalog.api.Plan;
import com.ning.billing.catalog.api.PlanPhase;
import com.ning.billing.catalog.api.PriceListSet;
-import com.ning.billing.entitlement.api.TestApiBase;
+import com.ning.billing.entitlement.EntitlementTestSuiteWithEmbeddedDB;
import com.ning.billing.util.clock.DefaultClock;
import com.ning.billing.util.svcapi.entitlement.EntitlementBillingApiException;
-public abstract class TestUserApiCancel extends TestApiBase {
- protected void testCancelSubscriptionIMM() {
+public class TestUserApiCancel extends EntitlementTestSuiteWithEmbeddedDB {
+
+ @Test(groups = "slow")
+ public void testCancelSubscriptionIMM() {
try {
final DateTime init = clock.getUTCNow();
@@ -46,7 +49,7 @@ public abstract class TestUserApiCancel extends TestApiBase {
final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE
- final SubscriptionData subscription = createSubscription(prod, term, planSet);
+ final SubscriptionData subscription = testUtil.createSubscription(bundle, prod, term, planSet);
PlanPhase currentPhase = subscription.getCurrentPhase();
assertEquals(currentPhase.getPhaseType(), PhaseType.TRIAL);
@@ -75,7 +78,7 @@ public abstract class TestUserApiCancel extends TestApiBase {
assertNull(currentPhase);
- checkNextPhaseChange(subscription, 0, null);
+ testUtil.checkNextPhaseChange(subscription, 0, null);
assertListenerStatus();
} catch (EntitlementUserApiException e) {
@@ -83,20 +86,21 @@ public abstract class TestUserApiCancel extends TestApiBase {
}
}
- protected void testCancelSubscriptionEOTWithChargeThroughDate() throws EntitlementBillingApiException {
+ @Test(groups = "slow")
+ public void testCancelSubscriptionEOTWithChargeThroughDate() throws EntitlementBillingApiException {
try {
final String prod = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE
- SubscriptionData subscription = createSubscription(prod, term, planSet);
+ SubscriptionData subscription = testUtil.createSubscription(bundle, prod, term, planSet);
PlanPhase trialPhase = subscription.getCurrentPhase();
assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
// NEXT PHASE
final DateTime expectedPhaseTrialChange = DefaultClock.addDuration(subscription.getStartDate(), trialPhase.getDuration());
- checkNextPhaseChange(subscription, 1, expectedPhaseTrialChange);
+ testUtil.checkNextPhaseChange(subscription, 1, expectedPhaseTrialChange);
// MOVE TO NEXT PHASE
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -108,7 +112,7 @@ public abstract class TestUserApiCancel extends TestApiBase {
assertEquals(trialPhase.getPhaseType(), PhaseType.EVERGREEN);
// SET CTD + RE READ SUBSCRIPTION + CHANGE PLAN
- final Duration ctd = getDurationMonth(1);
+ final Duration ctd = testUtil.getDurationMonth(1);
final DateTime newChargedThroughDate = DefaultClock.addDuration(expectedPhaseTrialChange, ctd);
entitlementInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate.toLocalDate(), internalCallContext);
subscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(subscription.getId(), callContext);
@@ -145,7 +149,7 @@ public abstract class TestUserApiCancel extends TestApiBase {
final PlanPhase currentPhase = subscription.getCurrentPhase();
assertNull(currentPhase);
- checkNextPhaseChange(subscription, 0, null);
+ testUtil.checkNextPhaseChange(subscription, 0, null);
assertEquals(subscription.getLastActiveProductName(), prod);
assertEquals(subscription.getLastActivePriceListName(), planSet);
@@ -159,20 +163,21 @@ public abstract class TestUserApiCancel extends TestApiBase {
}
}
- protected void testCancelSubscriptionEOTWithNoChargeThroughDate() {
+ @Test(groups = "slow")
+ public void testCancelSubscriptionEOTWithNoChargeThroughDate() {
try {
final String prod = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE
- final SubscriptionData subscription = createSubscription(prod, term, planSet);
+ final SubscriptionData subscription = testUtil.createSubscription(bundle, prod, term, planSet);
PlanPhase trialPhase = subscription.getCurrentPhase();
assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
// NEXT PHASE
final DateTime expectedPhaseTrialChange = DefaultClock.addDuration(subscription.getStartDate(), trialPhase.getDuration());
- checkNextPhaseChange(subscription, 1, expectedPhaseTrialChange);
+ testUtil.checkNextPhaseChange(subscription, 1, expectedPhaseTrialChange);
// MOVE TO NEXT PHASE
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -191,7 +196,7 @@ public abstract class TestUserApiCancel extends TestApiBase {
final PlanPhase currentPhase = subscription.getCurrentPhase();
assertNull(currentPhase);
- checkNextPhaseChange(subscription, 0, null);
+ testUtil.checkNextPhaseChange(subscription, 0, null);
assertListenerStatus();
} catch (EntitlementUserApiException e) {
@@ -202,20 +207,21 @@ public abstract class TestUserApiCancel extends TestApiBase {
// Similar test to testCancelSubscriptionEOTWithChargeThroughDate except we uncancel and check things
// are as they used to be and we can move forward without hitting cancellation
//
- protected void testUncancel() throws EntitlementBillingApiException {
+ @Test(groups = "slow")
+ public void testUncancel() throws EntitlementBillingApiException {
try {
final String prod = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE
- SubscriptionData subscription = createSubscription(prod, term, planSet);
+ SubscriptionData subscription = testUtil.createSubscription(bundle, prod, term, planSet);
final PlanPhase trialPhase = subscription.getCurrentPhase();
assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
// NEXT PHASE
final DateTime expectedPhaseTrialChange = DefaultClock.addDuration(subscription.getStartDate(), trialPhase.getDuration());
- checkNextPhaseChange(subscription, 1, expectedPhaseTrialChange);
+ testUtil.checkNextPhaseChange(subscription, 1, expectedPhaseTrialChange);
// MOVE TO NEXT PHASE
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -226,7 +232,7 @@ public abstract class TestUserApiCancel extends TestApiBase {
assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN);
// SET CTD + RE READ SUBSCRIPTION + CHANGE PLAN
- final Duration ctd = getDurationMonth(1);
+ final Duration ctd = testUtil.getDurationMonth(1);
final DateTime newChargedThroughDate = DefaultClock.addDuration(expectedPhaseTrialChange, ctd);
entitlementInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate.toLocalDate(), internalCallContext);
subscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(subscription.getId(), callContext);
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlan.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlan.java
index 349d57a..f8ed15c 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlan.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlan.java
@@ -27,6 +27,7 @@ import java.util.List;
import org.joda.time.DateTime;
import org.joda.time.Interval;
import org.testng.Assert;
+import org.testng.annotations.Test;
import com.ning.billing.api.TestApiListener.NextEvent;
import com.ning.billing.catalog.api.BillingPeriod;
@@ -36,13 +37,14 @@ import com.ning.billing.catalog.api.Plan;
import com.ning.billing.catalog.api.PlanPhase;
import com.ning.billing.catalog.api.PriceListSet;
import com.ning.billing.catalog.api.ProductCategory;
-import com.ning.billing.entitlement.api.TestApiBase;
+import com.ning.billing.entitlement.EntitlementTestSuiteWithEmbeddedDB;
import com.ning.billing.entitlement.events.EntitlementEvent;
import com.ning.billing.entitlement.events.user.ApiEvent;
import com.ning.billing.util.clock.DefaultClock;
import com.ning.billing.util.svcapi.entitlement.EntitlementBillingApiException;
-public abstract class TestUserApiChangePlan extends TestApiBase {
+public class TestUserApiChangePlan extends EntitlementTestSuiteWithEmbeddedDB {
+
private void checkChangePlan(final SubscriptionData subscription, final String expProduct, final ProductCategory expCategory,
final BillingPeriod expBillingPeriod, final PhaseType expPhase) {
@@ -57,7 +59,8 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
assertEquals(currentPhase.getPhaseType(), expPhase);
}
- protected void testChangePlanBundleAlignEOTWithNoChargeThroughDate() {
+ @Test(groups = "slow")
+ public void testChangePlanBundleAlignEOTWithNoChargeThroughDate() {
tChangePlanBundleAlignEOTWithNoChargeThroughDate("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, "Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
}
@@ -65,7 +68,7 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
final String toProd, final BillingPeriod toTerm, final String toPlanSet) {
try {
// CREATE
- final SubscriptionData subscription = createSubscription(fromProd, fromTerm, fromPlanSet);
+ final SubscriptionData subscription = testUtil.createSubscription(bundle, fromProd, fromTerm, fromPlanSet);
// MOVE TO NEXT PHASE
PlanPhase currentPhase = subscription.getCurrentPhase();
@@ -94,7 +97,8 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
}
}
- protected void testChangePlanBundleAlignEOTWithChargeThroughDate() throws EntitlementBillingApiException {
+ @Test(groups = "slow")
+ public void testChangePlanBundleAlignEOTWithChargeThroughDate() throws EntitlementBillingApiException {
testChangePlanBundleAlignEOTWithChargeThroughDate("Shotgun", BillingPeriod.ANNUAL, "gunclubDiscount", "Pistol", BillingPeriod.ANNUAL, "gunclubDiscount");
}
@@ -102,7 +106,7 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
final String toProd, final BillingPeriod toTerm, final String toPlanSet) throws EntitlementBillingApiException {
try {
// CREATE
- SubscriptionData subscription = createSubscription(fromProd, fromTerm, fromPlanSet);
+ SubscriptionData subscription = testUtil.createSubscription(bundle, fromProd, fromTerm, fromPlanSet);
final PlanPhase trialPhase = subscription.getCurrentPhase();
final DateTime expectedPhaseTrialChange = DefaultClock.addDuration(subscription.getStartDate(), trialPhase.getDuration());
assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
@@ -116,7 +120,7 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
assertEquals(currentPhase.getPhaseType(), PhaseType.DISCOUNT);
// SET CTD
- final Duration ctd = getDurationMonth(1);
+ final Duration ctd = testUtil.getDurationMonth(1);
final DateTime newChargedThroughDate = DefaultClock.addDuration(expectedPhaseTrialChange, ctd);
entitlementInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate.toLocalDate(), internalCallContext);
@@ -134,7 +138,7 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
// NEXT PHASE
final DateTime nextExpectedPhaseChange = DefaultClock.addDuration(expectedPhaseTrialChange, currentPhase.getDuration());
- checkNextPhaseChange(subscription, 2, nextExpectedPhaseChange);
+ testUtil.checkNextPhaseChange(subscription, 2, nextExpectedPhaseChange);
// ALSO VERIFY PENDING CHANGE EVENT
final List<EntitlementEvent> events = dao.getPendingEventsForSubscription(subscription.getId(), internalCallContext);
@@ -156,7 +160,8 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
}
}
- protected void testChangePlanBundleAlignIMM() {
+ @Test(groups = "slow")
+ public void testChangePlanBundleAlignIMM() {
tChangePlanBundleAlignIMM("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, "Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
}
@@ -164,7 +169,7 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
final String toProd, final BillingPeriod toTerm, final String toPlanSet) {
try {
- final SubscriptionData subscription = createSubscription(fromProd, fromTerm, fromPlanSet);
+ final SubscriptionData subscription = testUtil.createSubscription(bundle, fromProd, fromTerm, fromPlanSet);
testListener.pushExpectedEvent(NextEvent.CHANGE);
@@ -179,7 +184,7 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
final PlanPhase currentPhase = subscription.getCurrentPhase();
final DateTime nextExpectedPhaseChange = DefaultClock.addDuration(subscription.getStartDate(), currentPhase.getDuration());
- checkNextPhaseChange(subscription, 1, nextExpectedPhaseChange);
+ testUtil.checkNextPhaseChange(subscription, 1, nextExpectedPhaseChange);
// NEXT PHASE
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -196,7 +201,8 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
}
}
- protected void testChangePlanChangePlanAlignEOTWithChargeThroughDate() throws EntitlementBillingApiException {
+ @Test(groups = "slow")
+ public void testChangePlanChangePlanAlignEOTWithChargeThroughDate() throws EntitlementBillingApiException {
tChangePlanChangePlanAlignEOTWithChargeThroughDate("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, "Assault-Rifle", BillingPeriod.ANNUAL, "rescue");
}
@@ -205,7 +211,7 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
try {
DateTime currentTime = clock.getUTCNow();
- SubscriptionData subscription = createSubscription(fromProd, fromTerm, fromPlanSet);
+ SubscriptionData subscription = testUtil.createSubscription(bundle, fromProd, fromTerm, fromPlanSet);
final PlanPhase trialPhase = subscription.getCurrentPhase();
final DateTime expectedPhaseTrialChange = DefaultClock.addDuration(subscription.getStartDate(), trialPhase.getDuration());
assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
@@ -219,7 +225,7 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
assertTrue(testListener.isCompleted(5000));
// SET CTD
- final Duration ctd = getDurationMonth(1);
+ final Duration ctd = testUtil.getDurationMonth(1);
final DateTime newChargedThroughDate = DefaultClock.addDuration(expectedPhaseTrialChange, ctd);
entitlementInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate.toLocalDate(), internalCallContext);
@@ -266,7 +272,7 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
testListener.reset();
final DateTime nextExpectedPhaseChange = DefaultClock.addDuration(newChargedThroughDate, currentPhase.getDuration());
- checkNextPhaseChange(subscription, 1, nextExpectedPhaseChange);
+ testUtil.checkNextPhaseChange(subscription, 1, nextExpectedPhaseChange);
// MOVE TIME RIGHT AFTER NEXT EXPECTED PHASE CHANGE
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -282,9 +288,10 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
}
}
- protected void testMultipleChangeLastIMM() throws EntitlementBillingApiException {
+ @Test(groups = "slow")
+ public void testMultipleChangeLastIMM() throws EntitlementBillingApiException {
try {
- SubscriptionData subscription = createSubscription("Assault-Rifle", BillingPeriod.MONTHLY, "gunclubDiscount");
+ SubscriptionData subscription = testUtil.createSubscription(bundle, "Assault-Rifle", BillingPeriod.MONTHLY, "gunclubDiscount");
final PlanPhase trialPhase = subscription.getCurrentPhase();
assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
@@ -300,7 +307,7 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
durationList.add(trialPhase.getDuration());
//durationList.add(subscription.getCurrentPhase().getDuration());
final DateTime startDiscountPhase = DefaultClock.addDuration(subscription.getStartDate(), durationList);
- final Duration ctd = getDurationMonth(1);
+ final Duration ctd = testUtil.getDurationMonth(1);
final DateTime newChargedThroughDate = DefaultClock.addDuration(startDiscountPhase, ctd);
entitlementInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate.toLocalDate(), internalCallContext);
subscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(subscription.getId(), callContext);
@@ -333,9 +340,10 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
}
}
- protected void testMultipleChangeLastEOT() throws EntitlementBillingApiException {
+ @Test(groups = "slow")
+ public void testMultipleChangeLastEOT() throws EntitlementBillingApiException {
try {
- SubscriptionData subscription = createSubscription("Assault-Rifle", BillingPeriod.ANNUAL, "gunclubDiscount");
+ SubscriptionData subscription = testUtil.createSubscription(bundle, "Assault-Rifle", BillingPeriod.ANNUAL, "gunclubDiscount");
final PlanPhase trialPhase = subscription.getCurrentPhase();
assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
@@ -348,7 +356,7 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
final List<Duration> durationList = new ArrayList<Duration>();
durationList.add(trialPhase.getDuration());
final DateTime startDiscountPhase = DefaultClock.addDuration(subscription.getStartDate(), durationList);
- final Duration ctd = getDurationMonth(1);
+ final Duration ctd = testUtil.getDurationMonth(1);
final DateTime newChargedThroughDate = DefaultClock.addDuration(startDiscountPhase, ctd);
entitlementInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate.toLocalDate(), internalCallContext);
subscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(subscription.getId(), callContext);
@@ -418,9 +426,10 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
}
}
- protected void testCorrectPhaseAlignmentOnChange() {
+ @Test(groups = "slow")
+ public void testCorrectPhaseAlignmentOnChange() {
try {
- SubscriptionData subscription = createSubscription("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
+ SubscriptionData subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
PlanPhase trialPhase = subscription.getCurrentPhase();
assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreate.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreate.java
index 1925799..06ce806 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreate.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreate.java
@@ -20,10 +20,10 @@ import java.util.List;
import org.joda.time.DateTime;
import org.joda.time.Interval;
-import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
+import org.testng.annotations.Test;
import com.ning.billing.api.TestApiListener.NextEvent;
import com.ning.billing.catalog.api.BillingPeriod;
@@ -32,21 +32,20 @@ import com.ning.billing.catalog.api.Plan;
import com.ning.billing.catalog.api.PlanPhase;
import com.ning.billing.catalog.api.PriceListSet;
import com.ning.billing.catalog.api.ProductCategory;
-import com.ning.billing.entitlement.api.TestApiBase;
+import com.ning.billing.entitlement.EntitlementTestSuiteWithEmbeddedDB;
import com.ning.billing.entitlement.events.EntitlementEvent;
import com.ning.billing.entitlement.events.phase.PhaseEvent;
-import com.ning.billing.util.callcontext.InternalTenantContext;
-import com.ning.billing.util.callcontext.TenantContext;
import com.ning.billing.util.clock.DefaultClock;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
-public abstract class TestUserApiCreate extends TestApiBase {
+public class TestUserApiCreate extends EntitlementTestSuiteWithEmbeddedDB {
private static final Logger log = LoggerFactory.getLogger(TestUserApiCreate.class);
+ @Test(groups = "slow")
public void testCreateWithRequestedDate() {
try {
final DateTime init = clock.getUTCNow();
@@ -60,7 +59,7 @@ public abstract class TestUserApiCreate extends TestApiBase {
testListener.pushExpectedEvent(NextEvent.CREATE);
final SubscriptionData subscription = (SubscriptionData) entitlementApi.createSubscription(bundle.getId(),
- getProductSpecifier(productName, planSetName, term, null), requestedDate, callContext);
+ testUtil.getProductSpecifier(productName, planSetName, term, null), requestedDate, callContext);
assertNotNull(subscription);
assertEquals(subscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION);
@@ -78,7 +77,8 @@ public abstract class TestUserApiCreate extends TestApiBase {
}
}
- protected void testCreateWithInitialPhase() {
+ @Test(groups = "slow")
+ public void testCreateWithInitialPhase() {
try {
final DateTime init = clock.getUTCNow();
@@ -89,14 +89,14 @@ public abstract class TestUserApiCreate extends TestApiBase {
testListener.pushExpectedEvent(NextEvent.CREATE);
final SubscriptionData subscription = (SubscriptionData) entitlementApi.createSubscription(bundle.getId(),
- getProductSpecifier(productName, planSetName, term, PhaseType.EVERGREEN), clock.getUTCNow(), callContext);
+ testUtil.getProductSpecifier(productName, planSetName, term, PhaseType.EVERGREEN), clock.getUTCNow(), callContext);
assertNotNull(subscription);
assertEquals(subscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION);
//assertEquals(subscription.getAccount(), account.getId());
assertEquals(subscription.getBundleId(), bundle.getId());
- assertDateWithin(subscription.getStartDate(), init, clock.getUTCNow());
- assertDateWithin(subscription.getBundleStartDate(), init, clock.getUTCNow());
+ testUtil.assertDateWithin(subscription.getStartDate(), init, clock.getUTCNow());
+ testUtil.assertDateWithin(subscription.getBundleStartDate(), init, clock.getUTCNow());
final Plan currentPlan = subscription.getCurrentPlan();
assertNotNull(currentPlan);
@@ -115,7 +115,8 @@ public abstract class TestUserApiCreate extends TestApiBase {
}
}
- protected void testSimpleCreateSubscription() {
+ @Test(groups = "slow")
+ public void testSimpleCreateSubscription() {
try {
final DateTime init = clock.getUTCNow();
@@ -126,15 +127,15 @@ public abstract class TestUserApiCreate extends TestApiBase {
testListener.pushExpectedEvent(NextEvent.CREATE);
final SubscriptionData subscription = (SubscriptionData) entitlementApi.createSubscription(bundle.getId(),
- getProductSpecifier(productName, planSetName, term, null),
+ testUtil.getProductSpecifier(productName, planSetName, term, null),
clock.getUTCNow(), callContext);
assertNotNull(subscription);
assertEquals(subscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION);
//assertEquals(subscription.getAccount(), account.getId());
assertEquals(subscription.getBundleId(), bundle.getId());
- assertDateWithin(subscription.getStartDate(), init, clock.getUTCNow());
- assertDateWithin(subscription.getBundleStartDate(), init, clock.getUTCNow());
+ testUtil.assertDateWithin(subscription.getStartDate(), init, clock.getUTCNow());
+ testUtil.assertDateWithin(subscription.getBundleStartDate(), init, clock.getUTCNow());
final Plan currentPlan = subscription.getCurrentPlan();
assertNotNull(currentPlan);
@@ -149,7 +150,7 @@ public abstract class TestUserApiCreate extends TestApiBase {
final List<EntitlementEvent> events = dao.getPendingEventsForSubscription(subscription.getId(), internalCallContext);
assertNotNull(events);
- printEvents(events);
+ testUtil.printEvents(events);
assertTrue(events.size() == 1);
assertTrue(events.get(0) instanceof PhaseEvent);
final DateTime nextPhaseChange = ((PhaseEvent) events.get(0)).getEffectiveDate();
@@ -171,7 +172,8 @@ public abstract class TestUserApiCreate extends TestApiBase {
}
}
- protected void testSimpleSubscriptionThroughPhases() {
+ @Test(groups = "slow")
+ public void testSimpleSubscriptionThroughPhases() {
try {
final String productName = "Pistol";
final BillingPeriod term = BillingPeriod.ANNUAL;
@@ -181,7 +183,7 @@ public abstract class TestUserApiCreate extends TestApiBase {
// CREATE SUBSCRIPTION
SubscriptionData subscription = (SubscriptionData) entitlementApi.createSubscription(bundle.getId(),
- getProductSpecifier(productName, planSetName, term, null), clock.getUTCNow(), callContext);
+ testUtil.getProductSpecifier(productName, planSetName, term, null), clock.getUTCNow(), callContext);
assertNotNull(subscription);
PlanPhase currentPhase = subscription.getCurrentPhase();
@@ -215,7 +217,8 @@ public abstract class TestUserApiCreate extends TestApiBase {
}
}
- protected void testSubscriptionWithAddOn() {
+ @Test(groups = "slow")
+ public void testSubscriptionWithAddOn() {
try {
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.ANNUAL;
@@ -224,7 +227,7 @@ public abstract class TestUserApiCreate extends TestApiBase {
testListener.pushExpectedEvent(NextEvent.CREATE);
final SubscriptionData subscription = (SubscriptionData) entitlementApi.createSubscription(bundle.getId(),
- getProductSpecifier(productName, planSetName, term, null), clock.getUTCNow(), callContext);
+ testUtil.getProductSpecifier(productName, planSetName, term, null), clock.getUTCNow(), callContext);
assertNotNull(subscription);
assertListenerStatus();
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiError.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiError.java
index df1af0b..eff68f2 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiError.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiError.java
@@ -37,25 +37,15 @@ import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.catalog.api.Duration;
import com.ning.billing.catalog.api.PlanPhase;
import com.ning.billing.catalog.api.PriceListSet;
-import com.ning.billing.entitlement.api.TestApiBase;
+import com.ning.billing.entitlement.EntitlementTestSuiteNoDB;
import com.ning.billing.entitlement.exceptions.EntitlementError;
-import com.ning.billing.entitlement.glue.MockEngineModuleMemory;
import com.ning.billing.util.callcontext.TenantContext;
import com.ning.billing.util.clock.DefaultClock;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.Stage;
-
-public class TestUserApiError extends TestApiBase {
+public class TestUserApiError extends EntitlementTestSuiteNoDB {
private final TenantContext tenantContext = Mockito.mock(TenantContext.class);
- @Override
- protected Injector getInjector() {
- return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleMemory());
- }
-
@Test(groups = "fast")
public void testCreateSubscriptionBadCatalog() {
// WRONG PRODUCTS
@@ -83,7 +73,7 @@ public class TestUserApiError extends TestApiBase {
@Test(groups = "fast")
public void testCreateSubscriptionBPExists() {
try {
- createSubscription("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME);
+ testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME);
tCreateSubscriptionInternal(bundle.getId(), "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.ENT_CREATE_BP_EXISTS);
} catch (Exception e) {
Assert.fail(e.toString());
@@ -93,9 +83,9 @@ public class TestUserApiError extends TestApiBase {
@Test(groups = "fast")
public void testRecreateSubscriptionBPNotCancelled() {
try {
- final SubscriptionData subscription = createSubscription("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME);
+ final SubscriptionData subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME);
try {
- subscription.recreate(getProductSpecifier("Pistol", PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, null), clock.getUTCNow(), callContext);
+ subscription.recreate(testUtil.getProductSpecifier("Pistol", PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, null), clock.getUTCNow(), callContext);
Assert.assertFalse(true);
} catch (EntitlementUserApiException e) {
assertEquals(e.getCode(), ErrorCode.ENT_RECREATE_BAD_STATE.getCode());
@@ -110,7 +100,7 @@ public class TestUserApiError extends TestApiBase {
try {
final UUID accountId = UUID.randomUUID();
final SubscriptionBundle aoBundle = entitlementApi.createBundleForAccount(accountId, "myAOBundle", callContext);
- createSubscriptionWithBundle(aoBundle.getId(), "Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
+ testUtil.createSubscriptionWithBundle(aoBundle.getId(), "Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
tCreateSubscriptionInternal(aoBundle.getId(), "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.ENT_CREATE_AO_NOT_AVAILABLE);
} catch (Exception e) {
Assert.fail(e.toString());
@@ -123,7 +113,7 @@ public class TestUserApiError extends TestApiBase {
try {
final UUID accountId = UUID.randomUUID();
final SubscriptionBundle aoBundle = entitlementApi.createBundleForAccount(accountId, "myAOBundle", callContext);
- createSubscriptionWithBundle(aoBundle.getId(), "Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
+ testUtil.createSubscriptionWithBundle(aoBundle.getId(), "Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
tCreateSubscriptionInternal(aoBundle.getId(), "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.ENT_CREATE_AO_ALREADY_INCLUDED);
} catch (Exception e) {
Assert.fail(e.toString());
@@ -134,7 +124,7 @@ public class TestUserApiError extends TestApiBase {
@Nullable final BillingPeriod term, final String planSet, final ErrorCode expected) {
try {
entitlementApi.createSubscription(bundleId,
- getProductSpecifier(productName, planSet, term, null),
+ testUtil.getProductSpecifier(productName, planSet, term, null),
clock.getUTCNow(), callContext);
Assert.fail("Exception expected, error code: " + expected);
} catch (EntitlementUserApiException e) {
@@ -150,7 +140,7 @@ public class TestUserApiError extends TestApiBase {
@Test(groups = "fast")
public void testChangeSubscriptionNonActive() {
try {
- final Subscription subscription = createSubscription("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME);
+ final Subscription subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME);
testListener.pushExpectedEvent(NextEvent.CANCEL);
subscription.cancel(clock.getUTCNow(), callContext);
@@ -171,7 +161,7 @@ public class TestUserApiError extends TestApiBase {
@Test(groups = "fast")
public void testChangeSubscriptionWithPolicy() throws Exception {
- final Subscription subscription = createSubscription("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME);
+ final Subscription subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME);
try {
subscription.changePlanWithPolicy("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, clock.getUTCNow(), ActionPolicy.ILLEGAL, callContext);
@@ -188,7 +178,7 @@ public class TestUserApiError extends TestApiBase {
@Test(groups = "fast")
public void testChangeSubscriptionFutureCancelled() {
try {
- Subscription subscription = createSubscription("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
+ Subscription subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
final PlanPhase trialPhase = subscription.getCurrentPhase();
// MOVE TO NEXT PHASE
@@ -200,7 +190,7 @@ public class TestUserApiError extends TestApiBase {
// SET CTD TO CANCEL IN FUTURE
final DateTime expectedPhaseTrialChange = DefaultClock.addDuration(subscription.getStartDate(), trialPhase.getDuration());
- final Duration ctd = getDurationMonth(1);
+ final Duration ctd = testUtil.getDurationMonth(1);
final DateTime newChargedThroughDate = DefaultClock.addDuration(expectedPhaseTrialChange, ctd);
entitlementInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate.toLocalDate(), internalCallContext);
@@ -231,7 +221,7 @@ public class TestUserApiError extends TestApiBase {
@Test(groups = "fast")
public void testUncancelBadState() {
try {
- final Subscription subscription = createSubscription("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
+ final Subscription subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
try {
subscription.uncancel(callContext);
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreate.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreate.java
index b5d9efc..c0aab29 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreate.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreate.java
@@ -24,16 +24,19 @@ import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
+import org.testng.annotations.Test;
import com.ning.billing.api.TestApiListener.NextEvent;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.catalog.api.PriceListSet;
-import com.ning.billing.entitlement.api.TestApiBase;
+import com.ning.billing.entitlement.EntitlementTestSuiteWithEmbeddedDB;
+
+public abstract class TestUserApiRecreate extends EntitlementTestSuiteWithEmbeddedDB {
-public abstract class TestUserApiRecreate extends TestApiBase {
private static final Logger log = LoggerFactory.getLogger(TestUserApiRecreate.class);
- protected void testRecreateWithBPCanceledThroughSubscription() {
+ @Test(groups = "slow")
+ public void testRecreateWithBPCanceledThroughSubscription() {
try {
testCreateAndRecreate(false);
assertListenerStatus();
@@ -43,7 +46,8 @@ public abstract class TestUserApiRecreate extends TestApiBase {
}
}
- protected void testCreateWithBPCanceledFromUserApi() {
+ @Test(groups = "slow")
+ public void testCreateWithBPCanceledFromUserApi() {
try {
testCreateAndRecreate(true);
assertListenerStatus();
@@ -64,7 +68,7 @@ public abstract class TestUserApiRecreate extends TestApiBase {
testListener.pushExpectedEvent(NextEvent.PHASE);
testListener.pushExpectedEvent(NextEvent.CREATE);
SubscriptionData subscription = (SubscriptionData) entitlementApi.createSubscription(bundle.getId(),
- getProductSpecifier(productName, planSetName, term, null), requestedDate, callContext);
+ testUtil.getProductSpecifier(productName, planSetName, term, null), requestedDate, callContext);
assertNotNull(subscription);
assertEquals(subscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION);
assertEquals(subscription.getBundleId(), bundle.getId());
@@ -81,9 +85,9 @@ public abstract class TestUserApiRecreate extends TestApiBase {
if (fromUserAPi) {
subscription = (SubscriptionData) entitlementApi.createSubscription(bundle.getId(),
- getProductSpecifier(productName, planSetName, term, null), requestedDate, callContext);
+ testUtil.getProductSpecifier(productName, planSetName, term, null), requestedDate, callContext);
} else {
- subscription.recreate(getProductSpecifier(productName, planSetName, term, null), requestedDate, callContext);
+ subscription.recreate(testUtil.getProductSpecifier(productName, planSetName, term, null), requestedDate, callContext);
}
Assert.fail("Expected Create API to fail since BP already exists");
} catch (EntitlementUserApiException e) {
@@ -106,9 +110,9 @@ public abstract class TestUserApiRecreate extends TestApiBase {
if (fromUserAPi) {
subscription = (SubscriptionData) entitlementApi.createSubscription(bundle.getId(),
- getProductSpecifier(productName, planSetName, term, null), requestedDate, callContext);
+ testUtil.getProductSpecifier(productName, planSetName, term, null), requestedDate, callContext);
} else {
- subscription.recreate(getProductSpecifier(productName, planSetName, term, null), clock.getUTCNow(), callContext);
+ subscription.recreate(testUtil.getProductSpecifier(productName, planSetName, term, null), clock.getUTCNow(), callContext);
}
assertEquals(subscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION);
assertEquals(subscription.getBundleId(), bundle.getId());
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/DefaultEntitlementTestInitializer.java b/entitlement/src/test/java/com/ning/billing/entitlement/DefaultEntitlementTestInitializer.java
new file mode 100644
index 0000000..114b537
--- /dev/null
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/DefaultEntitlementTestInitializer.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2010-2013 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.entitlement;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.UUID;
+
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+import org.mockito.Mockito;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ning.billing.account.api.AccountData;
+import com.ning.billing.account.api.BillCycleDay;
+import com.ning.billing.api.TestApiListener;
+import com.ning.billing.api.TestListenerStatus;
+import com.ning.billing.catalog.DefaultCatalogService;
+import com.ning.billing.catalog.api.Catalog;
+import com.ning.billing.catalog.api.CatalogService;
+import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.entitlement.api.EntitlementService;
+import com.ning.billing.entitlement.api.user.EntitlementUserApi;
+import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.entitlement.engine.core.Engine;
+import com.ning.billing.mock.MockAccountBuilder;
+import com.ning.billing.util.callcontext.CallContext;
+import com.ning.billing.util.clock.ClockMock;
+import com.ning.billing.util.svcsapi.bus.BusService;
+
+import static org.testng.Assert.assertNotNull;
+
+public class DefaultEntitlementTestInitializer implements EntitlementTestInitializer {
+
+
+ protected static final Logger log = LoggerFactory.getLogger(DefaultEntitlementTestInitializer.class);
+
+ public DefaultEntitlementTestInitializer() {
+
+ }
+
+ public Catalog initCatalog(final CatalogService catalogService) throws Exception {
+
+ ((DefaultCatalogService) catalogService).loadCatalog();
+ final Catalog catalog = catalogService.getFullCatalog();
+ assertNotNull(catalog);
+ return catalog;
+ }
+
+ public AccountData initAccountData() {
+ final BillCycleDay billCycleDay = Mockito.mock(BillCycleDay.class);
+ Mockito.when(billCycleDay.getDayOfMonthUTC()).thenReturn(1);
+ final AccountData accountData = new MockAccountBuilder().name(UUID.randomUUID().toString())
+ .firstNameLength(6)
+ .email(UUID.randomUUID().toString())
+ .phone(UUID.randomUUID().toString())
+ .migrated(false)
+ .isNotifiedForInvoices(false)
+ .externalKey(UUID.randomUUID().toString())
+ .billingCycleDay(billCycleDay)
+ .currency(Currency.USD)
+ .paymentMethodId(UUID.randomUUID())
+ .timeZone(DateTimeZone.forID("Europe/Paris"))
+ .build();
+
+ assertNotNull(accountData);
+ return accountData;
+ }
+
+ public SubscriptionBundle initBundle(final EntitlementUserApi entitlementApi, final CallContext callContext) throws Exception {
+ final UUID accountId = UUID.randomUUID();
+ final SubscriptionBundle bundle = entitlementApi.createBundleForAccount(accountId, "myDefaultBundle", callContext);
+ assertNotNull(bundle);
+ return bundle;
+ }
+
+
+ public void startTestFamework(final TestApiListener testListener,
+ final TestListenerStatus testListenerStatus,
+ final ClockMock clock,
+ final BusService busService,
+ final EntitlementService entitlementService) throws Exception {
+ log.warn("STARTING TEST FRAMEWORK");
+
+ resetTestListener(testListener, testListenerStatus);
+
+ resetClockToStartOfTest(clock);
+
+ startBusAndRegisterListener(busService, testListener);
+
+ restartEntitlementService(entitlementService);
+
+ log.warn("STARTED TEST FRAMEWORK");
+ }
+
+ public void stopTestFramework(final TestApiListener testListener,
+ final BusService busService,
+ final EntitlementService entitlementService) throws Exception {
+ log.warn("STOPPING TEST FRAMEWORK");
+ stopBusAndUnregisterListener(busService, testListener);
+
+ stopEntitlementService(entitlementService);
+
+ log.warn("STOPPED TEST FRAMEWORK");
+ }
+
+
+
+ private void resetTestListener(final TestApiListener testListener, final TestListenerStatus testListenerStatus) {
+ // RESET LIST OF EXPECTED EVENTS
+ if (testListener != null) {
+ testListener.reset();
+ testListenerStatus.resetTestListenerStatus();
+ }
+ }
+
+ private void resetClockToStartOfTest(final ClockMock clock) {
+ clock.resetDeltaFromReality();
+
+ // Date at which all tests start-- we create the date object here after the system properties which set the JVM in UTC have been set.
+ final DateTime testStartDate = new DateTime(2012, 5, 7, 0, 3, 42, 0);
+ clock.setDeltaFromReality(testStartDate.getMillis() - clock.getUTCNow().getMillis());
+ }
+
+ private void startBusAndRegisterListener(final BusService busService, final TestApiListener testListener) throws Exception {
+ busService.getBus().start();
+ busService.getBus().register(testListener);
+ }
+
+ private void restartEntitlementService(final EntitlementService entitlementService) {
+ // START NOTIFICATION QUEUE FOR ENTITLEMENT
+ ((Engine) entitlementService).initialize();
+ ((Engine) entitlementService).start();
+ }
+
+ private void stopBusAndUnregisterListener(final BusService busService, final TestApiListener testListener) throws Exception {
+ busService.getBus().unregister(testListener);
+ busService.getBus().stop();
+ }
+
+ private void stopEntitlementService(final EntitlementService entitlementService) throws Exception {
+ ((Engine) entitlementService).stop();
+ }
+
+
+ public static void loadSystemPropertiesFromClasspath(final String resource) {
+ final URL url = EntitlementTestSuiteNoDB.class.getResource(resource);
+ assertNotNull(url);
+
+ try {
+ System.getProperties().load(url.openStream());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestInitializer.java b/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestInitializer.java
new file mode 100644
index 0000000..7ca20ab
--- /dev/null
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestInitializer.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2010-2013 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.entitlement;
+
+import com.ning.billing.account.api.AccountData;
+import com.ning.billing.api.TestApiListener;
+import com.ning.billing.api.TestListenerStatus;
+import com.ning.billing.catalog.api.Catalog;
+import com.ning.billing.catalog.api.CatalogService;
+import com.ning.billing.entitlement.api.EntitlementService;
+import com.ning.billing.entitlement.api.user.EntitlementUserApi;
+import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.util.callcontext.CallContext;
+import com.ning.billing.util.clock.ClockMock;
+import com.ning.billing.util.svcsapi.bus.BusService;
+
+public interface EntitlementTestInitializer {
+
+ public Catalog initCatalog(final CatalogService catalogService) throws Exception;
+
+ public AccountData initAccountData();
+
+ public SubscriptionBundle initBundle(final EntitlementUserApi entitlementApi, final CallContext callContext) throws Exception;
+
+ public void startTestFamework(final TestApiListener testListener,
+ final TestListenerStatus testListenerStatus,
+ final ClockMock clock,
+ final BusService busService,
+ final EntitlementService entitlementService) throws Exception;
+
+ public void stopTestFramework(final TestApiListener testListener,
+ final BusService busService,
+ final EntitlementService entitlementService) throws Exception;
+}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestListenerStatus.java b/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestListenerStatus.java
new file mode 100644
index 0000000..db6ee53
--- /dev/null
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestListenerStatus.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2010-2013 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.entitlement;
+
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+
+import com.ning.billing.api.TestListenerStatus;
+
+public class EntitlementTestListenerStatus implements TestListenerStatus {
+
+ private final Logger log = LoggerFactory.getLogger(EntitlementTestListenerStatus.class);
+
+ private boolean isListenerFailed;
+ private String listenerFailedMsg;
+
+
+ @Inject
+ public EntitlementTestListenerStatus() {
+ isListenerFailed = false;
+ }
+
+
+ @Override
+ public void failed(final String msg) {
+ this.isListenerFailed = true;
+ this.listenerFailedMsg = msg;
+ }
+
+ @Override
+ public void resetTestListenerStatus() {
+ this.isListenerFailed = false;
+ this.listenerFailedMsg = null;
+ }
+
+ public void assertListenerStatus() {
+ if (isListenerFailed) {
+ log.error(listenerFailedMsg);
+ Assert.fail(listenerFailedMsg);
+ }
+ }
+}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteNoDB.java b/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteNoDB.java
new file mode 100644
index 0000000..c13685d
--- /dev/null
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteNoDB.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2010-2013 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.entitlement;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.UUID;
+
+import javax.annotation.Nullable;
+import javax.inject.Inject;
+
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+import org.mockito.Mockito;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+
+import com.ning.billing.GuicyKillbillTestSuiteNoDB;
+import com.ning.billing.account.api.AccountData;
+import com.ning.billing.account.api.BillCycleDay;
+import com.ning.billing.api.TestApiListener;
+import com.ning.billing.api.TestListenerStatus;
+import com.ning.billing.catalog.DefaultCatalogService;
+import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.Catalog;
+import com.ning.billing.catalog.api.CatalogService;
+import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.catalog.api.Duration;
+import com.ning.billing.catalog.api.PhaseType;
+import com.ning.billing.catalog.api.PlanPhaseSpecifier;
+import com.ning.billing.entitlement.api.EntitlementService;
+import com.ning.billing.entitlement.api.migration.EntitlementMigrationApi;
+import com.ning.billing.entitlement.api.migration.EntitlementMigrationApi.EntitlementAccountMigration;
+import com.ning.billing.entitlement.api.timeline.EntitlementTimelineApi;
+import com.ning.billing.entitlement.api.transfer.EntitlementTransferApi;
+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.entitlement.api.user.SubscriptionData;
+import com.ning.billing.entitlement.api.user.TestUtil;
+import com.ning.billing.entitlement.api.user.TestUtil.EntitlementSubscriptionMigrationCaseWithCTD;
+import com.ning.billing.entitlement.engine.core.Engine;
+import com.ning.billing.entitlement.engine.dao.EntitlementDao;
+import com.ning.billing.entitlement.engine.dao.MockEntitlementDaoMemory;
+import com.ning.billing.entitlement.events.EntitlementEvent;
+import com.ning.billing.entitlement.glue.MockEngineModuleMemory;
+import com.ning.billing.entitlement.glue.MockEngineModuleSql;
+import com.ning.billing.mock.MockAccountBuilder;
+import com.ning.billing.util.bus.DefaultBusService;
+import com.ning.billing.util.clock.ClockMock;
+import com.ning.billing.util.config.EntitlementConfig;
+import com.ning.billing.util.events.EffectiveSubscriptionInternalEvent;
+import com.ning.billing.util.svcapi.entitlement.EntitlementInternalApi;
+import com.ning.billing.util.svcsapi.bus.BusService;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Stage;
+
+import static org.testng.Assert.assertNotNull;
+
+public class EntitlementTestSuiteNoDB extends GuicyKillbillTestSuiteNoDB {
+
+ protected static final Logger log = LoggerFactory.getLogger(EntitlementTestSuiteNoDB.class);
+
+ @Inject
+ protected EntitlementService entitlementService;
+ @Inject
+ protected EntitlementUserApi entitlementApi;
+ @Inject
+ protected EntitlementInternalApi entitlementInternalApi;
+ @Inject
+ protected EntitlementTransferApi transferApi;
+
+ @Inject
+ protected EntitlementMigrationApi migrationApi;
+ @Inject
+ protected EntitlementTimelineApi repairApi;
+
+ @Inject
+ protected CatalogService catalogService;
+ @Inject
+ protected EntitlementConfig config;
+ @Inject
+ protected EntitlementDao dao;
+ @Inject
+ protected ClockMock clock;
+ @Inject
+ protected BusService busService;
+
+ @Inject
+ protected TestUtil testUtil;
+ @Inject
+ protected TestApiListener testListener;
+ @Inject
+ protected TestListenerStatus testListenerStatus;
+
+ @Inject
+ protected EntitlementTestInitializer entitlementTestInitializer;
+
+ protected Catalog catalog;
+ protected AccountData accountData;
+ protected SubscriptionBundle bundle;
+
+
+ @BeforeClass(groups = "slow")
+ public void setup() throws Exception {
+ DefaultEntitlementTestInitializer.loadSystemPropertiesFromClasspath("/entitlement.properties");
+ final Injector g = Guice.createInjector(Stage.PRODUCTION, new MockEngineModuleMemory());
+ g.injectMembers(this);
+ }
+
+
+ @BeforeMethod(groups = "slow")
+ public void setupTest() throws Exception {
+
+ // CLEANUP ALL DB TABLES OR IN MEMORY STRUCTURES
+ ((MockEntitlementDaoMemory) dao).reset();
+
+ entitlementTestInitializer.startTestFamework(testListener, testListenerStatus, clock, busService, entitlementService);
+
+ this.catalog = entitlementTestInitializer.initCatalog(catalogService);
+ this.accountData = entitlementTestInitializer.initAccountData();
+ this.bundle = entitlementTestInitializer.initBundle(entitlementApi, callContext);
+ }
+
+
+ @AfterMethod(groups = "slow")
+ public void cleanupTest() throws Exception {
+ entitlementTestInitializer.stopTestFramework(testListener, busService, entitlementService);
+ }
+
+ protected void assertListenerStatus() {
+ ((EntitlementTestListenerStatus) testListenerStatus).assertListenerStatus();
+ }
+}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteWithEmbeddedDB.java b/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteWithEmbeddedDB.java
index 0537107..087f7ef 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteWithEmbeddedDB.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteWithEmbeddedDB.java
@@ -16,7 +16,108 @@
package com.ning.billing.entitlement;
-import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
+import javax.inject.Inject;
-public abstract class EntitlementTestSuiteWithEmbeddedDB extends KillbillTestSuiteWithEmbeddedDB {
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+
+import com.ning.billing.GuicyKillbillTestSuiteWithEmbeddedDB;
+import com.ning.billing.account.api.AccountData;
+import com.ning.billing.api.TestApiListener;
+import com.ning.billing.api.TestListenerStatus;
+import com.ning.billing.catalog.api.Catalog;
+import com.ning.billing.catalog.api.CatalogService;
+import com.ning.billing.entitlement.api.EntitlementService;
+import com.ning.billing.entitlement.api.migration.EntitlementMigrationApi;
+import com.ning.billing.entitlement.api.timeline.EntitlementTimelineApi;
+import com.ning.billing.entitlement.api.transfer.EntitlementTransferApi;
+import com.ning.billing.entitlement.api.user.EntitlementUserApi;
+import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.entitlement.api.user.TestUtil;
+import com.ning.billing.entitlement.engine.dao.EntitlementDao;
+import com.ning.billing.entitlement.glue.MockEngineModuleSql;
+import com.ning.billing.util.clock.ClockMock;
+import com.ning.billing.util.config.EntitlementConfig;
+import com.ning.billing.util.svcapi.entitlement.EntitlementInternalApi;
+import com.ning.billing.util.svcsapi.bus.BusService;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Stage;
+
+public class EntitlementTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuiteWithEmbeddedDB {
+
+
+ protected static final Logger log = LoggerFactory.getLogger(EntitlementTestSuiteWithEmbeddedDB.class);
+
+ @Inject
+ protected EntitlementService entitlementService;
+ @Inject
+ protected EntitlementUserApi entitlementApi;
+ @Inject
+ protected EntitlementInternalApi entitlementInternalApi;
+ @Inject
+ protected EntitlementTransferApi transferApi;
+
+ @Inject
+ protected EntitlementMigrationApi migrationApi;
+ @Inject
+ protected EntitlementTimelineApi repairApi;
+
+ @Inject
+ protected CatalogService catalogService;
+ @Inject
+ protected EntitlementConfig config;
+ @Inject
+ protected EntitlementDao dao;
+ @Inject
+ protected ClockMock clock;
+ @Inject
+ protected BusService busService;
+
+ @Inject
+ protected TestUtil testUtil;
+ @Inject
+ protected TestApiListener testListener;
+ @Inject
+ protected TestListenerStatus testListenerStatus;
+
+ @Inject
+ protected EntitlementTestInitializer entitlementTestInitializer;
+
+ protected Catalog catalog;
+ protected AccountData accountData;
+ protected SubscriptionBundle bundle;
+
+
+ @BeforeClass(groups = "slow")
+ public void setup() throws Exception {
+ DefaultEntitlementTestInitializer.loadSystemPropertiesFromClasspath("/entitlement.properties");
+ final Injector g = Guice.createInjector(Stage.PRODUCTION, new MockEngineModuleSql());
+ g.injectMembers(this);
+ }
+
+
+ @BeforeMethod(groups = "slow")
+ public void setupTest() throws Exception {
+ entitlementTestInitializer.startTestFamework(testListener, testListenerStatus, clock, busService, entitlementService);
+
+ this.catalog = entitlementTestInitializer.initCatalog(catalogService);
+ this.accountData = entitlementTestInitializer.initAccountData();
+ this.bundle = entitlementTestInitializer.initBundle(entitlementApi, callContext);
+ }
+
+
+ @AfterMethod(groups = "slow")
+ public void cleanupTest() throws Exception {
+ entitlementTestInitializer.stopTestFramework(testListener, busService, entitlementService);
+ }
+
+ protected void assertListenerStatus() {
+ ((EntitlementTestListenerStatus) testListenerStatus).assertListenerStatus();
+ }
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModule.java b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModule.java
index c45dae5..18aaf5b 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModule.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModule.java
@@ -19,20 +19,41 @@ package com.ning.billing.entitlement.glue;
import org.mockito.Mockito;
import com.ning.billing.account.api.AccountUserApi;
+import com.ning.billing.api.TestApiListener;
+import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.catalog.glue.CatalogModule;
+import com.ning.billing.entitlement.DefaultEntitlementTestInitializer;
+import com.ning.billing.entitlement.EntitlementTestInitializer;
+import com.ning.billing.entitlement.EntitlementTestListenerStatus;
+import com.ning.billing.entitlement.api.user.DefaultEntitlementUserApi;
+import com.ning.billing.entitlement.api.user.EntitlementUserApi;
+import com.ning.billing.entitlement.api.user.TestUtil;
import com.ning.billing.mock.glue.MockClockModule;
import com.ning.billing.util.glue.CacheModule;
import com.ning.billing.util.glue.CallContextModule;
import com.ning.billing.util.glue.NonEntityDaoModule;
+import com.ning.billing.util.glue.RealImplementation;
public class MockEngineModule extends DefaultEntitlementModule {
+
+
+ @Override
+ public void installEntitlementUserApi() {
+ bind(EntitlementUserApi.class).to(DefaultEntitlementUserApi.class).asEagerSingleton();
+ }
+
@Override
protected void configure() {
super.configure();
install(new CatalogModule());
- bind(AccountUserApi.class).toInstance(Mockito.mock(AccountUserApi.class));
- install(new MockClockModule());
install(new CallContextModule());
install(new CacheModule());
+
+ bind(AccountUserApi.class).toInstance(Mockito.mock(AccountUserApi.class));
+
+ bind(TestUtil.class).asEagerSingleton();
+ bind(TestListenerStatus.class).to(EntitlementTestListenerStatus.class).asEagerSingleton();
+ bind(TestApiListener.class).asEagerSingleton();
+ bind(EntitlementTestInitializer.class).to(DefaultEntitlementTestInitializer.class).asEagerSingleton();
}
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleMemory.java b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleMemory.java
index 63e0a44..7836eca 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleMemory.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleMemory.java
@@ -24,7 +24,9 @@ import org.mockito.Mockito;
import org.skife.config.ConfigurationObjectFactory;
import org.skife.jdbi.v2.IDBI;
+import com.ning.billing.GuicyKillbillTestModule;
import com.ning.billing.ObjectType;
+import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.entitlement.api.timeline.RepairEntitlementLifecycleDao;
import com.ning.billing.entitlement.engine.dao.EntitlementDao;
import com.ning.billing.entitlement.engine.dao.MockEntitlementDaoMemory;
@@ -68,10 +70,15 @@ public class MockEngineModuleMemory extends MockEngineModule {
@Override
protected void configure() {
installDBI();
+
+ install(new GuicyKillbillTestModule());
+
super.configure();
+
install(new BusModule(BusType.MEMORY));
installNotificationQueue();
install(new MockNonEntityDaoModule());
+
}
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleSql.java b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleSql.java
index d66a7aa..17ee6f4 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleSql.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleSql.java
@@ -19,6 +19,7 @@ package com.ning.billing.entitlement.glue;
import org.skife.config.ConfigurationObjectFactory;
import org.skife.jdbi.v2.IDBI;
+import com.ning.billing.GuicyKillbillTestWithEmbeddedDBModule;
import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.dbi.DBIProvider;
import com.ning.billing.dbi.DBTestingHelper;
@@ -44,6 +45,7 @@ public class MockEngineModuleSql extends MockEngineModule {
bind(RepairEntitlementDao.class).asEagerSingleton();
}
+/*
protected void installDBI() {
final DBTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getDBTestingHelper();
if (helper.isUsingLocalInstance()) {
@@ -55,11 +57,17 @@ public class MockEngineModuleSql extends MockEngineModule {
bind(IDBI.class).toInstance(dbi);
}
}
+*/
@Override
protected void configure() {
+
+ install(new GuicyKillbillTestWithEmbeddedDBModule());
+
install(new NonEntityDaoModule());
- installDBI();
+
+ //installDBI();
+
install(new NotificationQueueModule());
install(new CustomFieldModule());
install(new BusModule(BusType.PERSISTENT));
diff --git a/entitlement/src/test/resources/testInput.xml b/entitlement/src/test/resources/testInput.xml
index bdc73db..973afd0 100644
--- a/entitlement/src/test/resources/testInput.xml
+++ b/entitlement/src/test/resources/testInput.xml
@@ -71,6 +71,10 @@
<phaseType>TRIAL</phaseType>
<policy>IMMEDIATE</policy>
</changePolicyCase>
+ <changePolicyCase>
+ <toPriceList>rescue</toPriceList>
+ <policy>END_OF_TERM</policy>
+ </changePolicyCase>
<changePolicyCase>
<toProduct>Assault-Rifle</toProduct>
<policy>IMMEDIATE</policy>
@@ -81,10 +85,6 @@
<policy>IMMEDIATE</policy>
</changePolicyCase>
<changePolicyCase>
- <toPriceList>rescue</toPriceList>
- <policy>END_OF_TERM</policy>
- </changePolicyCase>
- <changePolicyCase>
<fromBillingPeriod>MONTHLY</fromBillingPeriod>
<toBillingPeriod>ANNUAL</toBillingPeriod>
<policy>IMMEDIATE</policy>
diff --git a/util/src/test/java/com/ning/billing/api/TestApiListener.java b/util/src/test/java/com/ning/billing/api/TestApiListener.java
index b7d7057..6979bc8 100644
--- a/util/src/test/java/com/ning/billing/api/TestApiListener.java
+++ b/util/src/test/java/com/ning/billing/api/TestApiListener.java
@@ -20,6 +20,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Stack;
+import javax.inject.Inject;
+
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,6 +48,7 @@ public class TestApiListener {
private volatile boolean completed;
+ @Inject
public TestApiListener(final TestListenerStatus testStatus) {
nextExpectedEvent = new Stack<NextEvent>();
this.completed = false;
diff --git a/util/src/test/java/com/ning/billing/GuicyKillbillTestModule.java b/util/src/test/java/com/ning/billing/GuicyKillbillTestModule.java
new file mode 100644
index 0000000..9ab7a27
--- /dev/null
+++ b/util/src/test/java/com/ning/billing/GuicyKillbillTestModule.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2010-2013 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;
+
+import java.util.UUID;
+
+import com.ning.billing.util.callcontext.CallContext;
+import com.ning.billing.util.callcontext.CallOrigin;
+import com.ning.billing.util.callcontext.InternalCallContext;
+import com.ning.billing.util.callcontext.InternalCallContextFactory;
+import com.ning.billing.util.callcontext.UserType;
+import com.ning.billing.util.clock.Clock;
+import com.ning.billing.util.clock.ClockMock;
+
+import com.google.inject.AbstractModule;
+
+public class GuicyKillbillTestModule extends AbstractModule {
+
+ //
+ // CreatedFontTracker references that will later be injected through Guices.
+ // That we we have only one clock and all internalContext/callContext are consistent
+ //
+ private final ClockMock clock = new ClockMock();
+
+ private final InternalCallContext internalCallContext = new InternalCallContext(InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID, 1687L, UUID.randomUUID(),
+ UUID.randomUUID().toString(), CallOrigin.TEST,
+ UserType.TEST, "Testing", "This is a test",
+ clock.getUTCNow(), clock.getUTCNow());
+
+ private final CallContext callContext = internalCallContext.toCallContext();
+
+
+ @Override
+ protected void configure() {
+ bind(Clock.class).toInstance(clock);
+ bind(ClockMock.class).toInstance(clock);
+ bind(InternalCallContext.class).toInstance(internalCallContext);
+ bind(CallContext.class).toInstance(callContext);
+ }
+}
diff --git a/util/src/test/java/com/ning/billing/GuicyKillbillTestSuite.java b/util/src/test/java/com/ning/billing/GuicyKillbillTestSuite.java
new file mode 100644
index 0000000..2cf9a7f
--- /dev/null
+++ b/util/src/test/java/com/ning/billing/GuicyKillbillTestSuite.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2010-2013 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;
+
+import java.lang.reflect.Method;
+import java.util.UUID;
+
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.ITestResult;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+
+import com.ning.billing.util.callcontext.CallContext;
+import com.ning.billing.util.callcontext.CallOrigin;
+import com.ning.billing.util.callcontext.InternalCallContext;
+import com.ning.billing.util.callcontext.InternalCallContextFactory;
+import com.ning.billing.util.callcontext.UserType;
+import com.ning.billing.util.clock.Clock;
+import com.ning.billing.util.clock.ClockMock;
+
+public class GuicyKillbillTestSuite {
+
+
+ // Use the simple name here to save screen real estate
+ protected static final Logger log = LoggerFactory.getLogger(KillbillTestSuite.class.getSimpleName());
+
+ private boolean hasFailed = false;
+
+ @Inject
+ protected ClockMock clock;
+
+ @Inject
+ protected InternalCallContext internalCallContext;
+
+ @Inject
+ protected CallContext callContext;
+
+
+ @BeforeMethod(alwaysRun = true)
+ public void startTestSuite(final Method method) throws Exception {
+ log.info("***************************************************************************************************");
+ log.info("*** Starting test {}:{}", method.getDeclaringClass().getName(), method.getName());
+ log.info("***************************************************************************************************");
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void endTestSuite(final Method method, final ITestResult result) throws Exception {
+ log.info("***************************************************************************************************");
+ log.info("*** Ending test {}:{} {} ({} s.)", new Object[]{method.getDeclaringClass().getName(), method.getName(),
+ result.isSuccess() ? "SUCCESS" : "!!! FAILURE !!!",
+ (result.getEndMillis() - result.getStartMillis()) / 1000});
+ log.info("***************************************************************************************************");
+ if (!hasFailed && !result.isSuccess()) {
+ hasFailed = true;
+ }
+ }
+
+ public boolean hasFailed() {
+ return hasFailed;
+ }
+}
diff --git a/util/src/test/java/com/ning/billing/GuicyKillbillTestSuiteWithEmbeddedDB.java b/util/src/test/java/com/ning/billing/GuicyKillbillTestSuiteWithEmbeddedDB.java
new file mode 100644
index 0000000..c171dcf
--- /dev/null
+++ b/util/src/test/java/com/ning/billing/GuicyKillbillTestSuiteWithEmbeddedDB.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2010-2013 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;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.sql.SQLException;
+
+import javax.inject.Inject;
+
+import org.skife.jdbi.v2.IDBI;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterSuite;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.BeforeSuite;
+
+import com.ning.billing.dbi.DBTestingHelper;
+import com.ning.billing.dbi.H2TestingHelper;
+import com.ning.billing.dbi.MysqlTestingHelper;
+
+public class GuicyKillbillTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuite {
+
+ private static final Logger log = LoggerFactory.getLogger(KillbillTestSuiteWithEmbeddedDB.class);
+
+ @Inject
+ private DBTestingHelper helper;
+
+ public DBTestingHelper getDBTestingHelper() {
+ return GuicyKillbillTestWithEmbeddedDBModule.getDBTestingHelper();
+ }
+
+ public IDBI getDBI() {
+ return GuicyKillbillTestWithEmbeddedDBModule.getDBTestingHelper().getDBI();
+ }
+
+ @BeforeSuite(groups = {"slow", "mysql"})
+ public void startMysqlBeforeTestSuite() throws IOException, ClassNotFoundException, SQLException, URISyntaxException {
+
+ GuicyKillbillTestWithEmbeddedDBModule.getDBTestingHelper().start();
+ GuicyKillbillTestWithEmbeddedDBModule.getDBTestingHelper().initDb();
+ GuicyKillbillTestWithEmbeddedDBModule.getDBTestingHelper().cleanupAllTables();
+ }
+
+ @BeforeMethod(groups = {"slow", "mysql"})
+ public void cleanupTablesBetweenMethods() {
+ try {
+ GuicyKillbillTestWithEmbeddedDBModule.getDBTestingHelper().cleanupAllTables();
+ } catch (Exception ignored) {
+ }
+ }
+
+ @AfterSuite(groups = {"slow", "mysql"})
+ public void shutdownMysqlAfterTestSuite() throws IOException, ClassNotFoundException, SQLException, URISyntaxException {
+ if (hasFailed()) {
+ log.error("**********************************************************************************************");
+ log.error("*** TESTS HAVE FAILED - LEAVING DB RUNNING FOR DEBUGGING - MAKE SURE TO KILL IT ONCE DONE ****");
+ log.error(GuicyKillbillTestWithEmbeddedDBModule.getDBTestingHelper().getConnectionString());
+ log.error("**********************************************************************************************");
+ return;
+ }
+
+ try {
+ GuicyKillbillTestWithEmbeddedDBModule.getDBTestingHelper().stop();
+ } catch (Exception ignored) {
+ }
+ }
+}
diff --git a/util/src/test/java/com/ning/billing/GuicyKillbillTestWithEmbeddedDBModule.java b/util/src/test/java/com/ning/billing/GuicyKillbillTestWithEmbeddedDBModule.java
new file mode 100644
index 0000000..c568530
--- /dev/null
+++ b/util/src/test/java/com/ning/billing/GuicyKillbillTestWithEmbeddedDBModule.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2010-2013 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;
+
+
+import javax.inject.Provider;
+
+import org.skife.jdbi.v2.DBI;
+import org.skife.jdbi.v2.IDBI;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ning.billing.dbi.DBTestingHelper;
+import com.ning.billing.dbi.H2TestingHelper;
+import com.ning.billing.dbi.MysqlTestingHelper;
+
+public class GuicyKillbillTestWithEmbeddedDBModule extends GuicyKillbillTestModule {
+
+ private final static Logger log = LoggerFactory.getLogger(GuicyKillbillTestWithEmbeddedDBModule.class);
+
+ private static DBTestingHelper instance = getDBTestingHelper();
+
+ public static synchronized DBTestingHelper getDBTestingHelper() {
+ if (instance == null) {
+ if ("true".equals(System.getProperty("com.ning.billing.dbi.test.h2"))) {
+ log.info("Using h2 as the embedded database");
+ return new H2TestingHelper();
+ } else {
+ log.info("Using MySQL as the embedded database");
+ return new MysqlTestingHelper();
+ }
+ }
+ return instance;
+ }
+
+ @Override
+ protected void configure() {
+ super.configure();
+ bind(DBTestingHelper.class).toInstance(instance);
+ bind(IDBI.class).toInstance(instance.getDBI());
+ }
+}