Search in sources :

Example 1 with TieredBlockPriceOverride

use of org.killbill.billing.catalog.api.TieredBlockPriceOverride in project killbill by killbill.

the class TestDefaultPriceOverride method testOverrideOneOutOfTwoTieredBlockPrices.

@Test(groups = "slow")
public void testOverrideOneOutOfTwoTieredBlockPrices() throws Exception {
    final StandaloneCatalog catalog = getCatalog("UsageExperimental.xml");
    final Plan plan = catalog.findPlan("chocolate-monthly");
    final List<PlanPhasePriceOverride> overrides = new ArrayList<PlanPhasePriceOverride>();
    final List<TieredBlockPriceOverride> tieredBlockPriceOverrides = new ArrayList<TieredBlockPriceOverride>();
    tieredBlockPriceOverrides.add(new DefaultTieredBlockPriceOverride("chocolate-videos", new Double("1"), new BigDecimal("0.75"), Currency.USD, new Double("10000")));
    final List<TierPriceOverride> tierPriceOverrides = new ArrayList<TierPriceOverride>();
    tierPriceOverrides.add(new DefaultTierPriceOverride(tieredBlockPriceOverrides));
    final List<UsagePriceOverride> usagePriceOverrides = new ArrayList<UsagePriceOverride>();
    usagePriceOverrides.add(new DefaultUsagePriceOverride("chocolate-monthly-videos", UsageType.CONSUMABLE, tierPriceOverrides));
    final PlanPhasePriceOverride phase = new DefaultPlanPhasePriceOverride(plan.getFinalPhase().getName(), Currency.USD, null, null, usagePriceOverrides);
    overrides.add(phase);
    // Overriding only the tieredblockprice for unit - 'chocolate-videos' with size = 1 and max = 10000 from $1 to $0.75
    final DefaultPlan overriddenPlan = priceOverride.getOrCreateOverriddenPlan(catalog, plan, new DateTime(catalog.getEffectiveDate()), overrides, internalCallContext);
    final String[] parts = priceOverridePattern.getPlanParts(overriddenPlan.getName());
    assertEquals(parts[0], plan.getName());
    assertEquals(overriddenPlan.getProduct().getName(), plan.getProduct().getName());
    assertEquals(overriddenPlan.getRecurringBillingPeriod(), plan.getRecurringBillingPeriod());
    if (plan.getEffectiveDateForExistingSubscriptions() != null) {
        assertEquals(overriddenPlan.getEffectiveDateForExistingSubscriptions().compareTo(plan.getEffectiveDateForExistingSubscriptions()), 0);
    }
    assertNotEquals(overriddenPlan.getFinalPhase().getName(), plan.getFinalPhase().getName());
    for (int i = 0; i < overriddenPlan.getFinalPhase().getUsages().length; i++) {
        final DefaultUsage initialUsage = (DefaultUsage) plan.getFinalPhase().getUsages()[i];
        final DefaultUsage newUsage = (DefaultUsage) overriddenPlan.getFinalPhase().getUsages()[i];
        assertEquals(newUsage.getName(), initialUsage.getName());
        assertEquals(newUsage.getUsageType(), initialUsage.getUsageType());
        assertEquals(newUsage.getBillingPeriod(), initialUsage.getBillingPeriod());
        assertEquals(newUsage.getBillingPeriod(), initialUsage.getBillingPeriod());
        assertEquals(newUsage.getTiers().length, initialUsage.getTiers().length);
        for (int j = 0; j < newUsage.getTiers().length; j++) {
            final DefaultTier initialTier = (DefaultTier) initialUsage.getTiers()[j];
            final DefaultTier newTier = (DefaultTier) newUsage.getTiers()[j];
            assertEquals(newTier.getTieredBlocks().length, initialTier.getTieredBlocks().length);
            for (int k = 0; k < newTier.getTieredBlocks().length; k++) {
                final DefaultTieredBlock initialTieredBlock = (DefaultTieredBlock) initialTier.getTieredBlocks()[k];
                final DefaultTieredBlock newTieredBlock = (DefaultTieredBlock) newTier.getTieredBlocks()[k];
                final TieredBlockPriceOverride override = Iterables.tryFind(tieredBlockPriceOverrides, new Predicate<TieredBlockPriceOverride>() {

                    @Override
                    public boolean apply(final TieredBlockPriceOverride input) {
                        return input.getUnitName().equals(initialTieredBlock.getUnit().getName()) && Double.compare(input.getSize(), initialTieredBlock.getSize()) == 0 && Double.compare(input.getMax(), initialTieredBlock.getMax()) == 0;
                    }
                }).orNull();
                assertEquals(newTieredBlock.getUnit().getName(), initialTieredBlock.getUnit().getName());
                assertEquals(newTieredBlock.getMax(), initialTieredBlock.getMax());
                assertEquals(newTieredBlock.getSize(), initialTieredBlock.getSize());
                assertTieredBlockInternationalPrice(newTieredBlock.getPrice(), initialTieredBlock.getPrice(), override);
            }
        }
    }
}
Also used : TieredBlockPriceOverride(org.killbill.billing.catalog.api.TieredBlockPriceOverride) ArrayList(java.util.ArrayList) TierPriceOverride(org.killbill.billing.catalog.api.TierPriceOverride) UsagePriceOverride(org.killbill.billing.catalog.api.UsagePriceOverride) DateTime(org.joda.time.DateTime) Predicate(com.google.common.base.Predicate) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) Plan(org.killbill.billing.catalog.api.Plan) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 2 with TieredBlockPriceOverride

