VelocityResultTestpublic 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 |
Methods Summary |
---|
protected void | setUp()
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 void | testCanResolveLocationUsingOgnl()
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 void | testCanResolveLocationUsingStaticExpression()
TestResult result = new TestResult();
String location = "/any.action";
result.setLocation("${'" + location + "'}");
result.execute(actionInvocation);
assertEquals(location, result.finalLocation);
| public void | testResourcesFoundUsingAbsolutePath()
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 void | testResourcesFoundUsingNames()
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);
|
|