TenantHandler extends HttpHandler { @Override protected HttpResponse handleDELETE(HttpRequest request) { final TenantName tenantName = getTenantNameFromRequest(request); Utils.checkThatTenantExists(tenantRepository, tenantName); applicationRepository.deleteTenant(tenantName); return new TenantDeleteResponse(tenantName); } @Inject  TenantHandler(Context ctx, ApplicationRepository applicationRepository);   }
@Test public void testDelete() throws IOException { putSync(HttpRequest.createTestRequest("http: assertEquals(tenantRepository.getTenant(a).getName(), a); TenantDeleteResponse delResp = (TenantDeleteResponse) handler.handleDELETE( HttpRequest.createTestRequest("http: assertResponseEquals(delResp, "{\"message\":\"Tenant a deleted.\"}"); assertNull(tenantRepository.getTenant(a)); }
@Test public void testDeleteTenantWithActiveApplications() { putSync(HttpRequest.createTestRequest("http: Tenant tenant = tenantRepository.getTenant(a); assertEquals(a, tenant.getName()); ApplicationId applicationId = ApplicationId.from(a, ApplicationName.from("foo"), InstanceName.defaultName()); applicationRepository.deploy(testApp, new PrepareParams.Builder().applicationId(applicationId).build()); try { handler.handleDELETE(HttpRequest.createTestRequest("http: fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("Cannot delete tenant 'a', it has active applications: [a.foo]")); } }
@Test(expected=NotFoundException.class) public void testDeleteNonExisting() { handler.handleDELETE(HttpRequest.createTestRequest("http: }