KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > jsp > ActionTagTest


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

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 JavaDoc;
16
17
18 /**
19  * ActionTagTest
20  *
21  * @author Jason Carreira
22  * Created Mar 27, 2003 9:10:27 PM
23  */

24 public class ActionTagTest extends AbstractTagTest {
25     //~ Methods ////////////////////////////////////////////////////////////////
26

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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc {
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 JavaDoc {
96         ConfigurationManager.destroyConfiguration();
97
98         OgnlValueStack stack = new OgnlValueStack();
99         ActionContext.setContext(new ActionContext(stack.getContext()));
100         super.tearDown();
101     }
102 }
103
Popular Tags