View Javadoc

1   /*
2    * $Id: UIBeanTest.java 498091 2007-01-20 08:44:14Z mrdon $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "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().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  }