Search in sources :

Example 1 with SubscriptionBillingEventJson

use of org.killbill.billing.invoice.dao.serialization.BillingEventSetJson.SubscriptionBillingEventJson in project killbill by killbill.

the class TestBillingEventSetJson method testTestBillingEventSetJsonSerialization.

@Test(groups = "fast")
public void testTestBillingEventSetJsonSerialization() throws Exception {
    final LocalDate startDate = new LocalDate(2019, 9, 26);
    final UUID subscriptionId = UUID.randomUUID();
    final UUID bundleId = UUID.randomUUID();
    final Currency currency = Currency.USD;
    final SubscriptionBase sub = Mockito.mock(SubscriptionBase.class);
    Mockito.when(sub.getId()).thenReturn(subscriptionId);
    Mockito.when(sub.getBundleId()).thenReturn(bundleId);
    final MockBillingEventSet billingEventSet = new MockBillingEventSet();
    final Plan plan = new MockPlan("Test");
    final MockInternationalPrice recurringPrice = new MockInternationalPrice(new DefaultPrice(THIRTEEN, Currency.USD));
    final PlanPhase planPhase = new MockPlanPhase(recurringPrice, null, BillingPeriod.MONTHLY, PhaseType.EVERGREEN);
    final DateTime effectiveDate1 = startDate.toDateTimeAtStartOfDay();
    final BillingEvent event1 = invoiceUtil.createMockBillingEvent(null, sub, effectiveDate1, plan, planPhase, planPhase.getFixed().getPrice() == null ? null : planPhase.getFixed().getPrice().getPrice(currency), planPhase.getRecurring().getRecurringPrice() == null ? null : planPhase.getRecurring().getRecurringPrice().getPrice(currency), currency, planPhase.getRecurring().getBillingPeriod(), 1, BillingMode.IN_ADVANCE, "Test", 1, SubscriptionBaseTransitionType.CREATE);
    billingEventSet.add(event1);
    final DateTime effectiveDate2 = startDate.toDateTimeAtStartOfDay().plusDays(10);
    final BillingEvent event2 = invoiceUtil.createMockBillingEvent(null, sub, effectiveDate2, plan, planPhase, planPhase.getFixed().getPrice() == null ? null : planPhase.getFixed().getPrice().getPrice(currency), planPhase.getRecurring().getRecurringPrice() == null ? null : planPhase.getRecurring().getRecurringPrice().getPrice(currency), currency, planPhase.getRecurring().getBillingPeriod(), 1, BillingMode.IN_ADVANCE, "Test", 1, SubscriptionBaseTransitionType.CHANGE);
    billingEventSet.add(event2);
    final BillingEventSetJson json = new BillingEventSetJson(billingEventSet);
    final String asJson = testMapper.writeValueAsString(json);
    final BillingEventSetJson res = testMapper.readValue(asJson, BillingEventSetJson.class);
    assertFalse(res.isAutoInvoiceOff());
    assertFalse(res.isAutoInvoiceDraft());
    assertFalse(res.isAutoInvoiceReuseDraft());
    assertEquals(res.getSubscriptionEvents().size(), 1);
    final SubscriptionBillingEventJson res1 = res.getSubscriptionEvents().get(0);
    assertEquals(res1.getSubscriptionId(), subscriptionId);
    assertEquals(res1.getEvents().size(), 2);
    final BillingEventJson billingEvent1 = res1.getEvents().get(0);
    assertEquals(billingEvent1.getBcdLocal(), 1);
    assertEquals(billingEvent1.getPlanName(), "Test");
    assertEquals(billingEvent1.getPhaseName(), "Test-evergreen");
    assertEquals(billingEvent1.getEffDate().compareTo(effectiveDate1), 0);
    assertNull(billingEvent1.getFixedPrice());
    assertEquals(billingEvent1.getRecurringPrice().compareTo(new BigDecimal("13.0")), 0);
    assertEquals(billingEvent1.getTransitionType(), SubscriptionBaseTransitionType.CREATE);
    // Our Mock implementation returns null
    assertNull(billingEvent1.getCatalogEffDt());
}
Also used : MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) SubscriptionBillingEventJson(org.killbill.billing.invoice.dao.serialization.BillingEventSetJson.SubscriptionBillingEventJson) BillingEventJson(org.killbill.billing.invoice.dao.serialization.BillingEventSetJson.BillingEventJson) SubscriptionBillingEventJson(org.killbill.billing.invoice.dao.serialization.BillingEventSetJson.SubscriptionBillingEventJson) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan) LocalDate(org.joda.time.LocalDate) MockInternationalPrice(org.killbill.billing.catalog.MockInternationalPrice) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) 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) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) BillingEvent(org.killbill.billing.junction.BillingEvent) UUID(java.util.UUID) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) Test(org.testng.annotations.Test)

Aggregations

BigDecimal (java.math.BigDecimal)1 UUID (java.util.UUID)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 DefaultPrice (org.killbill.billing.catalog.DefaultPrice)1 MockInternationalPrice (org.killbill.billing.catalog.MockInternationalPrice)1 MockPlan (org.killbill.billing.catalog.MockPlan)1 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)1 Currency (org.killbill.billing.catalog.api.Currency)1 Plan (org.killbill.billing.catalog.api.Plan)1 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)1 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)1 BillingEventJson (org.killbill.billing.invoice.dao.serialization.BillingEventSetJson.BillingEventJson)1 SubscriptionBillingEventJson (org.killbill.billing.invoice.dao.serialization.BillingEventSetJson.SubscriptionBillingEventJson)1 BillingEvent (org.killbill.billing.junction.BillingEvent)1 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)1 Test (org.testng.annotations.Test)1