View Javadoc

1   /*
2    * $Id: FormButtonTest.java 651946 2008-04-27 13:41:38Z apetrelli $
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  
22  package org.apache.struts2.components;
23  
24  import org.apache.struts2.StrutsTestCase;
25  import org.springframework.mock.web.MockHttpServletRequest;
26  import org.springframework.mock.web.MockHttpServletResponse;
27  
28  import com.opensymphony.xwork2.ActionContext;
29  import com.opensymphony.xwork2.util.ValueStack;
30  import com.opensymphony.xwork2.util.ValueStackFactory;
31  
32  /***
33   *
34   * @version $Date: 2008-04-27 13:41:38 +0000 (Sun, 27 Apr 2008) $ $Id: FormButtonTest.java 651946 2008-04-27 13:41:38Z apetrelli $
35   */
36  public class FormButtonTest extends StrutsTestCase {
37  
38      public void testPopulateComponentHtmlId1() throws Exception {
39          MockHttpServletRequest req = new MockHttpServletRequest();
40          MockHttpServletResponse res = new MockHttpServletResponse();
41          ValueStack stack = ActionContext.getContext().getValueStack();
42  
43          Form form = new Form(stack, req, res);
44          form.getParameters().put("id", "formId");
45  
46          Submit submit = new Submit(stack, req, res);
47          submit.setId("submitId");
48  
49          submit.populateComponentHtmlId(form);
50  
51          assertEquals("submitId", submit.getParameters().get("id"));
52      }
53  
54      public void testPopulateComponentHtmlId2() throws Exception {
55          MockHttpServletRequest req = new MockHttpServletRequest();
56          MockHttpServletResponse res = new MockHttpServletResponse();
57          ValueStack stack = ActionContext.getContext().getValueStack();
58  
59          Form form = new Form(stack, req, res);
60          form.getParameters().put("id", "formId");
61  
62          Submit submit = new Submit(stack, req, res);
63          submit.setName("submitName");
64  
65          submit.populateComponentHtmlId(form);
66  
67          assertEquals("formId_submitName", submit.getParameters().get("id"));
68      }
69  
70      public void testPopulateComponentHtmlId3() throws Exception {
71          MockHttpServletRequest req = new MockHttpServletRequest();
72          MockHttpServletResponse res = new MockHttpServletResponse();
73          ValueStack stack = ActionContext.getContext().getValueStack();
74  
75          Form form = new Form(stack, req, res);
76          form.getParameters().put("id", "formId");
77  
78          Submit submit = new Submit(stack, req, res);
79          submit.setAction("submitAction");
80          submit.setMethod("submitMethod");
81  
82          submit.populateComponentHtmlId(form);
83  
84          assertEquals("formId_submitAction_submitMethod", submit.getParameters().get("id"));
85      }
86  
87      public void testPopulateComponentHtmlId4() throws Exception {
88          MockHttpServletRequest req = new MockHttpServletRequest();
89          MockHttpServletResponse res = new MockHttpServletResponse();
90          ValueStack stack = ActionContext.getContext().getValueStack();
91  
92          Submit submit = new Submit(stack, req, res);
93          submit.setId("submitId");
94  
95          submit.populateComponentHtmlId(null);
96  
97          assertEquals("submitId", submit.getParameters().get("id"));
98      }
99  
100     public void testPopulateComponentHtmlId5() throws Exception {
101         MockHttpServletRequest req = new MockHttpServletRequest();
102         MockHttpServletResponse res = new MockHttpServletResponse();
103         ValueStack stack = ActionContext.getContext().getValueStack();
104 
105         Submit submit = new Submit(stack, req, res);
106         submit.setName("submitName");
107 
108         submit.populateComponentHtmlId(null);
109 
110         assertEquals("submitName", submit.getParameters().get("id"));
111     }
112 
113     public void testPopulateComponentHtmlId6() throws Exception {
114         MockHttpServletRequest req = new MockHttpServletRequest();
115         MockHttpServletResponse res = new MockHttpServletResponse();
116         ValueStack stack = ActionContext.getContext().getValueStack();
117 
118         Submit submit = new Submit(stack, req, res);
119         submit.setAction("submitAction");
120         submit.setMethod("submitMethod");
121 
122         submit.populateComponentHtmlId(null);
123 
124         assertEquals("submitAction_submitMethod", submit.getParameters().get("id"));
125     }
126 }