From 91c83aa5eb27428caf4480c45ea0d44f6d57477a Mon Sep 17 00:00:00 2001 From: Jan Vonka Date: Wed, 5 Sep 2007 13:02:08 +0000 Subject: [PATCH] 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 --- .../repo/policy/PolicyComponentTest.java | 55 ++++++++++++++++++- .../PolicyComponentTransactionTest.java | 2 + 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/source/java/org/alfresco/repo/policy/PolicyComponentTest.java b/source/java/org/alfresco/repo/policy/PolicyComponentTest.java index 45773e599d..a903cb1220 100644 --- a/source/java/org/alfresco/repo/policy/PolicyComponentTest.java +++ b/source/java/org/alfresco/repo/policy/PolicyComponentTest.java @@ -27,14 +27,19 @@ package org.alfresco.repo.policy; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; 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.DictionaryComponent; import org.alfresco.repo.dictionary.DictionaryDAOImpl; -import org.alfresco.repo.dictionary.NamespaceDAO; import org.alfresco.repo.dictionary.NamespaceDAOImpl; +import org.alfresco.repo.tenant.SingleTServiceImpl; +import org.alfresco.repo.tenant.TenantService; import org.alfresco.service.namespace.QName; @@ -60,8 +65,13 @@ public class PolicyComponentTest extends TestCase protected void setUp() throws Exception { // 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); + dictionaryDAO.setTenantService(tenantService); + initDictionaryCaches(dictionaryDAO); DictionaryBootstrap bootstrap = new DictionaryBootstrap(); List bootstrapModels = new ArrayList(); @@ -70,6 +80,7 @@ public class PolicyComponentTest extends TestCase bootstrapModels.add(TEST_MODEL); bootstrap.setModels(bootstrapModels); bootstrap.setDictionaryDAO(dictionaryDAO); + bootstrap.setTenantService(new SingleTServiceImpl()); bootstrap.bootstrap(); DictionaryComponent dictionary = new DictionaryComponent(); @@ -79,6 +90,46 @@ public class PolicyComponentTest extends TestCase 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>> uriToModelsCache = new EhCacheAdapter>>(); + EhCacheAdapter uriToModelsCache = new EhCacheAdapter(); + uriToModelsCache.setCache(uriToModelsEhCache); + + dictionaryDAO.setUriToModelsCache(uriToModelsCache); + + Cache compileModelsEhCache = new Cache("compiledModelsCache", 50, false, true, 0L, 0L); + cacheManager.addCache(compileModelsEhCache); + //EhCacheAdapter> compileModelCache = new EhCacheAdapter>(); + 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> urisCache = new EhCacheAdapter>(); + urisCache.setCache(urisEhCache); + + namespaceDAO.setUrisCache(urisCache); + + Cache prefixesEhCache = new Cache("prefixesCache", 50, false, true, 0L, 0L); + cacheManager.addCache(prefixesEhCache); + EhCacheAdapter> prefixesCache = new EhCacheAdapter>(); + prefixesCache.setCache(prefixesEhCache); + + namespaceDAO.setPrefixesCache(prefixesCache); + } public void testJavaBehaviour() { diff --git a/source/java/org/alfresco/repo/policy/PolicyComponentTransactionTest.java b/source/java/org/alfresco/repo/policy/PolicyComponentTransactionTest.java index 4cceaa659f..f0a52d77fc 100644 --- a/source/java/org/alfresco/repo/policy/PolicyComponentTransactionTest.java +++ b/source/java/org/alfresco/repo/policy/PolicyComponentTransactionTest.java @@ -36,6 +36,7 @@ import org.alfresco.repo.dictionary.DictionaryDAO; import org.alfresco.repo.policy.Behaviour.NotificationFrequency; import org.alfresco.repo.policy.Policy.Arg; import org.alfresco.repo.security.authentication.AuthenticationComponent; +import org.alfresco.repo.tenant.TenantService; import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; @@ -68,6 +69,7 @@ public class PolicyComponentTransactionTest extends TestCase bootstrapModels.add(TEST_MODEL); bootstrap.setModels(bootstrapModels); bootstrap.setDictionaryDAO((DictionaryDAO)applicationContext.getBean("dictionaryDAO")); + bootstrap.setTenantService((TenantService)applicationContext.getBean("tenantService")); bootstrap.bootstrap(); // retrieve policy component