KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > actionflow > test > ActionFlowURLToolsTest


1 /*
2  * Copyright (c) 2003-2004, Inversoft, All Rights Reserved
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.controller.actionflow.test;
8
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12
13 import junit.framework.TestCase;
14
15 import com.inversoft.verge.mvc.controller.actionflow.ActionFlowURLTools;
16
17
18 /**
19  * <p>
20  * This class tests the action flow URL tools.
21  * </p>
22  *
23  * @author Brian Pontarelli
24  */

25 public class ActionFlowURLToolsTest extends TestCase {
26
27     /**
28      * Constructs a new <code>FormURLToolsTest</code>.
29      */

30     public ActionFlowURLToolsTest(String JavaDoc name) {
31         super(name);
32     }
33
34
35     /**
36      * Tests the generation of the URL.
37      */

38     public void testGenerateURL() {
39         assertEquals("/mvc/actionflow/n.namespace/f.form/a.action/e.entry",
40             ActionFlowURLTools.generateURL("namespace", "form", "action", "entry"));
41         assertEquals("/mvc/actionflow/n.namespace/f.formName/a.actionName",
42             ActionFlowURLTools.generateURL("namespace", "formName", "actionName", null));
43         assertEquals("/mvc/actionflow/n.namespace/f.form",
44             ActionFlowURLTools.generateURL("namespace", "form", null, null));
45         assertEquals("/mvc/actionflow/n.namespace/a.action",
46             ActionFlowURLTools.generateURL("namespace", null, "action", null));
47         assertEquals("/mvc/actionflow/n.namespace/e.entry",
48             ActionFlowURLTools.generateURL("namespace", null, null, "entry"));
49
50         try {
51             ActionFlowURLTools.generateURL(null, "foo", "bar", "john");
52             fail("Should have failed");
53         } catch (IllegalArgumentException JavaDoc iae) {
54             // Expected
55
}
56     }
57
58     /**
59      * Tests the generation of the submit parameter
60      */

61     public void testSubmitParameter() {
62         String JavaDoc expected = "submitName" + ActionFlowURLTools.MAIN_DELIMITER +
63             "actionName";
64         String JavaDoc actual = ActionFlowURLTools.generateSubmitParameter("submitName",
65             "actionName", null, null);
66         assertEquals(expected, actual);
67
68         expected = "submitName" + ActionFlowURLTools.MAIN_DELIMITER +
69             "actionName" + ActionFlowURLTools.MAIN_DELIMITER + "en=entryName";
70         actual = ActionFlowURLTools.generateSubmitParameter("submitName",
71             "actionName", "entryName", null);
72         assertEquals(expected, actual);
73
74         Map JavaDoc params = new HashMap JavaDoc();
75         params.put("param1", "value1");
76         params.put("param2", "value2");
77         expected = "submitName" + ActionFlowURLTools.MAIN_DELIMITER +
78             "actionName" + ActionFlowURLTools.MAIN_DELIMITER + "param2=value2" +
79             ActionFlowURLTools.SUB_DELIMITER + "param1=value1";
80         actual = ActionFlowURLTools.generateSubmitParameter("submitName",
81             "actionName", null, params);
82         assertEquals(expected, actual);
83
84         params.clear();
85         params.put("param1", "value1");
86         params.put("param2", "value2");
87         expected = "submitName" + ActionFlowURLTools.MAIN_DELIMITER +
88             "actionName" + ActionFlowURLTools.MAIN_DELIMITER + "en=entryName" +
89             ActionFlowURLTools.MAIN_DELIMITER + "param2=value2" +
90             ActionFlowURLTools.SUB_DELIMITER + "param1=value1";
91         actual = ActionFlowURLTools.generateSubmitParameter("submitName",
92             "actionName", "entryName", params);
93         assertEquals(expected, actual);
94     }
95 }
Popular Tags