Search in sources :

Example 1 with TenantSqlDao

use of org.killbill.billing.tenant.dao.TenantSqlDao in project killbill by killbill.

the class TestDefaultAccountUserApi method testCreateAccountWithSameExternalKeyInDifferentTenants.

@Test(groups = "slow", description = "Test Account creation with same External Key in different tenants")
public void testCreateAccountWithSameExternalKeyInDifferentTenants() throws Exception {
    final AccountData accountData = createAccountData();
    final Account account1 = accountUserApi.createAccount(accountData, callContext);
    try {
        // Same tenant
        accountUserApi.createAccount(accountData, callContext);
        Assert.fail();
    } catch (final AccountApiException e) {
        assertEquals(e.getCode(), ErrorCode.ACCOUNT_ALREADY_EXISTS.getCode());
    }
    final TenantSqlDao tenantSqlDao = dbi.onDemand(TenantSqlDao.class);
    final TenantModelDao tenant2 = new TenantModelDao();
    tenantSqlDao.create(tenant2, internalCallContext);
    final CallContext callContext2 = new DefaultCallContext(tenant2.getId(), callContext.getUserName(), callContext.getCallOrigin(), callContext.getUserType(), callContext.getUserToken(), clock);
    final Account account2 = accountUserApi.createAccount(accountData, callContext2);
    Assert.assertEquals(account1.getExternalKey(), account2.getExternalKey());
    Assert.assertNotEquals(account1.getId(), account2.getId());
}
Also used : DefaultAccount(org.killbill.billing.account.api.DefaultAccount) AccountTestUtils.createTestAccount(org.killbill.billing.account.AccountTestUtils.createTestAccount) Account(org.killbill.billing.account.api.Account) 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) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) AccountApiException(org.killbill.billing.account.api.AccountApiException) TenantModelDao(org.killbill.billing.tenant.dao.TenantModelDao) TenantSqlDao(org.killbill.billing.tenant.dao.TenantSqlDao) CallContext(org.killbill.billing.util.callcontext.CallContext) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) Test(org.testng.annotations.Test)

Aggregations

AccountTestUtils.createAccountData (org.killbill.billing.account.AccountTestUtils.createAccountData)1 AccountTestUtils.createTestAccount (org.killbill.billing.account.AccountTestUtils.createTestAccount)1 Account (org.killbill.billing.account.api.Account)1 AccountApiException (org.killbill.billing.account.api.AccountApiException)1 AccountData (org.killbill.billing.account.api.AccountData)1 DefaultAccount (org.killbill.billing.account.api.DefaultAccount)1 DefaultMutableAccountData (org.killbill.billing.account.api.DefaultMutableAccountData)1 MutableAccountData (org.killbill.billing.account.api.MutableAccountData)1 DefaultCallContext (org.killbill.billing.callcontext.DefaultCallContext)1 TenantModelDao (org.killbill.billing.tenant.dao.TenantModelDao)1 TenantSqlDao (org.killbill.billing.tenant.dao.TenantSqlDao)1 CallContext (org.killbill.billing.util.callcontext.CallContext)1 Test (org.testng.annotations.Test)1