1 17 package org.alfresco.repo.template; 18 19 import java.io.InputStream ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 import junit.framework.TestCase; 24 25 import org.alfresco.repo.dictionary.DictionaryComponent; 26 import org.alfresco.repo.dictionary.DictionaryDAO; 27 import org.alfresco.repo.dictionary.M2Model; 28 import org.alfresco.repo.node.BaseNodeServiceTest; 29 import org.alfresco.repo.policy.PolicyComponent; 30 import org.alfresco.repo.security.authentication.AuthenticationComponent; 31 import org.alfresco.repo.transaction.TransactionUtil; 32 import org.alfresco.service.ServiceRegistry; 33 import org.alfresco.service.cmr.repository.ContentService; 34 import org.alfresco.service.cmr.repository.NodeRef; 35 import org.alfresco.service.cmr.repository.NodeService; 36 import org.alfresco.service.cmr.repository.StoreRef; 37 import org.alfresco.service.cmr.repository.TemplateNode; 38 import org.alfresco.service.cmr.repository.TemplateService; 39 import org.alfresco.service.transaction.TransactionService; 40 import org.alfresco.util.ApplicationContextHelper; 41 import org.springframework.context.ApplicationContext; 42 43 46 public class TemplateServiceImplTest extends TestCase 47 { 48 private static final ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); 49 50 private ContentService contentService; 51 private TemplateService templateService; 52 private NodeService nodeService; 53 private TransactionService transactionService; 54 private ServiceRegistry serviceRegistry; 55 private AuthenticationComponent authenticationComponent; 56 57 60 protected void setUp() throws Exception  61 { 62 super.setUp(); 63 64 transactionService = (TransactionService)this.ctx.getBean("transactionComponent"); 65 contentService = (ContentService)this.ctx.getBean("contentService"); 66 nodeService = (NodeService)this.ctx.getBean("nodeService"); 67 templateService = (TemplateService)this.ctx.getBean("templateService"); 68 serviceRegistry = (ServiceRegistry)this.ctx.getBean("ServiceRegistry"); 69 70 this.authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent"); 71 this.authenticationComponent.setSystemUserAsCurrentUser(); 72 73 DictionaryDAO dictionaryDao = (DictionaryDAO)ctx.getBean("dictionaryDAO"); 74 75 ClassLoader cl = BaseNodeServiceTest.class.getClassLoader(); 77 InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml"); 78 assertNotNull(modelStream); 79 M2Model model = M2Model.createModel(modelStream); 80 dictionaryDao.putModel(model); 81 82 modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml"); 84 assertNotNull(modelStream); 85 model = M2Model.createModel(modelStream); 86 dictionaryDao.putModel(model); 87 88 DictionaryComponent dictionary = new DictionaryComponent(); 89 dictionary.setDictionaryDAO(dictionaryDao); 90 BaseNodeServiceTest.loadModel(ctx); 91 } 92 93 @Override  94 protected void tearDown() throws Exception  95 { 96 authenticationComponent.clearCurrentSecurityContext(); 97 super.tearDown(); 98 } 99 100 public void testTemplates() 101 { 102 TransactionUtil.executeInUserTransaction( 103 transactionService, 104 new TransactionUtil.TransactionWork<Object >() 105 { 106 public Object doWork() throws Exception  107 { 108 StoreRef store = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "template_" + System.currentTimeMillis()); 109 NodeRef root = nodeService.getRootNode(store); 110 BaseNodeServiceTest.buildNodeGraph(nodeService, root); 111 112 assertNotNull(templateService.getTemplateProcessor("freemarker")); 114 115 Map model = new HashMap (7, 1.0f); 117 118 model.put("root", new TemplateNode(root, serviceRegistry, null)); 119 120 String output = templateService.processTemplate("freemarker", TEMPLATE_1, model); 122 123 assertTrue( (output.indexOf(root.getId()) != -1) ); 125 126 System.out.print(output); 127 128 return null; 129 } 130 }); 131 } 132 133 private static final String TEMPLATE_1 = "org/alfresco/repo/template/test_template1.ftl"; 134 } 135 | Popular Tags |