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
65 public Action getAction() {
66 return new InternalActionSupport();
67 }
68
69
70 public class InternalActionSupport extends ActionSupport {
71
72 private static final long serialVersionUID = -4777466640658557661L;
73
74 private boolean yesActionErrors;
75
76 public void setHasActionErrors(boolean aYesActionErrors) {
77 yesActionErrors = aYesActionErrors;
78 }
79
80 public boolean hasActionErrors() {
81 return yesActionErrors;
82 }
83
84 public Collection getActionErrors() {
85 if (yesActionErrors) {
86 List errors = new ArrayList();
87 errors.add("action error number 1");
88 errors.add("action error number 2");
89 errors.add("action error number 3");
90 return errors;
91 }
92 else {
93 return Collections.EMPTY_LIST;
94 }
95 }
96 }
97 }