Search in sources :

Example 21 with DefaultAccount

use of org.killbill.billing.account.api.DefaultAccount in project killbill by killbill.

the class TestDefaultAccountUserApi method testUnAndReParenting.

@Test(groups = "slow", description = "Test un- and re-parenting")
public void testUnAndReParenting() throws Exception {
    // Create child1
    final AccountModelDao childAccountModelDao1 = createTestAccount();
    Account childAccount1 = accountUserApi.createAccount(new DefaultAccount(childAccountModelDao1), callContext);
    Assert.assertNull(childAccount1.getParentAccountId());
    Assert.assertFalse(childAccount1.isPaymentDelegatedToParent());
    // Create parent
    final Account parentAccount = accountUserApi.createAccount(new DefaultAccount(createTestAccount()), callContext);
    Assert.assertNull(parentAccount.getParentAccountId());
    Assert.assertFalse(parentAccount.isPaymentDelegatedToParent());
    List<Account> childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
    Assert.assertEquals(childrenAccounts.size(), 0);
    // Associate child1 to parent
    childAccountModelDao1.setId(childAccount1.getId());
    childAccountModelDao1.setParentAccountId(parentAccount.getId());
    childAccountModelDao1.setIsPaymentDelegatedToParent(true);
    accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao1), callContext);
    // Verify mapping
    childAccount1 = accountUserApi.getAccountById(childAccount1.getId(), callContext);
    Assert.assertEquals(childAccount1.getParentAccountId(), parentAccount.getId());
    Assert.assertTrue(childAccount1.isPaymentDelegatedToParent());
    childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
    Assert.assertEquals(childrenAccounts.size(), 1);
    Assert.assertEquals(childrenAccounts.get(0).getId(), childAccount1.getId());
    // Un-parent child1 from parent
    childAccountModelDao1.setParentAccountId(null);
    childAccountModelDao1.setIsPaymentDelegatedToParent(false);
    accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao1), callContext);
    // Verify mapping
    childAccount1 = accountUserApi.getAccountById(childAccount1.getId(), callContext);
    Assert.assertNull(childAccount1.getParentAccountId());
    Assert.assertFalse(childAccount1.isPaymentDelegatedToParent());
    childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
    Assert.assertEquals(childrenAccounts.size(), 0);
    // Create child2
    final AccountModelDao childAccountModelDao2 = createTestAccount();
    Account childAccount2 = accountUserApi.createAccount(new DefaultAccount(childAccountModelDao2), callContext);
    Assert.assertNull(childAccount2.getParentAccountId());
    Assert.assertFalse(childAccount2.isPaymentDelegatedToParent());
    // Associate child2 to parent
    childAccountModelDao2.setId(childAccount2.getId());
    childAccountModelDao2.setParentAccountId(parentAccount.getId());
    childAccountModelDao2.setIsPaymentDelegatedToParent(true);
    accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao2), callContext);
    // Verify mapping
    childAccount1 = accountUserApi.getAccountById(childAccount1.getId(), callContext);
    Assert.assertNull(childAccount1.getParentAccountId());
    Assert.assertFalse(childAccount1.isPaymentDelegatedToParent());
    childAccount2 = accountUserApi.getAccountById(childAccount2.getId(), callContext);
    Assert.assertEquals(childAccount2.getParentAccountId(), parentAccount.getId());
    Assert.assertTrue(childAccount2.isPaymentDelegatedToParent());
    childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext);
    Assert.assertEquals(childrenAccounts.size(), 1);
    Assert.assertEquals(childrenAccounts.get(0).getId(), childAccount2.getId());
}
Also used : AccountModelDao(org.killbill.billing.account.dao.AccountModelDao) 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) Test(org.testng.annotations.Test)

Example 22 with DefaultAccount

use of org.killbill.billing.account.api.DefaultAccount in project killbill by killbill.

the class TestDefaultAccountUserApi method testAccountResetBCD.

@Test(groups = "slow", description = "Test failure on resetting BCD", expectedExceptions = IllegalArgumentException.class)
public void testAccountResetBCD() throws Exception {
    final Account account = createAccount(new DefaultAccount(createTestAccount()));
    // Update the address and leave other fields null
    final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account);
    mutableAccountData.setBillCycleDayLocal(DEFAULT_BILLING_CYCLE_DAY_LOCAL);
    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)

Example 23 with DefaultAccount

use of org.killbill.billing.account.api.DefaultAccount in project killbill by killbill.

the class TestDefaultAccountUserApi method testAccountChangeCurrency.

@Test(groups = "slow", description = "Test failure on changing currency", expectedExceptions = IllegalArgumentException.class)
public void testAccountChangeCurrency() throws Exception {
    final Account account = createAccount(new DefaultAccount(createTestAccount()));
    // Update the address and leave other fields null
    final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account);
    mutableAccountData.setCurrency(Currency.AFN);
    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)

Example 24 with DefaultAccount

use of org.killbill.billing.account.api.DefaultAccount in project killbill by killbill.

the class TestDefaultAccountUserApi method testShouldBeAbleToPassNullForSomeFieldsToAvoidUpdate.

