@@ -0,0 +1,2915 @@
+/*%0A * Copyright 2013 The Netty Project%0A *%0A * The Netty Project licenses this file to you under the Apache License,%0A * version 2.0 (the %22License%22); you may not use this file except in compliance%0A * with the License. You may obtain a copy of the License at:%0A *%0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A * License for the specific language governing permissions and limitations%0A * under the License.%0A */%0Apackage org.jboss.netty.handler.codec.http.multipart;%0A%0Aimport org.jboss.netty.buffer.ChannelBuffers;%0Aimport org.jboss.netty.handler.codec.http.*;%0Aimport org.jboss.netty.util.CharsetUtil;%0Aimport org.junit.Test;%0A%0Aimport java.util.Arrays;%0A%0Aimport static org.junit.Assert.assertArrayEquals;%0Aimport static org.junit.Assert.assertTrue;%0A%0A/** %7B@link HttpPostRequestDecoder%7D test case. */%0Apublic class HttpPostRequestDecoderTest %7B%0A    @Test%0A    public void testBinaryStreamUpload() throws Exception %7B%0A        final String boundary = %22dLV9Wyq26L_-JQxk6ferf-RT153LhOO%22;%0A%0A        final DefaultHttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, %22http://localhost%22);%0A%0A        req.setContent(ChannelBuffers.EMPTY_BUFFER);%0A        req.setHeader(HttpHeaders.Names.CONTENT_TYPE, %22multipart/form-data; boundary=%22 + boundary);%0A        req.setHeader(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);%0A        req.setChunked(true);%0A%0A        // Force to use memory-based data.%0A        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);%0A%0A        for (String data : Arrays.asList(%22%22, %22%5Cr%22, %22%5Cr%5Cr%22, %22%5Cr%5Cr%5Cr%22)) %7B%0A            final String body = %22%22%0A                + %22--%22 + boundary + %22%5Cr%5Cn%22 +%0A                %22Content-Disposition: form-data; name=%5C%22file%5C%22; filename=%5C%22tmp-0.txt%5C%22%5Cr%5Cn%22 +%0A                %22Content-Type: image/gif%5Cr%5Cn%22 +%0A                %22%5Cr%5Cn%22 +%0A                data + %22%5Cr%5Cn%22 +%0A                %22--%22 + boundary + %22--%5Cr%5Cn%22;%0A%0A            // Create decoder instance to test.%0A            final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);%0A%0A            decoder.offer(new DefaultHttpChunk(ChannelBuffers.copiedBuffer(body, CharsetUtil.UTF_8)));%0A            decoder.offer(new DefaultHttpChunk(ChannelBuffers.EMPTY_BUFFER));%0A%0A            // Validate it's enough chunks to decode upload.%0A            assertTrue(decoder.hasNext());%0A%0A            // Decode binary upload.%0A            MemoryFileUpload upload = (MemoryFileUpload) decoder.next();%0A%0A            // Validate data has been parsed correctly as it was passed into request.%0A            assertArrayEquals(%22Invalid decoded data %5Bdata=%22 + data + %22upload=%22 + upload + '%5D',%0A                data.getBytes(), upload.get());%0A        %7D%0A    %7D%0A%7D%0A

Add test for HttpPostRequestDecoder: validate '\r' symbols in the end of binary stream are parsed correctly.