Search in sources :

Example 61 with DefaultSubscriptionBase

use of org.killbill.billing.subscription.api.user.DefaultSubscriptionBase in project killbill by killbill.

the class TestPlanAligner method testCreateWithTargetPhaseType3.

// 
// Scenario : change Plan with START_OF_SUBSCRIPTION after skipping TRIAL on Create to a new Plan that has {TRIAL, DISCOUNT, EVERGREEN}
// 
@Test(groups = "fast")
public void testCreateWithTargetPhaseType3() throws Exception {
    final String productName = "pistol-monthly";
    final DateTime now = clock.getUTCNow();
    final DateTime bundleStartDate = now;
    final DateTime alignStartDate = bundleStartDate;
    final Plan plan = currentVersion.findPlan(productName);
    final TimedPhase[] phases = planAligner.getCurrentAndNextTimedPhaseOnCreate(alignStartDate, bundleStartDate, plan, PhaseType.EVERGREEN, PriceListSet.DEFAULT_PRICELIST_NAME, now, catalog, internalCallContext);
    Assert.assertEquals(phases.length, 2);
    Assert.assertEquals(phases[0].getPhase().getPhaseType(), PhaseType.EVERGREEN);
    Assert.assertEquals(phases[0].getStartPhase(), now);
    Assert.assertNull(phases[1]);
    final DefaultSubscriptionBase defaultSubscriptionBase = createSubscription(bundleStartDate, alignStartDate, productName, PhaseType.EVERGREEN);
    final String newProductName = "assault-rifle-annual-gunclub-discount";
    final Plan newPlan = currentVersion.findPlan(newProductName);
    final DateTime effectiveChangeDate = defaultSubscriptionBase.getStartDate().plusMonths(15);
    // Because new Plan has an EVERGREEN PhaseType we end up directly on that PhaseType
    final TimedPhase currentPhase = planAligner.getCurrentTimedPhaseOnChange(defaultSubscriptionBase, newPlan, effectiveChangeDate, null, catalog, internalCallContext);
    Assert.assertEquals(currentPhase.getStartPhase(), alignStartDate);
    Assert.assertEquals(currentPhase.getPhase().getPhaseType(), PhaseType.EVERGREEN);
}
Also used : DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) Plan(org.killbill.billing.catalog.api.Plan) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 62 with DefaultSubscriptionBase

use of org.killbill.billing.subscription.api.user.DefaultSubscriptionBase in project killbill by killbill.

the class TestDefaultSubscriptionTransferApi method testEventsForCancelledSubscriptionBeforeTransfer.

@Test(groups = "fast")
public void testEventsForCancelledSubscriptionBeforeTransfer() throws Exception {
    final DateTime subscriptionStartTime = clock.getUTCNow();
    final DateTime subscriptionCancelTime = subscriptionStartTime.plusDays(1);
    final ImmutableList<ExistingEvent> existingEvents = ImmutableList.<ExistingEvent>of(createEvent(subscriptionStartTime, SubscriptionBaseTransitionType.CREATE), createEvent(subscriptionCancelTime, SubscriptionBaseTransitionType.CANCEL));
    final SubscriptionBuilder subscriptionBuilder = new SubscriptionBuilder();
    final DefaultSubscriptionBase subscription = new DefaultSubscriptionBase(subscriptionBuilder);
    final DateTime transferDate = subscriptionStartTime.plusDays(10);
    final List<SubscriptionBaseEvent> events = transferApi.toEvents(existingEvents, subscription, transferDate, internalCallContext);
    Assert.assertEquals(events.size(), 0);
}
Also used : SubscriptionBuilder(org.killbill.billing.subscription.api.user.SubscriptionBuilder) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) ExistingEvent(org.killbill.billing.subscription.api.timeline.SubscriptionBaseTimeline.ExistingEvent) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 63 with DefaultSubscriptionBase

use of org.killbill.billing.subscription.api.user.DefaultSubscriptionBase in project killbill by killbill.

the class TestDefaultSubscriptionTransferApi method testEventsForCancelledSubscriptionAfterTransfer.

@Test(groups = "fast")
public void testEventsForCancelledSubscriptionAfterTransfer() throws Exception {
    final DateTime subscriptionStartTime = clock.getUTCNow();
    final DateTime subscriptionCancelTime = subscriptionStartTime.plusDays(1);
    final ImmutableList<ExistingEvent> existingEvents = ImmutableList.<ExistingEvent>of(createEvent(subscriptionStartTime, SubscriptionBaseTransitionType.CREATE), createEvent(subscriptionCancelTime, SubscriptionBaseTransitionType.CANCEL));
    final SubscriptionBuilder subscriptionBuilder = new SubscriptionBuilder();
    final DefaultSubscriptionBase subscription = new DefaultSubscriptionBase(subscriptionBuilder);
    final DateTime transferDate = subscriptionStartTime.plusHours(1);
    final List<SubscriptionBaseEvent> events = transferApi.toEvents(existingEvents, subscription, transferDate, internalCallContext);
    Assert.assertEquals(events.size(), 1);
    Assert.assertEquals(events.get(0).getType(), EventType.API_USER);
    Assert.assertEquals(events.get(0).getEffectiveDate(), transferDate);
    Assert.assertEquals(((ApiEventTransfer) events.get(0)).getApiEventType(), ApiEventType.TRANSFER);
}
Also used : SubscriptionBuilder(org.killbill.billing.subscription.api.user.SubscriptionBuilder) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) ExistingEvent(org.killbill.billing.subscription.api.timeline.SubscriptionBaseTimeline.ExistingEvent) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)63 DateTime (org.joda.time.DateTime)38 Test (org.testng.annotations.Test)30 SubscriptionBaseEvent (org.killbill.billing.subscription.events.SubscriptionBaseEvent)18 Plan (org.killbill.billing.catalog.api.Plan)17 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)17 ArrayList (java.util.ArrayList)16 LocalDate (org.joda.time.LocalDate)13 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)13 SubscriptionBuilder (org.killbill.billing.subscription.api.user.SubscriptionBuilder)13 BigDecimal (java.math.BigDecimal)12 Account (org.killbill.billing.account.api.Account)12 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)12 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)12 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)11 LinkedList (java.util.LinkedList)10 SubscriptionBaseBundle (org.killbill.billing.subscription.api.user.SubscriptionBaseBundle)10 UUID (java.util.UUID)9 Invoice (org.killbill.billing.invoice.api.Invoice)9 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)8