01: /*
02: * $Id: UIBeanTest.java 498091 2007-01-20 08:44:14Z mrdon $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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()
38: .createValueStack();
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.setId("txtFldId");
47:
48: txtFld.populateComponentHtmlId(form);
49:
50: assertEquals("txtFldId", txtFld.getParameters().get("id"));
51: }
52:
53: public void testPopulateComponentHtmlIdWithOgnl() throws Exception {
54: ValueStack stack = ValueStackFactory.getFactory()
55: .createValueStack();
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("txtFldName%{'1'}");
64:
65: txtFld.populateComponentHtmlId(form);
66:
67: assertEquals("formId_txtFldName1", txtFld.getParameters().get(
68: "id"));
69: }
70:
71: public void testPopulateComponentHtmlId2() throws Exception {
72: ValueStack stack = ValueStackFactory.getFactory()
73: .createValueStack();
74: MockHttpServletRequest req = new MockHttpServletRequest();
75: MockHttpServletResponse res = new MockHttpServletResponse();
76:
77: Form form = new Form(stack, req, res);
78: form.getParameters().put("id", "formId");
79:
80: TextField txtFld = new TextField(stack, req, res);
81: txtFld.setName("txtFldName");
82:
83: txtFld.populateComponentHtmlId(form);
84:
85: assertEquals("formId_txtFldName", txtFld.getParameters().get(
86: "id"));
87: }
88: }
|