001: // Copyright © 2004-2005 ASERT. Released under the Canoo Webtest license.
002: package com.canoo.webtest.steps.verify;
003:
004: import org.apache.tools.ant.Project;
005:
006: import com.canoo.webtest.engine.StepExecutionException;
007: import com.canoo.webtest.engine.StepFailedException;
008: import com.canoo.webtest.self.TestBlock;
009: import com.canoo.webtest.self.ThrowAssert;
010: import com.canoo.webtest.steps.BaseStepTestCase;
011: import com.canoo.webtest.steps.Step;
012:
013: /**
014: * Tests the verifyProperty step.
015: *
016: * @author Paul King, ASERT
017: */
018: public class VerifyPropertyTest extends BaseStepTestCase {
019: private VerifyProperty fStep;
020:
021: protected void setUp() throws Exception {
022: super .setUp();
023: fStep = (VerifyProperty) getStep();
024: fStep.setWebtestProperty("dynProp", "The DynProp Value");
025: fStep.setProject(new Project());
026: fStep.getProject().setNewProperty("antProp",
027: "The AntProp Value");
028: }
029:
030: protected Step createStep() {
031: return new VerifyProperty();
032: }
033:
034: public void testAliases() throws Exception {
035: fStep.setValue("foo");
036: assertEquals("foo", fStep.getValue());
037: assertEquals("foo", fStep.getText());
038: fStep.setText("fii");
039: assertEquals("fii", fStep.getValue());
040: assertEquals("fii", fStep.getText());
041:
042: fStep.setProperty("foo");
043: assertEquals("foo", fStep.getProperty());
044: assertEquals("foo", fStep.getName());
045: fStep.setName("fii");
046: assertEquals("fii", fStep.getProperty());
047: assertEquals("fii", fStep.getName());
048: }
049:
050: /*
051: * There is some overlap with the functional tests in these
052: * unit tests but thought it was better to be safe than sorry
053: */
054:
055: // <verifyProperty />
056: public void testNoPropertyNameAttributes() throws Exception {
057: assertStepRejectsNullParam("name", new TestBlock() {
058: public void call() throws Exception {
059: executeStep(fStep);
060: }
061: });
062: }
063:
064: // <verifyProperty name="dynProp" />
065: public void testDynPropertyExists() throws Exception {
066: fStep.setName("dynProp");
067: executeStep(fStep);
068: }
069:
070: // <verifyProperty name="antProp" propertyType="ant" />
071: public void testAntPropertyExists() throws Exception {
072: fStep.setName("antProp");
073: fStep.setPropertyType(Step.PROPERTY_TYPE_ANT);
074: executeStep(fStep);
075: }
076:
077: // <verifyProperty name="dynProp" text="The DynProp Value"/>
078: public void testDynPropertyHasCorrectValue() throws Exception {
079: fStep.setName("dynProp");
080: fStep.setText("The DynProp Value");
081: executeStep(fStep);
082: }
083:
084: // <verifyProperty name="antProp" propertyType="ant" text="The AntProp Value"/>
085: public void testAntPropertyHasCorrectValue() throws Exception {
086: fStep.setName("antProp");
087: fStep.setPropertyType(Step.PROPERTY_TYPE_ANT);
088: fStep.setText("The AntProp Value");
089: executeStep(fStep);
090: }
091:
092: // <verifyProperty name="dynProp" text="The DynProp Value"/>
093: public void testDynPropertyValueWithRegex() throws Exception {
094: fStep.setName("dynProp");
095: fStep.setRegex("true");
096: fStep.setText(".*Value");
097: executeStep(fStep);
098: }
099:
100: // <verifyProperty name="antProp" propertyType="ant" text="The AntProp Value"/>
101: public void testAntPropertyValueWithRegex() throws Exception {
102: fStep.setName("antProp");
103: fStep.setPropertyType(Step.PROPERTY_TYPE_ANT);
104: fStep.setRegex("true");
105: fStep.setText(".*Value");
106: executeStep(fStep);
107: }
108:
109: // <verifyProperty name="dynProp" text="Something completely different" />
110: public void testDynPropertyIncorrectValue() throws Exception {
111: fStep.setName("dynProp");
112: fStep.setText("Something completely different");
113: String msg = ThrowAssert.assertThrows(
114: StepFailedException.class, new TestBlock() {
115: public void call() throws Exception {
116: executeStep(fStep);
117: }
118: });
119: assertTrue(msg.indexOf("Incorrect property value found!") != -1);
120: }
121:
122: // <verifyProperty name="antProp" propertyType="ant" text="Something completely different" />
123: public void testAntPropertyIncorrectValue() throws Exception {
124: fStep.setName("antProp");
125: fStep.setPropertyType(Step.PROPERTY_TYPE_ANT);
126: fStep.setText("Something completely different");
127: String msg = ThrowAssert.assertThrows(
128: StepFailedException.class, new TestBlock() {
129: public void call() throws Exception {
130: executeStep(fStep);
131: }
132: });
133: assertTrue(msg.indexOf("Incorrect property value found!") != -1);
134: }
135:
136: // <verifyProperty name="someOtherProp" text="The DynProp Value" />
137: public void testDynPropertyUnknownName() throws Exception {
138: fStep.setName("someOtherProp");
139: fStep.setText("The DynProp Value");
140: String msg = ThrowAssert.assertThrows(
141: StepFailedException.class, new TestBlock() {
142: public void call() throws Exception {
143: executeStep(fStep);
144: }
145: });
146: assertTrue(msg
147: .indexOf("Expected property \"someOtherProp\" to be defined!") != -1);
148: }
149:
150: // <verifyProperty name="antProp" text="The AntProp Value" propertyType="unknown"/>
151: public void testUnknownPropertyType() {
152: fStep.setName("antProp");
153: fStep.setPropertyType("unknown");
154: fStep.setText("The AntProp Value");
155: String msg = ThrowAssert.assertThrows(
156: StepExecutionException.class, new TestBlock() {
157: public void call() throws Exception {
158: executeStep(fStep);
159: }
160: });
161: assertTrue(msg.indexOf("Unknown propertyType") != -1);
162: }
163:
164: // <verifyProperty name="someOtherProp" propertyType="ant" text="The AntProp Value" />
165: public void testAntPropertyUnknownName() throws Exception {
166: fStep.setName("someOtherProp");
167: fStep.setPropertyType(Step.PROPERTY_TYPE_ANT);
168: fStep.setText("The AntProp Value");
169: String msg = ThrowAssert.assertThrows(
170: StepFailedException.class, new TestBlock() {
171: public void call() throws Exception {
172: executeStep(fStep);
173: }
174: });
175: assertTrue(msg
176: .indexOf("Expected property \"someOtherProp\" to be defined!") != -1);
177: }
178:
179: }
|