diff options
Diffstat (limited to 'plugins/org.eclipse.osee.mail.test/src/org/eclipse')
12 files changed, 746 insertions, 4 deletions
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 71d0c4c5c22..4d1b9cfc267 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 @@ -13,11 +13,25 @@ package org.eclipse.osee.mail; import org.junit.runner.RunWith; import org.junit.runners.Suite; -@RunWith(Suite.class) -@Suite.SuiteClasses({MailUtilsTest.class}) /** * @author Roberto E. Escobar */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ +//@formatter:off + MailEventUtilTest.class, + MailMessageSingleParamTest.class, + MailMessageMultiParamTest.class, + MailServiceConfigSingleParamStringTest.class, + MailServiceConfigSingleParamIntTest.class, + MailServiceConfigSingleParamBoolTest.class, + MailServiceConfigSetToTest.class, + MailUtilsContainsAnyTest.class, + MailUtilsCreateFromHtmlTest.class, + MailUtilsCreateFromStringTest.class, + MailUtilsCreateOutlookEventTest.class, +//@formatter:on +}) public class AllMailTestSuite { - //Test Suite Class -} + // 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 new file mode 100644 index 00000000000..f869d25b2e5 --- /dev/null +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailEventUtilTest.java @@ -0,0 +1,19 @@ +/* + * Created on Jun 3, 2011 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.mail; + +/** + * Test unit for {@link MailEventUtil} + * + * @author Shawn F. cook + */ +public class MailEventUtilTest { + + @org.junit.Test + public void test_MailUtils_createTransportEventData() { + + }//test_MailUtils_createTransportEventData +} diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailMessageMultiParamTest.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailMessageMultiParamTest.java new file mode 100644 index 00000000000..163eed7fa50 --- /dev/null +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailMessageMultiParamTest.java @@ -0,0 +1,92 @@ +/* + * Created on Jun 6, 2011 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.mail; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedList; +import javax.activation.DataSource; +import junit.framework.Assert; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test unit for {@link MailMessage} using a multi-parameter list. + * + * @author Shawn F. cook + */ +@RunWith(Parameterized.class) +public class MailMessageMultiParamTest { + + private final Collection<String> llist; + + public MailMessageMultiParamTest(Collection<String> llist) { + this.llist = llist; + } + + @org.junit.Test + public void testMailMsgSetRecipients() { + MailMessage msg = new MailMessage(); + + msg.setRecipients(llist); + Assert.assertEquals(llist.size(), msg.getRecipients().size()); + Assert.assertTrue(msg.getRecipients().containsAll(llist)); + } + + @org.junit.Test + public void testMailMsgSetReplyTo() { + MailMessage msg = new MailMessage(); + + msg.setReplyTo(llist); + Assert.assertEquals(llist.size(), msg.getReplyTo().size()); + Assert.assertTrue(msg.getReplyTo().containsAll(llist)); + } + + @org.junit.Test + public void testMailMsgAddAttachments() { + MailMessage msg = new MailMessage(); + LinkedList<DataSource> dslist = new LinkedList<DataSource>(); + + for (String item : llist) { + DataSource ds = MailUtils.createFromString(item, item); + msg.addAttachment(ds); + dslist.add(ds); + } + + Assert.assertTrue("Item not retained by MailMessage.attachments.", msg.getAttachments().containsAll(dslist)); + } + + @Parameters + public static Collection<Object[]> getData() { + Collection<Object[]> data = new ArrayList<Object[]>(); + + data.add(new Object[] {Arrays.asList("One new string value.", "Another new string value", + "Yet another string value.", "And the final string value.")}); + + data.add(new Object[] {Arrays.asList("joe.schmoe@somedomain.com", "so.and.so@thisandthat.com", + "this_is-an.email@some-where.org", "just-one-more-email.something.com")}); + + data.add(new Object[] {Arrays.asList("1.Testing special characters - ~`!@#$%^&*()_-+={}|[]:\";'<>?,./", + "2.Testing special characters - ~`!@#$%^&*()_-+={}|[]:\";'<>?,./", + "3.Testing special characters - ~`!@#$%^&*()_-+={}|[]:\";'<>?,./", + "4.Testing special characters - ~`!@#$%^&*()_-+={}|[]:\";'<>?,./")}); + + //generate a very long string + String aLongString1 = "1."; + String aLongString2 = "2."; + String aLongString3 = "3."; + String aLongString4 = "4."; + //make a 1000 char string. + for (int i = 0; i < 1000; i++) { + aLongString1 += "x"; + } + data.add(new Object[] {Arrays.asList(aLongString1, aLongString2, aLongString3, aLongString4)}); + + return data; + }//getData +} diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailMessageSingleParamTest.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailMessageSingleParamTest.java new file mode 100644 index 00000000000..cb25b308807 --- /dev/null +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailMessageSingleParamTest.java @@ -0,0 +1,67 @@ +/* + * Created on Jun 6, 2011 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.mail; + +import java.util.ArrayList; +import java.util.Collection; +import junit.framework.Assert; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test unit for {@link MailMessage} using only a 1-String parameter list. + * + * @author Shawn F. cook + */ +@RunWith(Parameterized.class) +public class MailMessageSingleParamTest { + String str_value; + + public MailMessageSingleParamTest(String str_value) { + this.str_value = str_value; + } + + @org.junit.Test + public void testMailMsgSetFrom() { + MailMessage msg = new MailMessage(); + msg.setFrom(str_value); + Assert.assertEquals(str_value, msg.getFrom()); + } + + @org.junit.Test + public void testMailMsgSetId() { + MailMessage msg = new MailMessage(); + msg.setId(str_value); + Assert.assertEquals(str_value, msg.getId()); + } + + @org.junit.Test + public void testMailMsgSetSubject() { + MailMessage msg = new MailMessage(); + msg.setSubject(str_value); + Assert.assertEquals(str_value, msg.getSubject()); + }//test_MailMsg_accessors + + @Parameters + public static Collection<Object[]> getData() { + Collection<Object[]> data = new ArrayList<Object[]>(); + + data.add(new Object[] {"One new string value."}); + data.add(new Object[] {"joe.schmoe@somedomain.com"}); + data.add(new Object[] {"Testing special characters - ~`!@#$%^&*()_-+={}|[]:\";'<>?,./"}); + + //generate a very long string + String aLongString = ""; + //make a 1000 char string. + for (int i = 0; i < 1000; i++) { + aLongString += "x"; + } + data.add(new Object[] {aLongString}); + + return data; + }//getData +} diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailServiceConfigSetToTest.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailServiceConfigSetToTest.java new file mode 100644 index 00000000000..8f39cba2abd --- /dev/null +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailServiceConfigSetToTest.java @@ -0,0 +1,101 @@ +/* + * Created on Jun 6, 2011 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.mail; + +import java.util.ArrayList; +import java.util.Collection; +import junit.framework.Assert; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test unit for {@link MailServiceConfig} + * + * @author Shawn F. cook + */ +@RunWith(Parameterized.class) +public class MailServiceConfigSetToTest { + private final String host; + private final String pword; + private final String sysAdminEmail; + private final String transport; + private final String username; + private final int port; + + public MailServiceConfigSetToTest(String host, String pword, int port, String sysAdminEmail, String transport, String username) { + this.host = host; + this.pword = pword; + this.port = port; + this.sysAdminEmail = sysAdminEmail; + this.transport = transport; + this.username = username; + } + + @org.junit.Test + public void testMailMsgSetTo() { + MailServiceConfig mailsvc = new MailServiceConfig(); + MailServiceConfig mailsvc_to = new MailServiceConfig(); + + mailsvc_to.setHost(host); + mailsvc_to.setPassword(pword); + mailsvc_to.setPort(port); + mailsvc_to.setSystemAdminEmailAddress(sysAdminEmail); + mailsvc_to.setTransport(transport); + mailsvc_to.setUserName(username); + mailsvc.setTo(mailsvc_to); + Assert.assertEquals(mailsvc_to.getHost(), mailsvc.getHost()); + Assert.assertEquals(mailsvc_to.getPassword(), mailsvc.getPassword()); + Assert.assertEquals(mailsvc_to.getPort(), mailsvc.getPort()); + Assert.assertEquals(mailsvc_to.getSystemAdminEmailAddress(), mailsvc.getSystemAdminEmailAddress()); + Assert.assertEquals(mailsvc_to.getTransport(), mailsvc.getTransport()); + Assert.assertEquals(mailsvc_to.getUserName(), mailsvc.getUserName()); + + }//test_MailMsg_accessors + + @Parameters + public static Collection<Object[]> getData() { + Collection<Object[]> data = new ArrayList<Object[]>(); + data.add(new Object[] {"This is a host value.",//host + "This is a pword value.",//pword + 0,//port + "This is a sysAdminEmail value.",//sysAdminEmail + "This is a transport value.",//transport + "This is a username value."});//username + + data.add(new Object[] {"such.and.such.somewhere.com",//host + "th1$_!S_@_p#$$w0)d",//pword + 25,//port + "so.and.so@such-and-such.org",//sysAdminEmail + "smtp",//transport + "joe.schmoe"});//username + + data.add(new Object[] {"1.Testing special characters - ~`!@#$%^&*()_-+={}|[]:\";'<>?,./",//host + "2.Testing special characters - ~`!@#$%^&*()_-+={}|[]:\";'<>?,./",//pword + 32000,//port + "3.Testing special characters - ~`!@#$%^&*()_-+={}|[]:\";'<>?,./",//sysAdminEmail + "4.Testing special characters - ~`!@#$%^&*()_-+={}|[]:\";'<>?,./",//transport + "5.Testing special characters - ~`!@#$%^&*()_-+={}|[]:\";'<>?,./"});//username + + //generate a very long string + String aLongString1 = "1."; + String aLongString2 = "2."; + String aLongString3 = "3."; + String aLongString4 = "4."; + String aLongString5 = "5."; + //make a 1000 char string. + for (int i = 0; i < 1000; i++) { + aLongString1 += "x"; + aLongString2 += "x"; + aLongString3 += "x"; + aLongString4 += "x"; + aLongString5 += "x"; + } + data.add(new Object[] {aLongString1, aLongString2, 49151, aLongString3, aLongString4, aLongString5}); + + return data; + }//getData +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailServiceConfigSingleParamBoolTest.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailServiceConfigSingleParamBoolTest.java new file mode 100644 index 00000000000..fe7eed25102 --- /dev/null +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailServiceConfigSingleParamBoolTest.java @@ -0,0 +1,48 @@ +/* + * Created on Jun 6, 2011 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.mail; + +import java.util.ArrayList; +import java.util.Collection; +import junit.framework.Assert; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test unit for {@link MailServiceConfig} + * + * @author Shawn F. cook + */ +@RunWith(Parameterized.class) +public class MailServiceConfigSingleParamBoolTest { + boolean bool_value; + + public MailServiceConfigSingleParamBoolTest(boolean bool_value) { + this.bool_value = bool_value; + } + + @org.junit.Test + public void testMailMsgBoolAccessors() { + MailServiceConfig mailsvc = new MailServiceConfig(); + mailsvc.setAuthenticationRequired(bool_value); + Assert.assertEquals(bool_value, mailsvc.isAuthenticationRequired()); + mailsvc.setDebug(bool_value); + Assert.assertEquals(bool_value, mailsvc.isDebug()); + mailsvc.setMailStatsEnabled(bool_value); + Assert.assertEquals(bool_value, mailsvc.isMailStatsEnabled()); + }//test_MailMsg_accessors + + @Parameters + public static Collection<Object[]> getData() { + Collection<Object[]> data = new ArrayList<Object[]>(); + + data.add(new Object[] {false}); + data.add(new Object[] {true}); + + return data; + }//getData +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailServiceConfigSingleParamIntTest.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailServiceConfigSingleParamIntTest.java new file mode 100644 index 00000000000..99f5f6a158b --- /dev/null +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailServiceConfigSingleParamIntTest.java @@ -0,0 +1,46 @@ +/* + * Created on Jun 6, 2011 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.mail; + +import java.util.ArrayList; +import java.util.Collection; +import junit.framework.Assert; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test unit for {@link MailServiceConfig} + * + * @author Shawn F. cook + */ +@RunWith(Parameterized.class) +public class MailServiceConfigSingleParamIntTest { + int int_value; + + public MailServiceConfigSingleParamIntTest(int int_value) { + this.int_value = int_value; + } + + @org.junit.Test + public void testMailMsgIntAccessors() { + MailServiceConfig mailsvc = new MailServiceConfig(); + mailsvc.setPort(int_value); + Assert.assertEquals(int_value, mailsvc.getPort()); + }//test_MailMsg_accessors + + @Parameters + public static Collection<Object[]> getData() { + Collection<Object[]> data = new ArrayList<Object[]>(); + + data.add(new Object[] {0}); + data.add(new Object[] {-1234}); + data.add(new Object[] {999999}); + data.add(new Object[] {-8376346}); + + return data; + }//getData +} diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailServiceConfigSingleParamStringTest.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailServiceConfigSingleParamStringTest.java new file mode 100644 index 00000000000..ce6fb7bc82b --- /dev/null +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailServiceConfigSingleParamStringTest.java @@ -0,0 +1,63 @@ +/* + * Created on Jun 6, 2011 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.mail; + +import java.util.ArrayList; +import java.util.Collection; +import junit.framework.Assert; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test unit for {@link MailServiceConfig} + * + * @author Shawn F. cook + */ +@RunWith(Parameterized.class) +public class MailServiceConfigSingleParamStringTest { + String str_value; + + public MailServiceConfigSingleParamStringTest(String str_value) { + this.str_value = str_value; + } + + @org.junit.Test + public void testMailMsgStringAccessors() { + MailServiceConfig mailsvc = new MailServiceConfig(); + + mailsvc.setHost(str_value); + Assert.assertEquals(str_value, mailsvc.getHost()); + mailsvc.setPassword(str_value); + Assert.assertEquals(str_value, mailsvc.getPassword()); + mailsvc.setSystemAdminEmailAddress(str_value); + Assert.assertEquals(str_value, mailsvc.getSystemAdminEmailAddress()); + mailsvc.setTransport(str_value); + Assert.assertEquals(str_value, mailsvc.getTransport()); + mailsvc.setUserName(str_value); + Assert.assertEquals(str_value, mailsvc.getUserName()); + + }//test_MailMsg_accessors + + @Parameters + public static Collection<Object[]> getData() { + Collection<Object[]> data = new ArrayList<Object[]>(); + + data.add(new Object[] {"One new string value."}); + data.add(new Object[] {"joe.schmoe@somedomain.com"}); + data.add(new Object[] {"Testing special characters - ~`!@#$%^&*()_-+={}|[]:\";'<>?,./"}); + + //generate a very long string + String aLongString = ""; + //make a 1000 char string. + for (int i = 0; i < 1000; i++) { + aLongString += "x"; + } + data.add(new Object[] {aLongString}); + + return data; + }//getData +} diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsContainsAnyTest.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsContainsAnyTest.java new file mode 100644 index 00000000000..dbd7321ec4f --- /dev/null +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsContainsAnyTest.java @@ -0,0 +1,57 @@ +/* + * Created on Jun 7, 2011 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.mail; + +import java.util.ArrayList; +import java.util.Collection; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test unit for {@link MailMessageFactory}. + * + * @author Shawn F. cook + */ +@RunWith(Parameterized.class) +public class MailUtilsContainsAnyTest { + private final String testStr; + private final char[] chars; + private final int indexOfFirstInstance;//index of the first instance of any of chars in testStr. + + public MailUtilsContainsAnyTest(String testStr, char[] chars, int indexOfFirstInstance) { + this.testStr = testStr; + this.chars = chars; + this.indexOfFirstInstance = indexOfFirstInstance; + } + + @Parameters + public static Collection<Object[]> getData() { + Collection<Object[]> data = new ArrayList<Object[]>(); + + data.add(new Object[] {"xxxxx",//testStr + new char[] {'x'},//chars + 0,//indexOfFirstInstance + }); + + data.add(new Object[] {"xxxxx",//testStr + new char[] {'a'},//chars + -1,//indexOfFirstInstance + }); + + data.add(new Object[] {"XABcxx",//testStr + new char[] {'a', 'b', 'c'},//chars + 3,//indexOfFirstInstance + }); + + data.add(new Object[] {"XABcx%x",//testStr + new char[] {'z', '$', '\u0025'},//chars + 5,//indexOfFirstInstance + }); + + return data; + }//getData +} diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsCreateFromHtmlTest.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsCreateFromHtmlTest.java new file mode 100644 index 00000000000..aab1155eae4 --- /dev/null +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsCreateFromHtmlTest.java @@ -0,0 +1,76 @@ +/* + * Created on Jun 7, 2011 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.mail; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collection; +import javax.activation.DataSource; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.junit.Assert; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test unit for {@link MailMessageFactory}. + * + * @author Shawn F. cook + */ +@RunWith(Parameterized.class) +public class MailUtilsCreateFromHtmlTest { + private final String name_value; + private final String html_value; + + public MailUtilsCreateFromHtmlTest(String name_value, String html_value) { + this.name_value = name_value; + this.html_value = html_value; + } + + @org.junit.Test + public void testCreateFromHtml() throws Exception { + DataSource source = MailUtils.createFromHtml(name_value, html_value); + Assert.assertEquals(name_value, source.getName()); + + String actual = null; + InputStream is = null; + try { + is = source.getInputStream(); + actual = Lib.inputStreamToString(is); + } finally { + Lib.close(is); + } + + /* + * DataHandler handler = new DataHandler(source); String contentType = handler.getContentType(); + * handler.getContent(); handler.getPreferredCommands(); System.out.println(contentType); + * Assert.assertEquals("text/html", source.getContentType()); String expected = ""; Assert.assertEquals(expected, + * actual); + */ + + } + + @org.junit.Test(expected = UnsupportedOperationException.class) + public void testCreateFromHtmlException() throws Exception { + DataSource source = MailUtils.createFromHtml(name_value, html_value); + source.getOutputStream(); + } + + @Parameters + public static Collection<Object[]> getData() { + Collection<Object[]> data = new ArrayList<Object[]>(); + + data.add(new Object[] {"name_value",//name_value + "html_value",//html_value + }); + + data.add(new Object[] {"$p3c!@|_(#@0\\/@(+3&$",//name_value + "$p3c!@|_(#@0\\/@(+3&$",//html_value + }); + + return data; + }//getData +} diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsCreateFromStringTest.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsCreateFromStringTest.java new file mode 100644 index 00000000000..53ab982ecbd --- /dev/null +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsCreateFromStringTest.java @@ -0,0 +1,64 @@ +/* + * Created on Jun 7, 2011 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.mail; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import javax.activation.DataSource; +import javax.mail.MessagingException; +import org.junit.Assert; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test unit for {@link MailMessageFactory}. + * + * @author Shawn F. cook + */ +@RunWith(Parameterized.class) +public class MailUtilsCreateFromStringTest { + + private final String str_value; + + public MailUtilsCreateFromStringTest(String str_value) { + this.str_value = str_value; + } + + @org.junit.Test + public void testMailUtilsCreateFromString() throws IOException { + DataSource source = MailUtils.createFromString(str_value, "message_value"); + Assert.assertEquals("text/plain; charset=UTF-8", source.getContentType()); + Assert.assertEquals(str_value, source.getName()); + Assert.assertNotNull(source.getOutputStream()); + } + + @org.junit.Test + public void testMailUtilsCreateFromHtml() throws MessagingException { + DataSource source = MailUtils.createFromHtml(str_value, "html_value"); + //MailUtils::createFromHtml returns an instance of MultiPartDataSource which inherits from DataSource but is + // private to the MailUtils class. This is the only effective test I can think of right now. + Assert.assertEquals(str_value, source.getName()); + } + + @Parameters + public static Collection<Object[]> getData() { + Collection<Object[]> data = new ArrayList<Object[]>(); + + data.add(new Object[] {"name_value"}); + data.add(new Object[] {"$p3c!@|_(#@0\\/@(+3&$"}); + + String a = ""; + //make a 1000 char string. + for (int i = 0; i < 1000; i++) { + a += "x"; + } + data.add(new Object[] {a}); + + return data; + }//getData +} diff --git a/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsCreateOutlookEventTest.java b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsCreateOutlookEventTest.java new file mode 100644 index 00000000000..811d9b182b5 --- /dev/null +++ b/plugins/org.eclipse.osee.mail.test/src/org/eclipse/osee/mail/MailUtilsCreateOutlookEventTest.java @@ -0,0 +1,95 @@ +/* + * Created on Jun 7, 2011 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.mail; + +import java.text.DateFormat; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import javax.activation.DataSource; +import org.junit.Assert; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Test unit for {@link MailMessageFactory}. + * + * @author Shawn F. cook + */ +@RunWith(Parameterized.class) +public class MailUtilsCreateOutlookEventTest { + + private final String location; + private final String event; + private final Date startDate; + private final Date endDate; + + //NOTE: The current implementation of the MailUtils::createOutlookEvent() method requires that + // startDate and endDate to be on the same day. Testing dates on different calendar days will + // falsely fail. + public MailUtilsCreateOutlookEventTest(String location, String event, Date startDate, Date endDate) { + this.location = location; + this.event = event; + this.startDate = startDate; + this.endDate = endDate; + } + + @org.junit.Test + public void testMailUtilsCreateOutlookEvent() { + //MailUtils::createOutlookEvent returns an instance of StringDataSource which inherits from DataSource but is + // private to the MailUtils class. This is the only effective test I can think of right now. + Calendar startCal = Calendar.getInstance(); + Calendar endCal = Calendar.getInstance(); + + startCal.setTime(startDate); + String startTime = startCal.get(Calendar.HOUR_OF_DAY) + "" + startCal.get(Calendar.MINUTE); + + endCal.setTime(endDate); + String endTime = endCal.get(Calendar.HOUR_OF_DAY) + "" + endCal.get(Calendar.MINUTE); + + DataSource source = MailUtils.createOutlookEvent(location, event, startDate, startTime, endTime); + // String expectedResult = + // "\nBEGIN:VCALENDAR\nPRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN\nVERSION:1.0\nBEGIN:VEVENT\nDTSTART:" + startCal.get(Calendar.YEAR) + "" + startCal.get(Calendar.MONTH) + "" + startCal.get(Calendar.DAY_OF_MONTH) + "T" + startTime + "0Z\nDTEND:" + endCal.get(Calendar.YEAR) + "" + endCal.get(Calendar.MONTH) + "" + endCal.get(Calendar.DAY_OF_MONTH) + "T" + endTime + "0Z\nLOCATION;ENCODING=QUOTED-PRINTABLE:" + location + "\nTRANSP:1\nDESCRIPTION;ENCODING=QUOTED-PRINTABLE:=0D=0A\nSUMMARY;ENCODING=QUOTED-PRINTABLE:Event:" + event + "\nPRIORITY:3\nEND:VEVENT\nEND:VCALENDAR\n"; + + Assert.assertTrue(source.getName().startsWith(event)); + Assert.assertEquals("text/plain; charset=UTF-8", source.getContentType()); + }//test_MailUtils_createOutlookEvent + + @Parameters + public static Collection<Object[]> getData() throws ParseException { + //PLEASE SEE NOTE above the constructor. + Collection<Object[]> data = new ArrayList<Object[]>(); + + data.add(new Object[] {"Meeting room 220.",//location + "Daily SCRUM",//event + DateFormat.getInstance().parse("01/31/2011 09:45 AM, PDT"),//startDate + DateFormat.getInstance().parse("01/31/2011 10:00 AM, PDT"),//endDate + }); + + data.add(new Object[] {"!@#$%^ & ( ) _ + 1234567890-=`~}{[],.;'",//location + "Testing!@#$%^ & ( ) _ + 1234567890-=`~}{[],.;'",//event + DateFormat.getInstance().parse("01/31/2011 09:45 AM, PDT"),//startDate + DateFormat.getInstance().parse("01/31/2011 10:00 AM, PDT"),//endDate + }); + + data.add(new Object[] {"Joe Schmoe's Desk",//location + "Discuss what to do about the ant problem in the break room.",//event + DateFormat.getInstance().parse("12/31/2300 00:00 AM, PDT"),//startDate + DateFormat.getInstance().parse("12/31/2300 11:59 PM, PDT"),//endDate + }); + + data.add(new Object[] {"Joe Schmoe's Desk",//location + "Discuss what to do about the ant problem in the break room.",//event + DateFormat.getInstance().parse("12/31/2300 11:58 PM, PDT"),//startDate + DateFormat.getInstance().parse("12/31/2300 11:59 PM, PDT"),//endDate + }); + + return data; + }//getData +} |