1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  package org.apache.commons.fileupload;
18  
19  import static org.junit.Assert.assertNotNull;
20  
21  import java.io.ByteArrayInputStream;
22  import java.io.InputStream;
23  
24  import org.junit.Test;
25  
26  
27  
28  
29  public class MultipartStreamTest {
30  
31      static private final String BOUNDARY_TEXT = "myboundary";
32  
33      @Test
34      public void testThreeParamConstructor() throws Exception {
35          final String strData = "foobar";
36          final byte[] contents = strData.getBytes();
37          InputStream input = new ByteArrayInputStream(contents);
38          byte[] boundary = BOUNDARY_TEXT.getBytes();
39          int iBufSize =
40                  boundary.length + MultipartStream.BOUNDARY_PREFIX.length + 1;
41          MultipartStream ms = new MultipartStream(
42                  input,
43                  boundary,
44                  iBufSize,
45                  new MultipartStream.ProgressNotifier(null, contents.length));
46          assertNotNull(ms);
47      }
48  
49      @Test(expected=IllegalArgumentException.class)
50      public void testSmallBuffer() throws Exception {
51          final String strData = "foobar";
52          final byte[] contents = strData.getBytes();
53          InputStream input = new ByteArrayInputStream(contents);
54          byte[] boundary = BOUNDARY_TEXT.getBytes();
55          int iBufSize = 1;
56          new MultipartStream(
57                  input,
58                  boundary,
59                  iBufSize,
60                  new MultipartStream.ProgressNotifier(null, contents.length));
61      }
62  
63      @Test
64      public void testTwoParamConstructor() throws Exception {
65          final String strData = "foobar";
66          final byte[] contents = strData.getBytes();
67          InputStream input = new ByteArrayInputStream(contents);
68          byte[] boundary = BOUNDARY_TEXT.getBytes();
69          MultipartStream ms = new MultipartStream(
70                  input,
71                  boundary,
72                  new MultipartStream.ProgressNotifier(null, contents.length));
73          assertNotNull(ms);
74      }
75  
76  }