diff options
author | Bjørn Christian Seime <bjorncs@vespa.ai> | 2023-10-17 11:38:48 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@vespa.ai> | 2023-10-17 11:38:48 +0200 |
commit | 67135c3528fef9dfb7d2f2bba4482f8bd164a88b (patch) | |
tree | d28a689b47387dde6320595e4232e93e5d53e744 /controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudTrialExpirerTest.java | |
parent | 2735bc098c39fff0ddf29b9e68b477e2611a5265 (diff) |
Verify email content in unit test
Diffstat (limited to 'controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudTrialExpirerTest.java')
-rw-r--r-- | controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudTrialExpirerTest.java | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudTrialExpirerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudTrialExpirerTest.java index b595c8a8be3..7e8237606c6 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudTrialExpirerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudTrialExpirerTest.java @@ -9,6 +9,7 @@ import com.yahoo.vespa.flags.InMemoryFlagSource; import com.yahoo.vespa.flags.PermanentFlags; import com.yahoo.vespa.hosted.controller.ControllerTester; import com.yahoo.vespa.hosted.controller.api.integration.billing.PlanId; +import com.yahoo.vespa.hosted.controller.api.integration.stubs.MockMailer; import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder; import com.yahoo.vespa.hosted.controller.deployment.DeploymentTester; import com.yahoo.vespa.hosted.controller.notification.Notification; @@ -17,10 +18,15 @@ import com.yahoo.vespa.hosted.controller.tenant.LastLoginInfo; import com.yahoo.vespa.hosted.controller.tenant.Tenant; import org.junit.jupiter.api.Test; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; import java.time.Duration; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -28,6 +34,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; */ public class CloudTrialExpirerTest { + private static final boolean OVERWRITE_TEST_FILES = false; + private final ControllerTester tester = new ControllerTester(SystemName.PublicCd); private final DeploymentTester deploymentTester = new DeploymentTester(tester); private final CloudTrialExpirer expirer = new CloudTrialExpirer(tester.controller(), Duration.ofMinutes(5)); @@ -94,30 +102,50 @@ public class CloudTrialExpirerTest { } @Test - void queues_trial_notification_based_on_account_age() { + void queues_trial_notification_based_on_account_age() throws IOException { var clock = (ManualClock)tester.controller().clock(); + var mailer = (MockMailer) tester.serviceRegistry().mailer(); var tenant = TenantName.from("trial-tenant"); ((InMemoryFlagSource) tester.controller().flagSource()) .withBooleanFlag(Flags.CLOUD_TRIAL_NOTIFICATIONS.id(), true); registerTenant(tenant.value(), "trial", Duration.ZERO); assertEquals(0.0, expirer.maintain()); assertEquals("Welcome to Vespa Cloud", lastAccountLevelNotificationTitle(tenant)); + assertLastEmailEquals(mailer, "welcome.html"); clock.advance(Duration.ofDays(7)); assertEquals(0.0, expirer.maintain()); assertEquals("How is your Vespa Cloud trial going?", lastAccountLevelNotificationTitle(tenant)); + assertLastEmailEquals(mailer, "trial-reminder.html"); clock.advance(Duration.ofDays(5)); assertEquals(0.0, expirer.maintain()); assertEquals("Your Vespa Cloud trial expires in 2 days", lastAccountLevelNotificationTitle(tenant)); + assertLastEmailEquals(mailer, "trial-expiring-soon.html"); clock.advance(Duration.ofDays(1)); assertEquals(0.0, expirer.maintain()); assertEquals("Your Vespa Cloud trial expires tomorrow", lastAccountLevelNotificationTitle(tenant)); + assertLastEmailEquals(mailer, "trial-expiring-immediately.html"); clock.advance(Duration.ofDays(2)); assertEquals(0.0, expirer.maintain()); assertEquals("Your Vespa Cloud trial has expired", lastAccountLevelNotificationTitle(tenant)); + assertLastEmailEquals(mailer, "trial-expired.html"); + } + + private void assertLastEmailEquals(MockMailer mailer, String expectedContentFile) throws IOException { + var mails = mailer.inbox("dev-trial-tenant"); + assertFalse(mails.isEmpty()); + var content = mails.get(mails.size() - 1).htmlMessage().orElseThrow(); + var path = Paths.get("src/test/resources/mail/" + expectedContentFile); + if (OVERWRITE_TEST_FILES) { + Files.write(path, content.getBytes(), + StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE); + } else { + var expectedContent = Files.readString(path); + assertEquals(expectedContent, content); + } } private void registerTenant(String tenantName, String plan, Duration timeSinceLastLogin) { |