use of org.killbill.billing.catalog.api.Recurring 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.Recurring 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.Recurring in project killbill by killbill.
the class DefaultPlan method dateOfFirstRecurringNonZeroCharge.
@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;
}
use of org.killbill.billing.catalog.api.Recurring 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();
}
Aggregations