View Javadoc

    1   /*
    2    * $Id: FormButtonTest.java 471756 2006-11-06 15:01:43Z husted $
    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: 2006-11-06 10:01:43 -0500 (Mon, 06 Nov 2006) $ $Id: FormButtonTest.java 471756 2006-11-06 15:01:43Z husted $
    33   */
    34  public class FormButtonTest extends StrutsTestCase {
    35
    36      public void testPopulateComponentHtmlId1() throws Exception {
    37          MockHttpServletRequest req = new MockHttpServletRequest();
    38          MockHttpServletResponse res = new MockHttpServletResponse();
    39          ValueStack stack = ValueStackFactory.getFactory().createValueStack();
    40
    41          Form form = new Form(stack, req, res);
    42          form.getParameters().put("id", "formId");
    43
    44          Submit submit = new Submit(stack, req, res);
    45          submit.setId("submitId");
    46
    47          submit.populateComponentHtmlId(form);
    48
    49          assertEquals("submitId", submit.getParameters().get("id"));
    50      }
    51
    52      public void testPopulateComponentHtmlId2() throws Exception {
    53          MockHttpServletRequest req = new MockHttpServletRequest();
    54          MockHttpServletResponse res = new MockHttpServletResponse();
    55          ValueStack stack = ValueStackFactory.getFactory().createValueStack();
    56
    57          Form form = new Form(stack, req, res);
    58          form.getParameters().put("id", "formId");
    59
    60          Submit submit = new Submit(stack, req, res);
    61          submit.setName("submitName");
    62
    63          submit.populateComponentHtmlId(form);
    64
    65          assertEquals("formId_submitName", submit.getParameters().get("id"));
    66      }
    67
    68      public void testPopulateComponentHtmlId3() throws Exception {
    69          MockHttpServletRequest req = new MockHttpServletRequest();
    70          MockHttpServletResponse res = new MockHttpServletResponse();
    71          ValueStack stack = ValueStackFactory.getFactory().createValueStack();
    72
    73          Form form = new Form(stack, req, res);
    74          form.getParameters().put("id", "formId");
    75
    76          Submit submit = new Submit(stack, req, res);
    77          submit.setAction("submitAction");
    78          submit.setMethod("submitMethod");
    79
    80          submit.populateComponentHtmlId(form);
    81
    82          assertEquals("formId_submitAction_submitMethod", submit.getParameters().get("id"));
    83      }
    84
    85      public void testPopulateComponentHtmlId4() throws Exception {
    86          MockHttpServletRequest req = new MockHttpServletRequest();
    87          MockHttpServletResponse res = new MockHttpServletResponse();
    88          ValueStack stack = ValueStackFactory.getFactory().createValueStack();
    89
    90          Submit submit = new Submit(stack, req, res);
    91          submit.setId("submitId");
    92
    93          submit.populateComponentHtmlId(null);
    94
    95          assertEquals("submitId", submit.getParameters().get("id"));
    96      }
    97
    98      public void testPopulateComponentHtmlId5() throws Exception {
    99          MockHttpServletRequest req = new MockHttpServletRequest();
    100         MockHttpServletResponse res = new MockHttpServletResponse();
    101         ValueStack stack = ValueStackFactory.getFactory().createValueStack();
    102
    103         Submit submit = new Submit(stack, req, res);
    104         submit.setName("submitName");
    105
    106         submit.populateComponentHtmlId(null);
    107
    108         assertEquals("submitName", submit.getParameters().get("id"));
    109     }
    110
    111     public void testPopulateComponentHtmlId6() throws Exception {
    112         MockHttpServletRequest req = new MockHttpServletRequest();
    113         MockHttpServletResponse res = new MockHttpServletResponse();
    114         ValueStack stack = ValueStackFactory.getFactory().createValueStack();
    115
    116         Submit submit = new Submit(stack, req, res);
    117         submit.setAction("submitAction");
    118         submit.setMethod("submitMethod");
    119
    120         submit.populateComponentHtmlId(null);
    121
    122         assertEquals("submitAction_submitMethod", submit.getParameters().get("id"));
    123     }
    124 }