1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.components;
22
23 import org.apache.struts2.StrutsTestCase;
24 import org.springframework.mock.web.MockHttpServletRequest;
25 import org.springframework.mock.web.MockHttpServletResponse;
26
27 import com.opensymphony.xwork2.util.ValueStack;
28 import com.opensymphony.xwork2.util.ValueStackFactory;
29
30 /***
31 *
32 * @version $Date: 2007-01-20 03:44:14 -0500 (Sat, 20 Jan 2007) $ $Id: UIBeanTest.java 498091 2007-01-20 08:44:14Z mrdon $
33 */
34 public class UIBeanTest extends StrutsTestCase {
35
36 public void testPopulateComponentHtmlId1() throws Exception {
37 ValueStack stack = ValueStackFactory.getFactory().createValueStack();
38 MockHttpServletRequest req = new MockHttpServletRequest();
39 MockHttpServletResponse res = new MockHttpServletResponse();
40
41 Form form = new Form(stack, req, res);
42 form.getParameters().put("id", "formId");
43
44 TextField txtFld = new TextField(stack, req, res);
45 txtFld.setId("txtFldId");
46
47 txtFld.populateComponentHtmlId(form);
48
49 assertEquals("txtFldId", txtFld.getParameters().get("id"));
50 }
51
52 public void testPopulateComponentHtmlIdWithOgnl() throws Exception {
53 ValueStack stack = ValueStackFactory.getFactory().createValueStack();
54 MockHttpServletRequest req = new MockHttpServletRequest();
55 MockHttpServletResponse res = new MockHttpServletResponse();
56
57 Form form = new Form(stack, req, res);
58 form.getParameters().put("id", "formId");
59
60 TextField txtFld = new TextField(stack, req, res);
61 txtFld.setName("txtFldName%{'1'}");
62
63 txtFld.populateComponentHtmlId(form);
64
65 assertEquals("formId_txtFldName1", txtFld.getParameters().get("id"));
66 }
67
68 public void testPopulateComponentHtmlId2() throws Exception {
69 ValueStack stack = ValueStackFactory.getFactory().createValueStack();
70 MockHttpServletRequest req = new MockHttpServletRequest();
71 MockHttpServletResponse res = new MockHttpServletResponse();
72
73 Form form = new Form(stack, req, res);
74 form.getParameters().put("id", "formId");
75
76 TextField txtFld = new TextField(stack, req, res);
77 txtFld.setName("txtFldName");
78
79 txtFld.populateComponentHtmlId(form);
80
81 assertEquals("formId_txtFldName", txtFld.getParameters().get("id"));
82 }
83 }