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