}
@Test
public void testDeleteTenant() {
loginAsSysTenantAdmin();
ITenant mainTenant_1 =
tenantManager.createTenant( systemTenant, MAIN_TENANT_1, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
userRoleDao.createUser( mainTenant_1, USERNAME_ADMIN, PASSWORD, "", new String[]{ tenantAdminRoleName } );
ITenant mainTenant_2 =
tenantManager.createTenant( systemTenant, MAIN_TENANT_2, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
userRoleDao.createUser( mainTenant_2, USERNAME_ADMIN, PASSWORD, "", new String[]{ tenantAdminRoleName } );
ITenant subTenant1_1 = null;
// Testing SubTenant1_1 as a TenantAdmin of MainTenant2. This should fail
login( USERNAME_ADMIN, mainTenant_2, new String[]{ tenantAdminRoleName, tenantAuthenticatedRoleName } );
try {
subTenant1_1 =
tenantManager.createTenant( mainTenant_1, SUB_TENANT1_1, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
fail( "should have thrown an exception" );
} catch ( Throwable th ) {
assertNotNull( th );
}
logout();
login( USERNAME_ADMIN, mainTenant_1, new String[]{ tenantAdminRoleName, tenantAuthenticatedRoleName } );
subTenant1_1 =
tenantManager.createTenant( mainTenant_1, SUB_TENANT1_1, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
userRoleDao.createUser( subTenant1_1, USERNAME_ADMIN, PASSWORD, "", new String[]{ tenantAdminRoleName } );
ITenant subTenant1_1_1 =
tenantManager.createTenant( subTenant1_1, SUB_TENANT1_1_1, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
userRoleDao.createUser( subTenant1_1_1, USERNAME_ADMIN, PASSWORD, "", new String[]{ tenantAdminRoleName } );
ITenant subTenant1_1_2 =
tenantManager.createTenant( subTenant1_1, SUB_TENANT1_1_2, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
userRoleDao.createUser( subTenant1_1_2, USERNAME_ADMIN, PASSWORD, "", new String[]{ tenantAdminRoleName } );
logout();
// Testing SubTenant1_2 as a TenantAdmin of MainTenant2. This should fail
login( USERNAME_ADMIN, mainTenant_2, new String[]{ tenantAdminRoleName, tenantAuthenticatedRoleName } );
ITenant subTenant1_2 = null;
try {
subTenant1_2 =
tenantManager.createTenant( mainTenant_1, SUB_TENANT1_2, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
fail( "should have thrown an exception" );
} catch ( Throwable th ) {
assertNotNull( th );
}
logout();
login( USERNAME_ADMIN, mainTenant_1, new String[]{ tenantAdminRoleName, tenantAuthenticatedRoleName } );
subTenant1_2 =
tenantManager.createTenant( mainTenant_1, SUB_TENANT1_2, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
userRoleDao.createUser( subTenant1_2, USERNAME_ADMIN, PASSWORD, "", new String[]{ tenantAdminRoleName } );
logout();
login( USERNAME_ADMIN, subTenant1_2, new String[]{ tenantAdminRoleName, tenantAuthenticatedRoleName } );
ITenant subTenant1_2_1 =
tenantManager.createTenant( subTenant1_2, SUB_TENANT1_2_1, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
userRoleDao.createUser( subTenant1_2_1, USERNAME_ADMIN, PASSWORD, "", new String[]{ tenantAdminRoleName } );
ITenant subTenant1_2_2 =
tenantManager.createTenant( subTenant1_2, SUB_TENANT1_2_2, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
userRoleDao.createUser( subTenant1_2_2, USERNAME_ADMIN, PASSWORD, "", new String[]{ tenantAdminRoleName } );
logout();
login( USERNAME_ADMIN, mainTenant_2, new String[]{ tenantAdminRoleName, tenantAuthenticatedRoleName } );
ITenant subTenant2_1 =
tenantManager.createTenant( mainTenant_2, SUB_TENANT2_1, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
userRoleDao.createUser( subTenant2_1, USERNAME_ADMIN, PASSWORD, "", new String[]{ tenantAdminRoleName } );
ITenant subTenant2_1_1 =
tenantManager.createTenant( subTenant2_1, SUB_TENANT2_1_1, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
userRoleDao.createUser( subTenant2_1_1, USERNAME_ADMIN, PASSWORD, "", new String[]{ tenantAdminRoleName } );
ITenant subTenant2_1_2 =
tenantManager.createTenant( subTenant2_1, SUB_TENANT2_1_2, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
userRoleDao.createUser( subTenant2_1_2, USERNAME_ADMIN, PASSWORD, "", new String[]{ tenantAdminRoleName } );
logout();
login( USERNAME_ADMIN, mainTenant_1, new String[]{ tenantAdminRoleName, tenantAuthenticatedRoleName } );
ITenant subTenant2_2 = null;
try {
subTenant2_2 =
tenantManager.createTenant( mainTenant_2, SUB_TENANT2_2, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
fail( "should have thrown an exception" );
} catch ( Throwable th ) {
assertNotNull( th );
}
logout();
login( USERNAME_ADMIN, mainTenant_2, new String[]{ tenantAdminRoleName, tenantAuthenticatedRoleName } );
subTenant2_2 =
tenantManager.createTenant( mainTenant_2, SUB_TENANT2_2, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
userRoleDao.createUser( subTenant2_2, USERNAME_ADMIN, PASSWORD, "", new String[]{ tenantAdminRoleName } );
logout();
login( USERNAME_ADMIN, subTenant2_2, new String[]{ tenantAdminRoleName, tenantAuthenticatedRoleName } );
ITenant subTenant2_2_1 =
tenantManager.createTenant( subTenant2_2, SUB_TENANT2_2_1, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
userRoleDao.createUser( subTenant2_2_1, USERNAME_ADMIN, PASSWORD, "", new String[]{ tenantAdminRoleName } );
ITenant subTenant2_2_2 =
tenantManager.createTenant( subTenant2_2, SUB_TENANT2_2_2, tenantAdminRoleName,
tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME );
userRoleDao.createUser( subTenant2_2_2, USERNAME_ADMIN, PASSWORD, "", new String[]{ tenantAdminRoleName } );
// Delete Tenants
login( USERNAME_ADMIN, subTenant2_1, new String[]{ tenantAdminRoleName, tenantAuthenticatedRoleName } );
try {
tenantManager.deleteTenant( subTenant2_1 );
fail( "should have thrown an exception" );
} catch ( Throwable th ) {
assertNotNull( th );
}
logout();
login( USERNAME_ADMIN, mainTenant_2, new String[]{ tenantAdminRoleName, tenantAuthenticatedRoleName } );
tenantManager.deleteTenant( subTenant2_1 );
ITenant tenant = tenantManager.getTenant( subTenant2_1.getRootFolderAbsolutePath() );
assertNull( tenant );
tenant = tenantManager.getTenant( subTenant2_1_1.getRootFolderAbsolutePath() );
assertNull( tenant );
tenant = tenantManager.getTenant( subTenant2_1_2.getRootFolderAbsolutePath() );
assertNull( tenant );