@Test public void testMissingObjectReturn404() throws Exception { assertResponseStatus(doGetExternalAPI("/tenants/123", SUPERADMIN_HEADERS), HttpResponseStatus.NOT_FOUND); }
@Test public void testGetTenant() throws Exception { // write tenant to store TenantSpecification spec = new TenantSpecification("companyX", 10, 100, 1000); tenantProvisionerService.writeTenantSpecification(spec); // perform request to get tenant HttpResponse response = doGetExternalAPI("/tenants/" + spec.getName(), SUPERADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Reader reader = new InputStreamReader(response.getEntity().getContent()); Assert.assertEquals(spec, gson.fromJson(reader, TenantSpecification.class)); }
@Test public void testNonSuperadminReturnsError() throws Exception { assertResponseStatus(doGetExternalAPI("/tenants", ADMIN_HEADERS), HttpResponseStatus.NOT_FOUND); assertResponseStatus(doGetExternalAPI("/tenants/123", ADMIN_HEADERS), HttpResponseStatus.NOT_FOUND); assertResponseStatus(doPostExternalAPI("/tenants", "", ADMIN_HEADERS), HttpResponseStatus.NOT_FOUND); assertResponseStatus(doPutExternalAPI("/tenants/123", "", ADMIN_HEADERS), HttpResponseStatus.NOT_FOUND); }
@Test public void testGetAllTenants() throws Exception { // write tenants to store TenantSpecification spec1 = new TenantSpecification("companyX", 2, 100, 1000); TenantSpecification spec2 = new TenantSpecification("companyY", 3, 1000, 10000); tenantProvisionerService.writeTenantSpecification(spec1); tenantProvisionerService.writeTenantSpecification(spec2); // perform request to get tenant HttpResponse response = doGetExternalAPI("/tenants", SUPERADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Reader reader = new InputStreamReader(response.getEntity().getContent()); Set<Tenant> actualTenants = gson.fromJson(reader, new TypeToken<Set<TenantSpecification>>() {}.getType()); Assert.assertEquals(ImmutableSet.of(Tenant.DEFAULT_SUPERADMIN.getSpecification(), spec1, spec2), actualTenants); }