001: /*
002: * $Id: HttpHeaderResultTest.java 526222 2007-04-06 16:37:54Z hermanns $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.dispatcher;
022:
023: import java.util.HashMap;
024: import java.util.Map;
025:
026: import javax.servlet.http.HttpServletResponse;
027:
028: import org.apache.struts2.ServletActionContext;
029: import org.apache.struts2.StrutsTestCase;
030:
031: import com.mockobjects.dynamic.C;
032: import com.mockobjects.dynamic.Mock;
033: import com.opensymphony.xwork2.ActionContext;
034: import com.opensymphony.xwork2.ActionInvocation;
035: import com.opensymphony.xwork2.util.OgnlUtil;
036: import com.opensymphony.xwork2.util.XWorkConverter;
037: import com.opensymphony.xwork2.util.ObjectTypeDeterminerFactory;
038:
039: /**
040: * HttpHeaderResultTest
041: *
042: */
043: public class HttpHeaderResultTest extends StrutsTestCase {
044:
045: ActionInvocation invocation;
046: HttpHeaderResult result;
047: HttpServletResponse response;
048: Mock responseMock;
049:
050: public void testHeaderValuesAreNotParsedWhenParseIsFalse()
051: throws Exception {
052: Map params = new HashMap();
053: params.put("headers.foo", "${bar}");
054: params.put("headers.baz", "baz");
055:
056: Map values = new HashMap();
057: values.put("bar", "abc");
058:
059: ActionContext.getContext().getValueStack().push(values);
060: OgnlUtil.setProperties(params, result);
061:
062: responseMock.expect("addHeader", C.args(C.eq("foo"), C
063: .eq("${bar}")));
064: responseMock.expect("addHeader", C.args(C.eq("baz"), C
065: .eq("baz")));
066: result.setParse(false);
067: result.execute(invocation);
068: responseMock.verify();
069: }
070:
071: public void testHeaderValuesAreParsedAndSet() throws Exception {
072: Map params = new HashMap();
073: params.put("headers.foo", "${bar}");
074: params.put("headers.baz", "baz");
075:
076: Map values = new HashMap();
077: values.put("bar", "abc");
078:
079: ActionContext.getContext().getValueStack().push(values);
080: OgnlUtil.setProperties(params, result);
081:
082: responseMock.expect("addHeader", C.args(C.eq("foo"), C
083: .eq("abc")));
084: responseMock.expect("addHeader", C.args(C.eq("baz"), C
085: .eq("baz")));
086: result.execute(invocation);
087: responseMock.verify();
088: }
089:
090: public void testStatusIsSet() throws Exception {
091: responseMock.expect("setStatus", C.eq(123));
092: result.setStatus(123);
093: result.execute(invocation);
094: responseMock.verify();
095: }
096:
097: protected void setUp() throws Exception {
098: super .setUp();
099: result = new HttpHeaderResult();
100: responseMock = new Mock(HttpServletResponse.class);
101: response = (HttpServletResponse) responseMock.proxy();
102: invocation = (ActionInvocation) new Mock(ActionInvocation.class)
103: .proxy();
104: ServletActionContext.setResponse(response);
105:
106: XWorkConverter.getInstance().setObjectTypeDeterminer(
107: ObjectTypeDeterminerFactory.getInstance());
108: }
109:
110: protected void tearDown() throws Exception {
111: super.tearDown();
112: ServletActionContext.setResponse(null);
113: ActionContext.setContext(null);
114: XWorkConverter.resetInstance();
115: }
116: }
|