View Javadoc

1   /*
2    * $Id: ActionMessageTagTest.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   * ActionMessageTag test case.
32   * 
33   */
34  public class ActionMessageTagTest extends AbstractUITagTest {
35  
36  	public void testNoActionMessages() throws Exception {
37  		
38  		ActionMessageTag tag = new ActionMessageTag();
39  		((InternalActionSupport)action).setHasActionMessage(false);
40  		tag.setPageContext(pageContext);
41  		tag.doStartTag();
42  		tag.doEndTag();
43  		
44  		verify(ActionMessageTagTest.class.getResource("actionmessage-1.txt"));
45  	}
46  	
47  	public void testYesActionMessages() throws Exception {
48  		
49  		ActionMessageTag tag = new ActionMessageTag();
50  		((InternalActionSupport)action).setHasActionMessage(true);
51  		tag.setPageContext(pageContext);
52  		tag.doStartTag();
53  		tag.doEndTag();
54  		
55  		verify(ActionMessageTagTest.class.getResource("actionmessage-2.txt"));
56  	}
57  	
58  	public Action getAction() {
59  		return new InternalActionSupport();
60  	}
61  
62  	/***
63  	 * Internal ActionSupport class for testing, can be in state with
64  	 * or without action messages.
65  	 * 
66  	 * @author tm_jee
67  	 * @version $Date: 2006-09-03 05:22:46 -0400 (Sun, 03 Sep 2006) $ $Id: ActionMessageTagTest.java 439747 2006-09-03 09:22:46Z mrdon $
68  	 */
69  	public class InternalActionSupport extends ActionSupport {
70  		
71  		private static final long serialVersionUID = -3230043189352453629L;
72  		
73  		private boolean canHaveActionMessage;
74  		
75  		public void setHasActionMessage(boolean canHaveActionMessage) {
76  			this.canHaveActionMessage = canHaveActionMessage;
77  		}
78  		
79  		public Collection getActionMessages() {
80  			if (canHaveActionMessage) {
81  				List messages = new ArrayList();
82  				messages.add("action message number 1");
83  				messages.add("action message number 2");
84  				messages.add("action message number 3");
85  				return messages;
86  			}
87  			else {
88  				return Collections.EMPTY_LIST;
89  			}
90  		}
91  		
92  		public boolean hasActionMessages() {
93  			return canHaveActionMessage;
94  		}
95  	}
96  }