use of org.killbill.billing.invoice.dao.serialization.BillingEventSetJson.BillingEventJson 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());
}
Aggregations