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