01: // Copyright © 2006-2007 ASERT. Released under the Canoo Webtest license.
02: package com.canoo.webtest.plugins.emailtest;
03:
04: import javax.mail.Folder;
05: import javax.mail.MessagingException;
06:
07: import com.canoo.webtest.engine.StepFailedException;
08:
09: /**
10: * Abstract class used by email steps which store a result.
11: *
12: * @author Paul King
13: */
14: public abstract class AbstractStoreStep extends AbstractBaseStep {
15: private String fPropertyName;
16: private String fPropertyType;
17:
18: public String getProperty() {
19: return fPropertyName;
20: }
21:
22: /**
23: * Sets the target property name.
24: *
25: * @param name The Property Name
26: * @webtest.parameter
27: * required="yes"
28: * description="The target property name."
29: */
30: public void setProperty(final String name) {
31: fPropertyName = name;
32: }
33:
34: /**
35: * Sets the target property type.
36: *
37: * @param type The Property type
38: * @webtest.parameter
39: * required="no"
40: * description="The target property type. Either \"ant\" or \"dynamic\"."
41: * default="the \"defaultPropertyType\" as specified in the \"config\" element is used."
42: */
43: public void setPropertyType(final String type) {
44: fPropertyType = type;
45: }
46:
47: public String getPropertyType() {
48: return fPropertyType;
49: }
50:
51: public void doExecute() {
52: final EmailConfigInfo configInfo = (EmailConfigInfo) getContext()
53: .get("EmailConfigInfo");
54: Folder folder = null;
55: try {
56: folder = getHelper().getInboxFolder(configInfo);
57: setWebtestProperty(getProperty(), processContent(folder),
58: getPropertyType());
59: } catch (final MessagingException e) {
60: throw new StepFailedException("Error processing content: "
61: + e.getMessage(), this );
62: } finally {
63: getHelper().logout(folder, false);
64: }
65: }
66:
67: protected abstract String processContent(Folder info)
68: throws MessagingException;
69:
70: /**
71: * Verifies the parameters
72: */
73: protected void verifyParameters() {
74: super .verifyParameters();
75: nullParamCheck(getProperty(), "property");
76: }
77: }
|