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());
}
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));
}
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");
}
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;
}
});
}
Aggregations