From: <wa...@us...> - 2009-02-19 20:39:41
|
Revision: 368 http://columba.svn.sourceforge.net/columba/?rev=368&view=rev Author: waffel Date: 2009-02-19 20:39:36 +0000 (Thu, 19 Feb 2009) Log Message: ----------- [feature] using test cases from main package Added Paths: ----------- ristretto/trunk/ristretto-smtp/src/test/ ristretto/trunk/ristretto-smtp/src/test/java/ ristretto/trunk/ristretto-smtp/src/test/java/org/ ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/ ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/ ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/SMTPInputStreamTest.java ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/SMTPProtocol2Test.java ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/StopWordSafeInputStreamTest.java ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/parser/ ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/parser/SMTPResponseParserTest.java Added: ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/SMTPInputStreamTest.java =================================================================== --- ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/SMTPInputStreamTest.java (rev 0) +++ ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/SMTPInputStreamTest.java 2009-02-19 20:39:36 UTC (rev 368) @@ -0,0 +1,53 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ristretto Mail API. + * + * The Initial Developers of the Original Code are + * Timo Stich and Frederik Dietz. + * Portions created by the Initial Developers are Copyright (C) 2004 + * All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +package org.columba.ristretto.smtp; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import junit.framework.TestCase; + +public class SMTPInputStreamTest extends TestCase { + + public void testResponse() throws IOException, SMTPException { + String responseString = "250 message\r\n"; + SMTPInputStream in = new SMTPInputStream( new ByteArrayInputStream(responseString.getBytes())); + + SMTPResponse response = in.readSingleLineResponse(); + assertTrue(response != null); + } + +} Property changes on: ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/SMTPInputStreamTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/SMTPProtocol2Test.java =================================================================== --- ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/SMTPProtocol2Test.java (rev 0) +++ ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/SMTPProtocol2Test.java 2009-02-19 20:39:36 UTC (rev 368) @@ -0,0 +1,169 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ristretto Mail API. + * + * The Initial Developers of the Original Code are + * Timo Stich and Frederik Dietz. + * Portions created by the Initial Developers are Copyright (C) 2004 + * All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +package org.columba.ristretto.smtp; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.InetAddress; + +import junit.framework.TestCase; + +import org.columba.ristretto.coder.Base64; +import org.columba.ristretto.message.Address; +import org.columba.ristretto.testserver.SimpleTestServerSession; +import org.columba.ristretto.testserver.TestServer; + +public class SMTPProtocol2Test extends TestCase { + + public void testOpenPort() throws IOException, SMTPException { + SimpleTestServerSession testSession = new SimpleTestServerSession("220 test.domain Hello\r\n", "QUIT\r\n"); + testSession.addDialog("QUIT\r\n", "250 bye\r\n"); + + TestServer testServer = new TestServer(50025, testSession); + + SMTPProtocol protocol = new SMTPProtocol("localhost", 50025); + + assertTrue( protocol.openPort().equals("test.domain") ); + + protocol.quit(); + + testServer.stop(); + } + + public void testOpenPort2() throws IOException, SMTPException { + SimpleTestServerSession testSession = new SimpleTestServerSession("220 ESMTP\r\n", "QUIT\r\n"); + testSession.addDialog("QUIT\r\n", "250 bye\r\n"); + + TestServer testServer = new TestServer(50025, testSession); + + SMTPProtocol protocol = new SMTPProtocol("localhost", 50025); + + protocol.openPort(); + + protocol.quit(); + + testServer.stop(); + } + + public void testAuthenticate() throws Exception { + SimpleTestServerSession testSession = new SimpleTestServerSession("220 test.domain Hello\r\n", "QUIT\r\n"); + testSession.addDialog("AUTH PLAIN\r\n", "334 continue\r\n"); + testSession.addDialog( Base64.encode("\0test\0bar") + "\r\n", "250 OK\r\n"); + testSession.addDialog("QUIT\r\n", "250 bye\r\n"); + + TestServer testServer = new TestServer(50025, testSession); + + SMTPProtocol protocol = new SMTPProtocol("localhost", 50025); + + assertTrue( protocol.openPort().equals("test.domain") ); + protocol.auth("PLAIN", "test", "bar".toCharArray()); + + protocol.quit(); + + testServer.stop(); + } + + public void testSimpleSession() throws IOException, SMTPException { + SimpleTestServerSession testSession = new SimpleTestServerSession("220 test.domain Hello\r\n", "QUIT\r\n"); + testSession.addDialog("MAIL FROM:<sm...@ba...>\r\n", "250 OK\r\n"); + testSession.addDialog("RCPT TO:<Jo...@fo...>\r\n", "250 OK\r\n"); + testSession.addDialog("DATA\r\n", "354 Start mail input; end with <CRLF>.<CRLF>\r\n"); + testSession.addDialog("This is a test mail\r\n", ""); + testSession.addDialog(".\r\n", "250 OK\r\n"); + testSession.addDialog("QUIT\r\n", "250 bye\r\n"); + + TestServer testServer = new TestServer(50025, testSession); + + SMTPProtocol protocol = new SMTPProtocol("localhost", 50025); + + assertTrue( protocol.openPort().equals("test.domain") ); + + protocol.mail(new Address("sm...@ba...")); + protocol.rcpt(new Address("Jo...@fo...")); + protocol.data(new ByteArrayInputStream("This is a test mail".getBytes())); + protocol.quit(); + + testServer.stop(); + } + + public void testEhloFail() throws IOException, SMTPException { + SimpleTestServerSession testSession = new SimpleTestServerSession("220 ESMTP\r\n", "QUIT\r\n"); + testSession.addDialog("EHLO [127.0.0.1]\r\n", "500 5.5.1 Command unrecognized: \"XXXX [67.84.198.179]\"\r\n"); + testSession.addDialog("HELO [127.0.0.1]\r\n", "220 OK\r\n"); + testSession.addDialog("QUIT\r\n", "250 bye\r\n"); + + TestServer testServer = new TestServer(50025, testSession); + + SMTPProtocol protocol = new SMTPProtocol("localhost", 50025); + + InetAddress local = InetAddress.getByAddress(new byte[] {127,0,0,1}); + + protocol.openPort(); + try { + protocol.ehlo(local); + assertTrue(false); + } catch (SMTPException e) { + + } + protocol.helo(local); + + protocol.quit(); + + testServer.stop(); + } + + public void testCapabilities() throws Exception { + SimpleTestServerSession testSession = new SimpleTestServerSession("220 test.domain Hello\r\n", "QUIT\r\n"); + testSession.addDialog("EHLO [127.0.0.1]\r\n", "250-foo.com greets bar.com\r\n250-AUTH=LOGIN PLAIN\r\n250 HELP\r\n"); + testSession.addDialog("QUIT\r\n", "250 bye\r\n"); + + TestServer testServer = new TestServer(50025, testSession); + + SMTPProtocol protocol = new SMTPProtocol("localhost", 50025); + assertTrue( protocol.openPort().equals("test.domain") ); + + String capas[] = protocol.ehlo(InetAddress.getByAddress(new byte[] {127,0,0,1})); + assertEquals(2,capas.length); + assertEquals("AUTH=LOGIN PLAIN", capas[0]); + assertEquals("HELP", capas[1]); + + protocol.quit(); + + testServer.stop(); + } + + +} Property changes on: ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/SMTPProtocol2Test.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/StopWordSafeInputStreamTest.java =================================================================== --- ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/StopWordSafeInputStreamTest.java (rev 0) +++ ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/StopWordSafeInputStreamTest.java 2009-02-19 20:39:36 UTC (rev 368) @@ -0,0 +1,73 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ristretto Mail API. + * + * The Initial Developers of the Original Code are + * Timo Stich and Frederik Dietz. + * Portions created by the Initial Developers are Copyright (C) 2004 + * All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +package org.columba.ristretto.smtp; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import junit.framework.TestCase; + +public class StopWordSafeInputStreamTest extends TestCase { + + public void test1() throws IOException { + String test = "bla\r\n.\r\nbla"; + InputStream in = new StopWordSafeInputStream( new ByteArrayInputStream(test.getBytes())); + + StringBuffer result = new StringBuffer(); + int read = in.read(); + while(read != -1 ) { + result.append((char)read); + read = in.read(); + } + + assertTrue(result.toString().equals("bla\r\n..\r\nbla")); + } + + public void test2() throws IOException { + String test = "bla 15.10.\r\nbla"; + InputStream in = new StopWordSafeInputStream( new ByteArrayInputStream(test.getBytes())); + + StringBuffer result = new StringBuffer(); + int read = in.read(); + while(read != -1 ) { + result.append((char)read); + read = in.read(); + } + + assertTrue(result.toString().equals("bla 15.10.\r\nbla")); + } +} Property changes on: ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/StopWordSafeInputStreamTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/parser/SMTPResponseParserTest.java =================================================================== --- ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/parser/SMTPResponseParserTest.java (rev 0) +++ ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/parser/SMTPResponseParserTest.java 2009-02-19 20:39:36 UTC (rev 368) @@ -0,0 +1,81 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ristretto Mail API. + * + * The Initial Developers of the Original Code are + * Timo Stich and Frederik Dietz. + * Portions created by the Initial Developers are Copyright (C) 2004 + * All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +package org.columba.ristretto.smtp.parser; + +import junit.framework.TestCase; + +import org.columba.ristretto.parser.ParserException; +import org.columba.ristretto.smtp.SMTPResponse; + +public class SMTPResponseParserTest extends TestCase { + + public void testSingleMessage() throws ParserException { + String responseString = "250 OK\r\n"; + SMTPResponse response = SMTPResponseParser.parse(responseString); + + assertTrue( response.getCode() == 250); + assertTrue( response.getMessage().equals("OK")); + assertFalse( response.isHasSuccessor() ); + } + + public void testSingleNoMessage() throws ParserException { + String responseString = "250\r\n"; + SMTPResponse response = SMTPResponseParser.parse(responseString); + + assertTrue( response.getCode() == 250); + assertTrue( response.getMessage() == null); + assertFalse( response.isHasSuccessor() ); + } + + public void testSingleGreeting() throws ParserException { + String responseString = "220 smtp.domain greeting\r\n"; + SMTPResponse response = SMTPResponseParser.parse(responseString); + + assertTrue( response.getCode() == 220); + assertTrue( response.getDomain().equals("smtp.domain")); + assertTrue( response.getMessage().equals("greeting")); + assertFalse( response.isHasSuccessor() ); + } + + public void testSingleMessageSuccessor() throws ParserException { + String responseString = "250-OK\r\n"; + SMTPResponse response = SMTPResponseParser.parse(responseString); + + assertTrue( response.getCode() == 250); + assertTrue( response.getMessage().equals("OK")); + assertTrue( response.isHasSuccessor() ); + } + } Property changes on: ristretto/trunk/ristretto-smtp/src/test/java/org/columba/ristretto/smtp/parser/SMTPResponseParserTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |