01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.dispatcher;
06:
07: import com.mockobjects.dynamic.C;
08: import com.mockobjects.dynamic.Mock;
09: 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:
15: import javax.servlet.http.HttpServletResponse;
16: import java.util.HashMap;
17: import java.util.Map;
18:
19: /**
20: * HttpHeaderResultTest
21: *
22: * @author Jason Carreira
23: * Date: Nov 16, 2003 1:08:20 AM
24: */
25: public class HttpHeaderResultTest extends XWorkTestCase {
26:
27: ActionInvocation invocation;
28: HttpHeaderResult result;
29: HttpServletResponse response;
30: Mock responseMock;
31:
32: public void testHeaderValuesAreNotParsedWhenParseIsFalse()
33: throws Exception {
34: Map params = new HashMap();
35: params.put("headers.foo", "${bar}");
36: params.put("headers.baz", "baz");
37:
38: Map values = new HashMap();
39: values.put("bar", "abc");
40: ActionContext.getContext().getValueStack().push(values);
41:
42: OgnlUtil.setProperties(params, result);
43:
44: responseMock.expect("addHeader", C.args(C.eq("foo"), C
45: .eq("${bar}")));
46: responseMock.expect("addHeader", C.args(C.eq("baz"), C
47: .eq("baz")));
48: result.setParse(false);
49: result.execute(invocation);
50: responseMock.verify();
51: }
52:
53: public void testHeaderValuesAreParsedAndSet() throws Exception {
54: Map params = new HashMap();
55: params.put("headers.foo", "${bar}");
56: params.put("headers.baz", "baz");
57:
58: Map values = new HashMap();
59: values.put("bar", "abc");
60: ActionContext.getContext().getValueStack().push(values);
61:
62: OgnlUtil.setProperties(params, result);
63:
64: responseMock.expect("addHeader", C.args(C.eq("foo"), C
65: .eq("abc")));
66: responseMock.expect("addHeader", C.args(C.eq("baz"), C
67: .eq("baz")));
68: result.execute(invocation);
69: responseMock.verify();
70: }
71:
72: public void testStatusIsSet() throws Exception {
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 {
80: super .setUp();
81: result = new HttpHeaderResult();
82: responseMock = new Mock(HttpServletResponse.class);
83: response = (HttpServletResponse) responseMock.proxy();
84: invocation = (ActionInvocation) new Mock(ActionInvocation.class)
85: .proxy();
86: ServletActionContext.setResponse(response);
87: }
88:
89: protected void tearDown() throws Exception {
90: super.tearDown();
91: ServletActionContext.setResponse(null);
92: ActionContext.setContext(null);
93: }
94: }
|