KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > test > junit > HelloActionTest


1 package com.test.junit;
2
3 import com.opensymphony.webwork.util.AttributeMap;
4 import com.opensymphony.xwork.ActionContext;
5 import com.opensymphony.xwork.ActionProxy;
6 import com.opensymphony.xwork.ActionProxyFactory;
7 import com.test.HelloAction;
8 import junit.framework.TestCase;
9
10 import java.util.Date JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Map JavaDoc;
13
14 public class HelloActionTest extends TestCase {
15
16     HashMap JavaDoc extraContext = new HashMap JavaDoc();
17
18     protected void setUp() throws Exception JavaDoc {
19         super.setUp();
20
21         Map parameterMap = new HashMap JavaDoc();
22         parameterMap.put("userName", "HenryHu");
23         extraContext.put(ActionContext.PARAMETERS, parameterMap);
24
25         AttributeMap attrMap = new AttributeMap(extraContext);
26         extraContext.put("attr", attrMap);
27     }
28
29     public void testGetUserName() {
30         try {
31             HelloAction action = execute();
32
33             String JavaDoc userName = action.getUserName();
34             assertEquals(userName, "HenryHu");
35         } catch (Throwable JavaDoc e) {
36             e.printStackTrace();
37         }
38     }
39
40     public void testGetNow() {
41         try {
42             HelloAction action = execute();
43
44             Date JavaDoc now = action.getNow();
45             System.out.println(now);
46             assertNotNull(now);
47
48         } catch (Throwable JavaDoc e) {
49             e.printStackTrace();
50         }
51     }
52
53     public void testExecute() {
54         try {
55
56             ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("", "hello", extraContext);
57             proxy.setExecuteResult(false);
58             String JavaDoc result = proxy.execute();
59
60             String JavaDoc userName = ((HelloAction) proxy.getAction()).getUserName();
61             assertEquals(result, "success");
62         } catch (Throwable JavaDoc e) {
63             e.printStackTrace();
64         }
65     }
66
67
68     private HelloAction execute() throws Exception JavaDoc {
69         ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("", "hello", extraContext);
70         proxy.setExecuteResult(false);
71         proxy.execute();
72         return (HelloAction) proxy.getAction();
73     }
74
75 }
Popular Tags