Class MockEmailTransport
java.lang.Object
javax.mail.Service
javax.mail.Transport
com.webmethods.caf.faces.data.email.MockEmailTransport
- All Implemented Interfaces:
AutoCloseable
An email
Transport
implementation that doesn't send any messages,
just queues them in its getSentMessages()
list
(useful for message-sending functional tests).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Container class for message sent through the mock transport. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor using the session default instance and a defaultURLName
.MockEmailTransport
(Session session) Constructor for using a specified session and a defaultURLName
MockEmailTransport
(Session session, URLName name) Constructor for using a specified session and URLName. -
Method Summary
Modifier and TypeMethodDescriptionstatic Transport
Mock transport forEmailDeliverer
to use.Active list of sent messages.static boolean
Determine if thisTransport
is using a mock transport.protected boolean
protocolConnect
(String host, int port, String user, String password) The method to perform the actual protocol-specific connection attempt.void
sendMessage
(Message message, Address[] addresses) Adds a sent message to the list of message sent through the mock transport.static void
setMockTransport
(Transport transport) Mock transport forEmailDeliverer
to use (null to not use a mock transport).static void
setUseMockTransport
(boolean use) Set if thisTransport
is using a mock transport.Methods inherited from class javax.mail.Transport
addTransportListener, notifyTransportListeners, removeTransportListener, send, send, send, send
Methods inherited from class javax.mail.Service
addConnectionListener, close, connect, connect, connect, connect, finalize, getURLName, isConnected, notifyConnectionListeners, queueEvent, removeConnectionListener, setConnected, setURLName, toString
-
Field Details
-
sentMessages
-
-
Constructor Details
-
MockEmailTransport
public MockEmailTransport()Default constructor using the session default instance and a defaultURLName
. -
MockEmailTransport
Constructor for using a specified session and a defaultURLName
- Parameters:
session
-Session
object for this Transport.
-
MockEmailTransport
Constructor for using a specified session and URLName.
-
-
Method Details
-
isUseMockTransport
public static boolean isUseMockTransport()Determine if thisTransport
is using a mock transport.- Returns:
- True if
EmailDeliverer
is using a mock transport. Otherwise false.
-
setUseMockTransport
public static void setUseMockTransport(boolean use) -
getMockTransport
Mock transport forEmailDeliverer
to use.- Returns:
- The mock
Transport
used for this class.
-
setMockTransport
Mock transport forEmailDeliverer
to use (null to not use a mock transport).- Parameters:
transport
- ATransport
-
sendMessage
Adds a sent message to the list of message sent through the mock transport.- Specified by:
sendMessage
in classTransport
- Parameters:
message
- Themessage
sent.addresses
- The array ofaddress
contained in the message.- Throws:
MessagingException
-
protocolConnect
protected boolean protocolConnect(String host, int port, String user, String password) throws MessagingException The method to perform the actual protocol-specific connection attempt.- Overrides:
protocolConnect
in classService
- Parameters:
host
- String ( ignored )port
- int ( ignored )user
- String ( ignored )password
- String ( ignored )- Returns:
- Always returns true.
- Throws:
MessagingException
-
getSentMessages
Active list of sent messages.- Returns:
- A list of SentMessage.
-