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);
}
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();
}
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);
}
}
}
}
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();
}
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);
}
}
}
}
}
Aggregations