use of org.killbill.billing.account.api.AccountData in project killbill by killbill.
the class TestDefaultAccountUserApi method testBusEvents.
@Test(groups = "slow", description = "Test Account creation generates an event")
public void testBusEvents() throws Exception {
final AccountEventHandler eventHandler = new AccountEventHandler();
bus.register(eventHandler);
final AccountModelDao accountModelDao = createTestAccount();
final AccountData defaultAccount = new DefaultAccount(accountModelDao);
final Account account = createAccount(defaultAccount);
await().atMost(10, SECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return eventHandler.getAccountCreationInternalEvents().size() == 1;
}
});
final AccountCreationInternalEvent accountCreationInternalEvent = eventHandler.getAccountCreationInternalEvents().get(0);
Assert.assertEquals(accountCreationInternalEvent.getId(), account.getId());
// account_record_id is most likely 1, although, depending on the DB, we cannot be sure
Assert.assertNotNull(accountCreationInternalEvent.getSearchKey1());
Assert.assertEquals(accountCreationInternalEvent.getSearchKey2(), internalCallContext.getTenantRecordId());
}
use of org.killbill.billing.account.api.AccountData 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);
}
use of org.killbill.billing.account.api.AccountData in project killbill by killbill.
the class TestDefaultAccountUserApi method testCreateParentAndChildAccounts.
@Test(groups = "slow", description = "Test Account create Parent and Child")
public void testCreateParentAndChildAccounts() throws Exception {
final Account parentAccount = accountUserApi.createAccount(new DefaultAccount(createTestAccount()), callContext);
final AccountModelDao childAccountModel = createTestAccount();
childAccountModel.setParentAccountId(parentAccount.getId());
childAccountModel.setIsPaymentDelegatedToParent(true);
final AccountData childAccountData = new DefaultAccount(childAccountModel);
final Account childAccount = accountUserApi.createAccount(childAccountData, callContext);
final Account retrievedChildAccount = accountUserApi.getAccountById(childAccount.getId(), callContext);
Assert.assertNull(parentAccount.getParentAccountId());
Assert.assertNotNull(retrievedChildAccount.getParentAccountId());
Assert.assertEquals(retrievedChildAccount.getId(), childAccount.getId());
Assert.assertEquals(retrievedChildAccount.getParentAccountId(), parentAccount.getId());
Assert.assertEquals(retrievedChildAccount.isPaymentDelegatedToParent(), childAccount.isPaymentDelegatedToParent());
}
use of org.killbill.billing.account.api.AccountData in project killbill by killbill.
the class TestAccountDao method testMinimalFields.
@Test(groups = "slow", description = "Test Account: verify minimal set of required fields")
public void testMinimalFields() throws Exception {
final String email = UUID.randomUUID().toString();
final String name = UUID.randomUUID().toString();
final AccountData accountData = new DefaultMutableAccountData(null, email, name, 0, null, null, false, 0, null, null, null, null, null, null, null, null, null, null, null, null, false, true);
final AccountModelDao account = new AccountModelDao(UUID.randomUUID(), accountData);
accountDao.create(account, internalCallContext);
final AccountModelDao retrievedAccount = accountDao.getById(account.getId(), internalCallContext);
checkAccountsEqual(retrievedAccount, account);
// Verify a default external key was set
Assert.assertEquals(retrievedAccount.getExternalKey(), retrievedAccount.getId().toString());
// Verify a default time zone was set
Assert.assertEquals(retrievedAccount.getTimeZone(), DateTimeZone.UTC);
}
use of org.killbill.billing.account.api.AccountData in project killbill by killbill.
the class TestIntegrationWithCatalogUpdate method setupAccount.
private void setupAccount() throws Exception {
final AccountData accountData = getAccountData(0);
account = accountUserApi.createAccount(accountData, testCallContext);
assertNotNull(account);
final PaymentMethodPlugin info = createPaymentMethodPlugin();
paymentApi.addPaymentMethod(account, UUID.randomUUID().toString(), BeatrixIntegrationModule.NON_OSGI_PLUGIN_NAME, true, info, PLUGIN_PROPERTIES, testCallContext);
}
Aggregations