~ubuntu-branches/ubuntu/utopic/apache-mime4j/utopic-proposed

« back to all changes in this revision

Viewing changes to src/test/java/org/apache/james/mime4j/message/MultipartFormTest.java

  • Committer: Package Import Robot
  • Author(s): David Paleino
  • Date: 2013-11-03 11:13:27 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20131103111327-09huep00ex05z113
Tags: 0.7.2-2
* Upload to unstable
* Fixed Vcs-* fields in debian/control
* Updated debian/watch
* Standards-Version bump to 3.9.5, no changes needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************
2
 
 * Licensed to the Apache Software Foundation (ASF) under one   *
3
 
 * or more contributor license agreements.  See the NOTICE file *
4
 
 * distributed with this work for additional information        *
5
 
 * regarding copyright ownership.  The ASF licenses this file   *
6
 
 * to you under the Apache License, Version 2.0 (the            *
7
 
 * "License"); you may not use this file except in compliance   *
8
 
 * with the License.  You may obtain a copy of the License at   *
9
 
 *                                                              *
10
 
 *   http://www.apache.org/licenses/LICENSE-2.0                 *
11
 
 *                                                              *
12
 
 * Unless required by applicable law or agreed to in writing,   *
13
 
 * software distributed under the License is distributed on an  *
14
 
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15
 
 * KIND, either express or implied.  See the License for the    *
16
 
 * specific language governing permissions and limitations      *
17
 
 * under the License.                                           *
18
 
 ****************************************************************/
19
 
 
20
 
package org.apache.james.mime4j.message;
21
 
 
22
 
import java.io.ByteArrayOutputStream;
23
 
 
24
 
import junit.framework.TestCase;
25
 
 
26
 
import org.apache.james.mime4j.field.AbstractField;
27
 
 
28
 
public class MultipartFormTest extends TestCase {
29
 
 
30
 
    public void testMultipartFormContent() throws Exception {
31
 
        BodyFactory bodyFactory = new BodyFactory();
32
 
        
33
 
        Message message = new Message();
34
 
        Header header = new Header();
35
 
        header.addField(
36
 
                AbstractField.parse("Content-Type: multipart/form-data; boundary=foo"));
37
 
        message.setHeader(header);
38
 
        
39
 
        Multipart multipart = new Multipart("alternative");
40
 
        multipart.setParent(message);
41
 
        BodyPart p1 = new BodyPart();
42
 
        Header h1 = new Header();
43
 
        h1.addField(AbstractField.parse("Content-Type: text/plain"));
44
 
        p1.setHeader(h1);
45
 
        p1.setBody(bodyFactory.textBody("this stuff"));
46
 
        BodyPart p2 = new BodyPart();
47
 
        Header h2 = new Header();
48
 
        h2.addField(AbstractField.parse("Content-Type: text/plain"));
49
 
        p2.setHeader(h2);
50
 
        p2.setBody(bodyFactory.textBody("that stuff"));
51
 
        BodyPart p3 = new BodyPart();
52
 
        Header h3 = new Header();
53
 
        h3.addField(AbstractField.parse("Content-Type: text/plain"));
54
 
        p3.setHeader(h3);
55
 
        p3.setBody(bodyFactory.textBody("all kind of stuff"));
56
 
 
57
 
        multipart.addBodyPart(p1);
58
 
        multipart.addBodyPart(p2);
59
 
        multipart.addBodyPart(p3);
60
 
        
61
 
        ByteArrayOutputStream out = new ByteArrayOutputStream();
62
 
        MessageWriter.DEFAULT.writeMultipart(multipart, out);
63
 
        out.close();
64
 
        
65
 
        String expected = "\r\n" + 
66
 
            "--foo\r\n" +
67
 
            "Content-Type: text/plain\r\n" +
68
 
            "\r\n" +
69
 
            "this stuff\r\n" +
70
 
            "--foo\r\n" +
71
 
            "Content-Type: text/plain\r\n" +
72
 
            "\r\n" +
73
 
            "that stuff\r\n" +
74
 
            "--foo\r\n" +
75
 
            "Content-Type: text/plain\r\n" +
76
 
            "\r\n" +
77
 
            "all kind of stuff\r\n" +
78
 
            "--foo--\r\n";
79
 
        String s = out.toString("US-ASCII");
80
 
        assertEquals(expected, s);
81
 
    }
82
 
    
83
 
}