use of org.killbill.billing.catalog.api.Product in project killbill by killbill.
the class StandaloneCatalog method createOrFindCurrentPlan.
/* (non-Javadoc)
* @see org.killbill.billing.catalog.ICatalog#getPlan(java.lang.String, java.lang.String)
*/
@Override
public Plan createOrFindCurrentPlan(final PlanSpecifier spec, final PlanPhasePriceOverridesWithCallContext unused) throws CatalogApiException {
final Plan result;
if (spec.getPlanName() != null) {
result = findCurrentPlan(spec.getPlanName());
} else {
if (spec.getProductName() == null) {
throw new CatalogApiException(ErrorCode.CAT_NULL_PRODUCT_NAME);
}
if (spec.getBillingPeriod() == null) {
throw new CatalogApiException(ErrorCode.CAT_NULL_BILLING_PERIOD);
}
final String inputOrDefaultPricelist = (spec.getPriceListName() == null) ? PriceListSet.DEFAULT_PRICELIST_NAME : spec.getPriceListName();
final Product product = findCurrentProduct(spec.getProductName());
result = priceLists.getPlanFrom(product, spec.getBillingPeriod(), inputOrDefaultPricelist);
}
if (result == null) {
throw new CatalogApiException(ErrorCode.CAT_PLAN_NOT_FOUND, spec.getPlanName() != null ? spec.getPlanName() : "undefined", spec.getProductName() != null ? spec.getProductName() : "undefined", spec.getBillingPeriod() != null ? spec.getBillingPeriod() : "undefined", spec.getPriceListName() != null ? spec.getPriceListName() : "undefined");
}
return result;
}
use of org.killbill.billing.catalog.api.Product in project killbill by killbill.
the class TestDefaultSubscriptionBundleTimeline method createTransition.
private SubscriptionBaseTransition createTransition(final UUID entitlementId, final EventType eventType, final ApiEventType apiEventType, final DateTime effectiveDate, final DateTime createdDate, final String prevPhaseName, final String nextPhaseName) throws CatalogApiException {
final PlanPhase prevPhase;
final Plan prevPlan;
final Product prevProduct;
final PriceList prevPriceList;
if (prevPhaseName == null) {
prevPhase = null;
prevPlan = null;
prevProduct = null;
prevPriceList = null;
} else {
prevPhase = Mockito.mock(PlanPhase.class);
Mockito.when(prevPhase.getName()).thenReturn(prevPhaseName);
prevProduct = Mockito.mock(Product.class);
Mockito.when(prevProduct.getName()).thenReturn("product");
prevPlan = Mockito.mock(Plan.class);
Mockito.when(prevPlan.getName()).thenReturn("plan");
Mockito.when(prevPlan.getProduct()).thenReturn(prevProduct);
prevPriceList = Mockito.mock(PriceList.class);
Mockito.when(prevPriceList.getName()).thenReturn("pricelist");
}
final PlanPhase nextPhase;
final Plan nextPlan;
final Product nextProduct;
final PriceList nextPriceList;
if (nextPhaseName == null) {
nextPhase = null;
nextPlan = null;
nextProduct = null;
nextPriceList = null;
} else {
nextPhase = Mockito.mock(PlanPhase.class);
Mockito.when(nextPhase.getName()).thenReturn(nextPhaseName);
nextProduct = Mockito.mock(Product.class);
Mockito.when(nextProduct.getName()).thenReturn("product");
nextPlan = Mockito.mock(Plan.class);
Mockito.when(nextPlan.getName()).thenReturn("plan");
Mockito.when(nextPlan.getProduct()).thenReturn(nextProduct);
nextPriceList = Mockito.mock(PriceList.class);
Mockito.when(nextPriceList.getName()).thenReturn("pricelist");
}
return new SubscriptionBaseTransitionData(UUID.randomUUID(), entitlementId, bundleId, bundleExternalKey, eventType, apiEventType, effectiveDate, null, null, null, prevPlan, prevPhase, prevPriceList, null, null, null, null, nextPlan, nextPhase, nextPriceList, null, 1L, createdDate, UUID.randomUUID(), true);
}
use of org.killbill.billing.catalog.api.Product in project killbill by killbill.
the class TestPlanDetailJson method testFromListing.
@Test(groups = "fast")
public void testFromListing() throws Exception {
final Product product = Mockito.mock(Product.class);
Mockito.when(product.getName()).thenReturn(UUID.randomUUID().toString());
final InternationalPrice price = Mockito.mock(InternationalPrice.class);
Mockito.when(price.getPrices()).thenReturn(new DefaultPrice[0]);
final PlanPhase planPhase = Mockito.mock(PlanPhase.class);
final Recurring recurring = Mockito.mock(Recurring.class);
Mockito.when(recurring.getRecurringPrice()).thenReturn(price);
Mockito.when(planPhase.getRecurring()).thenReturn(recurring);
final Plan plan = Mockito.mock(Plan.class);
Mockito.when(plan.getProduct()).thenReturn(product);
Mockito.when(plan.getName()).thenReturn(UUID.randomUUID().toString());
Mockito.when(plan.getRecurringBillingPeriod()).thenReturn(BillingPeriod.QUARTERLY);
Mockito.when(plan.getFinalPhase()).thenReturn(planPhase);
final PriceList priceList = Mockito.mock(PriceList.class);
Mockito.when(priceList.getName()).thenReturn(UUID.randomUUID().toString());
final Listing listing = Mockito.mock(Listing.class);
Mockito.when(listing.getPlan()).thenReturn(plan);
Mockito.when(listing.getPriceList()).thenReturn(priceList);
final PlanDetailJson planDetailJson = new PlanDetailJson(listing);
Assert.assertEquals(planDetailJson.getProduct(), plan.getProduct().getName());
Assert.assertEquals(planDetailJson.getPlan(), plan.getName());
Assert.assertEquals(planDetailJson.getFinalPhaseBillingPeriod(), plan.getRecurringBillingPeriod());
Assert.assertEquals(planDetailJson.getPriceList(), priceList.getName());
Assert.assertEquals(planDetailJson.getFinalPhaseRecurringPrice().size(), 0);
}
use of org.killbill.billing.catalog.api.Product in project killbill by killbill.
the class TestCatalogUpdater method testAddTrialPlanOnFirstCatalog.
@Test(groups = "fast")
public void testAddTrialPlanOnFirstCatalog() throws CatalogApiException {
final DateTime now = clock.getUTCNow();
final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("foo-monthly", "Foo", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, ImmutableList.<String>of());
final CatalogUpdater catalogUpdater = new CatalogUpdater(BillingMode.IN_ADVANCE, now, desc.getCurrency());
catalogUpdater.addSimplePlanDescriptor(desc);
final StandaloneCatalog catalog = catalogUpdater.getCatalog();
assertEquals(catalog.getCurrentProducts().size(), 1);
final Product product = catalog.getCurrentProducts().iterator().next();
assertEquals(product.getName(), "Foo");
assertEquals(product.getCategory(), ProductCategory.BASE);
assertEquals(catalog.getCurrentPlans().size(), 1);
final Plan plan = catalog.findCurrentPlan("foo-monthly");
assertEquals(plan.getName(), "foo-monthly");
assertEquals(plan.getInitialPhases().length, 1);
assertEquals(plan.getInitialPhases()[0].getPhaseType(), PhaseType.TRIAL);
assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrices().length, 1);
assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrices()[0].getCurrency(), Currency.EUR);
assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrices()[0].getValue(), BigDecimal.ZERO);
assertEquals(plan.getInitialPhases()[0].getName(), "foo-monthly-trial");
assertEquals(plan.getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
assertNull(plan.getFinalPhase().getFixed());
assertEquals(plan.getFinalPhase().getName(), "foo-monthly-evergreen");
assertEquals(plan.getFinalPhase().getRecurring().getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices().length, 1);
assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getValue(), BigDecimal.TEN);
assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getCurrency(), Currency.EUR);
assertEquals(catalog.getPriceLists().getAllPriceLists().size(), 1);
final PriceList priceList = catalog.getPriceLists().getAllPriceLists().get(0);
assertEquals(priceList.getName(), new PriceListDefault().getName());
assertEquals(priceList.getPlans().size(), 1);
assertEquals(priceList.getPlans().iterator().next().getName(), "foo-monthly");
}
use of org.killbill.billing.catalog.api.Product in project killbill by killbill.
the class TestEhCacheCatalogCache method testDefaultCatalog.
//
// Verify CatalogCache returns default catalog when system property has been set (and CatalogCache has been initialized)
//
@Test(groups = "fast")
public void testDefaultCatalog() throws CatalogApiException {
catalogCache.loadDefaultCatalog(Resources.getResource("SpyCarBasic.xml").toExternalForm());
final VersionedCatalog result = catalogCache.getCatalog(true, true, internalCallContext);
Assert.assertNotNull(result);
final Collection<Product> products = result.getProducts(clock.getUTCNow());
Assert.assertEquals(products.size(), 3);
// Verify the lookup with other contexts
final VersionedCatalog resultForMultiTenantContext = new VersionedCatalog(result.getClock());
for (final StandaloneCatalog cur : result.getVersions()) {
resultForMultiTenantContext.add(new StandaloneCatalogWithPriceOverride(cur, priceOverride, multiTenantContext.getTenantRecordId(), internalCallContextFactory));
}
Assert.assertEquals(catalogCache.getCatalog(true, true, multiTenantContext).getCatalogName(), resultForMultiTenantContext.getCatalogName());
Assert.assertEquals(catalogCache.getCatalog(true, true, multiTenantContext).getVersions().size(), resultForMultiTenantContext.getVersions().size());
for (int i = 0; i < catalogCache.getCatalog(true, true, multiTenantContext).getVersions().size(); i++) {
Assert.assertEquals(((StandaloneCatalogWithPriceOverride) catalogCache.getCatalog(true, true, multiTenantContext).getVersions().get(i)).getTenantRecordId(), ((StandaloneCatalogWithPriceOverride) resultForMultiTenantContext.getVersions().get(i)).getTenantRecordId());
}
}
Aggregations