KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > dispatcher > HttpHeaderResultTest


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.dispatcher;
6
7 import com.mockobjects.dynamic.C;
8 import com.mockobjects.dynamic.Mock;
9 import com.opensymphony.webwork.ServletActionContext;
10 import com.opensymphony.xwork.ActionContext;
11 import com.opensymphony.xwork.ActionInvocation;
12 import com.opensymphony.xwork.XWorkTestCase;
13 import com.opensymphony.xwork.util.OgnlUtil;
14 import junit.framework.TestCase;
15
16 import javax.servlet.http.HttpServletResponse JavaDoc;
17 import java.util.HashMap JavaDoc;
18 import java.util.Map JavaDoc;
19
20
21 /**
22  * HttpHeaderResultTest
23  *
24  * @author Jason Carreira
25  * Date: Nov 16, 2003 1:08:20 AM
26  */

27 public class HttpHeaderResultTest extends XWorkTestCase {
28     //~ Instance fields ////////////////////////////////////////////////////////
29

30     ActionInvocation invocation;
31     HttpHeaderResult result;
32     HttpServletResponse JavaDoc response;
33     Mock responseMock;
34
35     //~ Methods ////////////////////////////////////////////////////////////////
36

37     public void testHeaderValuesAreNotParsedWhenParseIsFalse() throws Exception JavaDoc {
38         Map JavaDoc params = new HashMap JavaDoc();
39         params.put("headers.foo", "${bar}");
40         params.put("headers.baz", "baz");
41
42         Map JavaDoc values = new HashMap JavaDoc();
43         values.put("bar", "abc");
44         ActionContext.getContext().getValueStack().push(values);
45
46         OgnlUtil.setProperties(params, result);
47
48         responseMock.expect("addHeader", C.args(C.eq("foo"), C.eq("${bar}")));
49         responseMock.expect("addHeader", C.args(C.eq("baz"), C.eq("baz")));
50         result.setParse(false);
51         result.execute(invocation);
52         responseMock.verify();
53     }
54
55     public void testHeaderValuesAreParsedAndSet() throws Exception JavaDoc {
56         Map JavaDoc params = new HashMap JavaDoc();
57         params.put("headers.foo", "${bar}");
58         params.put("headers.baz", "baz");
59
60         Map JavaDoc values = new HashMap JavaDoc();
61         values.put("bar", "abc");
62         ActionContext.getContext().getValueStack().push(values);
63
64         OgnlUtil.setProperties(params, result);
65
66         responseMock.expect("addHeader", C.args(C.eq("foo"), C.eq("abc")));
67         responseMock.expect("addHeader", C.args(C.eq("baz"), C.eq("baz")));
68         result.execute(invocation);
69         responseMock.verify();
70     }
71
72     public void testStatusIsSet() throws Exception JavaDoc {
73         responseMock.expect("setStatus", C.eq(123));
74         result.setStatus(123);
75         result.execute(invocation);
76         responseMock.verify();
77     }
78
79     protected void setUp() throws Exception JavaDoc {
80         super.setUp();
81         result = new HttpHeaderResult();
82         responseMock = new Mock(HttpServletResponse JavaDoc.class);
83         response = (HttpServletResponse JavaDoc) responseMock.proxy();
84         invocation = (ActionInvocation) new Mock(ActionInvocation.class).proxy();
85         ServletActionContext.setResponse(response);
86     }
87
88     protected void tearDown() throws Exception JavaDoc {
89         super.tearDown();
90         ServletActionContext.setResponse(null);
91         ActionContext.setContext(null);
92     }
93 }
94
Popular Tags