dblevins 2003/09/03 18:31:41
Modified: specs/javamail/src/test/javax/mail AllTests.java
Added: specs/javamail/src/test/javax/mail MessageContextTest.java
SimpleFolder.java SimpleTextMessage.java
specs/javamail/src/test/javax/mail/internet
ContentDispositionTest.java
HeaderTokenizerTest.java InternetHeadersTest.java
MailDateFormatTest.java MimeMessageTest.java
NewsAddressTest.java
Log:
Patch: GERONIMO-56
From: Alex Blewitt
Implemented missing methods in MessageContext
Test to go into specs/javamail/src/test/javax/mail
Revision Changes Path
1.2 +5 -3
incubator-geronimo/specs/javamail/src/test/javax/mail/AllTests.java
Index: AllTests.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/specs/javamail/src/test/javax/mail/AllTests.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AllTests.java 16 Aug 2003 01:55:49 -0000 1.1
+++ AllTests.java 4 Sep 2003 01:31:41 -0000 1.2
@@ -62,6 +62,8 @@
// www.ioshq.com
package javax.mail;
import javax.mail.event.AllEventTests;
+import javax.mail.internet.AllInternetTests;
+
import junit.framework.Test;
import junit.framework.TestSuite;
/**
@@ -76,8 +78,8 @@
suite.addTest(new TestSuite(MessagingExceptionTest.class));
suite.addTest(new TestSuite(URLNameTest.class));
suite.addTest(new TestSuite(PasswordAuthenticationTest.class));
- Test eventTests = AllEventTests.suite();
- suite.addTest(eventTests);
+ suite.addTest(AllEventTests.suite());
+ suite.addTest(AllInternetTests.suite());
//$JUnit-END$
return suite;
}
1.1
incubator-geronimo/specs/javamail/src/test/javax/mail/MessageContextTest.java
Index: MessageContextTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package javax.mail;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import javax.activation.DataHandler;
import javax.mail.internet.MimeMessage;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/04 01:31:41 $
*/
public class MessageContextTest extends TestCase {
public void testMessageContext() {
Part p;
MessageContext mc;
p = new TestPart();
mc = new MessageContext(p);
assertSame(p, mc.getPart());
assertNull(mc.getMessage());
assertNull(mc.getSession());
Session s = Session.getDefaultInstance(null);
MimeMessage m = new MimeMessage(s);
p = new TestMultipart(m);
mc = new MessageContext(p);
assertSame(p, mc.getPart());
assertSame(m,mc.getMessage());
assertSame(s,mc.getSession());
}
private static class TestMultipart extends Multipart implements Part {
public TestMultipart(Part p) {
parent = p;
}
public void writeTo(OutputStream out) throws IOException,
MessagingException {
}
public void addHeader(String name, String value) throws
MessagingException {
}
public Enumeration getAllHeaders() throws MessagingException {
return null;
}
public Object getContent() throws IOException, MessagingException {
return null;
}
public DataHandler getDataHandler() throws MessagingException {
return null;
}
public String getDescription() throws MessagingException {
return null;
}
public String getDisposition() throws MessagingException {
return null;
}
public String getFileName() throws MessagingException {
return null;
}
public String[] getHeader(String name) throws MessagingException {
return null;
}
public InputStream getInputStream() throws IOException,
MessagingException {
return null;
}
public int getLineCount() throws MessagingException {
return 0;
}
public Enumeration getMatchingHeaders(String[] names) throws
MessagingException {
return null;
}
public Enumeration getNonMatchingHeaders(String[] names) throws
MessagingException {
return null;
}
public int getSize() throws MessagingException {
return 0;
}
public boolean isMimeType(String mimeType) throws MessagingException {
return false;
}
public void removeHeader(String name) throws MessagingException {
}
public void setContent(Multipart content) throws MessagingException {
}
public void setContent(Object content, String type) throws
MessagingException {
}
public void setDataHandler(DataHandler handler) throws
MessagingException {
}
public void setDescription(String description) throws
MessagingException {
}
public void setDisposition(String disposition) throws
MessagingException {
}
public void setFileName(String name) throws MessagingException {
}
public void setHeader(String name, String value) throws
MessagingException {
}
public void setText(String content) throws MessagingException {
}
}
private static class TestBodyPart extends BodyPart {
public TestBodyPart(Multipart p) {
super();
parent = p;
}
public void addHeader(String name, String value)
throws MessagingException {
}
public Enumeration getAllHeaders() throws MessagingException {
return null;
}
public Object getContent() throws IOException, MessagingException {
return null;
}
public String getContentType() throws MessagingException {
return null;
}
public DataHandler getDataHandler() throws MessagingException {
return null;
}
public String getDescription() throws MessagingException {
return null;
}
public String getDisposition() throws MessagingException {
return null;
}
public String getFileName() throws MessagingException {
return null;
}
public String[] getHeader(String name) throws MessagingException {
return null;
}
public InputStream getInputStream()
throws IOException, MessagingException {
return null;
}
public int getLineCount() throws MessagingException {
return 0;
}
public Enumeration getMatchingHeaders(String[] names)
throws MessagingException {
return null;
}
public Enumeration getNonMatchingHeaders(String[] names)
throws MessagingException {
return null;
}
public int getSize() throws MessagingException {
return 0;
}
public boolean isMimeType(String mimeType) throws MessagingException {
return false;
}
public void removeHeader(String name) throws MessagingException {
}
public void setContent(Multipart content) throws MessagingException {
}
public void setContent(Object content, String type)
throws MessagingException {
}
public void setDataHandler(DataHandler handler)
throws MessagingException {
}
public void setDescription(String description)
throws MessagingException {
}
public void setDisposition(String disposition)
throws MessagingException {
}
public void setFileName(String name) throws MessagingException {
}
public void setHeader(String name, String value)
throws MessagingException {
}
public void setText(String content) throws MessagingException {
}
public void writeTo(OutputStream out)
throws IOException, MessagingException {
}
}
private static class TestPart implements Part {
public void addHeader(String name, String value)
throws MessagingException {
}
public Enumeration getAllHeaders() throws MessagingException {
return null;
}
public Object getContent() throws IOException, MessagingException {
return null;
}
public String getContentType() throws MessagingException {
return null;
}
public DataHandler getDataHandler() throws MessagingException {
return null;
}
public String getDescription() throws MessagingException {
return null;
}
public String getDisposition() throws MessagingException {
return null;
}
public String getFileName() throws MessagingException {
return null;
}
public String[] getHeader(String name) throws MessagingException {
return null;
}
public InputStream getInputStream()
throws IOException, MessagingException {
return null;
}
public int getLineCount() throws MessagingException {
return 0;
}
public Enumeration getMatchingHeaders(String[] names)
throws MessagingException {
return null;
}
public Enumeration getNonMatchingHeaders(String[] names)
throws MessagingException {
return null;
}
public int getSize() throws MessagingException {
return 0;
}
public boolean isMimeType(String mimeType) throws MessagingException {
return false;
}
public void removeHeader(String name) throws MessagingException {
}
public void setContent(Multipart content) throws MessagingException {
}
public void setContent(Object content, String type)
throws MessagingException {
}
public void setDataHandler(DataHandler handler)
throws MessagingException {
}
public void setDescription(String description)
throws MessagingException {
}
public void setDisposition(String disposition)
throws MessagingException {
}
public void setFileName(String name) throws MessagingException {
}
public void setHeader(String name, String value)
throws MessagingException {
}
public void setText(String content) throws MessagingException {
}
public void writeTo(OutputStream out)
throws IOException, MessagingException {
}
}
}
1.1
incubator-geronimo/specs/javamail/src/test/javax/mail/SimpleFolder.java
Index: SimpleFolder.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package javax.mail;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/04 01:31:41 $
*/
public class SimpleFolder extends Folder {
private static final Message[] MESSAGE_ARRAY = new Message[0];
private List _messages = new LinkedList();
private String _name;
public SimpleFolder(Store store) {
this(store, "SimpleFolder");
}
SimpleFolder(Store store, String name) {
super(store);
_name = name;
}
/* (non-Javadoc)
* @see javax.mail.Folder#appendMessages(javax.mail.Message[])
*/
public void appendMessages(Message[] messages) throws MessagingException {
for (int i = 0; i < messages.length; i++) {
Message message = messages[i];
_messages.add(message);
}
}
/* (non-Javadoc)
* @see javax.mail.Folder#close(boolean)
*/
public void close(boolean expunge) throws MessagingException {
if (expunge) {
expunge();
}
}
/* (non-Javadoc)
* @see javax.mail.Folder#create(int)
*/
public boolean create(int type) throws MessagingException {
if (type == HOLDS_MESSAGES) {
return true;
} else {
throw new MessagingException("Cannot create folders that hold
folders");
}
}
/* (non-Javadoc)
* @see javax.mail.Folder#delete(boolean)
*/
public boolean delete(boolean recurse) throws MessagingException {
_messages = new LinkedList();
return true;
}
/* (non-Javadoc)
* @see javax.mail.Folder#exists()
*/
public boolean exists() throws MessagingException {
return true;
}
/* (non-Javadoc)
* @see javax.mail.Folder#expunge()
*/
public Message[] expunge() throws MessagingException {
Iterator it = _messages.iterator();
List result = new LinkedList();
while (it.hasNext()) {
Message message = (Message) it.next();
if (message.isSet(Flags.Flag.DELETED)) {
it.remove();
result.add(message);
}
}
// run through and renumber the messages
for (int i = 0; i < _messages.size(); i++) {
Message message = (Message) _messages.get(i);
message.setMessageNumber(i);
}
return (Message[]) result.toArray(MESSAGE_ARRAY);
}
/* (non-Javadoc)
* @see javax.mail.Folder#getFolder(java.lang.String)
*/
public Folder getFolder(String name) throws MessagingException {
return null;
}
/* (non-Javadoc)
* @see javax.mail.Folder#getFullName()
*/
public String getFullName() {
return getName();
}
/* (non-Javadoc)
* @see javax.mail.Folder#getMessage(int)
*/
public Message getMessage(int id) throws MessagingException {
return (Message) _messages.get(id);
}
/* (non-Javadoc)
* @see javax.mail.Folder#getMessageCount()
*/
public int getMessageCount() throws MessagingException {
return _messages.size();
}
/* (non-Javadoc)
* @see javax.mail.Folder#getName()
*/
public String getName() {
return _name;
}
/* (non-Javadoc)
* @see javax.mail.Folder#getParent()
*/
public Folder getParent() throws MessagingException {
return null;
}
/* (non-Javadoc)
* @see javax.mail.Folder#getPermanentFlags()
*/
public Flags getPermanentFlags() {
return null;
}
/* (non-Javadoc)
* @see javax.mail.Folder#getSeparator()
*/
public char getSeparator() throws MessagingException {
return '/';
}
/* (non-Javadoc)
* @see javax.mail.Folder#getType()
*/
public int getType() throws MessagingException {
return HOLDS_MESSAGES;
}
/* (non-Javadoc)
* @see javax.mail.Folder#hasNewMessages()
*/
public boolean hasNewMessages() throws MessagingException {
return false;
}
/* (non-Javadoc)
* @see javax.mail.Folder#isOpen()
*/
public boolean isOpen() {
return true;
}
/* (non-Javadoc)
* @see javax.mail.Folder#list(java.lang.String)
*/
public Folder[] list(String pattern) throws MessagingException {
return null;
}
/* (non-Javadoc)
* @see javax.mail.Folder#open(int)
*/
public void open(int mode) throws MessagingException {
if (mode != HOLDS_MESSAGES) {
throw new MessagingException("SimpleFolder can only be opened
with HOLDS_MESSAGES");
}
}
/* (non-Javadoc)
* @see javax.mail.Folder#renameTo(javax.mail.Folder)
*/
public boolean renameTo(Folder newName) throws MessagingException {
_name = newName.getName();
return true;
}
}
1.1
incubator-geronimo/specs/javamail/src/test/javax/mail/SimpleTextMessage.java
Index: SimpleTextMessage.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package javax.mail;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Date;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import javax.activation.DataHandler;
import javax.mail.internet.InternetAddress;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/04 01:31:41 $
*/
public class SimpleTextMessage extends Message {
public static final Address[] ADDRESS_ARRAY = new Address[0];
private List _bcc = new LinkedList();
private List _cc = new LinkedList();
private String _description;
private Flags _flags = new Flags();
private List _from = new LinkedList();
private Date _received;
private Date _sent;
private String _subject;
private String _text;
private List _to = new LinkedList();
/**
* @param folder
* @param number
*/
public SimpleTextMessage(Folder folder, int number) {
super(folder, number);
}
/* (non-Javadoc)
* @see javax.mail.Message#addFrom(javax.mail.Address[])
*/
public void addFrom(Address[] addresses) throws MessagingException {
_from.addAll(Arrays.asList(addresses));
}
/* (non-Javadoc)
* @see javax.mail.Part#addHeader(java.lang.String, java.lang.String)
*/
public void addHeader(String name, String value)
throws MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
/* (non-Javadoc)
* @see
javax.mail.Message#addRecipients(javax.mail.Message.RecipientType,
javax.mail.Address[])
*/
public void addRecipients(RecipientType type, Address[] addresses)
throws MessagingException {
getList(type).addAll(Arrays.asList(addresses));
}
/* (non-Javadoc)
* @see javax.mail.Part#getAllHeaders()
*/
public Enumeration getAllHeaders() throws MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
/* (non-Javadoc)
* @see javax.mail.Part#getContent()
*/
public Object getContent() throws IOException, MessagingException {
return _text;
}
/* (non-Javadoc)
* @see javax.mail.Part#getContentType()
*/
public String getContentType() throws MessagingException {
return "text/plain";
}
/* (non-Javadoc)
* @see javax.mail.Part#getDataHandler()
*/
public DataHandler getDataHandler() throws MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
/* (non-Javadoc)
* @see javax.mail.Part#getDescription()
*/
public String getDescription() throws MessagingException {
return _description;
}
/* (non-Javadoc)
* @see javax.mail.Part#getDisposition()
*/
public String getDisposition() throws MessagingException {
return Part.INLINE;
}
/* (non-Javadoc)
* @see javax.mail.Part#getFileName()
*/
public String getFileName() throws MessagingException {
return null;
}
/* (non-Javadoc)
* @see javax.mail.Message#getFlags()
*/
public Flags getFlags() throws MessagingException {
return _flags;
}
/* (non-Javadoc)
* @see javax.mail.Message#getFrom()
*/
public Address[] getFrom() throws MessagingException {
return (Address[]) _from.toArray(ADDRESS_ARRAY);
}
/* (non-Javadoc)
* @see javax.mail.Part#getHeader(java.lang.String)
*/
public String[] getHeader(String name) throws MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
/* (non-Javadoc)
* @see javax.mail.Part#getInputStream()
*/
public InputStream getInputStream()
throws IOException, MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
/* (non-Javadoc)
* @see javax.mail.Part#getLineCount()
*/
public int getLineCount() throws MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
private List getList(RecipientType type) throws MessagingException {
List list;
if (type == RecipientType.TO) {
list = _to;
} else if (type == RecipientType.CC) {
list = _cc;
} else if (type == RecipientType.BCC) {
list = _bcc;
} else {
throw new MessagingException("Address type not understood");
}
return list;
}
/* (non-Javadoc)
* @see javax.mail.Part#getMatchingHeaders(java.lang.String[])
*/
public Enumeration getMatchingHeaders(String[] names)
throws MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
/* (non-Javadoc)
* @see javax.mail.Part#getNonMatchingHeaders(java.lang.String[])
*/
public Enumeration getNonMatchingHeaders(String[] names)
throws MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
/* (non-Javadoc)
* @see javax.mail.Message#getReceivedDate()
*/
public Date getReceivedDate() throws MessagingException {
return _received;
}
/* (non-Javadoc)
* @see javax.mail.Message#getRecipients(javax.mail.Message.RecipientType)
*/
public Address[] getRecipients(RecipientType type)
throws MessagingException {
return (Address[]) getList(type).toArray(ADDRESS_ARRAY);
}
/* (non-Javadoc)
* @see javax.mail.Message#getSentDate()
*/
public Date getSentDate() throws MessagingException {
return _sent;
}
/* (non-Javadoc)
* @see javax.mail.Part#getSize()
*/
public int getSize() throws MessagingException {
return _text.length();
}
/* (non-Javadoc)
* @see javax.mail.Message#getSubject()
*/
public String getSubject() throws MessagingException {
return _subject;
}
/* (non-Javadoc)
* @see javax.mail.Part#isMimeType(java.lang.String)
*/
public boolean isMimeType(String mimeType) throws MessagingException {
return mimeType.equals("text/plain") || mimeType.equals("text/*");
}
/* (non-Javadoc)
* @see javax.mail.Part#removeHeader(java.lang.String)
*/
public void removeHeader(String name) throws MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
/* (non-Javadoc)
* @see javax.mail.Message#reply(boolean)
*/
public Message reply(boolean replyToAll) throws MessagingException {
try {
SimpleTextMessage reply = (SimpleTextMessage) this.clone();
reply._to = new LinkedList(_from);
if (replyToAll) {
reply._to.addAll(_cc);
}
return reply;
} catch (CloneNotSupportedException e) {
throw new MessagingException(e.getMessage());
}
}
/* (non-Javadoc)
* @see javax.mail.Message#saveChanges()
*/
public void saveChanges() throws MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
/* (non-Javadoc)
* @see javax.mail.Part#setContent(javax.mail.Multipart)
*/
public void setContent(Multipart content) throws MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
/* (non-Javadoc)
* @see javax.mail.Part#setContent(java.lang.Object, java.lang.String)
*/
public void setContent(Object content, String type)
throws MessagingException {
setText((String) content);
}
/* (non-Javadoc)
* @see javax.mail.Part#setDataHandler(javax.activation.DataHandler)
*/
public void setDataHandler(DataHandler handler) throws MessagingException
{
throw new UnsupportedOperationException("Method not implemented");
}
/* (non-Javadoc)
* @see javax.mail.Part#setDescription(java.lang.String)
*/
public void setDescription(String description) throws MessagingException {
_description = description;
}
/* (non-Javadoc)
* @see javax.mail.Part#setDisposition(java.lang.String)
*/
public void setDisposition(String disposition) throws MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
/* (non-Javadoc)
* @see javax.mail.Part#setFileName(java.lang.String)
*/
public void setFileName(String name) throws MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
/* (non-Javadoc)
* @see javax.mail.Message#setFlags(javax.mail.Flags, boolean)
*/
public void setFlags(Flags flags, boolean set) throws MessagingException {
if (set) {
_flags.add(flags);
} else {
_flags.remove(flags);
}
}
/* (non-Javadoc)
* @see javax.mail.Message#setFrom()
*/
public void setFrom() throws MessagingException {
setFrom(new InternetAddress("[EMAIL PROTECTED]"));
}
/* (non-Javadoc)
* @see javax.mail.Message#setFrom(javax.mail.Address)
*/
public void setFrom(Address address) throws MessagingException {
_from.clear();
_from.add(address);
}
/* (non-Javadoc)
* @see javax.mail.Part#setHeader(java.lang.String, java.lang.String)
*/
public void setHeader(String name, String value)
throws MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
/* (non-Javadoc)
* @see
javax.mail.Message#setRecipients(javax.mail.Message.RecipientType,
javax.mail.Address[])
*/
public void setRecipients(RecipientType type, Address[] addresses)
throws MessagingException {
List list = getList(type);
list.clear();
list.addAll(Arrays.asList(addresses));
}
/* (non-Javadoc)
* @see javax.mail.Message#setSentDate(java.util.Date)
*/
public void setSentDate(Date sent) throws MessagingException {
_sent = sent;
}
/* (non-Javadoc)
* @see javax.mail.Message#setSubject(java.lang.String)
*/
public void setSubject(String subject) throws MessagingException {
_subject = subject;
}
/* (non-Javadoc)
* @see javax.mail.Part#setText(java.lang.String)
*/
public void setText(String content) throws MessagingException {
_text = content;
}
/* (non-Javadoc)
* @see javax.mail.Part#writeTo(java.io.OutputStream)
*/
public void writeTo(OutputStream out)
throws IOException, MessagingException {
throw new UnsupportedOperationException("Method not implemented");
}
}
1.1
incubator-geronimo/specs/javamail/src/test/javax/mail/internet/ContentDispositionTest.java
Index: ContentDispositionTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package javax.mail.internet;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/04 01:31:41 $
*/
public class ContentDispositionTest extends TestCase {
public ContentDispositionTest(String name) {
super(name);
}
public void testContentDisposition() throws ParseException {
ContentDisposition c;
c = new ContentDisposition();
assertNotNull(c.getParameterList());
assertNull(c.getParameterList().get("nothing"));
assertNull(c.getDisposition());
assertNull(c.toString());
c.setDisposition("inline");
assertEquals("inline",c.getDisposition());
c.setParameter("file","file.txt");
assertEquals("file.txt",c.getParameterList().get("file"));
assertEquals("inline;file=file.txt",c.toString());
c = new ContentDisposition("inline");
assertEquals(0,c.getParameterList().size());
assertEquals("inline",c.getDisposition());
c = new ContentDisposition("inline",new
ParameterList("charset=us-ascii;content-type=text/plain"));
assertEquals("inline",c.getDisposition());
assertEquals("us-ascii",c.getParameter("charset"));
assertEquals("text/plain",c.getParameter("content-type"));
c = new
ContentDisposition("attachment;content-type=text/html;charset=UTF-8");
assertEquals("attachment",c.getDisposition());
assertEquals("UTF-8",c.getParameter("charset"));
assertEquals("text/html",c.getParameter("content-type"));
}
}
1.1
incubator-geronimo/specs/javamail/src/test/javax/mail/internet/HeaderTokenizerTest.java
Index: HeaderTokenizerTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package javax.mail.internet;
import javax.mail.internet.HeaderTokenizer.Token;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/04 01:31:41 $
*/
public class HeaderTokenizerTest extends TestCase {
public void testTokenizer() throws ParseException {
Token t;
HeaderTokenizer ht;
ht =
new HeaderTokenizer("To: \"Geronimo List\" <[EMAIL PROTECTED]>,
\n\r Geronimo User <[EMAIL PROTECTED]>");
assertEquals("To", ht.peek().getValue());
assertEquals("To", ht.next().getValue());
assertEquals(":", ht.peek().getValue());
assertEquals(":", ht.next().getValue());
t = ht.next();
assertEquals("Geronimo List", t.getValue());
assertEquals(Token.QUOTEDSTRING, t.getType());
assertEquals("<", ht.next().getValue());
assertEquals("geronimo-dev", ht.next().getValue());
assertEquals("@", ht.next().getValue());
assertEquals("apache", ht.next().getValue());
assertEquals(".", ht.next().getValue());
assertEquals("org", ht.next().getValue());
assertEquals(">", ht.next().getValue());
assertEquals(",", ht.next().getValue());
assertEquals("Geronimo", ht.next().getValue());
assertEquals("User", ht.next().getValue());
assertEquals("<", ht.next().getValue());
assertEquals("geronimo-user", ht.next().getValue());
assertEquals("@", ht.next().getValue());
assertEquals("apache", ht.next().getValue());
assertEquals(".", ht.next().getValue());
assertEquals("org>", ht.getRemainder());
assertEquals("org", ht.peek().getValue());
assertEquals("org>", ht.getRemainder());
assertEquals("org", ht.next().getValue());
assertEquals(">", ht.next().getValue());
assertEquals(Token.EOF, ht.next().getType());
ht = new HeaderTokenizer(" ");
assertEquals(Token.EOF, ht.next().getType());
ht = new HeaderTokenizer("J2EE");
assertEquals("J2EE", ht.next().getValue());
assertEquals(Token.EOF, ht.next().getType());
// test comments
doComment(true);
doComment(false);
}
public void doComment(boolean ignore) throws ParseException {
HeaderTokenizer ht;
Token t;
ht =
new HeaderTokenizer(
"Apache(Geronimo)J2EE",
HeaderTokenizer.RFC822,
ignore);
t = ht.next();
assertEquals("Apache", t.getValue());
assertEquals(Token.ATOM, t.getType());
if (!ignore) {
t = ht.next();
assertEquals("Geronimo", t.getValue());
assertEquals(Token.COMMENT, t.getType());
}
t = ht.next();
assertEquals("J2EE", t.getValue());
assertEquals(Token.ATOM, t.getType());
assertEquals(Token.EOF, ht.next().getType());
}
}
1.1
incubator-geronimo/specs/javamail/src/test/javax/mail/internet/InternetHeadersTest.java
Index: InternetHeadersTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package javax.mail.internet;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import javax.mail.Header;
import javax.mail.MessagingException;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/04 01:31:41 $
*/
public class InternetHeadersTest extends TestCase {
private static final String EOL = "\r\n";
private static final String users =
"Geronimo Users <[EMAIL PROTECTED]>";
private static final String developers =
"Geronimo Developers <[EMAIL PROTECTED]>";
private static final String announce =
"Geronimo Team <[EMAIL PROTECTED]>";
public void testAddHeaders() {
InternetHeaders headers = new InternetHeaders();
headers.addHeader("To", users);
headers.addHeader("To", developers);
headers.addHeader("Subject", "New release");
headers.addHeader("From", announce);
assertEquals("New release", headers.getHeader("subject", null));
assertEquals(announce, headers.getHeader("FROM", null));
assertEquals(users + "," + developers,headers.getHeader("To",","));
String[] toto = headers.getHeader("tO");
assertEquals(2, toto.length);
assertTrue(
(toto[0].equals(users) && toto[1].equals(developers))
|| (toto[1].equals(users) && toto[0].equals(developers)));
}
public void testAddHeaderLines() {
InternetHeaders headers = new InternetHeaders();
headers.addHeaderLine("To: " + users);
headers.addHeaderLine("To: " + developers);
headers.addHeaderLine("Subject: New release");
headers.addHeaderLine("From: " + announce);
assertEquals("New release", headers.getHeader("subject", null));
assertEquals(announce, headers.getHeader("FROM", null));
String[] toto = headers.getHeader("tO");
assertEquals(2, toto.length);
assertTrue(
(toto[0].equals(users) && toto[1].equals(developers))
|| (toto[1].equals(users) && toto[0].equals(developers)));
}
public void testReadHeaders() throws MessagingException, IOException {
StringBuffer buffer = new StringBuffer();
buffer.append("To: " + users);
buffer.append(EOL);
buffer.append("To: " + developers);
buffer.append(EOL);
buffer.append("Subject: New ");
buffer.append(EOL);
buffer.append(" release");
buffer.append(EOL);
buffer.append("From: " + announce);
buffer.append(EOL);
buffer.append(EOL);
buffer.append("Hello World");
byte[] data = buffer.toString().getBytes();
InputStream in = new ByteArrayInputStream(data);
InternetHeaders headers = new InternetHeaders(in);
assertEquals('H', in.read());
assertEquals('e', in.read());
assertEquals('l', in.read());
assertEquals('l', in.read());
assertEquals('o', in.read());
assertEquals("New release", headers.getHeader("subject", null));
assertEquals(announce, headers.getHeader("FROM", null));
String[] toto = headers.getHeader("tO");
assertEquals(2, toto.length);
assertTrue(
(toto[0].equals(users) && toto[1].equals(developers))
|| (toto[1].equals(users) && toto[0].equals(developers)));
Enumeration enum;
boolean to1, to2, from, subject;
enum = headers.getAllHeaders();
to1 = to2 = from = subject = false;
while (enum.hasMoreElements()) {
Header header = (Header) enum.nextElement();
to1 =
to1
|| (header.getName().equals("To")
&& header.getValue().equals(users));
to2 =
to2
|| (header.getName().equals("To")
&& header.getValue().equals(developers));
from =
from
|| (header.getName().equals("From")
&& header.getValue().equals(announce));
subject =
subject
|| (header.getName().equals("Subject")
&& header.getValue().equals("New release"));
}
assertTrue(to1 && to2 && from && subject);
enum = headers.getAllHeaderLines();
to1 = to2 = from = subject = false;
while (enum.hasMoreElements()) {
String line = (String) enum.nextElement();
to1 = to1 || line.equals("To: " + users);
to2 = to2 || line.equals("To: " + developers);
from = from || line.equals("From: " + announce);
subject = subject || line.equals("Subject: New release");
}
assertTrue(to1 && to2 && from && subject);
String[] fromSubject = new String[] { "From", "Subject" };
enum = headers.getMatchingHeaders(fromSubject);
to1 = to2 = from = subject = false;
while (enum.hasMoreElements()) {
Header header = (Header) enum.nextElement();
to1 =
to1
|| (header.getName().equals("To")
&& header.getValue().equals(users));
to2 =
to2
|| (header.getName().equals("To")
&& header.getValue().equals(developers));
from =
from
|| (header.getName().equals("From")
&& header.getValue().equals(announce));
subject =
subject
|| (header.getName().equals("Subject")
&& header.getValue().equals("New release"));
}
assertTrue(!to1 && !to2 && from && subject);
enum = headers.getMatchingHeaderLines(fromSubject);
to1 = to2 = from = subject = false;
while (enum.hasMoreElements()) {
String line = (String) enum.nextElement();
to1 = to1 || line.equals("To: " + users);
to2 = to2 || line.equals("To: " + developers);
from = from || line.equals("From: " + announce);
subject = subject || line.equals("Subject: New release");
}
assertTrue(!to1 && !to2 && from && subject);
enum = headers.getNonMatchingHeaders(fromSubject);
to1 = to2 = from = subject = false;
while (enum.hasMoreElements()) {
Header header = (Header) enum.nextElement();
to1 =
to1
|| (header.getName().equals("To")
&& header.getValue().equals(users));
to2 =
to2
|| (header.getName().equals("To")
&& header.getValue().equals(developers));
from =
from
|| (header.getName().equals("From")
&& header.getValue().equals(announce));
subject =
subject
|| (header.getName().equals("Subject")
&& header.getValue().equals("New release"));
}
assertTrue(to1 && to2 && !from && !subject);
enum = headers.getNonMatchingHeaderLines(fromSubject);
to1 = to2 = from = subject = false;
while (enum.hasMoreElements()) {
String line = (String) enum.nextElement();
to1 = to1 || line.equals("To: " + users);
to2 = to2 || line.equals("To: " + developers);
from = from || line.equals("From: " + announce);
subject = subject || line.equals("Subject: New release");
}
assertTrue(to1 && to2 && !from && !subject);
}
}
1.1
incubator-geronimo/specs/javamail/src/test/javax/mail/internet/MailDateFormatTest.java
Index: MailDateFormatTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package javax.mail.internet;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/04 01:31:41 $
*/
public class MailDateFormatTest extends TestCase {
public void testMailDateFormat() throws ParseException {
MailDateFormat mdf = new MailDateFormat();
Date date = mdf.parse("Wed, 27 Aug 2003 13:43:38 +0100 (BST)");
// don't we just love the Date class?
Calendar cal = Calendar.getInstance();
cal.setTime(date);
assertEquals(2003, cal.get(Calendar.YEAR));
assertEquals(Calendar.AUGUST, cal.get(Calendar.MONTH));
assertEquals(27, cal.get(Calendar.DAY_OF_MONTH));
assertEquals(Calendar.WEDNESDAY, cal.get(Calendar.DAY_OF_WEEK));
assertEquals(13, cal.get(Calendar.HOUR_OF_DAY));
assertEquals(43, cal.get(Calendar.MINUTE));
assertEquals(38, cal.get(Calendar.SECOND));
}
}
1.1
incubator-geronimo/specs/javamail/src/test/javax/mail/internet/MimeMessageTest.java
Index: MimeMessageTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package javax.mail.internet;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Part;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/04 01:31:41 $
*/
public class MimeMessageTest extends TestCase {
private static final String EOL = "\r\n";
private static final String users =
"Geronimo Users <[EMAIL PROTECTED]>";
private static final String developers =
"Geronimo Developers <[EMAIL PROTECTED]>";
private static final String announce =
"Geronimo Team <[EMAIL PROTECTED]>";
public void testMimeMessage() throws MessagingException {
StringBuffer buffer = new StringBuffer();
buffer.append("To: " + users);
buffer.append(EOL);
buffer.append("To: " + developers);
buffer.append(EOL);
buffer.append("Subject: New ");
buffer.append(EOL);
buffer.append(" release");
buffer.append(EOL);
buffer.append("From: " + announce);
buffer.append(EOL);
buffer.append("Bcc: " + announce);
buffer.append(EOL);
buffer.append(EOL);
buffer.append("Hello World");
byte[] data = buffer.toString().getBytes();
InputStream in = new ByteArrayInputStream(data);
MimeMessage message = new MimeMessage(null, in);
List to =
Arrays.asList(message.getRecipients(Message.RecipientType.TO));
assertEquals(2, to.size());
assertTrue(to.contains(new InternetAddress(users)));
assertTrue(to.contains(new InternetAddress(developers)));
List cc =
Arrays.asList(message.getRecipients(Message.RecipientType.CC));
assertEquals(0, cc.size());
List bcc =
Arrays.asList(message.getRecipients(Message.RecipientType.BCC));
assertEquals(1, bcc.size());
assertTrue(bcc.contains(new InternetAddress(announce)));
List all = Arrays.asList(message.getAllRecipients());
assertEquals(3, all.size());
assertTrue(all.contains(new InternetAddress(announce)));
assertTrue(all.contains(new InternetAddress(users)));
assertTrue(all.contains(new InternetAddress(developers)));
}
public void testSetters() throws MessagingException, IOException {
MimeMessage message = new MimeMessage(null, 1);
message.setContent("Hello world", "text/plain");
message.setContentID("Test message @ test.com");
//message.setContentLanguage(new String[] { "en" });
message.setContentMD5("md5hash");
message.setDescription("A test message");
message.setDisposition(Part.INLINE);
message.setFileName("file.txt");
message.setFrom(new InternetAddress(users));
message.setRecipient(
Message.RecipientType.TO,
new InternetAddress(developers));
message.setSubject("What is the first program you write?");
Date sent = new Date();
message.setSentDate(sent);
assertEquals("Hello world", message.getContent());
assertEquals("Test message @ test.com", message.getContentID());
assertEquals("md5hash", message.getContentMD5());
assertEquals("A test message", message.getDescription());
assertEquals("inline", message.getDisposition());
assertEquals("file.txt", message.getFileName());
// assertEquals("en",message.getContentLanguage()[0]);
assertEquals(
"inline;filename=file.txt",
message.getHeader("Content-Disposition", null));
assertEquals(new InternetAddress(users), message.getFrom()[0]);
assertEquals(
new InternetAddress(developers),
message.getRecipients(Message.RecipientType.TO)[0]);
// Cannot use 'equals' testing becaues new Date() contains
millisecond accuracy,
// whereas the one from the MessageContext has been encoded to a
string and parsed
assertEquals(sent.toString(),message.getSentDate().toString());
}
}
1.1
incubator-geronimo/specs/javamail/src/test/javax/mail/internet/NewsAddressTest.java
Index: NewsAddressTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package javax.mail.internet;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/04 01:31:41 $
*/
public class NewsAddressTest extends TestCase {
public void testNewsAddress() throws AddressException {
NewsAddress na = new NewsAddress("geronimo-dev", "news.apache.org");
assertEquals("geronimo-dev", na.getNewsgroup());
assertEquals("news.apache.org", na.getHost());
assertEquals("news", na.getType());
assertEquals("[EMAIL PROTECTED]", na.toString());
NewsAddress[] nas =
NewsAddress.parse(
"[EMAIL PROTECTED], [EMAIL PROTECTED]");
assertEquals(2, nas.length);
assertEquals("geronimo-dev", nas[0].getNewsgroup());
assertEquals("news.apache.org", nas[0].getHost());
assertEquals("geronimo-user", nas[1].getNewsgroup());
assertEquals("news.apache.org", nas[1].getHost());
}
}