Search in sources :

Example 51 with MockPlan

use of org.killbill.billing.catalog.MockPlan in project killbill by killbill.

the class TestInvoiceDao method testMixedModeInvoicePersistence.

@Test(groups = "slow")
public void testMixedModeInvoicePersistence() throws InvoiceApiException, CatalogApiException, EntityPersistenceException {
    final Currency currency = Currency.USD;
    final DefaultPrice zeroPrice = new DefaultPrice(BigDecimal.ZERO, Currency.USD);
    final MockInternationalPrice fixedPrice = new MockInternationalPrice(zeroPrice);
    final MockPlanPhase phase1 = new MockPlanPhase(null, fixedPrice);
    final BigDecimal cheapAmount = new BigDecimal("24.95");
    final DefaultPrice cheapPrice = new DefaultPrice(cheapAmount, Currency.USD);
    final MockInternationalPrice recurringPrice = new MockInternationalPrice(cheapPrice);
    final MockPlanPhase phase2 = new MockPlanPhase(recurringPrice, null);
    final MockPlan plan = new MockPlan();
    final SubscriptionBase subscription = getZombieSubscription();
    final DateTime effectiveDate1 = invoiceUtil.buildDate(2011, 1, 1).toDateTimeAtStartOfDay();
    final BillingEvent event1 = invoiceUtil.createMockBillingEvent(null, subscription, effectiveDate1, plan, phase1, fixedPrice.getPrice(currency), null, currency, BillingPeriod.MONTHLY, 1, BillingMode.IN_ADVANCE, "testEvent1", 1L, SubscriptionBaseTransitionType.CREATE);
    final BillingEventSet events = new MockBillingEventSet();
    events.add(event1);
    final DateTime effectiveDate2 = effectiveDate1.plusDays(30);
    final BillingEvent event2 = invoiceUtil.createMockBillingEvent(null, subscription, effectiveDate2, plan, phase2, null, recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 31, BillingMode.IN_ADVANCE, "testEvent2", 2L, SubscriptionBaseTransitionType.CHANGE);
    events.add(event2);
    final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, null, new LocalDate(effectiveDate2), Currency.USD, context);
    final Invoice invoice = invoiceWithMetadata.getInvoice();
    assertNotNull(invoice);
    assertEquals(invoice.getNumberOfItems(), 2);
    assertEquals(invoice.getBalance().compareTo(cheapAmount), 0);
    invoiceUtil.createInvoice(invoice, context);
    final InvoiceModelDao savedInvoice = invoiceDao.getById(invoice.getId(), context);
    assertNotNull(savedInvoice);
    assertEquals(savedInvoice.getInvoiceItems().size(), 2);
    assertEquals(InvoiceModelDaoHelper.getBalance(savedInvoice).compareTo(cheapAmount), 0);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) InvoiceWithMetadata(org.killbill.billing.invoice.generator.InvoiceWithMetadata) LocalDate(org.joda.time.LocalDate) MockInternationalPrice(org.killbill.billing.catalog.MockInternationalPrice) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) MockPlan(org.killbill.billing.catalog.MockPlan) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) Currency(org.killbill.billing.catalog.api.Currency) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) BillingEventSet(org.killbill.billing.junction.BillingEventSet) BillingEvent(org.killbill.billing.junction.BillingEvent) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) Test(org.testng.annotations.Test)

Aggregations

MockPlan (org.killbill.billing.catalog.MockPlan)51 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)50 Test (org.testng.annotations.Test)49 LocalDate (org.joda.time.LocalDate)48 Plan (org.killbill.billing.catalog.api.Plan)46 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)45 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)43 BillingEventSet (org.killbill.billing.junction.BillingEventSet)42 BigDecimal (java.math.BigDecimal)40 Invoice (org.killbill.billing.invoice.api.Invoice)40 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)39 BillingEvent (org.killbill.billing.junction.BillingEvent)38 UUID (java.util.UUID)31 DefaultPrice (org.killbill.billing.catalog.DefaultPrice)27 MockInternationalPrice (org.killbill.billing.catalog.MockInternationalPrice)27 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)22 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)22 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)21 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)20 RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)20