Fix unit tests / build - when initialising the Dictionary/Namespace services (follow-on to r6675)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6679 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2007-09-05 13:02:08 +00:00
parent 27ef680947
commit 91c83aa5eb
2 changed files with 55 additions and 2 deletions

View File

@@ -27,14 +27,19 @@ package org.alfresco.repo.policy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import junit.framework.TestCase; import junit.framework.TestCase;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import org.alfresco.repo.cache.EhCacheAdapter;
import org.alfresco.repo.dictionary.DictionaryBootstrap; import org.alfresco.repo.dictionary.DictionaryBootstrap;
import org.alfresco.repo.dictionary.DictionaryComponent; import org.alfresco.repo.dictionary.DictionaryComponent;
import org.alfresco.repo.dictionary.DictionaryDAOImpl; import org.alfresco.repo.dictionary.DictionaryDAOImpl;
import org.alfresco.repo.dictionary.NamespaceDAO;
import org.alfresco.repo.dictionary.NamespaceDAOImpl; import org.alfresco.repo.dictionary.NamespaceDAOImpl;
import org.alfresco.repo.tenant.SingleTServiceImpl;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
@@ -60,8 +65,13 @@ public class PolicyComponentTest extends TestCase
protected void setUp() throws Exception protected void setUp() throws Exception
{ {
// Instantiate Dictionary Service // Instantiate Dictionary Service
NamespaceDAO namespaceDAO = new NamespaceDAOImpl(); TenantService tenantService = new SingleTServiceImpl();
NamespaceDAOImpl namespaceDAO = new NamespaceDAOImpl();
namespaceDAO.setTenantService(tenantService);
initNamespaceCaches(namespaceDAO);
DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl(namespaceDAO); DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl(namespaceDAO);
dictionaryDAO.setTenantService(tenantService);
initDictionaryCaches(dictionaryDAO);
DictionaryBootstrap bootstrap = new DictionaryBootstrap(); DictionaryBootstrap bootstrap = new DictionaryBootstrap();
List<String> bootstrapModels = new ArrayList<String>(); List<String> bootstrapModels = new ArrayList<String>();
@@ -70,6 +80,7 @@ public class PolicyComponentTest extends TestCase
bootstrapModels.add(TEST_MODEL); bootstrapModels.add(TEST_MODEL);
bootstrap.setModels(bootstrapModels); bootstrap.setModels(bootstrapModels);
bootstrap.setDictionaryDAO(dictionaryDAO); bootstrap.setDictionaryDAO(dictionaryDAO);
bootstrap.setTenantService(new SingleTServiceImpl());
bootstrap.bootstrap(); bootstrap.bootstrap();
DictionaryComponent dictionary = new DictionaryComponent(); DictionaryComponent dictionary = new DictionaryComponent();
@@ -79,6 +90,46 @@ public class PolicyComponentTest extends TestCase
policyComponent = new PolicyComponentImpl(dictionary); policyComponent = new PolicyComponentImpl(dictionary);
} }
@SuppressWarnings("unchecked")
private void initDictionaryCaches(DictionaryDAOImpl dictionaryDAO)
{
CacheManager cacheManager = new CacheManager();
Cache uriToModelsEhCache = new Cache("uriToModelsCache", 50, false, true, 0L, 0L);
cacheManager.addCache(uriToModelsEhCache);
//EhCacheAdapter<String, Map<String, List<CompiledModel>>> uriToModelsCache = new EhCacheAdapter<String, Map<String, List<CompiledModel>>>();
EhCacheAdapter uriToModelsCache = new EhCacheAdapter();
uriToModelsCache.setCache(uriToModelsEhCache);
dictionaryDAO.setUriToModelsCache(uriToModelsCache);
Cache compileModelsEhCache = new Cache("compiledModelsCache", 50, false, true, 0L, 0L);
cacheManager.addCache(compileModelsEhCache);
//EhCacheAdapter<String, Map<QName,CompiledModel>> compileModelCache = new EhCacheAdapter<String, Map<QName,CompiledModel>>();
EhCacheAdapter compileModelCache = new EhCacheAdapter();
compileModelCache.setCache(compileModelsEhCache);
dictionaryDAO.setCompiledModelsCache(compileModelCache);
}
private void initNamespaceCaches(NamespaceDAOImpl namespaceDAO)
{
CacheManager cacheManager = new CacheManager();
Cache urisEhCache = new Cache("urisCache", 50, false, true, 0L, 0L);
cacheManager.addCache(urisEhCache);
EhCacheAdapter<String, List<String>> urisCache = new EhCacheAdapter<String, List<String>>();
urisCache.setCache(urisEhCache);
namespaceDAO.setUrisCache(urisCache);
Cache prefixesEhCache = new Cache("prefixesCache", 50, false, true, 0L, 0L);
cacheManager.addCache(prefixesEhCache);
EhCacheAdapter<String, Map<String, String>> prefixesCache = new EhCacheAdapter<String, Map<String, String>>();
prefixesCache.setCache(prefixesEhCache);
namespaceDAO.setPrefixesCache(prefixesCache);
}
public void testJavaBehaviour() public void testJavaBehaviour()
{ {

View File

@@ -36,6 +36,7 @@ import org.alfresco.repo.dictionary.DictionaryDAO;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency; import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.Policy.Arg; import org.alfresco.repo.policy.Policy.Arg;
import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
@@ -68,6 +69,7 @@ public class PolicyComponentTransactionTest extends TestCase
bootstrapModels.add(TEST_MODEL); bootstrapModels.add(TEST_MODEL);
bootstrap.setModels(bootstrapModels); bootstrap.setModels(bootstrapModels);
bootstrap.setDictionaryDAO((DictionaryDAO)applicationContext.getBean("dictionaryDAO")); bootstrap.setDictionaryDAO((DictionaryDAO)applicationContext.getBean("dictionaryDAO"));
bootstrap.setTenantService((TenantService)applicationContext.getBean("tenantService"));
bootstrap.bootstrap(); bootstrap.bootstrap();
// retrieve policy component // retrieve policy component