@Test(groups = "fast") public void testPriceInitialization() throws URISyntaxException, CatalogApiException { final StandaloneCatalog c = new MockCatalog(); c.setSupportedCurrencies(new Currency[]{Currency.GBP, Currency.EUR, Currency.USD, Currency.BRL, Currency.MXN}); ((DefaultInternationalPrice) c.getCurrentPlans().iterator().next().getFinalPhase().getRecurring().getRecurringPrice()).setPrices(new DefaultPrice[0]); c.setUnits(new DefaultUnit[0]); c.initialize(c); Assert.assertEquals(c.getCurrentPlans().iterator().next().getFinalPhase().getRecurring().getRecurringPrice().getPrice(Currency.GBP), new BigDecimal(0)); }
@Override public DateTime dateOfFirstRecurringNonZeroCharge(final DateTime subscriptionStartDate, final PhaseType initialPhaseType) { DateTime result = subscriptionStartDate; boolean skipPhase = initialPhaseType != null; for (final PlanPhase phase : getAllPhases()) { if (skipPhase) { if (phase.getPhaseType() != initialPhaseType) { continue; } else { skipPhase = false; } } final Recurring recurring = phase.getRecurring(); if (phase.getDuration().getUnit() != TimeUnit.UNLIMITED && (recurring == null || recurring.getRecurringPrice() == null || recurring.getRecurringPrice().isZero())) { try { result = phase.getDuration().addToDateTime(result); } catch (final CatalogApiException ignored) { } } else { break; } } return result; }
private DefaultInternationalPrice toDefaultInternationalPrice(final InternationalPrice input) { DefaultInternationalPrice result = null; if (input != null) { result = new DefaultInternationalPrice(); result.setPrices(toDefaultPrices(ImmutableList.copyOf(input.getPrices()))); } return result; }
(plan.getInitialPhases()[0].getPhaseType() != PhaseType.TRIAL || !plan.getInitialPhases()[0].getFixed().getPrice().isZero()))) { failedValidation = true; } else if (desc.getCurrency() != null && desc.getAmount() != null) { try { final BigDecimal currentAmount = plan.getFinalPhase().getRecurring().getRecurringPrice().getPrice(desc.getCurrency()); if (currentAmount.compareTo(desc.getAmount()) != 0) { failedValidation = true;
private void assertTieredBlockInternationalPrice(final InternationalPrice newInternationalPrice, final InternationalPrice initInternationalPrice, final TieredBlockPriceOverride override) throws CurrencyValueNull { assertEquals(newInternationalPrice.getPrices().length, initInternationalPrice.getPrices().length); for (int i = 0; i < newInternationalPrice.getPrices().length; i++) { final Price initPrice = initInternationalPrice.getPrices()[i]; final Price newPrice = newInternationalPrice.getPrices()[i]; if (override != null && override.getCurrency() == initPrice.getCurrency() && override.getPrice() != null) { assertEquals(newPrice.getValue().compareTo(override.getPrice()), 0); } else { if (initPrice != null && initPrice.getValue() != null) { assertEquals(newPrice.getValue().compareTo(initPrice.getValue()), 0); } } } } }
(plan.getInitialPhases()[0].getPhaseType() != PhaseType.TRIAL || !plan.getInitialPhases()[0].getFixed().getPrice().isZero()))) { failedValidation = true; } else if (desc.getCurrency() != null && desc.getAmount() != null) { try { final BigDecimal currentAmount = plan.getFinalPhase().getRecurring().getRecurringPrice().getPrice(desc.getCurrency()); if (currentAmount.compareTo(desc.getAmount()) != 0) { failedValidation = true;
final Plan newSubPlan3 = vc.findPlan("pistol-monthly", dt3, dt3); Assert.assertEquals(newSubPlan1.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("29.95")); Assert.assertEquals(newSubPlan2.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95")); Assert.assertEquals(newSubPlan214.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95")); Assert.assertEquals(newSubPlan3.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("49.95")); final Plan exSubPlan7 = vc.findPlan("shotgun-quarterly", dt214, dt214); Assert.assertEquals(exSubPlan2.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("29.95")); Assert.assertEquals(exSubPlan214.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95")); Assert.assertEquals(exSubPlan3.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95")); Assert.assertEquals(exSubPlan4.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("249.95")); Assert.assertEquals(exSubPlan5.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("249.95")); Assert.assertEquals(exSubPlan6.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("259.95")); Assert.assertEquals(exSubPlan7.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("259.95"));
private void assertInternationalPrice(final InternationalPrice newInternationalPrice, final InternationalPrice initInternationalPrice, final PlanPhasePriceOverride override, final boolean isFixed) throws CatalogApiException { if (initInternationalPrice.getPrices().length == 0) { if (override != null) { assertEquals(newInternationalPrice.getPrices().length, 1); assertEquals(newInternationalPrice.getPrice(override.getCurrency()).compareTo(isFixed ? override.getFixedPrice() : override.getRecurringPrice()), 0); } } else { assertEquals(newInternationalPrice.getPrices().length, initInternationalPrice.getPrices().length); for (int i = 0; i < newInternationalPrice.getPrices().length; i++) { final Price initPrice = initInternationalPrice.getPrices()[i]; final Price newPrice = newInternationalPrice.getPrices()[i]; if (override != null && override.getCurrency() == initPrice.getCurrency() && ((isFixed && override.getFixedPrice() != null) || (!isFixed && override.getRecurringPrice() != null))) { assertEquals(newPrice.getValue().compareTo(isFixed ? override.getFixedPrice() : override.getRecurringPrice()), 0); } else { if (initPrice != null && initPrice.getValue() != null) { assertEquals(newPrice.getValue().compareTo(initPrice.getValue()), 0); } } } } }
@Test(groups = "fast") public void testUsageCapacityInAdvance() { try { final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("UsageExperimental.xml").toExternalForm(), StandaloneCatalog.class); final Usage[] usages = getUsages(catalog, "capacity-in-advance-monthly"); assertEquals(usages.length, 1); final Usage usage = usages[0]; assertEquals(usage.getName(), "capacity-in-advance-monthly-usage1"); assertEquals(usage.getBillingPeriod(), BillingPeriod.MONTHLY); assertEquals(usage.getUsageType(), UsageType.CAPACITY); assertEquals(usage.getBillingMode(), BillingMode.IN_ADVANCE); assertEquals(usage.getTierBlockPolicy(), TierBlockPolicy.ALL_TIERS); assertEquals(usage.getBlocks().length, 0); assertEquals(usage.getTiers().length, 0); assertEquals(usage.getLimits().length, 1); assertEquals(usage.getLimits()[0].getUnit().getName(), "members"); assertEquals(usage.getLimits()[0].getMax(), new Double("100")); assertEquals(usage.getRecurringPrice().getPrices().length, 1); assertEquals(usage.getRecurringPrice().getPrices()[0].getCurrency(), Currency.BTC); assertEquals(usage.getRecurringPrice().getPrices()[0].getValue(), new BigDecimal("100.00")); } catch (Exception e) { Assert.fail(e.toString()); } }
@Override public DateTime dateOfFirstRecurringNonZeroCharge(final DateTime subscriptionStartDate, final PhaseType initialPhaseType) { DateTime result = subscriptionStartDate; boolean skipPhase = initialPhaseType != null; for (final PlanPhase phase : getAllPhases()) { if (skipPhase) { if (phase.getPhaseType() != initialPhaseType) { continue; } else { skipPhase = false; } } final Recurring recurring = phase.getRecurring(); if (phase.getDuration().getUnit() != TimeUnit.UNLIMITED && (recurring == null || recurring.getRecurringPrice() == null || recurring.getRecurringPrice().isZero())) { try { result = phase.getDuration().addToDateTime(result); } catch (final CatalogApiException ignored) { } } else { break; } } return result; }
final Plan newSubPlan3 = vc.createOrFindPlan(pistolMonthly, null, dt3, dt3); Assert.assertEquals(newSubPlan1.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("29.95")); Assert.assertEquals(newSubPlan2.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95")); Assert.assertEquals(newSubPlan214.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95")); Assert.assertEquals(newSubPlan3.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("49.95")); final Plan exSubPlan7 = vc.createOrFindPlan(shotgunQuarterly, null, dt214, dt214); Assert.assertEquals(exSubPlan2.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("29.95")); Assert.assertEquals(exSubPlan214.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95")); Assert.assertEquals(exSubPlan3.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95")); Assert.assertEquals(exSubPlan4.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("249.95")); Assert.assertEquals(exSubPlan5.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("249.95")); Assert.assertEquals(exSubPlan6.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("259.95")); Assert.assertEquals(exSubPlan7.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("259.95"));
@Test(groups = "fast") public void testAddExistingPlanWithNewCurrency() throws Exception { final StandaloneCatalog originalCatalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarBasic.xml").toExternalForm(), StandaloneCatalog.class); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().size(), 1); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getName(), new PriceListDefault().getName()); assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().size(), 3); final CatalogUpdater catalogUpdater = new CatalogUpdater(originalCatalog); final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.DAYS, ImmutableList.<String>of()); catalogUpdater.addSimplePlanDescriptor(desc); final StandaloneCatalog catalog = catalogUpdater.getCatalog(); final Plan plan = catalog.findCurrentPlan("standard-monthly"); assertEquals(plan.getName(), "standard-monthly"); assertEquals(plan.getInitialPhases().length, 1); assertEquals(plan.getInitialPhases()[0].getPhaseType(), PhaseType.TRIAL); assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrices().length, 0); assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrice(Currency.EUR), BigDecimal.ZERO); assertEquals(plan.getInitialPhases()[0].getName(), "standard-monthly-trial"); assertEquals(plan.getFinalPhase().getPhaseType(), PhaseType.EVERGREEN); assertNull(plan.getFinalPhase().getFixed()); assertEquals(plan.getFinalPhase().getName(), "standard-monthly-evergreen"); assertEquals(plan.getFinalPhase().getRecurring().getBillingPeriod(), BillingPeriod.MONTHLY); assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices().length, 3); assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrice(Currency.EUR), BigDecimal.TEN); }
@Test(groups = "fast") public void testUsageConsumableInAdvancePrepayCredit() { try { final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("UsageExperimental.xml").toExternalForm(), StandaloneCatalog.class); final Usage[] usages = getUsages(catalog, "consumable-in-advance-prepay-credit-monthly"); assertEquals(usages.length, 1); final Usage usage = usages[0]; assertEquals(usage.getName(), "consumable-in-advance-prepay-credit-monthly-usage1"); assertEquals(usage.getBillingPeriod(), BillingPeriod.MONTHLY); assertEquals(usage.getUsageType(), UsageType.CONSUMABLE); assertEquals(usage.getBillingMode(), BillingMode.IN_ADVANCE); assertEquals(usage.getLimits().length, 0); assertEquals(usage.getTiers().length, 0); assertEquals(usage.getBlocks().length, 1); assertEquals(usage.getBlocks()[0].getUnit().getName(), "cell-phone-minutes"); assertEquals(usage.getBlocks()[0].getSize(), new Double("1000")); assertEquals(usage.getBlocks()[0].getPrice().getPrices().length, 1); assertEquals(usage.getBlocks()[0].getPrice().getPrices()[0].getCurrency(), Currency.BTC); assertEquals(usage.getBlocks()[0].getPrice().getPrices()[0].getValue(), new BigDecimal("0.10")); } catch (Exception e) { Assert.fail(e.toString()); } }
UsageConsumableInArrearTierUnitAggregate computeToBeBilledConsumableInArrearWith_TOP_TIER(final List<TieredBlock> tieredBlocks, final List<UsageConsumableInArrearTierUnitAggregate> previousUsage, final Long units) throws CatalogApiException { int remainingUnits = units.intValue(); // By default last last tierBlock TieredBlock targetBlock = tieredBlocks.get(tieredBlocks.size() - 1); int targetTierNum = tieredBlocks.size(); int tierNum = 0; // Loop through all tier block for (final TieredBlock tieredBlock : tieredBlocks) { tierNum++; final int blockTierSize = tieredBlock.getSize().intValue(); final int tmp = remainingUnits / blockTierSize + (remainingUnits % blockTierSize == 0 ? 0 : 1); if ( tmp > tieredBlock.getMax()) { /* Includes the case where max is unlimited (-1) */ remainingUnits -= tieredBlock.getMax() * blockTierSize; } else { targetBlock = tieredBlock; targetTierNum = tierNum; break; } } final int lastBlockTierSize = targetBlock.getSize().intValue(); final int nbBlocks = units.intValue() / lastBlockTierSize + (units.intValue() % lastBlockTierSize == 0 ? 0 : 1); return new UsageConsumableInArrearTierUnitAggregate(targetTierNum, targetBlock.getUnit().getName(), targetBlock.getPrice().getPrice(getCurrency()), targetBlock.getSize().intValue(), nbBlocks); }
@Test(groups = "fast") public void testUsageConsumableInAdvanceTopUp() { try { final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("UsageExperimental.xml").toExternalForm(), StandaloneCatalog.class); final Usage[] usages = getUsages(catalog, "consumable-in-advance-topup"); assertEquals(usages.length, 1); final Usage usage = usages[0]; assertEquals(usage.getName(), "consumable-in-advance-topup-usage1"); assertEquals(usage.getBillingPeriod(), BillingPeriod.NO_BILLING_PERIOD); assertEquals(usage.getUsageType(), UsageType.CONSUMABLE); assertEquals(usage.getBillingMode(), BillingMode.IN_ADVANCE); assertEquals(usage.getLimits().length, 0); assertEquals(usage.getTiers().length, 0); assertEquals(usage.getBlocks().length, 1); assertEquals(usage.getBlocks()[0].getUnit().getName(), "fastrack-tokens"); assertEquals(usage.getBlocks()[0].getSize(), new Double("10")); assertEquals(usage.getBlocks()[0].getPrice().getPrices().length, 1); assertEquals(usage.getBlocks()[0].getPrice().getPrices()[0].getCurrency(), Currency.BTC); assertEquals(usage.getBlocks()[0].getPrice().getPrices()[0].getValue(), new BigDecimal("0.10")); assertEquals(usage.getBlocks()[0].getMinTopUpCredit(), new Double("5")); } catch (Exception e) { Assert.fail(e.toString()); } }
private BigDecimal getRecurringPrice(@Nullable final PlanPhase nextPhase, final Currency currency) throws CatalogApiException { return (nextPhase != null && nextPhase.getRecurring() != null && nextPhase.getRecurring().getRecurringPrice() != null) ? nextPhase.getRecurring().getRecurringPrice().getPrice(currency) : null; }
private void assertInternationalPrice(final InternationalPrice newInternationalPrice, final InternationalPrice initInternationalPrice, final PlanPhasePriceOverride override, final boolean isFixed) throws CatalogApiException { if (initInternationalPrice.getPrices().length == 0) { if (override != null) { assertEquals(newInternationalPrice.getPrices().length, 1); assertEquals(newInternationalPrice.getPrice(override.getCurrency()).compareTo(isFixed ? override.getFixedPrice() : override.getRecurringPrice()), 0); } } else { assertEquals(newInternationalPrice.getPrices().length, initInternationalPrice.getPrices().length); for (int i = 0; i < newInternationalPrice.getPrices().length; i++) { final Price initPrice = initInternationalPrice.getPrices()[i]; final Price newPrice = newInternationalPrice.getPrices()[i]; if (override != null && override.getCurrency() == initPrice.getCurrency() && ((isFixed && override.getFixedPrice() != null) || (!isFixed && override.getRecurringPrice() != null))) { assertEquals(newPrice.getValue().compareTo(isFixed ? override.getFixedPrice() : override.getRecurringPrice()), 0); } else { if (initPrice != null && initPrice.getValue() != null) { assertEquals(newPrice.getValue().compareTo(initPrice.getValue()), 0); } } } } }
assertEquals(usage.getTiers()[0].getLimits()[1].getUnit().getName(), "members"); assertEquals(usage.getTiers()[0].getLimits()[1].getMax(), new Double("500")); assertEquals(usage.getTiers()[0].getFixedPrice().getPrices().length, 1); assertEquals(usage.getTiers()[0].getFixedPrice().getPrices()[0].getCurrency(), Currency.BTC); assertEquals(usage.getTiers()[0].getFixedPrice().getPrices()[0].getValue(), new BigDecimal("0.007")); assertEquals(usage.getTiers()[0].getRecurringPrice().getPrices().length, 1); assertEquals(usage.getTiers()[0].getRecurringPrice().getPrices()[0].getCurrency(), Currency.BTC); assertEquals(usage.getTiers()[0].getRecurringPrice().getPrices()[0].getValue(), new BigDecimal("0.8")); assertEquals(usage.getTiers()[1].getLimits()[1].getUnit().getName(), "members"); assertEquals(usage.getTiers()[1].getLimits()[1].getMax(), new Double("1000")); assertEquals(usage.getTiers()[1].getFixedPrice().getPrices().length, 1); assertEquals(usage.getTiers()[1].getFixedPrice().getPrices()[0].getCurrency(), Currency.BTC); assertEquals(usage.getTiers()[1].getFixedPrice().getPrices()[0].getValue(), new BigDecimal("0.4")); assertEquals(usage.getTiers()[1].getRecurringPrice().getPrices().length, 1); assertEquals(usage.getTiers()[1].getRecurringPrice().getPrices()[0].getCurrency(), Currency.BTC); assertEquals(usage.getTiers()[1].getRecurringPrice().getPrices()[0].getValue(), new BigDecimal("1.2"));