TenantManager { public Tenant deleteTenant(EntityManager em, String tenantId, ApplicationManager am) throws Exception { Tenant tenant = getTenant(em, tenantId); if (tenant != null) { EntityTransaction t = em.getTransaction(); try { RulesManager.getInstance().deleteRules(em, tenant, am); TemplateManager.getInstance().deleteTemplates(em, tenant, am); TenantManager.getInstance().deleteApiKeys(em, tenant, am); t.begin(); tenant.setRulesTables(null); tenant.setTemplates(null); em.remove(tenant); em.flush(); t.commit(); return tenant; } catch (Exception e) { if (t.isActive()) { t.rollback(); } logger.log(Level.SEVERE, "Failed to delete tenant:" + tenant, e); throw e; } } else { throw new EntityNotFoundException("Tenant not found"); } } private  TenantManager(); static TenantManager getInstance(); void createTenant(EntityManager em, Tenant tenant); Tenant deleteTenant(EntityManager em, String tenantId, ApplicationManager am); Tenant updateTenant(EntityManager em, String tenantId, String tenantName); List<Tenant> getTenants(EntityManager em, List<String> tenants); Tenant getTenant(EntityManager em, String tenantId); List<Tenant> getTenantsByName(EntityManager em, String tenantName); List<Tenant> getTenants(EntityManager em); void deleteApiKey(EntityManager em, String tenantId, String apiKey, ApplicationManager am); List<ApiKey> getApiKeys(EntityManager em, Tenant tenant); ApiKey getApiKey(EntityManager em, Tenant tenant, String apiKey); void sendApikeyToKafka(ApplicationManager am, String operation, String tenantId, String apiKey); ApiKey updateApiKey(EntityManager em, Tenant tenant, ApiKey key, ApplicationManager am); ApiKey createApiKey(EntityManager em, String tenantId, ApplicationManager am); void deleteApiKeys(EntityManager em, Tenant tenant, ApplicationManager am); static final String CREATED_APIKEY; static final String DISABLED_APIKEY; static final String ENABLED_APIKEY; static final String DELETED_APIKEY; }
@Test public void testDeleteTenant() throws Exception { TenantManager.getInstance().deleteTenant(em, TENANT_ID, am); verify(producer, times(1)).send(any()); }