use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class TestWithTimeZones method testIntoDaylightSavingTransition3.
@Test(groups = "slow")
public void testIntoDaylightSavingTransition3() throws Exception {
final DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");
clock.setTime(new DateTime(2017, 3, 1, 23, 30, 0, tz));
final AccountData accountData = new MockAccountBuilder().currency(Currency.USD).timeZone(tz).referenceTime(clock.getUTCNow()).build();
// Create account with non BCD to force junction BCD logic to activate
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("pistol-monthly-notrial", null);
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "bundleExternalKey", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
// Technically, we should see the invoice at the end of day in the account timezone, but this is not the case, the invoice comes slightly after (30')
// clock.setTime(new DateTime(2017, 4, 1, 23, 59, 0, tz));
//
// But this is really not very important as long as invoicing is correct
clock.addMonths(1);
// Add one hour to hit the notification date of 2017-04-02T07:30:00.000Z
clock.addDeltaFromReality(3600 * 1000);
assertListenerStatus();
}
use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class TestPaymentHelper method addTestPaymentMethod.
public Account addTestPaymentMethod(final Account account, final PaymentMethodPlugin paymentMethodInfo, final Iterable<PluginProperty> pluginProperties) throws Exception {
final UUID paymentMethodId = paymentApi.addPaymentMethod(account, paymentMethodInfo.getExternalPaymentMethodId(), MockPaymentProviderPlugin.PLUGIN_NAME, true, paymentMethodInfo, pluginProperties, context);
if (isFastTest()) {
final Account account1 = new MockAccountBuilder(account).paymentMethodId(paymentMethodId).build();
accountApi.updateAccount(account, context);
return account1;
} else {
// To reflect the payment method id change
return accountApi.getAccountById(account.getId(), context);
}
}
use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class TestInvoiceHelper method createAccount.
public Account createAccount(final CallContext callContext) throws AccountApiException {
final Account accountData = new MockAccountBuilder().name(UUID.randomUUID().toString().substring(1, 8)).firstNameLength(6).email(UUID.randomUUID().toString().substring(1, 8)).phone(UUID.randomUUID().toString().substring(1, 8)).migrated(false).externalKey(UUID.randomUUID().toString().substring(1, 8)).billingCycleDayLocal(31).currency(accountCurrency).paymentMethodId(UUID.randomUUID()).timeZone(DateTimeZone.UTC).createdDate(clock.getUTCNow()).build();
final MutableCallContext mutableCallContext = new MutableCallContext(internalCallContext);
final Account account;
if (isFastTest()) {
account = GuicyKillbillTestSuiteNoDB.createMockAccount(accountData, accountUserApi, accountApi, immutableAccountApi, nonEntityDao, clock, internalCallContextFactory, mutableCallContext, internalCallContext);
} else {
account = accountUserApi.createAccount(accountData, callContext);
}
GuicyKillbillTestSuite.refreshCallContext(account.getId(), clock, internalCallContextFactory, mutableCallContext, internalCallContext);
return account;
}
use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class TestEntitlementDateHelper method createAccount.
private void createAccount(final DateTimeZone dateTimeZone, final DateTime referenceDateTime) throws AccountApiException {
final Account accountData = new MockAccountBuilder().externalKey(UUID.randomUUID().toString()).timeZone(dateTimeZone).referenceTime(referenceDateTime).createdDate(referenceDateTime).build();
GuicyKillbillTestSuiteNoDB.createMockAccount(accountData, accountUserApi, accountInternalApi, immutableAccountInternalApi, nonEntityDao, clock, internalCallContextFactory, callContext, internalCallContext);
}
use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class TestWithTimeZones method testCancellationFrom_PDT_to_PST.
// Verify cancellation logic when we exit daylight saving period
@Test(groups = "slow")
public void testCancellationFrom_PDT_to_PST() throws Exception {
// Start with a date in daylight saving period (PDT) and make sure we use a time of 7 hour so that we we reach standard time (PST)
// the next month where the difference is 8 hours, a transformation from DateTime to LocalDate with the account time zone would bring us a day earlier
// (e.g new LocalDate("2015-12-01T07:01:01.000Z", tz) -> "2015-11-30.
clock.setTime(new DateTime("2015-11-01T07:01:01.000Z"));
final DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");
final AccountData accountData = new MockAccountBuilder().name(UUID.randomUUID().toString().substring(1, 8)).firstNameLength(6).email(UUID.randomUUID().toString().substring(1, 8)).phone(UUID.randomUUID().toString().substring(1, 8)).migrated(false).externalKey(UUID.randomUUID().toString().substring(1, 8)).billingCycleDayLocal(1).currency(Currency.USD).paymentMethodId(UUID.randomUUID()).referenceTime(clock.getUTCNow()).timeZone(tz).build();
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
accountChecker.checkAccount(account.getId(), accountData, callContext);
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Blowdart", BillingPeriod.MONTHLY, "notrial", null);
UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), "Something", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext);
// Cancel the next month specifying just a LocalDate
final LocalDate cancellationDate = new LocalDate("2015-12-01", tz);
entitlement = entitlement.cancelEntitlementWithDate(cancellationDate, true, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
// Verify first entitlement is correctly cancelled on the right date
Assert.assertEquals(entitlement.getEffectiveEndDate(), cancellationDate);
// We now move the clock to the date of the cancellation, which match the cancellation day from the client point of view
busHandler.pushExpectedEvents(NextEvent.NULL_INVOICE, NextEvent.CANCEL, NextEvent.BLOCK, NextEvent.NULL_INVOICE);
clock.setTime(new DateTime("2015-12-01T07:01:02Z"));
assertListenerStatus();
// Verify second that there was no repair (so the cancellation did correctly happen on the "2015-12-01")
final List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, callContext);
Assert.assertEquals(invoices.size(), 1);
}
Aggregations