Search in sources :

Example 1 with TenantModelDao

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

the class TestKillbillJdbcTenantRealm method beforeMethod.

@Override
@BeforeMethod(groups = "slow")
public void beforeMethod() throws Exception {
    super.beforeMethod();
    // Create the tenant
    final DefaultTenantDao tenantDao = new DefaultTenantDao(dbi, clock, cacheControllerDispatcher, new DefaultNonEntityDao(dbi), Mockito.mock(InternalCallContextFactory.class), securityConfig);
    tenant = new DefaultTenant(UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString());
    tenantDao.create(new TenantModelDao(tenant), internalCallContext);
    // Setup the security manager
    final HikariConfig dbConfig = new HikariConfig();
    dbConfig.setJdbcUrl(helper.getJdbcConnectionString());
    dbConfig.setUsername(helper.getUsername());
    dbConfig.setPassword(helper.getPassword());
    final KillbillJdbcTenantRealm jdbcRealm = new KillbillJdbcTenantRealm(shiroDataSource, securityConfig);
    jdbcRealm.setDataSource(new HikariDataSource(dbConfig));
    securityManager = new DefaultSecurityManager(jdbcRealm);
}
Also used : DefaultNonEntityDao(org.killbill.billing.util.dao.DefaultNonEntityDao) DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) HikariDataSource(com.zaxxer.hikari.HikariDataSource) TenantModelDao(org.killbill.billing.tenant.dao.TenantModelDao) HikariConfig(com.zaxxer.hikari.HikariConfig) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) InternalCallContextFactory(org.killbill.billing.util.callcontext.InternalCallContextFactory) DefaultTenantDao(org.killbill.billing.tenant.dao.DefaultTenantDao) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with TenantModelDao

use of org.killbill.billing.tenant.dao.TenantModelDao 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

TenantModelDao (org.killbill.billing.tenant.dao.TenantModelDao)2 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)1 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 DefaultTenant (org.killbill.billing.tenant.api.DefaultTenant)1 DefaultTenantDao (org.killbill.billing.tenant.dao.DefaultTenantDao)1 TenantSqlDao (org.killbill.billing.tenant.dao.TenantSqlDao)1 CallContext (org.killbill.billing.util.callcontext.CallContext)1 InternalCallContextFactory (org.killbill.billing.util.callcontext.InternalCallContextFactory)1 DefaultNonEntityDao (org.killbill.billing.util.dao.DefaultNonEntityDao)1 BeforeMethod (org.testng.annotations.BeforeMethod)1