@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; } }); }
@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, @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 { 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)); return uriBuilder.buildResponse(uriInfo, TenantResource.class, "getTenant", tenant.getId()); }
private void setupTenant() throws TenantApiException { final UUID uuid = UUID.randomUUID(); final String externalKey = uuid.toString(); final String apiKey = externalKey + "-Key"; final String apiSecret = externalKey + "-$3cr3t"; // Only place where we use callContext tenant = tenantUserApi.createTenant( new DefaultTenant(uuid, init, init, externalKey, apiKey, apiSecret), callContext); testCallContext = new DefaultCallContext( tenant.getId(), "tester", CallOrigin.EXTERNAL, UserType.TEST, "good reason", "trust me", uuid, clock); }