use of org.killbill.billing.catalog.api.TieredBlockPriceOverride in project killbill by killbill.

the class TestDefaultPriceOverride method testOverrideTwoOutOfTwoTieredBlockPrices.

@Test(groups = "slow")
public void testOverrideTwoOutOfTwoTieredBlockPrices() throws Exception {
    final StandaloneCatalog catalog = getCatalog("UsageExperimental.xml");
    final Plan plan = catalog.findPlan("chocolate-monthly");
    final List<PlanPhasePriceOverride> overrides = new ArrayList<PlanPhasePriceOverride>();
    final List<TieredBlockPriceOverride> tieredBlockPriceOverrides1 = new ArrayList<TieredBlockPriceOverride>();
    tieredBlockPriceOverrides1.add(new DefaultTieredBlockPriceOverride("chocolate-videos", new Double("1"), new BigDecimal("1.5"), Currency.USD, new Double("5")));
    final List<TieredBlockPriceOverride> tieredBlockPriceOverrides2 = new ArrayList<TieredBlockPriceOverride>();
    tieredBlockPriceOverrides2.add(new DefaultTieredBlockPriceOverride("chocolate-videos", new Double("1"), new BigDecimal("0.75"), Currency.USD, new Double("10000")));
    final List<TierPriceOverride> tierPriceOverrides = new ArrayList<TierPriceOverride>();
    tierPriceOverrides.add(new DefaultTierPriceOverride(tieredBlockPriceOverrides1));
    tierPriceOverrides.add(new DefaultTierPriceOverride(tieredBlockPriceOverrides2));
    final List<UsagePriceOverride> usagePriceOverrides = new ArrayList<UsagePriceOverride>();
    usagePriceOverrides.add(new DefaultUsagePriceOverride("chocolate-monthly-videos", UsageType.CONSUMABLE, tierPriceOverrides));
    final PlanPhasePriceOverride phase = new DefaultPlanPhasePriceOverride(plan.getFinalPhase().getName(), Currency.USD, null, new BigDecimal("35"), usagePriceOverrides);
    overrides.add(phase);
    /* Overriding phase recurring price from $30 to $35, tieredblockprice from $2 to $1.5 for unit- 'chocolate-videos' with size = 1 and max = 5 and
         also overriding tieredblockprice from $1 to $0.75 for unit - 'chocolate-videos' with size = 1 and max = 10000 */
    final DefaultPlan overriddenPlan = priceOverride.getOrCreateOverriddenPlan(catalog, plan, new DateTime(catalog.getEffectiveDate()), overrides, internalCallContext);
    final String[] parts = priceOverridePattern.getPlanParts(overriddenPlan.getName());
    assertEquals(parts[0], plan.getName());
    assertEquals(overriddenPlan.getProduct().getName(), plan.getProduct().getName());
    assertEquals(overriddenPlan.getRecurringBillingPeriod(), plan.getRecurringBillingPeriod());
    if (plan.getEffectiveDateForExistingSubscriptions() != null) {
        assertEquals(overriddenPlan.getEffectiveDateForExistingSubscriptions().compareTo(plan.getEffectiveDateForExistingSubscriptions()), 0);
    }
    assertNotEquals(overriddenPlan.getFinalPhase().getName(), plan.getFinalPhase().getName());
    final DefaultPlanPhase initialPhase = (DefaultPlanPhase) plan.getFinalPhase();
    final DefaultPlanPhase newPhase = (DefaultPlanPhase) overriddenPlan.getFinalPhase();
    final PlanPhasePriceOverride override = Iterables.tryFind(overrides, new Predicate<PlanPhasePriceOverride>() {

        @Override
        public boolean apply(final PlanPhasePriceOverride input) {
            return input.getPhaseName().equals(initialPhase.getName());
        }
    }).orNull();
    assertNotEquals(newPhase.getName(), initialPhase.getName());
    assertEquals(newPhase.getName(), overriddenPlan.getName() + "-" + initialPhase.getName().split("-")[initialPhase.getName().split("-").length - 1]);
    assertEquals(newPhase.getDuration(), initialPhase.getDuration());
    assertEquals(newPhase.getPhaseType(), initialPhase.getPhaseType());
    assertEquals(newPhase.getUsages().length, initialPhase.getUsages().length);
    if (initialPhase.getFixed() != null) {
        assertEquals(newPhase.getFixed().getType(), initialPhase.getFixed().getType());
        assertInternationalPrice(newPhase.getFixed().getPrice(), initialPhase.getFixed().getPrice(), override, true);
    }
    if (initialPhase.getRecurring() != null) {
        assertInternationalPrice(newPhase.getRecurring().getRecurringPrice(), initialPhase.getRecurring().getRecurringPrice(), override, false);
    }
    for (int i = 0; i < overriddenPlan.getFinalPhase().getUsages().length; i++) {
        final DefaultUsage initialUsage = (DefaultUsage) plan.getFinalPhase().getUsages()[i];
        final DefaultUsage newUsage = (DefaultUsage) overriddenPlan.getFinalPhase().getUsages()[i];
        assertEquals(newUsage.getName(), initialUsage.getName());
        assertEquals(newUsage.getUsageType(), initialUsage.getUsageType());
        assertEquals(newUsage.getBillingPeriod(), initialUsage.getBillingPeriod());
        assertEquals(newUsage.getBillingPeriod(), initialUsage.getBillingPeriod());
        assertEquals(newUsage.getTiers().length, initialUsage.getTiers().length);
        for (int j = 0; j < newUsage.getTiers().length; j++) {
            final DefaultTier initialTier = (DefaultTier) initialUsage.getTiers()[j];
            final DefaultTier newTier = (DefaultTier) newUsage.getTiers()[j];
            assertEquals(newTier.getTieredBlocks().length, initialTier.getTieredBlocks().length);
            for (int k = 0; k < newTier.getTieredBlocks().length; k++) {
                final DefaultTieredBlock initialTieredBlock = (DefaultTieredBlock) initialTier.getTieredBlocks()[k];
                final DefaultTieredBlock newTieredBlock = (DefaultTieredBlock) newTier.getTieredBlocks()[k];
                List<TieredBlockPriceOverride> tieredBlockPriceOverrides = new ArrayList<TieredBlockPriceOverride>();
                tieredBlockPriceOverrides.addAll(tieredBlockPriceOverrides1);
                tieredBlockPriceOverrides.addAll(tieredBlockPriceOverrides2);
                final TieredBlockPriceOverride tieredBlockPriceOverride = Iterables.tryFind(tieredBlockPriceOverrides, new Predicate<TieredBlockPriceOverride>() {

                    @Override
                    public boolean apply(final TieredBlockPriceOverride input) {
                        return input.getUnitName().equals(initialTieredBlock.getUnit().getName()) && Double.compare(input.getSize(), initialTieredBlock.getSize()) == 0 && Double.compare(input.getMax(), initialTieredBlock.getMax()) == 0;
                    }
                }).orNull();
                assertEquals(newTieredBlock.getUnit().getName(), initialTieredBlock.getUnit().getName());
                assertEquals(newTieredBlock.getMax(), initialTieredBlock.getMax());
                assertEquals(newTieredBlock.getSize(), initialTieredBlock.getSize());
                assertTieredBlockInternationalPrice(newTieredBlock.getPrice(), initialTieredBlock.getPrice(), tieredBlockPriceOverride);
            }
        }
    }
}
Also used : TieredBlockPriceOverride(org.killbill.billing.catalog.api.TieredBlockPriceOverride) ArrayList(java.util.ArrayList) TierPriceOverride(org.killbill.billing.catalog.api.TierPriceOverride) UsagePriceOverride(org.killbill.billing.catalog.api.UsagePriceOverride) DateTime(org.joda.time.DateTime) Predicate(com.google.common.base.Predicate) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) Plan(org.killbill.billing.catalog.api.Plan) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 3 with TieredBlockPriceOverride

