FileDocCategorySizeDatePackage
VelocityResultTest.javaAPI DocExample5357Mon Jul 23 13:26:12 BST 2007org.apache.struts2.dispatcher

VelocityResultTest

public class VelocityResultTest extends TestCase

Fields Summary
com.opensymphony.xwork2.ActionInvocation
actionInvocation
com.mockobjects.dynamic.Mock
mockActionProxy
com.opensymphony.xwork2.util.ValueStack
stack
String
namespace
TestVelocityEngine
velocity
VelocityResult
result
Constructors Summary
Methods Summary
protected voidsetUp()

        namespace = "/html";
        result = new VelocityResult();
        stack = ValueStackFactory.getFactory().createValueStack();
        ActionContext.getContext().setValueStack(stack);
        velocity = new TestVelocityEngine();
        mockActionProxy = new Mock(ActionProxy.class);
        mockActionProxy.expectAndReturn("getNamespace", "/html");

        Mock mockActionInvocation = new Mock(ActionInvocation.class);
        mockActionInvocation.expectAndReturn("getProxy", mockActionProxy.proxy());
        mockActionInvocation.expectAndReturn("getStack", stack);
        actionInvocation = (ActionInvocation) mockActionInvocation.proxy();
    
public voidtestCanResolveLocationUsingOgnl()

        TestResult result = new TestResult();

        String location = "/myaction.action";
        Bean bean = new Bean();
        bean.setLocation(location);

        ValueStack stack = ActionContext.getContext().getValueStack();
        stack.push(bean);

        assertEquals(location, stack.findValue("location"));

        result.setLocation("${location}");
        result.execute(actionInvocation);
        assertEquals(location, result.finalLocation);
    
public voidtestCanResolveLocationUsingStaticExpression()

        TestResult result = new TestResult();
        String location = "/any.action";
        result.setLocation("${'" + location + "'}");
        result.execute(actionInvocation);
        assertEquals(location, result.finalLocation);
    
public voidtestResourcesFoundUsingAbsolutePath()

        String location = "/WEB-INF/views/registration.vm";

        Template template = result.getTemplate(stack, velocity, actionInvocation, location, "UTF-8");
        assertNotNull(template);
        assertEquals("expect absolute locations to be handled as is", location, velocity.templateName);
    
public voidtestResourcesFoundUsingNames()

        String location = "Registration.vm";
        String expectedTemplateName = namespace + "/" + location;

        Template template = result.getTemplate(stack, velocity, actionInvocation, location, "UTF-8");
        assertNotNull(template);
        assertEquals("expect the prefix to be appended to the path when the location is not absolute", expectedTemplateName, velocity.templateName);