Search in sources :

Example 21 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestUserApiError method testChangeSubscriptionNonActive.

@Test(groups = "fast")
public void testChangeSubscriptionNonActive() throws SubscriptionBaseApiException {
    final SubscriptionBase subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME);
    testListener.pushExpectedEvent(NextEvent.CANCEL);
    subscription.cancelWithDate(clock.getUTCNow(), callContext);
    try {
        subscription.changePlanWithDate(new PlanSpecifier("Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME), null, clock.getUTCNow(), callContext);
    } catch (final SubscriptionBaseApiException e) {
        assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_NON_ACTIVE.getCode());
    }
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 22 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestUserApiError method testChangeSubscriptionFutureCancelled.

@Test(groups = "fast")
public void testChangeSubscriptionFutureCancelled() throws SubscriptionBaseApiException {
    SubscriptionBase subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
    final PlanPhase trialPhase = subscription.getCurrentPhase();
    // MOVE TO NEXT PHASE
    final PlanPhase currentPhase = subscription.getCurrentPhase();
    testListener.pushExpectedEvent(NextEvent.PHASE);
    final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31));
    clock.addDeltaFromReality(it.toDurationMillis());
    assertListenerStatus();
    // SET CTD TO CANCEL IN FUTURE
    final DateTime expectedPhaseTrialChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), trialPhase.getDuration());
    final Duration ctd = testUtil.getDurationMonth(1);
    final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(expectedPhaseTrialChange, ctd);
    subscriptionInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate, internalCallContext);
    subscription = subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
    subscription.cancelWithPolicy(BillingActionPolicy.END_OF_TERM, null, -1, callContext);
    try {
        subscription.changePlanWithDate(new PlanSpecifier("Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME), null, clock.getUTCNow(), callContext);
    } catch (final SubscriptionBaseApiException e) {
        assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_FUTURE_CANCELLED.getCode());
    }
    assertListenerStatus();
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) Duration(org.killbill.billing.catalog.api.Duration) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 23 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestLoadRules method test.

@Test(groups = "fast")
public void test() throws Exception {
    final URI uri = new URI(Resources.getResource("WeaponsHireSmall.xml").toExternalForm());
    final StandaloneCatalog catalog = XMLLoader.getObjectFromUri(uri, StandaloneCatalog.class);
    Assert.assertNotNull(catalog);
    final DefaultPlanRules rules = catalog.getPlanRules();
    final PlanSpecifier specifier = new PlanSpecifier("Laser-Scope", BillingPeriod.MONTHLY, "DEFAULT");
    final PlanAlignmentCreate alignment = rules.getPlanCreateAlignment(specifier, catalog);
    Assert.assertEquals(alignment, PlanAlignmentCreate.START_OF_SUBSCRIPTION);
    final PlanSpecifier specifier2 = new PlanSpecifier("Extra-Ammo", BillingPeriod.MONTHLY, "DEFAULT");
    final PlanAlignmentCreate alignment2 = rules.getPlanCreateAlignment(specifier2, catalog);
    Assert.assertEquals(alignment2, PlanAlignmentCreate.START_OF_BUNDLE);
}
Also used : StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) URI(java.net.URI) PlanAlignmentCreate(org.killbill.billing.catalog.api.PlanAlignmentCreate) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 24 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestPlanRules method testExistingPriceListIsKept.

@Test(groups = "fast")
public void testExistingPriceListIsKept() throws CatalogApiException {
    final DefaultProduct product1 = cat.getCurrentProduct(0);
    final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final PlanPhaseSpecifier from = new PlanPhaseSpecifier(product1.getName(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN);
    final PlanSpecifier to = new PlanSpecifier(product1.getName(), BillingPeriod.ANNUAL, priceList1.getName());
    PlanChangeResult result = null;
    try {
        result = cat.getPlanRules().planChange(from, to, cat);
    } catch (IllegalPlanChange e) {
        Assert.fail("We should not have triggered this error");
    } catch (CatalogApiException e) {
        Assert.fail("", e);
    }
    Assert.assertEquals(result.getPolicy(), BillingActionPolicy.END_OF_TERM);
    Assert.assertEquals(result.getAlignment(), PlanAlignmentChange.START_OF_SUBSCRIPTION);
    Assert.assertEquals(result.getNewPriceList(), priceList1);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) IllegalPlanChange(org.killbill.billing.catalog.api.IllegalPlanChange) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PlanChangeResult(org.killbill.billing.catalog.api.PlanChangeResult) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 25 with PlanSpecifier

use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.

the class TestPlanRules method testBaseCase.

@Test(groups = "fast")
public void testBaseCase() throws CatalogApiException {
    final DefaultProduct product1 = cat.getCurrentProduct(0);
    final DefaultProduct product2 = cat.getCurrentProduct(1);
    final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[0];
    final PlanPhaseSpecifier from = new PlanPhaseSpecifier(product1.getName(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN);
    final PlanSpecifier to = new PlanSpecifier(product2.getName(), BillingPeriod.MONTHLY, null);
    PlanChangeResult result = null;
    try {
        result = cat.getPlanRules().planChange(from, to, cat);
    } catch (IllegalPlanChange e) {
        Assert.fail("We should not have triggered this error");
    } catch (CatalogApiException e) {
        Assert.fail("", e);
    }
    Assert.assertEquals(result.getPolicy(), BillingActionPolicy.END_OF_TERM);
    Assert.assertEquals(result.getAlignment(), PlanAlignmentChange.START_OF_SUBSCRIPTION);
    Assert.assertEquals(result.getNewPriceList(), priceList2);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) IllegalPlanChange(org.killbill.billing.catalog.api.IllegalPlanChange) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PlanChangeResult(org.killbill.billing.catalog.api.PlanChangeResult) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Aggregations

PlanSpecifier (org.killbill.billing.catalog.api.PlanSpecifier)39 Test (org.testng.annotations.Test)28 DateTime (org.joda.time.DateTime)16 Interval (org.joda.time.Interval)11 LocalDate (org.joda.time.LocalDate)9 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)8 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)8 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)7 Duration (org.killbill.billing.catalog.api.Duration)7 Account (org.killbill.billing.account.api.Account)6 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)6 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)6 DefaultPriceList (org.killbill.billing.catalog.DefaultPriceList)5 Plan (org.killbill.billing.catalog.api.Plan)5 ArrayList (java.util.ArrayList)4 DefaultProduct (org.killbill.billing.catalog.DefaultProduct)4 PlanAlignmentCreate (org.killbill.billing.catalog.api.PlanAlignmentCreate)4 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)4 BigDecimal (java.math.BigDecimal)3 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)3