FileDocCategorySizeDatePackage
HttpHeaderResultTest.javaAPI DocExample3927Mon Jul 23 13:26:12 BST 2007org.apache.struts2.dispatcher

HttpHeaderResultTest

public class HttpHeaderResultTest extends org.apache.struts2.StrutsTestCase
HttpHeaderResultTest

Fields Summary
com.opensymphony.xwork2.ActionInvocation
invocation
HttpHeaderResult
result
HttpServletResponse
response
com.mockobjects.dynamic.Mock
responseMock
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();
        result = new HttpHeaderResult();
        responseMock = new Mock(HttpServletResponse.class);
        response = (HttpServletResponse) responseMock.proxy();
        invocation = (ActionInvocation) new Mock(ActionInvocation.class).proxy();
        ServletActionContext.setResponse(response);

        XWorkConverter.getInstance().setObjectTypeDeterminer(ObjectTypeDeterminerFactory.getInstance());
    
protected voidtearDown()

        super.tearDown();
        ServletActionContext.setResponse(null);
        ActionContext.setContext(null);
        XWorkConverter.resetInstance();
    
public voidtestHeaderValuesAreNotParsedWhenParseIsFalse()

        Map params = new HashMap();
        params.put("headers.foo", "${bar}");
        params.put("headers.baz", "baz");

        Map values = new HashMap();
        values.put("bar", "abc");

        ActionContext.getContext().getValueStack().push(values);
        OgnlUtil.setProperties(params, result);

        responseMock.expect("addHeader", C.args(C.eq("foo"), C.eq("${bar}")));
        responseMock.expect("addHeader", C.args(C.eq("baz"), C.eq("baz")));
        result.setParse(false);
        result.execute(invocation);
        responseMock.verify();
    
public voidtestHeaderValuesAreParsedAndSet()

        Map params = new HashMap();
        params.put("headers.foo", "${bar}");
        params.put("headers.baz", "baz");

        Map values = new HashMap();
        values.put("bar", "abc");

        ActionContext.getContext().getValueStack().push(values);
        OgnlUtil.setProperties(params, result);

        responseMock.expect("addHeader", C.args(C.eq("foo"), C.eq("abc")));
        responseMock.expect("addHeader", C.args(C.eq("baz"), C.eq("baz")));
        result.execute(invocation);
        responseMock.verify();
    
public voidtestStatusIsSet()

        responseMock.expect("setStatus", C.eq(123));
        result.setStatus(123);
        result.execute(invocation);
        responseMock.verify();