Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: javax/mail/internet/MimeMultipartTest.java


1   /**
2    *
3    * Copyright 2005 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  
18  //
19  // This source code implements specifications defined by the Java
20  // Community Process. In order to remain compliant with the specification
21  // DO NOT add / change / or delete method signatures!
22  //
23  package javax.mail.internet;
24  
25  import java.io.IOException;
26  import java.io.OutputStream;
27  import java.awt.datatransfer.DataFlavor;
28  import java.awt.datatransfer.UnsupportedFlavorException;
29  import javax.mail.MessagingException;
30  import javax.activation.CommandMap;
31  import javax.activation.DataHandler;
32  import javax.activation.MailcapCommandMap;
33  import javax.activation.DataContentHandler;
34  import javax.activation.DataSource;
35  
36  import junit.framework.TestCase;
37  
38  /**
39   * @version $Rev$ $Date$
40   */
41  public class MimeMultipartTest extends TestCase {
42      private CommandMap defaultMap;
43  
44      public void testWriteTo() throws MessagingException, IOException {
45          MimeMultipart mp = new MimeMultipart();
46          MimeBodyPart part1 = new MimeBodyPart();
47          part1.setContent("Hello World", "text/plain");
48          mp.addBodyPart(part1);
49          MimeBodyPart part2 = new MimeBodyPart();
50          part2.setContent("Hello Again", "text/plain");
51          mp.addBodyPart(part2);
52          mp.writeTo(System.out);
53      }
54  
55      protected void setUp() throws Exception {
56          defaultMap = CommandMap.getDefaultCommandMap();
57          MailcapCommandMap myMap = new MailcapCommandMap();
58          myMap.addMailcap("text/plain;;    x-java-content-handler=" + DummyTextHandler.class.getName());
59          CommandMap.setDefaultCommandMap(myMap);
60      }
61  
62      protected void tearDown() throws Exception {
63          CommandMap.setDefaultCommandMap(defaultMap);
64      }
65  
66      public static class DummyTextHandler implements DataContentHandler {
67          public DataFlavor[] getTransferDataFlavors() {
68              return new DataFlavor[0];  //To change body of implemented methods use File | Settings | File Templates.
69          }
70  
71          public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException, IOException {
72              return null;  //To change body of implemented methods use File | Settings | File Templates.
73          }
74  
75          public Object getContent(DataSource ds) throws IOException {
76              return null;  //To change body of implemented methods use File | Settings | File Templates.
77          }
78  
79          public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException {
80              os.write(((String)obj).getBytes());
81          }
82      }
83  
84      public static class DummyMultipartHandler implements DataContentHandler {
85          public DataFlavor[] getTransferDataFlavors() {
86              return new DataFlavor[0];  //To change body of implemented methods use File | Settings | File Templates.
87          }
88  
89          public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException, IOException {
90              return null;  //To change body of implemented methods use File | Settings | File Templates.
91          }
92  
93          public Object getContent(DataSource ds) throws IOException {
94              return null;  //To change body of implemented methods use File | Settings | File Templates.
95          }
96  
97          public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException {
98              os.write(((String)obj).getBytes());
99          }
100     }
101 }