Search in sources :

Example 11 with Retriever

use of com.icegreen.greenmail.util.Retriever in project greenmail by greenmail-mail-test.

the class ExampleDisableAuthenticationTest method testNoAuthIMAP.

@Test
public void testNoAuthIMAP() {
    try (Retriever retriever = new Retriever(greenMail.getImap())) {
        Message[] messages = retriever.getMessages("foo@localhost");
        assertThat(messages.length).isEqualTo(0);
    }
}
Also used : Retriever(com.icegreen.greenmail.util.Retriever) Message(jakarta.mail.Message) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest) Test(org.junit.Test)

Example 12 with Retriever

use of com.icegreen.greenmail.util.Retriever in project greenmail by greenmail-mail-test.

the class ExampleDisableAuthenticationTest method testExistingUserNotRecreated.

@Test
public void testExistingUserNotRecreated() {
    try (Retriever retriever = new Retriever(greenMail.getImap())) {
        Message[] messages = retriever.getMessages("foo@localhost");
        assertThat(messages.length).isEqualTo(0);
        assertThat(greenMail.getUserManager().hasUser("foo@localhost")).isTrue();
    }
}
Also used : Retriever(com.icegreen.greenmail.util.Retriever) Message(jakarta.mail.Message) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest) Test(org.junit.Test)

Example 13 with Retriever

use of com.icegreen.greenmail.util.Retriever in project greenmail by greenmail-mail-test.

the class ExamplePurgeAllEmailsTest method testRemoveAllMessagesInImapMailbox.

@Test
public void testRemoveAllMessagesInImapMailbox() throws FolderException {
    try (Retriever retriever = new Retriever(greenMailRule.getImap())) {
        greenMailRule.setUser("foo@localhost", "pwd");
        GreenMailUtil.sendTextEmail("foo@localhost", "bar@localhost", "Test subject", "Test message", ServerSetupTest.SMTP);
        assertThat(greenMailRule.waitForIncomingEmail(1)).isTrue();
        greenMailRule.purgeEmailFromAllMailboxes();
        Message[] messages = retriever.getMessages("foo@localhost", "pwd");
        assertThat(messages.length).isEqualTo(0);
    }
}
Also used : Retriever(com.icegreen.greenmail.util.Retriever) Message(jakarta.mail.Message) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest) Test(org.junit.Test)

Example 14 with Retriever

use of com.icegreen.greenmail.util.Retriever in project greenmail by greenmail-mail-test.

the class AuthenticationDisabledTest method testReceiveWithAuthDisabled.

@Test
public void testReceiveWithAuthDisabled() {
    final String to = "to@localhost";
    greenMail.waitForIncomingEmail(500, 1);
    try (Retriever retriever = new Retriever(greenMail.getImap())) {
        Message[] messages = retriever.getMessages(to);
        assertThat(messages.length).isEqualTo(0);
    }
}
Also used : Retriever(com.icegreen.greenmail.util.Retriever) Message(jakarta.mail.Message) MimeMessage(jakarta.mail.internet.MimeMessage) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 15 with Retriever

use of com.icegreen.greenmail.util.Retriever in project greenmail by greenmail-mail-test.

the class AuthenticationDisabledTest method testSendMailAndReceiveWithAuthDisabled.

@Test
public void testSendMailAndReceiveWithAuthDisabled() throws MessagingException, IOException {
    final String to = "to@localhost";
    final String subject = "subject";
    final String body = "body";
    GreenMailUtil.sendTextEmailTest(to, "from@localhost", subject, body);
    MimeMessage[] emails = greenMail.getReceivedMessages();
    assertThat(emails.length).isEqualTo(1);
    assertThat(emails[0].getSubject()).isEqualTo(subject);
    assertThat(GreenMailUtil.getBody(emails[0])).isEqualTo(body);
    greenMail.waitForIncomingEmail(5000, 1);
    try (Retriever retriever = new Retriever(greenMail.getImap())) {
        Message[] messages = retriever.getMessages(to);
        assertThat(messages.length).isEqualTo(1);
        assertThat(messages[0].getSubject()).isEqualTo(subject);
        assertThat(messages[0].getContent()).isEqualTo(body);
    }
}
Also used : Retriever(com.icegreen.greenmail.util.Retriever) Message(jakarta.mail.Message) MimeMessage(jakarta.mail.internet.MimeMessage) MimeMessage(jakarta.mail.internet.MimeMessage) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Aggregations

Retriever (com.icegreen.greenmail.util.Retriever)25 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)17 Message (jakarta.mail.Message)17 Test (org.junit.Test)15 MimeMessage (jakarta.mail.internet.MimeMessage)11 MimeMultipart (jakarta.mail.internet.MimeMultipart)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 IMAPMessage (com.sun.mail.imap.IMAPMessage)2 BodyPart (jakarta.mail.BodyPart)2 InputStream (java.io.InputStream)2 URI (java.net.URI)2 Date (java.util.Date)2 Message (javax.mail.Message)2 Test (org.junit.jupiter.api.Test)2 EditUserDTO (com.github.nkonev.aaa.dto.EditUserDTO)1 GreenMailMimeMessage (com.icegreen.greenmail.test.util.GreenMailMimeMessage)1 GreenMail (com.icegreen.greenmail.util.GreenMail)1 POP3Folder (com.sun.mail.pop3.POP3Folder)1 Session (jakarta.mail.Session)1 Properties (java.util.Properties)1