Search in sources :

Example 11 with MutableAccountData

use of org.killbill.billing.account.api.MutableAccountData 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 12 with MutableAccountData

use of org.killbill.billing.account.api.MutableAccountData 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 13 with MutableAccountData

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

use of org.killbill.billing.account.api.MutableAccountData 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 MutableAccountData

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

the class TestDefaultAccountUserApi method testAccountResetAccountNotes.

@Test(groups = "slow", description = "Test Account update to reset notes")
public void testAccountResetAccountNotes() throws Exception {
    final Account account = createAccount(new DefaultAccount(createTestAccount()));
    // Update the address and leave other fields null
    final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account);
    mutableAccountData.setNotes(null);
    DefaultAccount newAccount = new DefaultAccount(account.getId(), mutableAccountData);
    accountUserApi.updateAccount(newAccount, callContext);
    final Account retrievedAccount = accountUserApi.getAccountById(account.getId(), callContext);
    Assert.assertEquals(retrievedAccount.getName(), account.getName());
    Assert.assertEquals(retrievedAccount.getFirstNameLength(), account.getFirstNameLength());
    Assert.assertEquals(retrievedAccount.getEmail(), account.getEmail());
    Assert.assertEquals(retrievedAccount.getBillCycleDayLocal(), account.getBillCycleDayLocal());
    Assert.assertEquals(retrievedAccount.getCurrency(), account.getCurrency());
    Assert.assertEquals(retrievedAccount.getPaymentMethodId(), account.getPaymentMethodId());
    Assert.assertEquals(retrievedAccount.getTimeZone(), account.getTimeZone());
    Assert.assertEquals(retrievedAccount.getLocale(), account.getLocale());
    Assert.assertEquals(retrievedAccount.getAddress1(), account.getAddress1());
    Assert.assertEquals(retrievedAccount.getAddress2(), account.getAddress2());
    Assert.assertEquals(retrievedAccount.getCompanyName(), account.getCompanyName());
    Assert.assertEquals(retrievedAccount.getCity(), account.getCity());
    Assert.assertEquals(retrievedAccount.getStateOrProvince(), account.getStateOrProvince());
    Assert.assertEquals(retrievedAccount.getPostalCode(), account.getPostalCode());
    Assert.assertEquals(retrievedAccount.getCountry(), account.getCountry());
    Assert.assertEquals(retrievedAccount.getPhone(), account.getPhone());
    Assert.assertEquals(retrievedAccount.isMigrated(), account.isMigrated());
    Assert.assertEquals(retrievedAccount.isNotifiedForInvoices(), account.isNotifiedForInvoices());
    Assert.assertEquals(retrievedAccount.getParentAccountId(), account.getParentAccountId());
    Assert.assertEquals(retrievedAccount.isPaymentDelegatedToParent(), account.isPaymentDelegatedToParent());
    // Finally check account notes did get reset
    Assert.assertNull(retrievedAccount.getNotes());
}
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)

Aggregations

MutableAccountData (org.killbill.billing.account.api.MutableAccountData)16 Account (org.killbill.billing.account.api.Account)15 DefaultAccount (org.killbill.billing.account.api.DefaultAccount)15 DefaultMutableAccountData (org.killbill.billing.account.api.DefaultMutableAccountData)15 Test (org.testng.annotations.Test)14 AccountTestUtils.createTestAccount (org.killbill.billing.account.AccountTestUtils.createTestAccount)13 AccountModelDao (org.killbill.billing.account.dao.AccountModelDao)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 UUID (java.util.UUID)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 AccountTestUtils.createAccountData (org.killbill.billing.account.AccountTestUtils.createAccountData)1 AccountApiException (org.killbill.billing.account.api.AccountApiException)1 AccountData (org.killbill.billing.account.api.AccountData)1 CallContext (org.killbill.billing.util.callcontext.CallContext)1 TimedResource (org.killbill.commons.metrics.TimedResource)1