use of org.killbill.billing.catalog.api.TieredBlockPriceOverride in project killbill by killbill.

the class DefaultOverriddenPlanCache method getTieredBlockPriceOverrides.

List<TieredBlockPriceOverride> getTieredBlockPriceOverrides(Tier curTier, CatalogOverrideTierDefinitionModelDao overriddenTier, final InternalTenantContext context) {
    final List<TieredBlockPriceOverride> blockPriceOverrides = new ArrayList<TieredBlockPriceOverride>();
    final List<CatalogOverrideBlockDefinitionModelDao> blockDefs = overrideDao.getOverriddenTierBlocks(overriddenTier.getRecordId(), context);
    for (int i = 0; i < curTier.getTieredBlocks().length; i++) {
        final TieredBlock curTieredBlock = curTier.getTieredBlocks()[i];
        final CatalogOverrideBlockDefinitionModelDao overriddenTierBlock = Iterables.tryFind(blockDefs, new Predicate<CatalogOverrideBlockDefinitionModelDao>() {

            @Override
            public boolean apply(final CatalogOverrideBlockDefinitionModelDao input) {
                return (input.getParentUnitName().equals(curTieredBlock.getUnit().getName()) && Double.compare(input.getSize(), curTieredBlock.getSize()) == 0 && Double.compare(input.getMax(), curTieredBlock.getMax()) == 0);
            }
        }).orNull();
        if (overriddenTierBlock != null) {
            blockPriceOverrides.add(new DefaultTieredBlockPriceOverride(overriddenTierBlock.getParentUnitName(), overriddenTierBlock.getSize(), overriddenTierBlock.getPrice(), Currency.valueOf(overriddenTierBlock.getCurrency()), overriddenTierBlock.getMax()));
        }
    }
    return blockPriceOverrides;
}
Also used : TieredBlockPriceOverride(org.killbill.billing.catalog.api.TieredBlockPriceOverride) DefaultTieredBlockPriceOverride(org.killbill.billing.catalog.DefaultTieredBlockPriceOverride) CatalogOverrideBlockDefinitionModelDao(org.killbill.billing.catalog.dao.CatalogOverrideBlockDefinitionModelDao) TieredBlock(org.killbill.billing.catalog.api.TieredBlock) ArrayList(java.util.ArrayList) DefaultTieredBlockPriceOverride(org.killbill.billing.catalog.DefaultTieredBlockPriceOverride) Predicate(com.google.common.base.Predicate)

