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