01: // Copyright (c) 2002-2005 Canoo Engineering AG, Switzerland. All Rights Reserved.
02: package com.canoo.webtest.steps;
03:
04: import java.util.List;
05:
06: import org.apache.tools.ant.Task;
07:
08: import com.canoo.webtest.self.StepStub;
09: import com.canoo.webtest.steps.request.InvokePage;
10:
11: /**
12: * Unit tests for {@link AbstractStepContainer}.
13: * @author Denis N. Antonioli
14: * @author Marc Guillemot
15: */
16: public class AbstractStepContainerTest extends BaseStepTestCase {
17: private AbstractStepContainer fAbstractStepContainer;
18:
19: /**
20: * Dummy concrete extension for tests
21: */
22: static class AbstractStepContainerStub extends
23: AbstractStepContainer {
24: public void doExecute() {
25: }
26: }
27:
28: protected void setUp() throws Exception {
29: super .setUp();
30: fAbstractStepContainer = (AbstractStepContainerStub) getStep();
31: }
32:
33: protected Step createStep() {
34: return new AbstractStepContainerStub();
35: }
36:
37: public void testStubCreation() throws Exception {
38: assertNotNull(fAbstractStepContainer);
39: executeStep(fAbstractStepContainer); // coverage
40: }
41:
42: public void testClone() throws Exception {
43: final InvokePage step1 = new InvokePage();
44: step1.setDescription("blah blah");
45: step1.setTaskName("invoke");
46: step1.setUrl("/my/Super/page.html");
47: step1.setProject(fAbstractStepContainer.getProject());
48: fAbstractStepContainer.addStep(step1);
49:
50: final AbstractStepContainer clonedContainer = (AbstractStepContainer) fAbstractStepContainer
51: .clone();
52: final List clonedSteps = clonedContainer.getSteps();
53:
54: assertEquals(1, clonedSteps.size());
55: assertEquals(InvokePage.class, clonedSteps.get(0).getClass());
56: final InvokePage clonedStep = (InvokePage) clonedSteps.get(0);
57: assertEquals(step1.getUrl(), clonedStep.getUrl());
58: assertEquals(step1.getDescription(), clonedStep
59: .getDescription());
60: assertEquals(step1.getTaskName(), clonedStep.getTaskName());
61: assertSame(step1.getProject(), clonedStep.getProject());
62: }
63:
64: public void testAddTask() {
65: final Task task = new Task() {
66: };
67: configureTask(task); // would have been done by ant in normal run
68: fAbstractStepContainer.addTask(task);
69:
70: final Task firstTask = (Task) fAbstractStepContainer.getSteps()
71: .get(0);
72: assertSame(fAbstractStepContainer.getProject(), firstTask
73: .getProject());
74: assertSame(fAbstractStepContainer.getOwningTarget(), firstTask
75: .getOwningTarget());
76: }
77:
78: public void testAddStep() {
79: final Step step = new StepStub();
80: configureTask(step); // would have been done by ant in normal run
81: fAbstractStepContainer.addTask(step);
82:
83: final Step firstStep = (Step) fAbstractStepContainer.getSteps()
84: .get(0);
85: assertSame(fAbstractStepContainer.getProject(), firstStep
86: .getProject());
87: }
88: }
|