Search in sources :

Example 6 with DefaultTenant

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

the class TestDefaultTenantUserApi method testTenant.

@Test(groups = "slow")
public void testTenant() throws Exception {
    final TenantData tenantdata = new DefaultTenant(UUID.randomUUID(), clock.getUTCNow(), clock.getUTCNow(), "er44TT-yy4r", "TTR445ee2", "dskjhfs^^54R");
    tenantUserApi.createTenant(tenantdata, callContext);
    final Tenant tenant = tenantUserApi.getTenantByApiKey(tenantdata.getApiKey());
    Assert.assertEquals(tenant.getApiKey(), tenantdata.getApiKey());
    Assert.assertEquals(tenant.getExternalKey(), tenantdata.getExternalKey());
    // The second time, the value is already in the cache so the TenantCacheLoader is not invoked
    final Tenant tenant2 = tenantUserApi.getTenantByApiKey(tenantdata.getApiKey());
    Assert.assertEquals(tenant2.getApiKey(), tenantdata.getApiKey());
    Assert.assertEquals(tenant2.getExternalKey(), tenantdata.getExternalKey());
}
Also used : DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) Tenant(org.killbill.billing.tenant.api.Tenant) DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) TenantData(org.killbill.billing.tenant.api.TenantData) Test(org.testng.annotations.Test)

Example 7 with DefaultTenant

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

the class TestDefaultTenantDao method testWeCanStoreAndMatchCredentials.

@Test(groups = "slow")
public void testWeCanStoreAndMatchCredentials() 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);
    // Verify we can retrieve it
    Assert.assertEquals(tenantDao.getTenantByApiKey(tenant.getApiKey()).getId(), tenant.getId());
    // Verify we can authenticate against it
    final AuthenticationInfo authenticationInfo = tenantDao.getAuthenticationInfoForTenant(tenant.getId());
    // Good combo
    final AuthenticationToken goodToken = new UsernamePasswordToken(tenant.getApiKey(), tenant.getApiSecret());
    Assert.assertTrue(KillbillCredentialsMatcher.getCredentialsMatcher(securityConfig).doCredentialsMatch(goodToken, authenticationInfo));
    // Bad combo
    final AuthenticationToken badToken = new UsernamePasswordToken(tenant.getApiKey(), tenant.getApiSecret() + "T");
    Assert.assertFalse(KillbillCredentialsMatcher.getCredentialsMatcher(securityConfig).doCredentialsMatch(badToken, authenticationInfo));
}
Also used : DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken) Test(org.testng.annotations.Test)

Example 8 with DefaultTenant

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

the class TestDefaultTenantDao method testTenantKeyValueUpdate.

@Test(groups = "slow")
public void testTenantKeyValueUpdate() 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("MY_KEY", "TheValue1", false, internalCallContext);
    tenantDao.addTenantKeyValue("MY_KEY", "TheValue2", false, internalCallContext);
    tenantDao.addTenantKeyValue("MY_KEY", "TheValue3", false, internalCallContext);
    final List<String> value = tenantDao.getTenantValueForKey("MY_KEY", internalCallContext);
    Assert.assertEquals(value.size(), 3);
    tenantDao.updateTenantLastKeyValue("MY_KEY", "NewValue3", internalCallContext);
    final List<String> newValues = tenantDao.getTenantValueForKey("MY_KEY", internalCallContext);
    Assert.assertEquals(newValues.size(), 3);
    Assert.assertEquals(newValues.get(0), "TheValue1");
    Assert.assertEquals(newValues.get(1), "TheValue2");
    Assert.assertEquals(newValues.get(2), "NewValue3");
}
Also used : DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) Test(org.testng.annotations.Test)

Example 9 with DefaultTenant

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

the class TestPublicBus method testTenantKVChange.

@Test(groups = "slow")
public void testTenantKVChange() throws Exception {
    final TenantData tenantData = new DefaultTenant(null, clock.getUTCNow(), clock.getUTCNow(), "MY_TENANT", "key", "s3Cr3T");
    final CallContext contextWithNoTenant = new DefaultCallContext(null, "loulou", CallOrigin.EXTERNAL, UserType.ADMIN, "no reason", "hum", UUID.randomUUID(), clock);
    final Tenant tenant = tenantUserApi.createTenant(tenantData, contextWithNoTenant);
    final CallContext contextWithTenant = new DefaultCallContext(tenant.getId(), "loulou", CallOrigin.EXTERNAL, UserType.ADMIN, "no reason", "hum", UUID.randomUUID(), clock);
    final String tenantKey = TenantKey.PLUGIN_CONFIG_ + "FOO";
    tenantUserApi.addTenantKeyValue(tenantKey, "FOO", contextWithTenant);
    await().atMost(10, SECONDS).until(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            // expecting  TENANT_CONFIG_CHANGE
            return externalBusCount.get() == 1;
        }
    });
}
Also used : DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) Tenant(org.killbill.billing.tenant.api.Tenant) DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) TenantData(org.killbill.billing.tenant.api.TenantData) CallContext(org.killbill.billing.util.callcontext.CallContext) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) JsonParseException(com.fasterxml.jackson.core.JsonParseException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) 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