You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2008/12/13 00:03:43 UTC

svn commit: r726146 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/attachments/BoundaryPushbackInputStream.java axiom-tests/src/test/java/org/apache/axiom/attachments/BoundaryPushbackInputStreamTest.java

Author: veithen
Date: Fri Dec 12 15:03:42 2008
New Revision: 726146

URL: http://svn.apache.org/viewvc?rev=726146&view=rev
Log:
WSCOMMONS-328: Removed an incorrect test from BoundaryPushbackInputStream that caused it in some cases to include the \r\n sequence at the end of an attachment. Added a test case for this.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/BoundaryPushbackInputStreamTest.java   (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/BoundaryPushbackInputStream.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/BoundaryPushbackInputStream.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/BoundaryPushbackInputStream.java?rev=726146&r1=726145&r2=726146&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/BoundaryPushbackInputStream.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/BoundaryPushbackInputStream.java Fri Dec 12 15:03:42 2008
@@ -317,13 +317,6 @@
         }
         int foundAt = ByteSearch.skipSearch(boundary, true,searchbuf, start, end, skip);
 
-        // First find the boundary marker
-        if (foundAt >= 0) {    // Something was found.
-            if (foundAt + rnBoundaryLen > end) {
-                foundAt = -1;  // Not sure why this check is done
-            }
-        }
-        
         // Backup 2 if the boundary is preceeded by /r/n
         // The /r/n are treated as part of the boundary
         if (foundAt >=2) {

Added: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/BoundaryPushbackInputStreamTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/BoundaryPushbackInputStreamTest.java?rev=726146&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/BoundaryPushbackInputStreamTest.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/BoundaryPushbackInputStreamTest.java Fri Dec 12 15:03:42 2008
@@ -0,0 +1,55 @@
+/*
+ * 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.axiom.attachments;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+
+import junit.framework.TestCase;
+
+public class BoundaryPushbackInputStreamTest extends TestCase {
+    /**
+     * Check that the implementation consistently skips the newline sequence at the end of
+     * an attachment by initializing the stream with various values for pushBackSize and
+     * using various buffer sizes to read from the stream.
+     * 
+     * This provides regression testing for WSCOMMONS-328.
+     * 
+     * @throws Exception
+     */
+    public void testReadWithNewline() throws Exception {
+        byte[] boundary = "--boundary".getBytes("ascii");
+        byte[] data = "xxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n--boundary\r\nyyyyyyyyyyyyyy".getBytes("ascii");
+        for (int bufferSize = 1; bufferSize < data.length; bufferSize++) {
+            byte[] buffer = new byte[bufferSize];
+            for (int pushBackSize = 0; pushBackSize < data.length; pushBackSize++) {
+                PushbackInputStream pbis = new PushbackInputStream(new ByteArrayInputStream(data), 20);
+                InputStream bpbis = new BoundaryPushbackInputStream(pbis, boundary, pushBackSize);
+                int count = 0;
+                int read;
+                while ((read = bpbis.read(buffer)) != -1) {
+                    count += read;
+                }
+                assertEquals(27, count);
+            }
+        }
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/BoundaryPushbackInputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native