Author: norman
Date: Sun Jan 1 16:13:29 2012
New Revision: 1226260
URL: http://svn.apache.org/viewvc?rev=1226260&view=rev
Log:
Start to add unit tests for pop3. See PROTOCOLS-65
Added:
james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/POP3ServerTest.java
(with props)
james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/TestUtils.java
(with props)
Modified:
james/protocols/trunk/pop3/pom.xml
Modified: james/protocols/trunk/pop3/pom.xml
URL:
http://svn.apache.org/viewvc/james/protocols/trunk/pop3/pom.xml?rev=1226260&r1=1226259&r2=1226260&view=diff
==============================================================================
--- james/protocols/trunk/pop3/pom.xml (original)
+++ james/protocols/trunk/pop3/pom.xml Sun Jan 1 16:13:29 2012
@@ -38,6 +38,16 @@
<artifactId>protocols-api</artifactId>
</dependency>
<dependency>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james.protocols</groupId>
+ <artifactId>protocols-netty</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Added:
james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/POP3ServerTest.java
URL:
http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/POP3ServerTest.java?rev=1226260&view=auto
==============================================================================
---
james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/POP3ServerTest.java
(added)
+++
james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/POP3ServerTest.java
Sun Jan 1 16:13:29 2012
@@ -0,0 +1,132 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.protocols.pop3;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+
+import org.apache.commons.net.pop3.POP3Client;
+import org.apache.james.protocols.api.logger.Logger;
+import org.apache.james.protocols.netty.NettyServer;
+import org.apache.james.protocols.pop3.mailbox.Mailbox;
+import org.apache.james.protocols.pop3.mailbox.MailboxFactory;
+
+import org.junit.Test;
+
+public class POP3ServerTest {
+
+ private POP3Protocol createProtocol(MailboxFactory factory) {
+ return new POP3Protocol(new POP3ProtocolHandlerChain(factory), new
POP3Configuration(), new Logger() {
+
+ public void warn(String message, Throwable t) {
+
+ }
+
+ public void warn(String message) {
+
+ }
+
+ public void trace(String message, Throwable t) {
+
+ }
+
+ public void trace(String message) {
+
+ }
+
+ public boolean isWarnEnabled() {
+ return false;
+ }
+
+ public boolean isTraceEnabled() {
+ return false;
+ }
+
+ public boolean isInfoEnabled() {
+ return false;
+ }
+
+ public boolean isErrorEnabled() {
+ return false;
+ }
+
+ public boolean isDebugEnabled() {
+ return false;
+ }
+
+ public void info(String message, Throwable t) {
+
+ }
+
+ public void info(String message) {
+ }
+
+ public void error(String message, Throwable t) {
+
+ }
+
+ public void error(String message) {
+
+ }
+
+ public void debug(String message, Throwable t) {
+
+ }
+
+ public void debug(String message) {
+
+ }
+ });
+ }
+ @Test
+ public void testInvalidAuth() throws Exception {
+ InetSocketAddress address = new InetSocketAddress("127.0.0.1",
TestUtils.getFreePort());
+
+ NettyServer server = null;
+ try {
+ server = new NettyServer(createProtocol(new MockMailboxFactory()));
+ server.setListenAddresses(address);
+ server.bind();
+
+ POP3Client client = new POP3Client();
+ client.connect(address.getAddress().getHostAddress(),
address.getPort());
+
+ assertFalse(client.login("invalid", "invalid"));
+
+ //assertTrue(client.logout());
+
+ } finally {
+ if (server != null) {
+ server.unbind();
+ }
+ }
+
+ }
+
+ private final class MockMailboxFactory implements MailboxFactory {
+
+ public Mailbox getMailbox(POP3Session session, String password) throws
IOException {
+ return null;
+ }
+
+ }
+}
Propchange:
james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/POP3ServerTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/TestUtils.java
URL:
http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/TestUtils.java?rev=1226260&view=auto
==============================================================================
---
james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/TestUtils.java
(added)
+++
james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/TestUtils.java
Sun Jan 1 16:13:29 2012
@@ -0,0 +1,48 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.protocols.pop3;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+
+public class TestUtils {
+
+ private final static int START_PORT = 20000;
+ private final static int END_PORT = 30000;
+
+ /**
+ * Return a free port which can be used to bind to
+ *
+ * @return port
+ */
+ public synchronized static int getFreePort() {
+ for(int start = START_PORT; start <= END_PORT; start++) {
+ try {
+ ServerSocket socket = new ServerSocket(start);
+ socket.setReuseAddress(true);
+ socket.close();
+ return start;
+ } catch (IOException e) {
+ // ignore
+ }
+
+ }
+ throw new RuntimeException("Unable to find a free port....");
+ }
+}
Propchange:
james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/TestUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]