Dave Ward 2e826e9e26 Merged V4.0-BUG-FIX to HEAD
35394: ALF-13394: Allow administrators to gain SiteManager role
   35407: ALF-12740: Updated XHR request processing for IE to ensure no caching (had previously thought IE9 was not affected but apparently it is)
   35408: Fix for ALF-13286 who_can_create_site mention and bad error message
   - explicitly declare public interface on SiteService
   35412: Merged DEV to V4.0-BUG-FIX
      35153: ALF-1834: Renaming folders breaks web form content
             Original solution by Ivan has been reimplemented as per Derek's requirements and against 4.0. 
             [DH: Did some minor legibility changes and fixed LF for AVMDiskDriver]
   35414: Incremented version.revision for 4.0.2
   35417: Merged BRANCHES/DEV/THOR0 to BRANCHES/DEV/V4.0-BUG-FIX: (THOR-6 / ALF-13755)
      29356: THOR-6: MT is configured (but not enabled) by default - will be auto-enabled when first tenant is created
      29455: THOR-6: build test/fix
      29471: THOR-6: build test/fix
   35423: Merged BRANCHES/DEV/THOR0 to BRANCHES/DEV/V4.0-BUG-FIX: (THOR-4 / ALF-13756)
      29500: THOR-4: Replace Tenant attributes with Tenant table (alf_tenant)
      29501: THOR-4: Replace Tenant attributes with Tenant table (alf_tenant)
      29503: THOR-4: Replace Tenant attributes with Tenant table (alf_tenant)
      TODO: ALF-13757 - patch to migrate Tenant attributes to Tenant table (for existing customers)
   35431: Merged V3.4-BUG-FIX to V4.0-BUG-FIX
      35367: ALF-13382: WorkflowService Returning Incorrect Values When Using Native jBPM API to set Local Task Variables
      - Fix by Alex Bykov
      35400: Fix for ALF-13557 - Share forms selectmany.ftl template does not work with Share search query parser; should do a logical OR or AND but does a concatenation
      35416: Incremented version.revision for 3.4.10
      35429: Merged V4.0-BUG-FIX to V3.4-BUG-FIX (partial)
         35328: ALF-13409: Avoid concurrency issues in unit test tear downs by deleting users before sites. User deletion deletes invitations synchronously. Site deletion deletes invitations concurrently to avoid UI timeouts. The potential to access invitations that are being concurrently deleted still exists, but always did!
      35430: ALF-13409: Avoid concurrency issues in unit test tear downs by deleting users before sites - another instance.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@35434 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2012-04-19 15:43:03 +00:00

244 lines
8.5 KiB
Java

