Search in sources :

Example 1 with TenantData

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

Example 2 with TenantData

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

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

the class TenantResource method createTenant.

@TimedResource
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Create a tenant")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Tenant already exists") })
public Response createTenant(final TenantJson json, @QueryParam(QUERY_TENANT_USE_GLOBAL_DEFAULT) @DefaultValue("true") final Boolean useGlobalDefault, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request, @javax.ws.rs.core.Context final UriInfo uriInfo) throws TenantApiException, CatalogApiException {
    verifyNonNullOrEmpty(json, "TenantJson body should be specified");
    verifyNonNullOrEmpty(json.getApiKey(), "TenantJson apiKey needs to be set", json.getApiSecret(), "TenantJson apiSecret needs to be set");
    final TenantData data = json.toTenantData();
    final Tenant tenant = tenantApi.createTenant(data, context.createContext(createdBy, reason, comment, request));
    if (!useGlobalDefault) {
        final CallContext callContext = new DefaultCallContext(tenant.getId(), createdBy, CallOrigin.EXTERNAL, UserType.CUSTOMER, Context.getOrCreateUserToken(), clock);
        catalogUserApi.createDefaultEmptyCatalog(clock.getUTCNow(), callContext);
    }
    return uriBuilder.buildResponse(uriInfo, TenantResource.class, "getTenant", tenant.getId(), request);
}
Also used : Tenant(org.killbill.billing.tenant.api.Tenant) 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) TimedResource(org.killbill.commons.metrics.TimedResource) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with TenantData

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

TenantData (org.killbill.billing.tenant.api.TenantData)4 DefaultTenant (org.killbill.billing.tenant.api.DefaultTenant)3 Tenant (org.killbill.billing.tenant.api.Tenant)3 Test (org.testng.annotations.Test)3 DefaultCallContext (org.killbill.billing.callcontext.DefaultCallContext)2 CallContext (org.killbill.billing.util.callcontext.CallContext)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 TenantApiException (org.killbill.billing.tenant.api.TenantApiException)1 TimedResource (org.killbill.commons.metrics.TimedResource)1