@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 testWriteTenantWithTooManyWorkersReturnsConflict() throws Exception { // write tenant to store String id = UUID.randomUUID().toString(); String name = "companyX"; Tenant actualTenant = new Tenant(id, new TenantSpecification(name, 10, 100, 1000)); tenantStore.writeTenant(actualTenant); // perform request to write tenant TenantSpecification updatedFields = new TenantSpecification(name, 100000, 100, 500); TenantWriteRequest writeRequest = new TenantWriteRequest(updatedFields); HttpResponse response = doPutExternalAPI("/tenants/" + name, gson.toJson(writeRequest), SUPERADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.CONFLICT); }
@Test public void testWriteTenant() throws Exception { // write tenant to store String id = UUID.randomUUID().toString(); Tenant actualTenant = new Tenant(id, new TenantSpecification("companyX", 10, 100, 1000)); tenantStore.writeTenant(actualTenant); // perform request to write tenant TenantSpecification updatedTenant = new TenantSpecification("companyX", 10, 100, 500); TenantWriteRequest writeRequest = new TenantWriteRequest(updatedTenant); HttpResponse response = doPutExternalAPI("/tenants/" + updatedTenant.getName(), gson.toJson(writeRequest), SUPERADMIN_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Assert.assertEquals(updatedTenant, tenantStore.getTenantByID(actualTenant.getId()).getSpecification()); }
@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); }