Search in sources :

Example 1 with TemplateEngineManager

use of org.apache.struts2.components.template.TemplateEngineManager in project struts by apache.

the class TemplateEngineManagerTest method setUp.

public void setUp() throws Exception {
    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("ftl")), new FreemarkerTemplateEngine());
    mockContainer.matchAndReturn("getInstanceNames", C.args(C.eq(TemplateEngine.class)), new HashSet<String>() {

        {
            add("jsp");
            add("vm");
            add("ftl");
        }
    });
    mgr.setContainer((Container) mockContainer.proxy());
    mgr.setDefaultTemplateType("jsp");
}
Also used : Container(com.opensymphony.xwork2.inject.Container) TemplateEngineManager(org.apache.struts2.components.template.TemplateEngineManager) Mock(com.mockobjects.dynamic.Mock) JspTemplateEngine(org.apache.struts2.components.template.JspTemplateEngine) FreemarkerTemplateEngine(org.apache.struts2.components.template.FreemarkerTemplateEngine)

Example 2 with TemplateEngineManager

use of org.apache.struts2.components.template.TemplateEngineManager in project struts by apache.

the class VelocityTemplateEngineTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    mgr = new TemplateEngineManager();
    Mock 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<String>() {

        {
            add("jsp");
            add("vm");
            add("ftl");
        }
    });
    mgr.setContainer((Container) mockContainer.proxy());
    mgr.setDefaultTemplateType("jsp");
}
Also used : TemplateEngineManager(org.apache.struts2.components.template.TemplateEngineManager) Mock(com.mockobjects.dynamic.Mock) JspTemplateEngine(org.apache.struts2.components.template.JspTemplateEngine) FreemarkerTemplateEngine(org.apache.struts2.components.template.FreemarkerTemplateEngine)

Example 3 with TemplateEngineManager

use of org.apache.struts2.components.template.TemplateEngineManager in project struts by apache.

the class UIBeanTest method testMergeTemplateNullEngineException.

public void testMergeTemplateNullEngineException() {
    ValueStack stack = ActionContext.getContext().getValueStack();
    MockHttpServletRequest req = new MockHttpServletRequest();
    MockHttpServletResponse res = new MockHttpServletResponse();
    // templateEngineManager that returns null as TemplateEngine
    TemplateEngineManager templateEngineManager = new TemplateEngineManager() {

        public TemplateEngine getTemplateEngine(Template template, String templateTypeOverride) {
            return null;
        }
    };
    TextField txtFld = new TextField(stack, req, res);
    txtFld.setTemplateEngineManager(templateEngineManager);
    try {
        txtFld.mergeTemplate(null, new Template(null, null, null));
        fail("Exception not thrown");
    } catch (final Exception e) {
        assertTrue(e instanceof ConfigurationException);
    }
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TemplateEngineManager(org.apache.struts2.components.template.TemplateEngineManager) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) Template(org.apache.struts2.components.template.Template)

Aggregations

TemplateEngineManager (org.apache.struts2.components.template.TemplateEngineManager)3 Mock (com.mockobjects.dynamic.Mock)2 FreemarkerTemplateEngine (org.apache.struts2.components.template.FreemarkerTemplateEngine)2 JspTemplateEngine (org.apache.struts2.components.template.JspTemplateEngine)2 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)1 Container (com.opensymphony.xwork2.inject.Container)1 ValueStack (com.opensymphony.xwork2.util.ValueStack)1 Template (org.apache.struts2.components.template.Template)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1