@Test(groups = "slow", description = "Test Account update with null values")
public void testShouldBeAbleToPassNullForSomeFieldsToAvoidUpdate() throws Exception {
    final Account account = createAccount(new DefaultAccount(createTestAccount()));
    // Update the address and leave other fields null
    final MutableAccountData mutableAccountData = new DefaultMutableAccountData(null, null, null, 0, null, null, false, 0, null, null, null, null, null, null, null, null, null, null, null, null, false, false);
    final String newAddress1 = UUID.randomUUID().toString();
    mutableAccountData.setAddress1(newAddress1);
    accountUserApi.updateAccount(account.getId(), mutableAccountData, callContext);
    final Account retrievedAccount = accountUserApi.getAccountById(account.getId(), callContext);
    Assert.assertEquals(retrievedAccount.getAddress1(), newAddress1);
    Assert.assertEquals(retrievedAccount.getAddress2(), account.getAddress2());
    Assert.assertEquals(retrievedAccount.getCurrency(), account.getCurrency());
    Assert.assertEquals(retrievedAccount.getExternalKey(), account.getExternalKey());
    Assert.assertEquals(retrievedAccount.getBillCycleDayLocal(), account.getBillCycleDayLocal());
}
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)

Example 25 with DefaultAccount

use of org.killbill.billing.account.api.DefaultAccount in project killbill by killbill.

the class TestDefaultAccountUserApi method testSearch.

@Test(groups = "slow", description = "Test Account search")
public void testSearch() throws Exception {
    final MutableAccountData mutableAccountData1 = createAccountData();
    mutableAccountData1.setEmail("john@acme.com");
    mutableAccountData1.setCompanyName("Acme, Inc.");
    final AccountModelDao account1ModelDao = new AccountModelDao(UUID.randomUUID(), mutableAccountData1);
    final AccountData accountData1 = new DefaultAccount(account1ModelDao);
    accountUserApi.createAccount(accountData1, callContext);
    final MutableAccountData mutableAccountData2 = createAccountData();
    mutableAccountData2.setEmail("bob@gmail.com");
    mutableAccountData2.setCompanyName("Acme, Inc.");
    final AccountModelDao account2ModelDao = new AccountModelDao(UUID.randomUUID(), mutableAccountData2);
    final AccountData accountData2 = new DefaultAccount(account2ModelDao);
    accountUserApi.createAccount(accountData2, callContext);
    final Pagination<Account> search1 = accountUserApi.searchAccounts("Inc.", 0L, 5L, callContext);
    Assert.assertEquals(search1.getCurrentOffset(), (Long) 0L);
    Assert.assertNull(search1.getNextOffset());
    Assert.assertEquals(search1.getMaxNbRecords(), (Long) 2L);
    Assert.assertEquals(search1.getTotalNbRecords(), (Long) 2L);
    Assert.assertEquals(ImmutableList.<Account>copyOf(search1.iterator()).size(), 2);
    final Pagination<Account> search2 = accountUserApi.searchAccounts("Inc.", 0L, 1L, callContext);
    Assert.assertEquals(search2.getCurrentOffset(), (Long) 0L);
    Assert.assertEquals(search2.getNextOffset(), (Long) 1L);
    Assert.assertEquals(search2.getMaxNbRecords(), (Long) 2L);
    Assert.assertEquals(search2.getTotalNbRecords(), (Long) 2L);
    Assert.assertEquals(ImmutableList.<Account>copyOf(search2.iterator()).size(), 1);
    final Pagination<Account> search3 = accountUserApi.searchAccounts("acme.com", 0L, 5L, callContext);
    Assert.assertEquals(search3.getCurrentOffset(), (Long) 0L);
    Assert.assertNull(search3.getNextOffset());
    Assert.assertEquals(search3.getMaxNbRecords(), (Long) 2L);
    Assert.assertEquals(search3.getTotalNbRecords(), (Long) 1L);
    Assert.assertEquals(ImmutableList.<Account>copyOf(search3.iterator()).size(), 1);
    // Exact search will fail
    final Pagination<Account> search4 = accountUserApi.searchAccounts("acme.com", -1L, 1L, callContext);
    Assert.assertEquals(search4.getCurrentOffset(), (Long) 0L);
    Assert.assertNull(search4.getNextOffset());
    // Not computed
    Assert.assertNull(search4.getMaxNbRecords());
    Assert.assertEquals(search4.getTotalNbRecords(), (Long) 0L);
    Assert.assertEquals(ImmutableList.<Account>copyOf(search4.iterator()).size(), 0);
    final Pagination<Account> search5 = accountUserApi.searchAccounts("john@acme.com", -1L, 1L, callContext);
    Assert.assertEquals(search5.getCurrentOffset(), (Long) 0L);
    Assert.assertNull(search5.getNextOffset());
    // Not computed
    Assert.assertNull(search5.getMaxNbRecords());
    Assert.assertEquals(search5.getTotalNbRecords(), (Long) 1L);
    Assert.assertEquals(ImmutableList.<Account>copyOf(search5.iterator()).size(), 1);
}
Also used : AccountModelDao(org.killbill.billing.account.dao.AccountModelDao) 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) AccountTestUtils.createAccountData(org.killbill.billing.account.AccountTestUtils.createAccountData) MutableAccountData(org.killbill.billing.account.api.MutableAccountData) AccountData(org.killbill.billing.account.api.AccountData) DefaultMutableAccountData(org.killbill.billing.account.api.DefaultMutableAccountData) MutableAccountData(org.killbill.billing.account.api.MutableAccountData) 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