1 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 ; 17 import java.util.HashMap ; 18 import java.util.Map ; 19 20 21 27 public class HttpHeaderResultTest extends XWorkTestCase { 28 30 ActionInvocation invocation; 31 HttpHeaderResult result; 32 HttpServletResponse response; 33 Mock responseMock; 34 35 37 public void testHeaderValuesAreNotParsedWhenParseIsFalse() throws Exception { 38 Map params = new HashMap (); 39 params.put("headers.foo", "${bar}"); 40 params.put("headers.baz", "baz"); 41 42 Map values = new HashMap (); 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 { 56 Map params = new HashMap (); 57 params.put("headers.foo", "${bar}"); 58 params.put("headers.baz", "baz"); 59 60 Map values = new HashMap (); 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 { 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).proxy(); 85 ServletActionContext.setResponse(response); 86 } 87 88 protected void tearDown() throws Exception { 89 super.tearDown(); 90 ServletActionContext.setResponse(null); 91 ActionContext.setContext(null); 92 } 93 } 94 | Popular Tags |