Search in sources :

Example 1 with Tenant

use of org.killbill.billing.client.model.gen.Tenant in project killbill by killbill.

the class TestJaxrsBase method createTenant.

protected Tenant createTenant(final String apiKey, final String apiSecret, final boolean useGlobalDefault) throws KillBillClientException {
    callbackServlet.assertListenerStatus();
    callbackServlet.reset();
    loginTenant(apiKey, apiSecret);
    final Tenant tenant = new Tenant();
    tenant.setApiKey(apiKey);
    tenant.setApiSecret(apiSecret);
    requestOptions = requestOptions.extend().withTenantApiKey(apiKey).withTenantApiSecret(apiSecret).build();
    callbackServlet.pushExpectedEvent(ExtBusEventType.TENANT_CONFIG_CHANGE);
    if (!useGlobalDefault) {
        // Catalog
        callbackServlet.pushExpectedEvent(ExtBusEventType.TENANT_CONFIG_CHANGE);
    }
    final Tenant createdTenant = tenantApi.createTenant(tenant, useGlobalDefault, requestOptions);
    // Register tenant for callback
    final String callback = callbackServer.getServletEndpoint();
    tenantApi.registerPushNotificationCallback(callback, requestOptions);
    // Use the flaky version... In the non-happy path, the catalog event sent during tenant creation is received
    // before we had the chance to register our servlet. In this case, instead of 2 events, we will only see one
    // and the flakyAssertListenerStatus will timeout but not fail the test
    callbackServlet.flakyAssertListenerStatus();
    createdTenant.setApiSecret(apiSecret);
    return createdTenant;
}
Also used : Tenant(org.killbill.billing.client.model.gen.Tenant)

Example 2 with Tenant

use of org.killbill.billing.client.model.gen.Tenant in project killbill by killbill.

the class TestTenantFilter method testTenantShouldOnlySeeOwnAccount.

@Test(groups = "slow")
public void testTenantShouldOnlySeeOwnAccount() throws Exception {
    // Try to create an account without being logged-in
    logoutTenant();
    try {
        accountApi.createAccount(getAccount(), requestOptions);
        Assert.fail();
    } catch (final KillBillClientException e) {
        Assert.assertEquals(e.getResponse().getStatusCode(), Status.UNAUTHORIZED.getStatusCode());
    }
    callbackServlet.assertListenerStatus();
    // Create the tenant
    final Tenant tenant1 = createTenant("pierre", "pierreIsFr3nch", true);
    final Account account1 = createAccount();
    Assert.assertEquals(accountApi.getAccountByKey(account1.getExternalKey(), requestOptions), account1);
    logoutTenant();
    // Create another tenant
    createTenant("stephane", "stephane1sAlsoFr3nch", true);
    final Account account2 = createAccount();
    Assert.assertEquals(accountApi.getAccountByKey(account2.getExternalKey(), requestOptions), account2);
    // We should not be able to retrieve the first account as tenant2
    Assert.assertNull(accountApi.getAccountByKey(account1.getExternalKey(), requestOptions));
    // Same for tenant1 and account2
    loginTenant(tenant1.getApiKey(), tenant1.getApiSecret());
    Assert.assertNull(accountApi.getAccountByKey(account2.getExternalKey(), requestOptions));
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Tenant(org.killbill.billing.client.model.gen.Tenant) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 3 with Tenant

use of org.killbill.billing.client.model.gen.Tenant in project killbill by killbill.

the class TestCache method testInvalidateCacheByTenant.

@Test(groups = "slow", description = "Can Invalidate (clear) all Tenant Caches for current Tenant")
public void testInvalidateCacheByTenant() throws Exception {
    // creating a new Tenant for this test
    final Tenant currentTenant = createTenant("testApiKey", "testApiSecret", false);
    // Uploading the test catalog using the new Tenant created before
    callbackServlet.pushExpectedEvent(ExtBusEventType.TENANT_CONFIG_CHANGE);
    final String catalogPath = Resources.getResource("SpyCarAdvanced.xml").getPath();
    final File catalogFile = new File(catalogPath);
    final String body = Files.toString(catalogFile, Charset.forName("UTF-8"));
    catalogApi.uploadCatalogXml(body, requestOptions);
    callbackServlet.assertListenerStatus();
    // creating an Account with PaymentMethod and a Subscription
    createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice("Sports", true);
    // get all caches per tenant level
    final CacheController<String, Long> tenantRecordIdCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT_RECORD_ID);
    final CacheController<String, StateMachineConfig> tenantPaymentStateMachineConfigCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT_PAYMENT_STATE_MACHINE_CONFIG);
    final CacheController<String, org.killbill.billing.tenant.api.Tenant> tenantCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT);
    final CacheController<String, String> tenantKvCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT_KV);
    final CacheController<Long, PerTenantConfig> tenantConfigCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT_CONFIG);
    final CacheController<Long, OverdueConfig> tenantOverdueConfigCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT_OVERDUE_CONFIG);
    final CacheController<Long, List<StaticCatalog>> tenantCatalogCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT_CATALOG);
    // verify that they are not null and have the expected tenant information
    assertTrue(tenantRecordIdCache.isKeyInCache(currentTenant.getTenantId().toString()));
    final Long tenantRecordId = tenantRecordIdCache.get(currentTenant.getTenantId().toString(), null);
    assertTrue(hasKeysByTenantRecordId(tenantPaymentStateMachineConfigCache, tenantRecordId.toString()));
    assertTrue(tenantCache.isKeyInCache(currentTenant.getApiKey()));
    assertTrue(hasKeysByTenantRecordId(tenantKvCache, tenantRecordId.toString()));
    assertTrue(tenantConfigCache.isKeyInCache(tenantRecordId));
    assertTrue(tenantOverdueConfigCache.isKeyInCache(tenantRecordId));
    assertTrue(tenantCatalogCache.isKeyInCache(tenantRecordId));
    // invalidate caches per tenant level
    adminApi.invalidatesCache(null, requestOptions);
    // verify that now the caches don't have the previous values
    assertFalse(tenantRecordIdCache.isKeyInCache(currentTenant.getTenantId().toString()));
    assertFalse(hasKeysByTenantRecordId(tenantPaymentStateMachineConfigCache, tenantRecordId.toString()));
    assertFalse(tenantCache.isKeyInCache(currentTenant.getApiKey()));
    assertFalse(hasKeysByTenantRecordId(tenantKvCache, tenantRecordId.toString()));
    assertFalse(tenantConfigCache.isKeyInCache(tenantRecordId));
    assertFalse(tenantOverdueConfigCache.isKeyInCache(tenantRecordId));
    assertFalse(tenantCatalogCache.isKeyInCache(tenantRecordId));
}
Also used : PerTenantConfig(org.killbill.billing.util.config.tenant.PerTenantConfig) Tenant(org.killbill.billing.client.model.gen.Tenant) StateMachineConfig(org.killbill.automaton.StateMachineConfig) List(java.util.List) OverdueConfig(org.killbill.billing.overdue.api.OverdueConfig) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

Tenant (org.killbill.billing.client.model.gen.Tenant)3 Test (org.testng.annotations.Test)2 File (java.io.File)1 List (java.util.List)1 StateMachineConfig (org.killbill.automaton.StateMachineConfig)1 KillBillClientException (org.killbill.billing.client.KillBillClientException)1 Account (org.killbill.billing.client.model.gen.Account)1 OverdueConfig (org.killbill.billing.overdue.api.OverdueConfig)1 PerTenantConfig (org.killbill.billing.util.config.tenant.PerTenantConfig)1