Search in sources :

Example 1 with InternationalPrice

use of org.killbill.billing.catalog.api.InternationalPrice 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);
    final Price[] mock = {};
    Mockito.when(price.getPrices()).thenReturn(mock);
    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);
}
Also used : Recurring(org.killbill.billing.catalog.api.Recurring) InternationalPrice(org.killbill.billing.catalog.api.InternationalPrice) Price(org.killbill.billing.catalog.api.Price) Listing(org.killbill.billing.catalog.api.Listing) Product(org.killbill.billing.catalog.api.Product) InternationalPrice(org.killbill.billing.catalog.api.InternationalPrice) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) Plan(org.killbill.billing.catalog.api.Plan) PriceList(org.killbill.billing.catalog.api.PriceList) Test(org.testng.annotations.Test)

Example 2 with InternationalPrice

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

the class TestBlockingCalculator method createRealEvent.

private BillingEvent createRealEvent(final SubscriptionBase subscription, final DateTime effectiveDate, final SubscriptionBaseTransitionType type, final Long totalOrdering) {
    try {
        final Integer billCycleDay = 1;
        final Plan plan = new MockPlan();
        final Currency currency = Currency.USD;
        final String description = "";
        final BillingPeriod billingPeriod = BillingPeriod.MONTHLY;
        final PlanPhase planPhase = Mockito.mock(PlanPhase.class);
        final InternationalPrice internationalPrice = Mockito.mock(InternationalPrice.class);
        Mockito.when(internationalPrice.getPrice(Mockito.<Currency>any())).thenReturn(BigDecimal.TEN);
        final Recurring recurring = Mockito.mock(Recurring.class);
        Mockito.when(recurring.getRecurringPrice()).thenReturn(internationalPrice);
        Mockito.when(planPhase.getRecurring()).thenReturn(recurring);
        Mockito.when(planPhase.getUsages()).thenReturn(new DefaultUsage[0]);
        final BigDecimal fixedPrice = BigDecimal.TEN;
        final BigDecimal recurringPrice = BigDecimal.TEN;
        return new DefaultBillingEvent(subscription.getId(), subscription.getBundleId(), effectiveDate, plan, planPhase, fixedPrice, recurringPrice, ImmutableList.of(), currency, billingPeriod, billCycleDay, description, totalOrdering, type, false);
    } catch (final CatalogApiException e) {
        Assert.fail("", e);
    }
    throw new IllegalStateException();
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) InternationalPrice(org.killbill.billing.catalog.api.InternationalPrice) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan) BigDecimal(java.math.BigDecimal) Recurring(org.killbill.billing.catalog.api.Recurring) MockPlan(org.killbill.billing.catalog.MockPlan) Currency(org.killbill.billing.catalog.api.Currency) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PlanPhase(org.killbill.billing.catalog.api.PlanPhase)

Example 3 with InternationalPrice

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

the class TestDefaultPriceOverride method assertTieredBlockInternationalPrice.

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);
            }
        }
    }
}
Also used : InternationalPrice(org.killbill.billing.catalog.api.InternationalPrice) Price(org.killbill.billing.catalog.api.Price)

Example 4 with InternationalPrice

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

the class TestBlockingCalculator method createRealEvent.

protected BillingEvent createRealEvent(final DateTime effectiveDate, final SubscriptionBase subscription, final SubscriptionBaseTransitionType type) {
    try {
        final Integer billCycleDay = 1;
        final Plan plan = new MockPlan();
        final Currency currency = Currency.USD;
        final String description = "";
        final BillingPeriod billingPeriod = BillingPeriod.MONTHLY;
        final Long totalOrdering = 0L;
        final DateTimeZone tz = DateTimeZone.UTC;
        final PlanPhase planPhase = Mockito.mock(PlanPhase.class);
        final InternationalPrice recurringPrice = Mockito.mock(InternationalPrice.class);
        Mockito.when(recurringPrice.getPrice(Mockito.<Currency>any())).thenReturn(BigDecimal.TEN);
        final Recurring recurring = Mockito.mock(Recurring.class);
        Mockito.when(recurring.getRecurringPrice()).thenReturn(recurringPrice);
        Mockito.when(planPhase.getRecurring()).thenReturn(recurring);
        Mockito.when(planPhase.getUsages()).thenReturn(new DefaultUsage[0]);
        final BigDecimal fixedPrice = BigDecimal.TEN;
        return new DefaultBillingEvent(subscription, effectiveDate, true, plan, planPhase, fixedPrice, currency, billingPeriod, billCycleDay, description, totalOrdering, type, tz, null, false);
    } catch (final CatalogApiException e) {
        Assert.fail("", e);
    }
    throw new IllegalStateException();
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) InternationalPrice(org.killbill.billing.catalog.api.InternationalPrice) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan) DateTimeZone(org.joda.time.DateTimeZone) BigDecimal(java.math.BigDecimal) Recurring(org.killbill.billing.catalog.api.Recurring) MockPlan(org.killbill.billing.catalog.MockPlan) Currency(org.killbill.billing.catalog.api.Currency) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PlanPhase(org.killbill.billing.catalog.api.PlanPhase)

Example 5 with InternationalPrice

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

the class TestDefaultPriceOverride method assertInternationalPrice.

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);
                }
            }
        }
    }
}
Also used : InternationalPrice(org.killbill.billing.catalog.api.InternationalPrice) Price(org.killbill.billing.catalog.api.Price)

Aggregations

InternationalPrice (org.killbill.billing.catalog.api.InternationalPrice)5 Plan (org.killbill.billing.catalog.api.Plan)3 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)3 Price (org.killbill.billing.catalog.api.Price)3 Recurring (org.killbill.billing.catalog.api.Recurring)3 BigDecimal (java.math.BigDecimal)2 MockPlan (org.killbill.billing.catalog.MockPlan)2 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)2 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)2 Currency (org.killbill.billing.catalog.api.Currency)2 DateTimeZone (org.joda.time.DateTimeZone)1 Listing (org.killbill.billing.catalog.api.Listing)1 PriceList (org.killbill.billing.catalog.api.PriceList)1 Product (org.killbill.billing.catalog.api.Product)1 Test (org.testng.annotations.Test)1