use of org.killbill.billing.account.api.DefaultAccount in project killbill by killbill.
the class DefaultAccountUserApi method createAccount.
@Override
public Account createAccount(final AccountData data, final CallContext context) throws AccountApiException {
// Not transactional, but there is a db constraint on that column
if (data.getExternalKey() != null && getIdFromKey(data.getExternalKey(), context) != null) {
throw new AccountApiException(ErrorCode.ACCOUNT_ALREADY_EXISTS, data.getExternalKey());
}
final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context);
if (data.getParentAccountId() != null) {
// verify that parent account exists if parentAccountId is not null
getAccountById(data.getParentAccountId(), internalContext);
}
final AccountModelDao account = new AccountModelDao(data);
if (null != account.getExternalKey() && account.getExternalKey().length() > 255) {
throw new AccountApiException(ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED);
}
accountDao.create(account, internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context));
return new DefaultAccount(account);
}
use of org.killbill.billing.account.api.DefaultAccount 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);
}
use of org.killbill.billing.account.api.DefaultAccount in project killbill by killbill.
the class MockAccountDao method updatePaymentMethod.
@Override
public void updatePaymentMethod(final UUID accountId, final UUID paymentMethodId, final InternalCallContext context) throws AccountApiException {
final AccountModelDao currentAccountModelDao = getById(accountId, context);
if (currentAccountModelDao == null) {
throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, accountId);
}
final DefaultAccount currentAccount = new DefaultAccount(currentAccountModelDao);
final DefaultMutableAccountData updatedAccount = new DefaultMutableAccountData(currentAccount);
updatedAccount.setPaymentMethodId(paymentMethodId);
update(new AccountModelDao(accountId, updatedAccount), context);
}
use of org.killbill.billing.account.api.DefaultAccount 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.DefaultAccount in project killbill by killbill.
the class TestDefaultAccountUserApi method testShouldntBeAbleToUpdateExternalKey.
@Test(groups = "slow", expectedExceptions = IllegalArgumentException.class, description = "Test updating Account externalKey throws an exception")
public void testShouldntBeAbleToUpdateExternalKey() throws Exception {
final Account account = createAccount(new DefaultAccount(createTestAccount()));
final MutableAccountData otherAccount = new DefaultAccount(account.getId(), account).toMutableAccountData();
otherAccount.setExternalKey(UUID.randomUUID().toString());
accountUserApi.updateAccount(new DefaultAccount(account.getId(), otherAccount), callContext);
}
Aggregations