IMAP: add IMAP unit test

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1116 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-01 13:27:49 +00:00
parent 3320d19494
commit ad42f58f24
1 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,83 @@
/*
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
* Copyright (C) 2010 Mickael Guessant
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package davmail.imap;
import davmail.Settings;
import davmail.exchange.AbstractExchangeSessionTestCase;
import java.io.*;
import java.net.Socket;
/**
* IMAP tests, an instance of DavMail Gateway must be available
*/
public class TestImap extends AbstractExchangeSessionTestCase {
static Socket clientSocket;
static BufferedWriter socketWriter;
static BufferedReader socketReader;
protected void writeLine(String line) throws IOException {
socketWriter.write(line);
socketWriter.newLine();
socketWriter.flush();
}
protected String readFullAnswer(String prefix) throws IOException {
String line = socketReader.readLine();
while (!line.startsWith(prefix)) {
line = socketReader.readLine();
}
return line;
}
@Override
public void setUp() throws IOException {
super.setUp();
if (clientSocket == null) {
clientSocket = new Socket("localhost", Settings.getIntProperty("davmail.imapPort"));
socketWriter = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
socketReader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
}
}
public void testBanner() throws IOException {
String banner = socketReader.readLine();
assertNotNull(banner);
}
public void testLogin() throws IOException {
writeLine(". LOGIN " + Settings.getProperty("davmail.username").replaceAll("\\\\", "\\\\\\\\") + ' ' + Settings.getProperty("davmail.password"));
assertEquals(". OK Authenticated", socketReader.readLine());
}
public void testSelectInbox() throws IOException {
writeLine(". SELECT INBOX");
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
}
public void testUidSearchUndeleted() throws IOException {
writeLine(". UID SEARCH UNDELETED");
assertEquals(". OK", readFullAnswer("."));
}
public void testLogout() throws IOException {
writeLine(". LOGOUT");
assertEquals("* BYE Closing connection", socketReader.readLine());
}
}