@Test public void testDuplicateTenantNameNotAllowed() throws Exception { String name = "companyX"; TenantSpecification requestedTenant = new TenantSpecification(name, 10, 100, 1000); TenantWriteRequest addRequest = new TenantWriteRequest(requestedTenant); assertResponseStatus(doPostExternalAPI("/tenants", gson.toJson(addRequest), SUPERADMIN_HEADERS), HttpResponseStatus.OK); assertResponseStatus(doPostExternalAPI("/tenants", gson.toJson(addRequest), SUPERADMIN_HEADERS), HttpResponseStatus.CONFLICT); }
@Test public void testCreateTenantWithTooManyWorkersReturnsConflict() throws Exception { TenantSpecification requestedTenant = new TenantSpecification("companyX", 10000, 100, 1000); TenantWriteRequest addRequest = new TenantWriteRequest(requestedTenant); HttpResponse response = doPostExternalAPI("/tenants", gson.toJson(addRequest), SUPERADMIN_HEADERS); // perform create request assertResponseStatus(response, HttpResponseStatus.CONFLICT); }
@Test public void testBadRequestReturns400() throws Exception { // test malformed requests assertResponseStatus(doPostExternalAPI("/tenants", "{}", SUPERADMIN_HEADERS), HttpResponseStatus.BAD_REQUEST); assertResponseStatus(doPostExternalAPI("/tenants", "", SUPERADMIN_HEADERS), HttpResponseStatus.BAD_REQUEST); // id in object does not match id in path TenantSpecification tenantSpecification = new TenantSpecification("name", 10, 10, 10); assertResponseStatus(doPutExternalAPI("/tenants/10", gson.toJson(tenantSpecification), SUPERADMIN_HEADERS), HttpResponseStatus.BAD_REQUEST); // missing id in object tenantSpecification = new TenantSpecification("name", 10, 10, 10); assertResponseStatus(doPutExternalAPI("/tenants/10", gson.toJson(tenantSpecification), SUPERADMIN_HEADERS), HttpResponseStatus.BAD_REQUEST); }
@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); }
TenantSpecification requestedTenant = new TenantSpecification(name, 10, 100, 1000); TenantWriteRequest tenantWriteRequest = new TenantWriteRequest(requestedTenant, true); HttpResponse response = doPostExternalAPI("/tenants", gson.toJson(tenantWriteRequest), SUPERADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK);
@Test public void testCreateTenant() throws Exception { String name = "companyX"; TenantSpecification requestedTenant = new TenantSpecification(name, 10, 100, 1000); TenantWriteRequest tenantWriteRequest = new TenantWriteRequest(requestedTenant); HttpResponse response = doPostExternalAPI("/tenants", gson.toJson(tenantWriteRequest), SUPERADMIN_HEADERS); // perform create request assertResponseStatus(response, HttpResponseStatus.OK); // make sure tenant was actually written TenantSpecification actualTenant = tenantStore.getTenantByName(name).getSpecification(); Assert.assertEquals(requestedTenant.getName(), actualTenant.getName()); Assert.assertEquals(requestedTenant.getWorkers(), actualTenant.getWorkers()); Assert.assertEquals(requestedTenant.getMaxClusters(), actualTenant.getMaxClusters()); Assert.assertEquals(requestedTenant.getMaxNodes(), actualTenant.getMaxNodes()); }