01: // Copyright © 2004-2005 ASERT. Released under the Canoo Webtest license.
02: package com.canoo.webtest.steps.store;
03:
04: import com.canoo.webtest.engine.StepFailedException;
05: import com.gargoylesoftware.htmlunit.WebResponse;
06:
07: /**
08: * Stores a header value (from the Http Response) into a property.<p>
09: * <p/>
10: * Either <em>ant</em> or <em>dynamic</em> properties are supported.
11: * The property can be checked subsequently with <em>verifyProperty</em>.
12: *
13: * @author Paul King
14: * @author Marc Guillemot
15: * @webtest.step category="Core"
16: * name="storeHeader"
17: * description="Provides the ability to store an <key>HTTP</key> Header value for later checking"
18: */
19: public class StoreHeader extends BaseStoreStep {
20: private String fHeaderName;
21:
22: /**
23: * Sets the Name of the Header of interest.<p>
24: *
25: * @param name The Header Name
26: * @webtest.parameter required="yes"
27: * description="The name of the Http Response Header of interest.
28: * If the property name is not specified, the header name is used as key to store the value found."
29: */
30: public void setName(final String name) {
31: fHeaderName = name;
32: }
33:
34: public String getName() {
35: return fHeaderName;
36: }
37:
38: public void doExecute() {
39: final WebResponse response = getContext().getCurrentResponse()
40: .getWebResponse();
41: final String headerValue = response
42: .getResponseHeaderValue(fHeaderName);
43:
44: if (headerValue == null) {
45: throw new StepFailedException("Header \"" + fHeaderName
46: + "\" not set!", this );
47: }
48: storeProperty(headerValue, getName());
49: }
50:
51: /**
52: * Verifies the parameters.<p>
53: */
54: protected void verifyParameters() {
55: super .verifyParameters();
56: nullParamCheck(fHeaderName, "name");
57: nullResponseCheck();
58: }
59: }
|