FileDocCategorySizeDatePackage
TemplateEngineManagerTest.javaAPI DocExample4192Mon Jul 23 13:26:16 BST 2007org.apache.struts2.views

TemplateEngineManagerTest

public class TemplateEngineManagerTest extends TestCase
TemplateEngineManagerTest

Fields Summary
org.apache.struts2.components.template.TemplateEngineManager
mgr
com.mockobjects.dynamic.Mock
mockContainer
Constructors Summary
Methods Summary
public voidsetUp()

        mgr = new TemplateEngineManager();
        mockContainer = new Mock(Container.class);
        mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("jsp")), new JspTemplateEngine());
        mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("vm")), new VelocityTemplateEngine());
        mockContainer.matchAndReturn("getInstance", C.args(C.eq(TemplateEngine.class), C.eq("ftl")), new FreemarkerTemplateEngine());
        mockContainer.matchAndReturn("getInstanceNames", C.args(C.eq(TemplateEngine.class)), new HashSet() {{
            add("jsp");
            add("vm");
            add("ftl");
        }});
        
        mgr.setContainer((Container)mockContainer.proxy());
        mgr.setDefaultTemplateType("jsp");
    
protected voidtearDown()

        super.tearDown();
    
public voidtestTemplateTypeFromTemplateNameAndDefaults()

        
        TemplateEngine engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo"), null);
        assertTrue(engine instanceof JspTemplateEngine);
        engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo.vm"), null);
        assertTrue(engine instanceof VelocityTemplateEngine);
    
public voidtestTemplateTypeOverrides()

        TemplateEngine engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo"), "ftl");
        assertTrue(engine instanceof FreemarkerTemplateEngine);
        engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo.vm"), "ftl");
        assertTrue(engine instanceof VelocityTemplateEngine);
        engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo.ftl"), "");
        assertTrue(engine instanceof FreemarkerTemplateEngine);
    
public voidtestTemplateTypeUsesDefaultWhenNotSetInConfiguration()

        mgr.setDefaultTemplateType(null);
        TemplateEngine engine = mgr.getTemplateEngine(new Template("/template", "simple", "foo"), null);
        Template template = new Template("/template", "simple", "foo." + TemplateEngineManager.DEFAULT_TEMPLATE_TYPE);
        TemplateEngine defaultTemplateEngine = mgr.getTemplateEngine(template, null);
        assertTrue(engine.getClass().equals(defaultTemplateEngine.getClass()));