use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.
the class TestUserApiCreate method testCreateWithInitialPhase.
@Test(groups = "slow")
public void testCreateWithInitialPhase() throws SubscriptionBaseApiException {
final DateTime init = clock.getUTCNow();
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
testListener.pushExpectedEvent(NextEvent.CREATE);
final DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) subscriptionInternalApi.createSubscription(bundle.getId(), testUtil.getProductSpecifier(productName, planSetName, term, PhaseType.EVERGREEN), null, clock.getUTCNow(), false, internalCallContext);
assertNotNull(subscription);
assertEquals(subscription.getBundleId(), bundle.getId());
testUtil.assertDateWithin(subscription.getStartDate(), init, clock.getUTCNow());
testUtil.assertDateWithin(subscription.getBundleStartDate(), init, clock.getUTCNow());
final Plan currentPlan = subscription.getCurrentPlan();
assertNotNull(currentPlan);
assertEquals(currentPlan.getProduct().getName(), productName);
assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE);
assertEquals(currentPlan.getRecurringBillingPeriod(), BillingPeriod.MONTHLY);
final PlanPhase currentPhase = subscription.getCurrentPhase();
assertNotNull(currentPhase);
assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN);
assertListenerStatus();
}
use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.
the class TestUserApiCreate method testSimpleSubscriptionThroughPhases.
@Test(groups = "slow")
public void testSimpleSubscriptionThroughPhases() throws SubscriptionBaseApiException {
final String productName = "Pistol";
final BillingPeriod term = BillingPeriod.ANNUAL;
final String planSetName = "gunclubDiscount";
testListener.pushExpectedEvent(NextEvent.CREATE);
// CREATE SUBSCRIPTION
DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) subscriptionInternalApi.createSubscription(bundle.getId(), testUtil.getProductSpecifier(productName, planSetName, term, null), null, clock.getUTCNow(), false, internalCallContext);
assertNotNull(subscription);
PlanPhase currentPhase = subscription.getCurrentPhase();
assertNotNull(currentPhase);
assertEquals(currentPhase.getPhaseType(), PhaseType.TRIAL);
assertListenerStatus();
// MOVE TO DISCOUNT PHASE
testListener.pushExpectedEvent(NextEvent.PHASE);
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31));
clock.addDeltaFromReality(it.toDurationMillis());
assertListenerStatus();
currentPhase = subscription.getCurrentPhase();
assertNotNull(currentPhase);
assertEquals(currentPhase.getPhaseType(), PhaseType.DISCOUNT);
// MOVE TO EVERGREEN PHASE + RE-READ SUBSCRIPTION
testListener.pushExpectedEvent(NextEvent.PHASE);
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusYears(1));
clock.addDeltaFromReality(it.toDurationMillis());
assertListenerStatus();
subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
currentPhase = subscription.getCurrentPhase();
assertNotNull(currentPhase);
assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN);
assertListenerStatus();
}
use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.
the class TestTimedPhase method testConstructor.
@Test(groups = "fast")
public void testConstructor() throws Exception {
final PlanPhase planPhase = Mockito.mock(PlanPhase.class);
final DateTime startPhase = new DateTime(DateTimeZone.UTC);
final TimedPhase timedPhase = new TimedPhase(planPhase, startPhase);
final TimedPhase otherTimedPhase = new TimedPhase(planPhase, startPhase);
Assert.assertEquals(otherTimedPhase, timedPhase);
Assert.assertEquals(timedPhase.getPhase(), planPhase);
Assert.assertEquals(timedPhase.getStartPhase(), startPhase);
}
use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.
the class TestUserApiCancel method testCancelSubscriptionIMM.
@Test(groups = "slow")
public void testCancelSubscriptionIMM() throws SubscriptionBaseApiException {
final DateTime init = clock.getUTCNow();
final String prod = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE
final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, prod, term, planSet);
PlanPhase currentPhase = subscription.getCurrentPhase();
assertEquals(currentPhase.getPhaseType(), PhaseType.TRIAL);
// ADVANCE TIME still in trial
final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3));
clock.addDeltaFromReality(it.toDurationMillis());
final DateTime future = clock.getUTCNow();
testListener.pushExpectedEvent(NextEvent.CANCEL);
assertEquals(subscription.getLastActiveProduct().getName(), prod);
assertEquals(subscription.getLastActivePriceList().getName(), planSet);
assertEquals(subscription.getLastActiveBillingPeriod(), term);
assertEquals(subscription.getLastActiveCategory(), ProductCategory.BASE);
// CANCEL in trial period to get IMM policy
subscription.cancel(callContext);
currentPhase = subscription.getCurrentPhase();
assertListenerStatus();
assertEquals(subscription.getLastActiveProduct().getName(), prod);
assertEquals(subscription.getLastActivePriceList().getName(), planSet);
assertEquals(subscription.getLastActiveBillingPeriod(), term);
assertEquals(subscription.getLastActiveCategory(), ProductCategory.BASE);
assertNull(currentPhase);
testUtil.checkNextPhaseChange(subscription, 0, null);
assertListenerStatus();
}
use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.
the class TestUserApiCancel method testUncancel.
// Similar test to testCancelSubscriptionEOTWithChargeThroughDate except we uncancel and check things
// are as they used to be and we can move forward without hitting cancellation
@Test(groups = "slow")
public void testUncancel() throws SubscriptionBillingApiException, SubscriptionBaseApiException {
final String prod = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE
DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, prod, term, planSet);
final PlanPhase trialPhase = subscription.getCurrentPhase();
assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
// NEXT PHASE
final DateTime expectedPhaseTrialChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), trialPhase.getDuration());
testUtil.checkNextPhaseChange(subscription, 1, expectedPhaseTrialChange);
// MOVE TO NEXT PHASE
testListener.pushExpectedEvent(NextEvent.PHASE);
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31));
clock.addDeltaFromReality(it.toDurationMillis());
assertListenerStatus();
PlanPhase currentPhase = subscription.getCurrentPhase();
assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN);
// SET CTD + RE READ SUBSCRIPTION + CHANGE PLAN
final Duration ctd = testUtil.getDurationMonth(1);
final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(expectedPhaseTrialChange, ctd);
subscriptionInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate, internalCallContext);
subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
// CANCEL EOT
subscription.cancel(callContext);
subscription.uncancel(callContext);
// MOVE TO EOT + RECHECK
testListener.pushExpectedEvent(NextEvent.UNCANCEL);
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(1));
clock.addDeltaFromReality(it.toDurationMillis());
assertListenerStatus();
final Plan currentPlan = subscription.getCurrentPlan();
assertEquals(currentPlan.getProduct().getName(), prod);
currentPhase = subscription.getCurrentPhase();
assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN);
assertListenerStatus();
}
Aggregations