mirror of
				https://github.com/Alfresco/alfresco-community-repo.git
				synced 2025-10-29 15:21:53 +00:00 
			
		
		
		
	119558 gcornwell: Merged code coverage improvements to 5.1-MC1 (5.1.0)
      r117774 gjames: RA-567: Increase /workflow/processes API code coverage
      r117773 gjames: RA-567: /workflow/processes coverage, removed unused ActivitiTypeConverter
      r116883 gjames: RA-531: reapplied change after merge, for MultiTServiceImpl test coverage
      r116629 gjames: RA-568 Increase /workflow/process-definitions API code coverage
      r116574 gjames: RA-569 Increase /workflow/tasks API code coverage
      r116286 gjames: RA-567: Increase /workflow/processes API code coverage
      r115853 gjames: RA-566: Increasing /people api coverage (description field)
      r115811 gjames: RA-566: Increasing /people api coverage
      r113007 gjames: Adding additional test coverage for DictionaryNamespaceComponent and DynamicNamespacePrefixResolver RA-521
      r113006 gjames: Adding additional test coverage for DictionaryNamespaceComponent and DictionaryComponent RA-514
      r112969 gjames: Adding additional test coverage for TemplateServiceImpl RA-530
      r112960 gjames: Alternative test approach for ModuleServiceImpl RA-520
      r112703 gjames: Adding additional test coverage for NodeLocatorService RA-522
      r112702 gjames: Adding additional test coverage for JobLockServiceImpl RA-516
      r112699 gjames: Adding additional test coverage for ModuleServiceImpl RA-520
      r112508 gjames: Adding additional test coverage for RenditionServiceImpl RA-526
      r112476 gjames: Adding additional test coverage for ContentServiceImpl RA-513
      r112475 gjames: Adding additional test coverage for MimetypeMap RA-519
      r112238 gjames: Adding additional test coverage for MimetypeMap RA-519
      r112237 gjames: Adding additional test coverage for TaggingService RA-529
      r112236 gjames: Adding additional test coverage for MultiTServiceImpl RA-531
      r112206 gjames: Adding additional test coverage for ContentServiceImpl RA-513
      r112167 gcornwell: RA-523: Increase NodeService code coverage (removed redundant code that was testing a version store we no longer use)
      r112102 gjames: Reverted changes to PermissionServiceImpl for RA-524
      r112048 gjames: Temporarily removed some PermissionServiceImpl code. I need to put it back.
      r111620 gjames: Adding additional test coverage for PermissionService RA-524
      r111619 gjames: Added some @Override to make Sonar happier
      r111456 gjames: Adding additional test coverage for AuthenticationService RA-509
      r111427 gjames: Adding additional test coverage for AttributeService RA-509
      r111317 gjames: Adding additional test coverage for WorkflowService RA-533
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@119945 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
		
	
		
			
				
	
	
		
			191 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			191 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| /*
 | |
|  * Copyright (C) 2005-2010 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.template;
 | |
| 
 | |
| import java.io.InputStream;
 | |
| import java.io.StringWriter;
 | |
| import java.util.HashMap;
 | |
| import java.util.Map;
 | |
| 
 | |
| import junit.framework.TestCase;
 | |
| 
 | |
| import org.alfresco.repo.dictionary.DictionaryComponent;
 | |
| import org.alfresco.repo.dictionary.DictionaryDAO;
 | |
| import org.alfresco.repo.dictionary.M2Model;
 | |
| import org.alfresco.repo.node.BaseNodeServiceTest;
 | |
| import org.alfresco.repo.security.authentication.AuthenticationComponent;
 | |
| import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
 | |
| import org.alfresco.service.ServiceRegistry;
 | |
| import org.alfresco.service.cmr.repository.NodeRef;
 | |
| import org.alfresco.service.cmr.repository.NodeService;
 | |
| import org.alfresco.service.cmr.repository.StoreRef;
 | |
| import org.alfresco.service.cmr.repository.TemplateException;
 | |
| import org.alfresco.service.cmr.repository.TemplateService;
 | |
| import org.alfresco.service.transaction.TransactionService;
 | |
| import org.alfresco.test_category.OwnJVMTestsCategory;
 | |
| import org.alfresco.util.ApplicationContextHelper;
 | |
| import org.junit.experimental.categories.Category;
 | |
| import org.springframework.context.ApplicationContext;
 | |
| import org.springframework.extensions.surf.util.I18NUtil;
 | |
| 
 | |
| /**
 | |
|  * @author Kevin Roast
 | |
|  */
 | |
| @Category(OwnJVMTestsCategory.class)
 | |
| public class TemplateServiceImplTest extends TestCase
 | |
