01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.components;
06:
07: import com.opensymphony.webwork.components.Form;
08: import com.opensymphony.webwork.components.TextField;
09: import org.springframework.mock.web.MockHttpServletRequest;
10: import org.springframework.mock.web.MockHttpServletResponse;
11:
12: import com.opensymphony.webwork.WebWorkTestCase;
13: import com.opensymphony.xwork.util.OgnlValueStack;
14:
15: /**
16: *
17: * @author tm_jee
18: * @version $Date: 2007-02-09 03:19:00 +0100 (Fri, 09 Feb 2007) $ $Id: UIBeanTest.java 2843 2007-02-09 02:19:00Z tschneider22 $
19: */
20: public class UIBeanTest extends WebWorkTestCase {
21: public void testPopulateComponentHtmlId1() throws Exception {
22: OgnlValueStack stack = new OgnlValueStack();
23: MockHttpServletRequest req = new MockHttpServletRequest();
24: MockHttpServletResponse res = new MockHttpServletResponse();
25:
26: Form form = new Form(stack, req, res);
27: form.getParameters().put("id", "formId");
28:
29: TextField txtFld = new TextField(stack, req, res);
30: txtFld.setId("txtFldId");
31:
32: txtFld.populateComponentHtmlId(form);
33:
34: assertEquals("txtFldId", txtFld.getParameters().get("id"));
35: }
36:
37: public void testPopulateComponentHtmlId2() throws Exception {
38: OgnlValueStack stack = new OgnlValueStack();
39: MockHttpServletRequest req = new MockHttpServletRequest();
40: MockHttpServletResponse res = new MockHttpServletResponse();
41:
42: Form form = new Form(stack, req, res);
43: form.getParameters().put("id", "formId");
44:
45: TextField txtFld = new TextField(stack, req, res);
46: txtFld.setName("txtFldName");
47:
48: txtFld.populateComponentHtmlId(form);
49:
50: assertEquals("formId_txtFldName", txtFld.getParameters().get(
51: "id"));
52: }
53:
54: public void testPopulateComponentHtmlId3() throws Exception {
55: OgnlValueStack stack = new OgnlValueStack();
56: MockHttpServletRequest req = new MockHttpServletRequest();
57: MockHttpServletResponse res = new MockHttpServletResponse();
58:
59: Form form = new Form(stack, req, res);
60: form.getParameters().put("id", "formId");
61:
62: TextField txtFld = new TextField(stack, req, res);
63: txtFld.setName("%{1 + 1}");
64:
65: txtFld.populateComponentHtmlId(form);
66:
67: assertEquals("formId_2", txtFld.getParameters().get("id"));
68: }
69: }
|