summaryrefslogtreecommitdiffstats
path: root/simple/simple-http/src/test/java/org/simpleframework/http/message/PartConsumerTest.java
blob: 4f96405b7985620206a844c7554b3a3fc31df59e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package org.simpleframework.http.message;

import junit.framework.TestCase;

import org.simpleframework.common.buffer.ArrayAllocator;
import org.simpleframework.http.Part;
import org.simpleframework.http.core.StreamCursor;
import org.simpleframework.http.message.PartConsumer;
import org.simpleframework.http.message.PartData;
import org.simpleframework.transport.ByteCursor;

public class PartConsumerTest extends TestCase {
   
   private static final String SOURCE =
   "Content-Disposition: form-data; name='pics'; filename='file1.txt'\r\n"+
   "Content-Type: text/plain\r\n\r\n"+
   "... contents of file1.txt ...\r\n"+
   "--AaB03x\r\n";
   
   public void testHeader() throws Exception {
      PartData list = new PartData();
      PartConsumer consumer = new PartConsumer(new ArrayAllocator(), list, "AaB03x".getBytes("UTF-8"), 8192);
      ByteCursor cursor = new StreamCursor(SOURCE);
      
      while(!consumer.isFinished()) {
         consumer.consume(cursor);
      }   
      assertEquals(list.getParts().size(), 1);
      assertEquals(list.getParts().get(0).getContentType().getPrimary(), "text");
      assertEquals(list.getParts().get(0).getContentType().getSecondary(), "plain");
      assertEquals(((Part)list.getParts().get(0)).getHeader("Content-Disposition"), "form-data; name='pics'; filename='file1.txt'");         
   }
}