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());
}
}
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();
}
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);
}
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);
}
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);
}
Aggregations