Search in sources :

Example 11 with AccountModelDao

use of org.killbill.billing.account.dao.AccountModelDao in project killbill by killbill.

the class TestDefaultAccountUserApiWithMocks method testCreateAccount.

@Test(groups = "fast", description = "Test Account create API")
public void testCreateAccount() throws Exception {
    final UUID id = UUID.randomUUID();
    final String externalKey = UUID.randomUUID().toString();
    final String email = UUID.randomUUID().toString();
    final String name = UUID.randomUUID().toString();
    final Integer firstNameLength = Integer.MAX_VALUE;
    final Currency currency = Currency.BRL;
    final Integer billCycleDay = Integer.MAX_VALUE;
    final UUID paymentMethodId = UUID.randomUUID();
    final DateTimeZone timeZone = DateTimeZone.UTC;
    final String locale = UUID.randomUUID().toString();
    final String address1 = UUID.randomUUID().toString();
    final String address2 = UUID.randomUUID().toString();
    final String companyName = UUID.randomUUID().toString();
    final String city = UUID.randomUUID().toString();
    final String stateOrProvince = UUID.randomUUID().toString();
    final String country = UUID.randomUUID().toString();
    final String postalCode = UUID.randomUUID().toString();
    final String phone = UUID.randomUUID().toString();
    final String notes = UUID.randomUUID().toString();
    final Boolean isMigrated = true;
    final Boolean isNotifiedForInvoices = false;
    final AccountData data = new DefaultAccount(id, externalKey, email, name, firstNameLength, currency, null, false, billCycleDay, paymentMethodId, timeZone, locale, address1, address2, companyName, city, stateOrProvince, country, postalCode, phone, notes, isMigrated, isNotifiedForInvoices);
    accountUserApi.createAccount(data, callContext);
    final AccountModelDao account = accountDao.getAccountByKey(externalKey, tenantContext);
    Assert.assertEquals(account.getExternalKey(), externalKey);
    Assert.assertEquals(account.getEmail(), email);
    Assert.assertEquals(account.getName(), name);
    Assert.assertEquals(account.getFirstNameLength(), firstNameLength);
    Assert.assertEquals(account.getCurrency(), currency);
    Assert.assertEquals(account.getBillingCycleDayLocal(), (Integer) billCycleDay);
    Assert.assertEquals(account.getPaymentMethodId(), paymentMethodId);
    Assert.assertEquals(account.getTimeZone(), timeZone);
    Assert.assertEquals(account.getLocale(), locale);
    Assert.assertEquals(account.getAddress1(), address1);
    Assert.assertEquals(account.getAddress2(), address2);
    Assert.assertEquals(account.getCompanyName(), companyName);
    Assert.assertEquals(account.getCity(), city);
    Assert.assertEquals(account.getStateOrProvince(), stateOrProvince);
    Assert.assertEquals(account.getCountry(), country);
    Assert.assertEquals(account.getPostalCode(), postalCode);
    Assert.assertEquals(account.getPhone(), phone);
    Assert.assertEquals(account.getMigrated(), isMigrated);
    Assert.assertEquals(account.getIsNotifiedForInvoices(), isNotifiedForInvoices);
}
Also used : AccountModelDao(org.killbill.billing.account.dao.AccountModelDao) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) AccountData(org.killbill.billing.account.api.AccountData) Currency(org.killbill.billing.catalog.api.Currency) UUID(java.util.UUID) DateTimeZone(org.joda.time.DateTimeZone) Test(org.testng.annotations.Test)

Example 12 with AccountModelDao

use of org.killbill.billing.account.dao.AccountModelDao 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());
}
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) AccountApiException(org.killbill.billing.account.api.AccountApiException) AccountCreationInternalEvent(org.killbill.billing.events.AccountCreationInternalEvent) Test(org.testng.annotations.Test)

Example 13 with AccountModelDao

use of org.killbill.billing.account.dao.AccountModelDao 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 14 with AccountModelDao

use of org.killbill.billing.account.dao.AccountModelDao 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)

Example 15 with AccountModelDao

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

Aggregations

AccountModelDao (org.killbill.billing.account.dao.AccountModelDao)15 DefaultAccount (org.killbill.billing.account.api.DefaultAccount)14 Account (org.killbill.billing.account.api.Account)11 Test (org.testng.annotations.Test)9 AccountApiException (org.killbill.billing.account.api.AccountApiException)6 AccountData (org.killbill.billing.account.api.AccountData)6 DefaultMutableAccountData (org.killbill.billing.account.api.DefaultMutableAccountData)6 MutableAccountData (org.killbill.billing.account.api.MutableAccountData)6 AccountTestUtils.createAccountData (org.killbill.billing.account.AccountTestUtils.createAccountData)5 AccountTestUtils.createTestAccount (org.killbill.billing.account.AccountTestUtils.createTestAccount)5 UUID (java.util.UUID)2 DateTime (org.joda.time.DateTime)2 Invoice (org.killbill.billing.invoice.api.Invoice)2 BigDecimal (java.math.BigDecimal)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