Example 4 with TieredBlockPriceOverride

use of org.killbill.billing.catalog.api.TieredBlockPriceOverride in project killbill by killbill.

the class TestCatalogOverrideDao method testGetOverrideOneOutOfTwoTieredBlocks.

@Test(groups = "slow")
public void testGetOverrideOneOutOfTwoTieredBlocks() throws Exception {
    final StandaloneCatalog catalog = getCatalog("UsageExperimental.xml");
    final Plan plan = catalog.findPlan("chocolate-monthly");
    final PlanPhasePriceOverride[] resolvedOverrides = new PlanPhasePriceOverride[plan.getAllPhases().length];
    List<TieredBlockPriceOverride> tieredBlockPriceOverrides = new ArrayList<TieredBlockPriceOverride>();
    DefaultTieredBlockPriceOverride tieredBlockPriceOverride = new DefaultTieredBlockPriceOverride("chocolate-videos", new Double("1"), new BigDecimal(0.75), Currency.USD, new Double("10000"));
    tieredBlockPriceOverrides.add(tieredBlockPriceOverride);
    List<TierPriceOverride> tierPriceOverrides = new ArrayList<TierPriceOverride>();
    DefaultTierPriceOverride tierPriceOverride = new DefaultTierPriceOverride(tieredBlockPriceOverrides);
    tierPriceOverrides.add(null);
    tierPriceOverrides.add(tierPriceOverride);
    List<UsagePriceOverride> usagePriceOverrides = new ArrayList<UsagePriceOverride>();
    DefaultUsagePriceOverride usagePriceOverride = new DefaultUsagePriceOverride("chocolate-monthly-videos", UsageType.CONSUMABLE, tierPriceOverrides);
    usagePriceOverrides.add(usagePriceOverride);
    // Override chocolate-videos unit price with size = 1 and max value = 10000 from $1 to $0.75
    resolvedOverrides[0] = new DefaultPlanPhasePriceOverride(plan.getFinalPhase().getName(), Currency.USD, null, null, usagePriceOverrides);
    final CatalogOverridePlanDefinitionModelDao newPlan = catalogOverrideDao.getOrCreateOverridePlanDefinition(plan, new DateTime(catalog.getEffectiveDate()), resolvedOverrides, internalCallContext);
    final List<CatalogOverridePhaseDefinitionModelDao> phases = catalogOverrideDao.getOverriddenPlanPhases(newPlan.getRecordId(), internalCallContext);
    assertEquals(phases.size(), 1);
    final CatalogOverridePhaseDefinitionModelDao curPhase = phases.get(0);
    assertEquals(curPhase.getCurrency(), resolvedOverrides[0].getCurrency().name());
    Assert.assertNull(curPhase.getFixedPrice());
    Assert.assertNull(curPhase.getRecurringPrice());
    assertEquals(curPhase.getParentPhaseName(), resolvedOverrides[0].getPhaseName());
    final List<CatalogOverrideUsageDefinitionModelDao> usages = catalogOverrideDao.getOverriddenPhaseUsages(curPhase.getRecordId(), internalCallContext);
    assertEquals(usages.size(), 1);
    final CatalogOverrideUsageDefinitionModelDao curUsage = usages.get(0);
    assertEquals(curUsage.getParentUsageName(), usagePriceOverride.getName());
    assertEquals(curUsage.getType(), usagePriceOverride.getUsageType().toString());
    final List<CatalogOverrideTierDefinitionModelDao> tiers = catalogOverrideDao.getOverriddenUsageTiers(curUsage.getRecordId(), internalCallContext);
    assertEquals(tiers.size(), 1);
    final CatalogOverrideTierDefinitionModelDao curTier = tiers.get(0);
    final List<CatalogOverrideBlockDefinitionModelDao> tierBlocks = catalogOverrideDao.getOverriddenTierBlocks(curTier.getRecordId(), internalCallContext);
    assertEquals(tierBlocks.size(), 1);
    final CatalogOverrideBlockDefinitionModelDao curTieredBlock = tierBlocks.get(0);
    assertEquals(curTieredBlock.getParentUnitName(), tieredBlockPriceOverride.getUnitName());
    assertEquals(curTieredBlock.getPrice().compareTo(tieredBlockPriceOverride.getPrice()), 0);
    assertEquals(curTieredBlock.getSize(), (double) tieredBlockPriceOverride.getSize());
    assertEquals(curTieredBlock.getMax(), (double) tieredBlockPriceOverride.getMax());
}
Also used : DefaultTieredBlockPriceOverride(org.killbill.billing.catalog.DefaultTieredBlockPriceOverride) TieredBlockPriceOverride(org.killbill.billing.catalog.api.TieredBlockPriceOverride) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) ArrayList(java.util.ArrayList) TierPriceOverride(org.killbill.billing.catalog.api.TierPriceOverride) DefaultTierPriceOverride(org.killbill.billing.catalog.DefaultTierPriceOverride) UsagePriceOverride(org.killbill.billing.catalog.api.UsagePriceOverride) DefaultUsagePriceOverride(org.killbill.billing.catalog.DefaultUsagePriceOverride) DefaultTieredBlockPriceOverride(org.killbill.billing.catalog.DefaultTieredBlockPriceOverride) DateTime(org.joda.time.DateTime) DefaultTierPriceOverride(org.killbill.billing.catalog.DefaultTierPriceOverride) DefaultUsagePriceOverride(org.killbill.billing.catalog.DefaultUsagePriceOverride) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) Plan(org.killbill.billing.catalog.api.Plan) BigDecimal(java.math.BigDecimal) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) Test(org.testng.annotations.Test)

