1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.views.jsp.ui;
19
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.List;
24
25 import org.apache.struts2.views.jsp.AbstractUITagTest;
26
27 import com.opensymphony.xwork2.Action;
28 import com.opensymphony.xwork2.ActionSupport;
29
30 /***
31 * ActionErrorTag test case.
32 *
33 */
34 public class ActionErrorTagTest extends AbstractUITagTest {
35
36 boolean shouldActionHaveError = false;
37
38 public void testNoActionErrors() throws Exception {
39 ActionErrorTag tag = new ActionErrorTag();
40 ((InternalActionSupport)action).setHasActionErrors(false);
41 tag.setPageContext(pageContext);
42 tag.doStartTag();
43 tag.doEndTag();
44
45
46 verify(ActionErrorTagTest.class.getResource("actionerror-1.txt"));
47 }
48
49 public void testHaveActionErrors() throws Exception {
50
51 ActionErrorTag tag = new ActionErrorTag();
52 ((InternalActionSupport)action).setHasActionErrors(true);
53 tag.setPageContext(pageContext);
54 tag.doStartTag();
55 tag.doEndTag();
56
57 verify(ActionErrorTagTest.class.getResource("actionerror-2.txt"));
58 }
59
60
61 public Action getAction() {
62 return new InternalActionSupport();
63 }
64
65
66 public class InternalActionSupport extends ActionSupport {
67
68 private static final long serialVersionUID = -4777466640658557661L;
69
70 private boolean yesActionErrors;
71
72 public void setHasActionErrors(boolean aYesActionErrors) {
73 yesActionErrors = aYesActionErrors;
74 }
75
76 public boolean hasActionErrors() {
77 return yesActionErrors;
78 }
79
80 public Collection getActionErrors() {
81 if (yesActionErrors) {
82 List errors = new ArrayList();
83 errors.add("action error number 1");
84 errors.add("action error number 2");
85 errors.add("action error number 3");
86 return errors;
87 }
88 else {
89 return Collections.EMPTY_LIST;
90 }
91 }
92 }
93 }