01: // Copyright © 2004-2005 ASERT. Released under the Canoo Webtest license.
02: package com.canoo.webtest.extension;
03:
04: import com.canoo.webtest.engine.StepExecutionException;
05: import com.canoo.webtest.self.TestBlock;
06: import com.canoo.webtest.self.ThrowAssert;
07: import com.canoo.webtest.steps.BaseStepTestCase;
08: import com.canoo.webtest.steps.Step;
09:
10: /**
11: * Test class for {@link StoreRandom}.<p>
12: *
13: * @author Paul King
14: */
15: public class StoreRandomTest extends BaseStepTestCase {
16: private StoreRandom fStep;
17:
18: protected Step createStep() {
19: return new StoreRandom();
20: }
21:
22: protected void setUp() throws Exception {
23: super .setUp();
24: fStep = (StoreRandom) getStep();
25: }
26:
27: public void testVerifyParameterUsage() {
28: TestBlock block = new TestBlock() {
29: public void call() throws Exception {
30: executeStep(fStep);
31: }
32: };
33: // <storeRandom />
34: assertStepRejectsNullParam("property", block);
35: // <storeRandom description="from without to" property="someProp" from="2" />
36: fStep.setProperty("someProp");
37: fStep.setFrom("2");
38: ThrowAssert.assertThrows(StepExecutionException.class, block);
39: // <storeRandom description="to without from" property="someProp" to="3" />
40: fStep.setFrom(null);
41: fStep.setTo("3");
42: ThrowAssert.assertThrows(StepExecutionException.class, block);
43: // <storeRandom description="to smaller than from" property="someProp" from="3" to="2" />
44: fStep.setFrom("3");
45: fStep.setTo("2");
46: ThrowAssert.assertThrows(StepExecutionException.class, block);
47: // <storeRandom description="non-integer from" property="someProp" from="three" to="2" />
48: fStep.setFrom("three");
49: fStep.setTo("2");
50: ThrowAssert.assertThrows(StepExecutionException.class, block);
51: // <storeRandom description="non-integer to" property="someProp" from="3" to="two" />
52: fStep.setFrom("3");
53: fStep.setTo("two");
54: ThrowAssert.assertThrows(StepExecutionException.class, block);
55: // <storeRandom description="negative from" property="someProp" from="-3" to="2" />
56: fStep.setFrom("-3");
57: fStep.setTo("2");
58: ThrowAssert.assertThrows(StepExecutionException.class, block);
59: // <storeRandom description="negative to" property="someProp" from="3" to="-2" />
60: fStep.setFrom("3");
61: fStep.setTo("-2");
62: ThrowAssert.assertThrows(StepExecutionException.class, block);
63: // <storeRandom property="someProp" from="2" to="3" />
64: fStep.setFrom("2");
65: fStep.setTo("3");
66: ThrowAssert.assertPasses("Valid params for random number",
67: block);
68: // <storeRandom property="someProp" from="2" length="5" />
69: fStep.setFrom("2");
70: fStep.setTo(null);
71: fStep.setLength("5");
72: ThrowAssert.assertThrows(StepExecutionException.class, block);
73: // <storeRandom description="negative length" property="someProp" length="-5" />
74: fStep.setFrom(null);
75: fStep.setLength("-5");
76: ThrowAssert.assertThrows(StepExecutionException.class, block);
77: // <storeRandom property="someProp" length="5" />
78: fStep.setLength("5");
79: ThrowAssert.assertPasses("Valid params for random string",
80: block);
81: // <storeRandom property="someProp" length="5" chars="abc" />
82: fStep.setChars("abc");
83: ThrowAssert.assertPasses("Valid params for random string",
84: block);
85: // <storeRandom property="someProp" choice="a,b" length="5" />
86: fStep.setChoice("a,b");
87: fStep.setChars(null);
88: ThrowAssert.assertThrows(StepExecutionException.class, block);
89: // <storeRandom property="someProp" choice="a,b" />
90: fStep.setLength(null);
91: ThrowAssert.assertPasses("Valid params for random choice",
92: block);
93: }
94:
95: }
|