Class MockEmailTransport

java.lang.Object
javax.mail.Service
javax.mail.Transport
com.webmethods.caf.faces.data.email.MockEmailTransport
All Implemented Interfaces:
AutoCloseable

public class MockEmailTransport extends Transport
An email Transport implementation that doesn't send any messages, just queues them in its getSentMessages() list (useful for message-sending functional tests).
  • Field Details

  • Constructor Details

    • MockEmailTransport

      public MockEmailTransport()
      Default constructor using the session default instance and a default URLName.
    • MockEmailTransport

      public MockEmailTransport(Session session)
      Constructor for using a specified session and a default URLName
      Parameters:
      session - Session object for this Transport.
    • MockEmailTransport

      public MockEmailTransport(Session session, URLName name)
      Constructor for using a specified session and URLName.
      Parameters:
      session - Session object for this Transport.
      name - URLName object to be used for this Transport.
  • Method Details

    • isUseMockTransport

      public static boolean isUseMockTransport()
      Determine if this Transport is using a mock transport.
      Returns:
      True if EmailDeliverer is using a mock transport. Otherwise false.
    • setUseMockTransport

      public static void setUseMockTransport(boolean use)
      Set if this Transport is using a mock transport. If the Transport is already set then continue to use the same Transport. Set the use value to false to clear the Transport.
      Parameters:
      True - will set the Transport to use a mock transport. False will clear the Transport to use.
    • getMockTransport

      public static Transport getMockTransport()
      Mock transport for EmailDeliverer to use.
      Returns:
      The mock Transport used for this class.
    • setMockTransport

      public static void setMockTransport(Transport transport)
      Mock transport for EmailDeliverer to use (null to not use a mock transport).
      Parameters:
      transport - A Transport
    • sendMessage

      public void sendMessage(Message message, Address[] addresses) throws MessagingException
      Adds a sent message to the list of message sent through the mock transport.
      Specified by:
      sendMessage in class Transport
      Parameters:
      message - The message sent.
      addresses - The array of address 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 class Service
      Parameters:
      host - String ( ignored )
      port - int ( ignored )
      user - String ( ignored )
      password - String ( ignored )
      Returns:
      Always returns true.
      Throws:
      MessagingException
    • getSentMessages

      public List<MockEmailTransport.SentMessage> getSentMessages()
      Active list of sent messages.
      Returns:
      A list of SentMessage.