Merge branch '2.7.x' into 3.0.x

Closes gh-35254
This commit is contained in:
Andy Wilkinson
2023-05-03 17:44:49 +01:00
2 changed files with 31 additions and 7 deletions

View File

@@ -56,25 +56,47 @@ class MailHealthIndicatorTests {
session.addProvider(new Provider(Type.TRANSPORT, "success", SuccessTransport.class.getName(), "Test", "1.0.0"));
this.mailSender = mock(JavaMailSenderImpl.class);
given(this.mailSender.getHost()).willReturn("smtp.acme.org");
given(this.mailSender.getPort()).willReturn(25);
given(this.mailSender.getSession()).willReturn(session);
this.indicator = new MailHealthIndicator(this.mailSender);
}
@Test
void smtpIsUp() {
void smtpOnDefaultPortIsUp() {
given(this.mailSender.getPort()).willReturn(-1);
given(this.mailSender.getProtocol()).willReturn("success");
Health health = this.indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails()).containsEntry("location", "smtp.acme.org:25");
assertThat(health.getDetails()).containsEntry("location", "smtp.acme.org");
}
@Test
void smtpIsDown() throws MessagingException {
void smtpOnDefaultPortIsDown() throws MessagingException {
given(this.mailSender.getPort()).willReturn(-1);
willThrow(new MessagingException("A test exception")).given(this.mailSender).testConnection();
Health health = this.indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails()).containsEntry("location", "smtp.acme.org:25");
assertThat(health.getDetails()).containsEntry("location", "smtp.acme.org");
Object errorMessage = health.getDetails().get("error");
assertThat(errorMessage).isNotNull();
assertThat(errorMessage.toString().contains("A test exception")).isTrue();
}
@Test
void smtpOnCustomPortIsUp() {
given(this.mailSender.getPort()).willReturn(1234);
given(this.mailSender.getProtocol()).willReturn("success");
Health health = this.indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails()).containsEntry("location", "smtp.acme.org:1234");
}
@Test
void smtpOnCustomPortIsDown() throws MessagingException {
given(this.mailSender.getPort()).willReturn(1234);
willThrow(new MessagingException("A test exception")).given(this.mailSender).testConnection();
Health health = this.indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails()).containsEntry("location", "smtp.acme.org:1234");
Object errorMessage = health.getDetails().get("error");
assertThat(errorMessage).isNotNull();
assertThat(errorMessage.toString()).contains("A test exception");