01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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: public void testMimeMessage() throws Exception {
29: Session session = Session.getDefaultInstance(new Properties());
30: // Instantiate a Multipart object
31: MimeMultipart mp = new MimeMultipart();
32: // create the first bodypart object
33: MimeBodyPart b1 = new MimeBodyPart();
34: // create textual content
35: // and add it to the bodypart object
36: b1.setContent("Spaceport Map", "text/plain");
37: mp.addBodyPart(b1);
38: // Multipart messages usually have more than
39: // one body part. Create a second body part
40: // object, add new text to it, and place it
41: // into the multipart message as well. This
42: // second object holds postscript data.
43: MimeBodyPart b2 = new MimeBodyPart();
44: b2.setDataHandler(new DataHandler(new FileDataSource(
45: "project.xml")));
46: mp.addBodyPart(b2);
47: // Create a new message object as described above,
48: // and set its attributes. Add the multipart
49: // object to this message and call saveChanges()
50: // to write other message headers automatically.
51: Message msg = new MimeMessage(session);
52: // Set message attrubutes as in a singlepart
53: // message.
54: msg.setContent(mp); // add Multipart
55: msg.saveChanges(); // save changes
56: }
57: }
|