use of org.killbill.billing.catalog.api.Product in project killbill by killbill.
the class TestTransfer method testTransferWithAO.
@Test(groups = "slow")
public void testTransferWithAO() throws Exception {
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
final SubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
// MOVE 3 DAYS AND CREATE AO1
clock.addDays(3);
final String aoProduct1 = "Telescopic-Scope";
final BillingPeriod aoTerm1 = BillingPeriod.MONTHLY;
final DefaultSubscriptionBase aoSubscription1 = testUtil.createSubscription(bundle, aoProduct1, aoTerm1, basePriceList);
assertEquals(aoSubscription1.getState(), EntitlementState.ACTIVE);
// MOVE ANOTHER 25 DAYS AND CREATE AO2 [ BP STILL IN TRIAL]
// LASER-SCOPE IS SUBSCRIPTION ALIGN SO EVERGREN WILL ONLY START IN A MONTH
clock.addDays(25);
final String aoProduct2 = "Laser-Scope";
final BillingPeriod aoTerm2 = BillingPeriod.MONTHLY;
final DefaultSubscriptionBase aoSubscription2 = testUtil.createSubscription(bundle, aoProduct2, aoTerm2, basePriceList);
assertEquals(aoSubscription2.getState(), EntitlementState.ACTIVE);
// MOVE AFTER TRIAL AND AO DISCOUNT PHASE [LASER SCOPE STILL IN DISCOUNT]
testListener.pushExpectedEvent(NextEvent.PHASE);
testListener.pushExpectedEvent(NextEvent.PHASE);
clock.addDays(5);
assertListenerStatus();
// SET CTD TO TRIGGER CANCELLATION EOT
final DateTime ctd = baseSubscription.getStartDate().plusDays(30).plusMonths(1);
subscriptionInternalApi.setChargedThroughDate(baseSubscription.getId(), ctd, internalCallContext);
final DateTime transferRequestedDate = clock.getUTCNow();
testListener.pushExpectedEvent(NextEvent.TRANSFER);
testListener.pushExpectedEvent(NextEvent.TRANSFER);
testListener.pushExpectedEvent(NextEvent.TRANSFER);
transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, true, false, callContext);
assertListenerStatus();
// RETRIEVE NEW BUNDLE AND CHECK SUBSCRIPTIONS
final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext);
assertEquals(bundlesForAccountAndKey.size(), 1);
final SubscriptionBaseBundle newBundle = bundlesForAccountAndKey.get(0);
final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(newBundle.getId(), null, internalCallContext);
assertEquals(subscriptions.size(), 3);
boolean foundBP = false;
boolean foundAO1 = false;
boolean foundAO2 = false;
for (final SubscriptionBase cur : subscriptions) {
final Plan curPlan = cur.getCurrentPlan();
final Product curProduct = curPlan.getProduct();
if (curProduct.getName().equals(baseProduct)) {
foundBP = true;
assertTrue(((DefaultSubscriptionBase) cur).getAlignStartDate().compareTo(((DefaultSubscriptionBase) baseSubscription).getAlignStartDate()) == 0);
assertNull(cur.getPendingTransition());
} else if (curProduct.getName().equals(aoProduct1)) {
foundAO1 = true;
assertTrue(((DefaultSubscriptionBase) cur).getAlignStartDate().compareTo((aoSubscription1).getAlignStartDate()) == 0);
assertNull(cur.getPendingTransition());
} else if (curProduct.getName().equals(aoProduct2)) {
foundAO2 = true;
assertTrue(((DefaultSubscriptionBase) cur).getAlignStartDate().compareTo((aoSubscription2).getAlignStartDate()) == 0);
assertNotNull(cur.getPendingTransition());
} else {
Assert.fail("Unexpected product " + curProduct.getName());
}
}
assertTrue(foundBP);
assertTrue(foundAO1);
assertTrue(foundAO2);
// MOVE AFTER CANCEL DATE TO TRIGGER OLD SUBSCRIPTIONS CANCELLATION + LASER_SCOPE PHASE EVENT
testListener.pushExpectedEvents(NextEvent.PHASE, NextEvent.PHASE);
testListener.pushExpectedEvent(NextEvent.CANCEL);
testListener.pushExpectedEvent(NextEvent.CANCEL);
testListener.pushExpectedEvent(NextEvent.CANCEL);
clock.addMonths(1);
assertListenerStatus();
// ISSUE ANOTHER TRANSFER TO CHECK THAT WE CAN TRANSFER AGAIN-- NOTE WILL NOT WORK ON PREVIOUS ACCOUNT (LIMITATION)
final DateTime newTransferRequestedDate = clock.getUTCNow();
testListener.pushExpectedEvent(NextEvent.CANCEL);
testListener.pushExpectedEvent(NextEvent.TRANSFER);
testListener.pushExpectedEvent(NextEvent.TRANSFER);
testListener.pushExpectedEvent(NextEvent.TRANSFER);
transferApi.transferBundle(newBundle.getAccountId(), finalNewAccountId, newBundle.getExternalKey(), newTransferRequestedDate, true, false, callContext);
assertListenerStatus();
}
use of org.killbill.billing.catalog.api.Product in project killbill by killbill.
the class AddonUtils method isAddonIncludedFromPlanName.
public boolean isAddonIncludedFromPlanName(final String basePlanName, final Plan targetAddOnPlan, final DateTime requestedDate, final InternalTenantContext context) {
try {
final Plan plan = catalogService.getFullCatalog(true, true, context).findPlan(basePlanName, requestedDate);
final Product product = plan.getProduct();
return isAddonIncluded(product, targetAddOnPlan);
} catch (CatalogApiException e) {
throw new SubscriptionBaseError(e);
}
}
use of org.killbill.billing.catalog.api.Product in project killbill by killbill.
the class AddonUtils method isAddonIncluded.
private boolean isAddonIncluded(final Product baseProduct, final Plan targetAddOnPlan) {
final Product targetAddonProduct = targetAddOnPlan.getProduct();
final Collection<Product> includedAddOns = baseProduct.getIncluded();
for (final Product curAv : includedAddOns) {
if (curAv.getName().equals(targetAddonProduct.getName())) {
return true;
}
}
return false;
}
use of org.killbill.billing.catalog.api.Product in project killbill by killbill.
the class StandaloneCatalogMapper method toStandaloneCatalog.
public StandaloneCatalog toStandaloneCatalog(final StandalonePluginCatalog pluginCatalog, @Nullable URI catalogURI) {
final StandaloneCatalog result = new StandaloneCatalog();
result.setCatalogName(catalogName);
result.setEffectiveDate(pluginCatalog.getEffectiveDate().toDate());
result.setProducts(toDefaultProducts(pluginCatalog.getProducts()));
result.setPlans(toDefaultPlans(pluginCatalog.getPlans()));
result.setPriceLists(toDefaultPriceListSet(pluginCatalog.getDefaultPriceList(), pluginCatalog.getChildrenPriceList()));
result.setRecurringBillingMode(recurringBillingMode);
result.setSupportedCurrencies(toArray(pluginCatalog.getCurrencies()));
result.setUnits(toDefaultUnits(pluginCatalog.getUnits()));
result.setPlanRules(toDefaultPlanRules(pluginCatalog.getPlanRules()));
for (final Product cur : pluginCatalog.getProducts()) {
final Product target = result.getCatalogEntityCollectionProduct().findByName(cur.getName());
if (target != null) {
((DefaultProduct) target).setAvailable(toFilteredDefaultProduct(cur.getAvailable()));
((DefaultProduct) target).setIncluded(toFilteredDefaultProduct(cur.getIncluded()));
}
}
result.initialize(result, catalogURI);
return result;
}
use of org.killbill.billing.catalog.api.Product in project killbill by killbill.
the class StandaloneCatalogMapper method toDefaultProducts.
private Iterable<Product> toDefaultProducts(final Iterable<Product> input) {
if (tmpDefaultProducts == null) {
final Map<String, Product> map = new HashMap<String, Product>();
for (final Product product : input) map.put(product.getName(), toDefaultProduct(product));
tmpDefaultProducts = map;
}
return tmpDefaultProducts.values();
}
Aggregations