Search in sources :

Example 1 with DefaultAccount

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);
}
Also used : DefaultAccount(org.killbill.billing.account.api.DefaultAccount) Account(org.killbill.billing.account.api.Account) AccountModelDao(org.killbill.billing.account.dao.AccountModelDao) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) Invoice(org.killbill.billing.invoice.api.Invoice) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 2 with DefaultAccount

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;
}
Also used : AccountModelDao(org.killbill.billing.account.dao.AccountModelDao) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) Account(org.killbill.billing.account.api.Account) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) DefaultImmutableAccountData(org.killbill.billing.account.api.DefaultImmutableAccountData) AccountApiException(org.killbill.billing.account.api.AccountApiException)

Example 3 with DefaultAccount

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);
}
Also used : DefaultAccount(org.killbill.billing.account.api.DefaultAccount) MockAccountBuilder(org.killbill.billing.mock.MockAccountBuilder) DefaultMutableAccountData(org.killbill.billing.account.api.DefaultMutableAccountData) MutableAccountData(org.killbill.billing.account.api.MutableAccountData) AccountData(org.killbill.billing.account.api.AccountData) Test(org.testng.annotations.Test)

Example 4 with DefaultAccount

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);
}
Also used : DefaultAccount(org.killbill.billing.account.api.DefaultAccount) DefaultMutableAccountData(org.killbill.billing.account.api.DefaultMutableAccountData) MutableAccountData(org.killbill.billing.account.api.MutableAccountData) Test(org.testng.annotations.Test)

Example 5 with DefaultAccount

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);
}
Also used : DefaultAccount(org.killbill.billing.account.api.DefaultAccount) AccountTestUtils.createTestAccount(org.killbill.billing.account.AccountTestUtils.createTestAccount) Account(org.killbill.billing.account.api.Account) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) DefaultMutableAccountData(org.killbill.billing.account.api.DefaultMutableAccountData) MutableAccountData(org.killbill.billing.account.api.MutableAccountData) DefaultMutableAccountData(org.killbill.billing.account.api.DefaultMutableAccountData) Test(org.testng.annotations.Test)

Aggregations

DefaultAccount (org.killbill.billing.account.api.DefaultAccount)28 Test (org.testng.annotations.Test)23 Account (org.killbill.billing.account.api.Account)22 DefaultMutableAccountData (org.killbill.billing.account.api.DefaultMutableAccountData)20 MutableAccountData (org.killbill.billing.account.api.MutableAccountData)19 AccountTestUtils.createTestAccount (org.killbill.billing.account.AccountTestUtils.createTestAccount)17 AccountModelDao (org.killbill.billing.account.dao.AccountModelDao)13 AccountData (org.killbill.billing.account.api.AccountData)7 AccountApiException (org.killbill.billing.account.api.AccountApiException)6 AccountTestUtils.createAccountData (org.killbill.billing.account.AccountTestUtils.createAccountData)5 DateTime (org.joda.time.DateTime)2 Invoice (org.killbill.billing.invoice.api.Invoice)2 BigDecimal (java.math.BigDecimal)1 UUID (java.util.UUID)1 DateTimeZone (org.joda.time.DateTimeZone)1 DefaultImmutableAccountData (org.killbill.billing.account.api.DefaultImmutableAccountData)1 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)1 Currency (org.killbill.billing.catalog.api.Currency)1 AccountCreationInternalEvent (org.killbill.billing.events.AccountCreationInternalEvent)1 MockAccountBuilder (org.killbill.billing.mock.MockAccountBuilder)1