View Javadoc

1   /*
2    * $Id: ActionErrorTagTest.java 471756 2006-11-06 15:01:43Z husted $
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  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.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  }