@Test
@Ignore
public void testStatUidlListTwoConnections() throws Exception {
finishSetUp(pop3Configuration);
pop3Client = new POP3Client();
pop3Client.connect("127.0.0.1", pop3Port);
usersRepository.addUser("foo2", "bar2");
MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, "foo2", "INBOX");
MailboxSession session = mailboxManager.login("foo2", "bar2", LoggerFactory.getLogger("Test"));
if (!mailboxManager.mailboxExists(mailboxPath, session)) {
mailboxManager.createMailbox(mailboxPath, session);
}
int msgCount = 100;
for (int i = 0; i < msgCount; i++) {
mailboxManager.getMailbox(mailboxPath, session).appendMessage(new ByteArrayInputStream(("Subject: test\r\n\r\n" + i).
getBytes()), new Date(), session, true, new Flags());
}
pop3Client.login("foo2", "bar2");
assertEquals(1, pop3Client.getState());
POP3MessageInfo[] listEntries = pop3Client.listMessages();
POP3MessageInfo[] uidlEntries = pop3Client.listUniqueIdentifiers();
POP3MessageInfo statInfo = pop3Client.status();
assertEquals(msgCount, listEntries.length);
assertEquals(msgCount, uidlEntries.length);
assertEquals(msgCount, statInfo.number);
POP3Client m_pop3Protocol2 = new POP3Client();
m_pop3Protocol2.connect("127.0.0.1", pop3Port);
m_pop3Protocol2.login("foo2", "bar2");
assertEquals(1, m_pop3Protocol2.getState());
POP3MessageInfo[] listEntries2 = m_pop3Protocol2.listMessages();
POP3MessageInfo[] uidlEntries2 = m_pop3Protocol2.listUniqueIdentifiers();
POP3MessageInfo statInfo2 = m_pop3Protocol2.status();
assertEquals(msgCount, listEntries2.length);
assertEquals(msgCount, uidlEntries2.length);
assertEquals(msgCount, statInfo2.number);
pop3Client.deleteMessage(1);
listEntries = pop3Client.listMessages();
uidlEntries = pop3Client.listUniqueIdentifiers();
statInfo = pop3Client.status();
assertEquals(msgCount - 1, listEntries.length);
assertEquals(msgCount - 1, uidlEntries.length);
assertEquals(msgCount - 1, statInfo.number);
// even after the message was deleted it should get displayed in the
// second connection
listEntries2 = m_pop3Protocol2.listMessages();
uidlEntries2 = m_pop3Protocol2.listUniqueIdentifiers();
statInfo2 = m_pop3Protocol2.status();
assertEquals(msgCount, listEntries2.length);
assertEquals(msgCount, uidlEntries2.length);
assertEquals(msgCount, statInfo2.number);
assertTrue(pop3Client.logout());
pop3Client.disconnect();
// even after the message was deleted and the session was quit it should
// get displayed in the second connection
listEntries2 = m_pop3Protocol2.listMessages();
uidlEntries2 = m_pop3Protocol2.listUniqueIdentifiers();
statInfo2 = m_pop3Protocol2.status();
assertEquals(msgCount, listEntries2.length);
assertEquals(msgCount, uidlEntries2.length);
assertEquals(msgCount, statInfo2.number);
// This both should error and so return null
assertNull(m_pop3Protocol2.retrieveMessageTop(1, 100));
assertNull(m_pop3Protocol2.retrieveMessage(1));
m_pop3Protocol2.sendCommand("quit");
m_pop3Protocol2.disconnect();
mailboxManager.deleteMailbox(mailboxPath, session);
}