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