KickJava   Java API By Example, From Geeks To Geeks.

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


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.FormProcessingAction;
8 import junit.framework.TestCase;
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12
13 public class FormProcessingActionTest extends TestCase {
14
15     HashMap JavaDoc extraContext = new HashMap JavaDoc();
16
17     protected void setUp() throws Exception JavaDoc {
18         super.setUp();
19
20         /*
21         * If miss one of following parameters, execute() in FormProcessingAction
22         * will be not executed and be by-passed, proxy.execute() return result is input.
23         */

24
25         Map parameterMap = new HashMap JavaDoc();
26         parameterMap.put("file", "file");
27         parameterMap.put("checkbox", "checkbox");
28         parameterMap.put("radio", "checkbox");
29         parameterMap.put("textarea", "checkbox");
30         parameterMap.put("password", "password");
31         parameterMap.put("select", "select");
32         parameterMap.put("textfield", "textfield");
33         extraContext.put(ActionContext.PARAMETERS, parameterMap);
34
35         AttributeMap attrMap = new AttributeMap(extraContext);
36         extraContext.put("attr", attrMap);
37     }
38
39
40     public void testSetFile() {
41         try {
42             FormProcessingAction action = execute();
43             System.out.println(action.getFile());
44             assertEquals("file1", action.getFile());
45         } catch (Exception JavaDoc e) {
46             e.printStackTrace();
47         }
48     }
49
50     public void testSetPassword() {
51         try {
52             FormProcessingAction action = execute();
53             assertEquals("password", action.getPassword());
54         } catch (Exception JavaDoc e) {
55             e.printStackTrace();
56         }
57     }
58
59     public void testSetSelect() {
60         try {
61             FormProcessingAction action = execute();
62             assertEquals("select", action.getSelect());
63         } catch (Exception JavaDoc e) {
64             e.printStackTrace();
65         }
66     }
67
68     public void testSetTextfield() {
69         try {
70             FormProcessingAction action = execute();
71             assertEquals("textfield", action.getTextfield());
72         } catch (Exception JavaDoc e) {
73             e.printStackTrace();
74         }
75     }
76
77     /**
78      * Test Customer Method
79      */

80     public void testMyMethod() {
81
82         try {
83             ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("", "formProcessing!myMethod", extraContext);
84             proxy.setExecuteResult(false);
85             System.out.println(proxy.execute());
86             FormProcessingAction action = (FormProcessingAction) proxy.getAction();
87             action.execute();
88             assertEquals("fileHello", action.getFile());
89         } catch (Exception JavaDoc e) {
90             e.printStackTrace();
91         }
92
93     }
94
95     private FormProcessingAction execute() throws Exception JavaDoc {
96         ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("", "formProcessing", extraContext);
97         proxy.setExecuteResult(false);
98         proxy.execute();
99         return (FormProcessingAction) proxy.getAction();
100     }
101
102 }
103
Popular Tags