use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class TestConsumableInArrear method testWithDayLightSaving.
@Test(groups = "slow")
public void testWithDayLightSaving() throws Exception {
clock.setTime(new DateTime("2015-09-01T08:01:01.000Z"));
final DateTimeZone tz = DateTimeZone.forID("America/Juneau");
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).isNotifiedForInvoices(false).externalKey(UUID.randomUUID().toString().substring(1, 8)).billingCycleDayLocal(1).currency(Currency.USD).paymentMethodId(UUID.randomUUID()).timeZone(tz).build();
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
accountChecker.checkAccount(account.getId(), accountData, callContext);
//
// CREATE SUBSCRIPTION AND EXPECT BOTH EVENTS: NextEvent.CREATE, NextEvent.BLOCK NextEvent.INVOICE
//
final DefaultEntitlement bpSubscription = createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", "Shotgun", ProductCategory.BASE, BillingPeriod.ANNUAL, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
// Check bundle after BP got created otherwise we get an error from auditApi.
subscriptionChecker.checkSubscriptionCreated(bpSubscription.getId(), internalCallContext);
invoiceChecker.checkInvoice(account.getId(), 1, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2015, 9, 1), null, InvoiceItemType.FIXED, new BigDecimal("0")));
assertListenerStatus();
//
// ADD ADD_ON ON THE SAME DAY
//
final DefaultEntitlement aoSubscription = addAOEntitlementAndCheckForCompletion(bpSubscription.getBundleId(), "Bullets", ProductCategory.ADD_ON, BillingPeriod.NO_BILLING_PERIOD, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.NULL_INVOICE);
assertListenerStatus();
busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.NULL_INVOICE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
clock.addDays(30);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2015, 10, 1), new LocalDate(2016, 10, 1), InvoiceItemType.RECURRING, new BigDecimal("2399.95")));
// 2015-11-1
busHandler.pushExpectedEvent(NextEvent.NULL_INVOICE);
clock.addMonths(1);
assertListenerStatus();
// 2015-12-1
busHandler.pushExpectedEvent(NextEvent.NULL_INVOICE);
clock.addMonths(1);
assertListenerStatus();
// We sleep to let system creates lots of notification if an infinite loop was indeed happening
Thread.sleep(3000);
// And then we check that we only have the expected number of notifications in the history table.
final Integer countNotifications = dbi.withHandle(new HandleCallback<Integer>() {
@Override
public Integer withHandle(final Handle handle) throws Exception {
List<Map<String, Object>> res = handle.select("select count(*) as count from notifications_history;");
final Integer count = Integer.valueOf(res.get(0).get("count").toString());
return count;
}
});
Assert.assertEquals(countNotifications.intValue(), 4);
}
use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class DefaultSubscriptionTestInitializer method initAccountData.
public AccountData initAccountData() {
final AccountData accountData = new MockAccountBuilder().name(UUIDs.randomUUID().toString().substring(1, 8)).firstNameLength(6).email(UUIDs.randomUUID().toString().substring(1, 8)).phone(UUIDs.randomUUID().toString().substring(1, 8)).migrated(false).isNotifiedForInvoices(false).externalKey(UUIDs.randomUUID().toString()).billingCycleDayLocal(1).currency(Currency.USD).paymentMethodId(UUIDs.randomUUID()).timeZone(DateTimeZone.forID("Europe/Paris")).build();
assertNotNull(accountData);
return accountData;
}
use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class TestDefaultBillingEvent method createEvent.
private BillingEvent createEvent(final SubscriptionBase sub, final DateTime effectiveDate, final SubscriptionBaseTransitionType type, final long totalOrdering) {
final int billCycleDay = 1;
final Plan shotgun = new MockPlan();
final PlanPhase shotgunMonthly = createMockMonthlyPlanPhase(null, BigDecimal.ZERO, PhaseType.TRIAL);
final Account account = new MockAccountBuilder().build();
return new DefaultBillingEvent(sub, effectiveDate, true, shotgun, shotgunMonthly, BigDecimal.ZERO, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, billCycleDay, "Test Event 1", totalOrdering, type, DateTimeZone.UTC, null, false);
}
use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class TestDefaultInvoiceGenerator method beforeClass.
@BeforeClass(groups = "fast")
protected void beforeClass() throws Exception {
if (hasFailed()) {
return;
}
super.beforeClass();
final Clock clock = new DefaultClock();
this.account = 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(Currency.USD).paymentMethodId(UUID.randomUUID()).timeZone(DateTimeZone.UTC).build();
}
use of org.killbill.billing.mock.MockAccountBuilder in project killbill by killbill.
the class TestAccountDao method testUpdate.
@Test(groups = "slow", description = "Test Account DAO: basic update (1)")
public void testUpdate() throws Exception {
final AccountModelDao account = createTestAccount();
accountDao.create(account, internalCallContext);
refreshCallContext(account.getId());
final AccountModelDao createdAccount = accountDao.getAccountByKey(account.getExternalKey(), internalCallContext);
List<AuditLogWithHistory> auditLogsWithHistory = accountDao.getAuditLogsWithHistoryForId(account.getId(), AuditLevel.FULL, internalCallContext);
Assert.assertEquals(auditLogsWithHistory.size(), 1);
final AccountModelDao history1 = (AccountModelDao) auditLogsWithHistory.get(0).getEntity();
Assert.assertEquals(auditLogsWithHistory.get(0).getChangeType(), ChangeType.INSERT);
Assert.assertEquals(history1.getAccountRecordId(), createdAccount.getRecordId());
Assert.assertEquals(history1.getTenantRecordId(), createdAccount.getTenantRecordId());
Assert.assertEquals(history1.getExternalKey(), createdAccount.getExternalKey());
Assert.assertEquals(history1.getMigrated(), createdAccount.getMigrated());
Assert.assertEquals(history1.getTimeZone(), createdAccount.getTimeZone());
Assert.assertEquals(history1.getLocale(), createdAccount.getLocale());
final AccountData accountData = new MockAccountBuilder(new DefaultAccount(account)).migrated(false).locale("FR-CA").build();
final AccountModelDao updatedAccount = new AccountModelDao(account.getId(), accountData);
accountDao.update(updatedAccount, true, internalCallContext);
final AccountModelDao retrievedAccount = accountDao.getAccountByKey(account.getExternalKey(), internalCallContext);
checkAccountsEqual(retrievedAccount, updatedAccount);
auditLogsWithHistory = accountDao.getAuditLogsWithHistoryForId(retrievedAccount.getId(), AuditLevel.FULL, internalCallContext);
Assert.assertEquals(auditLogsWithHistory.size(), 2);
final AccountModelDao history2 = (AccountModelDao) auditLogsWithHistory.get(1).getEntity();
Assert.assertEquals(auditLogsWithHistory.get(0).getChangeType(), ChangeType.INSERT);
Assert.assertEquals(auditLogsWithHistory.get(1).getChangeType(), ChangeType.UPDATE);
Assert.assertEquals(history2.getAccountRecordId(), retrievedAccount.getRecordId());
Assert.assertEquals(history2.getTenantRecordId(), retrievedAccount.getTenantRecordId());
Assert.assertEquals(history2.getExternalKey(), retrievedAccount.getExternalKey());
Assert.assertEquals(history2.getMigrated(), retrievedAccount.getMigrated());
Assert.assertEquals(history2.getTimeZone(), retrievedAccount.getTimeZone());
Assert.assertEquals(history2.getLocale(), retrievedAccount.getLocale());
final AccountData accountData2 = new MockAccountBuilder(new DefaultAccount(updatedAccount)).locale("en_US").build();
final AccountModelDao updatedAccount2 = new AccountModelDao(account.getId(), accountData2);
accountDao.update(updatedAccount2, true, internalCallContext);
final AccountModelDao retrievedAccount2 = accountDao.getAccountByKey(account.getExternalKey(), internalCallContext);
checkAccountsEqual(retrievedAccount2, updatedAccount2);
auditLogsWithHistory = accountDao.getAuditLogsWithHistoryForId(retrievedAccount2.getId(), AuditLevel.FULL, internalCallContext);
Assert.assertEquals(auditLogsWithHistory.size(), 3);
final AccountModelDao history3 = (AccountModelDao) auditLogsWithHistory.get(2).getEntity();
Assert.assertEquals(auditLogsWithHistory.get(0).getChangeType(), ChangeType.INSERT);
Assert.assertEquals(auditLogsWithHistory.get(1).getChangeType(), ChangeType.UPDATE);
Assert.assertEquals(auditLogsWithHistory.get(2).getChangeType(), ChangeType.UPDATE);
Assert.assertEquals(history3.getAccountRecordId(), retrievedAccount2.getRecordId());
Assert.assertEquals(history3.getTenantRecordId(), retrievedAccount2.getTenantRecordId());
Assert.assertEquals(history3.getExternalKey(), retrievedAccount2.getExternalKey());
Assert.assertEquals(history3.getMigrated(), retrievedAccount2.getMigrated());
Assert.assertEquals(history3.getTimeZone(), retrievedAccount2.getTimeZone());
Assert.assertEquals(history3.getLocale(), retrievedAccount2.getLocale());
}
Aggregations