use of org.killbill.billing.account.api.DefaultAccount in project killbill by killbill.
the class TestIntegrationParentInvoice method testParentingWithFuturePhaseEvent.
@Test(groups = "slow")
public void testParentingWithFuturePhaseEvent() throws Exception {
final int billingDay = 14;
final DateTime initialCreationDate = new DateTime(2015, 5, 15, 0, 0, 0, 0, testTimeZone);
// set clock to the initial start date
clock.setTime(initialCreationDate);
final Account parentAccount = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
Account childAccount = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
// Verify mapping
childAccount = accountUserApi.getAccountById(childAccount.getId(), callContext);
assertNull(childAccount.getParentAccountId());
assertFalse(childAccount.isPaymentDelegatedToParent());
List<Account> childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
assertEquals(childrenAccounts.size(), 0);
// Create subscription
createBaseEntitlementAndCheckForCompletion(childAccount.getId(), "bundleKey1", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
// First child invoice over TRIAL period
List<Invoice> childInvoices = invoiceUserApi.getInvoicesByAccount(childAccount.getId(), false, callContext);
assertEquals(childInvoices.size(), 1);
assertEquals(childInvoices.get(0).getBalance().compareTo(BigDecimal.ZERO), 0);
// Add parent to the child -- the child still pays its invoices though
AccountModelDao childAccountModelDao = new AccountModelDao(childAccount.getId(), childAccount);
childAccountModelDao.setParentAccountId(parentAccount.getId());
childAccountModelDao.setIsPaymentDelegatedToParent(false);
accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao), callContext);
// Verify mapping
childAccount = accountUserApi.getAccountById(childAccount.getId(), callContext);
assertEquals(childAccount.getParentAccountId(), parentAccount.getId());
assertFalse(childAccount.isPaymentDelegatedToParent());
childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
assertEquals(childrenAccounts.size(), 1);
assertEquals(childrenAccounts.get(0).getId(), childAccount.getId());
busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
clock.addDays(30);
assertListenerStatus();
// The parent still has no invoice
List<Invoice> parentInvoices = invoiceUserApi.getInvoicesByAccount(parentAccount.getId(), false, callContext);
assertEquals(parentInvoices.size(), 0);
// Second child invoice over Recurring period
childInvoices = invoiceUserApi.getInvoicesByAccount(childAccount.getId(), false, callContext);
assertEquals(childInvoices.size(), 2);
assertEquals(childInvoices.get(1).getBalance().compareTo(BigDecimal.ZERO), 0);
assertEquals(childInvoices.get(1).getPayments().size(), 1);
assertEquals(paymentApi.getPayment(childInvoices.get(1).getPayments().get(0).getPaymentId(), false, false, ImmutableList.<PluginProperty>of(), callContext).getPaymentMethodId(), childAccount.getPaymentMethodId());
// The child now delegates its payments
childAccountModelDao = new AccountModelDao(childAccount.getId(), childAccount);
childAccountModelDao.setIsPaymentDelegatedToParent(true);
accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao), callContext);
// Verify mapping
childAccount = accountUserApi.getAccountById(childAccount.getId(), callContext);
assertEquals(childAccount.getParentAccountId(), parentAccount.getId());
assertTrue(childAccount.isPaymentDelegatedToParent());
childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
assertEquals(childrenAccounts.size(), 1);
assertEquals(childrenAccounts.get(0).getId(), childAccount.getId());
busHandler.pushExpectedEvents(NextEvent.INVOICE);
clock.addDays(30);
assertListenerStatus();
// Moving a day the NotificationQ calls the commitInvoice. No payment is expected
busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
clock.addDays(1);
assertListenerStatus();
// The parent now owns the invoice
parentInvoices = invoiceUserApi.getInvoicesByAccount(parentAccount.getId(), false, callContext);
assertEquals(parentInvoices.size(), 1);
final Invoice parentInvoice = parentInvoices.get(0);
assertEquals(parentInvoice.getNumberOfItems(), 1);
assertEquals(parentInvoice.getStatus(), InvoiceStatus.COMMITTED);
assertTrue(parentInvoice.isParentInvoice());
assertEquals(parentInvoice.getBalance().compareTo(BigDecimal.ZERO), 0);
assertEquals(parentInvoice.getPayments().size(), 1);
assertEquals(paymentApi.getPayment(parentInvoice.getPayments().get(0).getPaymentId(), false, false, ImmutableList.<PluginProperty>of(), callContext).getPaymentMethodId(), parentAccount.getPaymentMethodId());
// Third child invoice over Recurring period
childInvoices = invoiceUserApi.getInvoicesByAccount(childAccount.getId(), false, callContext);
assertEquals(childInvoices.size(), 3);
assertEquals(childInvoices.get(2).getBalance().compareTo(BigDecimal.ZERO), 0);
}
use of org.killbill.billing.account.api.DefaultAccount in project killbill by killbill.
the class DefaultAccountApiBase method getAccountByKey.
protected Account getAccountByKey(final String key, final InternalTenantContext context) throws AccountApiException {
final AccountModelDao accountModelDao = accountDao.getAccountByKey(key, context);
if (accountModelDao == null) {
throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_KEY, key);
}
final Account account = new DefaultAccount(accountModelDao);
accountCacheController.putIfAbsent(account.getId(), new DefaultImmutableAccountData(account));
return account;
}
use of org.killbill.billing.account.api.DefaultAccount 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);
final AccountData accountData = new MockAccountBuilder(new DefaultAccount(account)).migrated(false).isNotifiedForInvoices(false).timeZone(DateTimeZone.forID("Australia/Darwin")).locale("FR-CA").build();
final AccountModelDao updatedAccount = new AccountModelDao(account.getId(), accountData);
accountDao.update(updatedAccount, internalCallContext);
final AccountModelDao retrievedAccount = accountDao.getAccountByKey(account.getExternalKey(), internalCallContext);
checkAccountsEqual(retrievedAccount, updatedAccount);
}
use of org.killbill.billing.account.api.DefaultAccount in project killbill by killbill.
the class TestAccountDao method testShouldBeAbleToUpdateSomeFields.
@Test(groups = "slow", description = "Test Account DAO: basic update (2)")
public void testShouldBeAbleToUpdateSomeFields() throws Exception {
final AccountModelDao account = createTestAccount();
accountDao.create(account, internalCallContext);
final MutableAccountData otherAccount = new DefaultAccount(account).toMutableAccountData();
otherAccount.setAddress1(UUID.randomUUID().toString());
otherAccount.setEmail(UUID.randomUUID().toString());
final AccountModelDao newAccount = new AccountModelDao(account.getId(), otherAccount);
accountDao.update(newAccount, internalCallContext);
final AccountModelDao retrievedAccount = accountDao.getById(account.getId(), internalCallContext);
checkAccountsEqual(retrievedAccount, newAccount);
}
use of org.killbill.billing.account.api.DefaultAccount in project killbill by killbill.
the class TestDefaultAccountUserApi method testAccountResetTimeZone.
@Test(groups = "slow", description = "Test failure on resetting timeZone", expectedExceptions = IllegalArgumentException.class)
public void testAccountResetTimeZone() throws Exception {
final Account account = createAccount(new DefaultAccount(createTestAccount()));
// Update the address and leave other fields null
final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account);
mutableAccountData.setTimeZone(null);
DefaultAccount newAccount = new DefaultAccount(account.getId(), mutableAccountData);
accountUserApi.updateAccount(newAccount, callContext);
}
Aggregations