Example 5 with TieredBlockPriceOverride

use of org.killbill.billing.catalog.api.TieredBlockPriceOverride in project killbill by killbill.

the class TestCatalogOverrideDao method testGetOverriddenPlanPhasesWithUsageOverrides.

@Test(groups = "slow")
public void testGetOverriddenPlanPhasesWithUsageOverrides() throws Exception {
    final StandaloneCatalog catalog = getCatalog("SpyCarAdvanced.xml");
    final Plan plan = catalog.findPlan("gas-monthly");
    final PlanPhasePriceOverride[] resolvedOverrides = new PlanPhasePriceOverride[plan.getAllPhases().length];
    List<TieredBlockPriceOverride> tieredBlockPriceOverrides = new ArrayList<TieredBlockPriceOverride>();
    DefaultTieredBlockPriceOverride tieredBlockPriceOverride = new DefaultTieredBlockPriceOverride("gallons", new Double("1"), new BigDecimal(4), Currency.USD, new Double("100"));
    tieredBlockPriceOverrides.add(tieredBlockPriceOverride);
    List<TierPriceOverride> tierPriceOverrides = new ArrayList<TierPriceOverride>();
    DefaultTierPriceOverride tierPriceOverride = new DefaultTierPriceOverride(tieredBlockPriceOverrides);
    tierPriceOverrides.add(tierPriceOverride);
    List<UsagePriceOverride> usagePriceOverrides = new ArrayList<UsagePriceOverride>();
    DefaultUsagePriceOverride usagePriceOverride = new DefaultUsagePriceOverride("gas-monthly-in-arrear", UsageType.CONSUMABLE, tierPriceOverrides);
    usagePriceOverrides.add(usagePriceOverride);
    // Override the gallons price from $3.95 to $4 and also the recurring price from  $0 to $348.64
    resolvedOverrides[0] = new DefaultPlanPhasePriceOverride(plan.getFinalPhase().getName(), Currency.USD, BigDecimal.ZERO, new BigDecimal("348.64"), usagePriceOverrides);
    final CatalogOverridePlanDefinitionModelDao newPlan = catalogOverrideDao.getOrCreateOverridePlanDefinition(plan, new DateTime(catalog.getEffectiveDate()), resolvedOverrides, internalCallContext);
    final List<CatalogOverridePhaseDefinitionModelDao> phases = catalogOverrideDao.getOverriddenPlanPhases(newPlan.getRecordId(), internalCallContext);
    assertEquals(phases.size(), 1);
    final CatalogOverridePhaseDefinitionModelDao curPhase = phases.get(0);
    assertEquals(curPhase.getCurrency(), resolvedOverrides[0].getCurrency().name());
    assertEquals(curPhase.getFixedPrice().compareTo(resolvedOverrides[0].getFixedPrice()), 0);
    assertEquals(curPhase.getRecurringPrice().compareTo(resolvedOverrides[0].getRecurringPrice()), 0);
    assertEquals(curPhase.getParentPhaseName(), resolvedOverrides[0].getPhaseName());
    final List<CatalogOverrideUsageDefinitionModelDao> usages = catalogOverrideDao.getOverriddenPhaseUsages(curPhase.getRecordId(), internalCallContext);
    assertEquals(usages.size(), 1);
    final CatalogOverrideUsageDefinitionModelDao curUsage = usages.get(0);
    assertEquals(curUsage.getParentUsageName(), usagePriceOverride.getName());
    assertEquals(curUsage.getType(), usagePriceOverride.getUsageType().toString());
    final List<CatalogOverrideTierDefinitionModelDao> tiers = catalogOverrideDao.getOverriddenUsageTiers(curUsage.getRecordId(), internalCallContext);
    assertEquals(tiers.size(), 1);
    final CatalogOverrideTierDefinitionModelDao curTier = tiers.get(0);
    final List<CatalogOverrideBlockDefinitionModelDao> tierBlocks = catalogOverrideDao.getOverriddenTierBlocks(curTier.getRecordId(), internalCallContext);
    assertEquals(tierBlocks.size(), 1);
    final CatalogOverrideBlockDefinitionModelDao curTieredBlock = tierBlocks.get(0);
    assertEquals(curTieredBlock.getParentUnitName(), tieredBlockPriceOverride.getUnitName());
    assertEquals(curTieredBlock.getPrice().compareTo(tieredBlockPriceOverride.getPrice()), 0);
    assertEquals(curTieredBlock.getSize(), (double) tieredBlockPriceOverride.getSize());
    assertEquals(curTieredBlock.getMax(), (double) tieredBlockPriceOverride.getMax());
}
Also used : DefaultTieredBlockPriceOverride(org.killbill.billing.catalog.DefaultTieredBlockPriceOverride) TieredBlockPriceOverride(org.killbill.billing.catalog.api.TieredBlockPriceOverride) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) ArrayList(java.util.ArrayList) TierPriceOverride(org.killbill.billing.catalog.api.TierPriceOverride) DefaultTierPriceOverride(org.killbill.billing.catalog.DefaultTierPriceOverride) UsagePriceOverride(org.killbill.billing.catalog.api.UsagePriceOverride) DefaultUsagePriceOverride(org.killbill.billing.catalog.DefaultUsagePriceOverride) DefaultTieredBlockPriceOverride(org.killbill.billing.catalog.DefaultTieredBlockPriceOverride) DateTime(org.joda.time.DateTime) DefaultTierPriceOverride(org.killbill.billing.catalog.DefaultTierPriceOverride) DefaultUsagePriceOverride(org.killbill.billing.catalog.DefaultUsagePriceOverride) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) Plan(org.killbill.billing.catalog.api.Plan) BigDecimal(java.math.BigDecimal) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) Test(org.testng.annotations.Test)

