001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.views.jsp.ui;
006:
007: import java.util.ArrayList;
008: import java.util.Collections;
009: import java.util.LinkedHashMap;
010: import java.util.List;
011: import java.util.Map;
012:
013: import com.opensymphony.webwork.views.jsp.AbstractUITagTest;
014: import com.opensymphony.webwork.views.jsp.ParamTag;
015: import com.opensymphony.xwork.Action;
016: import com.opensymphony.xwork.ActionSupport;
017:
018: /**
019: * FieldError Tag Test Case.
020: *
021: * @author tm_jee
022: * @version $Date: 2006-02-25 11:56:53 +0100 (Sat, 25 Feb 2006) $ $Id: FieldErrorTagTest.java 2262 2006-02-25 10:56:53Z tmjee $
023: */
024: public class FieldErrorTagTest extends AbstractUITagTest {
025:
026: public void testWithoutParamsWithFieldErrors() throws Exception {
027: FieldErrorTag tag = new FieldErrorTag();
028: ((InternalAction) action).setHaveFieldErrors(true);
029: tag.setPageContext(pageContext);
030: tag.doStartTag();
031: tag.doEndTag();
032:
033: verify(FieldErrorTagTest.class.getResource("fielderror-1.txt"));
034: }
035:
036: public void testWithoutParamsWithoutFieldErrors() throws Exception {
037: FieldErrorTag tag = new FieldErrorTag();
038: ((InternalAction) action).setHaveFieldErrors(false);
039: tag.setPageContext(pageContext);
040: tag.doStartTag();
041: tag.doEndTag();
042:
043: verify(FieldErrorTagTest.class.getResource("fielderror-2.txt"));
044: }
045:
046: public void testWithParamsWithFieldErrors1() throws Exception {
047: FieldErrorTag tag = new FieldErrorTag();
048: ((InternalAction) action).setHaveFieldErrors(true);
049: tag.setPageContext(pageContext);
050: tag.doStartTag();
051: ParamTag pTag1 = new ParamTag();
052: pTag1.setPageContext(pageContext);
053: pTag1.setValue("%{'field1'}");
054: pTag1.doStartTag();
055: pTag1.doEndTag();
056:
057: ParamTag pTag2 = new ParamTag();
058: pTag2.setPageContext(pageContext);
059: pTag2.setValue("%{'field3'}");
060: pTag2.doStartTag();
061: pTag2.doEndTag();
062:
063: tag.doEndTag();
064:
065: verify(FieldErrorTagTest.class.getResource("fielderror-3.txt"));
066: }
067:
068: public void testWithParamsWithFieldErrors2() throws Exception {
069: FieldErrorTag tag = new FieldErrorTag();
070: ((InternalAction) action).setHaveFieldErrors(true);
071: tag.setPageContext(pageContext);
072: tag.doStartTag();
073: ParamTag pTag1 = new ParamTag();
074: pTag1.setPageContext(pageContext);
075: pTag1.setValue("%{'field1'}");
076: pTag1.doStartTag();
077: pTag1.doEndTag();
078:
079: ParamTag pTag2 = new ParamTag();
080: pTag2.setPageContext(pageContext);
081: pTag2.setValue("%{'field2'}");
082: pTag2.doStartTag();
083: pTag2.doEndTag();
084:
085: tag.doEndTag();
086:
087: verify(FieldErrorTagTest.class.getResource("fielderror-4.txt"));
088: }
089:
090: public void testWithParamsWithFieldErrors3() throws Exception {
091: FieldErrorTag tag = new FieldErrorTag();
092: ((InternalAction) action).setHaveFieldErrors(true);
093: tag.setPageContext(pageContext);
094: tag.doStartTag();
095: ParamTag pTag1 = new ParamTag();
096: pTag1.setPageContext(pageContext);
097: pTag1.setValue("%{'field2'}");
098: pTag1.doStartTag();
099: pTag1.doEndTag();
100:
101: tag.doEndTag();
102:
103: verify(FieldErrorTagTest.class.getResource("fielderror-5.txt"));
104: }
105:
106: public void testWithParamsWithoutFieldErrors1() throws Exception {
107: FieldErrorTag tag = new FieldErrorTag();
108: ((InternalAction) action).setHaveFieldErrors(false);
109: tag.setPageContext(pageContext);
110: tag.doStartTag();
111: ParamTag pTag1 = new ParamTag();
112: pTag1.setPageContext(pageContext);
113: pTag1.setValue("%{'field1'}");
114: pTag1.doStartTag();
115: pTag1.doEndTag();
116:
117: ParamTag pTag2 = new ParamTag();
118: pTag2.setPageContext(pageContext);
119: pTag2.setValue("%{'field3'}");
120: pTag2.doStartTag();
121: pTag2.doEndTag();
122: tag.doEndTag();
123:
124: verify(FieldErrorTagTest.class.getResource("fielderror-2.txt"));
125: }
126:
127: public void testWithParamsWithoutFieldErrors2() throws Exception {
128: FieldErrorTag tag = new FieldErrorTag();
129: ((InternalAction) action).setHaveFieldErrors(false);
130: tag.setPageContext(pageContext);
131: tag.doStartTag();
132: ParamTag pTag1 = new ParamTag();
133: pTag1.setPageContext(pageContext);
134: pTag1.setValue("%{'field1'}");
135: pTag1.doStartTag();
136: pTag1.doEndTag();
137:
138: ParamTag pTag2 = new ParamTag();
139: pTag2.setPageContext(pageContext);
140: pTag2.setValue("%{'field3'}");
141: pTag2.doStartTag();
142: pTag2.doEndTag();
143: tag.doEndTag();
144:
145: verify(FieldErrorTagTest.class.getResource("fielderror-2.txt"));
146: }
147:
148: public void testWithParamsWithoutFieldErrors3() throws Exception {
149: FieldErrorTag tag = new FieldErrorTag();
150: ((InternalAction) action).setHaveFieldErrors(false);
151: tag.setPageContext(pageContext);
152: tag.doStartTag();
153: ParamTag pTag1 = new ParamTag();
154: pTag1.setPageContext(pageContext);
155: pTag1.setValue("%{'field2'}");
156: pTag1.doStartTag();
157: pTag1.doEndTag();
158:
159: tag.doEndTag();
160:
161: verify(FieldErrorTagTest.class.getResource("fielderror-2.txt"));
162: }
163:
164: public void testWithNullFieldErrors() throws Exception {
165: FieldErrorTag tag = new FieldErrorTag();
166: ((InternalAction) action).setHaveFieldErrors(false);
167: ((InternalAction) action).setReturnNullForFieldErrors(true);
168: tag.setPageContext(pageContext);
169: tag.doStartTag();
170: ParamTag pTag1 = new ParamTag();
171: pTag1.setPageContext(pageContext);
172: pTag1.setValue("%{'field2'}");
173: pTag1.doStartTag();
174: pTag1.doEndTag();
175:
176: tag.doEndTag();
177:
178: verify(FieldErrorTagTest.class.getResource("fielderror-2.txt"));
179: }
180:
181: public Action getAction() {
182: return new InternalAction();
183: }
184:
185: public class InternalAction extends ActionSupport {
186:
187: private boolean haveFieldErrors = false;
188: private boolean returnNullForFieldErrors = false;
189:
190: public void setHaveFieldErrors(boolean haveFieldErrors) {
191: this .haveFieldErrors = haveFieldErrors;
192: }
193:
194: public void setReturnNullForFieldErrors(
195: boolean returnNullForFieldErrors) {
196: this .returnNullForFieldErrors = returnNullForFieldErrors;
197: }
198:
199: public Map getFieldErrors() {
200: if (haveFieldErrors) {
201: List err1 = new ArrayList();
202: err1.add("field error message number 1");
203: List err2 = new ArrayList();
204: err2.add("field error message number 2");
205: List err3 = new ArrayList();
206: err3.add("field error message number 3");
207: Map fieldErrors = new LinkedHashMap();
208: fieldErrors.put("field1", err1);
209: fieldErrors.put("field2", err2);
210: fieldErrors.put("field3", err3);
211: return fieldErrors;
212: } else if (returnNullForFieldErrors) {
213: return null;
214: } else {
215: return Collections.EMPTY_MAP;
216: }
217: }
218:
219: public boolean hasFieldErrors() {
220: return haveFieldErrors;
221: }
222: }
223: }
|