1 5 package com.opensymphony.webwork.views.jsp; 6 7 import com.opensymphony.webwork.ServletActionContext; 8 import com.opensymphony.webwork.TestAction; 9 import com.opensymphony.webwork.TestConfigurationProvider; 10 import com.opensymphony.xwork.Action; 11 import com.opensymphony.xwork.ActionContext; 12 import com.opensymphony.xwork.config.ConfigurationManager; 13 import com.opensymphony.xwork.util.OgnlValueStack; 14 15 import javax.servlet.jsp.JspException ; 16 17 18 24 public class ActionTagTest extends AbstractTagTest { 25 27 public void testActionTagWithNamespace() { 28 request.setupGetServletPath(TestConfigurationProvider.TEST_NAMESPACE + "/" + "foo.action"); 29 30 ActionTag tag = new ActionTag(); 31 tag.setPageContext(pageContext); 32 tag.setName(TestConfigurationProvider.TEST_NAMESPACE_ACTION); 33 tag.setId(TestConfigurationProvider.TEST_NAMESPACE_ACTION); 34 35 try { 36 tag.doStartTag(); 37 tag.doEndTag(); 38 39 Object o = pageContext.findAttribute(TestConfigurationProvider.TEST_NAMESPACE_ACTION); 40 assertTrue(o instanceof TestAction); 41 42 assertEquals(TestConfigurationProvider.TEST_NAMESPACE, tag.component.getProxy().getNamespace()); 43 } catch (JspException ex) { 44 ex.printStackTrace(); 45 fail(); 46 } 47 } 48 49 public void testSimple() { 50 request.setupGetServletPath("/foo.action"); 51 52 ActionTag tag = new ActionTag(); 53 tag.setPageContext(pageContext); 54 tag.setName("testAction"); 55 tag.setId("testAction"); 56 57 int stackSize = stack.size(); 58 59 try { 60 tag.doStartTag(); 61 tag.addParameter("foo", "myFoo"); 62 tag.doEndTag(); 63 64 assertEquals("myFoo", stack.findValue("#testAction.foo")); 65 assertEquals(stackSize, stack.size()); 66 67 Object o = pageContext.findAttribute("testAction"); 68 assertTrue(o instanceof TestAction); 69 assertEquals("myFoo", ((TestAction) o).getFoo()); 70 assertEquals(Action.SUCCESS, ((TestAction) o).getResult()); 71 } catch (JspException ex) { 72 ex.printStackTrace(); 73 fail(); 74 } 75 } 76 77 public void testSimpleWithoutServletActionContext() { 78 ServletActionContext.setRequest(null); 79 ServletActionContext.setResponse(null); 80 this.testSimple(); 81 } 82 83 protected void setUp() throws Exception { 84 super.setUp(); 85 86 ConfigurationManager.clearConfigurationProviders(); 87 ConfigurationManager.addConfigurationProvider(new TestConfigurationProvider()); 88 ConfigurationManager.getConfiguration().reload(); 89 90 ActionContext actionContext = new ActionContext(context); 91 actionContext.setValueStack(stack); 92 ActionContext.setContext(actionContext); 93 } 94 95 protected void tearDown() throws Exception { 96 ConfigurationManager.destroyConfiguration(); 97 98 OgnlValueStack stack = new OgnlValueStack(); 99 ActionContext.setContext(new ActionContext(stack.getContext())); 100 super.tearDown(); 101 } 102 } 103 | Popular Tags |