public static FakeSmtp withSmtpPort(Integer smtpPort) { SwarmGenericContainer container = fakeSmtpContainer() .withCommands("node", "cli", "--listen", "80", "--smtp", smtpPort.toString()); return new FakeSmtp(container, smtpPort); }
public void clean() { given(requestSpecification(), RESPONSE_SPECIFICATION) .get("/api/email") .jsonPath() .getList("id", String.class) .stream() .mapToInt(Integer::valueOf) .max() .ifPresent(id -> given(requestSpecification(), RESPONSE_SPECIFICATION) .get("/api/email/purge/" + id)); } }
public FakeSmtp() { this(fakeSmtpContainer().withExposedPorts(SMTP_PORT), SMTP_PORT); }
@BeforeClass public static void classSetUp() { fakeSmtp.awaitStarted(calmlyAwait.atMost(ONE_MINUTE)); }
@After public void teardown() { fakeSmtp.clean(); guiceJamesServer.stop(); }
@Test public void forwardingAnEmailShouldWork() throws Exception { jmapGuiceProbe.modifyVacation(AccountId.fromString(USER_WITH_DOMAIN), VacationPatch .builder() .isEnabled(true) .textBody(REASON) .build()); String externalMail = "ray@yopmail.com"; SMTPClient smtpClient = new SMTPClient(); smtpClient.connect(LOCALHOST_IP, guiceJamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort()); smtpClient.helo(DOMAIN); smtpClient.setSender(externalMail); smtpClient.rcpt("<" + USER_WITH_DOMAIN + ">"); smtpClient.sendShortMessageData("content"); calmlyAwait.atMost(1, TimeUnit.MINUTES) .untilAsserted(() -> fakeSmtp.assertEmailReceived(response -> response .body("[0].from", equalTo(USER_WITH_DOMAIN)) .body("[0].to[0]", equalTo(externalMail)) .body("[0].text", equalTo(REASON)))); } }
@Before public void setUp() throws Exception { getInMemoryDns() .registerMxRecord("yopmail.com", fakeSmtp.getContainer().getContainerIp()); guiceJamesServer = getJmapServer(); guiceJamesServer.start(); DataProbe dataProbe = guiceJamesServer.getProbe(DataProbeImpl.class); dataProbe.addDomain(DOMAIN); dataProbe.addUser(USER_WITH_DOMAIN, PASSWORD); MailboxProbe mailboxProbe = guiceJamesServer.getProbe(MailboxProbeImpl.class); mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USER_WITH_DOMAIN, DefaultMailboxes.SENT); mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USER_WITH_DOMAIN, DefaultMailboxes.INBOX); await(); jmapGuiceProbe = guiceJamesServer.getProbe(JmapGuiceProbe.class); }
public void assertEmailReceived(Function<ValidatableResponse, ValidatableResponse> expectations) { expectations.apply( given(requestSpecification(), RESPONSE_SPECIFICATION) .get("/api/email") .then() .statusCode(200)); }