use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.
the class TestUserApiChangePlan method tChangePlanBundleAlignEOTWithNoChargeThroughDate.
private void tChangePlanBundleAlignEOTWithNoChargeThroughDate(final String fromProd, final BillingPeriod fromTerm, final String fromPlanSet, final String toProd, final BillingPeriod toTerm, final String toPlanSet) {
try {
// CREATE
final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, fromProd, fromTerm, fromPlanSet);
// MOVE TO NEXT PHASE
PlanPhase currentPhase = subscription.getCurrentPhase();
testListener.pushExpectedEvent(NextEvent.PHASE);
final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31));
clock.addDeltaFromReality(it.toDurationMillis());
final DateTime futureNow = clock.getUTCNow();
final DateTime nextExpectedPhaseChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), currentPhase.getDuration());
assertTrue(futureNow.isAfter(nextExpectedPhaseChange));
assertListenerStatus();
// CHANGE PLAN
testListener.pushExpectedEvent(NextEvent.CHANGE);
subscription.changePlan(new PlanSpecifier(toProd, toTerm, toPlanSet), null, callContext);
assertListenerStatus();
// CHECK CHANGE PLAN
currentPhase = subscription.getCurrentPhase();
checkChangePlan(subscription, toProd, ProductCategory.BASE, toTerm, PhaseType.EVERGREEN);
assertListenerStatus();
} catch (SubscriptionBaseApiException e) {
Assert.fail(e.getMessage());
}
}
use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.
the class TestStandaloneCatalogWithPriceOverride method testCreatePlanInvalidProduct.
@Test(groups = "slow")
public void testCreatePlanInvalidProduct() throws Exception {
final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarAdvanced.xml").toExternalForm(), StandaloneCatalog.class);
final StaticCatalog standaloneCatalogWithPriceOverride = new StandaloneCatalogWithPriceOverride(catalog, priceOverride, internalCallContext.getTenantRecordId(), internalCallContextFactory);
try {
final PlanSpecifier specWithNullProduct = new PlanSpecifier("INVALID", BillingPeriod.ANNUAL, "DEFAULT");
standaloneCatalogWithPriceOverride.createOrFindCurrentPlan(specWithNullProduct, null);
Assert.fail();
} catch (final CatalogApiException e) {
Assert.assertEquals(e.getCode(), ErrorCode.CAT_NO_SUCH_PRODUCT.getCode());
}
}
use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.
the class DefaultPlanRules method planChange.
public PlanChangeResult planChange(final PlanPhaseSpecifier from, final PlanSpecifier to, final StaticCatalog catalog) throws CatalogApiException {
final DefaultPriceList toPriceList = to.getPriceListName() != null ? (DefaultPriceList) catalog.findCurrentPricelist(to.getPriceListName()) : findPriceList(from, catalog);
// If we use old scheme {product, billingPeriod, pricelist}, ensure pricelist is correct
// (Pricelist may be null because if it is unspecified this is the principal use-case)
final PlanSpecifier toWithPriceList = to.getPlanName() == null ? new PlanSpecifier(to.getProductName(), to.getBillingPeriod(), toPriceList.getName()) : to;
final BillingActionPolicy policy = getPlanChangePolicy(from, toWithPriceList, catalog);
if (policy == BillingActionPolicy.ILLEGAL) {
throw new IllegalPlanChange(from, toWithPriceList);
}
final PlanAlignmentChange alignment = getPlanChangeAlignment(from, toWithPriceList, catalog);
return new PlanChangeResult(toPriceList, policy, alignment);
}
use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.
the class TestDefaultEntitlement method testCancelWithEntitlementPolicyEOTNoCTDAndImmediateChange.
@Test(groups = "slow")
public void testCancelWithEntitlementPolicyEOTNoCTDAndImmediateChange() throws AccountApiException, EntitlementApiException, SubscriptionApiException, InterruptedException {
final LocalDate initialDate = new LocalDate(2013, 8, 7);
clock.setDay(initialDate);
final Account account = createAccount(getAccountData(7));
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
// Create entitlement and check each field
testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
final Entitlement entitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, account.getExternalKey(), null, null, null, false, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
// Immediate change during trial
testListener.pushExpectedEvent(NextEvent.CHANGE);
entitlement.changePlan(new PlanSpecifier("Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME), null, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
// Verify the change is immediate
final Entitlement entitlement2 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext);
assertEquals(entitlement2.getLastActivePlan().getProduct().getName(), "Assault-Rifle");
testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK);
final Entitlement cancelledEntitlement = entitlement.cancelEntitlementWithPolicy(EntitlementActionPolicy.END_OF_TERM, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
assertEquals(cancelledEntitlement.getState(), EntitlementState.CANCELLED);
assertEquals(cancelledEntitlement.getEffectiveEndDate(), initialDate);
// Entitlement started in trial on 2013-08-07, which is when we want the billing cancellation date to occur
final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(entitlement.getBaseEntitlementId(), callContext);
assertEquals(subscription.getBillingEndDate(), new LocalDate(2013, 8, 7));
}
use of org.killbill.billing.catalog.api.PlanSpecifier in project killbill by killbill.
the class TestCase method testCaseOrder.
@Test
public void testCaseOrder() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
final DefaultProduct product = cat.getCurrentProduct(0);
final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
final DefaultCaseResult cr0 = new DefaultCaseResult(product, ProductCategory.BASE, BillingPeriod.MONTHLY, priceList, Result.FOO);
final DefaultCaseResult cr1 = new DefaultCaseResult(product, ProductCategory.BASE, BillingPeriod.MONTHLY, priceList, Result.BAR);
final DefaultCaseResult cr2 = new DefaultCaseResult(product, ProductCategory.BASE, BillingPeriod.ANNUAL, priceList, Result.DIPSY);
final DefaultCaseResult cr3 = new DefaultCaseResult(product, ProductCategory.BASE, BillingPeriod.ANNUAL, priceList, Result.LALA);
final Result r1 = DefaultCase.getResult(new DefaultCaseResult[] { cr0, cr1, cr2, cr3 }, new PlanSpecifier(product.getName(), BillingPeriod.MONTHLY, priceList.getName()), cat);
Assert.assertEquals(r1, Result.FOO);
final Result r2 = DefaultCase.getResult(new DefaultCaseResult[] { cr0, cr1, cr2 }, new PlanSpecifier(product.getName(), BillingPeriod.ANNUAL, priceList.getName()), cat);
Assert.assertEquals(r2, Result.DIPSY);
}
Aggregations