use of org.joda.time.LocalDate in project killbill by killbill.
the class TestEffectiveDateForNewBCD method testPastEffectiveDateWithBCDAfterEndOfTheMonth.
@Test(groups = "fast")
public void testPastEffectiveDateWithBCDAfterEndOfTheMonth() throws Exception {
// Set by test as : 2012-05-07T00:03:42.000Z
final DateTime now = clock.getUTCNow();
int newBCD = 31;
// effectiveDate = 2012-02-03 => ComputedEffectiveDay = 3
LocalDate effectiveDate = new LocalDate(2012, 2, 3);
// newBCD > 30 (max day in June)
final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext);
Assert.assertEquals(result, internalCallContext.toUTCDateTime(new LocalDate("2012-2-29")));
}
use of org.joda.time.LocalDate in project killbill by killbill.
the class TestEffectiveDateForNewBCD method testNullEffectiveDateWithBCDEqualsComputedEffectiveDay.
@Test(groups = "fast")
public void testNullEffectiveDateWithBCDEqualsComputedEffectiveDay() throws Exception {
// Set by test as : 2012-05-07T00:03:42.000Z
final DateTime now = clock.getUTCNow();
int newBCD = 7;
// effectiveDate = 2012-05-07T00:03:42.000Z => ComputedEffectiveDay = 7
LocalDate effectiveDate = null;
// newBCD == ComputedEffectiveDay
final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext);
final DateTime nowAfterCall = clock.getUTCNow();
// In that case because we want the event to fire right NOW, we don't use the account reference time but instead use the clock.getUTCNOW(). In case test
// takes longer than 1 mSec we need to check a (very small) range of dates
Assert.assertTrue(result.compareTo(now) >= 0);
Assert.assertTrue(result.compareTo(nowAfterCall) <= 0);
}
use of org.joda.time.LocalDate in project killbill by killbill.
the class TestEffectiveDateForNewBCD method testFutureEffectiveDateWithBCDPriorComputedEffectiveDay.
@Test(groups = "fast")
public void testFutureEffectiveDateWithBCDPriorComputedEffectiveDay() throws Exception {
// Set by test as : 2012-05-07T00:03:42.000Z
final DateTime now = clock.getUTCNow();
int newBCD = 3;
// effectiveDate = 2012-05-07T00:03:42.000Z => ComputedEffectiveDay = 7
LocalDate effectiveDate = new LocalDate(2012, 7, 7);
// newBCD < ComputedEffectiveDay
final DateTime result = ((DefaultSubscriptionInternalApi) subscriptionInternalApi).getEffectiveDateForNewBCD(newBCD, effectiveDate, internalCallContext);
Assert.assertEquals(result, internalCallContext.toUTCDateTime(new LocalDate("2012-08-03")));
}
use of org.joda.time.LocalDate in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testOnePlan_TwoMonthlyPhases_ChangeImmediate.
@Test(groups = "fast")
public void testOnePlan_TwoMonthlyPhases_ChangeImmediate() throws InvoiceApiException, CatalogApiException {
final BillingEventSet events = new MockBillingEventSet();
final Plan plan1 = new MockPlan();
final BigDecimal rate1 = FIVE;
final PlanPhase phase1 = createMockMonthlyPlanPhase(rate1);
final SubscriptionBase sub = createSubscription();
final BillingEvent event1 = createBillingEvent(sub.getId(), sub.getBundleId(), invoiceUtil.buildDate(2011, 9, 1), plan1, phase1, 1);
events.add(event1);
final BigDecimal rate2 = TEN;
final PlanPhase phase2 = createMockMonthlyPlanPhase(rate2);
final BillingEvent event2 = createBillingEvent(sub.getId(), sub.getBundleId(), invoiceUtil.buildDate(2011, 10, 15), plan1, phase2, 15);
events.add(event2);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 12, 3);
final UUID accountId = UUID.randomUUID();
final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, null, targetDate, Currency.USD, internalCallContext);
final Invoice invoice = invoiceWithMetadata.getInvoice();
assertNotNull(invoice);
assertEquals(invoice.getNumberOfItems(), 4);
final BigDecimal numberOfCyclesEvent1;
numberOfCyclesEvent1 = ONE.add(FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
final BigDecimal numberOfCyclesEvent2 = TWO;
BigDecimal expectedValue;
expectedValue = numberOfCyclesEvent1.multiply(rate1);
expectedValue = expectedValue.add(numberOfCyclesEvent2.multiply(rate2));
expectedValue = KillBillMoney.of(expectedValue, invoice.getCurrency());
assertEquals(invoice.getBalance(), expectedValue);
}
use of org.joda.time.LocalDate in project killbill by killbill.
the class TestDefaultInvoiceGenerator method testSimpleWithTimeZone.
@Test(groups = "fast")
public void testSimpleWithTimeZone() throws InvoiceApiException, CatalogApiException {
final SubscriptionBase sub = createSubscription();
final Plan plan = new MockPlan();
final BigDecimal rate = TEN;
final PlanPhase phase = createMockMonthlyPlanPhase(rate);
// Start date was the 16 local, but was the 17 UTC
final int bcdLocal = 16;
final LocalDate startDate = invoiceUtil.buildDate(2012, 7, bcdLocal);
final BillingEventSet events = new MockBillingEventSet();
final BillingEvent event = createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan, phase, bcdLocal);
events.add(event);
// Target date is the next BCD, in local time
final LocalDate targetDate = invoiceUtil.buildDate(2012, 8, bcdLocal);
final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, null, targetDate, Currency.USD, internalCallContext);
final Invoice invoice = invoiceWithMetadata.getInvoice();
assertNotNull(invoice);
assertEquals(invoice.getNumberOfItems(), 2);
assertEquals(invoice.getInvoiceItems().get(0).getStartDate(), invoiceUtil.buildDate(2012, 7, 16));
assertEquals(invoice.getInvoiceItems().get(0).getEndDate(), invoiceUtil.buildDate(2012, 8, 16));
assertEquals(invoice.getInvoiceItems().get(1).getStartDate(), invoiceUtil.buildDate(2012, 8, 16));
assertEquals(invoice.getInvoiceItems().get(1).getEndDate(), invoiceUtil.buildDate(2012, 9, 16));
}
Aggregations