View Javadoc

1   /*
2    * $Id: ActionErrorTagTest.java 651946 2008-04-27 13:41:38Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "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  
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          //assertEquals("", writer.toString());
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  }