diff --git a/core/src/main/java/google/registry/batch/SendExpiringCertificateNotificationEmailAction.java b/core/src/main/java/google/registry/batch/SendExpiringCertificateNotificationEmailAction.java index 8d4ca3ac4..83c5746de 100644 --- a/core/src/main/java/google/registry/batch/SendExpiringCertificateNotificationEmailAction.java +++ b/core/src/main/java/google/registry/batch/SendExpiringCertificateNotificationEmailAction.java @@ -55,6 +55,7 @@ import org.joda.time.format.DateTimeFormatter; path = SendExpiringCertificateNotificationEmailAction.PATH, auth = Auth.AUTH_INTERNAL_OR_ADMIN) public class SendExpiringCertificateNotificationEmailAction implements Runnable { + public static final String PATH = "/_dr/task/sendExpiringCertificateNotificationEmail"; /** * Used as an offset when storing the last notification email sent date. @@ -96,8 +97,13 @@ public class SendExpiringCertificateNotificationEmailAction implements Runnable public void run() { response.setContentType(MediaType.PLAIN_TEXT_UTF_8); try { - sendNotificationEmails(); + int numEmailsSent = sendNotificationEmails(); + String message = + String.format( + "Done. Sent %d expiring certificate notification emails in total.", numEmailsSent); + logger.atInfo().log(message); response.setStatus(SC_OK); + response.setPayload(message); } catch (Exception e) { logger.atWarning().withCause(e).log( "Exception thrown when sending expiring certificate notification emails."); @@ -263,8 +269,6 @@ public class SendExpiringCertificateNotificationEmailAction implements Runnable emailsSent++; } } - logger.atInfo().log( - "Attempted to send %d expiring certificate notification emails.", emailsSent); return emailsSent; } @@ -327,6 +331,7 @@ public class SendExpiringCertificateNotificationEmailAction implements Runnable @AutoValue public abstract static class RegistrarInfo { + static RegistrarInfo create( Registrar registrar, boolean isCertExpiring, boolean isFailOverCertExpiring) { return new AutoValue_SendExpiringCertificateNotificationEmailAction_RegistrarInfo( diff --git a/core/src/test/java/google/registry/batch/SendExpiringCertificateNotificationEmailActionTest.java b/core/src/test/java/google/registry/batch/SendExpiringCertificateNotificationEmailActionTest.java index 0f659c681..c628973c0 100644 --- a/core/src/test/java/google/registry/batch/SendExpiringCertificateNotificationEmailActionTest.java +++ b/core/src/test/java/google/registry/batch/SendExpiringCertificateNotificationEmailActionTest.java @@ -639,9 +639,32 @@ class SendExpiringCertificateNotificationEmailActionTest { } @TestOfyAndSql - void run_responseStatusIs200() { + void run_sentZeroEmail_responseStatusIs200() { action.run(); assertThat(response.getStatus()).isEqualTo(SC_OK); + assertThat(response.getPayload()) + .isEqualTo("Done. Sent 0 expiring certificate notification emails in total."); + } + + @TestOfyAndSql + void run_sentEmails_responseStatusIs200() throws Exception { + for (int i = 1; i <= 5; i++) { + persistResource( + createRegistrar( + "id_" + i, + "name" + i, + SelfSignedCaCertificate.create( + "www.example.tld", + DateTime.parse("2020-09-02T00:00:00Z"), + DateTime.parse("2021-06-01T00:00:00Z")) + .cert(), + null) + .build()); + } + action.run(); + assertThat(response.getStatus()).isEqualTo(SC_OK); + assertThat(response.getPayload()) + .isEqualTo("Done. Sent 5 expiring certificate notification emails in total."); } /** Returns a sample registrar with a customized registrar name, client id and certificate* */