/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.domain.tenant;
import java.util.List;
import junit.framework.TestCase;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;
/**
* @see TenantAdminDAO
*
* @author janv
* @since 4.0 (thor)
*/
public class TenantAdminDAOTest extends TestCase
{
private ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private TransactionService transactionService;
private RetryingTransactionHelper txnHelper;
private TenantAdminDAO tenantAdminDAO;
@Override
public void setUp() throws Exception
{
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
transactionService = serviceRegistry.getTransactionService();
txnHelper = transactionService.getRetryingTransactionHelper();
tenantAdminDAO = (TenantAdminDAO)ctx.getBean("tenantAdminDAO");
}
private TenantEntity createTenant(final String tenantDomain, final boolean enabled) throws Exception
{
RetryingTransactionCallback<TenantEntity> callback = new RetryingTransactionCallback<TenantEntity>()
{
public TenantEntity execute() throws Throwable
{
TenantEntity tenantEntity = new TenantEntity();
tenantEntity.setTenantDomain(tenantDomain);
tenantEntity.setEnabled(enabled);
return tenantAdminDAO.createTenant(tenantEntity);
}
};
return txnHelper.doInTransaction(callback, false);
}
private void deleteTenant(final String tenantDomain) throws Exception
{
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
tenantAdminDAO.deleteTenant(tenantDomain);
return null;
}
};
txnHelper.doInTransaction(callback, false);
}
private void updateTenant(final TenantUpdateEntity tenantUpdateEntity) throws Exception
{
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
tenantAdminDAO.updateTenant(tenantUpdateEntity);
return null;
}
};
txnHelper.doInTransaction(callback, false);
}
private TenantEntity getTenant(final String tenantDomain) throws Exception
{
RetryingTransactionCallback<TenantEntity> callback = new RetryingTransactionCallback<TenantEntity>()
{
public TenantEntity execute() throws Throwable
{
return tenantAdminDAO.getTenant(tenantDomain);
}
};
return txnHelper.doInTransaction(callback, true);
}
private TenantUpdateEntity getTenantForUpdate(final String tenantDomain) throws Exception
{
RetryingTransactionCallback<TenantUpdateEntity> callback = new RetryingTransactionCallback<TenantUpdateEntity>()
{
public TenantUpdateEntity execute() throws Throwable
{
return tenantAdminDAO.getTenantForUpdate(tenantDomain);
}
};
return txnHelper.doInTransaction(callback, true);
}
private List<TenantEntity> listTenants() throws Exception
{
RetryingTransactionCallback<List<TenantEntity>> callback = new RetryingTransactionCallback<List<TenantEntity>>()
{
public List<TenantEntity> execute() throws Throwable
{
return tenantAdminDAO.listTenants();
}
};
return txnHelper.doInTransaction(callback, true);
}
public void testCreateAndDeleteTenant() throws Exception
{
final String tenantDomain = getName() + "-" + System.currentTimeMillis();
TenantEntity tenantEntity= getTenant(tenantDomain);
assertNull(tenantEntity);
TenantEntity createTenantEntity = createTenant(tenantDomain, false);
assertNotNull(createTenantEntity);
tenantEntity= getTenant(tenantDomain);
assertEquals(createTenantEntity, tenantEntity);
deleteTenant(tenantDomain);
assertNull(getTenant(tenantDomain));
}
public void testCreateTenantWithRollback() throws Exception
{
final String tenantDomain = getName() + "-" + System.currentTimeMillis();
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
createTenant(tenantDomain, false);
// Now force a rollback
throw new RuntimeException("Forced");
}
};
try
{
txnHelper.doInTransaction(callback);
fail("Transaction didn't roll back");
}
catch (RuntimeException e)
{
// Expected
}
// Check that it doesn't exist
assertNull(getTenant(tenantDomain));
}
public void testUpdateTenant() throws Exception
{
final String tenantDomain = getName() + "-" + System.currentTimeMillis();
TenantEntity tenantEntity = getTenant(tenantDomain);
assertNull(tenantEntity);
TenantEntity createTenantEntity = createTenant(tenantDomain, false);
assertNotNull(createTenantEntity);
assertFalse(createTenantEntity.getEnabled());
TenantUpdateEntity tenantUpdateEntity = getTenantForUpdate(tenantDomain);
assertEquals(createTenantEntity, tenantUpdateEntity);
assertFalse(tenantUpdateEntity.getEnabled());
tenantUpdateEntity.setEnabled(true);
updateTenant(tenantUpdateEntity);
tenantEntity = getTenant(tenantDomain);
assertNotNull(tenantEntity);
assertTrue(tenantEntity.getEnabled());
deleteTenant(tenantDomain);
assertNull(getTenant(tenantDomain));
}
public void testListTenants() throws Exception
{
final String tenantDomainPrefix = getName() + "-" + System.currentTimeMillis();
final int cnt = 5;
int beforeCnt = listTenants().size();
for (int i = 1; i <= cnt; i++)
{
String tenantDomain = tenantDomainPrefix + "-" + i;
TenantEntity tenantEntity = getTenant(tenantDomain);
assertNull(tenantEntity);
tenantEntity = createTenant(tenantDomain, false);
assertNotNull(tenantEntity);
assertEquals(i+beforeCnt, listTenants().size());
tenantEntity = getTenant(tenantDomain);
assertNotNull(tenantEntity);
}
for (int i = cnt; i >= 1; i--)
{
String tenantDomain = tenantDomainPrefix + "-" + i;
TenantEntity tenantEntity = getTenant(tenantDomain);
assertNotNull(tenantEntity);
deleteTenant(tenantDomain);
assertEquals(i-1+beforeCnt, listTenants().size());
tenantEntity = getTenant(tenantDomain);
assertNull(tenantEntity);
}
}
}