| {
 | |
|     private static final String TEMPLATE_1 = "org/alfresco/repo/template/test_template1.ftl";
 | |
|     private static final ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
 | |
|     private NodeRef root_node;
 | |
| 
 | |
|     private TemplateService templateService;
 | |
|     private NodeService nodeService;
 | |
|     private TransactionService transactionService;
 | |
|     private ServiceRegistry serviceRegistry;
 | |
|     private AuthenticationComponent authenticationComponent;
 | |
|     
 | |
|     /*
 | |
|      * @see junit.framework.TestCase#setUp()
 | |
|      */
 | |
|     protected void setUp() throws Exception
 | |
|     {
 | |
|         super.setUp();
 | |
|         
 | |
|         transactionService = (TransactionService)ctx.getBean("transactionComponent");
 | |
|         nodeService = (NodeService)ctx.getBean("nodeService");
 | |
|         templateService = (TemplateService)ctx.getBean("templateService");
 | |
|         serviceRegistry = (ServiceRegistry)ctx.getBean("ServiceRegistry");
 | |
|         
 | |
|         this.authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent");
 | |
|         this.authenticationComponent.setSystemUserAsCurrentUser();
 | |
|         
 | |
|         DictionaryDAO dictionaryDao = (DictionaryDAO)ctx.getBean("dictionaryDAO");
 | |
|         
 | |
|         // load the system model
 | |
|         ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
 | |
|         InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml");
 | |
|         assertNotNull(modelStream);
 | |
|         M2Model model = M2Model.createModel(modelStream);
 | |
|         dictionaryDao.putModel(model);
 | |
|         
 | |
|         // load the test model
 | |
|         modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml");
 | |
|         assertNotNull(modelStream);
 | |
|         model = M2Model.createModel(modelStream);
 | |
|         dictionaryDao.putModel(model);
 | |
|         
 | |
|         DictionaryComponent dictionary = new DictionaryComponent();
 | |
|         dictionary.setDictionaryDAO(dictionaryDao);
 | |
|         BaseNodeServiceTest.loadModel(ctx);
 | |
| 
 | |
|         transactionService.getRetryingTransactionHelper().doInTransaction(
 | |
|                 new RetryingTransactionCallback<Object>()
 | |
|                 {
 | |
|                     @SuppressWarnings("unchecked")
 | |
|                     public Object execute() throws Exception
 | |
|                     {
 | |
|                         StoreRef store = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "template_" + System.currentTimeMillis());
 | |
|                         root_node = nodeService.getRootNode(store);
 | |
|                         BaseNodeServiceTest.buildNodeGraph(nodeService, root_node);
 | |
|                         return null;
 | |
|                     }
 | |
|                 });
 | |
|     }
 | |
| 
 | |
|     @Override
 | |
|     protected void tearDown() throws Exception
 | |
|     {
 | |
|         authenticationComponent.clearCurrentSecurityContext();
 | |
|         super.tearDown();
 | |
|     }
 | |
|     
 | |
|     public void testTemplates()
 | |
|     {
 | |
|         transactionService.getRetryingTransactionHelper().doInTransaction(
 | |
|             new RetryingTransactionCallback<Object>()
 | |
|             {
 | |
|                 @SuppressWarnings("unchecked")
 | |
|                 public Object execute() throws Exception
 | |
|                 {
 | |
| 
 | |
|                     // check the default template engine exists
 | |
|                     assertNotNull(templateService.getTemplateProcessor("freemarker"));
 | |
|                     Map model = createTemplateModel(root_node);
 | |
| 
 | |
|                     // execute on test template
 | |
|                     String output = templateService.processTemplate("freemarker", TEMPLATE_1, model);
 | |
|                     
 | |
|                     // check template contains the expected output
 | |
|                     assertTrue( (output.indexOf(root_node.getId()) != -1) );
 | |
| 
 | |
|                     return null;
 | |
|                 }                
 | |
|             });
 | |
|     }
 | |
| 
 | |
|     private Map createTemplateModel(NodeRef root)
 | |
|     {
 | |
|         // create test model
 | |
|         Map model = new HashMap(7, 1.0f);
 | |
|         model.put("root", new TemplateNode(root, serviceRegistry, null));
 | |
|         return model;
 | |
|     }
 | |
| 
 | |
|     public void testGetTemplateProcessor()
 | |
|     {
 | |
|         assertNotNull(templateService.getTemplateProcessor(null));
 | |
|     }
 | |
| 
 | |
|     public void testProcessTemplate()
 | |
|     {
 | |
|         Map model = createTemplateModel(root_node);
 | |
|         StringWriter writer = new StringWriter();
 | |
|         templateService.processTemplate(TEMPLATE_1, model, writer);
 | |
|         assertTrue( (writer.toString().indexOf(root_node.getId()) != -1) );
 | |
| 
 | |
|         try
 | |
|         {
 | |
|             templateService.processTemplate("NOT_REAL", TEMPLATE_1, model, new StringWriter());
 | |
|             fail("The engine name is nonsense");
 | |
|         } catch (TemplateException expected)
 | |
|         {
 | |
|             //
 | |
|         }
 | |
| 
 | |
|         try
 | |
|         {
 | |
|             templateService.processTemplate("NOT_REAL", TEMPLATE_1, model, I18NUtil.getLocale());
 | |
|             fail("The engine name is nonsense");
 | |
|         } catch (TemplateException expected)
 | |
|         {
 | |
|             //
 | |
|         }
 | |
| 
 | |
|         try
 | |
|         {
 | |
|             templateService.processTemplateString("NOT_REAL", TEMPLATE_1, model, new StringWriter());
 | |
|             fail("The engine name is nonsense");
 | |
|         } catch (TemplateException expected)
 | |
|         {
 | |
|             //
 | |
|         }
 | |
|     }
 | |
|     
 | |
| }
 |