View Javadoc

1   /*
2    * $Id: ActionErrorTagTest.java 439747 2006-09-03 09:22:46Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.views.jsp.ui;
19  
20  import java.util.ArrayList;
21  import java.util.Collection;
22  import java.util.Collections;
23  import java.util.List;
24  
25  import org.apache.struts2.views.jsp.AbstractUITagTest;
26  
27  import com.opensymphony.xwork2.Action;
28  import com.opensymphony.xwork2.ActionSupport;
29  
30  /***
31   * ActionErrorTag test case.
32   * 
33   */
34  public class ActionErrorTagTest extends AbstractUITagTest {
35  	
36  	boolean shouldActionHaveError = false;
37  	
38  	public void testNoActionErrors() throws Exception {
39  		ActionErrorTag tag = new ActionErrorTag();
40  		((InternalActionSupport)action).setHasActionErrors(false);
41  		tag.setPageContext(pageContext);
42  		tag.doStartTag();
43  		tag.doEndTag();
44  		
45  		//assertEquals("", writer.toString());
46  		verify(ActionErrorTagTest.class.getResource("actionerror-1.txt"));
47  	}
48  	
49  	public void testHaveActionErrors() throws Exception {
50  		
51  		ActionErrorTag tag = new ActionErrorTag();
52  		((InternalActionSupport)action).setHasActionErrors(true);
53  		tag.setPageContext(pageContext);
54  		tag.doStartTag();
55  		tag.doEndTag();
56  
57  		verify(ActionErrorTagTest.class.getResource("actionerror-2.txt"));
58  	}
59  	
60  	
61  	public Action getAction() {
62  		return new InternalActionSupport();
63  	}
64  	
65  	
66  	public class InternalActionSupport extends ActionSupport {
67  		
68  		private static final long serialVersionUID = -4777466640658557661L;
69  		
70  		private boolean yesActionErrors;
71  		
72  		public void setHasActionErrors(boolean aYesActionErrors) {
73  			yesActionErrors = aYesActionErrors;
74  		}
75  		
76  		public boolean hasActionErrors() {
77  			return yesActionErrors;
78  		}
79  		
80  		public Collection getActionErrors() {
81  			if (yesActionErrors) {
82  				List errors = new ArrayList();
83  				errors.add("action error number 1");
84  				errors.add("action error number 2");
85  				errors.add("action error number 3");
86  				return errors;
87  			}
88  			else {
89  				return Collections.EMPTY_LIST;
90  			}
91  		}
92  	}
93  }