Class MailpitClient
java.lang.Object
com.irurueta.authserver.testsupport.MailpitClient
Reads the messages a Mailpit server received through its HTTP API, so a test finds the code or the link the
application mailed to a recipient. Every call is a plain HTTP request; there is no state besides the server's.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA message Mailpit received. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringBase URL of the HTTP API, without a trailing slash.private static final DurationLongest wait for one HTTP call.private static final PatternMatches the numeric code of a message: a run of digits that stands alone.private static final DurationDefault longest wait for a message to arrive.private static final PatternMatches the whole magic link a message carries.private final HttpClientSends the HTTP calls.private static final intHTTP status of a successful call.private static final tools.jackson.databind.json.JsonMapperReads the JSON answers.private static final PatternMatches the magic link a message carries and captures its token.private static final longPause between two polls of the server. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionawaitMessagesTo(String recipient, int count) Waits until at least a number of messages addressed to a recipient arrived.awaitMessageTo(String recipient) Waits for the first message addressed to a recipient.intcountMessagesTo(String recipient) Counts the messages addressed to a recipient that Mailpit holds now.private tools.jackson.databind.JsonNodeCalls the API with GET and parses the JSON answer.messagesTo(String recipient) Lists the messages addressed to a recipient that Mailpit holds now.private static voidpause()Sleeps a short while between two polls.private MailpitClient.MessageReads one message.
-
Field Details
-
CALL_TIMEOUT
Longest wait for one HTTP call. -
DEFAULT_WAIT
Default longest wait for a message to arrive. -
POLL_MILLIS
private static final long POLL_MILLISPause between two polls of the server.- See Also:
-
HTTP_OK
private static final int HTTP_OKHTTP status of a successful call.- See Also:
-
LINK_TOKEN
Matches the magic link a message carries and captures its token. -
FULL_LINK
Matches the whole magic link a message carries. -
CODE
Matches the numeric code of a message: a run of digits that stands alone. -
JSON
private static final tools.jackson.databind.json.JsonMapper JSONReads the JSON answers. -
http
Sends the HTTP calls. -
baseUrl
Base URL of the HTTP API, without a trailing slash.
-
-
Constructor Details
-
MailpitClient
Creates the client.- Parameters:
baseUrl- base URL of the HTTP API, such ashttp://localhost:8025.
-
-
Method Details
-
awaitMessageTo
Waits for the first message addressed to a recipient.- Parameters:
recipient- address the message was sent to.- Returns:
- the message.
- Throws:
IllegalStateException- if none arrives in time.
-
awaitMessagesTo
Waits until at least a number of messages addressed to a recipient arrived.- Parameters:
recipient- address the messages were sent to.count- number of messages to wait for.- Returns:
- the messages, oldest first.
- Throws:
IllegalStateException- if they do not arrive in time.
-
messagesTo
Lists the messages addressed to a recipient that Mailpit holds now.- Parameters:
recipient- address the messages were sent to.- Returns:
- the messages, oldest first; empty when there are none.
-
countMessagesTo
Counts the messages addressed to a recipient that Mailpit holds now.- Parameters:
recipient- address the messages were sent to.- Returns:
- the number of messages.
-
read
Reads one message.- Parameters:
id- identifier Mailpit gave the message.- Returns:
- the message.
-
get
Calls the API with GET and parses the JSON answer.- Parameters:
path- path and query of the call.- Returns:
- the answer.
-
pause
private static void pause()Sleeps a short while between two polls.
-