diff options
author | Roberto E. Escobar | 2014-06-24 23:42:38 +0000 |
---|---|---|
committer | Roberto E. Escobar | 2014-08-28 23:58:56 +0000 |
commit | 868f517e191584dab637571e243b8eda2be1181f (patch) | |
tree | 23ffc238a81973e6565546a64d3d3a7bcb14ef08 /plugins/org.eclipse.osee.mail.test | |
parent | 543c55775e48e8f476abbbfe436d45778d4ad85c (diff) | |
download | org.eclipse.osee-868f517e191584dab637571e243b8eda2be1181f.tar.gz org.eclipse.osee-868f517e191584dab637571e243b8eda2be1181f.tar.xz org.eclipse.osee-868f517e191584dab637571e243b8eda2be1181f.zip |
refactor: Simplify Mail Service API
Change-Id: I586ba68a8aa607f203a174c8b184e538037e0806
Diffstat (limited to 'plugins/org.eclipse.osee.mail.test')
-rw-r--r-- | plugins/org.eclipse.osee.mail.test/pom.xml | 7 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/AllMailTestSuite.java | 5 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailEventUtilTest.java | 117 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/internal/MailConfigurationTest.java (renamed from plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailConfigurationTest.java) | 43 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/internal/MailMessageTest.java (renamed from plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailMessageTest.java) | 4 | ||||
-rw-r--r-- | plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/internal/MailUtilsTest.java (renamed from plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsTest.java) | 40 |
6 files changed, 31 insertions, 185 deletions
diff --git a/plugins/org.eclipse.osee.mail.test/pom.xml b/plugins/org.eclipse.osee.mail.test/pom.xml index 346413109b4..675daf3eb41 100644 --- a/plugins/org.eclipse.osee.mail.test/pom.xml +++ b/plugins/org.eclipse.osee.mail.test/pom.xml @@ -23,13 +23,6 @@ <configuration> <testSuite>org.eclipse.osee.mail.test</testSuite> <testClass>org.eclipse.osee.mail.AllMailTestSuite</testClass> - <dependencies> - <dependency> - <type>eclipse-plugin</type> - <artifactId>javax.activation</artifactId> - <version>0.0.0</version> - </dependency> - </dependencies> </configuration> </plugin> </plugins> diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/AllMailTestSuite.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/AllMailTestSuite.java index 20476b77b27..7f55f1ff6d5 100644 --- a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/AllMailTestSuite.java +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/AllMailTestSuite.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.osee.mail; +import org.eclipse.osee.mail.internal.MailConfigurationTest; +import org.eclipse.osee.mail.internal.MailMessageTest; +import org.eclipse.osee.mail.internal.MailUtilsTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -17,7 +20,7 @@ import org.junit.runners.Suite; * @author Roberto E. Escobar */ @RunWith(Suite.class) -@Suite.SuiteClasses({MailConfigurationTest.class, MailEventUtilTest.class, MailMessageTest.class, MailUtilsTest.class}) +@Suite.SuiteClasses({MailConfigurationTest.class, MailMessageTest.class, MailUtilsTest.class}) public class AllMailTestSuite { // Test Suite }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailEventUtilTest.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailEventUtilTest.java deleted file mode 100644 index e9eeca545a7..00000000000 --- a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailEventUtilTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.mail; - -import java.util.Date; -import java.util.Map; -import java.util.Properties; -import javax.mail.Address; -import javax.mail.Message; -import javax.mail.MessagingException; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.URLName; -import javax.mail.event.TransportEvent; -import javax.mail.internet.AddressException; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; -import org.junit.Assert; - -/** - * Test unit for {@link MailEventUtil} - * - * @author Roberto E. Escobar - */ -public class MailEventUtilTest { - - private static final String ADDRESS1 = "hello@hello.com"; - private static final String ADDRESS2 = "goodbye@goodbye.com"; - private static final String ADDRESS3 = "dummy@inbox.com"; - private static final String ADDRESS4 = "another@x.com"; - private static final String ADDRESS5 = "another@asda.com"; - private static final String ADDRESS6 = "anor@asd.com"; - private static final String ADDRESS7 = "anoasdadaasdrf@asdfas.com"; - private static final String ADDRESS8 = "s.d.f.a.s.dfasdf@com"; - - @org.junit.Test - public void testCreateTransportEventData() throws MessagingException { - Address[] from = toAddress(ADDRESS1); - Address[] sent = toAddress(ADDRESS2, ADDRESS3, ADDRESS8); - Address[] unsent = toAddress(ADDRESS4, ADDRESS5); - Address[] invalid = toAddress(ADDRESS6, ADDRESS7); - - String uuid = "123114135"; - Date sendDate = new Date(12345); - String subject = "dummy subject"; - - Session session = Session.getDefaultInstance(new Properties()); - - MimeMessage message = new MimeMessage(session); - message.setHeader(MailConstants.MAIL_UUID_HEADER, uuid); - message.setSentDate(sendDate); - message.setSubject(subject); - message.setFrom(from[0]); - - TransportEvent event = createEvent(session, message, sent, unsent, invalid); - - Map<String, String> data = MailEventUtil.createTransportEventData(event); - assertEventData(data, uuid, message.getSentDate(), subject, from, sent, unsent, invalid); - } - - private static void assertEventData(Map<String, String> data, String uuid, Date sendDate, String subject, Address[] from, Address[] validSent, Address[] validUnsent, Address[] invalid) { - Assert.assertEquals(uuid, data.get(MailConstants.MAIL_UUID)); - Assert.assertEquals(subject, data.get(MailConstants.MAIL_SUBJECT)); - - String actualDate = data.get(MailConstants.MAIL_DATE_SENT); - if (sendDate != null) { - Assert.assertEquals(sendDate.getTime(), Long.parseLong(actualDate)); - } else { - Assert.assertNull(actualDate); - } - - assertAddress(data, MailConstants.MAIL_FROM_ADDRESS, from); - assertAddress(data, MailConstants.MAIL_INVALID_ADDRESS, invalid); - assertAddress(data, MailConstants.MAIL_VALID_SENT_ADDRESS, validSent); - assertAddress(data, MailConstants.MAIL_VALID_UNSENT_ADDRESS, validUnsent); - } - - private static void assertAddress(Map<String, String> data, String key, Address[] addresses) { - Assert.assertEquals(addresses.length, Integer.parseInt(data.get(key + ".count"))); - for (int index = 0; index < addresses.length; index++) { - Address address = addresses[index]; - Assert.assertEquals(address.toString(), data.get(key + "." + index)); - } - } - - private static TransportEvent createEvent(Session session, MimeMessage message, Address[] sent, Address[] unsent, Address[] invalid) { - Transport transport = new Transport(session, new URLName("http://hello.com")) { - - @Override - public void sendMessage(Message arg0, Address[] arg1) { - // Do nothing - } - }; - return new TransportEvent(transport, 1, sent, unsent, invalid, message); - } - - private static Address[] toAddress(String... rawAddresses) throws AddressException { - Address[] toReturn = new Address[rawAddresses.length]; - int index = 0; - for (String rawAddress : rawAddresses) { - toReturn[index++] = asAddress(rawAddress); - } - return toReturn; - } - - private static Address asAddress(String value) throws AddressException { - return new InternetAddress(value); - } -} diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailConfigurationTest.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/internal/MailConfigurationTest.java index 4bcda309561..0d7fe2f1eb7 100644 --- a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailConfigurationTest.java +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/internal/MailConfigurationTest.java @@ -8,32 +8,33 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.mail; - -import static org.eclipse.osee.mail.MailConstants.DEFAULT_MAIL_SERVER_ADMIN_EMAIL; -import static org.eclipse.osee.mail.MailConstants.DEFAULT_MAIL_SERVER_HOST; -import static org.eclipse.osee.mail.MailConstants.DEFAULT_MAIL_SERVER_PASSWORD; -import static org.eclipse.osee.mail.MailConstants.DEFAULT_MAIL_SERVER_PORT; -import static org.eclipse.osee.mail.MailConstants.DEFAULT_MAIL_SERVER_STATUS_WAIT_TIME_MILLIS; -import static org.eclipse.osee.mail.MailConstants.DEFAULT_MAIL_SERVER_TEST_EMAIL_BODY; -import static org.eclipse.osee.mail.MailConstants.DEFAULT_MAIL_SERVER_TEST_EMAIL_SUBJECT; -import static org.eclipse.osee.mail.MailConstants.DEFAULT_MAIL_SERVER_TRANSPORT; -import static org.eclipse.osee.mail.MailConstants.DEFAULT_MAIL_SERVER_USERNAME; -import static org.eclipse.osee.mail.MailConstants.MAIL_SERVER_ADMIN_EMAIL; -import static org.eclipse.osee.mail.MailConstants.MAIL_SERVER_HOST; -import static org.eclipse.osee.mail.MailConstants.MAIL_SERVER_PASSWORD; -import static org.eclipse.osee.mail.MailConstants.MAIL_SERVER_PORT; -import static org.eclipse.osee.mail.MailConstants.MAIL_SERVER_STATUS_WAIT_TIME_MILLIS; -import static org.eclipse.osee.mail.MailConstants.MAIL_SERVER_TEST_EMAIL_BODY; -import static org.eclipse.osee.mail.MailConstants.MAIL_SERVER_TEST_EMAIL_SUBJECT; -import static org.eclipse.osee.mail.MailConstants.MAIL_SERVER_TRANSPORT; -import static org.eclipse.osee.mail.MailConstants.MAIL_SERVER_USERNAME; +package org.eclipse.osee.mail.internal; + +import static org.eclipse.osee.mail.internal.MailConstants.DEFAULT_MAIL_SERVER_ADMIN_EMAIL; +import static org.eclipse.osee.mail.internal.MailConstants.DEFAULT_MAIL_SERVER_HOST; +import static org.eclipse.osee.mail.internal.MailConstants.DEFAULT_MAIL_SERVER_PASSWORD; +import static org.eclipse.osee.mail.internal.MailConstants.DEFAULT_MAIL_SERVER_PORT; +import static org.eclipse.osee.mail.internal.MailConstants.DEFAULT_MAIL_SERVER_STATUS_WAIT_TIME_MILLIS; +import static org.eclipse.osee.mail.internal.MailConstants.DEFAULT_MAIL_SERVER_TEST_EMAIL_BODY; +import static org.eclipse.osee.mail.internal.MailConstants.DEFAULT_MAIL_SERVER_TEST_EMAIL_SUBJECT; +import static org.eclipse.osee.mail.internal.MailConstants.DEFAULT_MAIL_SERVER_TRANSPORT; +import static org.eclipse.osee.mail.internal.MailConstants.DEFAULT_MAIL_SERVER_USERNAME; +import static org.eclipse.osee.mail.internal.MailConstants.MAIL_SERVER_ADMIN_EMAIL; +import static org.eclipse.osee.mail.internal.MailConstants.MAIL_SERVER_HOST; +import static org.eclipse.osee.mail.internal.MailConstants.MAIL_SERVER_PASSWORD; +import static org.eclipse.osee.mail.internal.MailConstants.MAIL_SERVER_PORT; +import static org.eclipse.osee.mail.internal.MailConstants.MAIL_SERVER_STATUS_WAIT_TIME_MILLIS; +import static org.eclipse.osee.mail.internal.MailConstants.MAIL_SERVER_TEST_EMAIL_BODY; +import static org.eclipse.osee.mail.internal.MailConstants.MAIL_SERVER_TEST_EMAIL_SUBJECT; +import static org.eclipse.osee.mail.internal.MailConstants.MAIL_SERVER_TRANSPORT; +import static org.eclipse.osee.mail.internal.MailConstants.MAIL_SERVER_USERNAME; import static org.junit.Assert.assertEquals; import static org.mockito.MockitoAnnotations.initMocks; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.eclipse.osee.mail.MailConfiguration.MailConfigurationBuilder; +import org.eclipse.osee.mail.internal.MailConfiguration; +import org.eclipse.osee.mail.internal.MailConfiguration.MailConfigurationBuilder; import org.junit.Before; import org.junit.Test; diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailMessageTest.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/internal/MailMessageTest.java index c099aa64c44..a5d174954ff 100644 --- a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailMessageTest.java +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/internal/MailMessageTest.java @@ -8,13 +8,15 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.mail; +package org.eclipse.osee.mail.internal; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.LinkedList; import javax.activation.DataSource; +import org.eclipse.osee.mail.api.MailMessage; +import org.eclipse.osee.mail.api.MailUtils; import org.junit.Assert; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsTest.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/internal/MailUtilsTest.java index 690b21cd9a9..0e4cff54544 100644 --- a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsTest.java +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/internal/MailUtilsTest.java @@ -8,25 +8,22 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.mail; +package org.eclipse.osee.mail.internal; import java.io.IOException; import java.io.OutputStream; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.activation.DataContentHandler; import javax.activation.DataSource; -import javax.activation.MailcapCommandMap; import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.mail.api.MailUtils; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; /** @@ -48,33 +45,6 @@ public class MailUtilsTest { Pattern.DOTALL); @Test - @Ignore - public void testMailCapCommand() { - MailcapCommandMap map = MailUtils.getMailcapCommandMap(); - List<String> mimeTypes = Arrays.asList(map.getMimeTypes()); - - Assert.assertTrue(mimeTypes.contains("text/*")); - Assert.assertTrue(mimeTypes.contains("text/html")); - Assert.assertTrue(mimeTypes.contains("text/xml")); - Assert.assertTrue(mimeTypes.contains("text/plain")); - Assert.assertTrue(mimeTypes.contains("multipart/*")); - Assert.assertTrue(mimeTypes.contains("multipart/mixed")); - Assert.assertTrue(mimeTypes.contains("message/rfc822")); - Assert.assertTrue(mimeTypes.contains("image/jpeg")); - Assert.assertTrue(mimeTypes.contains("image/gif")); - - assertHandler(map, "text/*", "com.sun.mail.handlers.text_plain"); - assertHandler(map, "text/html", "com.sun.mail.handlers.text_html"); - assertHandler(map, "text/xml", "com.sun.mail.handlers.text_xml"); - assertHandler(map, "text/plain", "com.sun.mail.handlers.text_plain"); - assertHandler(map, "multipart/*", "com.sun.mail.handlers.multipart_mixed"); - assertHandler(map, "multipart/mixed", "com.sun.mail.handlers.multipart_mixed"); - assertHandler(map, "message/rfc822", "com.sun.mail.handlers.message_rfc822"); - assertHandler(map, "image/jpeg", "com.sun.mail.handlers.image_jpeg"); - assertHandler(map, "image/gif", "com.sun.mail.handlers.image_gif"); - } - - @Test public void testCreateFromString() throws IOException { DataSource source = MailUtils.createFromString(EXPECTED_NAME, EXPECTED_MESSAGE); Assert.assertEquals(EXPECTED_NAME, source.getName()); @@ -226,10 +196,4 @@ public class MailUtilsTest { return toReturn; } - private static void assertHandler(MailcapCommandMap map, String mimeType, String handler) { - DataContentHandler actualHandler = map.createDataContentHandler(mimeType); - Assert.assertNotNull(String.format("handler for [%s] is null", mimeType), actualHandler); - Assert.assertEquals(handler, actualHandler.getClass().getName()); - } - } |