Search in sources :

Example 1 with GreenMailUser

use of com.icegreen.greenmail.user.GreenMailUser in project gerrit by GerritCodeReview.

the class MailIT method delete.

@Test
public void delete() throws Exception {
    GreenMailUser user = mockPop3Server.setUser(USERNAME, USERNAME, PASSWORD);
    user.deliver(createSimpleMessage());
    assertThat(mockPop3Server.getReceivedMessages().length).isEqualTo(1);
    // Let Gerrit handle emails
    mailReceiver.handleEmails(false);
    // Check that the message is still present
    assertThat(mockPop3Server.getReceivedMessages().length).isEqualTo(1);
    // Mark the message for deletion
    mailReceiver.requestDeletion(mockPop3Server.getReceivedMessages()[0].getMessageID());
    // Let Gerrit handle emails
    mailReceiver.handleEmails(false);
    // Check that the message was deleted
    assertThat(mockPop3Server.getReceivedMessages().length).isEqualTo(0);
}
Also used : GreenMailUser(com.icegreen.greenmail.user.GreenMailUser) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with GreenMailUser

use of com.icegreen.greenmail.user.GreenMailUser in project wso2-axis2-transports by wso2.

the class GreenMailTestEnvironment method allocateAccount.

@Override
public Account allocateAccount() throws Exception {
    if (unallocatedAccounts.isEmpty()) {
        String login = "test" + accountNumber++;
        GreenMailUser user = greenMail.setUser(login + "@localhost", login, "password");
        final MailFolder inbox = greenMail.getManagers().getImapHostManager().getInbox(user);
        inbox.addListener(new FolderListener() {

            public void added(int msn) {
                StoredMessage storedMessage = (StoredMessage) inbox.getMessages().get(msn - 1);
                try {
                    OutputStream out = logManager.createLog("greenmail");
                    try {
                        storedMessage.getMimeMessage().writeTo(out);
                    } finally {
                        out.close();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }

            public void expunged(int msn) {
            }

            public void flagsUpdated(int msn, Flags flags, Long uid) {
            }

            public void mailboxDeleted() {
            }
        });
        return new Account(user.getEmail(), user.getLogin(), user.getPassword());
    } else {
        return unallocatedAccounts.remove(0);
    }
}
Also used : FolderListener(com.icegreen.greenmail.store.FolderListener) StoredMessage(com.icegreen.greenmail.store.StoredMessage) MailFolder(com.icegreen.greenmail.store.MailFolder) OutputStream(java.io.OutputStream) GreenMailUser(com.icegreen.greenmail.user.GreenMailUser) Flags(javax.mail.Flags)

Example 3 with GreenMailUser

use of com.icegreen.greenmail.user.GreenMailUser in project gerrit by GerritCodeReview.

the class MailIT method deletesMessageMarkedForDeletion.

@Test
public void deletesMessageMarkedForDeletion() throws Exception {
    GreenMailUser user = mockPop3Server.setUser(USERNAME, USERNAME, PASSWORD);
    user.deliver(createSimpleMessage());
    assertThat(mockPop3Server.getReceivedMessages().length).isEqualTo(1);
    // Mark the message for deletion
    mailReceiver.requestDeletion(mockPop3Server.getReceivedMessages()[0].getMessageID());
    // Let Gerrit handle emails
    mailReceiver.handleEmails(false);
    // Check that the message was deleted
    assertThat(mockPop3Server.getReceivedMessages().length).isEqualTo(0);
}
Also used : GreenMailUser(com.icegreen.greenmail.user.GreenMailUser) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with GreenMailUser

use of com.icegreen.greenmail.user.GreenMailUser in project gerrit by GerritCodeReview.

the class MailIT method doesNotDeleteMessageNotMarkedForDeletion.

@Test
public void doesNotDeleteMessageNotMarkedForDeletion() throws Exception {
    GreenMailUser user = mockPop3Server.setUser(USERNAME, USERNAME, PASSWORD);
    user.deliver(createSimpleMessage());
    assertThat(mockPop3Server.getReceivedMessages().length).isEqualTo(1);
    // Let Gerrit handle emails
    mailReceiver.handleEmails(false);
    // Check that the message is still present
    assertThat(mockPop3Server.getReceivedMessages().length).isEqualTo(1);
}
Also used : GreenMailUser(com.icegreen.greenmail.user.GreenMailUser) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with GreenMailUser

use of com.icegreen.greenmail.user.GreenMailUser in project sandbox by irof.

the class GreenMailTest method testRetrieving.

@Test
public void testRetrieving() throws Exception {
    GreenMailUser user = greenMailRule.setUser("to@example.com", "login-test-id", "login-test-password");
    user.deliver(createMessage());
    GreenMailUtil.sendTextEmailTest("to@example.com", "from@example.com", "some test subject", "some test body");
    assertThat(greenMailRule.getReceivedMessages()).hasSize(2);
}
Also used : GreenMailUser(com.icegreen.greenmail.user.GreenMailUser) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Aggregations

GreenMailUser (com.icegreen.greenmail.user.GreenMailUser)5 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)4 Test (org.junit.Test)4 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 FolderListener (com.icegreen.greenmail.store.FolderListener)1 MailFolder (com.icegreen.greenmail.store.MailFolder)1 StoredMessage (com.icegreen.greenmail.store.StoredMessage)1 OutputStream (java.io.OutputStream)1 Flags (javax.mail.Flags)1