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());
}
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);
}
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);
}
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());
}
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);
}
Aggregations