Search in sources :

Example 36 with AccountData

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());
}
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 37 with AccountData

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);
}
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 38 with AccountData

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

Example 39 with AccountData

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

Example 40 with AccountData

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);
}
Also used : AccountData(org.killbill.billing.account.api.AccountData) PaymentMethodPlugin(org.killbill.billing.payment.api.PaymentMethodPlugin)

Aggregations

AccountData (org.killbill.billing.account.api.AccountData)54 Test (org.testng.annotations.Test)49 Account (org.killbill.billing.account.api.Account)47 LocalDate (org.joda.time.LocalDate)38 BigDecimal (java.math.BigDecimal)33 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)30 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)26 Invoice (org.killbill.billing.invoice.api.Invoice)19 ArrayList (java.util.ArrayList)17 Payment (org.killbill.billing.payment.api.Payment)14 DateTime (org.joda.time.DateTime)11 MutableAccountData (org.killbill.billing.account.api.MutableAccountData)9 DefaultAccount (org.killbill.billing.account.api.DefaultAccount)8 DefaultMutableAccountData (org.killbill.billing.account.api.DefaultMutableAccountData)8 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)8 Entitlement (org.killbill.billing.entitlement.api.Entitlement)8 ExpectedPaymentCheck (org.killbill.billing.beatrix.util.PaymentChecker.ExpectedPaymentCheck)7 MockAccountBuilder (org.killbill.billing.mock.MockAccountBuilder)7 DateTimeZone (org.joda.time.DateTimeZone)6 AccountTestUtils.createAccountData (org.killbill.billing.account.AccountTestUtils.createAccountData)6