001: /*
002: * $Id: FormButtonTest.java 471756 2006-11-06 15:01:43Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.components;
022:
023: import org.apache.struts2.StrutsTestCase;
024: import org.springframework.mock.web.MockHttpServletRequest;
025: import org.springframework.mock.web.MockHttpServletResponse;
026:
027: import com.opensymphony.xwork2.util.ValueStack;
028: import com.opensymphony.xwork2.util.ValueStackFactory;
029:
030: /**
031: *
032: * @version $Date: 2006-11-06 10:01:43 -0500 (Mon, 06 Nov 2006) $ $Id: FormButtonTest.java 471756 2006-11-06 15:01:43Z husted $
033: */
034: public class FormButtonTest extends StrutsTestCase {
035:
036: public void testPopulateComponentHtmlId1() throws Exception {
037: MockHttpServletRequest req = new MockHttpServletRequest();
038: MockHttpServletResponse res = new MockHttpServletResponse();
039: ValueStack stack = ValueStackFactory.getFactory()
040: .createValueStack();
041:
042: Form form = new Form(stack, req, res);
043: form.getParameters().put("id", "formId");
044:
045: Submit submit = new Submit(stack, req, res);
046: submit.setId("submitId");
047:
048: submit.populateComponentHtmlId(form);
049:
050: assertEquals("submitId", submit.getParameters().get("id"));
051: }
052:
053: public void testPopulateComponentHtmlId2() throws Exception {
054: MockHttpServletRequest req = new MockHttpServletRequest();
055: MockHttpServletResponse res = new MockHttpServletResponse();
056: ValueStack stack = ValueStackFactory.getFactory()
057: .createValueStack();
058:
059: Form form = new Form(stack, req, res);
060: form.getParameters().put("id", "formId");
061:
062: Submit submit = new Submit(stack, req, res);
063: submit.setName("submitName");
064:
065: submit.populateComponentHtmlId(form);
066:
067: assertEquals("formId_submitName", submit.getParameters().get(
068: "id"));
069: }
070:
071: public void testPopulateComponentHtmlId3() throws Exception {
072: MockHttpServletRequest req = new MockHttpServletRequest();
073: MockHttpServletResponse res = new MockHttpServletResponse();
074: ValueStack stack = ValueStackFactory.getFactory()
075: .createValueStack();
076:
077: Form form = new Form(stack, req, res);
078: form.getParameters().put("id", "formId");
079:
080: Submit submit = new Submit(stack, req, res);
081: submit.setAction("submitAction");
082: submit.setMethod("submitMethod");
083:
084: submit.populateComponentHtmlId(form);
085:
086: assertEquals("formId_submitAction_submitMethod", submit
087: .getParameters().get("id"));
088: }
089:
090: public void testPopulateComponentHtmlId4() throws Exception {
091: MockHttpServletRequest req = new MockHttpServletRequest();
092: MockHttpServletResponse res = new MockHttpServletResponse();
093: ValueStack stack = ValueStackFactory.getFactory()
094: .createValueStack();
095:
096: Submit submit = new Submit(stack, req, res);
097: submit.setId("submitId");
098:
099: submit.populateComponentHtmlId(null);
100:
101: assertEquals("submitId", submit.getParameters().get("id"));
102: }
103:
104: public void testPopulateComponentHtmlId5() throws Exception {
105: MockHttpServletRequest req = new MockHttpServletRequest();
106: MockHttpServletResponse res = new MockHttpServletResponse();
107: ValueStack stack = ValueStackFactory.getFactory()
108: .createValueStack();
109:
110: Submit submit = new Submit(stack, req, res);
111: submit.setName("submitName");
112:
113: submit.populateComponentHtmlId(null);
114:
115: assertEquals("submitName", submit.getParameters().get("id"));
116: }
117:
118: public void testPopulateComponentHtmlId6() throws Exception {
119: MockHttpServletRequest req = new MockHttpServletRequest();
120: MockHttpServletResponse res = new MockHttpServletResponse();
121: ValueStack stack = ValueStackFactory.getFactory()
122: .createValueStack();
123:
124: Submit submit = new Submit(stack, req, res);
125: submit.setAction("submitAction");
126: submit.setMethod("submitMethod");
127:
128: submit.populateComponentHtmlId(null);
129:
130: assertEquals("submitAction_submitMethod", submit
131: .getParameters().get("id"));
132: }
133: }
|