01: /*
02: * Copyright (c) 2005 Canoo Engineering. All Rights Reserved.
03: */
04: package com.canoo.webtest.extension.spider;
05:
06: import org.apache.log4j.Logger;
07:
08: import com.canoo.webtest.steps.AbstractStepContainer;
09: import com.canoo.webtest.util.ConversionUtil;
10:
11: /**
12: * @author Denis N. Antonioli
13: * @webtest.step category="Extension"
14: * name="reportSite"
15: * description="This step is used to test a complete site."
16: */
17: public class ReportSiteStep extends AbstractStepContainer {
18: private static final Logger LOG = Logger
19: .getLogger(ReportSiteStep.class);
20: public static final String[] HEADERS = {
21: ExecuteStepValidator.KEY_DEPTH,
22: ExecuteStepValidator.KEY_VERIFY };
23: private String fFile;
24: private String fDepth;
25: private int fDepthCount;
26:
27: /**
28: * @webtest.parameter required="no"
29: * description="the name of the file that should contain the report.
30: * If not specified, report will be generated to standard output"
31: */
32: public void setFile(final String filename) {
33: fFile = filename;
34: }
35:
36: public String getFile() {
37: return fFile;
38: }
39:
40: protected void verifyParameters() {
41: super .verifyParameters();
42: optionalIntegerParamCheck(getDepth(), "depth", true);
43: fDepthCount = ConversionUtil.convertToInt(getDepth(), 0);
44: }
45:
46: /**
47: * @webtest.parameter required="no"
48: * default="0"
49: * description="the recursion depth"
50: */
51: public void setDepth(final String depth) {
52: fDepth = depth;
53: }
54:
55: public String getDepth() {
56: return fDepth;
57: }
58:
59: public void doExecute() throws CloneNotSupportedException {
60: LOG.debug("Creating spider");
61: final Spider spider = new Spider();
62: spider.setDepth(fDepthCount);
63: spider.setFileName(getFile());
64:
65: spider.setReporter(getReporter());
66: spider.setVisitorStrategy(getVisitorStrategy());
67: spider.setValidator(getValidator());
68:
69: LOG.debug("Executing spider");
70: spider.execute(getContext());
71: }
72:
73: protected IReporter getReporter() {
74: return new SeparatedValueReporter(HEADERS);
75: }
76:
77: protected IVisitorStrategy getVisitorStrategy() {
78: return new PatternVisitorStrategy("/.*/");
79: }
80:
81: protected IValidator getValidator() {
82: return new ExecuteStepValidator(getContext(), this);
83: }
84: }
|