Search in sources :

Example 1 with DefaultTenant

use of org.killbill.billing.tenant.api.DefaultTenant 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 DefaultTenant

use of org.killbill.billing.tenant.api.DefaultTenant in project killbill by killbill.

the class TestIntegrationWithCatalogUpdate method setupTenant.

private void setupTenant() throws TenantApiException {
    final UUID uuid = UUID.randomUUID();
    final String externalKey = uuid.toString();
    final String apiKey = externalKey + "-Key";
    final String apiSecret = externalKey + "-$3cr3t";
    // Only place where we use callContext
    tenant = tenantUserApi.createTenant(new DefaultTenant(uuid, init, init, externalKey, apiKey, apiSecret), callContext);
    testCallContext = new DefaultCallContext(tenant.getId(), "tester", CallOrigin.EXTERNAL, UserType.TEST, "good reason", "trust me", uuid, clock);
}
Also used : DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) UUID(java.util.UUID)

Example 3 with DefaultTenant

use of org.killbill.billing.tenant.api.DefaultTenant in project killbill by killbill.

the class TestDefaultTenantDao method testTenantKeyValue.

@Test(groups = "slow")
public void testTenantKeyValue() throws Exception {
    final DefaultTenant tenant = new DefaultTenant(UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString());
    tenantDao.create(new TenantModelDao(tenant), internalCallContext);
    tenantDao.addTenantKeyValue("THE_KEY", "TheValue", false, internalCallContext);
    List<String> value = tenantDao.getTenantValueForKey("THE_KEY", internalCallContext);
    Assert.assertEquals(value.size(), 1);
    Assert.assertEquals(value.get(0), "TheValue");
    tenantDao.addTenantKeyValue("THE_KEY", "TheSecondValue", false, internalCallContext);
    value = tenantDao.getTenantValueForKey("THE_KEY", internalCallContext);
    Assert.assertEquals(value.size(), 2);
    value = tenantDao.getTenantValueForKey("THE_KEY", internalCallContext);
    Assert.assertEquals(value.size(), 2);
    tenantDao.deleteTenantKey("THE_KEY", internalCallContext);
    value = tenantDao.getTenantValueForKey("THE_KEY", internalCallContext);
    Assert.assertEquals(value.size(), 0);
}
Also used : DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) Test(org.testng.annotations.Test)

Example 4 with DefaultTenant

use of org.killbill.billing.tenant.api.DefaultTenant in project killbill by killbill.

the class TestDefaultTenantDao method testTenantSearch.

@Test(groups = "slow")
public void testTenantSearch() throws Exception {
    final DefaultTenant tenant = new DefaultTenant(UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString());
    tenantDao.create(new TenantModelDao(tenant), internalCallContext);
    tenantDao.addTenantKeyValue("foobar", "foobar1", false, internalCallContext);
    tenantDao.addTenantKeyValue("foobar", "foobar2", false, internalCallContext);
    tenantDao.addTenantKeyValue("foobar", "foobar3", false, internalCallContext);
    tenantDao.updateTenantLastKeyValue("foo", "foo1", internalCallContext);
    tenantDao.updateTenantLastKeyValue("fooXX", "fooXX1", internalCallContext);
    tenantDao.updateTenantLastKeyValue("bar", "bar", internalCallContext);
    final List<TenantKVModelDao> result = tenantDao.searchTenantKeyValues("foo", internalCallContext);
    Assert.assertEquals(result.size(), 5);
}
Also used : DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) Test(org.testng.annotations.Test)

Example 5 with DefaultTenant

use of org.killbill.billing.tenant.api.DefaultTenant in project killbill by killbill.

the class TestDefaultTenantUserApi method testCreateTenantWithExternalKeyOverLimit.

@Test(groups = "slow", description = "Test Tenant creation with External Key over limit")
public void testCreateTenantWithExternalKeyOverLimit() throws Exception {
    final TenantData tenantdata = new DefaultTenant(UUID.randomUUID(), clock.getUTCNow(), clock.getUTCNow(), "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis,.", "TTR445ee2", "dskjhfs^^54R");
    try {
        tenantUserApi.createTenant(tenantdata, callContext);
        Assert.fail();
    } catch (final TenantApiException e) {
        Assert.assertEquals(e.getCode(), ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED.getCode());
    }
}
Also used : DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) TenantApiException(org.killbill.billing.tenant.api.TenantApiException) TenantData(org.killbill.billing.tenant.api.TenantData) Test(org.testng.annotations.Test)

Aggregations

DefaultTenant (org.killbill.billing.tenant.api.DefaultTenant)9 Test (org.testng.annotations.Test)7 TenantData (org.killbill.billing.tenant.api.TenantData)3 DefaultCallContext (org.killbill.billing.callcontext.DefaultCallContext)2 Tenant (org.killbill.billing.tenant.api.Tenant)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 IOException (java.io.IOException)1 UUID (java.util.UUID)1 AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)1 AuthenticationToken (org.apache.shiro.authc.AuthenticationToken)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)1 TenantApiException (org.killbill.billing.tenant.api.TenantApiException)1 DefaultTenantDao (org.killbill.billing.tenant.dao.DefaultTenantDao)1 TenantModelDao (org.killbill.billing.tenant.dao.TenantModelDao)1 CallContext (org.killbill.billing.util.callcontext.CallContext)1 InternalCallContextFactory (org.killbill.billing.util.callcontext.InternalCallContextFactory)1