Aggregations

TieredBlockPriceOverride (org.killbill.billing.catalog.api.TieredBlockPriceOverride)9 ArrayList (java.util.ArrayList)7 TierPriceOverride (org.killbill.billing.catalog.api.TierPriceOverride)7 Predicate (com.google.common.base.Predicate)5 BigDecimal (java.math.BigDecimal)5 DefaultTieredBlockPriceOverride (org.killbill.billing.catalog.DefaultTieredBlockPriceOverride)5 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)5 UsagePriceOverride (org.killbill.billing.catalog.api.UsagePriceOverride)5 DateTime (org.joda.time.DateTime)4 DefaultTierPriceOverride (org.killbill.billing.catalog.DefaultTierPriceOverride)4 Plan (org.killbill.billing.catalog.api.Plan)4 Test (org.testng.annotations.Test)4 TieredBlock (org.killbill.billing.catalog.api.TieredBlock)3 DefaultPlanPhasePriceOverride (org.killbill.billing.catalog.DefaultPlanPhasePriceOverride)2 DefaultUsagePriceOverride (org.killbill.billing.catalog.DefaultUsagePriceOverride)2 StandaloneCatalog (org.killbill.billing.catalog.StandaloneCatalog)2 Tier (org.killbill.billing.catalog.api.Tier)2 CatalogOverrideBlockDefinitionModelDao (org.killbill.billing.catalog.dao.CatalogOverrideBlockDefinitionModelDao)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1