01: /*
02: * $Id: ActionErrorTagTest.java 471756 2006-11-06 15:01:43Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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: //assertEquals("", writer.toString());
49: verify(ActionErrorTagTest.class
50: .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
62: .getResource("actionerror-2.txt"));
63: }
64:
65: public Action getAction() {
66: return new InternalActionSupport();
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: } else {
91: return Collections.EMPTY_LIST;
92: }
93: }
94: }
95: }
|