You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2011/11/18 11:57:06 UTC

svn commit: r1203587 - in /james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core: AbstractInputStreamTest.java CRLFTerminatedInputStreamTest.java ExtraDotInputStreamTest.java

Author: norman
Date: Fri Nov 18 10:57:06 2011
New Revision: 1203587

URL: http://svn.apache.org/viewvc?rev=1203587&view=rev
Log:
Add tests from server to protocols pop3. See PROTOCOLS-2

Added:
    james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/AbstractInputStreamTest.java
    james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStreamTest.java
    james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/ExtraDotInputStreamTest.java

Added: james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/AbstractInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/AbstractInputStreamTest.java?rev=1203587&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/AbstractInputStreamTest.java (added)
+++ james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/AbstractInputStreamTest.java Fri Nov 18 10:57:06 2011
@@ -0,0 +1,59 @@
+/****************************************************************
+ * 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.core;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import junit.framework.TestCase;
+
+
+public abstract class AbstractInputStreamTest extends TestCase{
+
+    protected void checkRead(InputStream in, String expected) throws IOException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        int i = -1;
+        while ((i = in.read()) != -1) {
+            out.write(i);
+        }
+        in.close();
+        out.close();        
+        assertEquals(expected, new String(out.toByteArray()));
+
+        
+        
+    }
+    
+    protected void checkReadViaArray(InputStream in, String expected) throws IOException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+        byte[] buf = new byte[3];
+        int i = 0;
+        while ((i = in.read(buf)) != -1) {
+            out.write(buf, 0, i);
+        }
+        
+       
+        in.close();
+        out.close();
+        assertEquals(expected, new String(out.toByteArray()));
+        
+        
+    }
+}

Added: james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStreamTest.java?rev=1203587&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStreamTest.java (added)
+++ james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/CRLFTerminatedInputStreamTest.java Fri Nov 18 10:57:06 2011
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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.core;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+public class CRLFTerminatedInputStreamTest extends AbstractInputStreamTest {
+
+    public void testCRLFPresent() throws IOException {
+        String data = "Subject: test\r\n\r\ndata\r\n";
+        checkRead(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), data);
+        checkReadViaArray(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), data);
+
+    }
+
+    public void testCRPresent() throws IOException {
+        String data = "Subject: test\r\n\r\ndata\r";
+        String expected = data + "\n";
+        checkRead(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), expected);
+        checkReadViaArray(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), expected);
+    }
+
+    public void testNonPresent() throws IOException {
+        String data = "Subject: test\r\n\r\ndata";
+        String expected = data + "\r\n";
+        checkRead(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), expected);
+        checkReadViaArray(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), expected);
+
+    }
+
+}

Added: james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/ExtraDotInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/ExtraDotInputStreamTest.java?rev=1203587&view=auto
==============================================================================
--- james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/ExtraDotInputStreamTest.java (added)
+++ james/protocols/trunk/pop3/src/test/java/org/apache/james/protocols/pop3/core/ExtraDotInputStreamTest.java Fri Nov 18 10:57:06 2011
@@ -0,0 +1,78 @@
+/****************************************************************
+ * 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.core;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+public class ExtraDotInputStreamTest extends AbstractInputStreamTest {
+
+    public void testExtraDot() throws IOException {
+        String data = "This\r\n.\r\nThis.\r\n";
+        String expectedOutput = "This\r\n..\r\nThis.\r\n";
+        
+        checkRead(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), expectedOutput);
+        checkReadViaArray(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), expectedOutput);
+
+    }
+
+    public void testExtraDotOnDoubleDot() throws IOException {
+        String data = "This\r\n..\r\nThis.\r\n";
+        String expectedOutput = "This\r\n...\r\nThis.\r\n";
+
+        checkRead(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), expectedOutput);
+        checkReadViaArray(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), expectedOutput);
+
+    }
+    
+
+    public void testExtraDotOnDotWithText() throws IOException {
+        String data = "This\r\n.TestText\r\nThis.\r\n";
+        String expected = "This\r\n..TestText\r\nThis.\r\n";
+
+        checkRead(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), expected);
+        checkReadViaArray(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), expected);
+
+    }
+    
+    public void testNoDotCLRF() throws IOException {
+        String data = "ABCD\r\n";
+        checkRead(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), data);
+        checkReadViaArray(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), data);
+    }
+
+    public void testNoDot() throws IOException {
+        String data = "ABCD";
+        checkRead(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), data);
+        checkReadViaArray(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), data);
+    }
+
+    // Proof of BUG JAMES-1152
+    public void testNoDotHeaderBody() throws IOException {
+        String data = "Subject: test\r\n\r\nABCD\r\n";
+        checkRead(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), data);
+        checkReadViaArray(new ExtraDotInputStream(new ByteArrayInputStream(data.getBytes())), data);
+
+    }
+   
+
+
+    
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org