TenantManager { public void createTenant(EntityManager em, Tenant tenant) throws Exception { if (tenant == null) { throw new NullPointerException("Tenant can't be empty"); } EntityTransaction t = em.getTransaction(); try { t.begin(); em.persist(tenant); em.flush(); t.commit(); } catch (Exception e) { if (t.isActive()) { t.rollback(); } logger.log(Level.SEVERE, "Failed to create tenant:" + tenant, e); throw e; } } 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 testCreateTenant() throws Exception { Tenant tenant = new Tenant(); tenant.setTenant_id(TENANT_ID); tenant.setTenant_name("simple-tenant"); TenantManager.getInstance().createTenant(em, tenant); tenant = TenantManager.getInstance().getTenant(em, TENANT_ID); assertEquals(TENANT_ID, tenant.getTenant_id()); }