001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.components;
006:
007: import com.opensymphony.webwork.components.Form;
008: import com.opensymphony.webwork.components.Submit;
009: import org.springframework.mock.web.MockHttpServletRequest;
010: import org.springframework.mock.web.MockHttpServletResponse;
011:
012: import com.opensymphony.webwork.WebWorkTestCase;
013: import com.opensymphony.xwork.util.OgnlValueStack;
014:
015: /**
016: *
017: * @author tm_jee
018: * @version $Date: 2006-08-13 08:46:35 +0200 (Sun, 13 Aug 2006) $ $Id: FormButtonTest.java 2682 2006-08-13 06:46:35Z tmjee $
019: */
020: public class FormButtonTest extends WebWorkTestCase {
021: public void testPopulateComponentHtmlId1() throws Exception {
022: MockHttpServletRequest req = new MockHttpServletRequest();
023: MockHttpServletResponse res = new MockHttpServletResponse();
024: OgnlValueStack stack = new OgnlValueStack();
025:
026: Form form = new Form(stack, req, res);
027: form.getParameters().put("id", "formId");
028:
029: Submit submit = new Submit(stack, req, res);
030: submit.setId("submitId");
031:
032: submit.populateComponentHtmlId(form);
033:
034: assertEquals("submitId", submit.getParameters().get("id"));
035: }
036:
037: public void testPopulateComponentHtmlId2() throws Exception {
038: MockHttpServletRequest req = new MockHttpServletRequest();
039: MockHttpServletResponse res = new MockHttpServletResponse();
040: OgnlValueStack stack = new OgnlValueStack();
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.setName("submitName");
047:
048: submit.populateComponentHtmlId(form);
049:
050: assertEquals("formId_submitName", submit.getParameters().get(
051: "id"));
052: }
053:
054: public void testPopulateComponentHtmlId3() throws Exception {
055: MockHttpServletRequest req = new MockHttpServletRequest();
056: MockHttpServletResponse res = new MockHttpServletResponse();
057: OgnlValueStack stack = new OgnlValueStack();
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.setAction("submitAction");
064: submit.setMethod("submitMethod");
065:
066: submit.populateComponentHtmlId(form);
067:
068: assertEquals("formId_submitAction_submitMethod", submit
069: .getParameters().get("id"));
070: }
071:
072: public void testPopulateComponentHtmlId4() throws Exception {
073: MockHttpServletRequest req = new MockHttpServletRequest();
074: MockHttpServletResponse res = new MockHttpServletResponse();
075: OgnlValueStack stack = new OgnlValueStack();
076:
077: Submit submit = new Submit(stack, req, res);
078: submit.setId("submitId");
079:
080: submit.populateComponentHtmlId(null);
081:
082: assertEquals("submitId", submit.getParameters().get("id"));
083: }
084:
085: public void testPopulateComponentHtmlId5() throws Exception {
086: MockHttpServletRequest req = new MockHttpServletRequest();
087: MockHttpServletResponse res = new MockHttpServletResponse();
088: OgnlValueStack stack = new OgnlValueStack();
089:
090: Submit submit = new Submit(stack, req, res);
091: submit.setName("submitName");
092:
093: submit.populateComponentHtmlId(null);
094:
095: assertEquals("submitName", submit.getParameters().get("id"));
096: }
097:
098: public void testPopulateComponentHtmlId6() throws Exception {
099: MockHttpServletRequest req = new MockHttpServletRequest();
100: MockHttpServletResponse res = new MockHttpServletResponse();
101: OgnlValueStack stack = new OgnlValueStack();
102:
103: Submit submit = new Submit(stack, req, res);
104: submit.setAction("submitAction");
105: submit.setMethod("submitMethod");
106:
107: submit.populateComponentHtmlId(null);
108:
109: assertEquals("submitAction_submitMethod", submit
110: .getParameters().get("id"));
111: }
112: }
|