1 /*
2 * soapUI, copyright (C) 2004-2007 eviware.com
3 *
4 * soapUI is free software; you can redistribute it and/or modify it under the
5 * terms of version 2.1 of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
7 *
8 * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 * See the GNU Lesser General Public License for more details at gnu.org.
11 */
12
13 package com.eviware.soapui.impl.wsdl.submit.transports;
14
15 import java.util.Properties;
16
17 import javax.activation.DataHandler;
18 import javax.activation.FileDataSource;
19 import javax.mail.Message;
20 import javax.mail.Session;
21 import javax.mail.internet.MimeBodyPart;
22 import javax.mail.internet.MimeMessage;
23 import javax.mail.internet.MimeMultipart;
24
25 import junit.framework.TestCase;
26
27 public class MimeMessageTestCase extends TestCase
28 {
29 public void testMimeMessage() throws Exception
30 {
31 Session session = Session.getDefaultInstance( new Properties() );
32 // Instantiate a Multipart object
33 MimeMultipart mp = new MimeMultipart();
34 // create the first bodypart object
35 MimeBodyPart b1 = new MimeBodyPart();
36 // create textual content
37 // and add it to the bodypart object
38 b1.setContent("Spaceport Map","text/plain");
39 mp.addBodyPart(b1);
40 // Multipart messages usually have more than
41 // one body part. Create a second body part
42 // object, add new text to it, and place it
43 // into the multipart message as well. This
44 // second object holds postscript data.
45 MimeBodyPart b2 = new MimeBodyPart();
46 b2.setDataHandler( new DataHandler( new FileDataSource( "project.xml")) );
47 mp.addBodyPart(b2);
48 // Create a new message object as described above,
49 // and set its attributes. Add the multipart
50 // object to this message and call saveChanges()
51 // to write other message headers automatically.
52 Message msg = new MimeMessage(session);
53 // Set message attrubutes as in a singlepart
54 // message.
55 msg.setContent(mp); // add Multipart
56 msg.saveChanges(); // save changes
57 }
58 }