01: // Copyright © 2004-2005 ASERT.
02: // Parts Copyright © 2005 Canoo Engineering AG, Switzerland.
03: // Released under the Canoo Webtest license.
04: package com.canoo.webtest.steps.store;
05:
06: import org.apache.commons.lang.StringUtils;
07:
08: import com.canoo.webtest.interfaces.IComputeValue;
09: import com.canoo.webtest.steps.Step;
10:
11: /**
12: * Base store step offering common functionalities for concrete implemetations
13: * Either ant or dynamic properties are supported. The property can
14: * be checked subsequently with \"verifyProperty\".
15: *
16: * @author Marc Guillemot
17: */
18: public abstract class BaseStoreStep extends Step implements
19: IComputeValue {
20: private String fPropertyName;
21: private String fPropertyType;
22: private String fComputedValue;
23:
24: /**
25: * Sets the Name of the Property.<p>
26: *
27: * @param name The Property Name
28: * @webtest.parameter required="no"
29: * description="The name of the property in which to store the retrieved value."
30: */
31: public void setProperty(final String name) {
32: fPropertyName = name;
33: }
34:
35: public String getProperty() {
36: return fPropertyName;
37: }
38:
39: /**
40: * Sets the Type of the Property.<p>
41: *
42: * @param type The Property type
43: * @webtest.parameter required="no"
44: * description="The type of the property in which to store the retrieve value.
45: * Either \"ant\" or \"dynamic\"."
46: * default="the \"defaultPropertyType\" as specified in the \"config\" element is used."
47: */
48: public void setPropertyType(final String type) {
49: fPropertyType = type;
50: }
51:
52: public String getPropertyType() {
53: return fPropertyType;
54: }
55:
56: /**
57: * Stores the property value
58: * @param value the value to store
59: * @param defaultName the name to use to store the property if no
60: * property name is configured
61: */
62: protected void storeProperty(final String value,
63: final String defaultName) {
64: fComputedValue = value;
65: final String propertyName = StringUtils.defaultIfEmpty(
66: getProperty(), defaultName);
67: setWebtestProperty(propertyName, value, getPropertyType());
68: }
69:
70: /**
71: * Stores the property value
72: * @param value the value to store
73: */
74: protected void storeProperty(final String value) {
75: fComputedValue = value;
76: setWebtestProperty(getProperty(), value, getPropertyType());
77: }
78:
79: public String getComputedValue() {
80: return fComputedValue;
81: }
82: }
|