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 *
10
* http://www.apache.org/licenses/LICENSE-2.0 *
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
****************************************************************/
20
package org.apache.james.mime4j.message;
22
import java.io.ByteArrayOutputStream;
24
import junit.framework.TestCase;
26
import org.apache.james.mime4j.field.AbstractField;
28
public class MultipartFormTest extends TestCase {
30
public void testMultipartFormContent() throws Exception {
31
BodyFactory bodyFactory = new BodyFactory();
33
Message message = new Message();
34
Header header = new Header();
36
AbstractField.parse("Content-Type: multipart/form-data; boundary=foo"));
37
message.setHeader(header);
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"));
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"));
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"));
55
p3.setBody(bodyFactory.textBody("all kind of stuff"));
57
multipart.addBodyPart(p1);
58
multipart.addBodyPart(p2);
59
multipart.addBodyPart(p3);
61
ByteArrayOutputStream out = new ByteArrayOutputStream();
62
MessageWriter.DEFAULT.writeMultipart(multipart, out);
65
String expected = "\r\n" +
67
"Content-Type: text/plain\r\n" +
71
"Content-Type: text/plain\r\n" +
75
"Content-Type: text/plain\r\n" +
77
"all kind of stuff\r\n" +
79
String s = out.toString("US-ASCII");
80
assertEquals(expected, s);