// Test adding tenants
private void addTenants() throws RegistryException,
org.wso2.carbon.user.api.UserStoreException, FileNotFoundException {
RealmService realmService = ctx.getRealmService();
TenantManager tenantManager = realmService.getTenantManager();
String userMgtXML = getUserManagementConfigurationPath();
RealmConfigXMLProcessor processor = new RealmConfigXMLProcessor();
RealmConfiguration realmConfig = processor.buildRealmConfiguration(new FileInputStream(
userMgtXML));
Tenant tenant = new Tenant();
tenant.setDomain("wso2.org");
tenant.setRealmConfig(realmConfig);
int tenantId = tenantManager.addTenant(tenant);
Tenant tenant2 = (Tenant) tenantManager.getTenant(tenantId);
// checking if the everything is stored.
assertEquals("tenant domain should be equal.", tenant.getDomain(), tenant2.getDomain());
Tenant tenant3 = new Tenant();
tenant3.setDomain("abc.org");
tenant3.setRealmConfig(realmConfig);
tenantManager.addTenant(tenant3);
Tenant[] tenants = (Tenant[]) tenantManager.getAllTenants();
// check the get all tenants
assertEquals("tenants length should be 2", tenants.length, 2);
assertTrue("tenants should contain wso2.org",
(tenants[0].getDomain() + tenants[1].getDomain()).contains("wso2.org"));
assertTrue("tenants should contain abc.org",
(tenants[0].getDomain() + tenants[1].getDomain()).contains("abc.org"));
// if the domain exists
assertTrue("wso2.org should exist", tenantManager.getTenantId("wso2.org") > 0);
assertTrue("pqr.org should not exists", tenantManager.getTenantId("pqr.org") < 0);
int tenantId4 = tenantManager.getTenantId("wso2.org");
assertEquals("tenant domain should be wso2.org", "wso2.org",
tenantManager.getDomain(tenantId4));
// check the update
Tenant tenant4 = (Tenant) tenantManager.getTenant(tenantId4);
tenant4.setDomain("WSO2.com");
tenantManager.updateTenant(tenant4);
// checking the updated values
Tenant tenant5 = (Tenant) tenantManager.getTenant(tenantId4);
assertEquals("tenant domain should be equal.", tenant5.getDomain(), "WSO2.com");
Tenant[] tenants2 = (Tenant[]) tenantManager.getAllTenants();
// check the updated values get all tenants
assertEquals("tenants length should be 2", tenants.length, 2);
assertTrue("tenants should contain WSO2.com",
(tenants2[0].getDomain() + tenants2[1].getDomain()).contains("WSO2.com"));
assertTrue("tenants should contain abc.org",