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.Message;
06: import javax.mail.MessagingException;
07:
08: import com.canoo.webtest.engine.StepFailedException;
09: import com.canoo.webtest.util.ConversionUtil;
10:
11: /**
12: * Abstract class used by email steps that store a property related to a single message.
13: *
14: * @author Paul King
15: */
16: public abstract class AbstractMessageStoreStep extends
17: AbstractStoreStep implements ISingleMessageStep {
18: private String fMessageId;
19:
20: /**
21: * Sets the message id.
22: *
23: * @param id The id of the message of interest
24: * @webtest.parameter
25: * required="yes"
26: * description="The message id."
27: */
28: public void setMessageId(final String id) {
29: fMessageId = id;
30: }
31:
32: public String getMessageId() {
33: return fMessageId;
34: }
35:
36: /**
37: * Verifies the parameters
38: */
39: protected void verifyParameters() {
40: super .verifyParameters();
41: optionalIntegerParamCheck(fMessageId, "messageId", true);
42: }
43:
44: protected String processContent(final Folder folder)
45: throws MessagingException {
46: final int id = ConversionUtil.convertToInt(getMessageId(), 0);
47: final Message message = getHelper().getMessage(id, folder);
48: if (message == null) {
49: throw new StepFailedException(
50: "Could not find message with id '" + id
51: + "' on server.", this );
52: }
53: return performOperation(message);
54: }
55:
56: protected abstract String performOperation(Message message)
57: throws MessagingException;
58: }
|